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