Search in sources :

Example 51 with IEditorReference

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

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

the class EditorOpener method showWithReuse.

private IEditorPart showWithReuse(IFile file, IWorkbenchPage page, String editorId, boolean activate) throws PartInitException {
    IEditorInput input = new FileEditorInput(file);
    IEditorPart editor = page.findEditor(input);
    if (editor != null) {
        page.bringToTop(editor);
        if (activate) {
            page.activate(editor);
        }
        return editor;
    }
    IEditorReference reusedEditorRef = fReusedEditor;
    if (reusedEditorRef != null) {
        boolean isOpen = reusedEditorRef.getEditor(false) != null;
        boolean canBeReused = isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned();
        if (canBeReused) {
            boolean showsSameInputType = reusedEditorRef.getId().equals(editorId);
            if (!showsSameInputType) {
                page.closeEditors(new IEditorReference[] { reusedEditorRef }, false);
                fReusedEditor = null;
            } else {
                editor = reusedEditorRef.getEditor(true);
                if (editor instanceof IReusableEditor) {
                    ((IReusableEditor) editor).setInput(input);
                    page.bringToTop(editor);
                    if (activate) {
                        page.activate(editor);
                    }
                    return editor;
                }
            }
        }
    }
    editor = page.openEditor(input, editorId, activate);
    if (editor instanceof IReusableEditor) {
        IEditorReference reference = (IEditorReference) page.getReference(editor);
        fReusedEditor = reference;
    } else {
        fReusedEditor = null;
    }
    return editor;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IReusableEditor(org.eclipse.ui.IReusableEditor) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput)

Example 53 with IEditorReference

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

the class HippieProposalProcessor method getSuggestions.

/**
 * Create the array of suggestions. It scans all open text editors and prefers suggestions from
 * the currently open editor. It also adds the empty suggestion at the end.
 *
 * @param viewer the viewer
 * @param offset the offset
 * @param prefix the prefix to search for
 * @return the list of all possible suggestions in the currently open editors
 * @throws BadLocationException if accessing the current document fails
 */
private List<String> getSuggestions(ITextViewer viewer, int offset, String prefix) throws BadLocationException {
    ArrayList<String> suggestions = createSuggestionsFromOpenDocument(viewer, offset, prefix);
    IDocument currentDocument = viewer.getDocument();
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorReference[] editorReferences = window.getActivePage().getEditorReferences();
    for (int i = 0; i < editorReferences.length; i++) {
        // don't create!
        IEditorPart editor = editorReferences[i].getEditor(false);
        if (editor instanceof ITextEditor) {
            ITextEditor textEditor = (ITextEditor) editor;
            IEditorInput input = textEditor.getEditorInput();
            IDocument doc = textEditor.getDocumentProvider().getDocument(input);
            if (!currentDocument.equals(doc))
                suggestions.addAll(fEngine.getCompletionsForward(doc, prefix, 0, false));
        }
    }
    // add the empty suggestion
    // $NON-NLS-1$
    suggestions.add("");
    List<String> uniqueSuggestions = fEngine.makeUnique(suggestions);
    return uniqueSuggestions;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) StyledString(org.eclipse.jface.viewers.StyledString) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point) IEditorInput(org.eclipse.ui.IEditorInput)

Example 54 with IEditorReference

use of org.eclipse.ui.IEditorReference in project linuxtools by eclipse.

the class CreaterepoResourceChangeListener method closeEditors.

/**
 * Close the editors thats resource has been affected by a change in the
 * workspace. E.g. if an editor's project has been closed/deleted, close the
 * editor.
 */
private void closeEditors() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IResource repomdFile = project.getRepoFile();
    // deleted, or the file was deleted. If so, close the editor of the file.
    if (!repomdFile.exists()) {
        for (IWorkbenchPage page : workbench.getActiveWorkbenchWindow().getPages()) {
            for (IEditorReference ref : page.getEditorReferences()) {
                try {
                    // get the resource from the editor part and exit the editor if
                    // it is within the project(s) being closed/deleted
                    IResource resource = ResourceUtil.getResource(ref.getEditorInput());
                    if (ref.getId().equals(RepoFormEditor.EDITOR_ID) && resource.getProject().equals(project.getProject())) {
                        page.closeEditor(ref.getEditor(false), false);
                    }
                } catch (PartInitException e) {
                    Activator.logError(Messages.CreaterepoResourceChangeListener_errorGettingResource, e);
                }
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IResource(org.eclipse.core.resources.IResource)

Example 55 with IEditorReference

use of org.eclipse.ui.IEditorReference in project linuxtools by eclipse.

the class AddChangelogEntrySWTBotTest method canAddChangeLogEntryUsingEditMenuIfSourceIsActive.

/**
 * ChangeLog editor should pop-up if inside an active editor
 * and a ChangeLog file exists in the project. Tests the "Edit" => "ChangeLog Entry"
 * menu item.
 *
 * @throws Exception
 */
@Test
public void canAddChangeLogEntryUsingEditMenuIfSourceIsActive() throws Exception {
    // Add a Java source file
    String sourceCode = "package src;\n" + "public class JavaTest {\n" + "public static void main(String args[]) {\n" + "//" + OFFSET_MARKER + "\n" + "System.out.println(\"Hello World!\");\n" + "}\n" + "}\n";
    assertNull(project.getTestProject().findMember(new Path("/src/JavaTest.java")));
    InputStream newFileInputStream = new ByteArrayInputStream(sourceCode.getBytes());
    project.addFileToProject("/src", "JavaTest.java", newFileInputStream);
    // Add a changelog file
    newFileInputStream = new ByteArrayInputStream("".getBytes());
    project.addFileToProject("/", "ChangeLog", newFileInputStream);
    assertNotNull(project.getTestProject().findMember(new Path("/src/JavaTest.java")));
    assertNotNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    // Open JavaTest.java in an editor
    SWTBotTreeItem projectItem = projectExplorerViewTree.expandNode(PROJECT_NAME);
    projectItem.expandNode("src").expandNode("JavaTest.java").doubleClick();
    Matcher<IEditorReference> editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName("JavaTest.java"));
    // Wait for editor to open
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    SWTBotEditor swtBoteditor = bot.editorByTitle("JavaTest.java");
    SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
    eclipseEditor.selectLine(getLineOfOffsetMarker(sourceCode));
    // Click menu item.
    bot.menu("Edit").menu("Insert ChangeLog entry").click();
    // Wait for ChangeLog editor to open
    editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName("ChangeLog"));
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    swtBoteditor = bot.activeEditor();
    // save to avoid "save changes"-pop-up
    swtBoteditor.save();
    assertEquals("ChangeLog", swtBoteditor.getTitle());
    eclipseEditor = swtBoteditor.toTextEditor();
    // make sure expected entry has been added.
    assertTrue(eclipseEditor.getText().contains("* src/JavaTest.java"));
}
Also used : Path(org.eclipse.core.runtime.Path) SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) IEditorReference(org.eclipse.ui.IEditorReference) ByteArrayInputStream(java.io.ByteArrayInputStream) SWTBotEclipseEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) Test(org.junit.Test)

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