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();
}
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));
}
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;
}
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);
}
}
}
}
}
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();
}
Aggregations