IBM Rational Performance Tester SDK

com.ibm.rational.common.test.editor.framework.kernel.actions
Class NewModelElementAction

java.lang.Object
  extended by org.eclipse.core.commands.common.EventManager
      extended by org.eclipse.jface.action.AbstractAction
          extended by org.eclipse.jface.action.Action
              extended by org.eclipse.ui.actions.BaseSelectionListenerAction
                  extended by com.ibm.rational.common.test.editor.framework.kernel.actions.NewModelElementAction
All Implemented Interfaces:
IAction, ISelectionChangedListener

public class NewModelElementAction
extends BaseSelectionListenerAction

NewModelElementAction is a base class to be used to contribute actions to "Add" and "Insert" sub-menus in Test Editor. Typically, such action needs to be created in the protocol's plugin class once and registered with RptMenuManager as follows:

  RptMenuManager mm = TestEditorPlugin.getMenuManager();
  mm.registerAddActionGroup( ... )
  mm.registerInsertActionGroup( ... )
 

Plugin may register any number of add and insert groups and publish their names so other plugin can contribute their actions. The groups are needed to visually separate menu items in a menu. If the same action is to be displayed in both "Add" and "Insert" menu, to separate instances must be created. Once registered, the actions are managed by Test Editor infrastructure and are shared between multiple open tests.

When user selects a menu item, NewModelElementAction calls ExtActionHandler#createNew(CBActioneElement parent) to actually create a child object.

See Also:
RptMenuManager, EditorNewActionGroup, (extension point), ExtActionHandler

Field Summary
static int ADD
          constant indicating that this action adds, rather then inserts new elements
protected  Map m_contributions
           
protected  ArrayList m_parents
           
protected  boolean m_valid
          The value of this flag can be set to false by NewModelElementAction.addChild(List, CBActionElement) method to stop processing.
 
Fields inherited from interface org.eclipse.jface.action.IAction
AS_CHECK_BOX, AS_DROP_DOWN_MENU, AS_PUSH_BUTTON, AS_RADIO_BUTTON, AS_UNSPECIFIED, CHECKED, DESCRIPTION, ENABLED, HANDLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT
 
Constructor Summary
NewModelElementAction(String type)
          Create an action for model element type type.
NewModelElementAction(String type, boolean loadExtensions)
          Create an action for model element type type and load contributions (if any) made through com.ibm.rational.test.common.editor.framework.newElementActionContributor extension point.
 
Method Summary
protected  void addChild(List children, CBActionElement child)
          Adds or inserts a new children into a list of children.
protected  void clearCache()
           
protected  CBActionElement createNewModelObject(CBActionElement parent)
          Finds ExtActionHandler for its type and calls createnewObject method.
 CBActionElement doCreate(CBActionElement parent)
          This method is called from run{} method.
 int getInsertPoint()
           
 ExtActionHandler getMyActionHandler()
           
 ArrayList getNewElements()
           
 TestEditor getTestEditor()
           
protected  void init()
          Extracts text and image descriptor from ExtLabelProvider>/code>
 boolean isRefreshEnabled()
           
protected  boolean isValidParent(Object object)
          This method is called from updateSelection and is used to determine whether this action should be enabled or disabled.
protected  void refreshTest(CBActionElement parent, CBActionElement child)
           
protected  boolean relocateChildren(CBActionElement oldParent, CBActionElement newParent)
           
 void run()
          Calls doCreate method, and refreshes the Test in the tree.
 void setInsertPoint(int insertPoint)
          Set dynamically by test editor framework as selection in the editor tree changes.
 void setRefreshEnabled(boolean refreshEnabled)
           
 void setTestEditor(TestEditor editor)
           
protected  void updateMode(ExtActionHandler prov)
           
 boolean updateSelection(IStructuredSelection selection)
          This method is called by editor framework when selection changes in the editor's tree or when the editor become active.
 
Methods inherited from class org.eclipse.ui.actions.BaseSelectionListenerAction
getStructuredSelection, runWithEvent, selectionChanged, selectionChanged
 
Methods inherited from class org.eclipse.jface.action.Action
convertAccelerator, convertAccelerator, findKeyCode, findKeyString, findModifier, findModifierString, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, notifyResult, removeAcceleratorText, removeMnemonics, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText
 
Methods inherited from class org.eclipse.jface.action.AbstractAction
addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener
 
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.action.IAction
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

ADD

public static int ADD
constant indicating that this action adds, rather then inserts new elements


m_parents

protected ArrayList m_parents

m_contributions

protected Map m_contributions

m_valid

protected boolean m_valid
The value of this flag can be set to false by NewModelElementAction.addChild(List, CBActionElement) method to stop processing.

Constructor Detail

NewModelElementAction

public NewModelElementAction(String type)
Create an action for model element type type.

Parameters:
type - String Type of a CBActionElement object that this action produces.

NewModelElementAction

public NewModelElementAction(String type,
                             boolean loadExtensions)
Create an action for model element type type and load contributions (if any) made through com.ibm.rational.test.common.editor.framework.newElementActionContributor extension point.

Parameters:
type - String Type of a CBActionElement object that this action produces.
loadExtensions - boolean. If true the newElementActionContributor extension will be loaded.
Method Detail

init

protected void init()
Extracts text and image descriptor from ExtLabelProvider>/code>


createNewModelObject

protected CBActionElement createNewModelObject(CBActionElement parent)
Finds ExtActionHandler for its type and calls createnewObject method.

Parameters:
parent - CBActionElement. Object that is typically selected in the editor's tree.
Returns:
CBActionElement. Newly created child object.

updateMode

protected void updateMode(ExtActionHandler prov)

run

public void run()
Calls doCreate method, and refreshes the Test in the tree.

Specified by:
run in interface IAction
Overrides:
run in class Action
See Also:
IAction.run()

doCreate

public CBActionElement doCreate(CBActionElement parent)
This method is called from run{} method. It does the following:
  • Finds ExtContentProvider for the parent and obtains its list of children,
  • Calls createNewModelObject to create new child object,
  • Adds new child object to the the list of parent's children (if the list is an instanceof EMF EList)
  • Sets NEW status on the child object by calling ModelStateManager.setStatusNew(child, getTestEditor())

    Parameters:
    parent - CBActionElement selected in the tree
    Returns:
    CBActionElement new child object

  • relocateChildren

    protected boolean relocateChildren(CBActionElement oldParent,
                                       CBActionElement newParent)
    Parameters:
    oldParent - CBActionElement
    newParent - CBActionElement
    Returns:
    boolean true if chilfdren were relocated, false if there was an error. Typically, some element could not be moved to different parent element.

    addChild

    protected void addChild(List children,
                            CBActionElement child)
    Adds or inserts a new children into a list of children. If the list if an instaceof EList, the model change occures. Otherwise clients need to make sure the new child objects is indeed added to a model.

    This method is called by doCreate only if the children obtained from parent's ExtContentProvider is of (sub-)type of EMF EList.

    Parameters:
    children - List of children
    child -

    refreshTest

    protected void refreshTest(CBActionElement parent,
                               CBActionElement child)

    getTestEditor

    public TestEditor getTestEditor()

    isRefreshEnabled

    public boolean isRefreshEnabled()
    Returns:
    Returns the refreshEnabled.

    setRefreshEnabled

    public void setRefreshEnabled(boolean refreshEnabled)
    Parameters:
    refreshEnabled - The refreshEnabled to set.

    updateSelection

    public boolean updateSelection(IStructuredSelection selection)
    This method is called by editor framework when selection changes in the editor's tree or when the editor become active. Clients should not call this method.

    If isValidParent() returns false and extensions are loaded, the list of contributions is checked to see whether the parent/child relation was allowed declaretively.

    Overrides:
    updateSelection in class BaseSelectionListenerAction
    See Also:
    BaseSelectionListenerAction.updateSelection(org.eclipse.jface.viewers.IStructuredSelection)

    clearCache

    protected void clearCache()
    Overrides:
    clearCache in class BaseSelectionListenerAction

    isValidParent

    protected boolean isValidParent(Object object)
    This method is called from updateSelection and is used to determine whether this action should be enabled or disabled.

    If client decides that the argument is one of the recognised types, suitable to have a child object of the type handled by this action, this method should return true. If the parent's type is not suitable or not recognised, the method should return false.

    If isValidParent() returns false and extensions are loaded, the list of contributions is checked to see whether the parent/child relation was allowed declaretively (by updateSelection method). This implementation simply calls:

        CBActionElement element = (CBActionElement)object;
        return getTestEditor().getProviders( element ).getActionHandler().isValidParent( element );
     

    Parameters:
    object -
    Returns:
    boolean

    setTestEditor

    public void setTestEditor(TestEditor editor)
    Parameters:
    editor -

    getInsertPoint

    public int getInsertPoint()
    Returns:
    Returns the insertPoint.

    setInsertPoint

    public void setInsertPoint(int insertPoint)
    Set dynamically by test editor framework as selection in the editor tree changes. The insertion point is an index in the children list, where the new child will be inserted, if user selects Insert->newModelElementAction sequence.

    Clients should not call this method.

    Parameters:
    insertPoint - The insertPoint to set.

    getNewElements

    public ArrayList getNewElements()
    Returns:
    Returns the newElements.

    getMyActionHandler

    public ExtActionHandler getMyActionHandler()

    IBM Rational Performance Tester SDK

    © Copyright IBM Corp. 2012. All rights reserved.