Search in sources :

Example 36 with IEditorInput

use of org.eclipse.ui.IEditorInput 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)

Example 37 with IEditorInput

use of org.eclipse.ui.IEditorInput in project bndtools by bndtools.

the class PrivatePackagesPart method getJavaProject.

private IJavaProject getJavaProject() {
    IFormPage page = (IFormPage) getManagedForm().getContainer();
    IEditorInput input = page.getEditorInput();
    if (!IFileEditorInput.class.isInstance(input)) {
        return null;
    }
    IProject project = ((IFileEditorInput) input).getFile().getProject();
    return JavaCore.create(project);
}
Also used : IFileEditorInput(org.eclipse.ui.IFileEditorInput) IFormPage(org.eclipse.ui.forms.editor.IFormPage) IEditorInput(org.eclipse.ui.IEditorInput) IProject(org.eclipse.core.resources.IProject)

Example 38 with IEditorInput

use of org.eclipse.ui.IEditorInput in project bndtools by bndtools.

the class BndSourceEditorPage method getDocument.

private IDocument getDocument() {
    IDocumentProvider docProvider = getDocumentProvider();
    IEditorInput input = getEditorInput();
    return new IDocumentWrapper(docProvider.getDocument(input));
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IEditorInput(org.eclipse.ui.IEditorInput)

Example 39 with IEditorInput

use of org.eclipse.ui.IEditorInput in project bndtools by bndtools.

the class JAREntryPart method loadContent.

protected void loadContent() {
    if (displayJob != null && displayJob.getState() != Job.NONE)
        displayJob.cancel();
    if (zipEntry != null && !zipEntry.isDirectory()) {
        IEditorInput input = editor.getEditorInput();
        final Display display = text.getDisplay();
        final URI uri = URIHelper.retrieveFileURI(input);
        if (uri != null) {
            displayJob = new Job("Load zip content") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    File ioFile = new File(uri);
                    try (ZipFile zipFile = new ZipFile(ioFile)) {
                        final StringWriter writer = new StringWriter();
                        if (showAsText)
                            readAsText(zipFile, zipEntry, charsets[selectedCharset], writer, 1024 * 20, monitor);
                        else
                            readAsHex(zipFile, zipEntry, writer, 1024 * 20, 2, monitor);
                        display.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                setContent(writer.toString());
                            }
                        });
                        return Status.OK_STATUS;
                    } catch (IOException e) {
                        Status status = new Status(IStatus.ERROR, PluginConstants.PLUGIN_ID, 0, "I/O error reading JAR file contents", e);
                        // ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, status);
                        return status;
                    }
                }
            };
            displayJob.schedule();
        }
    } else {
        setContent("");
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IOException(java.io.IOException) URI(java.net.URI) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ZipFile(java.util.zip.ZipFile) StringWriter(java.io.StringWriter) Job(org.eclipse.core.runtime.jobs.Job) ZipFile(java.util.zip.ZipFile) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput) Display(org.eclipse.swt.widgets.Display)

Example 40 with IEditorInput

use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.

the class LastSaveReferenceProvider method setActiveEditor.

@Override
public void setActiveEditor(ITextEditor targetEditor) {
    IDocumentProvider provider = null;
    IEditorInput input = null;
    if (targetEditor != null) {
        provider = targetEditor.getDocumentProvider();
        input = targetEditor.getEditorInput();
    }
    // note that they may serve multiple editors
    if (provider != fDocumentProvider || input != fEditorInput) {
        dispose();
        synchronized (fLock) {
            fEditor = targetEditor;
            fDocumentProvider = provider;
            fEditorInput = input;
        }
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)135 IFile (org.eclipse.core.resources.IFile)38 IEditorPart (org.eclipse.ui.IEditorPart)37 PartInitException (org.eclipse.ui.PartInitException)31 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)28 CoreException (org.eclipse.core.runtime.CoreException)25 IFileEditorInput (org.eclipse.ui.IFileEditorInput)22 IDocument (org.eclipse.jface.text.IDocument)17 IEditorReference (org.eclipse.ui.IEditorReference)17 FileEditorInput (org.eclipse.ui.part.FileEditorInput)16 File (java.io.File)14 ArrayList (java.util.ArrayList)14 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)14 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)14 IResource (org.eclipse.core.resources.IResource)13 Shell (org.eclipse.swt.widgets.Shell)13 IViewPart (org.eclipse.ui.IViewPart)13 IPath (org.eclipse.core.runtime.IPath)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)11