projectviewer.action
Class Action

java.lang.Object
  extended by projectviewer.action.Action
All Implemented Interfaces:
java.awt.event.ActionListener, java.lang.Cloneable, java.lang.Comparable<Action>, java.util.EventListener
Direct Known Subclasses:
ActionSeparator, AddProjectAction, ArchiveAction, CollapseAllAction, EditGroupAction, EditProjectAction, ExpandAllAction, FileImportAction, LaunchBrowserAction, MoveNodeAction, NewFileAction, NodePropertiesAction, NodeRemoverAction, NodeRenamerAction, OpenCloseAllProjectFilesAction, OpenParentGroupAction, OpenSelectedAction, OpenWithAppAction, OpenWithEncodingAction, ReimportAction, SearchAction, SetActiveAction, UpAction, UpdateVCSStatusAction

public abstract class Action
extends java.lang.Object
implements java.awt.event.ActionListener, java.lang.Cloneable, java.lang.Comparable<Action>

An action defines an action to be taken when the user presses some menu item in the tree's context menu.

Author:
Marcelo Vanzin

Field Summary
protected  java.lang.String action
           
protected  javax.swing.JComponent cmItem
           
protected  ProjectViewer viewer
           
 
Constructor Summary
protected Action()
          Creates a regular action.
protected Action(java.lang.String action)
          Creates an action tied to an action name.
 
Method Summary
 java.lang.Object clone()
          Clones the current action, returning a copy of it.
 int compareTo(Action other)
          Compares this action with another.
 boolean equals(java.lang.Object o)
          Implementation of equals() so that it's consistent with compareTo(Action).
 javax.swing.JComponent getMenuItem()
          Returns the menu item that triggers this action.
abstract  java.lang.String getText()
          Returns a String that will be shown as the text of the menu item or the tooltip of the toolbar button.
 void prepareForNode(VPTNode node)
          When a node is selected (for the toolbar button) or when the context menu is shown (for the menu item), this method is called and the selected node is passed, so the action can choose whether the action will be available or not for that node.
 void setViewer(ProjectViewer viewer)
          Sets the viewer where this action is being used.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.event.ActionListener
actionPerformed
 

Field Detail

viewer

protected ProjectViewer viewer

cmItem

protected javax.swing.JComponent cmItem

action

protected java.lang.String action
Constructor Detail

Action

protected Action()
Creates a regular action.


Action

protected Action(java.lang.String action)
Creates an action tied to an action name. If the action name is not null, the default menu item created will be a jEdit EnhancedMenuItem tied to the action name; this will allow the item to show the currently assigned shortcut of the action, if any. The action listeners are removed from the menu item so that only the actionPerformed() method on this instance is called, avoiding using the jEdit action mechanism for this instance.

Method Detail

getText

public abstract java.lang.String getText()
Returns a String that will be shown as the text of the menu item or the tooltip of the toolbar button.


prepareForNode

public void prepareForNode(VPTNode node)
When a node is selected (for the toolbar button) or when the context menu is shown (for the menu item), this method is called and the selected node is passed, so the action can choose whether the action will be available or not for that node. A common action would be disable the button or hide the menu item.

By default, does nothing.

Parameters:
node - The selected node, or null if multiple nodes are selected.

getMenuItem

public javax.swing.JComponent getMenuItem()
Returns the menu item that triggers this action. This returns a JComponent, which makes it possible to add virtually anything to the menu. For example, it's possible to return a sub-menu instead of a simple menu item. The default implementation returns a menu item, which is stored in the "cmItem" variable.


clone

public java.lang.Object clone()
Clones the current action, returning a copy of it.

Overrides:
clone in class java.lang.Object

setViewer

public void setViewer(ProjectViewer viewer)
Sets the viewer where this action is being used.


compareTo

public int compareTo(Action other)
Compares this action with another. This is used to define the position of the action in the context menu, so that it is always shown in a consistent manner. By default, this first compares the class name of the action, and if those match, the text returned by getText().

Specified by:
compareTo in interface java.lang.Comparable<Action>
Parameters:
other - Action to compare to.
Returns:
Result of comparison (see Comparable.compareTo(Object)).
Since:
PV 3.0.0

equals

public boolean equals(java.lang.Object o)
Implementation of equals() so that it's consistent with compareTo(Action).

Overrides:
equals in class java.lang.Object