Search in sources :

Example 1 with IDiagramEditorInput

use of org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput in project statecharts by Yakindu.

the class DiagramPartitioningEditor method closeSubdiagramEditors.

protected void closeSubdiagramEditors() {
    if (getDiagram() != null && getDiagram().getElement() instanceof Statechart) {
        List<IEditorReference> refsToClose = new ArrayList<IEditorReference>();
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (workbenchWindow == null)
            return;
        IWorkbenchPage activePage = workbenchWindow.getActivePage();
        if (activePage == null)
            return;
        IEditorReference[] refs = activePage.getEditorReferences();
        for (IEditorReference ref : refs) {
            try {
                if (ref.getEditorInput() instanceof IDiagramEditorInput) {
                    IDiagramEditorInput diagramInput = (IDiagramEditorInput) ref.getEditorInput();
                    if (diagramInput.getDiagram().eResource() == getDiagram().eResource()) {
                        refsToClose.add(ref);
                    }
                }
            } catch (PartInitException e) {
                e.printStackTrace();
            }
        }
        if (refsToClose.size() > 0) {
            boolean close = MessageDialog.openQuestion(activePage.getActivePart().getSite().getShell(), "Close subdiagram editors?", "There are still subdiagram editors open. Do you want to close them?");
            if (close) {
                for (IEditorReference ref : refsToClose) {
                    activePage.closeEditor(ref.getEditor(false), false);
                }
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) ArrayList(java.util.ArrayList) Statechart(org.yakindu.sct.model.sgraph.Statechart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IDiagramEditorInput(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput)

Example 2 with IDiagramEditorInput

use of org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput in project statecharts by Yakindu.

the class DiagramPartitioningDocumentProvider method createElementInfo.

@Override
protected ElementInfo createElementInfo(Object element) throws CoreException {
    ElementInfo info = super.createElementInfo(element);
    if (element instanceof IDiagramEditorInput) {
        Resource eResource = ((IDiagramEditorInput) element).getDiagram().eResource();
        TransactionalEditingDomain sharedDomain = DiagramPartitioningUtil.getSharedDomain();
        if (eResource.isLoaded() && !sharedDomain.isReadOnly(eResource) && eResource.isModified()) {
            info.fCanBeSaved = true;
        }
    }
    return info;
}
Also used : TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) Resource(org.eclipse.emf.ecore.resource.Resource) IDiagramEditorInput(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput)

Example 3 with IDiagramEditorInput

use of org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput in project statecharts by Yakindu.

the class DiagramPartitioningDocumentProvider method setDocumentContent.

@Override
protected boolean setDocumentContent(IDocument document, IEditorInput editorInput) throws CoreException {
    if (editorInput instanceof IDiagramEditorInput) {
        Diagram diagram = ((IDiagramEditorInput) editorInput).getDiagram();
        document.setContent(diagram);
        return true;
    } else if (editorInput instanceof FileEditorInputProxy) {
        setDocumentContentFromStorage(document, ((FileEditorInputProxy) editorInput).getFile());
        return true;
    }
    return super.setDocumentContent(document, editorInput);
}
Also used : IDiagramEditorInput(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput) Diagram(org.eclipse.gmf.runtime.notation.Diagram) FileEditorInputProxy(org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.document.FileEditorInputProxy)

Example 4 with IDiagramEditorInput

use of org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput in project statecharts by Yakindu.

the class DiagramPartitioningUtil method closeSubdiagramEditors.

/**
 * Forces the user to close all opened editors for subdiagrams that are inlined.
 *
 * @return true if all editors were closed, false otherwise
 */
public static boolean closeSubdiagramEditors(State state) {
    Diagram diagram = DiagramPartitioningUtil.getSubDiagram(state);
    if (diagram == null)
        return true;
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorReference[] refs = activePage.getEditorReferences();
    for (IEditorReference ref : refs) {
        try {
            if (ref.getEditorInput() instanceof IDiagramEditorInput) {
                IDiagramEditorInput diagramInput = (IDiagramEditorInput) ref.getEditorInput();
                if (diagramInput.getDiagram().equals(diagram)) {
                    boolean close = MessageDialog.openQuestion(activePage.getActivePart().getSite().getShell(), "Close subdiagram editor?", "The subdiagram is still open in another editor. Do you want to close it?");
                    if (close) {
                        activePage.closeEditor(ref.getEditor(false), false);
                    }
                    return close;
                }
            }
        } catch (PartInitException e) {
            e.printStackTrace();
        }
    }
    return true;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IDiagramEditorInput(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Example 5 with IDiagramEditorInput

use of org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput in project statecharts by Yakindu.

the class ResourceUnloadingTool method getDiagramResource.

private static Resource getDiagramResource(ResourceSet resourceSet, IEditorInput editorInput) {
    Resource diagramResource = null;
    if (editorInput instanceof URIEditorInput) {
        final URI resourceURI = ((URIEditorInput) editorInput).getURI().trimFragment();
        diagramResource = resourceSet.getResource(resourceURI, false);
    } else if (editorInput instanceof IDiagramEditorInput) {
        final Diagram diagram = ((IDiagramEditorInput) editorInput).getDiagram();
        diagramResource = diagram.eResource();
    } else if (editorInput instanceof IFileEditorInput) {
        final URI resourceURI = URI.createPlatformResourceURI(((IFileEditorInput) editorInput).getFile().getFullPath().toString(), true);
        diagramResource = resourceSet.getResource(resourceURI, false);
    }
    return diagramResource;
}
Also used : IFileEditorInput(org.eclipse.ui.IFileEditorInput) URIEditorInput(org.eclipse.emf.common.ui.URIEditorInput) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) IDiagramEditorInput(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Aggregations

IDiagramEditorInput (org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput)5 Diagram (org.eclipse.gmf.runtime.notation.Diagram)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 IEditorReference (org.eclipse.ui.IEditorReference)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 PartInitException (org.eclipse.ui.PartInitException)2 ArrayList (java.util.ArrayList)1 URIEditorInput (org.eclipse.emf.common.ui.URIEditorInput)1 URI (org.eclipse.emf.common.util.URI)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 FileEditorInputProxy (org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.document.FileEditorInputProxy)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 Statechart (org.yakindu.sct.model.sgraph.Statechart)1