Class AbstractEditPart

java.lang.Object
org.eclipse.gef.editparts.AbstractEditPart
All Implemented Interfaces:
IAdaptable, EditPart, RequestConstants
Direct Known Subclasses:
AbstractGraphicalEditPart, AbstractTreeEditPart, RootTreeEditPart

public abstract class AbstractEditPart extends Object implements EditPart, RequestConstants, IAdaptable
The baseline implementation for the EditPart interface.

Since this is the default implementation of an interface, this document deals with proper sub-classing of this implementation. This class is not the API. For documentation on proper usage of the public API, see the documentation for the interface itself: EditPart.

This class assumes no visual representation. Subclasses AbstractGraphicalEditPart and AbstractTreeEditPart add support for Figures and TreeItems respectively.

AbstractEditPart provides support for children. All AbstractEditPart's can potentially be containers for other EditParts.

  • Field Details

    • FLAG_ACTIVE

      protected static final int FLAG_ACTIVE
      This flag is set during activate(), and reset on deactivate()
      See Also:
    • FLAG_FOCUS

      protected static final int FLAG_FOCUS
      This flag indicates that the EditPart has focus.
      See Also:
    • MAX_FLAG

      protected static final int MAX_FLAG
      The left-most bit that is reserved by this class for setting flags. Subclasses may define additional flags starting at (MAX_FLAG << 1).
      See Also:
    • children

      protected List children
      The List of children EditParts
  • Constructor Details

    • AbstractEditPart

      public AbstractEditPart()
  • Method Details

    • activate

      public void activate()
      Activates this EditPart, which in turn activates its children and EditPolicies. Subclasses should extend this method to add listeners to the model. Activation indicates that the EditPart is realized in an EditPartViewer. deactivate() is the inverse, and is eventually called on all EditParts.
      Specified by:
      activate in interface EditPart
      See Also:
    • activateEditPolicies

      protected void activateEditPolicies()
      Activates all EditPolicies installed on this part. There is no reason to override this method.
      See Also:
    • addChild

      protected void addChild(EditPart child, int index)
      Adds a child EditPart to this EditPart. This method is called from refreshChildren(). The following events occur in the order listed:
      1. The child is added to the children List, and its parent is set to this
      2. addChildVisual(EditPart, int) is called to add the child's visual
      3. EditPart.addNotify() is called on the child.
      4. activate() is called if this part is active
      5. EditPartListeners are notified that the child has been added.

      Subclasses should implement addChildVisual(EditPart, int).

      Parameters:
      child - The EditPart to add
      index - The index
      See Also:
    • addChildVisual

      protected abstract void addChildVisual(EditPart child, int index)
      Performs the addition of the child's visual to this EditPart's Visual. The provided subclasses AbstractGraphicalEditPart and AbstractTreeEditPart already implement this method correctly, so it is unlikely that this method should be overridden.
      Parameters:
      child - The EditPart being added
      index - The child's position
      See Also:
    • addEditPartListener

      public void addEditPartListener(EditPartListener listener)
      Adds an EditPartListener.
      Specified by:
      addEditPartListener in interface EditPart
      Parameters:
      listener - the listener
    • addNotify

      public void addNotify()
      Description copied from interface: EditPart
      Called after the EditPart has been added to its parent. This is used to indicate to the EditPart that it should refresh itself for the first time.
      Specified by:
      addNotify in interface EditPart
      See Also:
    • createChild

      protected EditPart createChild(Object model)
      Create the child EditPart for the given model object. This method is called from refreshChildren().

      By default, the implementation will delegate to the EditPartViewer's EditPartFactory. Subclasses may override this method instead of using a Factory.

      Parameters:
      model - the Child model object
      Returns:
      The child EditPart
    • createEditPolicies

      protected abstract void createEditPolicies()
      Creates the initial EditPolicies and/or reserves slots for dynamic ones. Should be implemented to install the inital EditPolicies based on the model's initial state. null can be used to reserve a "slot", should there be some desire to guarantee the ordering of EditPolcies.
      See Also:
    • deactivate

      public void deactivate()
      Deactivates this EditPart, and in turn deactivates its children and EditPolicies. Subclasses should extend this method to remove any listeners established in activate()
      Specified by:
      deactivate in interface EditPart
      See Also:
    • deactivateEditPolicies

      protected void deactivateEditPolicies()
      Deactivates all installed EditPolicies.
    • debug

      protected final void debug(String message)
      Deprecated.
      in 3.1
      This method will log a message to GEF's trace/debug system if the corresponding flag for EditParts is set to true.
      Parameters:
      message - a debug message
    • debugFeedback

      protected final void debugFeedback(String message)
      Deprecated.
      in 3.1
      This method will log the message to GEF's trace/debug system if the corrseponding flag for FEEDBACK is set to true.
      Parameters:
      message - Message to be passed
    • eraseSourceFeedback

      public void eraseSourceFeedback(Request request)
      Erases source feedback for the given Request. By default, this responsibility is delegated to this part's EditPolicies . Subclasses should rarely extend this method.

      It is recommended that feedback be handled by EditPolicies, and not directly by the EditPart.
      Specified by:
      eraseSourceFeedback in interface EditPart
      Parameters:
      request - identifies the type of feedback to erase.
      See Also:
    • eraseTargetFeedback

      public void eraseTargetFeedback(Request request)
      Erases target feedback for the given Request. By default, this responsibility is delegated to this part's EditPolicies. Subclasses should rarely extend this method.

      It is recommended that feedback be handled by EditPolicies, and not directly by the EditPart.
      Specified by:
      eraseTargetFeedback in interface EditPart
      Parameters:
      request - Command requesting the erase.
      See Also:
    • fireActivated

      protected void fireActivated()
      Notifies EditPartListeners that this EditPart has been activated.
    • fireChildAdded

      protected void fireChildAdded(EditPart child, int index)
      Notifies EditPartListeners that a child has been added.
      Parameters:
      child - EditPart being added as child.
      index - Position child is being added into.
    • fireDeactivated

      protected void fireDeactivated()
      Notifies EditPartListeners that this EditPart has been deactivated.
    • fireRemovingChild

      protected void fireRemovingChild(EditPart child, int index)
      Notifies EditPartListeners that a child is being removed.
      Parameters:
      child - EditPart being removed.
      index - Position of the child in children list.
    • fireSelectionChanged

      protected void fireSelectionChanged()
      Notifies EditPartListeners that the selection has changed.
    • getAccessibleEditPart

      protected AccessibleEditPart getAccessibleEditPart()
      Returns the AccessibleEditPart adapter for this EditPart. The same adapter instance must be used throughout the editpart's existance. Each adapter has a unique ID which is registered during register(). Accessibility clients can only refer to this editpart via that ID.
      Returns:
      null or an AccessibleEditPart adapter
    • getAdapter

      public <T> T getAdapter(Class<T> key)
      Returns the specified adapter if recognized. Delegates to the workbench adapter mechanism.

      Additional adapter types may be added in the future. Subclasses should extend this method as needed.

      Specified by:
      getAdapter in interface IAdaptable
      See Also:
    • getChildren

      public List getChildren()
      Description copied from interface: EditPart
      Returns the List of children EditParts. This method should rarely be called, and is only made public so that helper objects of this EditPart, such as EditPolicies, can obtain the children. The returned List may be by reference, and should never be modified.
      Specified by:
      getChildren in interface EditPart
      Returns:
      a List of children
      See Also:
    • getCommand

      public Command getCommand(Request request)
      Subclasses should rarely extend this method. The default implementation combines the contributions from each installed EditPolicy. This method is implemented indirectly using EditPolicies.

      It is recommended that Command creation be handled by EditPolicies, and not directly by the EditPart.
      Specified by:
      getCommand in interface EditPart
      Parameters:
      request - the Request
      Returns:
      a Command
      See Also:
    • getEventListeners

      protected final Iterator getEventListeners(Class clazz)
      Returns an iterator for the specified type of listener
      Parameters:
      clazz - the Listener type over which to iterate
      Returns:
      Iterator
    • getEditPolicy

      public EditPolicy getEditPolicy(Object key)
      Specified by:
      getEditPolicy in interface EditPart
      Parameters:
      key - the key identifying the EditPolicy
      Returns:
      null or the EditPolicy installed with the given key
      See Also:
    • getEditPolicyIterator

      protected final AbstractEditPart.EditPolicyIterator getEditPolicyIterator()
      Used internally to iterate over the installed EditPolicies. While EditPolicy slots may be reserved with null, the iterator only returns the non-null ones.
      Returns:
      an EditPolicyIterator
    • getFlag

      protected final boolean getFlag(int flag)
      Returns the boolean value of the given flag. Specifically, returns true if the bitwise AND of the specified flag and the internal flags field is non-zero.
      Parameters:
      flag - Bitmask indicating which flag to return
      Returns:
      the requested flag's value
      See Also:
    • getModel

      public Object getModel()
      Description copied from interface: EditPart
      Returns the primary model object that this EditPart represents. EditParts may correspond to more than one model object, or even no model object. In practice, the Object returned is used by other EditParts to identify this EditPart. In addition, EditPolicies probably rely on this method to build Commands that operate on the model.
      Specified by:
      getModel in interface EditPart
      Returns:
      null or the primary model object
      See Also:
    • getModelChildren

      protected List getModelChildren()
      Returns a List containing the children model objects. If this EditPart's model is a container, this method should be overridden to returns its children. This is what causes children EditParts to be created.

      Callers must not modify the returned List. Must not return null.

      Returns:
      the List of children
    • getParent

      public EditPart getParent()
      Description copied from interface: EditPart
      Returns the parent EditPart. This method should only be called internally or by helpers such as EditPolicies.
      Specified by:
      getParent in interface EditPart
      Returns:
      null or the parent EditPart
      See Also:
    • getRoot

      public RootEditPart getRoot()
      Description copied from interface: EditPart
      Returns the RootEditPart. This method should only be called internally or by helpers such as edit policies. The root can be used to get the viewer.
      Specified by:
      getRoot in interface EditPart
      Returns:
      null or the RootEditPart
      See Also:
    • getSelected

      public int getSelected()
      Description copied from interface: EditPart
      Returns the selected state of this EditPart. This method should only be called internally or by helpers such as EditPolicies.
      Specified by:
      getSelected in interface EditPart
      Returns:
      one of:
      See Also:
    • getTargetEditPart

      public EditPart getTargetEditPart(Request request)
      Returns the EditPart which is the target of the Request. The default implementation delegates this method to the installed EditPolicies. The first non-null result returned by an EditPolicy is returned. Subclasses should rarely extend this method.

      It is recommended that targeting be handled by EditPolicies, and not directly by the EditPart.
      Specified by:
      getTargetEditPart in interface EditPart
      Parameters:
      request - Describes the type of target desired.
      Returns:
      null or the target EditPart
      See Also:
    • getViewer

      public EditPartViewer getViewer()
      Description copied from interface: EditPart
      Convenience method for returning the EditPartViewer for this part.
      Specified by:
      getViewer in interface EditPart
      Returns:
      the EditPartViewer or null
      See Also:
    • hasFocus

      public boolean hasFocus()
      Description copied from interface: EditPart
      Returns true if this EditPart has focus. The focus EditPart is a property of the EditPartViewer. The Viewer keeps this property in sync with its focus.
      Specified by:
      hasFocus in interface EditPart
      Returns:
      true if the EditPart has focus
      See Also:
    • installEditPolicy

      public void installEditPolicy(Object key, EditPolicy editPolicy)
      Description copied from interface: EditPart
      Installs an EditPolicy for a specified role. A role is is simply an Object used to identify the EditPolicy. An example of a role is layout. EditPolicy.LAYOUT_ROLE is generally used as the key for this EditPolicy. null is a valid value for reserving a location.
      Specified by:
      installEditPolicy in interface EditPart
      Parameters:
      key - an identifier used to key the EditPolicy
      editPolicy - the EditPolicy
      See Also:
    • isActive

      public boolean isActive()
      Description copied from interface: EditPart
      returns true if the EditPart is active. Editparts are active after EditPart.activate() is called, and until EditPart.deactivate() is called.
      Specified by:
      isActive in interface EditPart
      Returns:
      true if this EditPart is active.
    • isSelectable

      public boolean isSelectable()
      By default, an EditPart is regarded to be selectable.
      Specified by:
      isSelectable in interface EditPart
      Returns:
      true if the receiver can be selected
      See Also:
    • performRequest

      public void performRequest(Request req)
      Subclasses should extend this method to handle Requests. For now, the default implementation does not handle any requests.
      Specified by:
      performRequest in interface EditPart
      Parameters:
      req - the request to be performed
      See Also:
    • refresh

      public void refresh()
      Refreshes all properties visually displayed by this EditPart. The default implementation will call refreshChildren() to update its structural features. It also calls refreshVisuals() to update its own displayed properties. Subclasses should extend this method to handle additional types of structural refreshing.
      Specified by:
      refresh in interface EditPart
    • refreshChildren

      protected void refreshChildren()
      Updates the set of children EditParts so that it is in sync with the model children. This method is called from refresh(), and may also be called in response to notification from the model. This method requires linear time to complete. Clients should call this method as few times as possible. Consider also calling removeChild(EditPart) and addChild(EditPart, int) which run in constant time.

      The update is performed by comparing the existing EditParts with the set of model children returned from getModelChildren(). EditParts whose models no longer exist are removed. New models have their EditParts created.

      This method should not be overridden.

      See Also:
    • refreshVisuals

      protected void refreshVisuals()
      Refreshes this EditPart's visuals. This method is called by refresh(), and may also be called in response to notifications from the model. This method does nothing by default. Subclasses may override.
    • register

      protected void register()
      Registers itself in the viewer's various registries. If your EditPart has a 1-to-1 relationship with a visual object and a 1-to-1 relationship with a model object, the default implementation should be sufficent.
      See Also:
    • registerAccessibility

      protected final void registerAccessibility()
      Registers the AccessibleEditPart adapter.
      See Also:
    • registerModel

      protected void registerModel()
      Registers the model in the EditPartViewer.getEditPartRegistry(). Subclasses should only extend this method if they need to register this EditPart in additional ways.
    • registerVisuals

      protected void registerVisuals()
      Registers the visuals in the EditPartViewer.getVisualPartMap(). Subclasses should override this method for the visual part they support. AbstractGraphicalEditPart and AbstractTreeEditPart already do this.
    • removeChild

      protected void removeChild(EditPart child)
      Removes a child EditPart. This method is called from refreshChildren(). The following events occur in the order listed:
      1. EditPartListeners are notified that the child is being removed
      2. deactivate() is called if the child is active
      3. EditPart.removeNotify() is called on the child.
      4. removeChildVisual(EditPart) is called to remove the child's visual object.
      5. The child's parent is set to null

      Subclasses should implement removeChildVisual(EditPart).

      Parameters:
      child - EditPart being removed
      See Also:
    • removeChildVisual

      protected abstract void removeChildVisual(EditPart child)
      Removes the childs visual from this EditPart's visual. Subclasses should implement this method to support the visual type they introduce, such as Figures or TreeItems.
      Parameters:
      child - the child EditPart
    • removeEditPartListener

      public void removeEditPartListener(EditPartListener listener)
      No reason to override
      Specified by:
      removeEditPartListener in interface EditPart
      Parameters:
      listener - the listener being removed
      See Also:
    • removeEditPolicy

      public void removeEditPolicy(Object key)
      No reason to override
      Specified by:
      removeEditPolicy in interface EditPart
      Parameters:
      key - the key identifying the EditPolicy to be removed
      See Also:
    • removeNotify

      public void removeNotify()
      Removes all references from the EditPartViewer to this EditPart. This includes:
      • deselecting this EditPart if selected
      • setting the Viewer's focus to null if this EditPart has focus
      • unregister() this EditPart

      In addition, removeNotify() is called recursively on all children EditParts. Subclasses should extend this method to perform any additional cleanup.

      Specified by:
      removeNotify in interface EditPart
      See Also:
    • reorderChild

      protected void reorderChild(EditPart editpart, int index)
      Moves a child EditPart into a lower index than it currently occupies. This method is called from refreshChildren().
      Parameters:
      editpart - the child being reordered
      index - new index for the child
    • setFlag

      protected final void setFlag(int flag, boolean value)
      Sets the value of the specified flag. Flag values are decalared as static constants. Subclasses may define additional constants above MAX_FLAG.
      Parameters:
      flag - Flag being set
      value - Value of the flag to be set
      See Also:
    • setFocus

      public void setFocus(boolean value)
      Called by EditPartViewer to indicate that the EditPart has gained or lost keyboard focus. Focus is considered to be part of the selected state. Therefore, only selectable EditParts are able to obtain focus, and the method may thus only be called with a value of true in case the receiver is selectable, i.e. isSelectable() returns true. The method should rarely be overridden. Instead, EditPolicies that are selection-aware listen for notifications about the change of focus via EditPartListener.selectedStateChanged(EditPart).
      Specified by:
      setFocus in interface EditPart
      Parameters:
      value - boolean indicating if this part has focus
      See Also:
    • setModel

      public void setModel(Object model)
      Set the primary model object that this EditPart represents. This method is used by an EditPartFactory when creating an EditPart.
      Specified by:
      setModel in interface EditPart
      Parameters:
      model - the Model
      See Also:
    • setParent

      public void setParent(EditPart parent)
      Sets the parent EditPart. There is no reason to override this method.
      Specified by:
      setParent in interface EditPart
      Parameters:
      parent - the parent EditPart
      See Also:
    • setSelected

      public void setSelected(int value)
      Sets the selected state for this EditPart, which may be one of: As only selectable EditParts may get selected, the method may only be called with a selected value of EditPart.SELECTED or EditPart.SELECTED_PRIMARY in case the receiver is selectable, i.e. isSelectable() returns true. The method should rarely be overridden. Instead, EditPolicies that are selection-aware listen for notifications about the change of selection state via EditPartListener.selectedStateChanged(EditPart).
      Specified by:
      setSelected in interface EditPart
      Parameters:
      value - the selected value
      See Also:
    • showSourceFeedback

      public void showSourceFeedback(Request request)
      Shows or updates source feedback for the given Request. By default, this responsibility is delegated to this part's EditPolicies. Subclasses should rarely extend this method.

      It is recommended that feedback be handled by EditPolicies, and not directly by the EditPart.
      Specified by:
      showSourceFeedback in interface EditPart
      Parameters:
      request - the Request
      See Also:
    • showTargetFeedback

      public void showTargetFeedback(Request request)
      Shows or updates target feedback for the given Request. By default, this responsibility is delegated to this part's EditPolicies. Subclasses should rarely extend this method.

      It is recommended that feedback be handled by EditPolicies, and not directly by the EditPart.
      Specified by:
      showTargetFeedback in interface EditPart
      Parameters:
      request - the Request
      See Also:
    • toString

      public String toString()
      Describes this EditPart for developmental debugging purposes.
      Overrides:
      toString in class Object
      Returns:
      a description
    • understandsRequest

      public boolean understandsRequest(Request req)
      Returns true if this EditPart understand the given Request. By default, this responsibility is delegated to this part's installed EditPolicies.

      It is recommended that EditPolicies implement understandsRequest()
      Specified by:
      understandsRequest in interface EditPart
      Parameters:
      req - a Request describing an operation of some type
      Returns:
      true if Request is understood
      See Also:
    • unregister

      protected void unregister()
      Undoes any registration performed by register(). The provided base classes will correctly unregister their visuals.
    • unregisterAccessibility

      protected final void unregisterAccessibility()
      Unregisters the AccessibleEditPart adapter.
    • unregisterModel

      protected void unregisterModel()
      Unregisters the model in the EditPartViewer.getEditPartRegistry(). Subclasses should only extend this method if they need to unregister this EditPart in additional ways.
    • unregisterVisuals

      protected void unregisterVisuals()
      Unregisters the visuals in the EditPartViewer.getVisualPartMap(). Subclasses should override this method for the visual part they support. AbstractGraphicalEditPart and AbstractTreeEditPart already do this.