Search in sources :

Example 1 with IFileEditorInput

use of org.eclipse.ui.IFileEditorInput in project KaiZen-OpenAPI-Editor by RepreZen.

the class QuickOutline method setInput.

@Override
public void setInput(Object input) {
    if (input instanceof Model) {
        Model model = (Model) input;
        if (model.getPath() == null) {
            IFile currentFile = null;
            IEditorInput editorInput = editor.getEditorInput();
            if (editorInput instanceof IFileEditorInput) {
                currentFile = ((IFileEditorInput) editorInput).getFile();
            }
            if (currentFile != null) {
                model.setPath(currentFile.getFullPath());
            }
        }
    }
    treeViewer.setInput(input);
    treeViewer.setSelection(null, true);
}
Also used : IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) Model(com.reprezen.swagedit.core.model.Model) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with IFileEditorInput

use of org.eclipse.ui.IFileEditorInput in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonEditor method validate.

private void validate(boolean onOpen) {
    IEditorInput editorInput = getEditorInput();
    final IDocument document = getDocumentProvider().getDocument(getEditorInput());
    // such files.
    if (!(editorInput instanceof IFileEditorInput)) {
        YEditLog.logError("Marking errors not supported for files outside of a project.");
        YEditLog.logger.info("editorInput is not a part of a project.");
        return;
    }
    if (document instanceof JsonDocument) {
        final IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
        final IFile file = fileEditorInput.getFile();
        if (onOpen) {
            // force parsing of yaml to init parsing errors
            ((JsonDocument) document).onChange();
        }
        clearMarkers(file);
        validateYaml(file, (JsonDocument) document);
        validateSwagger(file, (JsonDocument) document, fileEditorInput);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with IFileEditorInput

use of org.eclipse.ui.IFileEditorInput in project tesb-studio-se by Talend.

the class OpenOnSelectionHelper method openEditor.

@Override
protected void openEditor(String resource, String spec) {
    //$NON-NLS-1$
    String pattern = "platform:/resource";
    IWorkbenchPage workbenchPage = WSDLEditorPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart editorPart = workbenchPage.getActiveEditor();
    String currentEditorId = editorPart.getEditorSite().getId();
    if (resource != null && resource.startsWith(pattern)) {
        Path path = new Path(resource.substring(pattern.length()));
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (editorPart.getEditorInput() instanceof IFileEditorInput && ((IFileEditorInput) editorPart.getEditorInput()).getFile().equals(file)) {
            workbenchPage.getNavigationHistory().markLocation(editorPart);
        } else {
            try {
                Item item = ((ServiceEditorInput) editorPart.getEditorInput()).getItem();
                // TODO: Use content type as below
                if (resource.endsWith("xsd")) {
                    //$NON-NLS-1$
                    editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), WSDLEditorPlugin.XSD_EDITOR_ID);
                } else {
                    // Since we are already in the wsdleditor
                    editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), editorPart.getEditorSite().getId());
                }
            } catch (PartInitException initEx) {
                ExceptionHandler.process(initEx);
            }
        }
        try {
            Class<? extends IEditorPart> theClass = editorPart.getClass();
            Class<?>[] methodArgs = { String.class };
            //$NON-NLS-1$
            Method method = theClass.getMethod("openOnSelection", methodArgs);
            Object[] args = { spec };
            method.invoke(editorPart, args);
            workbenchPage.getNavigationHistory().markLocation(editorPart);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    } else if (resource != null && resource.startsWith("http")) {
        IEditorPart newEditorPart = null;
        boolean doOpenWsdlEditor = true;
        if (//$NON-NLS-1$
        resource.endsWith("xsd")) {
            doOpenWsdlEditor = false;
        }
        try {
            IEditorReference[] refs = workbenchPage.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(resource) && (!doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.XSD_EDITOR_ID) || doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.WSDL_EDITOR_ID))) {
                        newEditorPart = refs[i].getEditor(true);
                        workbenchPage.activate(refs[i].getPart(true));
                        break;
                    }
                }
            }
            if (newEditorPart == null) {
                ADTReadOnlyFileEditorInput readOnlyStorageEditorInput = new ADTReadOnlyFileEditorInput(resource);
                IContentType contentType = null;
                try (InputStream iStream = readOnlyStorageEditorInput.getStorage().getContents()) {
                    contentType = Platform.getContentTypeManager().findContentTypeFor(iStream, resource);
                }
                // content type more reliable check
                if (//$NON-NLS-1$
                contentType != null && contentType.equals(XSDEditorPlugin.XSD_CONTENT_TYPE_ID) || resource.endsWith("xsd")) {
                    readOnlyStorageEditorInput.setEditorID(WSDLEditorPlugin.XSD_EDITOR_ID);
                    //$NON-NLS-1$
                    workbenchPage.openEditor(readOnlyStorageEditorInput, WSDLEditorPlugin.XSD_EDITOR_ID, true, 0);
                } else {
                    readOnlyStorageEditorInput.setEditorID(currentEditorId);
                    //$NON-NLS-1$
                    workbenchPage.openEditor(readOnlyStorageEditorInput, currentEditorId, true, 0);
                }
            }
        } catch (IOException | CoreException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ADTReadOnlyFileEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.ADTReadOnlyFileEditorInput) InputStream(java.io.InputStream) IContentType(org.eclipse.core.runtime.content.IContentType) IEditorPart(org.eclipse.ui.IEditorPart) Method(java.lang.reflect.Method) ServiceEditorInput(org.talend.repository.services.action.ServiceEditorInput) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Item(org.talend.core.model.properties.Item) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 4 with IFileEditorInput

use of org.eclipse.ui.IFileEditorInput in project ow by vtst.

the class AbstractEditorRegistry method addEditor.

private synchronized void addEditor(ITextEditor textEditor) {
    IEditorInput editorInput = textEditor.getEditorInput();
    if (!(editorInput instanceof IFileEditorInput))
        return;
    IFile file = ((IFileEditorInput) editorInput).getFile();
    IDocument document = textEditor.getDocumentProvider().getDocument(editorInput);
    if (file == null || document == null)
        return;
    editorToFile.put(textEditor, file);
    editorToDocument.put(textEditor, document);
    boolean newlyOpenedFile = fileToEditors.put(file, textEditor);
    if (documentToEditors.put(document, textEditor)) {
        DocumentListener listener = makeDocumentListener(document);
        documentToListener.put(document, listener);
        document.addDocumentListener(listener);
        documentToFile.put(document, file);
    }
    if (newlyOpenedFile) {
        triggerFileOpenListener(file);
    }
}
Also used : IDocumentListener(org.eclipse.jface.text.IDocumentListener) NullDocumentListener(net.vtst.ow.eclipse.js.closure.util.listeners.NullDocumentListener) IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with IFileEditorInput

use of org.eclipse.ui.IFileEditorInput in project sling by apache.

the class LinkHelper method activateEditor.

@Override
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    final Object selectedElement = aSelection.getFirstElement();
    if (!(selectedElement instanceof JcrNode)) {
        return;
    }
    final JcrNode node = (JcrNode) selectedElement;
    // bring properties view to top, if it is open
    // SLING-3641 : moved link-with-editor behavior to the JCR Properties view atm
    //TODO: to be reviewed at a later stage with SLING-3641
    //		IViewPart propertiesView = aPage.findView(IPageLayout.ID_PROP_SHEET);
    //		if (propertiesView!=null) {
    //			aPage.bringToTop(propertiesView);
    //		}
    final IResource resource = node.getResource();
    if (resource == null || !(resource instanceof IFile)) {
        return;
    }
    final IFile selectedFile = (IFile) resource;
    for (final IEditorReference reference : aPage.getEditorReferences()) {
        if (reference == null) {
            continue;
        }
        final IEditorInput editorInput;
        try {
            editorInput = reference.getEditorInput();
        } catch (PartInitException e) {
            //TODO proper logging
            e.printStackTrace();
            continue;
        }
        if (editorInput == null) {
            continue;
        }
        if (!(editorInput instanceof IFileEditorInput)) {
            continue;
        }
        final IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
        final IFile file = fileEditorInput.getFile();
        if (file == null) {
            continue;
        }
        if (file.equals(selectedFile)) {
            aPage.bringToTop(reference.getEditor(true));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorReference(org.eclipse.ui.IEditorReference) IFileEditorInput(org.eclipse.ui.IFileEditorInput) PartInitException(org.eclipse.ui.PartInitException) IResource(org.eclipse.core.resources.IResource) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IFileEditorInput (org.eclipse.ui.IFileEditorInput)10 IFile (org.eclipse.core.resources.IFile)8 IEditorInput (org.eclipse.ui.IEditorInput)8 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CoreException (org.eclipse.core.runtime.CoreException)2 IDocument (org.eclipse.jface.text.IDocument)2 PartInitException (org.eclipse.ui.PartInitException)2 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)2 Model (com.reprezen.swagedit.core.model.Model)1 SwaggerFileFinder (com.reprezen.swagedit.core.utils.SwaggerFileFinder)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 NullDocumentListener (net.vtst.ow.eclipse.js.closure.util.listeners.NullDocumentListener)1