Java Code Examples for org.eclipse.ui.IWorkbench#getWorkbenchWindows()
The following examples show how to use
org.eclipse.ui.IWorkbench#getWorkbenchWindows() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenDocumentTracker.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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()); } } } } }
Example 2
Source File: UIPlugin.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
private void removePerspectiveListener() { IWorkbench workbench = null; try { workbench = PlatformUI.getWorkbench(); } catch (Exception e) { // ignore, may be running headless, like in tests } if (workbench != null) { IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); for (IWorkbenchWindow window : windows) { window.removePerspectiveListener(perspectiveListener); } PlatformUI.getWorkbench().removeWindowListener(windowListener); } }
Example 3
Source File: JavaHistoryActionImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
final JavaEditor getEditor(IFile file) { FileEditorInput fei= new FileEditorInput(file); IWorkbench workbench= JavaPlugin.getDefault().getWorkbench(); IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); for (int i= 0; i < windows.length; i++) { IWorkbenchPage[] pages= windows[i].getPages(); for (int x= 0; x < pages.length; x++) { IEditorPart[] editors= pages[x].getDirtyEditors(); for (int z= 0; z < editors.length; z++) { IEditorPart ep= editors[z]; if (ep instanceof JavaEditor) { JavaEditor je= (JavaEditor) ep; if (fei.equals(je.getEditorInput())) return (JavaEditor) ep; } } } } return null; }
Example 4
Source File: ExampleDropSupportRegistrar.java From statecharts with Eclipse Public License 1.0 | 6 votes |
private void registerExampleDropAdapter() { UIJob registerJob = new UIJob(Display.getDefault(), "Registering example drop adapter.") { { setPriority(Job.SHORT); setSystem(true); } @Override public IStatus runInUIThread(IProgressMonitor monitor) { IWorkbench workbench = PlatformUI.getWorkbench(); workbench.addWindowListener(workbenchListener); IWorkbenchWindow[] workbenchWindows = workbench .getWorkbenchWindows(); for (IWorkbenchWindow window : workbenchWindows) { workbenchListener.hookWindow(window); } return Status.OK_STATUS; } }; registerJob.schedule(); }
Example 5
Source File: TmfCommonProjectElement.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Close open editors associated with this experiment. */ public void closeEditors() { IFile file = getBookmarksFile(); FileEditorInput input = new FileEditorInput(file); IWorkbench wb = PlatformUI.getWorkbench(); for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) { for (IWorkbenchPage wbPage : wbWindow.getPages()) { for (IEditorReference editorReference : wbPage.getEditorReferences()) { try { if (editorReference.getEditorInput().equals(input)) { wbPage.closeEditor(editorReference.getEditor(false), false); } } catch (PartInitException e) { Activator.getDefault().logError(NLS.bind(Messages.TmfCommonProjectElement_ErrorClosingEditor, getName()), e); } } } } }
Example 6
Source File: EditorUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns an array of all editors that have an unsaved content. If the identical content is * presented in more than one editor, only one of those editor parts is part of the result. * @param skipNonResourceEditors if <code>true</code>, editors whose inputs do not adapt to {@link IResource} * are not saved * * @return an array of dirty editor parts * @since 3.4 */ public static IEditorPart[] getDirtyEditors(boolean skipNonResourceEditors) { Set<IEditorInput> inputs= new HashSet<IEditorInput>(); List<IEditorPart> result= new ArrayList<IEditorPart>(0); IWorkbench workbench= PlatformUI.getWorkbench(); IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); for (int i= 0; i < windows.length; i++) { IWorkbenchPage[] pages= windows[i].getPages(); for (int x= 0; x < pages.length; x++) { IEditorPart[] editors= pages[x].getDirtyEditors(); for (int z= 0; z < editors.length; z++) { IEditorPart ep= editors[z]; IEditorInput input= ep.getEditorInput(); if (inputs.add(input)) { if (!skipNonResourceEditors || isResourceEditorInput(input)) { result.add(ep); } } } } } return result.toArray(new IEditorPart[result.size()]); }
Example 7
Source File: UIHelper.java From tlaplus with MIT License | 6 votes |
/** * Closes all windows with a perspective * * @param perspectiveId * a perspective Id pointing the perspective */ public static void closeWindow(String perspectiveId) { IWorkbench workbench = Activator.getDefault().getWorkbench(); // hide intro if (InitialPerspective.ID.equals(perspectiveId)) { workbench.getIntroManager().closeIntro(workbench.getIntroManager().getIntro()); } IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); // closing the perspective opened in a window for (int i = 0; i < windows.length; i++) { IWorkbenchPage page = windows[i].getActivePage(); if (page != null && page.getPerspective() != null && perspectiveId.equals(page.getPerspective().getId())) { windows[i].close(); } } }
Example 8
Source File: UIHelper.java From tlaplus with MIT License | 6 votes |
/** * Retrieves active page * * @return */ public static IWorkbenchPage getActivePage() { final IWorkbenchWindow window = getActiveWindow(); if (window == null) { // try to get a not null window final IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench != null) { IWorkbenchWindow[] workbenchWindows = workbench.getWorkbenchWindows(); for (int i = 0; i < workbenchWindows.length; i++) { if (workbenchWindows[i] != null) { return workbenchWindows[i].getActivePage(); } } return null; } else { return null; } } return window.getActivePage(); }
Example 9
Source File: AppEngineActionProvider.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
private IWorkbenchPage getWorkbenchPage() { IWorkbenchPage page = getActionSite().getViewSite().getAdapter(IWorkbenchPage.class); if (page != null) { return page; } IWorkbenchWindow window = getActionSite().getViewSite().getAdapter(IWorkbenchWindow.class); if (window != null) { return window.getActivePage(); } IWorkbench workbench = getActionSite().getViewSite().getAdapter(IWorkbench.class); if (workbench == null) { workbench = PlatformUI.getWorkbench(); } Preconditions.checkNotNull(workbench); window = workbench.getActiveWorkbenchWindow(); if (window == null) { Preconditions.checkState(workbench.getWorkbenchWindowCount() > 0); window = workbench.getWorkbenchWindows()[0]; } Preconditions.checkNotNull(window); return window.getActivePage(); }
Example 10
Source File: EmacsPlusPreferencePage.java From e4macs with Eclipse Public License 1.0 | 5 votes |
private Shell getDefaultShell() { Shell result = null; IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { result = window.getShell(); } else { IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); if (windows.length > 0) result = windows[0].getShell(); } return result; }
Example 11
Source File: CommonEditorPlugin.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private void addPartListener() { try { IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench != null) { IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); IPartService partService; for (IWorkbenchWindow window : windows) { partService = window.getPartService(); if (partService != null) { partService.addPartListener(fPartListener); } window.addPerspectiveListener(fPerspectiveListener); } // Listen on any future windows PlatformUI.getWorkbench().addWindowListener(fWindowListener); } } catch (Exception e) { // ignore, may be running headless, like in tests } }
Example 12
Source File: JSDTEditorTracker.java From typescript.java with MIT License | 5 votes |
private void init() { if (PlatformUI.isWorkbenchRunning()) { IWorkbench workbench = JSDTTypeScriptUIPlugin.getDefault().getWorkbench(); if (workbench != null) { IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); for (IWorkbenchWindow window : windows) { windowOpened(window); } JSDTTypeScriptUIPlugin.getDefault().getWorkbench().addWindowListener(this); } } }
Example 13
Source File: AllInOneWorkbenchListener.java From typescript.java with MIT License | 5 votes |
private void unhookListeners(final IWorkbench workbench) { // If the display is disposed, then we're shutting down and the // listeners have already been removed. if (workbench.getDisplay().isDisposed()) return; workbench.removeWindowListener(this); // Walk through the workbench windows and unhook the listeners from each // of them. for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) { unhookListeners(window); } }
Example 14
Source File: StartupJob.java From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 | 5 votes |
/** * Runs this job on UI thread. * @param monitor ProgressBar * @return Return Status. */ public IStatus runInUIThread(IProgressMonitor monitor) { CcGlobalConfiguration.getInstance(); try { // TODO: find a better solution... Thread.sleep(WAIT_TIME); } catch (InterruptedException e) { // TODO Auto-generated catch block Logger.log(IStatus.ERROR, e.getMessage()); Logger.log(IStatus.INFO, Logger.getStackTrace(e)); } Logger.log(IStatus.INFO, "adding addResourceChangeListener "); ResourcesPlugin.getWorkspace().addResourceChangeListener(new ResourceChangeListener(), IResourceChangeEvent.POST_BUILD | IResourceDelta.OPEN | IResourceChangeEvent.PRE_DELETE); ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); commandService.addExecutionListener(new ISaveCommandExecutionListener()); // check all open projects for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { projectOpened(project); } Logger.log(IStatus.INFO, "CodeChecker reports had been parsed."); // check all open windows IWorkbench wb = PlatformUI.getWorkbench(); for (IWorkbenchWindow win : wb.getWorkbenchWindows()) { addListenerToWorkbenchWindow(win); } return Status.OK_STATUS; }
Example 15
Source File: ResourceCloseManagement.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Saves any modified files after confirmation from the user (if needed). * * @return true if the files were saved, false otherwise. */ public static boolean checkAndSaveAllFiles( ) { ArrayList<IEditorPart> editorsToSave = new ArrayList<IEditorPart>( ); IWorkbench workbench = PlatformUI.getWorkbench( ); IWorkbenchWindow windows[] = workbench.getWorkbenchWindows( ); for ( int currWindow = 0; currWindow < windows.length; currWindow++ ) { IWorkbenchPage pages[] = windows[currWindow].getPages( ); for ( int currPage = 0; currPage < pages.length; currPage++ ) { IEditorReference editors[] = pages[currPage].getEditorReferences( ); for ( IEditorReference currEditorRef : editors ) { IEditorPart currEditor = currEditorRef.getEditor( false ); if ( currEditor != null && currEditor.isDirty( ) ) { editorsToSave.add( currEditor ); } } } } // Ask to save open files return checkAndSaveDirtyFiles( editorsToSave ); }
Example 16
Source File: CommonEditorPlugin.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private void removePartListener() { IWorkbench workbench = null; try { workbench = PlatformUI.getWorkbench(); } catch (Exception e) { // ignore, may be running headless, like in tests } if (workbench != null) { IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); IPartService partService; for (IWorkbenchWindow window : windows) { partService = window.getPartService(); if (partService != null) { partService.removePartListener(fPartListener); } window.removePerspectiveListener(fPerspectiveListener); } PlatformUI.getWorkbench().removeWindowListener(fWindowListener); } }
Example 17
Source File: SyncUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void reconcileAllEditors(IWorkbench workbench, final boolean saveAll, final IProgressMonitor monitor) { for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) { for (IWorkbenchPage page : window.getPages()) { for (IEditorReference editorReference : page.getEditorReferences()) { if (monitor.isCanceled()) return; final IEditorPart editor = editorReference.getEditor(false); if (editor != null) { if (editor instanceof XtextEditor) { waitForReconciler((XtextEditor) editor); } if (saveAll) { Display display = workbench.getDisplay(); display.syncExec(new Runnable() { @Override public void run() { if (editor.isDirty()) { editor.doSave(monitor); } } }); } } } } } }
Example 18
Source File: DatastoreIndexesUpdatedStatusHandler.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** Find the current window page; should never be {@code null}. */ private IWorkbenchPage getActivePage() { IWorkbench workbench = PlatformUI.getWorkbench(); Preconditions.checkState(workbench.getWorkbenchWindowCount() > 0); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) { window = workbench.getWorkbenchWindows()[0]; } return window.getActivePage(); }
Example 19
Source File: WorkbenchUtils.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
public static IWorkbenchWindow[] getWorkbenchWindows() { IWorkbench workbench = PlatformUI.getWorkbench(); return workbench.getWorkbenchWindows(); }
Example 20
Source File: DeleteEditorFileHandler.java From eclipse-extras with Eclipse Public License 1.0 | 4 votes |
private static void closeEditors( IWorkbench workbench, File file ) { for( IWorkbenchWindow workbenchWindow : workbench.getWorkbenchWindows() ) { closeEditors( workbenchWindow, file ); } }