private void tryValidateManifestInEditor(final IResourceDelta delta) { if (isWorkbenchRunning()) { Display.getDefault().asyncExec(() -> { final IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow(); if (null != window) { final IWorkbenchPage page = window.getActivePage(); for (final IEditorReference editorRef : page.getEditorReferences()) { if (isEditorForResource(editorRef, delta.getResource())) { final IWorkbenchPart part = editorRef.getPart(true); if (part instanceof XtextEditor) { editorCallback.afterSave((XtextEditor) part); return; } } } } }); } }
/** * Obtains all editors that are currently opened. * @return the collection of the opened editors */ public static List<IEditorPart> getEditors() { List<IEditorPart> editors = new ArrayList<IEditorPart>(); IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); for (IWorkbenchWindow window : windows) { IWorkbenchPage[] pages = window.getPages(); for (IWorkbenchPage page : pages) { IEditorReference[] refs = page.getEditorReferences(); for (IEditorReference ref : refs) { IEditorPart part = ref.getEditor(false); if (part != null) { editors.add(part); } } } } return editors; }
public void closeConnectorEditors() { IWorkbenchPage activePage = PlatformUI .getWorkbench() .getActiveWorkbenchWindow() .getActivePage(); if (activePage != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof ConnectorEditorInput)) { if (((ConnectorEditorInput)editorInput).is(getObject())) activePage.closeEditor(editorRef.getEditor(false),true); } } catch(PartInitException e) { ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'"); } } } }
public void closeConnectorEditors(Connector connector) { IWorkbenchPage activePage = PlatformUI .getWorkbench() .getActiveWorkbenchWindow() .getActivePage(); if (activePage != null) { if (connector != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof ConnectorEditorInput)) { if (((ConnectorEditorInput)editorInput).is(connector)) { activePage.closeEditor(editorRef.getEditor(false),true); break; } } } catch(PartInitException e) { ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'"); } } } } }
public void closeSequenceEditors(Sequence sequence) { IWorkbenchPage activePage = PlatformUI .getWorkbench() .getActiveWorkbenchWindow() .getActivePage(); if (activePage != null) { if (sequence != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof SequenceEditorInput)) { if (((SequenceEditorInput)editorInput).is(sequence)) { activePage.closeEditor(editorRef.getEditor(false),true); break; } } } catch(PartInitException e) { ConvertigoPlugin.logException(e, "Error while retrieving the sequence editor '" + editorRef.getName() + "'"); } } } } }
private IEditorPart getConnectorEditor(IWorkbenchPage activePage, Connector connector) { IEditorPart editorPart = null; if (activePage != null) { if (connector != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof ConnectorEditorInput)) { if (((ConnectorEditorInput)editorInput).is(connector)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
private void closeComponentFileEditor(final IFile file) { try { IWorkbenchPage activePage = PlatformUI .getWorkbench() .getActiveWorkbenchWindow() .getActivePage(); for (IEditorReference editorReference : activePage.getEditorReferences()) { IEditorInput editorInput = editorReference.getEditorInput(); if (editorInput instanceof ComponentFileEditorInput) { ComponentFileEditorInput cfei = (ComponentFileEditorInput) editorInput; if (cfei.getFile().equals(file)) { activePage.closeEditor(editorReference.getEditor(false), true); return; } } } } catch (Exception e) { } }
public IEditorPart getConnectorEditor(Connector connector) { IEditorPart editorPart = null; IWorkbenchPage activePage = getActivePage(); if (activePage != null) { if (connector != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof ConnectorEditorInput)) { if (((ConnectorEditorInput)editorInput).is(connector)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
@Override public void closeAllEditors(boolean save) { super.closeAllEditors(save);// will close any child component editor ApplicationComponent application = (ApplicationComponent) getObject(); synchronized (application) { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (activePage != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i = 0; i < editorRefs.length; i++) { IEditorReference editorRef = (IEditorReference) editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if (editorInput != null && editorInput instanceof ApplicationComponentEditorInput) { if (((ApplicationComponentEditorInput) editorInput).is(application)) { activePage.closeEditor(editorRef.getEditor(false),false); } } } catch(Exception e) { } } } } }
public void closeAllEditors(boolean save) { MobileComponent mc = getObject(); IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (activePage != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i = 0; i < editorRefs.length; i++) { IEditorReference editorRef = (IEditorReference) editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if (editorInput != null && editorInput instanceof ComponentFileEditorInput) { if (((ComponentFileEditorInput)editorInput).is(mc) || ((ComponentFileEditorInput)editorInput).isChildOf(mc)) { activePage.closeEditor(editorRef.getEditor(false),save); } } } catch(Exception e) { } } } }
private IEditorPart getSequenceEditor(IWorkbenchPage activePage, Sequence sequence) { IEditorPart editorPart = null; if (activePage != null) { if (sequence != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof SequenceEditorInput)) { if (((SequenceEditorInput)editorInput).is(sequence)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the sequence editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
public IEditorPart getJscriptTransactionEditor(Transaction transaction) { IEditorPart editorPart = null; IWorkbenchPage activePage = getActivePage(); if (activePage != null) { if (transaction != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof JscriptTransactionEditorInput)) { if (((JscriptTransactionEditorInput)editorInput).transaction.equals(transaction)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the jscript transaction editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
/** * Gets the jscript editor associated with given transaction. * !!MUST BE CALLED IN A UI-THREAD!! * @return IEditorPart : the found jscript editor or null */ public IEditorPart getJscriptTransactionEditor(Transaction transaction) { IEditorPart editorPart = null; IWorkbenchPage activePage = getActivePage(); if (activePage != null) { if (transaction != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof JscriptTransactionEditorInput)) { if (((JscriptTransactionEditorInput)editorInput).transaction.equals(transaction)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the jscript transaction editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
public IEditorPart getApplicationComponentEditor() { IEditorPart editorPart = null; IWorkbenchPage activePage = getActivePage(); if (activePage != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof ApplicationComponentEditorInput)) { editorPart = editorRef.getEditor(false); break; } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'"); } } } return editorPart; }
@Override public boolean checkCondition() throws Exception { Display.getDefault().syncExec(new Runnable() { @Override public void run() { IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (ww == null) return; IWorkbenchPage page = ww.getActivePage(); if (page == null) return; IEditorReference[] part = page.getEditorReferences(); if (part == null) return; for (IEditorReference iEditorReference : part) { if( title.equals(iEditorReference.getTitle()) ) found = true; } } }); return !found; }
@Override public boolean checkCondition() throws Exception { Display.getDefault().syncExec(new Runnable() { @Override public void run() { IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (ww == null) return; IWorkbenchPage page = ww.getActivePage(); if (page == null) return; IEditorReference[] part = page.getEditorReferences(); if (part == null) return; for (IEditorReference iEditorReference : part) { if( title.equals(iEditorReference.getTitle()) ) found = true; } } }); return found; }
public static void notifyDbChanged(DbInfo dbinfo) { String action = Activator.getDefault().getPreferenceStore().getString(PG_EDIT_PREF.EDITOR_UPDATE_ACTION); if (action.equals(PG_EDIT_PREF.NO_ACTION)) { return; } for (IWorkbenchWindow wnd : PlatformUI.getWorkbench().getWorkbenchWindows()) { for (IWorkbenchPage page : wnd.getPages()) { for (IEditorReference ref : page.getEditorReferences()) { IEditorPart ed = ref.getEditor(false); if (ed instanceof ProjectEditorDiffer) { notifyDbChanged(dbinfo, (ProjectEditorDiffer) ed, action.equals(PG_EDIT_PREF.UPDATE)); } } } } }
private boolean closeEditorIfAlreadyOpen(IPath jobFilePath, String fileName) { String jobPathRelative = StringUtils.removeStart(jobFilePath.toString(), ".."); jobPathRelative = StringUtils.removeStart(jobPathRelative, "/"); String jobPathAbsolute = StringUtils.replace(jobPathRelative, "/", "\\"); IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWorkbenchWindow != null) { IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); for (IEditorReference editorRefrence : activePage.getEditorReferences()) { if (StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathRelative) || StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathAbsolute) || fileName.equals(editorRefrence.getTitleToolTip())) { IEditorPart editor = editorRefrence.getEditor(true); if (!activePage.closeEditor(editor, true)) { LOGGER.debug("Editor not closed"); } LOGGER.debug("Editor closed"); return true; } } } return false; }
/** * * Called by web socket server, message contain execution tracking status that updated on job canvas. * * @param message the message * @param session the session */ @OnMessage public void updateJobTrackingStatus(String message, Session session) { final String status = message; Display.getDefault().asyncExec(new Runnable() { public void run() { Gson gson = new Gson(); ExecutionStatus executionStatus=gson.fromJson(status, ExecutionStatus.class); IWorkbenchPage page = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage(); IEditorReference[] refs = page.getEditorReferences(); for (IEditorReference ref : refs){ IEditorPart editor = ref.getEditor(false); if(editor instanceof ELTGraphicalEditor){ ELTGraphicalEditor editPart=(ELTGraphicalEditor)editor; if(editPart.getJobId().equals(executionStatus.getJobId()) || (((editPart.getContainer()!=null) && (editPart.getContainer().getUniqueJobId().equals(executionStatus.getJobId()))) && editPart.getContainer().isOpenedForTracking() )){ TrackingStatusUpdateUtils.INSTANCE.updateEditorWithCompStatus(executionStatus, (ELTGraphicalEditor)editor,false); } } } } }); }
/** * Note: it compares marker's resource file name and open editors' file name. * * @param marker * @return if marker's editor is open, return editor, else return null */ public static IEditorPart getOpenEditorOfMarker(final IMarker marker) { final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); for (final IWorkbenchWindow iWorkbenchWindow : windows) { final IWorkbenchPage[] pages = iWorkbenchWindow.getPages(); for (final IWorkbenchPage iWorkbenchPage : pages) { final IEditorReference[] editors = iWorkbenchPage.getEditorReferences(); for (final IEditorReference iEditorReference : editors) { try { if (iEditorReference instanceof IFileEditorInput) { final IFileEditorInput input = (IFileEditorInput) iEditorReference.getEditorInput(); final IFile file = input.getFile(); // TODO Caused by: java.lang.NullPointerException when delete marker on ecore editor. if (file.getFullPath().equals(marker.getResource().getFullPath())) { return iEditorReference.getEditor(false); } } } catch (final PartInitException e) { e.printStackTrace(); } } } } return null; }
/** * Creates and returns a new IGazeHandler object from the specified object * and partRef, or returns null if no handler object is defined for that object. */ public static IGazeHandler createHandler(Object target, IWorkbenchPartReference partRef) { // create gaze handler for a StyledText widget within an EditorPart if (target instanceof StyledText && partRef instanceof IEditorReference) { return new StyledTextGazeHandler(target); //can go back to using partRef } else if (target instanceof Browser) { //create gaze handler for a Browser Stack overflow and Bug Report widget //cannot get associated partRef return new BrowserGazeHandler(target); } else if (target instanceof Tree && partRef instanceof IViewReference && partRef.getTitle().equals("Project Explorer")) { //create gaze handler for a Project Explorer Tree return new ProjectExplorerGazeHandler(target, partRef); } return null; }
/** * Most SVN workspace actions modify the workspace and thus should * save dirty editors. * @see org.tigris.subversion.subclipse.ui.actions.SVNAction#needsToSaveDirtyEditors() */ protected boolean needsToSaveDirtyEditors() { IResource[] selectedResources = getSelectedResources(); if (selectedResources != null && selectedResources.length > 0) { IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences(); for (IEditorReference editorReference : editorReferences) { if (editorReference.isDirty()) { try { IEditorInput editorInput = editorReference.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFile file = ((IFileEditorInput)editorInput).getFile(); if (needsToSave(file, selectedResources)) { return true; } } } catch (PartInitException e) {} } } } return false; }
/** * resets syntax coloring and notifies all ftc editors */ public void notifyColoringChange() { org.eclipse.ui.IWorkbench workbench = org.eclipse.ui.PlatformUI.getWorkbench(); // org.eclipse.ui.IEditorPart editor = // workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor(); for (IEditorReference p : workbench.getActiveWorkbenchWindow().getActivePage().getEditorReferences()) { IEditorPart editor = p.getEditor(false); if (editor != null && editor instanceof FtcEditor) { FtcEditor ftcEditor = (FtcEditor) editor; ftcEditor.invalidateTextRepresentation(); } } }
private void updateJimpleOutline(IFile file) { IWorkbenchWindow activeWorkbenchWindow = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); if(activeWorkbenchWindow==null) return; IEditorReference [] refs = activeWorkbenchWindow.getActivePage().getEditorReferences(); for (int i = 0; i < refs.length; i++){ if (refs[i] == null) continue; if (refs[i].getName() == null) continue; if (refs[i].getName().equals(file.getName())){ JimpleEditor ed = (JimpleEditor) refs[i].getEditor(true).getAdapter(JimpleEditor.class); if (ed != null){ if (ed.getPage() != null){ ed.getPage().getContentOutline(); ed.getPage().getViewer().setInput(ed.getPage().getContentOutline()); ed.getPage().getViewer().refresh(); ed.getPage().getViewer().expandAll(); } } } } }
/** * */ public static List<IEditorReference> checkOpenResources(String title, String message) { List<IEditorReference> dirtyEditors = new LinkedList<IEditorReference>(); IEditorReference[] references = UIHelper.getActivePage().getEditorReferences(); if (references != null) { for (int i = 0; i < references.length; i++) { if (references[i].isDirty()) { dirtyEditors.add(references[i]); } } } if (dirtyEditors.size() > 0) { boolean saveFiles = MessageDialog.openQuestion(getShell(), title, message); if (saveFiles) { // TODO provide a way to select what to save and what to drop // TODO provide a way to cancel return dirtyEditors; } } return new LinkedList<IEditorReference>(); }
/** * Returns true iff some module of the spec is unsaved. Code taken from * UIHelper.promptUserForDirtyModules. This is not optimal because it * returns true even if the dirty module is not a spec module, but that's * not worth worrying about. * * @return */ public boolean existDirtyModules() { final List<IEditorReference> dirtyEditors = new LinkedList<IEditorReference>(); IEditorReference[] references = UIHelper.getActivePage() .getEditorReferences(); if (references != null) { for (int i = 0; i < references.length; i++) { try { if (references[i].isDirty() && references[i].getEditorInput().getName() .endsWith(".tla")) { dirtyEditors.add(references[i]); } } catch (PartInitException e) { Activator.getDefault().logError( "Error getting unsaved resources.", e); } } } return (dirtyEditors.size() > 0); }
public RenameSelectionState(Object element) { fElement = element; fParts = new ArrayList<>(); fSelections = new ArrayList<>(); IWorkbenchWindow dw = JavaScriptPlugin.getActiveWorkbenchWindow(); if (dw == null) { fDisplay = null; return; } fDisplay = dw.getShell().getDisplay(); IWorkbenchPage page = dw.getActivePage(); if (page == null) return; IViewReference vrefs[] = page.getViewReferences(); for (int i = 0; i < vrefs.length; i++) { consider(vrefs[i].getPart(false)); } IEditorReference refs[] = page.getEditorReferences(); for (int i = 0; i < refs.length; i++) { consider(refs[i].getPart(false)); } }
/** * closeAllEditor * void */ public static void closeAllEditor() { for (final IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) { IEditorReference[] editorRefs = window.getActivePage().getEditorReferences(); for (IEditorReference ref : editorRefs) { final IEditorPart editor = ref.getEditor(true); if (editor != null) { if ( editorList.contains(editor.getClass().getName()) || editor.getEditorInput() instanceof UMLEditorInput || editor.getEditorInput() instanceof DiagramEditorInput) { ViewerRegistry.getViewer().getControl().getDisplay().asyncExec(new Runnable() { public void run() { window.getActivePage().closeEditor(editor, true); } }); } } } } }
/** * closeEditor * void */ public void closeEditor() { for (final IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) { IEditorReference[] editorRefs = window.getActivePage().getEditorReferences(); for (IEditorReference ref : editorRefs) { final IEditorPart editor = ref.getEditor(false); if (editor != null && editor.getEditorInput() instanceof UMLEditorInput) { ViewerRegistry.getViewer().getControl().getDisplay().syncExec(new Runnable() { public void run() { window.getActivePage().closeEditor(editor, false); } }); } else if (editor != null && editor.getEditorInput() instanceof DiagramEditorInput) { ViewerRegistry.getViewer().getControl().getDisplay().syncExec(new Runnable() { public void run() { window.getActivePage().closeEditor(editor, false); } }); } } } }
/** * Find the selected diagram editor. * * @return the selected diagram editor */ public static TriqDiagramEditor getSelectedDiagramEditor() { TriqDiagramEditor result = null; IWorkbenchPage page = EclipseUtils.getPage(); if (page != null) { IEditorPart activeEditor = page.getActiveEditor(); if (activeEditor instanceof TriqDiagramEditor) { result = (TriqDiagramEditor) activeEditor; } else { for (IEditorReference editorRef : page.getEditorReferences()) { if (editorRef.getId().contains("triquetrum")) { result = ((TriqDiagramEditor) editorRef.getEditor(true)); break; } } } } return result; }
@Inject(optional=true) protected void initialize(final IWorkbench workbench) { Assert.isNotNull(Display.getCurrent()); partListener = new PartListener(); pageListener = new PageListener(); for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) { window.addPageListener(pageListener); for (IWorkbenchPage page : window.getPages()) { page.addPartListener(partListener); for (IEditorReference editorRef : page.getEditorReferences()) { Pair<URI, IXtextDocument> entry = getEntry(editorRef); if (entry != null) { resourceUri2document.put(entry.getFirst(), entry.getSecond()); } } } } }
public void reconcileAllEditors(IWorkbench workbench, final boolean saveAll, IProgressMonitor monitor) { SubMonitor pm0 = SubMonitor.convert(monitor, workbench.getWorkbenchWindowCount()); for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) { SubMonitor pm1 = pm0.newChild(1).setWorkRemaining(window.getPages().length); for (IWorkbenchPage page : window.getPages()) { SubMonitor pm2 = pm1.newChild(1).setWorkRemaining(2 * page.getEditorReferences().length); for (IEditorReference editorReference : page.getEditorReferences()) { if (pm2.isCanceled()) return; IEditorPart editor = editorReference.getEditor(false); if (editor != null) { if (editor instanceof XtextEditor) waitForReconciler((XtextEditor) editor); if (editor.isDirty() && saveAll) editor.doSave(pm2.newChild(1)); } pm2.worked(1); } } } }
/** * @generated */ public boolean matches(IEditorReference editorRef, IEditorInput input) { IEditorInput editorInput; try { editorInput = editorRef.getEditorInput(); } catch (PartInitException e) { return false; } if (editorInput.equals(input)) { return true; } if (editorInput instanceof URIEditorInput && input instanceof URIEditorInput) { return ((URIEditorInput) editorInput).getURI().equals( ((URIEditorInput) input).getURI()); } return false; }
/** * @return The last active editor with the given editor ID in the current * active workbench page. */ public static IEditorPart getLastEditor(String editorId) { if (INSTANCE == null) { // not yet initialized, e.g. when another early startups blocks us! // Let's try to get any editor with the specified id instead. if (PlatformUI.getWorkbench() != null) { final IWorkbenchWindow window = PlatformUI.getWorkbench() .getActiveWorkbenchWindow(); if (window != null) { final IWorkbenchPage page = window.getActivePage(); if (page != null) { for (IEditorReference ref : page.getEditorReferences()) { if (ref.getId().equals(editorId)) { return ref.getEditor(false); } } } } } return null; } return INSTANCE.getEditorById(editorId); }
protected Optional<IEditorPart> getEditorWithSameResource() { ArrayList<IEditorReference> currentEditors = Lists.newArrayList( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()); Optional<IEditorPart> editorWithSameResource = currentEditors.stream().filter(e -> { try { IEditorInput otherInput = e.getEditorInput(); IEditorInput thisInput = this.getEditorInput(); return ID.equals(e.getId()) && !otherInput.equals(thisInput) && ((IFileEditorInput) otherInput) .getFile().getLocationURI().equals(((IFileEditorInput) thisInput).getFile().getLocationURI()); } catch (PartInitException e1) { e1.printStackTrace(); return false; } }).map(e -> e.getEditor(false)).findFirst(); return editorWithSameResource; }
public static boolean multiApply( Function<EntryEditor, Boolean> func, IEditorPart exclude) { for(IWorkbenchPage page: Helper.iterWBPages()) { final IEditorReference[] editorRefs = page.findEditors(null, ID, IWorkbenchPage.MATCH_ID); for(IEditorReference editorRef: editorRefs) { final EntryEditor editor = (EntryEditor) editorRef.getEditor(false); if(editor == exclude) { continue; } if(func.apply(editor)) { return true; } } } return false; }
public static void reopenWithGWTJavaEditor(IEditorReference[] openEditors) { IWorkbenchPage page = JavaPlugin.getActivePage(); for (IEditorReference editorRef : openEditors) { try { IEditorPart editor = editorRef.getEditor(false); IEditorInput input = editorRef.getEditorInput(); // Close the editor, prompting the user to save if document is dirty if (page.closeEditor(editor, true)) { // Re-open the .java file in the GWT Java Editor IEditorPart gwtEditor = page.openEditor(input, GWTJavaEditor.EDITOR_ID); // Save the file from the new editor if the Java editor's // auto-format-on-save action screwed up the JSNI formatting gwtEditor.doSave(null); } } catch (PartInitException e) { GWTPluginLog.logError(e, "Could not open GWT Java editor on {0}", editorRef.getTitleToolTip()); } } }
private boolean tryToGetInput(ClosedPart closedPart, IPresentablePart part) { IWorkbenchPartReference partReference = getPartReference(part); if(partReference == null){ partReference = getMatchingPart(closedPart); } if(!(partReference instanceof IEditorReference)){ return false; } // XXX probably this will init editor which is not initialized yet, // just before it will be closed.... try { String id = partReference.getId(); IEditorInput editorInput = ((IEditorReference)partReference).getEditorInput(); closedPart.setEditorInfo(new EditorInfo(editorInput, id, getPartNumber(part))); return closedPart.getEditorInfo().isOpenable(); } catch (PartInitException e) { PresentationPlugin.getDefault().getLog().log( new Status(IStatus.ERROR, "VSPresentation", 0, "Could not get editor input for: " + closedPart.name, e)); } return false; }