/** * Adds the new wizards to the current perspective displayed in <code>activeWorkbenchWindow</code>, if they've not * been added already. Adds listeners on the window so that the same is done whenever the user switches perspectives * in the window. * * Note: This method can only be called once the workbench has been started. */ private void maybeAddNewWizardActionsToWindow(IWorkbenchWindow activeWorkbenchWindow) { if (activeWorkbenchWindow == null) { return; } activeWorkbenchWindow.addPerspectiveListener(perspectiveListener); WorkbenchPage activePage = (WorkbenchPage) activeWorkbenchWindow.getActivePage(); if (activePage == null) { return; } IPerspectiveDescriptor perspectiveDesc = activePage.getPerspective(); maybeAddNewWizardActionsToPerspective(activePage, perspectiveDesc); }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); if ( activeWorkbenchWindow != null ) { WorkbenchPage page = (WorkbenchPage) activeWorkbenchWindow.getActivePage(); if ( page != null ) { IPerspectiveDescriptor descriptor = page.getPerspective(); if ( descriptor != null ) { String message = "Resetting the perspective will reload the current experiment. Do you want to proceed ?"; boolean result = MessageDialog.open(MessageDialog.QUESTION, activeWorkbenchWindow.getShell(), "Reset experiment perspective", message, SWT.SHEET); if ( !result ) { return null; } page.resetPerspective(); GAMA.reloadFrontmostExperiment(); } } } return null; }
@Override protected EvaluationResult evaluate(IEvaluationContext context) { IWorkbenchWindow window = InternalHandlerUtil.getActiveWorkbenchWindow(context); // no window? not active if (window == null) return EvaluationResult.FALSE; WorkbenchPage page = (WorkbenchPage) window.getActivePage(); // no page? not active if (page == null) return EvaluationResult.FALSE; // get saveable part ISaveablePart saveablePart = getSaveablePart(context); if (saveablePart == null) return EvaluationResult.FALSE; if (saveablePart instanceof ISaveablesSource) { ISaveablesSource modelSource = (ISaveablesSource) saveablePart; if (SaveableHelper.needsSave(modelSource)) return EvaluationResult.TRUE; return EvaluationResult.FALSE; } if (saveablePart != null && saveablePart.isDirty()) return EvaluationResult.TRUE; return EvaluationResult.FALSE; }
public static IEditorReference[] getSortedEditors(IWorkbenchPage page) { IEditorReference[] result = null; if (page != null && page instanceof WorkbenchPage) { result = ((WorkbenchPage) page).getSortedEditors(); } return result; }
@Override public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspectiveDesc) { maybeAddNewWizardActionsToPerspective((WorkbenchPage) page, perspectiveDesc); }
/** * If we haven't added them in the past, add the new wizard actions that this to the perspective which is being * displayed on the workbench page. * * Note: This method can only be called once the workbench has been started. */ private void maybeAddNewWizardActionsToPerspective(WorkbenchPage page, IPerspectiveDescriptor desc) { if (page == null || desc == null) { return; } if (PERSPECTIVES_TO_ADD_WIZARDS_TO.contains(desc.getId())) { // Perspective perspective = page.findPerspective(desc); // if (perspective != null) { // List<String> wizardsToAdd = new ArrayList<String>( // WIZARDS_TO_ADD_TO_PERSPECTIVES); // // // Ignore any wizards we've already tried to add to this perspective. // // That way we don't re-add any wizards that the user explicitly // // removed from the New shortcut menu. // List<String> wizardsAlreadyAdded = GdtPreferences // .getAddedNewWizardActionsForPerspective(desc.getId()); // wizardsToAdd.removeAll(wizardsAlreadyAdded); // // // Get the current set of wizard shortcuts // List<String> currentWizardShortcuts = new ArrayList<String>( // Arrays.asList(perspective.getNewWizardShortcuts())); // // // Ignore wizards that already have shortcuts in this perspective // wizardsToAdd.removeAll(currentWizardShortcuts); // // // Only update the perspective if there are new wizards to add // if (!wizardsToAdd.isEmpty()) { // currentWizardShortcuts.addAll(wizardsToAdd); // // // Update the perspective // perspective.setNewWizardActionIds(new ArrayList<String>( // currentWizardShortcuts)); // } // // // Remember the wizards that we've attempted to add to this perspective // GdtPreferences.setAddedNewWizardActionsForPerspective(desc.getId(), // WIZARDS_TO_ADD_TO_PERSPECTIVES); // } else { // assert false : "Perspective was activated but not found"; // } } }