Java Reference
In-Depth Information
Consuming CreateRequests
The target
EditPart
is responsible for showing feedback and returning the com-
mand for creation. GEF provides two types of policies for handling creation. One
type of policy is specific to the view in which creation occurs, either graphical or
tree based. This edit policy corresponds to either the
LAYOUT_ROLE
or the
TREE_CONTAINER_ROLE
.
The other type of edit policy is specific to only the model, in case applica-
tions want to separate the portion that is shared between graphical and non-
graphical creation. In most cases, any kind of shared logic is in the command
implementations, making this type of policy unnecessary.
A
LayoutEditPolicy
handles the process of creation based on the con-
tainer's layout manager. For example, if
XYLayout
is being used, the resulting
Command
needs to associate an (x, y, w, h) constraint with the created child.
Layouts that don't use constraints require that the index of the drop location be
determined. GEF provides abstract policies for the basic layout types.
The
TreeContainerEditPolicy
supports creation in a tree-based viewer.
The policy is responsible for determining the index of creation and showing
feedback.
The
PasteTemplateAction
can create objects without requiring the
mouse. This is important for accessibility. The
CopyTemplateAction
is added
to the palette. When the user invokes this action, an internal mechanism copies
the transfer so that it can be pasted in a viewer. When the paste occurs,
the
PasteTemplateAction
retrieves the template object, constructs a
CreateRequest
, and sends it to the selected
EditPart
. The mouse location is
not available in this interaction. Paste is enabled only when the selection is
exactly one
EditPart
.
When a creation command is redone, it must restore the original child that
was created the first time it was executed. If it creates a new object, subsequent
commands will fail upon redo when they try to modify the originally created
child.
Creation Sequence
Using sequence diagrams, let's look at the sequence of events that occurs when
the creation tool moves over the diagram surface using the mouse in GEF.
As you can see in Figure 9-14, as the mouse moves over the diagram, obtain-
ing a command includes passing a request to the
EditPart
, which queries its
EditPolicies. The request obtains a new
object from its factory, im
plying that a new
model object is created and loaded into the creation tool as it is moved over the
Search WWH ::
Custom Search