Java Reference
In-Depth Information
underlying command infrastructure. One of the primary benefits of using GMF
is a unified command infrastructure that additionally uses the EMF Transaction
API. Section 10.7, “Command Infrastructure,” covers this in detail.
EditPolicies
EditPart s delegate the handling of editing to EditPolicy classes, which the
createEditPolicies() method invoked upon EditPart creation installs.
EditPolicies handle specific editing tasks and can be reused across different
EditPart s. With the exception of performRequest() , each of the previous
EditPart methods that takes a Request object is delegated to one or more of its
EditPolicies.
As described in the EditPolicy API documentation, an EditPolicy is a
pluggable contribution that implements a portion of an EditPart 's behavior.
EditPolicies contribute to the overall editing behavior of an EditPart . Editing
behavior is defined as one or more of the following: command creation, feedback
management, and delegation/forwarding by collecting contributions from other
EditPart s.
In response to a given Request , an EditPolicy can create a derived
Request and forward it to other EditPart s. For example, during the deletion
of a composite EditPart , that composite can consult its children for contribu-
tions to the delete command. Then if the children have any additional work to
do, they return additional commands to be executed.
EditPolicies should be used to determine an EditPart 's editing capabilities.
Although it is possible to implement an EditPart so that it handles all editing
responsibility, using EditPolicies is more flexible and object oriented. Using poli-
cies, you can select the editing behavior for an EditPart without being bound
to its class hierarchy, improving code reuse and simplifying code management.
GMF adds the concept of an EditPolicy provider service, where edit policies
can be contributed to an existing diagram for extensibility.
When EditPolicies are installed, they are assigned a role. Roles are simply a
key, with several roles provided as constants in the org.eclipse.gef.
EditPolicy interface. Some examples are CONNECTION_ROLE , CONTAINER_
ROLE , LAYOUT_ROLE , NODE_ROLE , CONNECTION_ENDPOINTS_ROLE , and
COMPONENT_ROLE . Roles become important when an EditPart needs to sub-
stitute policies, and using them is generally good practice. Several EditPolicies are
provided by default in GEF, although you can write many others to handle your
particular editing functionality.
Following is the createEditPolicies() method found in the Logic
DiagramEditPart class, where several provided roles are used in addition to a
custom Snap Feedback role and policy.
Search WWH ::




Custom Search