PageRenderTime 37ms CodeModel.GetById 30ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/Console/console/ProjectTreeListener.java

#
Java | 112 lines | 55 code | 14 blank | 43 comment | 12 complexity | 43a3a55bd6fa3c3c31760c6202fa354d MD5 | raw file
  1/*
  2 * ProjectTreeListener.java - for listening to ProjectViewer
  3 * events in the Console.
  4
  5 * :tabSize=8:indentSize=8:noTabs=false:
  6 * :folding=explicit:collapseFolds=1:
  7 *
  8 * (c) 2005, 2009 by Alan Ezust
  9 *
 10 * This program is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU General Public License
 12 * as published by the Free Software Foundation; either version 2
 13 * of the License, or any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 23 */
 24package console;
 25
 26// {{{ imports
 27
 28
 29import org.gjt.sp.jedit.BeanShell;
 30import org.gjt.sp.jedit.EBComponent;
 31import org.gjt.sp.jedit.EBMessage;
 32import org.gjt.sp.jedit.View;
 33import org.gjt.sp.jedit.jEdit;
 34
 35import projectviewer.event.ViewerUpdate;
 36import org.gjt.sp.jedit.bsh.NameSpace;
 37// }}}
 38
 39// {{{ ProjectTreeListener class
 40/**
 41 *
 42 * Listener of ProjectViewer 2.9 node selection events.
 43 * Triggers console beanshell scripts as actions in response.
 44 * 
 45 * @author ezust
 46 *
 47 */
 48
 49public class ProjectTreeListener implements EBComponent
 50{
 51
 52	static boolean onProjectChange;
 53	
 54	private Console console;
 55	// {{{ constructor
 56	public ProjectTreeListener(Console c)
 57	{
 58		update();
 59		console = c;
 60	}
 61	// }}}
 62	public void finalize() {
 63		console = null;
 64	}
 65
 66	// {{{ handleMessage()
 67	/**
 68	 * On project change...
 69	 */
 70	public void handleMessage(EBMessage msg)
 71	{
 72		update();
 73		if (!onProjectChange)
 74			return;
 75		if (!(msg.getClass().getName().endsWith("ViewerUpdate"))) return;
 76		final ViewerUpdate vu = (ViewerUpdate) msg;
 77		if (vu.getType() != ViewerUpdate.Type.PROJECT_LOADED) return;
 78		if (console == null) return;
 79		if (vu.getView() != console.getView()) return;
 80		new Thread()
 81		{
 82			public void run()
 83			{
 84				try
 85				{
 86					sleep(500);
 87				}
 88				catch (InterruptedException ie)
 89				{
 90					interrupt();
 91				}
 92				//VPTNode n = vu.getNode();
 93				View view = vu.getView();
 94				if (view == null || view != jEdit.getActiveView()) return;
 95				String code = "changeToPvRoot(view);";
 96				NameSpace namespace =  BeanShell.getNameSpace();
 97				BeanShell.eval(view, namespace, code);
 98			
 99			}
100		}.start();
101	} // }}}
102
103
104	// {{{ update()
105	/** Reloads properties and updates flags */
106	private void update()
107	{
108		onProjectChange = jEdit.getBooleanProperty("console.changedir.pvchange");
109	} // }}}
110
111
112} // }}}