/** * This method is called when 'Finish' button is pressed in the wizard. We will create an * operation and run it using wizard as execution context. */ public boolean performFinish() { final String fileName = page.getProjectName(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { doFinish(fileName, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; try { getContainer().run(true, false, op); workbench.showPerspective( "edu.rosehulman.soar.perspective.SoarPerspectiveFactory", workbench.getWorkbenchWindows()[0]); } catch (InterruptedException e) { return false; } catch (InvocationTargetException e) { Throwable realException = e.getTargetException(); MessageDialog.openError(getShell(), "Error", realException.getMessage()); return false; } catch (WorkbenchException e) { MessageDialog.openError(getShell(), "Error", e.getMessage()); return false; } return true; }
/** Handles workbench exception */ private void handleWorkbenchException(WorkbenchException e) { ErrorDialog.openError( getWindow().getShell(), WorkbenchMessages.get().ChangeToPerspectiveMenu_errorTitle, e.getMessage(), e.getStatus()); }
@SuppressWarnings("deprecation") public void run(IAction action) { try { if (window == null) window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); final IWorkbenchPage page = window.getActivePage(); page.showView(IPageLayout.ID_RES_NAV); } catch (WorkbenchException e) { final String message = NLS.bind("Failed to open navigator. \n{0}", e.getMessage()); MessageDialog.openError(null, "Error", message); OPIBuilderPlugin.getLogger().log(Level.WARNING, message, e); } }
boolean openPerspective( final String perspId, final IAdaptable input, final IWorkbench workbench, final IPreferenceStore store, final ILog logger) { try { // Verify the requested perspective ID IPerspectiveRegistry reg = workbench.getPerspectiveRegistry(); IPerspectiveDescriptor perspective = reg.findPerspectiveWithId(perspId); if (perspective == null) { logger.log(statusFactory.error("Unable to open perspective: " + perspId)); return false; } // Get "Open Behavior" preference. String pref = store.getString(IWorkbenchPreferenceConstants.OPEN_NEW_PERSPECTIVE); // Implement open behavior. if (pref.equals(IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_WINDOW)) { workbench.openWorkbenchWindow(perspId, input); } else if (pref.equals(IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE)) { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); IWorkbenchPage activePage = window.getActivePage(); if (activePage != null) { activePage.setPerspective(perspective); } else { window.openPage(perspId, input); } } Shell shell = workbench.getActiveWorkbenchWindow().getShell(); shell.setMinimized(false); shell.forceActive(); logger.log(statusFactory.info("Opened perspective: " + perspId)); return true; } catch (WorkbenchException e) { logger.log(statusFactory.error("Error opening perspective: " + e.getMessage(), e)); return false; } }