Java Reference
In-Depth Information
Finally, we can add the diagram to a page in our editor. Back in
create
Pages()
, enter the following code and corresponding
RequirementsDiagram
Editor
diagramEditor class attribute:
private
RequirementsDiagramEditor diagramEditor;
public void
createPages() {
// . . .
try
{
int pageIndex;
// . . .
// Create diagram viewer page
diagramEditor =
new
RequirementsDiagramEditor();
pageIndex = addPage(diagramEditor, getEditorInput());
setPageText(pageIndex, "Diagram");
}
catch
(PartInitException e) {
RequirementsEditorPlugin.INSTANCE.log(e);
}
// . . .
}
We need to revisit our
handleContentOutlineSelection()
method to
take into account the diagram page because we want to map the selection to the
proper
EditPart
on the diagram (changes in bold):
public void handleContentOutlineSelection(ISelection selection) {
if (!selection.isEmpty() && selection instanceof
IStructuredSelection) {
List selectedElements = ((IStructuredSelection)
selection).toList();
if (getActiveEditor() == selectionTreeEditorPart) {
// . . .
}
else if (getActiveEditor() == diagramEditor) {
// For diagrams, map to the appropriate EditPart
ArrayList<Object> selectionList = new ArrayList<Object>();
for (Object selectedElement : selectedElements) {
if (selectedElement instanceof EObject) {
String elementID = EMFCoreUtil.getProxyID((EObject)
selectedElement);
selectionList.addAll(
diagramEditor.getDiagramGraphicalViewer()
.findEditPartsForElement(elementID,
IGraphicalEditPart.class));
}
selectionProvider.setSelection(new
StructuredSelection(selectionList));
}
}
else {
// . . .
}
}
}
Search WWH ::
Custom Search