Search in sources :

Example 96 with IEditorReference

use of org.eclipse.ui.IEditorReference in project webtools.sourceediting by eclipse.

the class JSPRenameChange method findOpenEditor.

/**
 * <p>Checks if a document is open in an editor and returns it if it is</p>
 *
 * @param jspDoc check to see if this {@link IDocument} is currently open in an editor
 * @return the open {@link ITextEditor} associated with the given {@link IDocument} or
 * <code>null</code> if none can be found.
 */
private static ITextEditor findOpenEditor(IDocument jspDoc) {
    IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
    IWorkbenchWindow w = null;
    for (int i = 0; i < windows.length; i++) {
        w = windows[i];
        IWorkbenchPage page = w.getActivePage();
        if (page != null) {
            IEditorReference[] references = page.getEditorReferences();
            IEditorPart editor = null;
            Object o = null;
            IDocument doc = null;
            for (int j = 0; j < references.length; j++) {
                editor = references[j].getEditor(false);
                if (editor != null) {
                    // editor might not be instantiated
                    // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3764
                    // use adapter to get ITextEditor (for things like
                    // page designer)
                    o = editor.getAdapter(ITextEditor.class);
                    if (o != null && o instanceof ITextEditor) {
                        doc = ((ITextEditor) o).getDocumentProvider().getDocument(editor.getEditorInput());
                        if (doc != null && doc.equals(jspDoc)) {
                            return (ITextEditor) o;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument)

Example 97 with IEditorReference

use of org.eclipse.ui.IEditorReference 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 98 with IEditorReference

use of org.eclipse.ui.IEditorReference 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 99 with IEditorReference

use of org.eclipse.ui.IEditorReference in project webtools.sourceediting by eclipse.

the class ResourceSelectionBlock method filterOpenEditorsByFileExtension.

private String[] filterOpenEditorsByFileExtension(IEditorReference[] editors) {
    String[] paths = new String[editors.length];
    String[] fileExts = getFileExtensions();
    for (int i = 0; i < editors.length; i++) {
        IEditorReference currentEditor = editors[i];
        IEditorPart editorPart = currentEditor.getEditor(true);
        IFile file = (IFile) editorPart.getEditorInput().getAdapter(IFile.class);
        if (file != null) {
            IPath path = file.getFullPath();
            paths[i] = getEditorPath(path, fileExts);
        }
    }
    return paths;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IEditorPart(org.eclipse.ui.IEditorPart)

Example 100 with IEditorReference

use of org.eclipse.ui.IEditorReference in project webtools.sourceediting by eclipse.

the class DelegatingSourceValidatorForXSL method validate.

@Override
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
    super.validate(helper, reporter);
    // validating will refresh the model, so now calculate the overrides.
    // (we only calculate overrides for source validation as we only want to do it for files open in an editor)
    // There follows a very complicated way of creating the required annotations in an editor.
    // TODO resolve this when bug 247222 is sorted
    String[] delta = helper.getURIs();
    if (delta.length > 0) {
        IFile file = getFile(delta[0]);
        // find any files with open editors...
        IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
        for (IWorkbenchWindow workbenchWindow : windows) {
            IWorkbenchPage page = workbenchWindow.getActivePage();
            if (page != null) {
                IEditorReference[] refs = page.findEditors(new FileEditorInput(file), XSL_UI_XSL_EDITOR_ID, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
                // lets hope we only have one XSL editor open on the file, or else we don't know which one started this validation...
                if (refs.length == 1) {
                    XSLEditor editor = (XSLEditor) refs[0].getEditor(false);
                    if (editor != null) {
                        // all this work just to get here...
                        editor.getOverrideIndicatorManager().updateAnnotations();
                    }
                }
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XSLEditor(org.eclipse.wst.xsl.ui.internal.editor.XSLEditor)

Aggregations

IEditorReference (org.eclipse.ui.IEditorReference)174 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)83 IEditorPart (org.eclipse.ui.IEditorPart)78 PartInitException (org.eclipse.ui.PartInitException)59 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)55 IFile (org.eclipse.core.resources.IFile)50 IEditorInput (org.eclipse.ui.IEditorInput)49 ArrayList (java.util.ArrayList)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)28 Item (org.talend.core.model.properties.Item)17 IWorkbench (org.eclipse.ui.IWorkbench)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 IOException (java.io.IOException)12 CoreException (org.eclipse.core.runtime.CoreException)12 ProcessItem (org.talend.core.model.properties.ProcessItem)11 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 Path (org.eclipse.core.runtime.Path)10 IProcess2 (org.talend.core.model.process.IProcess2)10