Java Code Examples for org.eclipse.ui.IWorkbench#getActiveWorkbenchWindow()
The following examples show how to use
org.eclipse.ui.IWorkbench#getActiveWorkbenchWindow() .
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: Hub.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * get the currently active Shell. If no such Shell exists, it will be created using dhe default * Display. * * @return always a valid shell. Never null */ public static Shell getActiveShell(){ if (plugin != null) { IWorkbench wb = plugin.getWorkbench(); if (wb != null) { IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); if (win != null) { return win.getShell(); } } } Display dis = UiDesk.getDisplay(); if (dis == null) { dis = PlatformUI.createDisplay(); } return new Shell(dis); }
Example 2
Source File: ItemSelectedPropertyTester.java From ice with Eclipse Public License 1.0 | 6 votes |
/** * Gets the <code>IViewPart</code> associated with the specified ID. * * @param ID * The string ID of the desired <code>IViewPart</code>. * @return The <code>IViewPart</code> corresponding to the specified ID, or * null if it could not be found. */ protected static IViewPart getViewPart(String ID) { IViewPart viewPart = null; // We need to check all intermediate workbench components for null lest // we get exceptions, particularly when the workbench is starting. IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench != null && !workbench.isStarting()) { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { // Try to get the IViewPart with the specified ID. viewPart = page.findView(ID); } } } return viewPart; }
Example 3
Source File: XsltQuickFix.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Returns {@link IDocument} in the open editor, or null if the editor * is not open. */ static IDocument getCurrentDocument(IFile file) { try { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); IEditorPart editorPart = ResourceUtil.findEditor(activePage, file); if (editorPart != null) { IDocument document = editorPart.getAdapter(IDocument.class); return document; } return null; } catch (IllegalStateException ex) { //If workbench does not exist return null; } }
Example 4
Source File: ViewUtils.java From saros with GNU General Public License v2.0 | 6 votes |
public static void openSarosView() { /* * TODO What to do if no WorkbenchWindows are are active? */ final IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench == null) return; final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) return; try { window.getActivePage().showView(SarosView.ID, null, IWorkbenchPage.VIEW_CREATE); } catch (PartInitException e) { log.error("could not open Saros view (id: " + SarosView.ID + ")", e); // $NON-NLS-1$ } }
Example 5
Source File: OpenJavaBrowsingPerspectiveAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public void run() { IWorkbench workbench= JavaPlugin.getDefault().getWorkbench(); IWorkbenchWindow window= workbench.getActiveWorkbenchWindow(); IWorkbenchPage page= window.getActivePage(); IAdaptable input; if (page != null) input= page.getInput(); else input= ResourcesPlugin.getWorkspace().getRoot(); try { workbench.showPerspective(JavaUI.ID_BROWSING_PERSPECTIVE, window, input); } catch (WorkbenchException e) { ExceptionHandler.handle(e, window.getShell(), ActionMessages.OpenJavaBrowsingPerspectiveAction_dialog_title, ActionMessages.OpenJavaBrowsingPerspectiveAction_error_open_failed); } }
Example 6
Source File: TexlipsePlugin.java From texlipse with Eclipse Public License 1.0 | 6 votes |
/** * Returns the current workbench page. * * Used by getCurrentProject() and by gotoMarker(). * @return the currently open WorkbenchPage or <code>null</code> if none */ public static IWorkbenchPage getCurrentWorkbenchPage() { IWorkbench workbench = getDefault().getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) { Display display = workbench.getDisplay(); display.syncExec(new Runnable() { public void run() { currentWindow = TexlipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); }}); window = currentWindow; } return window.getActivePage(); }
Example 7
Source File: PyOpenEditor.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Opens some editor from an editor input (See PySourceLocatorBase for obtaining it) * * @param file the editor input * @return the part correspondent to the editor * @throws PartInitException */ public static IEditorPart openEditorInput(IEditorInput file) throws PartInitException { final IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench == null) { throw new RuntimeException("workbench cannot be null"); } IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); if (activeWorkbenchWindow == null) { throw new RuntimeException( "activeWorkbenchWindow cannot be null (we have to be in a ui thread for this to work)"); } IWorkbenchPage wp = activeWorkbenchWindow.getActivePage(); // File is inside the workspace return IDE.openEditor(wp, file, PyEdit.EDITOR_ID); }
Example 8
Source File: ASMDEditorUtils.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** {@inheritDoc} */ public XtextEditor getActiveXtextEditor() { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); if (workbenchWindow == null) { return null; } IWorkbenchPage activePage = workbenchWindow.getActivePage(); if (activePage == null) { return null; } IEditorPart activeEditor = activePage.getActiveEditor(); if (activeEditor instanceof XtextEditor) { return (XtextEditor) activeEditor; // return null; } // XtextEditor xtextEditor = (XtextEditor) activeEditor.getAdapter(XtextEditor.class); // return xtextEditor; return null; }
Example 9
Source File: FilenameDifferentiator.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public void dispose() { IWorkbench workbench = null; try { workbench = PlatformUI.getWorkbench(); } catch (Exception e) { // ignore } if (workbench != null) { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { page.removePartListener(this); } } } if (baseNames != null) { baseNames.clear(); baseNames = null; } }
Example 10
Source File: ExtLibPanelUtil.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
public static IWorkbenchWindow getActiveWorkbenchWindow(){ IWorkbench workbench = PlatformUI.getWorkbench(); if(null != workbench){ return workbench.getActiveWorkbenchWindow(); } return null; }
Example 11
Source File: UIUtils.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public static IWorkbenchWindow getActiveWorkbenchWindow() { if (!PlatformUI.isWorkbenchRunning()) { return null; } IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench == null) { return null; } return workbench.getActiveWorkbenchWindow(); }
Example 12
Source File: TmfViewFactoryTest.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Test method for * {@link org.eclipse.tracecompass.tmf.ui.views.TmfViewFactory#newView(java.lang.String, boolean)}. */ @Test public void testNewView() { IViewPart firstView = TmfViewFactory.newView(checkNotNull(TmfViewStub.TMF_VIEW_STUB_ID), false); IViewPart sameAsFirstView = TmfViewFactory.newView(checkNotNull(TmfViewStub.TMF_VIEW_STUB_ID), false); IViewPart secondView = TmfViewFactory.newView(checkNotNull(TmfViewStub.TMF_VIEW_STUB_ID), true); IViewPart failView1 = TmfViewFactory.newView("this.is.a.failing.view.id", false); IViewPart failView2 = TmfViewFactory.newView("this.is.a.failing.view.id", true); assertNotNull("Failed to spawn first view", firstView); assertEquals("Same id returned different instance", sameAsFirstView, firstView); assertNotNull("Failed to open second view with suffix", secondView); assertNull("Expected to fail on dummy view id", failView1); assertNull("Expected to fail on dummy view id with suffix", failView2); /** Test for new view from a duplicate view */ /* Fetch duplicate view complete id */ IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); IWorkbenchPage page = win.getActivePage(); IViewReference[] viewRefs = page.getViewReferences(); String fullId = null; for (IViewReference view : viewRefs) { if (view.getSecondaryId() != null && view.getId().equals(TmfViewStub.TMF_VIEW_STUB_ID)) { assertTrue("Instanceof a TmfViewStub", view.getView(false) instanceof TmfViewStub); fullId = ((TmfViewStub) view.getView(false)).getViewId(); break; } } assertNotNull(fullId); IViewPart thirdView = TmfViewFactory.newView(fullId, true); assertNotNull("Creation from a view id with suffix failed", fullId); assertFalse("New view from view id with suffix was not created", Arrays.asList(viewRefs).contains(thirdView)); }
Example 13
Source File: H5ValuePage.java From dawnsci with Eclipse Public License 1.0 | 5 votes |
private static IWorkbenchPage getActivePage() { final IWorkbench bench = PlatformUI.getWorkbench(); if (bench == null) return null; final IWorkbenchWindow window = bench.getActiveWorkbenchWindow(); if (window == null) return null; return window.getActivePage(); }
Example 14
Source File: RcpWindowAdvisor.java From olca-app with Mozilla Public License 2.0 | 5 votes |
private boolean isStandardPerspective() { IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); IWorkbenchPage page = win.getActivePage(); IPerspectiveDescriptor perspective = page.getPerspective(); return perspective.getId().equals(RcpPerspective.ID); }
Example 15
Source File: CustomCaretListener.java From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void caretMoved(CaretEvent event) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) return; if (window.getPartService() == null) return; if (window.getPartService().getActivePart() == null) return; if (window.getPartService().getActivePart().getSite() == null) return; if (window.getPartService().getActivePart().getSite().getPage() == null) return; if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return; if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return; // log file if one is opened by default IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput(); if (input instanceof IURIEditorInput) { URI uri = ((IURIEditorInput)input).getURI(); if (uri != null && uri.getPath() != null) { String currentFile = uri.getPath(); long currentTime = System.currentTimeMillis() / 1000; if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) { WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), false); WakaTime.getDefault().lastFile = currentFile; WakaTime.getDefault().lastTime = currentTime; } } } }
Example 16
Source File: CustomExecutionListener.java From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void postExecuteSuccess(String commandId, Object returnValue) { if (commandId.equals("org.eclipse.ui.file.save")) { IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench == null) return; IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) return; if (window.getPartService() == null) return; if (window.getPartService().getActivePart() == null) return; if (window.getPartService().getActivePart().getSite() == null) return; if (window.getPartService().getActivePart().getSite().getPage() == null) return; if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return; if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return; // log file save event IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput(); if (input instanceof IURIEditorInput) { URI uri = ((IURIEditorInput)input).getURI(); if (uri != null && uri.getPath() != null) { String currentFile = uri.getPath(); long currentTime = System.currentTimeMillis() / 1000; // always log writes WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), true); WakaTime.getDefault().lastFile = currentFile; WakaTime.getDefault().lastTime = currentTime; } } } }
Example 17
Source File: EmptyPageSite.java From dawnsci with Eclipse Public License 1.0 | 5 votes |
/** * @return IWorkbenchPage */ private static final IWorkbenchPage getActivePage() { final IWorkbench bench = PlatformUI.getWorkbench(); if (bench==null) return null; final IWorkbenchWindow window = bench.getActiveWorkbenchWindow(); if (window==null) return null; return window.getActivePage(); }
Example 18
Source File: ERModelUtil.java From erflute with Apache License 2.0 | 5 votes |
public static IEditorPart getActiveEditor() { final IWorkbench workbench = PlatformUI.getWorkbench(); final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); final IWorkbenchPage page = window.getActivePage(); final IEditorPart editorPart = page.getActiveEditor(); return editorPart; }
Example 19
Source File: SWTUtils.java From saros with GNU General Public License v2.0 | 5 votes |
/** @swt Needs to be called from the SWT-UI thread, otherwise <code>null</code> is returned. */ public static IViewPart findView(String id) { IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench == null) return null; IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) return null; IWorkbenchPage page = window.getActivePage(); if (page == null) return null; return page.findView(id); }
Example 20
Source File: UIHelper.java From tlaplus with MIT License | 4 votes |
/** * Attaches the perspective listener to active window * * @param listener */ public static void addPerspectiveListener(IPerspectiveListener listener) { IWorkbench workbench = Activator.getDefault().getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); window.addPerspectiveListener(listener); }