Class AbstractEditPart
- All Implemented Interfaces:
IAdaptable
,EditPart
,RequestConstants
- Direct Known Subclasses:
AbstractGraphicalEditPart
,AbstractTreeEditPart
,RootTreeEditPart
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Iterates over aList
of EditPolcies, skipping anynull
values encountered. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe List of children EditPartsprotected static final int
This flag is set duringactivate()
, and reset ondeactivate()
protected static final int
This flag indicates that the EditPart has focus.protected static final int
The left-most bit that is reserved by this class for setting flags.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_CHILDREN, REQ_CLONE, REQ_CONNECTION_END, REQ_CONNECTION_START, REQ_CREATE, REQ_CREATE_BENDPOINT, REQ_DELETE, REQ_DELETE_DEPENDANT, REQ_DIRECT_EDIT, REQ_MOVE, REQ_MOVE_BENDPOINT, REQ_MOVE_CHILDREN, REQ_OPEN, REQ_ORPHAN, REQ_ORPHAN_CHILDREN, REQ_RECONNECT_SOURCE, REQ_RECONNECT_TARGET, REQ_RESIZE, REQ_RESIZE_CHILDREN, REQ_SELECTION, REQ_SELECTION_HOVER
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Activates this EditPart, which in turn activates its children and EditPolicies.protected void
Activates all EditPolicies installed on this part.protected void
Adds a childEditPart
to this EditPart.protected abstract void
addChildVisual
(EditPart child, int index) Performs the addition of the child's visual to this EditPart's Visual.void
addEditPartListener
(EditPartListener listener) Adds an EditPartListener.void
Called after the EditPart has been added to its parent.protected EditPart
createChild
(Object model) Create the childEditPart
for the given model object.protected abstract void
Creates the initial EditPolicies and/or reserves slots for dynamic ones.void
Deactivates this EditPart, and in turn deactivates its children and EditPolicies.protected void
Deactivates all installed EditPolicies.protected final void
Deprecated.in 3.1protected final void
debugFeedback
(String message) Deprecated.in 3.1void
eraseSourceFeedback
(Request request) Erases source feedback for the givenRequest
.void
eraseTargetFeedback
(Request request) Erases target feedback for the givenRequest
.protected void
NotifiesEditPartListeners
that this EditPart has been activated.protected void
fireChildAdded
(EditPart child, int index) NotifiesEditPartListeners
that a child has been added.protected void
NotifiesEditPartListeners
that this EditPart has been deactivated.protected void
fireRemovingChild
(EditPart child, int index) NotifiesEditPartListeners
that a child is being removed.protected void
NotifiesEditPartListeners
that the selection has changed.protected AccessibleEditPart
Returns theAccessibleEditPart
adapter for this EditPart.<T> T
getAdapter
(Class<T> key) Returns the specified adapter if recognized.Returns the List of childrenEditParts
.getCommand
(Request request) Subclasses should rarely extend this method.getEditPolicy
(Object key) protected final Iterable<EditPolicy>
Used internally to iterate over the installed EditPolicies.protected final AbstractEditPart.EditPolicyIterator
Deprecated, for removal: This API element is subject to removal in a future version.use UsegetEditPolicyIterable()
instead.protected final <T> Iterator<T>
getEventListeners
(Class<T> clazz) Returns an iterator for the specified type of listenerprotected <T> Iterable<T>
getEventListenersIterable
(Class<T> listenerType) * Returns an Iterator for the specified type of listenerprotected final boolean
getFlag
(int flag) Returns the boolean value of the given flag.getModel()
Returns the primary model object that this EditPart represents.protected List
Returns aList
containing the children model objects.Returns the parentEditPart
.getRoot()
Returns theRootEditPart
.int
Returns the selected state of this EditPart.getTargetEditPart
(Request request) Returns theEditPart
which is the target of theRequest
.Convenience method for returning theEditPartViewer
for this part.boolean
hasFocus()
Returns true if this EditPart has focus.void
installEditPolicy
(Object key, EditPolicy editPolicy) Installs an EditPolicy for a specified role.boolean
isActive()
returnstrue
if the EditPart is active.boolean
By default, an EditPart is regarded to be selectable.void
performRequest
(Request req) Subclasses should extend this method to handle Requests.void
refresh()
Refreshes all properties visually displayed by this EditPart.protected void
Updates the set of children EditParts so that it is in sync with the model children.protected void
Refreshes this EditPart's visuals.protected void
register()
Registers itself in the viewer's various registries.protected final void
Registers theAccessibleEditPart
adapter.protected void
Registers the model in theEditPartViewer.getEditPartRegistry()
.protected void
Registers the visuals in theEditPartViewer.getVisualPartMap()
.protected void
removeChild
(EditPart child) Removes a childEditPart
.protected abstract void
removeChildVisual
(EditPart child) Removes the child's visual from this EditPart's visual.void
removeEditPartListener
(EditPartListener listener) No reason to overridevoid
removeEditPolicy
(Object key) No reason to overridevoid
Removes all references from theEditPartViewer
to this EditPart.protected void
reorderChild
(EditPart editpart, int index) Moves a childEditPart
into a lower index than it currently occupies.protected final void
setFlag
(int flag, boolean value) Sets the value of the specified flag.void
setFocus
(boolean value) Called byEditPartViewer
to indicate that theEditPart
has gained or lost keyboard focus.void
Set the primary model object that this EditPart represents.void
Sets the parent EditPart.void
setSelected
(int value) Sets the selected state for this EditPart, which may be one of:EditPart.SELECTED_PRIMARY
EditPart.SELECTED
EditPart.SELECTED_NONE
.void
showSourceFeedback
(Request request) Shows or updates source feedback for the givenRequest
.void
showTargetFeedback
(Request request) Shows or updates target feedback for the givenRequest
.toString()
Describes this EditPart for developmental debugging purposes.boolean
Returnstrue
if thisEditPart
understand the givenRequest
.protected void
Undoes any registration performed byregister()
.protected final void
Unregisters theAccessibleEditPart
adapter.protected void
Unregisters the model in theEditPartViewer.getEditPartRegistry()
.protected void
Unregisters the visuals in theEditPartViewer.getVisualPartMap()
.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 Details
-
FLAG_ACTIVE
protected static final int FLAG_ACTIVEThis flag is set duringactivate()
, and reset ondeactivate()
- See Also:
-
FLAG_FOCUS
protected static final int FLAG_FOCUSThis flag indicates that the EditPart has focus.- See Also:
-
MAX_FLAG
protected static final int MAX_FLAGThe 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
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. -
activateEditPolicies
protected void activateEditPolicies()Activates all EditPolicies installed on this part. There is no reason to override this method.- See Also:
-
addChild
Adds a childEditPart
to this EditPart. This method is called fromrefreshChildren()
. The following events occur in the order listed:- The child is added to the
children
List, and its parent is set tothis
addChildVisual(EditPart, int)
is called to add the child's visualEditPart.addNotify()
is called on the child.activate()
is called if this part is activeEditPartListeners
are notified that the child has been added.
Subclasses should implement
addChildVisual(EditPart, int)
.- Parameters:
child
- TheEditPart
to addindex
- The index- See Also:
- The child is added to the
-
addChildVisual
Performs the addition of the child's visual to this EditPart's Visual. The provided subclassesAbstractGraphicalEditPart
andAbstractTreeEditPart
already implement this method correctly, so it is unlikely that this method should be overridden.- Parameters:
child
- The EditPart being addedindex
- The child's position- See Also:
-
addEditPartListener
Adds an EditPartListener.- Specified by:
addEditPartListener
in interfaceEditPart
- 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. -
createChild
Create the childEditPart
for the given model object. This method is called fromrefreshChildren()
.By default, the implementation will delegate to the
EditPartViewer
'sEditPartFactory
. 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 initial 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. -
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 inactivate()
- Specified by:
deactivate
in interfaceEditPart
- See Also:
-
deactivateEditPolicies
protected void deactivateEditPolicies()Deactivates all installed EditPolicies. -
debug
Deprecated.in 3.1This 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
Deprecated.in 3.1This 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
Erases source feedback for the givenRequest
. By default, this responsibility is delegated to this part'sEditPolicies
. 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 interfaceEditPart
- Parameters:
request
- identifies the type of feedback to erase.- See Also:
-
eraseTargetFeedback
Erases target feedback for the givenRequest
. 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 interfaceEditPart
- Parameters:
request
- Command requesting the erase.- See Also:
-
fireActivated
protected void fireActivated()NotifiesEditPartListeners
that this EditPart has been activated. -
fireChildAdded
NotifiesEditPartListeners
that a child has been added.- Parameters:
child
-EditPart
being added as child.index
- Position child is being added into.
-
fireDeactivated
protected void fireDeactivated()NotifiesEditPartListeners
that this EditPart has been deactivated. -
fireRemovingChild
NotifiesEditPartListeners
that a child is being removed.- Parameters:
child
-EditPart
being removed.index
- Position of the child in children list.
-
fireSelectionChanged
protected void fireSelectionChanged()NotifiesEditPartListeners
that the selection has changed. -
getAccessibleEditPart
Returns theAccessibleEditPart
adapter for this EditPart. The same adapter instance must be used throughout the editpart's existence. Each adapter has a unique ID which is registered duringregister()
. Accessibility clients can only refer to this editpart via that ID.- Returns:
null
or an AccessibleEditPart adapter
-
getAdapter
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 interfaceIAdaptable
- See Also:
-
getChildren
Description copied from interface:EditPart
Returns the List of childrenEditParts
. 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 interfaceEditPart
- Returns:
- a
List
of children - See Also:
-
getCommand
Subclasses should rarely extend this method. The default implementation combines the contributions from each installedEditPolicy
. 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 interfaceEditPart
- Parameters:
request
- the Request- Returns:
- a Command
- See Also:
-
getEventListeners
Returns an iterator for the specified type of listener- Parameters:
clazz
- the Listener type over which to iterate- Returns:
- Iterator
-
getEventListenersIterable
* Returns an Iterator for the specified type of listener- Parameters:
listenerType
- the type of listeners to get- Returns:
- an Iterable over the requested listeners
- Since:
- 3.14
-
getEditPolicy
- Specified by:
getEditPolicy
in interfaceEditPart
- Parameters:
key
- the key identifying the EditPolicy- Returns:
null
or the EditPolicy installed with the given key- See Also:
-
getEditPolicyIterator
@Deprecated(since="3.15", forRemoval=true) protected final AbstractEditPart.EditPolicyIterator getEditPolicyIterator()Deprecated, for removal: This API element is subject to removal in a future version.use UsegetEditPolicyIterable()
instead.Used internally to iterate over the installed EditPolicies. While EditPolicy slots may be reserved withnull
, the iterator only returns the non-null ones.- Returns:
- an EditPolicyIterator
-
getEditPolicyIterable
Used internally to iterate over the installed EditPolicies.- Returns:
- an Iterable for the installed EditPolicies
- Since:
- 3.15
-
getFlag
protected final boolean getFlag(int flag) Returns the boolean value of the given flag. Specifically, returnstrue
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
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. -
getModelChildren
Returns aList
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
Description copied from interface:EditPart
Returns the parentEditPart
. This method should only be called internally or by helpers such as EditPolicies. -
getRoot
Description copied from interface:EditPart
Returns theRootEditPart
. 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 interfaceEditPart
- Returns:
null
or theRootEditPart
- 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 interfaceEditPart
- Returns:
- one of:
- See Also:
-
getTargetEditPart
Returns theEditPart
which is the target of theRequest
. 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 interfaceEditPart
- Parameters:
request
- Describes the type of target desired.- Returns:
null
or the targetEditPart
- See Also:
-
getViewer
Description copied from interface:EditPart
Convenience method for returning theEditPartViewer
for this part.- Specified by:
getViewer
in interfaceEditPart
- Returns:
- the
EditPartViewer
ornull
- 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. -
installEditPolicy
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 interfaceEditPart
- Parameters:
key
- an identifier used to key the EditPolicyeditPolicy
- the EditPolicy- See Also:
-
isActive
public boolean isActive()Description copied from interface:EditPart
returnstrue
if the EditPart is active. Editparts are active afterEditPart.activate()
is called, and untilEditPart.deactivate()
is called. -
isSelectable
public boolean isSelectable()By default, an EditPart is regarded to be selectable.- Specified by:
isSelectable
in interfaceEditPart
- Returns:
true
if the receiver can be selected- See Also:
-
performRequest
Subclasses should extend this method to handle Requests. For now, the default implementation does not handle any requests.- Specified by:
performRequest
in interfaceEditPart
- 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 callrefreshChildren()
to update its structural features. It also callsrefreshVisuals()
to update its own displayed properties. Subclasses should extend this method to handle additional types of structural refreshing. -
refreshChildren
protected void refreshChildren()Updates the set of children EditParts so that it is in sync with the model children. This method is called fromrefresh()
, 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 callingremoveChild(EditPart)
andaddChild(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 areremoved
. New models have their EditPartscreated
.This method should not be overridden.
- See Also:
-
refreshVisuals
protected void refreshVisuals()Refreshes this EditPart's visuals. This method is called byrefresh()
, 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 sufficient. -
registerAccessibility
protected final void registerAccessibility()Registers theAccessibleEditPart
adapter.- See Also:
-
registerModel
protected void registerModel()Registers the model in theEditPartViewer.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 theEditPartViewer.getVisualPartMap()
. Subclasses should override this method for the visual part they support.AbstractGraphicalEditPart
andAbstractTreeEditPart
already do this. -
removeChild
Removes a childEditPart
. This method is called fromrefreshChildren()
. The following events occur in the order listed:EditPartListeners
are notified that the child is being removeddeactivate()
is called if the child is activeEditPart.removeNotify()
is called on the child.removeChildVisual(EditPart)
is called to remove the child's visual object.- The child's parent is set to
null
Subclasses should implement
removeChildVisual(EditPart)
.- Parameters:
child
- EditPart being removed- See Also:
-
removeChildVisual
Removes the child's 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
No reason to override- Specified by:
removeEditPartListener
in interfaceEditPart
- Parameters:
listener
- the listener being removed- See Also:
-
removeEditPolicy
No reason to override- Specified by:
removeEditPolicy
in interfaceEditPart
- Parameters:
key
- the key identifying the EditPolicy to be removed- See Also:
-
removeNotify
public void removeNotify()Removes all references from theEditPartViewer
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 interfaceEditPart
- See Also:
-
reorderChild
Moves a childEditPart
into a lower index than it currently occupies. This method is called fromrefreshChildren()
.- Parameters:
editpart
- the child being reorderedindex
- new index for the child
-
setFlag
protected final void setFlag(int flag, boolean value) Sets the value of the specified flag. Flag values are declared as static constants. Subclasses may define additional constants aboveMAX_FLAG
.- Parameters:
flag
- Flag being setvalue
- Value of the flag to be set- See Also:
-
setFocus
public void setFocus(boolean value) Called byEditPartViewer
to indicate that theEditPart
has gained or lost keyboard focus. Focus is considered to be part of the selected state. Therefore, only selectableEditPart
s are able to obtain focus, and the method may thus only be called with a value oftrue
in case the receiver is selectable, i.e.isSelectable()
returnstrue
. The method should rarely be overridden. Instead, EditPolicies that are selection-aware listen for notifications about the change of focus viaEditPartListener.selectedStateChanged(EditPart)
. -
setModel
Set the primary model object that this EditPart represents. This method is used by anEditPartFactory
when creating an EditPart. -
setParent
Sets the parent EditPart. There is no reason to override this method. -
setSelected
public void setSelected(int value) Sets the selected state for this EditPart, which may be one of: As only selectableEditPart
s may get selected, the method may only be called with a selected value ofEditPart.SELECTED
orEditPart.SELECTED_PRIMARY
in case the receiver is selectable, i.e.isSelectable()
returnstrue
. The method should rarely be overridden. Instead, EditPolicies that are selection-aware listen for notifications about the change of selection state viaEditPartListener.selectedStateChanged(EditPart)
.- Specified by:
setSelected
in interfaceEditPart
- Parameters:
value
- the selected value- See Also:
-
showSourceFeedback
Shows or updates source feedback for the givenRequest
. 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 interfaceEditPart
- Parameters:
request
- the Request- See Also:
-
showTargetFeedback
Shows or updates target feedback for the givenRequest
. 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 interfaceEditPart
- Parameters:
request
- the Request- See Also:
-
toString
Describes this EditPart for developmental debugging purposes. -
understandsRequest
Returnstrue
if thisEditPart
understand the givenRequest
. By default, this responsibility is delegated to this part's installed EditPolicies.It is recommended that EditPolicies implement understandsRequest()
- Specified by:
understandsRequest
in interfaceEditPart
- Parameters:
req
- aRequest
describing an operation of some type- Returns:
true
if Request is understood- See Also:
-
unregister
protected void unregister()Undoes any registration performed byregister()
. The provided base classes will correctly unregister their visuals. -
unregisterAccessibility
protected final void unregisterAccessibility()Unregisters theAccessibleEditPart
adapter. -
unregisterModel
protected void unregisterModel()Unregisters the model in theEditPartViewer.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 theEditPartViewer.getVisualPartMap()
. Subclasses should override this method for the visual part they support.AbstractGraphicalEditPart
andAbstractTreeEditPart
already do this.
-