use of org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor in project statecharts by Yakindu.
the class SCTFileEditorOpener method open.
@Override
public IEditorPart open(URI uri, boolean select) {
try {
IFile fileToOpen = toFile(uri);
if (fileToOpen != null) {
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput(fileToOpen), StatechartDiagramEditor.ID);
if (editor instanceof DiagramEditor) {
DiagramEditor diagramEditor = (DiagramEditor) editor;
EObject targetElement = (EObject) diagramEditor.getDiagram().eResource().getEObject(uri.fragment());
if (targetElement == null) {
return editor;
}
View view = DiagramPartitioningUtil.findNotationView(targetElement);
if (view == null) {
return editor;
}
Diagram element = DiagramPartitioningUtil.getDiagramContaining(view.getElement());
diagramEditor = (DiagramEditor) DiagramPartitioningUtil.openEditor(element);
@SuppressWarnings("rawtypes") Map editPartRegistry = diagramEditor.getDiagramGraphicalViewer().getEditPartRegistry();
EditPart targetEditPart = (EditPart) editPartRegistry.get(view);
if (targetEditPart != null) {
DiagramPartitioningUtil.selectElementsInDiagram(diagramEditor, Arrays.asList(new EditPart[] { targetEditPart }));
}
}
return editor;
}
} catch (PartInitException e) {
e.printStackTrace();
}
return null;
}
use of org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor in project statecharts by Yakindu.
the class NavigatorLinkHelper method activateEditor.
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
if (aSelection == null || aSelection.isEmpty()) {
return;
}
if (false == aSelection.getFirstElement() instanceof DomainNavigatorItem) {
return;
}
DomainNavigatorItem abstractNavigatorItem = (DomainNavigatorItem) aSelection.getFirstElement();
View navigatorView = abstractNavigatorItem.getView();
if (navigatorView == null) {
return;
}
IEditorInput editorInput = getEditorInput(navigatorView.getDiagram());
IEditorPart editor = aPage.findEditor(editorInput);
if (editor == null) {
return;
}
aPage.bringToTop(editor);
if (editor instanceof DiagramEditor) {
DiagramEditor diagramEditor = (DiagramEditor) editor;
ResourceSet diagramEditorResourceSet = diagramEditor.getEditingDomain().getResourceSet();
EObject selectedView = diagramEditorResourceSet.getEObject(EcoreUtil.getURI(navigatorView), true);
if (selectedView == null) {
return;
}
GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor.getAdapter(GraphicalViewer.class);
EditPart selectedEditPart = (EditPart) graphicalViewer.getEditPartRegistry().get(selectedView);
if (selectedEditPart != null) {
graphicalViewer.select(selectedEditPart);
graphicalViewer.reveal(selectedEditPart);
}
}
}
use of org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor in project statecharts by Yakindu.
the class StatechartMarkerNavigationProvider method doGotoMarker.
@Override
@SuppressWarnings("rawtypes")
protected void doGotoMarker(IMarker marker) {
String elementId = marker.getAttribute(SCTMarkerType.SEMANTIC_ELEMENT_ID, null);
if (elementId == null || !(getEditor() instanceof DiagramEditor)) {
return;
}
DiagramEditor editor = (DiagramEditor) getEditor();
EObject targetElement = (EObject) editor.getDiagram().eResource().getEObject(elementId);
if (targetElement == null) {
return;
}
View view = DiagramPartitioningUtil.findNotationView(targetElement);
if (view == null) {
return;
}
Diagram element = DiagramPartitioningUtil.getDiagramContaining(view.getElement());
editor = (DiagramEditor) DiagramPartitioningUtil.openEditor(element);
Map editPartRegistry = editor.getDiagramGraphicalViewer().getEditPartRegistry();
EditPart targetEditPart = (EditPart) editPartRegistry.get(view);
if (targetEditPart != null) {
if (!targetEditPart.isSelectable())
return;
DiagramPartitioningUtil.selectElementsInDiagram(editor, Arrays.asList(new EditPart[] { targetEditPart }));
}
try {
if (marker.isSubtypeOf(SCTMarkerType.SUPERTYPE)) {
final DirectEditRequest request = new DirectEditRequest();
request.setDirectEditFeature(getEditFeature(targetElement, marker));
List<IGraphicalEditPart> allEditParts = getEditParts(editPartRegistry, EcoreUtil2.eAllContentsAsList(view));
for (IGraphicalEditPart editPart : allEditParts) {
if (editPart instanceof IXtextAwareEditPart || (editPart instanceof TextAwareLabelEditPart) && ((TextAwareLabelEditPart) editPart).getFeature().equals(request.getDirectEditFeature())) {
editPart.performRequest(request);
break;
}
}
}
} catch (CoreException e) {
e.printStackTrace();
}
}
Aggregations