Java Reference
In-Depth Information
we use the provided refresh action by pressing F5, we see that the figure updates
and its location is preserved. If we create a relationship link, the diagram is
refreshed automatically because of the canonical update of the Map itself. We
want the image to automatically update when a subtopic link is created or
removed, and for layout to be invoked when using the palette or an action. As
with most things in GMF, we can solve our problem in many ways.
If we look at our MapCanonicalEditPolicy class, we see the
refreshSemantic() method, which is invoked by our refresh action. The gen-
erated code overrides this method and the isOrphaned() method from
CanonicalConnectionEditPolicy to incorporate knowledge of our map-
ping constraints into the logic. If you look into the code, you'll see that view ele-
ments that have no corresponding semantic element are deleted, while semantic
elements with no view have one created. As soon as a subtopic connection is
made between two Topics , our constraints prompt the deletion of our target
Topic view because its visual ID no longer matches its semantic constraint. We
could override the methods in this EditPolicy and its superclass to transfer the
location of the original view to the updated view. This is feasible but would
require the copy and paste of a lot of code because many of these methods are
marked as final in the runtime.
Another option is to implement our own connection tool used in the palette
that could invoke a delete-and-create-view-command to update our Topic fig-
ure after link creation. This would not solve our problem of switching the view
back when the subtopic link is removed, although it would be a clean way of
creating an updated figure in the same location. This approach is covered in
the UML2 Tools project, which provides actions to toggle alternative notations
of some UML elements, such as Interface. Specifically, take a look at the
ChangeNotationAction class, in the org.eclipse.uml2.diagram.common
plug-in. There, the original view element's location is passed to the create-view-
request, to avoid the positioning problem.
We know that the view needs to change when an element is added or
removed from a Topic 's subtopics reference list, so we can watch for events on
this feature and invoke a refresh on our MapCanonicalEditPolicy .
Furthermore, we can add code to the EditPolicy to invoke a diagram layout
when subtopics are added, or when Topics are added or removed from the dia-
gram.
In each of our Topic EditParts , we override the handleEvent
Notification() method and invoke the refresh() method on our
MapCanonicalEditPolicy class, to let the generated code update the view on
our Topic elements.
Search WWH ::




Custom Search