org.eclipse.gef.editparts
Class AbstractEditPart
java.lang.Object
org.eclipse.gef.editparts.AbstractEditPart
-
All Implemented Interfaces:
-
EditPart,
RequestConstants
-
Direct Known Subclasses:
-
AbstractGraphicalEditPart,
AbstractTreeEditPart,
RootTreeEditPart
- public abstract class AbstractEditPart
- extends java.lang.Object
- implements
EditPart,
RequestConstants
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 Summary
|
protected java.util.List
|
children
The List of children EditParts |
protected static int
|
FLAG_ACTIVE
This flag is set during
activate() , and reset on
deactivate()
|
protected static int
|
FLAG_FOCUS
This flag indicates that the EditPart has focus. |
protected static int
|
MAX_FLAG
The left-most bit that is reserved by this class for setting flags. |
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
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
|
FLAG_ACTIVE
protected static final int FLAG_ACTIVE
- This flag is set during
activate()
, and reset on
deactivate()
-
See Also:
-
Constant Field Values
FLAG_FOCUS
protected static final int FLAG_FOCUS
- This flag indicates that the EditPart has focus.
-
See Also:
-
Constant Field Values
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:
-
Constant Field Values
children
protected java.util.List children
- The List of children EditParts
AbstractEditPart
public AbstractEditPart()
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:
-
EditPart.activate()
,
deactivate()
activateEditPolicies
protected void activateEditPolicies()
- Activates all EditPolicies installed on this part.
There is no reason to override this method.
-
-
-
See Also:
-
activate()
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:
- The child is added to the
children
List, and its parent is set to
this
-
addChildVisual(EditPart, int)
is called to add the child's visual
-
EditPart.addNotify()
is called on the child.
-
activate()
is called if this part is active
-
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(EditPart, int)
,
removeChild(EditPart)
,
reorderChild(EditPart,int)
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:
-
addChild(EditPart, int)
,
AbstractGraphicalEditPart.removeChildVisual(EditPart)
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:
-
EditPart.addNotify()
createChild
protected
EditPart createChild(java.lang.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:
-
EditPart.installEditPolicy(Object, EditPolicy)
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:
-
EditPart.deactivate()
,
activate()
deactivateEditPolicies
protected void deactivateEditPolicies()
- Deactivates all installed EditPolicies.
-
-
debug
protected final void debug(java.lang.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(java.lang.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:
-
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. 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:
-
showTargetFeedback(Request)
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 java.lang.Object getAdapter(java.lang.Class 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.
-
-
-
See Also:
-
IAdaptable#getAdapter(java.lang.Class)
getChildren
public java.util.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:
-
EditPart.getChildren()
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:
-
EditPart.getCommand(Request)
,
EditPolicy.getCommand(Request)
getEventListeners
protected final java.util.Iterator getEventListeners(java.lang.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(java.lang.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:
-
EditPart.getEditPolicy(Object)
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:
-
setFlag(int,boolean)
getModel
public java.lang.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:
- the primary model object
-
See Also:
-
EditPart.getModel()
getModelChildren
protected java.util.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:
- the parent
-
See Also:
-
EditPart.getParent()
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:
- the
RootEditPart
-
See Also:
-
EditPart.getRoot()
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:
-
EditPart.getSelected()
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:
-
EditPart.getTargetEditPart(Request)
,
EditPolicy.getTargetEditPart(Request)
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
-
See Also:
-
EditPart.getViewer()
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:
-
EditPart.hasFocus()
installEditPolicy
public void installEditPolicy(java.lang.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:
-
EditPart.installEditPolicy(Object, EditPolicy)
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()
- Reserved for future use
-
-
Specified by:
-
isSelectable
in interface
EditPart
-
-
Returns:
- boolean
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:
-
EditPart.performRequest(Request)
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 exising 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:
-
getModelChildren()
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:
-
unregister()
,
EditPartViewer.getVisualPartMap()
,
EditPartViewer.getEditPartRegistry()
registerAccessibility
protected final void registerAccessibility()
- Registers the
AccessibleEditPart
adapter.
-
-
-
See Also:
-
getAccessibleEditPart()
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:
-
EditPartListeners
are notified that the child is being removed
-
deactivate()
is called if the child is active
-
EditPart.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:
-
addChild(EditPart,int)
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:
-
EditPart.removeEditPartListener(EditPartListener)
removeEditPolicy
public void removeEditPolicy(java.lang.Object key)
- No reason to override
-
-
Specified by:
-
removeEditPolicy
in interface
EditPart
-
-
Parameters:
-
key
- the key identifying the EditPolicy to be removed -
See Also:
-
EditPart.removeEditPolicy(Object)
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:
-
EditPart.removeNotify()
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:
-
getFlag(int)
setFocus
public void setFocus(boolean value)
-
Description copied from interface:
EditPart
- Set the focus property to reflect the value in the EditPartViewer. Focus is
determined by the EditPartViewer.
Focus is considered to be part of the selected state, changing this value
will fire
EditPartListener.selectedStateChanged(EditPart)
.
IMPORTANT: This method should only be called by the EditPartViewer.
-
-
Specified by:
-
setFocus
in interface
EditPart
-
-
Parameters:
-
value
- boolean indicating if this part has focus -
See Also:
-
EditPart.setFocus(boolean)
setModel
public void setModel(java.lang.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:
-
EditPart.setModel(Object)
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:
-
EditPart.setParent(EditPart)
setSelected
public void setSelected(int value)
- sets the selected state for 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
-
-
Parameters:
-
value
- the selected value -
See Also:
-
SelectionEditPolicy
,
EditPartListener.selectedStateChanged(EditPart)
,
EditPart.setSelected(int)
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:
-
EditPolicy.showSourceFeedback(Request)
,
EditPart.showSourceFeedback(Request)
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:
-
EditPolicy.showTargetFeedback(Request)
,
EditPart.showTargetFeedback(Request)
toString
public java.lang.String toString()
- Describes this EditPart for developmental debugging
purposes.
-
-
-
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:
-
EditPart.understandsRequest(Request)
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.
-
-
Copyright (c) IBM Corp. and others 2000, 2007. All Rights Reserved.