Search in sources :

Example 1 with URIEditorInput

use of org.eclipse.emf.common.ui.URIEditorInput in project statecharts by Yakindu.

the class NavigatorLinkHelper method getEditorInput.

private static IEditorInput getEditorInput(Diagram diagram) {
    Resource diagramResource = diagram.eResource();
    for (Iterator<EObject> it = diagramResource.getContents().iterator(); it.hasNext(); ) {
        EObject nextEObject = (EObject) it.next();
        if (nextEObject == diagram) {
            return new FileEditorInput(WorkspaceSynchronizer.getFile(diagramResource));
        }
        if (nextEObject instanceof Diagram) {
            break;
        }
    }
    URI uri = EcoreUtil.getURI(diagram);
    String editorName = uri.lastSegment() + "#" + diagram.eResource().getContents().indexOf(diagram);
    IEditorInput editorInput = new URIEditorInput(uri, editorName);
    return editorInput;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) URIEditorInput(org.eclipse.emf.common.ui.URIEditorInput) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) URIEditorInput(org.eclipse.emf.common.ui.URIEditorInput) IEditorInput(org.eclipse.ui.IEditorInput) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Example 2 with URIEditorInput

use of org.eclipse.emf.common.ui.URIEditorInput in project statecharts by Yakindu.

the class ActiveEditorTracker method getLastActiveEditorProject.

/**
 * @return The project which contains the file that is open in the last
 *         active editor in the current workbench page.
 */
public static IProject getLastActiveEditorProject() {
    final IEditorPart editor = getLastActiveEditor();
    if (editor == null)
        return null;
    final IEditorInput editorInput = editor.getEditorInput();
    if (editorInput instanceof IFileEditorInput) {
        final IFileEditorInput input = (IFileEditorInput) editorInput;
        return input.getFile().getProject();
    } else if (editorInput instanceof URIEditorInput) {
        final URI uri = ((URIEditorInput) editorInput).getURI();
        if (uri.isPlatformResource()) {
            final String platformString = uri.toPlatformString(true);
            return ResourcesPlugin.getWorkspace().getRoot().findMember(platformString).getProject();
        }
    }
    return null;
}
Also used : IFileEditorInput(org.eclipse.ui.IFileEditorInput) URIEditorInput(org.eclipse.emf.common.ui.URIEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) URI(org.eclipse.emf.common.util.URI) IEditorInput(org.eclipse.ui.IEditorInput) URIEditorInput(org.eclipse.emf.common.ui.URIEditorInput)

Example 3 with URIEditorInput

use of org.eclipse.emf.common.ui.URIEditorInput 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

URIEditorInput (org.eclipse.emf.common.ui.URIEditorInput)3 URI (org.eclipse.emf.common.util.URI)3 Resource (org.eclipse.emf.ecore.resource.Resource)2 Diagram (org.eclipse.gmf.runtime.notation.Diagram)2 IEditorInput (org.eclipse.ui.IEditorInput)2 IFileEditorInput (org.eclipse.ui.IFileEditorInput)2 EObject (org.eclipse.emf.ecore.EObject)1 IDiagramEditorInput (org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1