/plugins/ProjectViewer/tags/pv_2_1_3_7/projectviewer/action/package.html

# · HTML · 76 lines · 64 code · 12 blank · 0 comment · 0 complexity · da928c35f172a4e6398b04584ee6e799 MD5 · raw file

  1. <body><h2>Creating custom actions.</h2>
  2. <p>ProjectViewer allows other plugin developers too interact with the file trees
  3. by creating custom actions to be executed on the nodes. Actions can be added
  4. to the tree's context menu or to the viewer's toolbar. It's recommended to
  5. extend the context menu, since there's only so much useful space in the
  6. toolbar for new actions.</p>
  7. <p>Creating a new action is very simple:</p>
  8. <ul>
  9. <li>Create a new class that extends {@link projectviewer.action.Action Action}.</li>
  10. <li>Implement the {@link projectviewer.action.Action#actionPerformed(ActionEvent)
  11. actionPerformed()} method to execute the desired operations.</li>
  12. <li>Register the action in the context menu
  13. ({@link projectviewer.vpt.VPTContextMenu#registerAction(Action) registerAction()})
  14. or in the toolbar
  15. ({@link projectviewer.ProjectViewer#registerAction(Action) registerAction()})
  16. by calling the appropriate method.</li>
  17. </ul>
  18. <p>It's recommended to use the new API to register actions. Create the
  19. following properties to automatically register actions with
  20. ProjectViewer:</p>
  21. <ul>
  22. <li>plugin.projectviewer.<i>class name</i>.toolbar-actions:<br>
  23. list of classes that provide {@link projectviewer.action.Action Action}s that
  24. will be added to the toolbar of the ProjectViewer dockable. One instance is
  25. created for each class, and for each jEdit view the instance is cloned,
  26. and then the "projectViewer" instance is set for the cloned object.</li>
  27. <li>plugin.projectviewer.<i>class name</i>.context-menu-actions:<br>
  28. list of classes that provide {@link projectviewer.action.Action Action}s that
  29. will be added to the tree's context menu. One instance is created for each
  30. class, and for each jEdit view the instance is cloned, and then the
  31. "projectViewer" instance is set for the cloned object.</li>
  32. </ul>
  33. <p>The menu item show in the context menu is provided by the
  34. {@link projectviewer.action.Action#getMenuItem() getMenuItem()} of the Action
  35. class. Subclasses are welcome to override this method to provide other kinds
  36. of menu items (a sub-menu, for example). For the toolbar button, the
  37. {@link projectviewer.action.Action#getButton() getButton()} method is used.</p>
  38. <p>Before showing the menu item in the context menu, ProjectViewer will call
  39. the {@link projectviewer.action.Action#prepareForNode(VPTNode) prepareForNode()}
  40. method in all actions registered in the context menu. This allows each action to
  41. decide if it should be shown for the given node and what message to show, for
  42. example. For the toolbar buttons, this method is <b>never</b> called, so the
  43. toolbar buttons should be able to be executed regardless of the current tree
  44. selection. If your action depends on a certain kind of node, add it to the
  45. context menu, and not to the toolbar. If you want to add it to the toolbar,
  46. check for the node type in your <code>actionPerformed()</code> implementation.</p>
  47. <p>Another important thing to notice in the prepareForNode() method is that
  48. the actions should check is the node is of a certain type, and not if the
  49. node is not of a certain type. For example, use "node.isFile()" and not
  50. "!node.isDirectory()". This ensures that the action will not do anything
  51. wrong if a different node type is added in the future to PV, or if another
  52. plugin adds a custom node type to PV.</p>
  53. <p>It's important to notice that the instance given to the <i>registerAction</i>
  54. methods is not the instance used by the viewer instances. Those instances are
  55. used as prototypes, and the viewers use {@link projectviewer.action.Action#clone()
  56. clone()} to get instances for the specific viewer. After the cloning, the
  57. {@link projectviewer.action.Action#setViewer(ProjectViewer) setViewer()} method
  58. is called, so the actions have a reference to the viewers where they are being
  59. used. This also means that you should not use the constructor of your Action
  60. implementation to instantiate GUI components. Instantiations of GUI components
  61. should be done lazily in the <code>getMenuItem()</code> or <code>getButton()</code>
  62. methods. The default implementation already does this, so you should only worry
  63. about this if you are overriding one of these methods.</p>
  64. </body>