/** * Constructs a new instance of {@link LegacyActionPersistence}. * * @param window * The window from which the services should be retrieved; must * not be <code>null</code>. */ public LegacyActionPersistence(final IWorkbenchWindow window) { // TODO Blind casts are bad. this.commandService = window .getService(ICommandService.class); this.window = window; }
@Override public void partActivated(IWorkbenchPart part) { if (!(part instanceof IEditorPart)) { return; } // update the "toggled" state based on the current editor ICommandService commandService = window.getService(ICommandService.class); commandService.refreshElements(IWorkbenchCommandConstants.WINDOW_PIN_EDITOR, null); }
private void updateCommandEnablement(String commandId) { IHandlerService handlerService = window.getService(IHandlerService.class); ICommandService commandService = window.getService(ICommandService.class); if (handlerService != null && commandService != null) { Command buildAllCmd = commandService.getCommand(commandId); buildAllCmd.setEnabled(handlerService.getCurrentState()); } } };
@Override public void handleEvent(Event event) { Object element = event.getProperty(UIEvents.EventTags.ELEMENT); // if the current-window trim is the event element if (element != null && element == getTrimStatus((WorkbenchWindow) window)) { // refresh menu item label, triggering updateElement() ICommandService commandService = window.getService(ICommandService.class); Map<String, WorkbenchWindow> filter = new HashMap<>(); filter.put(IServiceScopes.WINDOW_SCOPE, (WorkbenchWindow) window); commandService.refreshElements(COMMAND_ID_TOGGLE_STATUSBAR, filter); } } };
protected IDebugContextService createService(IWorkbenchWindow window) { DebugWindowContextService service = fServices.get(window); if (service == null) { IEvaluationService evaluationService = window.getService(IEvaluationService.class); if (window.getShell() == null || evaluationService == null) { // the window has been closed - return a dummy service return NULL_SERVICE; } else { service = new DebugWindowContextService(window, evaluationService); fServices.put(window, service); // register global listeners for (IDebugContextListener iDebugContextListener : fGlobalListeners) { service.addDebugContextListener(iDebugContextListener); } } } return service; }
/** * Opens a view selection dialog, allowing the user to chose a view. */ private static void openOther(ExecutionEvent event, IWorkbenchWindow workbenchWindow, MApplication app, EPartService partService) { Shell shell = HandlerUtil.getActiveShell(event); IEclipseContext ctx = workbenchWindow.getService(IEclipseContext.class); EModelService modelService = workbenchWindow.getService(EModelService.class); MWindow window = workbenchWindow.getService(MWindow.class); final ShowViewDialog dialog = new ShowViewDialog(shell, app, window, modelService, partService, ctx); dialog.open(); if (dialog.getReturnCode() == Window.CANCEL) { return; } final MPartDescriptor[] descriptors = dialog.getSelection(); for (MPartDescriptor descriptor : descriptors) { openView(workbenchWindow, descriptor, partService); } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); MTrimmedWindow winModel = window.getService(MTrimmedWindow.class); EModelService modelService = window.getService(EModelService.class); // ensure we have everything we need if ((winModel == null || modelService == null)) { return null; } if (winModel.getTags().contains(WINDOWS_WITH_MINIMIZED_TRIMBARS)) { winModel.getTags().remove(WINDOWS_WITH_MINIMIZED_TRIMBARS); disableCodeFocus(winModel, modelService); } else { enableCodeFocus(winModel, modelService); winModel.getTags().add(WINDOWS_WITH_MINIMIZED_TRIMBARS); } return null; }
/** * Show the "other" dialog, select a perspective, and run it. Pass on the selection event should * the menu need it. * * @param event the selection event */ void runOther(SelectionEvent event) { IHandlerService handlerService = window .getService(IHandlerService.class); try { handlerService.executeCommand(IWorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE, null); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { StatusManager.getManager().handle( new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH, "Failed to execute " + IWorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE, e)); //$NON-NLS-1$ } }
private IEvaluationContext getEvaluationContext() { IEvaluationContext ctx; IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench() .getActiveWorkbenchWindow(); // no active window during Eclipse shutdown if (activeWorkbenchWindow == null) return null; IHandlerService hsr = (IHandlerService) activeWorkbenchWindow .getService(IHandlerService.class); ctx = hsr.getCurrentState(); return ctx; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindowChecked(event); EPartService partService = workbenchWindow.getService(EPartService.class); MApplication app = workbenchWindow.getService(MApplication.class); // Get the view identifier, if any. final Object id = event.getParameters().get(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID); // let user select one or more if (!(id instanceof String)) { openOther(event, workbenchWindow, app, partService); return null; } MPartDescriptor viewDescriptor = getViewDescriptor(app, (String) id); if (viewDescriptor == null) { handleMissingView(id); return null; } openView(workbenchWindow, viewDescriptor, partService); return null; }
public void dispose() { if(menuManager != null) { menuManager.dispose(); } // participant listener TeamUI.getSynchronizeManager().removeSynchronizeParticipantListener(this); // handlers if (window != null) { IHandlerService hs = (IHandlerService)window.getService(IHandlerService.class); if (hs != null) { if (syncAll != null) hs.deactivateHandler(syncAll); if (syncLatest != null) hs.deactivateHandler(syncLatest); } } }
@Override public void dispose() { if(menuManager != null) { menuManager.dispose(); } // participant listener TeamUI.getSynchronizeManager().removeSynchronizeParticipantListener(this); // handlers if (window != null) { IHandlerService hs = window.getService(IHandlerService.class); if (hs != null) { if (syncAll != null) hs.deactivateHandler(syncAll); if (syncLatest != null) hs.deactivateHandler(syncLatest); } } }
private CommandContributionItem createItem(String itemAction, final TableViewer tableViewer) { IWorkbench workbench = PlatformUI.getWorkbench(); CommandContributionItemParameter itemParam = new CommandContributionItemParameter( workbench, null, itemAction, STYLE_PUSH); IWorkbenchWindow activeWorkbenchWindow = workbench .getActiveWorkbenchWindow(); IHandlerService hsr = (IHandlerService) activeWorkbenchWindow .getService(IHandlerService.class); IEvaluationContext ctx = hsr.getCurrentState(); ctx.addVariable(ACTIVE_MENU_SELECTION_NAME, tableViewer.getSelection()); return new CommandContributionItem(itemParam); }
/** * {@inheritDoc} */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editorPart = HandlerUtil.getActiveEditor(event); if (editorPart instanceof AbstractRootEditor) { AbstractRootEditor abstractRootEditor = (AbstractRootEditor) editorPart; if (abstractRootEditor.canMaximizeActiveSubView()) { abstractRootEditor.maximizeActiveSubView(); } else if (abstractRootEditor.canMinimizeActiveSubView()) { abstractRootEditor.minimizeActiveSubView(); } } // after the maximized/minimized is executed we need to refresh the UI elements bounded to // the command, so that checked state of that elements is updated ICommandService commandService = (ICommandService) HandlerUtil.getActiveWorkbenchWindow(event).getService(ICommandService.class); Map<Object, Object> filter = new HashMap<>(); filter.put(IServiceScopes.WINDOW_SCOPE, HandlerUtil.getActiveWorkbenchWindow(event)); commandService.refreshElements(event.getCommand().getId(), filter); return null; }
private CommandContributionItem createItem(String itemAction) { IWorkbench workbench = PlatformUI.getWorkbench(); CommandContributionItemParameter itemParam = new CommandContributionItemParameter( workbench, null, itemAction, STYLE_PUSH); IWorkbenchWindow activeWorkbenchWindow = workbench .getActiveWorkbenchWindow(); IHandlerService hsr = (IHandlerService) activeWorkbenchWindow .getService(IHandlerService.class); IEvaluationContext ctx = hsr.getCurrentState(); ctx.addVariable(ACTIVE_MENU_SELECTION_NAME, getContext().getSelection()); return new CommandContributionItem(itemParam); }
@Override public void setSession ( final LoginSession session ) { checkRealm (); if ( this.session != null ) { this.session.dispose (); } this.session = session; if ( this.session != null ) { this.session.register (); } for ( final IWorkbenchWindow window : PlatformUI.getWorkbench ().getWorkbenchWindows () ) { final ISourceProviderService service = (ISourceProviderService)window.getService ( ISourceProviderService.class ); final LoginSessionProvider sessionSourceProvider = (LoginSessionProvider)service.getSourceProvider ( LoginSessionProvider.SESSION_STATE ); sessionSourceProvider.setLoginSession ( session ); } super.setSession ( session ); }
@Override public synchronized void dispose() { m_isDisposed = true; stopTest(); IHandlerService handlerService= (IHandlerService) getSite().getWorkbenchWindow().getService(IHandlerService.class); handlerService.deactivateHandler(m_rerunActivation); handlerService.deactivateHandler(m_rerunFailedActivation); TestNGPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); m_viewIcon.dispose(); fOKColor.dispose(); fFailureColor.dispose(); }
private IContributionItem getItem(String actionId, String commandId, String image, String disabledImage, String label, String tooltip, String helpContextId) { ISharedImages sharedImages = getWindow().getWorkbench() .getSharedImages(); IActionCommandMappingService acms = getWindow() .getService(IActionCommandMappingService.class); acms.map(actionId, commandId); CommandContributionItemParameter commandParm = new CommandContributionItemParameter( getWindow(), actionId, commandId, null, sharedImages .getImageDescriptor(image), sharedImages .getImageDescriptor(disabledImage), null, label, null, tooltip, CommandContributionItem.STYLE_PUSH, null, false); return new CommandContributionItem(commandParm); } }
@Override public Object execute(ExecutionEvent event) { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if (window == null) { return null; } IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor == null) { return null; } IWorkbenchPartReference ref = window.getActivePage().getReference( editor); if (ref instanceof WorkbenchPartReference) { WorkbenchPartReference concreteRef = (WorkbenchPartReference) ref; concreteRef.setPinned(!concreteRef.isPinned()); ICommandService commandService = window .getService(ICommandService.class); commandService.refreshElements(event.getCommand().getId(), null); } return null; }
/** * Set the content and label providers for the treeViewer * * @param treeViewer */ protected void setContentAndLabelProviders(TreeViewer treeViewer) { if (hasAtMostOnePage()) { treeViewer.setLabelProvider(new PreferenceLabelProvider()); } else { treeViewer.setLabelProvider(new PreferenceBoldLabelProvider(filteredTree)); } IContributionService cs = PlatformUI .getWorkbench().getActiveWorkbenchWindow().getService( IContributionService.class); treeViewer.setComparator(cs.getComparatorFor(getContributionType())); treeViewer.setContentProvider(new PreferenceContentProvider()); }