Search in sources :

Example 56 with IEditorReference

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

the class FormatChangeLogSWTBotTest method canFormatChangeLogFile.

/**
 * Simple test for ChangeLog formatting.
 *
 * @throws Exception
 */
@Test
public void canFormatChangeLogFile() throws Exception {
    // add a ChangeLog file
    assertNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    final String changelogContent = "2010-12-14  Severin Gehwolf  <sgehwolf@redhat.com>\n\n" + "\tAdded org.eclipse.linuxtools.changelog.tests.ui plug-in.\n" + "\t* .classpath: New file.\n" + "\t* .project: New file.\n" + "\t* .settings/org.eclipse.jdt.core.prefs: New file.\n" + "\t* build.properties: New file.\n" + "\t* src/log4j.xml: New file.\n" + "\t* src/org/eclipse/linuxtools/changelog/tests/ui/utils/ContextMenuHelper.java: New file.\n" + "\t* src/org/eclipse/linuxtools/changelog/tests/ui/utils/ProjectExplorer.java: New file.\n" + "\t* src/org/eclipse/linuxtools/changelog/tests/ui/utils/ProjectExplorerTreeItemAppearsCondition.java: New file.\n";
    project.addFileToProject("/", "ChangeLog", new ByteArrayInputStream(changelogContent.getBytes()));
    assertNotNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    // select ChangeLog file
    String teamProviderString = "n/a";
    SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME, teamProviderString);
    long oldTimeout = SWTBotPreferences.TIMEOUT;
    SWTBotPreferences.TIMEOUT = 5000;
    bot.waitUntil(new ProjectExplorerTreeItemAppearsCondition(projectExplorerViewTree, PROJECT_NAME, teamProviderString, "ChangeLog"));
    SWTBotPreferences.TIMEOUT = oldTimeout;
    SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
    // should open ChangeLog file
    changeLogItem.doubleClick();
    oldTimeout = SWTBotPreferences.TIMEOUT;
    SWTBotPreferences.TIMEOUT = 3 * 5000;
    // Wait for ChangeLog editor to open
    Matcher<IEditorReference> editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName("ChangeLog"));
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    SWTBotEditor swtBoteditor = bot.activeEditor();
    assertEquals("ChangeLog", swtBoteditor.getTitle());
    SWTBotEclipseEditor swtBotEclipseEditor = swtBoteditor.toTextEditor();
    // Add two extra lines after the first date line
    swtBotEclipseEditor.insertText(1, 0, "\n\n");
    // Should have 3 empty lines between date-line and first file entry
    swtBotEclipseEditor.selectRange(1, 0, 3);
    // format: ESC CTRL+F
    swtBotEclipseEditor.pressShortcut(Keystrokes.ESC);
    swtBotEclipseEditor.pressShortcut(Keystrokes.CTRL, KeyStroke.getInstance("F"));
    swtBoteditor.save();
}
Also used : Path(org.eclipse.core.runtime.Path) SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) ProjectExplorerTreeItemAppearsCondition(org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition) IEditorReference(org.eclipse.ui.IEditorReference) ByteArrayInputStream(java.io.ByteArrayInputStream) SWTBotEclipseEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) Test(org.junit.Test)

Example 57 with IEditorReference

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

the class PrepareChangelogSWTBotTest method canPrepareChangeLog.

/**
 * Basic prepare changelog test.
 *
 * @throws Exception
 */
@Test
@Ignore
public void canPrepareChangeLog() throws Exception {
    // Find manifest file
    IResource manifest = project.findMember(new Path("/META-INF/MANIFEST.MF"));
    assertNotNull(manifest);
    // delete it
    manifest.delete(true, null);
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    // select ChangeLog file
    String teamProviderString = "[changelog/trunk/" + PROJECT_NAME + "]";
    SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME, teamProviderString);
    SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
    changeLogItem.select();
    // Should be unique
    bot.menu("Prepare ChangeLog").click();
    long oldTimeout = SWTBotPreferences.TIMEOUT;
    SWTBotPreferences.TIMEOUT = 3 * 5000;
    // Wait for ChangeLog editor to open
    Matcher<IEditorReference> editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName("ChangeLog"));
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    SWTBotPreferences.TIMEOUT = oldTimeout;
    SWTBotEditor swtBoteditor = bot.activeEditor();
    // save to avoid "save changes"-pop-up
    swtBoteditor.save();
    assertEquals("ChangeLog", swtBoteditor.getTitle());
    SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
    // make sure expected entry has been added.
    assertTrue(matchHead(eclipseEditor.getText(), "\t* META-INF/MANIFEST.MF:", 3));
}
Also used : Path(org.eclipse.core.runtime.Path) SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) IEditorReference(org.eclipse.ui.IEditorReference) SWTBotEclipseEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) IResource(org.eclipse.core.resources.IResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 58 with IEditorReference

use of org.eclipse.ui.IEditorReference in project knime-core by knime.

the class WorkflowEditor method isOtherEditorToWorkflowOpen.

/**
 * Checks if a non workflow editor (e.g. meta info editor) to the workflow with the given URI is open.
 *
 * @param workflowURI The URI to the workflow directory. Must be file protocol
 * @return true if an editor is open, false otherwise
 */
private static boolean isOtherEditorToWorkflowOpen(final URI workflowURI) {
    boolean isOpen = false;
    File wfDir = new File(workflowURI);
    // Go through all open editors
    for (IEditorReference editorRef : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()) {
        // avoid restoring editor (for large workflows)
        IEditorPart editorPart = editorRef.getEditor(false);
        if (editorPart == null) {
            // Editor is not active/loaded. But tooltip usually points to report template file or meta file
            final String titleToolTip = editorRef.getTitleToolTip();
            if (titleToolTip == null || wfDir.equals(new File(titleToolTip).getParentFile())) {
                // the tooltip indicates that it is an editor for the same workflow (report/metadata/etc.)
                // activate/load the editor
                editorPart = editorRef.getEditor(true);
            }
        }
        // Check if editor is something other than a workflow editor
        if ((editorPart != null) && !(editorPart instanceof WorkflowEditor)) {
            IEditorInput editorInput = editorPart.getEditorInput();
            if (editorInput instanceof FileStoreEditorInput) {
                FileStoreEditorInput fileStoreInput = (FileStoreEditorInput) editorInput;
                // Get URI of the editor
                URI uri = fileStoreInput.getURI();
                // Check if parent of the editor is the workflow directory
                uri = new File(uri).getParentFile().toURI();
                if (workflowURI.equals(uri)) {
                    isOpen = true;
                    break;
                }
            }
        }
    }
    return isOpen;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IEditorPart(org.eclipse.ui.IEditorPart) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File) URI(java.net.URI) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 59 with IEditorReference

use of org.eclipse.ui.IEditorReference in project knime-core by knime.

the class DeleteAction method closeOpenWorkflows.

private void closeOpenWorkflows(final List<IContainer> allWorkflows) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (IContainer wf : allWorkflows) {
        NodeContainer wfm = ProjectWorkflowMap.getWorkflow(wf.getLocationURI());
        if (wfm != null) {
            for (IEditorReference editRef : page.getEditorReferences()) {
                IEditorPart editor = editRef.getEditor(false);
                if (editor == null) {
                    // got closed in the mean time
                    continue;
                }
                WorkflowEditorAdapter wea = (WorkflowEditorAdapter) editor.getAdapter(WorkflowEditorAdapter.class);
                NodeContainer editWFM = null;
                if (wea != null) {
                    editWFM = wea.getWorkflowManager();
                }
                if (wfm == editWFM) {
                    page.closeEditor(editor, false);
                }
            }
        }
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) WorkflowEditorAdapter(org.knime.workbench.ui.navigator.WorkflowEditorAdapter) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NodeContainer(org.knime.core.node.workflow.NodeContainer) IEditorPart(org.eclipse.ui.IEditorPart) IContainer(org.eclipse.core.resources.IContainer)

Example 60 with IEditorReference

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

the class NavigatorHandlerObjectBase method getCommandTarget.

protected static CommandTarget getCommandTarget(IWorkbenchWindow workbenchWindow, DBNContainer container, Class<?> childType, boolean openEditor) throws DBException {
    final Object parentObject = container.getValueObject();
    DBSObject objectToSeek = null;
    if (parentObject instanceof DBSObject) {
        final DBEStructEditor parentStructEditor = EntityEditorsRegistry.getInstance().getObjectManager(parentObject.getClass(), DBEStructEditor.class);
        if (parentStructEditor != null && RuntimeUtils.isTypeSupported(childType, parentStructEditor.getChildTypes())) {
            objectToSeek = (DBSObject) parentObject;
        }
    }
    if (objectToSeek != null) {
        for (final IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
            final IEditorPart editor = editorRef.getEditor(false);
            if (editor instanceof IDatabaseEditor) {
                final IDatabaseEditorInput editorInput = ((IDatabaseEditor) editor).getEditorInput();
                if (editorInput.getDatabaseObject() == objectToSeek) {
                    workbenchWindow.getActivePage().activate(editor);
                    switchEditorFolder(container, editor);
                    return new CommandTarget((IDatabaseEditor) editor);
                }
            }
        }
        if (openEditor && container instanceof DBNDatabaseNode) {
            final IDatabaseEditor editor = (IDatabaseEditor) NavigatorHandlerObjectOpen.openEntityEditor((DBNDatabaseNode) container, null, workbenchWindow);
            if (editor != null) {
                switchEditorFolder(container, editor);
                return new CommandTarget(editor);
            }
        }
    }
    if (container instanceof DBNDatabaseNode) {
        // No editor found - create new command context
        DBPDataSource dataSource = ((DBNDatabaseNode) container).getObject().getDataSource();
        if (dataSource != null) {
            return new CommandTarget(new SimpleCommandContext(dataSource.getDefaultContext(true), !openEditor));
        }
    }
    return new CommandTarget();
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IEditorReference(org.eclipse.ui.IEditorReference) SimpleCommandContext(org.jkiss.dbeaver.ui.SimpleCommandContext) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBEStructEditor(org.jkiss.dbeaver.model.edit.DBEStructEditor) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IDatabaseEditor(org.jkiss.dbeaver.ui.editors.IDatabaseEditor)

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