Search in sources :

Example 1 with DiagramEditor

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;
}
Also used : DiagramEditor(org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) EObject(org.eclipse.emf.ecore.EObject) EditPart(org.eclipse.gef.EditPart) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) View(org.eclipse.gmf.runtime.notation.View) Map(java.util.Map) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Example 2 with DiagramEditor

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);
        }
    }
}
Also used : DiagramEditor(org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor) GraphicalViewer(org.eclipse.gef.GraphicalViewer) EObject(org.eclipse.emf.ecore.EObject) EditPart(org.eclipse.gef.EditPart) IEditorPart(org.eclipse.ui.IEditorPart) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) View(org.eclipse.gmf.runtime.notation.View) URIEditorInput(org.eclipse.emf.common.ui.URIEditorInput) IEditorInput(org.eclipse.ui.IEditorInput)

Example 3 with DiagramEditor

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();
    }
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) DiagramEditor(org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor) TextAwareLabelEditPart(org.yakindu.base.gmf.runtime.editparts.TextAwareLabelEditPart) IXtextAwareEditPart(org.yakindu.base.xtext.utils.gmf.directedit.IXtextAwareEditPart) EditPart(org.eclipse.gef.EditPart) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) View(org.eclipse.gmf.runtime.notation.View) Diagram(org.eclipse.gmf.runtime.notation.Diagram) CoreException(org.eclipse.core.runtime.CoreException) DirectEditRequest(org.eclipse.gef.requests.DirectEditRequest) TextAwareLabelEditPart(org.yakindu.base.gmf.runtime.editparts.TextAwareLabelEditPart) EObject(org.eclipse.emf.ecore.EObject) IXtextAwareEditPart(org.yakindu.base.xtext.utils.gmf.directedit.IXtextAwareEditPart) Map(java.util.Map)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)3 EditPart (org.eclipse.gef.EditPart)3 DiagramEditor (org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor)3 View (org.eclipse.gmf.runtime.notation.View)3 Map (java.util.Map)2 Diagram (org.eclipse.gmf.runtime.notation.Diagram)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 URIEditorInput (org.eclipse.emf.common.ui.URIEditorInput)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 GraphicalViewer (org.eclipse.gef.GraphicalViewer)1 DirectEditRequest (org.eclipse.gef.requests.DirectEditRequest)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 IEditorInput (org.eclipse.ui.IEditorInput)1 PartInitException (org.eclipse.ui.PartInitException)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1 TextAwareLabelEditPart (org.yakindu.base.gmf.runtime.editparts.TextAwareLabelEditPart)1 IXtextAwareEditPart (org.yakindu.base.xtext.utils.gmf.directedit.IXtextAwareEditPart)1