Java Code Examples for org.eclipse.ui.IWorkbenchWindow#getActivePage()
The following examples show how to use
org.eclipse.ui.IWorkbenchWindow#getActivePage() .
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: BonitaPerspectivesUtils.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * Switch to the perspective with id given as parameter * * @param perspectiveID */ public static synchronized void switchToPerspective(final String perspectiveID) { final IWorkbench workbench = PlatformUI.getWorkbench(); final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { final IWorkbenchPage activePage = window.getActivePage(); if (activePage != null) { final IPerspectiveDescriptor activePerspective = activePage.getPerspective(); if (activePerspective == null || !activePerspective.getId().equals(perspectiveID)) { final IPerspectiveRegistry registry = workbench.getPerspectiveRegistry(); final IWorkbenchPage page = window.getActivePage(); final IPerspectiveDescriptor desc = registry.findPerspectiveWithId(perspectiveID); page.setPerspective(desc); } } } }
Example 2
Source File: AbstractBDMFileStore.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override protected void doClose() { IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWorkbenchWindow != null && activeWorkbenchWindow.getActivePage() != null) { IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); Stream.of(activePage.getEditorReferences()) .filter(editorRef -> { try { return getName().contentEquals(editorRef.getEditorInput().getName()); } catch (PartInitException e) { throw new RuntimeException("an error occured while trying to close the file", e); } }) .forEach(editorRef -> activePage.closeEditor(editorRef.getEditor(true), false)); } }
Example 3
Source File: RenameSelectionState.java From typescript.java with MIT License | 6 votes |
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)); } }
Example 4
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 5
Source File: CopyHandler.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
@Override public boolean isEnabled() { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } // Get the selection IWorkbenchPage page = window.getActivePage(); IWorkbenchPart part = page.getActivePart(); if (part instanceof FilterView) { FilterView tcv = (FilterView) part; ISelection selection = tcv.getSite().getSelectionProvider().getSelection(); // only enable if tree is in focus if (!selection.isEmpty() && tcv.isTreeInFocus()) { return true; } } return false; }
Example 6
Source File: Navigator.java From olca-app with Mozilla Public License 2.0 | 6 votes |
/** * Returns the instance of the navigation view or NULL if there is# no such * instance available. */ public static Navigator getInstance() { 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; IViewPart part = page.findView(ID); if (part instanceof Navigator) return (Navigator) part; return null; }
Example 7
Source File: BrowserEditorInstance.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public void openURL(URL url) throws PartInitException { WebBrowserEditorInput editorInput = new WebBrowserEditorInput(url, style); editorInput.setName(name); editorInput.setToolTipText(tooltip); WebBrowserEditor editor = (WebBrowserEditor) part; IWorkbenchWindow workbenchWindow = WebBrowserUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage workbenchPage = null; if (workbenchWindow != null) { workbenchPage = workbenchWindow.getActivePage(); } if (workbenchPage == null) { throw new PartInitException("Cannot get Workbench page"); //$NON-NLS-1$ } if (editor != null) { editor.init(editor.getEditorSite(), editorInput); workbenchPage.activate(editor); } else { editor = (WebBrowserEditor) workbenchPage.openEditor(editorInput, WebBrowserEditor.EDITOR_ID); hookPart(workbenchPage, editor); } }
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: ActiveEditorTracker.java From statecharts with Eclipse Public License 1.0 | 6 votes |
/** * @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); }
Example 10
Source File: RCPTestSetupHelper.java From tlaplus with MIT License | 6 votes |
/** * Close all open windows, editors, perspectives. Open and reset default perspective. */ private static void resetWorkbench() { try { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); Shell activeShell = Display.getCurrent().getActiveShell(); if (activeShell != null && activeShell != workbenchWindow.getShell()) { activeShell.close(); } page.closeAllEditors(false); page.resetPerspective(); String defaultPerspectiveId = workbench.getPerspectiveRegistry().getDefaultPerspective(); workbench.showPerspective(defaultPerspectiveId, workbenchWindow); page.resetPerspective(); page.showView("org.eclipse.ui.internal.introview"); } catch (WorkbenchException e) { throw new RuntimeException(e); } }
Example 11
Source File: JavadocView.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected Object computeInput(Object input) { if (getControl() == null || ! (input instanceof IJavaElement)) return null; IWorkbenchPart part= null; IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page= window.getActivePage(); if (page != null) { part= page.getActivePart(); } } ISelection selection= null; if (part != null) { IWorkbenchPartSite site= part.getSite(); if (site != null) { ISelectionProvider provider= site.getSelectionProvider(); if (provider != null) { selection= provider.getSelection(); } } } return computeInput(part, selection, (IJavaElement) input, new NullProgressMonitor()); }
Example 12
Source File: EditorUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
public static void openEditor( Object adaptable, File target, String editorId ) throws PartInitException { IWorkbench workbench = PlatformUI.getWorkbench( ); IWorkbenchWindow window = workbench == null ? null : workbench.getActiveWorkbenchWindow( ); IWorkbenchPage page = window == null ? null : window.getActivePage( ); if ( page != null ) { IEditorInput input = null; Object adapter = Platform.getAdapterManager( ) .getAdapter( adaptable, IPathEditorInputFactory.class ); if ( adapter instanceof IPathEditorInputFactory ) { input = ( (IPathEditorInputFactory) adapter ).create( new Path( target.getAbsolutePath( ) ) ); IFile file = (IFile) input.getAdapter( IFile.class ); if ( file != null ) { try { file.refreshLocal( IResource.DEPTH_INFINITE, null ); } catch ( CoreException e ) { // do nothing now } } } if ( input == null ) { input = new ReportEditorInput( target ); } page.openEditor( input, editorId, true ); } }
Example 13
Source File: OpenDashboardHandler.java From developer-studio with Apache License 2.0 | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage(); try { hideIntroView(); hideDashboards(); PlatformUI.getWorkbench().showPerspective(J2EE_PERSPECTIVE_ID, window); page.openEditor(new NullEditorInput(), DASHBOARD_VIEW_ID); } catch (Exception e) { log.error("Cannot open dashboard", e); } return true; }
Example 14
Source File: Starter.java From IndentGuide with MIT License | 5 votes |
public void windowOpened(IWorkbenchWindow window) { if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { IEditorPart part = page.getActiveEditor(); if (part != null) { addListener(part); } } window.getPartService().addPartListener(new PartListener()); } }
Example 15
Source File: SelectedResourceManager.java From texlipse with Eclipse Public License 1.0 | 5 votes |
/** * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow) */ public void windowActivated(IWorkbenchWindow window) { ISelectionService service = window.getSelectionService(); service.addSelectionListener(this); IWorkbenchPage page = window.getActivePage(); if (page != null) { IWorkbenchPart part = page.getActivePart(); if (part != null) { ISelection selection = service.getSelection(); if (selection != null) { selectionChanged(part, selection); } } } }
Example 16
Source File: Exercise3.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 17
Source File: NewFileWizard.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public boolean performFinish() { IFile file = mainPage.createNewFile(); if (file == null) { return false; } selectAndReveal(file); // Open editor on new file. IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow(); try { if (dw != null) { IWorkbenchPage page = dw.getActivePage(); if (page != null) { IDE.openEditor(page, file, true); } } } catch (PartInitException e) { DialogUtil.openError(dw.getShell(), ResourceMessages.FileResource_errorMessage, e.getMessage(), e); } return true; }
Example 18
Source File: OpenAppOverviewAction.java From codewind-eclipse with Eclipse Public License 2.0 | 5 votes |
public static void openAppOverview(CodewindApplication app) { IWorkbenchWindow workbenchWindow = CodewindUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); try { ApplicationOverviewEditorInput input = new ApplicationOverviewEditorInput(app); IEditorPart part = page.openEditor(input, ApplicationOverviewEditorInput.EDITOR_ID); if (!(part instanceof ApplicationOverviewEditorPart)) { // This should not happen Logger.logError("Application overview editor part for the " + app.name + " application is the wrong type: " + part.getClass()); //$NON-NLS-1$ //$NON-NLS-2$ } } catch (Exception e) { Logger.logError("An error occurred opening the editor for application: " + app.name, e); //$NON-NLS-1$ } }
Example 19
Source File: EditorAPI.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Opens the editor for the given file. Needs to be called from an UI thread. * * @param activate <code>true</code>, if editor should get focus, otherwise <code>false</code> * @return the opened editor or <code>null</code> if the editor couldn't be opened. */ public static IEditorPart openEditor(saros.filesystem.IFile wrappedFile, boolean activate) { IFile file = ((EclipseFileImpl) wrappedFile).getDelegate(); if (!file.exists()) { log.error("EditorAPI cannot open file which does not exist: " + file, new StackTrace()); return null; } IWorkbenchWindow window = getActiveWindow(); if (window == null) return null; try { IWorkbenchPage page = window.getActivePage(); /* * TODO Use * * IWorkbenchPage.openEditor(IEditorInput input, String editorId, * boolean activate) * * to open an editor and set activate to false! So that we can * separate opening from activating, which save us duplicate sending * of activated events. */ IEditorDescriptor descriptor = IDE.getEditorDescriptor(file); if (descriptor.isOpenExternal()) { /* * WORK-AROUND for #224: Editors are opened externally * erroneously (http://sourceforge.net/p/dpp/bugs/224) * * TODO Open as an internal editor */ log.warn( "Editor for file " + file.getName() + " is configured to be opened externally," + " which is not supported by Saros"); if (warnOnceExternalEditor) { warnOnceExternalEditor = false; WarningMessageDialog.showWarningMessage( "Unsupported Editor Settings", "Eclipse is configured to open this file externally, " + "which is not supported by Saros.\n\nPlease change the configuration" + " (Right Click on File -> Open With...) so that the file is opened in Eclipse." + "\n\nAll further " + "warnings of this type will be shown in the error " + "log."); } return null; } return IDE.openEditor(page, file, activate); } catch (PartInitException e) { log.error("could not initialize part: ", e); } return null; }
Example 20
Source File: RunAsAppFormMobileCommand.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { RunAsAppFormDeviceHandler deviceHandler=RunAsAppFormDeviceHandler.getInstance(); List<AndroidDevice> aMobiles =deviceHandler.getAndroidDevice(); List<IOSDevice> iMobiles =deviceHandler.getIosDevice(); if(aMobiles.size()<=0&&iMobiles.size()<=0){ DeviceNotFoundDialog dialog = new DeviceNotFoundDialog(Display .getDefault().getActiveShell()); dialog.open(); return null; } IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWorkbenchWindow != null) { IWorkbenchPage page = (IWorkbenchPage) activeWorkbenchWindow.getActivePage(); if (page != null) { IEditorPart part = page.getActiveEditor(); if (part != null) { IEditorInput input = part.getEditorInput(); if (input instanceof IFileEditorInput) { IFileEditorInput fileInput = (IFileEditorInput) input; obj = fileInput.getFile().getProject(); final SyncApplicationDialog sad = new SyncApplicationDialog( null, aMobiles, iMobiles, obj); final CountDownLatch threadSignal = new CountDownLatch( aMobiles.size() + iMobiles.size()); sad.open(); sad.run(threadSignal); Job job = new WorkspaceJob("") { @Override public IStatus runInWorkspace( IProgressMonitor monitor) throws CoreException { try { threadSignal.await(); } catch (InterruptedException e) { e.printStackTrace(); } sad.finish(); return Status.OK_STATUS; } }; job.schedule(); return null; } } } } RunAsAppFormMobile action = new RunAsAppFormMobile(); action.run(null); return null; }