@Test public void testGetLinkedBookmarksInMultipageEditor() throws Exception { // Given importProjectFromTemplate("testGetLinkedBookmarksInMultipageEditor", "commons-cli"); Bookmark bookmark = bookmark("pom.xml") .withProperty(PROP_WORKSPACE_PATH, "/testGetLinkedBookmarksInMultipageEditor/pom.xml") .withProperty(PROP_LINE_NUMBER, "10").build(); addBookmark(rootFolderId, bookmark); waitUntil("Cannot find marker", () -> bookmarksMarkers.findMarker(bookmark.getId(), null)); // When IEditorPart editorPart = openEditor(new Path("/testGetLinkedBookmarksInMultipageEditor/pom.xml")); // that's why we require org.eclipse.m2e.editor in MANIFEST.MF assertThat(editorPart).isInstanceOf(MultiPageEditorPart.class); ITextEditor textEditor = getTextEditor(editorPart); selectAndReveal(textEditor, getOffset(textEditor, 10)); List<Bookmark> bookmarks = operation.getLinkedBookmarks(textEditor, getSelection(textEditor)); // Then assertEquals(1, bookmarks.size()); assertEquals(bookmark, bookmarks.get(0)); }
@Override public String createAdditionalPage(MultiPageEditorPart parent, IFileEditorInput file, int pageNum) { // Create the specified page switch (pageNum) { // Page 2 is the file's data displayed in text case 1: // Create a text editor with the file as input and add its page with // the name Data try { editor = (IEditorPart) new TextEditor(); parent.addPage(editor, file); return "Data"; } catch (PartInitException e) { logger.error("Error initializing text editor for CSV Plot Editor."); } break; } // If the page number is not supported, return null return null; }
private void finishNotCompiledReport() { UIUtils.getDisplay().asyncExec(new Runnable() { public void run() { pcontainer.setNotRunning(true); if (pcontainer.getSite() instanceof MultiPageEditorSite) { MultiPageEditorPart mpe = ((MultiPageEditorSite) pcontainer.getSite()).getMultiPageEditor(); IEditorPart[] editors = mpe.findEditors(mpe.getEditorInput()); if (editors != null && editors.length > 0) { // Dialog, if not ..., it's not clear for the user that error happened UIUtils.showInformation(Messages.ReportControler_compilationerrors); mpe.setActiveEditor(editors[0]); } } } }); }
public void partClosed(IWorkbenchPartReference partRef) { if (partRef instanceof IEditorReference) { IEditorPart part = (IEditorPart) partRef.getPart(false); if (part instanceof MultiPageEditorPart) { MultiPageEditorPart multi = (MultiPageEditorPart) part; if (pageListener != null) { multi.getSite().getSelectionProvider().removeSelectionChangedListener(pageListener); } } } // If it's a search view, remove any query listeners for it! else if (partRef instanceof IViewReference) { IViewPart view = (IViewPart) partRef.getPart(false); if (queryListeners.containsKey(view)) { NewSearchUI.removeQueryListener(queryListeners.remove(view)); } } }
public static void selectAndReveal(IEditorPart editorPart, IRegion highlightRange) { ITextEditor textEditor = null; if (editorPart instanceof MultiPageEditorPart) { MultiPageEditorPart part = (MultiPageEditorPart) editorPart; Object editorPage = part.getSelectedPage(); if (editorPage != null && editorPage instanceof ITextEditor) { textEditor = (ITextEditor) editorPage; } } else if (editorPart instanceof ITextEditor) { textEditor = (ITextEditor) editorPart; } // highlight range in editor if possible if (highlightRange != null && textEditor != null) { textEditor.selectAndReveal(highlightRange.getOffset(), highlightRange.getLength()); } }
public static IEditorPart getTimelineEditor(Object object) { IEditorPart editor = null; if (object instanceof IEditorPart) { editor = (IEditorPart) object; } else if (object instanceof ExecutionEvent) { ExecutionEvent event = (ExecutionEvent) object; IEditorPart activeEditor = HandlerUtil.getActiveEditor(event); if (activeEditor instanceof MultiPageEditorPart) { MultiPageEditorPart multiPageEditorPart = (MultiPageEditorPart) activeEditor; IEditorPart[] editorParts = multiPageEditorPart.findEditors(multiPageEditorPart.getEditorInput()); for (IEditorPart editorPart : editorParts) { Timeline timeline = (Timeline) editorPart.getAdapter(Timeline.class); if (timeline != null) { editor = editorPart; break; } } } } return editor; }
public static boolean isTimelineActive() { IWorkbench workbench = Activator.getDefault().getWorkbench(); IEditorPart current = EditorPartUtils.getCurrent(workbench); if (current instanceof EditorPart) { IEditorPart activeEditor = current; if (activeEditor instanceof MultiPageEditorPart) { MultiPageEditorPart editor = (MultiPageEditorPart) current; int activePage = editor.getActivePage(); if (activePage >= 0) { IEditorPart[] subEditors = editor.findEditors(editor.getEditorInput()); if (activePage < subEditors.length) { activeEditor = subEditors[activePage]; } } } Object adapter = activeEditor.getAdapter(Timeline.class); if (adapter != null) { return true; } } return false; }
private void refresh() { ITextEditor iteEditor = null; if (this.editor instanceof EcoreEditor) { final EcoreEditor ecEditor = (EcoreEditor) this.editor; ecEditor.getViewer().refresh(); } else { if (this.editor instanceof ITextEditor) { iteEditor = (ITextEditor) this.editor; } else { final MultiPageEditorPart mpepEditor = (MultiPageEditorPart) this.editor; final IEditorPart[] editors = mpepEditor.findEditors(mpepEditor.getEditorInput()); iteEditor = (ITextEditor) editors[0]; } final IDocumentProvider idp = iteEditor.getDocumentProvider(); try { idp.resetDocument(iteEditor.getEditorInput()); } catch (final CoreException e) { e.printStackTrace(); } } MarkerFactory.refreshProjectExp(); if (Activator.getDefault().getWorkbench().getWorkbenchWindows()[0].getActivePage() .findView(Visualization.ID) != null) { Visualization.showViz(); } }
private void refresh() { ITextEditor iteEditor = null; if (editor instanceof EcoreEditor) { final EcoreEditor ecEditor = (EcoreEditor) editor; ecEditor.getViewer().refresh(); } else { if (editor instanceof ITextEditor) { iteEditor = (ITextEditor) editor; } else { final MultiPageEditorPart mpepEditor = (MultiPageEditorPart) editor; final IEditorPart[] editors = mpepEditor.findEditors(mpepEditor.getEditorInput()); iteEditor = (ITextEditor) editors[0]; } final IDocumentProvider idp = iteEditor.getDocumentProvider(); try { idp.resetDocument(iteEditor.getEditorInput()); } catch (final CoreException e) { e.printStackTrace(); } } MarkerFactory.refreshProjectExp(); if (Activator.getDefault().getWorkbench().getWorkbenchWindows()[0].getActivePage() .findView(Visualization.ID) != null) { Visualization.showViz(); } }
private void refresh() { ITextEditor iteEditor = null; if (editor instanceof EcoreEditor) { final EcoreEditor ecEditor = (EcoreEditor) editor; ecEditor.getViewer().refresh(); } else { if (editor instanceof ITextEditor) { iteEditor = (ITextEditor) editor; } else { final MultiPageEditorPart mpepEditor = (MultiPageEditorPart) editor; final IEditorPart[] editors = mpepEditor.findEditors(mpepEditor.getEditorInput()); iteEditor = (ITextEditor) editors[0]; } final IDocumentProvider idp = iteEditor.getDocumentProvider(); try { idp.resetDocument(iteEditor.getEditorInput()); } catch (final CoreException e) { e.printStackTrace(); } } MarkerFactory.refreshProjectExp(); }
@Override public final void editorOpened(IEditorPart editorPart) { if (editorPart instanceof MultiPageEditorPart) { Object selectedPage = ((MultiPageEditorPart) editorPart).getSelectedPage(); if (selectedPage instanceof IEditorPart) { editorPart = (IEditorPart) selectedPage; } } if (editorPart instanceof ITextEditor) { editorOpened((ITextEditor) editorPart); } }
private IEditorInput getActiveEditorInput() { IEditorPart editor = getActiveEditor(); if (editor == null) return null; // Handle multi-page editors if (editor instanceof MultiPageEditorPart) { Object page= ((MultiPageEditorPart)editor).getSelectedPage(); if (page instanceof IEditorPart) editor= (IEditorPart)page; else return null; } return editor.getEditorInput(); }
public void setActiveEditor(IEditorPart part) { if (part instanceof MultiPageEditorPart) { part = ((NCLMultiPageEditor) part).getActivePageAsEditor(); activeNestedEditor = part; /* layout editor, not in use for now if(part instanceof NCLLayoutEditor){ nclLayoutActionBarContributor.setActiveEditor(part); } else*/ if (part instanceof NCLEditor) { nclActionContributor.setActiveEditor(part); } } super.setActiveEditor(part); }
public static void openEditor(final Object val, IEditorPart editor, ANode node) { if (editor.getEditorSite() instanceof MultiPageEditorSite) { final MultiPageEditorPart mpep = ((MultiPageEditorSite) editor.getEditorSite()).getMultiPageEditor(); if (mpep instanceof IJROBjectEditor) doOpenEditor(val, (IJROBjectEditor) mpep, node); } else { editor = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (editor instanceof IJROBjectEditor) doOpenEditor(val, (IJROBjectEditor) editor, node); } }
public void partOpened(IWorkbenchPartReference partRef) { if (partRef instanceof IEditorReference) { IEditorPart editorPart = (IEditorPart) partRef.getPart(false); hijackEditor(editorPart, false); if (editorPart instanceof MultiPageEditorPart) { MultiPageEditorPart multi = (MultiPageEditorPart) editorPart; if (pageListener == null) { pageListener = new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { hijackOutline(); } }; } multi.getSite().getSelectionProvider().addSelectionChangedListener(pageListener); } return; } if (partRef instanceof IViewReference) { IViewPart view = (IViewPart) partRef.getPart(false); hijackView(view, false); } }
private void refreshActiveEditor() { IEditorPart editor = Activator.getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (editor == null) { return; } ITextEditor iteEditor = null; if (editor instanceof EcoreEditor) { final EcoreEditor ecEditor = (EcoreEditor) editor; ecEditor.getViewer().refresh(); } else { if (editor instanceof ITextEditor) { iteEditor = (ITextEditor) editor; } else if (editor instanceof MultiPageEditorPart) { final MultiPageEditorPart mpepEditor = (MultiPageEditorPart) editor; final IEditorPart[] editors = mpepEditor.findEditors(mpepEditor.getEditorInput()); iteEditor = (ITextEditor) editors[0]; } if (iteEditor != null) { final IDocumentProvider idp = iteEditor.getDocumentProvider(); try { idp.resetDocument(iteEditor.getEditorInput()); } catch (final CoreException e) { e.printStackTrace(); } } } MarkerFactory.refreshProjectExp(); if (Activator.getDefault().getWorkbench().getWorkbenchWindows()[0].getActivePage() .findView(Visualization.ID) != null) { Visualization.showViz(); } }
public void open() { if (file == null) { textViewer.setSelectedRange(destRegion.getOffset(), destRegion.getLength()); textViewer.revealRange(destRegion.getOffset(), destRegion.getLength()); } else { try { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IEditorPart editorPart = IDE.openEditor(window.getActivePage(), file); if (editorPart instanceof MultiPageEditorPart) { MultiPageEditorPart multiPageEditorPart = (MultiPageEditorPart)editorPart; IEditorPart[] editors = multiPageEditorPart .findEditors(editorPart.getEditorInput()); if (editors.length == 1 && editors[0] instanceof ITextEditor) { ((ITextEditor)editors[0]).selectAndReveal(destRegion.getOffset(), destRegion.getLength()); } } } } catch (Exception e) { Activator.log(Status.WARNING, e.getMessage(), e); } } }
/** * Verify that the editor in the location is still in use * * @param location * @return true if editor is valid */ private boolean checkEditor(IBufferLocation location) { boolean result = false; if (location != null) { ITextEditor editor = location.getEditor(); if (editor != null) { IEditorInput input = editor.getEditorInput(); // check all the editor references that match the input for a match IEditorReference[] refs = EmacsPlusUtils.getWorkbenchPage().findEditors(input,null, IWorkbenchPage.MATCH_INPUT); for (int i=0; i< refs.length; i++) { IEditorPart ed = refs[i].getEditor(false); // multi page annoyance if (ed instanceof MultiPageEditorPart) { IEditorPart[] eds = ((MultiPageEditorPart)ed).findEditors(input); for (int j=0; j < eds.length; j++) { if (eds[i] == editor) { result = true; break; } } if (result) { break; } } else { if (ed == editor) { result = true; break; } } } } } return result; }
/** * If we're a multi-page editor, try to extract the text editor * * @param editor the selected editor * @param activate force the text editor to be the active page * @return a text editor or null */ public static ITextEditor getTextEditor(IEditorPart editor, boolean activate) { ITextEditor result = null; if (editor != null) { if (editor instanceof ITextEditor) { result = (ITextEditor) editor; } else { // this should retrieve the currently active editor from MultiPageEditors & etc. result = (ITextEditor) editor.getAdapter(ITextEditor.class); // dig further if multi type if (result == null) { if (editor instanceof MultiEditor) { // this code is ancient - not sure if there are any plain MultiEditors anymore IEditorPart epart = ((MultiEditor) editor).getActiveEditor(); // potentially recurse if (epart != editor) { result = getTextEditor(epart, activate); } } else if (editor instanceof MultiPageEditorPart) { MultiPageEditorPart med = (MultiPageEditorPart)editor; IEditorPart[] eds = med.findEditors(med.getEditorInput()); for (IEditorPart ep : eds) { if (ep instanceof ITextEditor) { result = (ITextEditor)ep; if (activate) { med.setActiveEditor(result); IWorkbenchPage wpage = getWorkbenchPage(); wpage.bringToTop(result); wpage.activate(result); } break; } } } } } } return result; }
private IDocument getDocumentForEditor(IEditorReference editorReference) { IEditorPart editorPart = editorReference.getEditor(true); if (editorPart instanceof MultiPageEditorPart) { ((MultiPageEditorPart) editorPart).addPageChangedListener(new MultiEditorPageChangedListener()); return null; } ISourceViewer sourceViewer = (ISourceViewer) editorPart.getAdapter(ITextOperationTarget.class); if (sourceViewer == null) return null; IDocument document = sourceViewer.getDocument(); return document; }
private IDocument getDocumentForEditor(IEditorPart editorPart) { if (editorPart instanceof MultiPageEditorPart) { return null; } ISourceViewer sourceViewer = (ISourceViewer) editorPart.getAdapter(ITextOperationTarget.class); IDocument document = sourceViewer.getDocument(); return document; }
public static ISourceViewer fromEditorPart(IEditorPart editorPart) { Object activeEditor = editorPart; if (editorPart instanceof MultiPageEditorPart) { MultiPageEditorPart multiPageEditorPart = (MultiPageEditorPart) editorPart; activeEditor = multiPageEditorPart.getSelectedPage(); } if (activeEditor instanceof AbstractTextEditor) { return fromAbstractTextEditor((AbstractTextEditor) activeEditor); } else { logger.info("Unable to get ISourceViewer from " + editorPart + " of type " + editorPart.getClass().getCanonicalName()); return null; } }
@Override public String createAdditionalPage(MultiPageEditorPart parent, IFileEditorInput file, int pageNum) { return null; }
@Override public String createAdditionalPage(MultiPageEditorPart parent, IFileEditorInput file, int pageNum) { // No additional pages, so nothing to do return null; }
@Override public String createAdditionalPage(MultiPageEditorPart parent, IFileEditorInput file, int pageNum) { return source.createAdditionalPage(parent, file, pageNum); }
public PDEMultiPageEditorSite(MultiPageEditorPart multiPageEditor, IEditorPart editor) { super(multiPageEditor, editor); }
/** * Get the next position off the global mark ring and move to that file and location * * @param editor * @param document * @param currentSelection * @param norotate - if true, pop else rotate and pop * @return NO_OFFSET * @throws BadLocationException */ protected int doTransform(ITextEditor editor, IDocument document, ITextSelection currentSelection, boolean norotate, boolean isTags) throws BadLocationException { // get editor and offset IBufferLocation location = (isTags ? MarkUtils.popTagMark() : MarkUtils.popGlobalMark(norotate)); if (location != null) { if (currentSelection != null && location.getEditor() == editor && location.getOffset() == currentSelection.getOffset()) { // if we're already at the global mark location, move to next location // recurse with no selection to avoid infinite loop if only one global location return doTransform(editor,document,null,norotate, isTags); } ITextEditor jumpTo = location.getEditor(); int offset = location.getOffset(); IWorkbenchPage page = getWorkbenchPage(); IEditorPart part = jumpTo; if (part != null) { // move to the correct page IEditorPart apart = part; IEditorSite esite = part.getEditorSite(); if (esite instanceof MultiPageEditorSite) { apart = ((MultiPageEditorSite)esite).getMultiPageEditor(); // handle multi page by activating the correct part within the parent if (apart instanceof MultiPageEditorPart) { ((MultiPageEditorPart)apart).setActiveEditor(part); } } // check to make sure the editor is still valid if (page.findEditor(apart.getEditorInput()) != null) { // then activate page.activate(apart); page.bringToTop(apart); if (part instanceof ITextEditor) { selectAndReveal((ITextEditor) part,offset,offset); EmacsPlusUtils.clearMessage(part); } } else { EmacsPlusUtils.showMessage(editor, String.format(BAD_MARK, apart.getTitle()), true); } } } else { beep(); } return NO_OFFSET; }
/** * @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(org.eclipse.ui.texteditor.ITextEditor, java.lang.Object) */ public boolean doExecuteResult(ITextEditor editor, Object minibufferResult) { if (minibufferResult != null) { String key = (String)minibufferResult; IRegisterLocation location = TecoRegister.getInstance().getLocation(key); if (location != null) { IWorkbenchPage page = getWorkbenchPage(); IEditorPart part = location.getEditor(); int offset = location.getOffset(); if (part != null) { // move to the correct page IEditorPart apart = part; IEditorSite esite = part.getEditorSite(); if (esite instanceof MultiPageEditorSite) { apart = ((MultiPageEditorSite)esite).getMultiPageEditor(); // handle multi page by activating the correct part within the parent if (apart instanceof MultiPageEditorPart) { ((MultiPageEditorPart)apart).setActiveEditor(part); } } // now activate page.activate(apart); page.bringToTop(apart); } else { // restore the resource from the file system if (location.getPath() != null) { try { // loads and activates part = IDE.openEditor(page, location.getPath(), true); if (part instanceof IEditorPart) { if (part instanceof MultiPageEditorPart) { IEditorPart[] parts = ((MultiPageEditorPart)part).findEditors(part.getEditorInput()); // TODO this will only work on the first load of a multi page // There is no supported way to determine the correct sub part in this case // Investigate org.eclipse.ui.PageSwitcher (used in org.eclipse.ui.part.MultiPageEditorPart) // as a means for locating the correct sub page at this level for (int i = 0; i < parts.length; i++) { if (parts[i] instanceof ITextEditor) { ((MultiPageEditorPart)part).setActiveEditor(parts[i]); part = parts[i]; break; } } } location.setEditor((ITextEditor)part); } } catch (PartInitException e) { showResultMessage(editor, String.format(BAD_LOCATION,key + ' ' + e.getLocalizedMessage()), true); } } else { showResultMessage(editor, String.format(NO_LOCATION,key), true); } } if (part instanceof ITextEditor) { ((ITextEditor) part).selectAndReveal(offset, 0); showResultMessage(editor, String.format(LOCATED, key), false); } else { } } else { showResultMessage(editor, NO_REGISTER, true); } } return true; }
public UrnMultiPageEditorSite(MultiPageEditorPart multiPageEditor, IEditorPart editor) { super(multiPageEditor, editor); }
/** * Directs the service to draw one of its additional pages and add it to the * MultiPageEditorPart. The expected use is to call * creatAddionalPage(parent, file, 1), createAdditonalPage(parent, file, 2), * etc. until all additional pages have been drawn in separate tabs. * * @param parent * The part which the page will be added to. * @param file * The file to use as input for the page. * @param pageNum * The id of the page to be drawn. * * @return The name of the new page, to be displayed as the title of the tab * containing it */ public String createAdditionalPage(MultiPageEditorPart parent, IFileEditorInput file, int pageNum);