Search in sources :

Example 6 with XtextReadonlyEditorInput

use of org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput in project dsl-devkit by dsldevkit.

the class PlatformPluginAwareEditorOpener method open.

/**
 * If a platform plugin URI is given, a read-only Xtext editor is opened and returned. {@inheritDoc}
 *
 * @see {@link org.eclipse.emf.common.util.URI#isPlatformPlugin()}
 */
@Override
public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) {
    IEditorPart result = super.open(uri, crossReference, indexInList, select);
    if (result == null && (uri.isPlatformPlugin() || OSGI_RESOURCE_URL_PROTOCOL.equals(uri.scheme()))) {
        final IModelLocation modelLocation = getModelLocation(uri.trimFragment());
        if (modelLocation != null) {
            PlatformPluginStorage storage = new PlatformPluginStorage(modelLocation);
            IEditorInput editorInput = new XtextReadonlyEditorInput(storage);
            IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
            try {
                IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID);
                selectAndReveal(editor, uri, crossReference, indexInList, select);
                return EditorUtils.getXtextEditor(editor);
            } catch (WrappedException e) {
                // $NON-NLS-1$ //$NON-NLS-2$
                LOG.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause());
            } catch (PartInitException partInitException) {
                // $NON-NLS-1$ //$NON-NLS-2$
                LOG.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException);
            }
        }
    }
    return result;
}
Also used : XtextReadonlyEditorInput(org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput) WrappedException(org.eclipse.emf.common.util.WrappedException) IModelLocation(com.avaloq.tools.ddk.check.runtime.configuration.IModelLocation) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 7 with XtextReadonlyEditorInput

use of org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput in project dsl-devkit by dsldevkit.

the class CheckHyperlinkHelper method createHyperlinksByOffset.

@Override
public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) {
    IEditorPart activeEditor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor.getEditorInput() instanceof XtextReadonlyEditorInput) {
        INode crossRefNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(offset, 0));
        if (crossRefNode == null) {
            return;
        }
        EObject crossLinkedEObject = eObjectAtOffsetHelper.getCrossReferencedElement(crossRefNode);
        if (crossLinkedEObject != null && crossLinkedEObject.eClass().getEPackage() != CheckPackage.eINSTANCE) {
            return;
        }
    // if EPackage of referenced object is CheckPackage, try to provide hyperlinks: works for included catalogs
    }
    super.createHyperlinksByOffset(resource, offset, acceptor);
}
Also used : XtextReadonlyEditorInput(org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput) INode(org.eclipse.xtext.nodemodel.INode) TextRegion(org.eclipse.xtext.util.TextRegion) EObject(org.eclipse.emf.ecore.EObject) IEditorPart(org.eclipse.ui.IEditorPart)

Example 8 with XtextReadonlyEditorInput

use of org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput in project xtext-eclipse by eclipse.

the class JavaClassPathResourceForIEditorInputFactoryTest method testBug463258_03b.

@Test(expected = CoreException.class)
public void testBug463258_03b() throws Throwable {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.testlanguage", "//empty")), true, monitor());
    IPackageFragmentRoot root = JarPackageFragmentRootTestUtil.getJarPackageFragmentRoot(file, (JavaProject) project);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage");
    fileInJar.setParent(foo);
    File jarFile = file.getLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());
    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    try {
        factory.createResource(editorInput);
    } catch (WrappedException e) {
        throw e.getCause();
    }
}
Also used : XtextReadonlyEditorInput(org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) WrappedException(org.eclipse.emf.common.util.WrappedException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) File(java.io.File) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IFile(org.eclipse.core.resources.IFile) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test) AbstractWorkbenchTest(org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)

Example 9 with XtextReadonlyEditorInput

use of org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput in project xtext-eclipse by eclipse.

the class JavaClassPathResourceForIEditorInputFactoryTest method testBug463258_01.

@Test
public void testBug463258_01() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/A.testlanguage", "//empty")), true, monitor());
    addJarToClasspath(project, file);
    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("A.testlanguage");
    fileInJar.setParent(foo);
    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    Resource resource = factory.createResource(editorInput);
    assertNotNull(resource);
    resource.load(null);
}
Also used : XtextReadonlyEditorInput(org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) NonJavaResource(org.eclipse.jdt.internal.core.NonJavaResource) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test) AbstractWorkbenchTest(org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)

Aggregations

XtextReadonlyEditorInput (org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput)9 IJavaProject (org.eclipse.jdt.core.IJavaProject)7 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)7 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)7 AbstractWorkbenchTest (org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)7 Test (org.junit.Test)7 JarEntryFile (org.eclipse.jdt.internal.core.JarEntryFile)6 IFile (org.eclipse.core.resources.IFile)5 WrappedException (org.eclipse.emf.common.util.WrappedException)5 TextFile (org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile)5 NonJavaResource (org.eclipse.jdt.internal.core.NonJavaResource)4 File (java.io.File)3 IResource (org.eclipse.core.resources.IResource)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 IOException (java.io.IOException)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IModelLocation (com.avaloq.tools.ddk.check.runtime.configuration.IModelLocation)1 IFolder (org.eclipse.core.resources.IFolder)1 EObject (org.eclipse.emf.ecore.EObject)1 IEditorInput (org.eclipse.ui.IEditorInput)1