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