Search in sources :

Example 1 with InternalXSDMultiPageEditor

use of org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor in project webtools.sourceediting by eclipse.

the class OpenInNewEditor method openExternalFiles.

public static void openExternalFiles(IWorkbenchPage page, String schemaLocation, XSDConcreteComponent fComponent) {
    // Assert not null
    if (schemaLocation == null)
        return;
    IPath schemaPath = new Path(schemaLocation);
    // So as a result of bug 221421, we will just use the schemaLocation.
    if (!schemaLocation.startsWith("http")) {
        schemaPath = new Path(URIHelper.removeProtocol(schemaLocation));
    }
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(schemaPath);
    URI schemaURI = URI.create(schemaLocation);
    if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
        try {
            IEditorPart editorPart = null;
            IEditorReference[] refs = page.getEditorReferences();
            int length = refs.length;
            // Need to find if an editor on that schema has already been opened
            for (int i = 0; i < length; i++) {
                IEditorInput input = refs[i].getEditorInput();
                if (input instanceof FileStoreEditorInput) {
                    URI uri = ((FileStoreEditorInput) input).getURI();
                    if (uri.equals(schemaURI)) {
                        editorPart = refs[i].getEditor(true);
                        page.activate(refs[i].getPart(true));
                        break;
                    }
                }
            }
            if (editorPart == null) {
                editorPart = IDE.openEditorOnFileStore(page, fileStore);
            }
            if (editorPart instanceof InternalXSDMultiPageEditor) {
                InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
                xsdEditor.openOnGlobalReference(fComponent);
            }
        } catch (PartInitException pie) {
        }
    } else {
        try {
            if (schemaLocation.startsWith("http")) {
                try {
                    IEditorPart editorPart = null;
                    IEditorReference[] refs = page.getEditorReferences();
                    int length = refs.length;
                    // Need to find if an editor on that schema has already been opened
                    for (int i = 0; i < length; i++) {
                        IEditorInput input = refs[i].getEditorInput();
                        if (input instanceof ADTReadOnlyFileEditorInput) {
                            ADTReadOnlyFileEditorInput readOnlyEditorInput = (ADTReadOnlyFileEditorInput) input;
                            if (readOnlyEditorInput.getUrlString().equals(schemaLocation) && XSDEditorPlugin.EDITOR_ID.equals(readOnlyEditorInput.getEditorID())) {
                                editorPart = refs[i].getEditor(true);
                                page.activate(refs[i].getPart(true));
                                break;
                            }
                        }
                    }
                    if (editorPart == null) {
                        ADTReadOnlyFileEditorInput readOnlyStorageEditorInput = new ADTReadOnlyFileEditorInput(schemaLocation);
                        readOnlyStorageEditorInput.setEditorID(XSDEditorPlugin.EDITOR_ID);
                        // $NON-NLS-1$
                        editorPart = page.openEditor(readOnlyStorageEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
                    }
                    if (editorPart instanceof InternalXSDMultiPageEditor) {
                        InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
                        xsdEditor.openOnGlobalReference(fComponent);
                    }
                } catch (PartInitException pie) {
                }
            } else {
                FileStoreEditorInput xsdFileStoreEditorInput = new FileStoreEditorInput(fileStore);
                // $NON-NLS-1$
                page.openEditor(xsdFileStoreEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
            }
        } catch (PartInitException e) {
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ADTReadOnlyFileEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.ADTReadOnlyFileEditorInput) IPath(org.eclipse.core.runtime.IPath) InternalXSDMultiPageEditor(org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) IEditorReference(org.eclipse.ui.IEditorReference) IFileStore(org.eclipse.core.filesystem.IFileStore) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) ADTFileStoreEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.ADTFileStoreEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 2 with InternalXSDMultiPageEditor

use of org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor in project webtools.sourceediting by eclipse.

the class OpenInNewEditor method openInlineSchema.

public static void openInlineSchema(IEditorInput editorInput, XSDConcreteComponent xsdComponent, XSDSchema schema, String editorName) {
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = null;
    if (workbenchWindow != null) {
        page = workbenchWindow.getActivePage();
    }
    boolean isWorkspaceFile = false;
    String schemaLocation = schema.getSchemaLocation();
    String workspaceFileLocation = URIHelper.removePlatformResourceProtocol(schemaLocation);
    IPath workspaceFilePath = new Path(workspaceFileLocation);
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(workspaceFilePath);
    if (page != null && file != null && file.exists()) {
        isWorkspaceFile = true;
    }
    if (isWorkspaceFile) {
        try {
            IEditorPart editorPart = null;
            XSDFileEditorInput xsdFileEditorInput = new XSDFileEditorInput(file, schema);
            xsdFileEditorInput.setEditorName(editorName);
            IEditorReference[] refs = page.getEditorReferences();
            int length = refs.length;
            for (int i = 0; i < length; i++) {
                IEditorInput input = refs[i].getEditorInput();
                if (input instanceof XSDFileEditorInput) {
                    IFile aFile = ((XSDFileEditorInput) input).getFile();
                    if (aFile.getFullPath().equals(file.getFullPath())) {
                        if (((XSDFileEditorInput) input).getSchema() == schema) {
                            editorPart = refs[i].getEditor(true);
                            page.activate(refs[i].getPart(true));
                            break;
                        }
                    }
                }
            }
            if (editorPart == null) {
                // $NON-NLS-1$
                editorPart = page.openEditor(xsdFileEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
            }
            if (editorPart instanceof InternalXSDMultiPageEditor) {
                InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
                xsdEditor.openOnGlobalReference(xsdComponent);
            }
        } catch (PartInitException pie) {
        }
    } else {
        if (schemaLocation != null && !schemaLocation.startsWith("http")) {
            String fileLocation = null;
            // 
            if (java.io.File.separatorChar == '/') {
                fileLocation = "/" + URIHelper.removePlatformResourceProtocol(schemaLocation);
            } else // Windows
            {
                fileLocation = URIHelper.removeProtocol(schemaLocation);
            }
            IPath schemaPath = new Path(fileLocation);
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(schemaPath);
            if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
                try {
                    ADTFileStoreEditorInput xsdFileStoreEditorInput = new ADTFileStoreEditorInput(fileStore, schema);
                    xsdFileStoreEditorInput.setEditorName(editorName);
                    IEditorPart editorPart = null;
                    IEditorReference[] refs = page.getEditorReferences();
                    int length = refs.length;
                    for (int i = 0; i < length; i++) {
                        IEditorInput input = refs[i].getEditorInput();
                        if (input instanceof ADTFileStoreEditorInput) {
                            URI uri = ((ADTFileStoreEditorInput) input).getURI();
                            if (uri.equals(xsdFileStoreEditorInput.getURI()) && ((ADTFileStoreEditorInput) input).getSchema() == xsdFileStoreEditorInput.getSchema()) {
                                editorPart = refs[i].getEditor(true);
                                page.activate(refs[i].getPart(true));
                                break;
                            }
                        }
                    }
                    if (page != null && editorPart == null) {
                        // $NON-NLS-1$
                        editorPart = page.openEditor(xsdFileStoreEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
                    }
                    if (editorPart instanceof InternalXSDMultiPageEditor) {
                        InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
                        xsdEditor.openOnGlobalReference(xsdComponent);
                    }
                } catch (PartInitException pie) {
                }
            }
        } else {
            try {
                IEditorPart editorPart = null;
                IEditorReference[] refs = page.getEditorReferences();
                int length = refs.length;
                // Need to find if an editor on that schema has already been opened
                for (int i = 0; i < length; i++) {
                    IEditorInput input = refs[i].getEditorInput();
                    if (input instanceof ADTReadOnlyFileEditorInput) {
                        ADTReadOnlyFileEditorInput xsdFileStorageEditorInput = (ADTReadOnlyFileEditorInput) input;
                        if (xsdFileStorageEditorInput.getUrlString().equals(schemaLocation) && xsdFileStorageEditorInput.getEditorID().equals(XSDEditorPlugin.EDITOR_ID)) {
                            editorPart = refs[i].getEditor(true);
                            page.activate(refs[i].getPart(true));
                            break;
                        }
                    }
                }
                if (editorPart == null) {
                    ADTReadOnlyFileEditorInput xsdFileStorageEditorInput = new ADTReadOnlyFileEditorInput(schemaLocation);
                    xsdFileStorageEditorInput.setSchema(schema);
                    xsdFileStorageEditorInput.setEditorName(editorName);
                    xsdFileStorageEditorInput.setEditorID(XSDEditorPlugin.EDITOR_ID);
                    editorPart = page.openEditor(xsdFileStorageEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
                }
                if (editorPart instanceof InternalXSDMultiPageEditor) {
                    InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
                    xsdEditor.openOnGlobalReference(xsdComponent);
                }
            } catch (PartInitException pie) {
            }
        }
        return;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ADTReadOnlyFileEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.ADTReadOnlyFileEditorInput) IPath(org.eclipse.core.runtime.IPath) InternalXSDMultiPageEditor(org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) IEditorReference(org.eclipse.ui.IEditorReference) XSDFileEditorInput(org.eclipse.wst.xsd.ui.internal.editor.XSDFileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFileStore(org.eclipse.core.filesystem.IFileStore) PartInitException(org.eclipse.ui.PartInitException) ADTFileStoreEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.ADTFileStoreEditorInput) IEditorInput(org.eclipse.ui.IEditorInput)

Example 3 with InternalXSDMultiPageEditor

use of org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor in project webtools.sourceediting by eclipse.

the class OpenInNewEditor method openWorkspaceFile.

public static void openWorkspaceFile(IWorkbenchPage page, String schemaLocation, XSDConcreteComponent xsdComponent) {
    IPath schemaPath = new Path(schemaLocation);
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
    if (page != null && file != null && file.exists()) {
        try {
            IEditorPart editorPart = IDE.openEditor(page, file, true);
            if (editorPart instanceof InternalXSDMultiPageEditor) {
                InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
                xsdEditor.openOnGlobalReference(xsdComponent);
            }
        } catch (PartInitException pie) {
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) InternalXSDMultiPageEditor(org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 4 with InternalXSDMultiPageEditor

use of org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor in project webtools.sourceediting by eclipse.

the class OpenOnSelectionHelper method revealObject.

protected boolean revealObject(final XSDConcreteComponent component) {
    if (component.getRootContainer().equals(xsdSchema)) {
        Node element = component.getElement();
        if (element instanceof IndexedRegion) {
            IndexedRegion indexNode = (IndexedRegion) element;
            textEditor.getTextViewer().setRangeIndication(indexNode.getStartOffset(), indexNode.getEndOffset() - indexNode.getStartOffset(), true);
            return true;
        }
        return false;
    } else {
        lastResult = false;
        if (component.getSchema() != null) {
            String schemaLocation = URIHelper.removePlatformResourceProtocol(component.getSchema().getSchemaLocation());
            IPath schemaPath = new Path(schemaLocation);
            final IFile schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
            Display.getDefault().syncExec(new Runnable() {

                /**
                 * @see java.lang.Runnable#run()
                 */
                public void run() {
                    final IWorkbenchWindow workbenchWindow = XSDEditorPlugin.getPlugin().getWorkbench().getActiveWorkbenchWindow();
                    if (workbenchWindow != null) {
                        try {
                            IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), XSDEditorPlugin.PLUGIN_ID);
                            if (editorPart instanceof InternalXSDMultiPageEditor) {
                                ((InternalXSDMultiPageEditor) editorPart).openOnGlobalReference(component);
                                lastResult = true;
                            }
                        } catch (PartInitException initEx) {
                        }
                    }
                }
            });
        }
        return lastResult;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Node(org.w3c.dom.Node) FileEditorInput(org.eclipse.ui.part.FileEditorInput) InternalXSDMultiPageEditor(org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 5 with InternalXSDMultiPageEditor

use of org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor in project webtools.sourceediting by eclipse.

the class XSDModelDelayedReconciler method shouldDelay.

/**
 * Determines if the delayed reconciler should kick in.
 */
public boolean shouldDelay(XSDSchema schema) {
    boolean shouldDelay = false;
    // The delayed reconciler should not be used when the editor is in graphical editing mode.
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
    IEditorPart editorPart = workbenchPage != null ? workbenchPage.getActiveEditor() : null;
    if (editorPart != null && editorPart instanceof InternalXSDMultiPageEditor) {
        InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
        shouldDelay = xsdEditor.isSourcePageActive();
    }
    return shouldDelay;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) InternalXSDMultiPageEditor(org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Aggregations

IEditorPart (org.eclipse.ui.IEditorPart)6 InternalXSDMultiPageEditor (org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor)6 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 PartInitException (org.eclipse.ui.PartInitException)5 IFile (org.eclipse.core.resources.IFile)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 IEditorInput (org.eclipse.ui.IEditorInput)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 ADTReadOnlyFileEditorInput (org.eclipse.wst.xsd.ui.internal.adt.editor.ADTReadOnlyFileEditorInput)3 URI (java.net.URI)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IEditorReference (org.eclipse.ui.IEditorReference)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 ADTFileStoreEditorInput (org.eclipse.wst.xsd.ui.internal.adt.editor.ADTFileStoreEditorInput)2 XSDFileEditorInput (org.eclipse.wst.xsd.ui.internal.editor.XSDFileEditorInput)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)1 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1