Java Reference
In-Depth Information
// here, update view to subtopic
final EditPartViewer viewer = selectedElement.getViewer();
final EditPart ep = (EditPart) mapEditPart.getChildren()
.get(mapEditPart.getChildren().size()-1);
if (ep != null ) {
viewer.setSelection( new StructuredSelection(ep));
viewer.reveal(ep);
Display.getCurrent().syncExec( new Runnable() {
public void run() {
Request der = new Request(RequestConstants.REQ_DIRECT_EDIT);
ep.performRequest(der);
}
});
}
}
public void selectionChanged(IAction action, ISelection selection) {
selectedElement = null ;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection)
selection;
if (structuredSelection.getFirstElement() instanceof
TopicEditPart || structuredSelection.getFirstElement()
instanceof Topic2EditPart) {
selectedElement = (ShapeNodeEditPart)
structuredSelection.getFirstElement();
}
}
}
}
Starting at the bottom with the selectionChanged() method, we set our
selectedElement field to be that of the currently selected Topic . The run()
method of our action class does all the work to create the compound command
for creating our new subtopic and associated link, invoking the diagram layout,
and finally activating the in-place editor. The code is fairly straightforward, aside
from the details of what goes on within the DeferredCreateConnection
ViewAndElementCommand when executed. For this, it's recommended that you
set a breakpoint and follow its execution, if interested, as is the case with much
of the GMF runtime code.
One troubling point of our implementation are the references to
MindmapElementTypes TopicSubtopics_4001 and Topic_2001 . These are
generated visual IDs that are produced by the tooling of GMF and are subject to
change, unfortunately. A better solution here is to create custom templates that
would enable us to generate this action and, therefore, eliminate the possibility
that our custom action code will break after some future change to the generated
diagram code. Section 4.4.5, “ToolTips,” covers the use of custom templates for
diagram generation.
Search WWH ::




Custom Search