GEF v2.0

org.eclipse.gef.editparts
Class AbstractEditPart

java.lang.Object
  |
  +--org.eclipse.gef.editparts.AbstractEditPart
All Implemented Interfaces:
EditPart, IAdaptable, 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.

Indicates methods that are commonly overridden or even abstract
These methods might be overridden. Especially if you were extending this class directly.
Should rarely be overridden.
Essentially "internal" and should never be overridden.

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

AbstractEditPart provides support for, but does not require the usage of:


Inner Class Summary
protected static class AbstractEditPart.EditPolicyIterator
          Iterates over a List of EditPolcies, skipping any null values encountered.
 
Field Summary
protected  List children
           
protected  EventListenerList eventListeners
          Deprecated. do not reference, call getEventListeners(Class) instead.
protected static int FLAG_ACTIVE
           
protected static int FLAG_FOCUS
           
protected static int FLAG_INITIALIZED
           
protected static int MAX_FLAG
          The highest bit used as a bitmask in this class.
 
Fields inherited from interface org.eclipse.gef.EditPart
SELECTED, SELECTED_NONE, SELECTED_PRIMARY
 
Fields inherited from interface org.eclipse.gef.RequestConstants
REQ_ADD, REQ_ALIGN, REQ_ALIGN_CHILD, REQ_ALIGN_CHILDREN, REQ_ANCESTOR_DELETED, REQ_CONNECTION_END, REQ_CONNECTION_START, REQ_CREATE, REQ_CREATE_BENDPOINT, REQ_DELETE, REQ_DELETE_BENDPOINT, REQ_DELETE_DEPENDANT, REQ_DIRECT_EDIT, REQ_MOVE, REQ_MOVE_BENDPOINT, REQ_MOVE_CHILD, REQ_MOVE_CHILDREN, REQ_ORPHAN, REQ_ORPHAN_CHILDREN, REQ_RECONNECT_END, REQ_RECONNECT_SOURCE, REQ_RECONNECT_START, REQ_RECONNECT_TARGET, REQ_RESIZE, REQ_RESIZE_CHILD, REQ_RESIZE_CHILDREN, REQ_SELECTION, REQ_SELECTION_HOVER, REQ_SOURCE_DELETED, REQ_TARGET_DELETED
 
Constructor Summary
AbstractEditPart()
           
 
Method Summary
 void activate()
           Initializes or reactivates this part and hooks any needed listeners.
protected  void activateEditPolicies()
           Activates all EditPolicies.
protected  void addChild(EditPart child, int index)
           Adds a child EditPart to this EditPart.
protected abstract  void addChildVisual(EditPart child, int index)
           Performs the actual addition of the child to this EditPart.
 void addEditPartListener(EditPartListener listener)
           Adds an editpart listener.
protected  EditPart createChild(Object model)
           Override to create the child EditPart for the given model object.
protected  ConnectionEditPart createConnection(Object model)
           Creates a ConnectionEditPart for the given model.
protected abstract  void createEditPolicies()
          Creates the initial EditPolicies and reserves slots for dynamic ones.
protected  ConnectionEditPart createOrFindConnection(Object model)
           
 void deactivate()
           Override this method to remove any listeners established in activate(), and ALWAYS call super.deactivate() to ensure that children, etc., are also deactivated.
protected  void deactivateEditPolicies()
           Deactivates all installed EditPolicies.
protected  void debug(String message)
          This method will log the message to GEF's debug system if the corresponding flag for EditParts is set to true.
protected  void debugFeedback(String message)
          This method will log the message to GEF's debug system if the corrseponding flag for FEEDBACK is set to true.
 void dispose()
          Called when the EditPart will no longer be used.
protected  void doInitialize()
          Initializes the entire state of the EditPart.
 void eraseSourceFeedback(Request request)
           Erases source feedback for the given Request.
 void eraseTargetFeedback(Request request)
           Erases target feedback for the given Request.
protected  void fireActivated()
           
protected  void fireChildAdded(EditPart child, int index)
          Notifies listeners that a child has been added.
protected  void fireDeactivated()
           
protected  void fireRemovingChild(EditPart child, int index)
          Notifies listeners prior to removing a child.
protected  void fireSelectionChanged()
          Called when the selected state for this EditPart changes.
protected  AccessibleEditPart getAccessibleEditPart()
           
 Object getAdapter(Class key)
           Returns the adapter of the given type, for example: IPropertySource.
 List getChildren()
           Returns a non-null List containing the children EditParts.
 Command getCommand(Request request)
           Returns null or a command that performs the operation specified by the Request.
 EditPolicy getEditPolicy(Object key)
          Returns null or the EditPolicy installed with the given key.
protected  AbstractEditPart.EditPolicyIterator getEditPolicyIterator()
          Used internally to iterate over the installed EditPolicies.
protected  Iterator getEventListeners(Class clazz)
           
protected  boolean getFlag(int flag)
          Returns the boolean value of the given flag.
 KeyHandler getKeyHandler()
          Returns the KeyHandler for this EditPart or null.
 Object getModel()
           Returns the primary model object for this EditPart.
protected  List getModelChildren()
           Returns a List containing the children model objects.
 EditPart getParent()
          Returns the parent of this editpart.
 RootEditPart getRoot()
          Returns the root EditPart.
 int getSelected()
          Returns the selected state of this EditPart.
 EditPart getTargetEditPart(Request request)
           Returns the EditPart which is the target of the Request.
protected  EditPartViewer getViewer()
          A convenience method which uses the Root to obtain the Viewer.
 boolean hasFocus()
          Returns true if this EditPart has focus.
protected  void initialize()
          Calls doInitialize() if shouldInitialize() returns true.
 void installEditPolicy(Object key, EditPolicy editPolicy)
          Installs the given EditPolicy using the given key or ID.
protected  boolean isActive()
          Returns true if this EditPart is active.
protected  boolean isSelectable()
           
 void performRequest(Request req)
          Performs the specified Request.
 void refresh()
           Refreshes all properties visually displayed by this EditPart.
protected  void refreshChildren()
           Refreshes the set of Children.
protected  void refreshVisuals()
           Refreshes this part's visuals.
protected  void register()
           Registers itself in the viewer's various registries.
protected  void registerAccessibility()
           
protected  void registerModel()
           
protected  void registerVisuals()
           
protected  void removeChild(EditPart child)
           Removes a child EditPart.
protected abstract  void removeChildVisual(EditPart child)
           
 void removeEditPartListener(EditPartListener listener)
           Removes a listener.
 void removeEditPolicy(Object key)
           Uninstalls the edit policy if present.
protected  void reorderChild(EditPart editpart, int index)
           Bubbles and EditPart forward into a lower index than it previously occupied.
protected  void setFlag(int flag, boolean value)
          Sets the value of the given flag to the appropriate value.
 void setFocus(boolean value)
          Tells the EditPart whether it is the focus owner.
 void setModel(Object model)
           Set the primary model object that this EditPart represents.
 void setParent(EditPart parent)
           Sets the parent EditPart.
 void setSelected(int value)
           sets the selected state of this EditPart.
protected  boolean shouldInitialize()
           determines whether doInitialize() should be called.
 void showSourceFeedback(Request request)
           Shows source feedback for the given Request.
 void showTargetFeedback(Request request)
           Shows target feedback for the given Request.
 String toString()
           Describes this EditPart for developmental debugging purposes.
 boolean understandsRequest(Request req)
           Returns true if this EditPart understand the given Request.
protected  void unregister()
           Undoes any registration performed by register().
protected  void unregisterAccessibility()
           
protected  void unregisterModel()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.gef.EditPart
getDragTracker
 

Field Detail

FLAG_INITIALIZED

protected static final int FLAG_INITIALIZED

FLAG_FOCUS

protected static final int FLAG_FOCUS

FLAG_ACTIVE

protected static final int FLAG_ACTIVE

MAX_FLAG

protected static final int MAX_FLAG
The highest bit used as a bitmask in this class. A single integer field is used to store up to 32 boolean values. Subclasses may call setFlag(int, boolean) and getFlag(int) methods with additional bitmasks iff those masks are greater than MAX_FLAG. Example:

static final int MY_FLAG = super.MAX_FLAG << 1;


children

protected List children

eventListeners

protected EventListenerList eventListeners
Deprecated. do not reference, call getEventListeners(Class) instead.

Constructor Detail

AbstractEditPart

public AbstractEditPart()
Method Detail

activate

public void activate()
Initializes or reactivates this part and hooks any needed listeners. This method is commonly overridden to add listeners to the model. Subclasses should always call super.activate(). Activation indicates that the EditPart is realized in an EditPartViewer. deactivate() is guaranteed to be called. Both may be called multiple times.

During activation, and EditPart will generally:

  1. Register itself as an observer to its model
  2. Activate its editpolicies (implemented here)
  3. Activate all associated EditParts managed by it (implemented here)
An EditPart is generally activated by the part that manages it, usually a parent.
Specified by:
activate in interface EditPart
See Also:
deactivate()

activateEditPolicies

protected void activateEditPolicies()
Activates all EditPolicies. There is little reason to override this method.
See Also:
activate()

addChild

protected void addChild(EditPart child,
                        int index)
Adds a child EditPart to this EditPart. If activated, this editpart will activate the child.

Notifies listeners that a child has been added. addChildVisual(EditPart, int) is called to separate the act of performing the add from the act of activation and the firing of notification to listeners. Subclasses should generally override addChildVisual(EditPart, int) instead of this method.

Parameters:
child - The EditPart to add
index - The index
See Also:
addChildVisual(EditPart, int), removeChild(EditPart), reorderChild(EditPart,int)

addChildVisual

protected abstract void addChildVisual(EditPart child,
                                       int index)
Performs the actual addition of the child to this EditPart. Subclasses must supply additional code to update the visuals being used. 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:
addChild(EditPart, int), AbstractGraphicalEditPart.removeChildVisual(EditPart)

addEditPartListener

public void addEditPartListener(EditPartListener listener)
Adds an editpart listener.
Specified by:
addEditPartListener in interface EditPart

createChild

protected EditPart createChild(Object model)
Override to create the child EditPart for the given model object. This method is called from refreshChildren() Subclasses may implement this method in place, or have it call out to some type of EditPart factory associated with their application. This method should be overriden together with getModelChildren().
Parameters:
model - the Child model object
Returns:
The child EditPart
See Also:
getModelChildren()

createConnection

protected ConnectionEditPart createConnection(Object model)
Creates a ConnectionEditPart for the given model. Similar to createChild(Object). called from refreshSourceConnections(), and refreshTargetConnections().
Parameters:
model - the connection model object

createOrFindConnection

protected ConnectionEditPart createOrFindConnection(Object model)

createEditPolicies

protected abstract void createEditPolicies()
Creates the initial EditPolicies and reserves slots for dynamic ones. Should be overridden to install the inital edit policies 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:
doInitialize(), installEditPolicy(Object, EditPolicy)

deactivate

public void deactivate()
Override this method to remove any listeners established in activate(), and ALWAYS call super.deactivate() to ensure that children, etc., are also deactivated. activate() may be called again afterwards.
Specified by:
deactivate in interface EditPart
See Also:
activate()

deactivateEditPolicies

protected void deactivateEditPolicies()
Deactivates all installed EditPolicies.

debug

protected void debug(String message)
This method will log the message to GEF's debug system if the corresponding flag for EditParts is set to true.
Parameters:
message - Message to be passed

debugFeedback

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

dispose

public void dispose()
Description copied from interface: EditPart
Called when the EditPart will no longer be used. The EditPart should perform cleanup that cannot be performed in EditPart.deactivate(), such as unregistering itself from the Viewer.
Specified by:
dispose in interface EditPart

doInitialize

protected void doInitialize()
Initializes the entire state of the EditPart.

eraseSourceFeedback

public void eraseSourceFeedback(Request request)
Erases source feedback for the given Request. By default, this responsibility is delegated to this part's EditPolicies. This method should not be overridden.
Specified by:
eraseSourceFeedback in interface EditPart
Parameters:
request - identifies the type of feedback to erase.
See Also:
showSourceFeedback(Request)

eraseTargetFeedback

public void eraseTargetFeedback(Request request)
Erases target feedback for the given Request. By default, this responsibility is delegated to this part's EditPolicies. This method should not be overridden.
Specified by:
eraseTargetFeedback in interface EditPart
Parameters:
request - Command requesting the erase.
See Also:
showTargetFeedback(Request)

fireActivated

protected void fireActivated()

fireChildAdded

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

fireDeactivated

protected void fireDeactivated()

fireRemovingChild

protected void fireRemovingChild(EditPart child,
                                 int index)
Notifies listeners prior to removing a child.
Parameters:
child - EditPart being removed.
index - Position of the child in children list.

fireSelectionChanged

protected void fireSelectionChanged()
Called when the selected state for this EditPart changes. Notifies to all listeners

getAdapter

public Object getAdapter(Class key)
Returns the adapter of the given type, for example: IPropertySource. If your model implements IPropertySource, or if it is IAdaptable then there is no reason to override this method. Or, if you do not need propertysheet support. EditParts are the objects sent out as selection to other viewers. If you have viewers that require additional adapter types, return them here.
Specified by:
getAdapter in interface IAdaptable
See Also:
IAdaptable

getAccessibleEditPart

protected AccessibleEditPart getAccessibleEditPart()

getChildren

public List getChildren()
Returns a non-null List containing the children EditParts.
Specified by:
getChildren in interface EditPart
Returns:
children EditParts

getCommand

public Command getCommand(Request request)
Returns null or a command that performs the operation specified by the Request. This method should not be overridden. By default, each installed EditPolicy will be given the opportunity to return its contribution, and all contributions will be chained together and returned.
Specified by:
getCommand in interface EditPart
Parameters:
Request - A request describing the command to be created.
See Also:
EditPolicy.getCommand(Request)

getEventListeners

protected Iterator getEventListeners(Class clazz)

getEditPolicy

public EditPolicy getEditPolicy(Object key)
Description copied from interface: EditPart
Returns null or the EditPolicy installed with the given key.
Specified by:
getEditPolicy in interface EditPart

getEditPolicyIterator

protected 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.

getFlag

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

getKeyHandler

public KeyHandler getKeyHandler()
Description copied from interface: EditPart
Returns the KeyHandler for this EditPart or null.
Specified by:
getKeyHandler in interface EditPart

getModel

public Object getModel()
Returns the primary model object for this EditPart.
Specified by:
getModel in interface EditPart

getModelChildren

protected List getModelChildren()
Returns a List containing the children model objects. Iff this EditPart's model is a composite, this method should be overridden to returns its children. refreshChildren() requires that this List be non-null.

getParent

public EditPart getParent()
Description copied from interface: EditPart
Returns the parent of this editpart. This method should only be called internally or by helpers such as edit policies.
Specified by:
getParent in interface EditPart

getRoot

public RootEditPart getRoot()
Description copied from interface: EditPart
Returns the root EditPart. This method should only be called internally or by helpers such as edit policies.
Specified by:
getRoot in interface EditPart

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 edit policies.
Specified by:
getSelected in interface EditPart

getTargetEditPart

public EditPart getTargetEditPart(Request request)
Returns the EditPart which is the target of the Request. This implementation determines the target by delegating to its EditPolicies. An EditPart should not understand any editing requests, instead, editing behavior is added by installing EditPolicies. The first non-null result returned by an EditPolicy is returned. If no EditPolicy understand the request (all EditPolicies return null), this EditPart is not the target, and the request is forwarded to the parent EditPart.
Specified by:
getTargetEditPart in interface EditPart
Parameters:
request - Describes the type of target desired.

getViewer

protected EditPartViewer getViewer()
A convenience method which uses the Root to obtain the Viewer.

hasFocus

public boolean hasFocus()
Description copied from interface: EditPart
Returns true if this EditPart has focus.
Specified by:
hasFocus in interface EditPart

initialize

protected void initialize()
Calls doInitialize() if shouldInitialize() returns true. Sets a flag indicating that initialization has occurred.

installEditPolicy

public void installEditPolicy(Object key,
                              EditPolicy editPolicy)
Installs the given EditPolicy using the given key or ID. Previously installed polciies for the same key are deactivated and overwritten.
Specified by:
installEditPolicy in interface EditPart
Parameters:
key - Identifier for the type of EditPolicy.
editPolicy - the EditPolicy being added.
See Also:
removeEditPolicy(Object)

isActive

protected boolean isActive()
Returns true if this EditPart is active.

isSelectable

protected boolean isSelectable()

performRequest

public void performRequest(Request req)
Description copied from interface: EditPart
Performs the specified Request. This method can be used to send a generic message to an EditPart. It is bad practice to use the API as a way to make changes to the model. Commands should be used to modify the model.
Specified by:
performRequest in interface EditPart

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. This method should only be overridden if the previous four methods are not sufficient.
Specified by:
refresh in interface EditPart

refreshChildren

protected void refreshChildren()
Refreshes the set of Children. This method should not be overridden. createChild(Object) and getModelChildren() should be overridden together.

refreshVisuals

protected void refreshVisuals()
Refreshes this part's visuals. After creating the visuals, they should be initialized and the updated in response to model changes by implementing this method.

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:
createConnection(Object), unregister(), EditPartViewer.getVisualPartMap(), EditPartViewer.getEditPartRegistry()

registerAccessibility

protected void registerAccessibility()

registerModel

protected void registerModel()

registerVisuals

protected void registerVisuals()

removeChild

protected void removeChild(EditPart child)
Removes a child EditPart. Calls removeChildVisual(EditPart) to separate the act of removal from the process of deactivation and notification. dispose() is called in refreshChildren() instead of here, since this method could be used when reordering children. Subclasses would generally override removeChildVisual(EditPart) instead of this method.
Deactivates child.
Fires notification.
Inverse of addChild(EditPart, int)
Parameters:
child - EditPart being removed
See Also:
addChild(EditPart,int)

removeChildVisual

protected abstract void removeChildVisual(EditPart child)

removeEditPartListener

public void removeEditPartListener(EditPartListener listener)
Removes a listener.
Specified by:
removeEditPartListener in interface EditPart

removeEditPolicy

public void removeEditPolicy(Object key)
Uninstalls the edit policy if present.
Specified by:
removeEditPolicy in interface EditPart

reorderChild

protected void reorderChild(EditPart editpart,
                            int index)
Bubbles and EditPart forward into a lower index than it previously occupied. This method is correctly implemented in the provided base classes. This method is called from refreshChildren().
Parameters:
child - EditPart being reordered
index - Position into which it is being shifted

setFlag

protected final void setFlag(int flag,
                             boolean value)
Sets the value of the given flag to the appropriate value.
Parameters:
flag - Flag being set
value - Value of the flag to be set
See Also:
getFlag(int)

setFocus

public void setFocus(boolean value)
Description copied from interface: EditPart
Tells the EditPart whether it is the focus owner. Changes in focus are notified using EditPartListener.selectedStateChanged(EditPart).
Specified by:
setFocus in interface EditPart

setModel

public void setModel(Object model)
Set the primary model object that this EditPart represents. Listeners to the model should be added in {#activate()}, not here. activate() and deactivate() may be called multiple times on an EditPart.
Specified by:
setModel in interface EditPart

setParent

public void setParent(EditPart parent)
Sets the parent EditPart.
Specified by:
setParent in interface EditPart

setSelected

public void setSelected(int value)
sets the selected state of this EditPart. This method should rarely be overridden. Instead, EditPolicies that are selection-aware will listen for notification of this property changing.
Specified by:
setSelected in interface EditPart
See Also:
SelectionHandlesEditPolicy

shouldInitialize

protected boolean shouldInitialize()
determines whether doInitialize() should be called. The provided abstract base classes correctly override this method to ensure that the visuals exists prior to doInitialize().

showSourceFeedback

public void showSourceFeedback(Request request)
Shows source feedback for the given Request. By default, this responsibility is delegated to this part's EditPolicies. This method should not be overridden.
Specified by:
showSourceFeedback in interface EditPart
Parameters:
request - identifies the type of feedback to erase.
See Also:
eraseSourceFeedback(Request)

showTargetFeedback

public void showTargetFeedback(Request request)
Shows target feedback for the given Request. By default, this responsibility is delegated to this part's EditPolicies. This method should not be overridden.
Specified by:
showTargetFeedback in interface EditPart
Parameters:
request - identifies the type of feedback to erase.
See Also:
eraseTargetFeedback(Request)

toString

public String toString()
Describes this EditPart for developmental debugging purposes.
Overrides:
toString in class Object

understandsRequest

public boolean understandsRequest(Request req)
Returns true if this EditPart understand the given Request. By default, this is determined by the installed EditPolicies.
EditParts should not understand any requests directly. ALL editing behavior is to be added by installing one or more EditPolicies into the EditPart.
Specified by:
understandsRequest in interface EditPart
Parameters:
request - identifies the type of feedback to erase.
See Also:
eraseTargetFeedback(Request)

unregister

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

unregisterAccessibility

protected void unregisterAccessibility()

unregisterModel

protected void unregisterModel()

GEF v2.0