@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { IMenuService menuService = (IMenuService) serviceLocator.getService(IMenuService.class); if (menuService == null) { CloudFoundryPlugin .logError("Unable to retrieve Eclipse menu service. Cannot add Cloud Foundry context menus."); //$NON-NLS-1$ return; } List<IAction> debugActions = getActions(menuService); for (IAction action : debugActions) { additions.addContributionItem(new ActionContributionItem(action), new Expression() { public EvaluationResult evaluate(IEvaluationContext context) { return EvaluationResult.TRUE; } public void collectExpressionInfo(ExpressionInfo info) { } }); } }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { IMenuService menuService = (IMenuService) serviceLocator.getService(IMenuService.class); if (menuService == null) { DockerFoundryPlugin .logError("Unable to retrieve Eclipse menu service. Cannot add Cloud Foundry context menus."); //$NON-NLS-1$ return; } List<IAction> debugActions = getActions(menuService); for (IAction action : debugActions) { additions.addContributionItem(new ActionContributionItem(action), new Expression() { public EvaluationResult evaluate(IEvaluationContext context) { return EvaluationResult.TRUE; } public void collectExpressionInfo(ExpressionInfo info) { } }); } }
@Override @SuppressWarnings("rawtypes") public Object create(Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) { if(disposed) { return null; } Object rv = serviceRegistry.get(serviceInterface); if(rv == null) { if(serviceInterface == IDService.class) { rv = new IDService(); serviceRegistry.put(serviceInterface, rv); } } return rv; }
@Override public boolean performDrop(Object data) { IServiceLocator locator = Helper.getWB(); ICommandService svc = (ICommandService)locator.getService( ICommandService.class); Command cmd = svc.getCommand(CMD_ID_MOVE_ENTRY); Map<String, String> params = new HashMap<>(); params.put("source", data.toString()); TreeNode en = (TreeNode)getCurrentTarget(); EntryData ed = EntryData.of(en); params.put("target", String.valueOf(ed.entryID())); try { cmd.executeWithChecks( new ExecutionEvent(cmd, params, getCurrentEvent(), null)); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { throw new RuntimeException(e); } return true; }
@Override public void createContributionItems(final IServiceLocator serviceLocator, final IContributionRoot additions) { // See http://blog.vogella.com/2009/12/03/commands-menu-runtime // for ExtensionContributionFactory example try { final String setting = Preferences.getTopDisplays(); final List<DisplayInfo> displays = DisplayInfoXMLUtil.fromDisplaysXML(setting); for (DisplayInfo display : displays) { final IAction action = new OpenDisplayAction(display); final IContributionItem item = new ActionContributionItem(action); additions.addContributionItem(item, null); } } catch (Exception ex) { logger.log(Level.WARNING, "Cannot create 'top displays'", ex); } }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { ITextEditor editor = (ITextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); IVerticalRulerInfo rulerInfo = editor.getAdapter(IVerticalRulerInfo.class); try { List<IMarker> markers = getMarkers(editor, rulerInfo); additions.addContributionItem(new ReviewMarkerMenuContribution(editor, markers), null); if (!markers.isEmpty()) { additions.addContributionItem(new Separator(), null); } } catch (CoreException e) { AppraiseUiPlugin.logError("Error creating marker context menus", e); } }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { CommandContributionItemParameter toggleWatchpointParam = new CommandContributionItemParameter(serviceLocator, null, "org.eclipse.debug.ui.commands.ToggleWatchpoint", CommandContributionItem.STYLE_PUSH); toggleWatchpointParam.icon = DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_WATCHPOINT); toggleWatchpointParam.disabledIcon = DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OBJS_WATCHPOINT_DISABLED); toggleWatchpointParam.label = "Add Watchpoint"; CommandContributionItem toggleWatchpoint = new CommandContributionItem(toggleWatchpointParam); Expression toggleWatchpointVisible = new Expression() { @Override public EvaluationResult evaluate(IEvaluationContext context) throws CoreException { return EvaluationResult.valueOf((context.getVariable("activeEditor") instanceof BfEditor)); } }; additions.addContributionItem(toggleWatchpoint, toggleWatchpointVisible); }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { MenuDataList items = MenuDataStore.instance().getEnabledCommandMenuDataList(); for (MenuData item : items) { ResourceType resTypeWanted = getWantedResourceType(); ResourceType resTypeSupported; try { resTypeSupported = item.getCommandData().getResourceType(); if ((resTypeSupported == ResourceType.resourceTypeFileOrDirectory) || (resTypeSupported == resTypeWanted)) { addItem(serviceLocator, additions, item.getNameExpanded(), "de.anbos.eclipse.easyshell.plugin.commands.execute", Utils.getParameterMapFromMenuData(item), item.getImageId(), true); } } catch (UnknownCommandID e) { e.logInternalError(); } } }
/** * Creates a site for the given editor nested within the given multi-page editor. * * @param multiPageEditor * the multi-page editor * @param editor * the nested editor */ public MultiPageToolbarEditorSite(MultiPageToolbarEditorPart multiPageEditor, IEditorPart editor) { Assert.isNotNull(multiPageEditor); Assert.isNotNull(editor); this.multiPageEditor = multiPageEditor; this.editor = editor; final IServiceLocator parentServiceLocator = multiPageEditor.getSite(); IServiceLocatorCreator slc = (IServiceLocatorCreator) parentServiceLocator.getService(IServiceLocatorCreator.class); this.serviceLocator = (ServiceLocator) slc.createServiceLocator(multiPageEditor.getSite(), null, new IDisposable() { public void dispose() { // Fix for ensuring compilation in E4 getMultiPageEditor().close(); } }); initializeDefaultServices(); }
/** * The <code>MultiPageEditor</code> implementation of this <code>IWorkbenchPart</code> method creates the control for * the multi-page editor by calling <code>createContainer</code>, then <code>createPages</code>. Subclasses should * implement <code>createPages</code> rather than overriding this method. * * @param parent * The parent in which the editor should be created; must not be <code>null</code>. */ public final void createPartControl(Composite parent) { Composite pageContainer = createPageContainer(parent); this.container = createContainer(pageContainer); createPages(); // set the active page (page 0 by default), unless it has already been // done if (getActivePage() == -1) { setActivePage(0); IEditorPart part = getEditor(0); if (part != null) { final IServiceLocator serviceLocator = part.getEditorSite(); if (serviceLocator instanceof INestable) { activeServiceLocator = (INestable) serviceLocator; activeServiceLocator.activate(); } } } initializePageSwitching(); initializeSubTabSwitching(); }
public void dispose() { pageChangeListeners.clear(); for (IEditorPart editor : nestedEditors) { disposePart(editor); } nestedEditors.clear(); if (pageContainerSite instanceof IDisposable) { ((IDisposable) pageContainerSite).dispose(); pageContainerSite = null; } for (IServiceLocator sl : pageSites) { if (sl instanceof IDisposable) { ((IDisposable) sl).dispose(); } } pageSites.clear(); super.dispose(); }
@SuppressWarnings("unchecked") @Override public Object create(final Class serviceInterface, final IServiceLocator parentLocator, final IServiceLocator locator) { if (serviceProvider == null) { // if (dependencyInjector != null) // return dependencyInjector.getInstance(c); try { serviceProvider = IResourceServiceProvider.Registry.INSTANCE .getResourceServiceProvider(URI.createPlatformResourceURI("dummy/dummy.gaml", false)); } catch (final Exception e) { System.out.println("Exception in initializing injector: " + e.getMessage()); } } return serviceProvider.get(serviceInterface); }
@Override public void run(final IAction action) { // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench(): IServiceLocator serviceLocator = PlatformUI.getWorkbench(); // or a site from within a editor or view: // IServiceLocator serviceLocator = getSite(); ICommandService commandService = serviceLocator.getService(ICommandService.class); try { // Lookup commmand with its ID Command command = commandService.getCommand("org.eclipse.xtext.ui.shared.OpenXtextElementCommand"); // Optionally pass a ExecutionEvent instance, default no-param arg creates blank event command.executeWithChecks(new ExecutionEvent()); } catch (Exception e) { // Replace with real-world exception handling e.printStackTrace(); } }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { for (PlanModifierFactory factory : PlanModifierRegistry.getInstance().getModifierFactories()) { String name = factory.getName(); ImageDescriptor imageDescriptor = factory.getImageDescriptor(); String id = null; String commandId = TEMPORAL_MODIFICATION_COMMAND_ID; Map<?, ?> parameters = Collections.singletonMap("name", name); ImageDescriptor icon = imageDescriptor; String label = name; String tooltip = name; FactoryServiceLocator locator = new FactoryServiceLocator(serviceLocator, factory); CommandContributionItemParameter parameter = new CommandContributionItemParameter(locator, id, commandId, parameters, icon, null, null, label, null, tooltip, SWT.RADIO, null, false); IContributionItem item = new CommandContributionItem(parameter); Expression visibleWhen = null; additions.addContributionItem(item, visibleWhen); } }
@Override public void updateElement(UIElement element, Map parameters) { IServiceLocator serviceLocator = element.getServiceLocator(); IPartService partService = (IPartService)serviceLocator.getService(IPartService.class); partService.addPartListener(ACTIVE_EDITOR_LISTENER); // adding the same listener multiple times is ok and ignored PlanModifierFactory elementFactory = (PlanModifierFactory)serviceLocator.getService(PlanModifierFactory.class); IPlanModifier planModifier = getCurrentPlanModifier(parameters); PlanModifierFactory planFactory = PlanModifierRegistry.getInstance().getFactory(planModifier); if (elementFactory != null) { if (elementFactory == planFactory) { element.setChecked(true); } else { element.setChecked(false); } } else if (PLAN_MODIFIER_FACTORIES.size() == 2) { boolean checked = !(planModifier instanceof DirectPlanModifier); element.setChecked(checked); if (planFactory != null) { element.setTooltip(planFactory.getName()); element.setIcon(planFactory.getImageDescriptor()); } } }
private boolean callRuleGenerationCommand(EPackage ePack, PatternInstance pattern, IPath iPath) { IServiceLocator serviceLocator = PlatformUI.getWorkbench(); ICommandService commandService = serviceLocator.getService(ICommandService.class); IHandlerService handlerService = serviceLocator.getService(IHandlerService.class); Command command = commandService.getCommand("org.mondo.collaboration.security.macl.tao.generation.rule"); try { IParameter parameter = command.getParameter(MACLCommandContext.ID); String contextId = UUID.randomUUID().toString(); Activator.put(contextId, context); Parameterization parameterization = new Parameterization(parameter, contextId); ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, new Parameterization[] { parameterization }); return (Boolean) handlerService.executeCommand(parameterizedCommand, null); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) { return false; } }
@Override public boolean execute(EPackage ePack, PatternInstance pattern, IPath iPath) { IServiceLocator serviceLocator = PlatformUI.getWorkbench(); ICommandService commandService = serviceLocator.getService(ICommandService.class); IHandlerService handlerService = serviceLocator.getService(IHandlerService.class); Command command = commandService.getCommand("org.mondo.collaboration.security.macl.tao.generation"); try { IParameter parameter = command.getParameter(MACLCommandContext.ID); MACLCommandContext context = new MACLCommandContext(ePack, pattern, iPath); String contextId = UUID.randomUUID().toString(); Activator.put(contextId, context); Parameterization parameterization = new Parameterization(parameter, contextId); ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, new Parameterization[] { parameterization }); return (Boolean) handlerService.executeCommand(parameterizedCommand, null); } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e1) { return false; } }
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) { if (receiver instanceof IServiceLocator && args.length == 1 && args[0] instanceof String) { final IServiceLocator locator = (IServiceLocator) receiver; if (TOGGLE_PROPERTY_NAME.equals(property)) { final String commandId = args[0].toString(); final ICommandService commandService = (ICommandService) locator .getService(ICommandService.class); final Command command = commandService.getCommand(commandId); final State state = command .getState(RegistryToggleState.STATE_ID); if (state != null) { return state.getValue().equals(expectedValue); } } } return false; }
private static BindingManager loadModelBackend(IServiceLocator locator) { IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class); BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager()); final Scheme[] definedSchemes = bindingService.getDefinedSchemes(); try { Scheme modelActiveScheme = null; for (int i = 0; i < definedSchemes.length; i++) { final Scheme scheme = definedSchemes[i]; final Scheme copy = bindingManager.getScheme(scheme.getId()); copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId()); if (definedSchemes[i] == bindingService.getActiveScheme()) { modelActiveScheme = copy; } } bindingManager.setActiveScheme(modelActiveScheme); } catch (final NotDefinedException e) { StatusManager.getManager() .handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH, "Keys page found an undefined scheme", e)); //$NON-NLS-1$ } bindingManager.setLocale(bindingService.getLocale()); bindingManager.setPlatform(bindingService.getPlatform()); bindingManager.setBindings(bindingService.getBindings()); return bindingManager; }
@Override public void initialize ( final IServiceLocator locator ) { super.initialize ( locator ); this.mgr = KeyInstanceManager.getInstance ( Display.getCurrent () ); this.mgr.addStatusListener ( this ); }
private IContributionItem buildWizardItem( IServiceLocator srvcLocator, String planId, LayoutPlanDocument<? extends LayoutPlan> planDoc) { String name = planDoc.getName(); String id = MessageFormat.format("{0}.{1}", MENU_ROOT, name); int style = CommandContributionItem.STYLE_PUSH; Map<String, String> parameters = LayoutNodesHandler.buildParameters(planId); IContributionItem result = new CommandContributionItem( new CommandContributionItemParameter(srvcLocator, id, LayoutNodesHandler.LAYOUT_COMMAND, parameters, null, null, null, name, null, null, style, null, false)); return result; }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { ITextEditor editor = (ITextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); additions.addContributionItem(new TextEditorContextMenuContribution(editor), null); }
private void addItem(IServiceLocator serviceLocator, IContributionRoot additions, String commandLabel, String commandId, Map<String, Object> commandParamametersMap, String commandImageId, boolean visible) { CommandContributionItemParameter param = new CommandContributionItemParameter(serviceLocator, "", commandId, SWT.PUSH); param.label = commandLabel; param.icon = Activator.getImageDescriptor(commandImageId); param.parameters = commandParamametersMap; CommandContributionItem item = new CommandContributionItem(param); item.setVisible(visible); additions.addContributionItem(item, null); }
/** * Returns the service locator for the given page index. This method can be used to create service locators for pages * that are just controls. The page index must be valid. * <p> * This will return the editor site service locator for an editor, and create one for a page that is just a control. * </p> * * @param pageIndex * the index of the page * @return the editor for the specified page, or <code>null</code> if the specified page was not created with * <code>addPage(IEditorPart,IEditorInput)</code> * @since 3.4 */ protected final IServiceLocator getPageSite(int pageIndex) { if (pageIndex == PAGE_CONTAINER_SITE) { return getPageContainerSite(); } Item item = getItem(pageIndex); if (item != null) { Object data = item.getData(); if (data instanceof IEditorPart) { return ((IEditorPart) data).getSite(); } else if (data instanceof IServiceLocator) { return (IServiceLocator) data; } else if (data == null) { IServiceLocatorCreator slc = (IServiceLocatorCreator) getSite().getService(IServiceLocatorCreator.class); IServiceLocator sl = slc.createServiceLocator(getSite(), null, new IDisposable() { public void dispose() { close(); } }); item.setData(sl); pageSites.add(sl); return sl; } } return null; }
/** * @return A site that can be used with a header. * @since 3.4 * @see #createPageContainer(Composite) * @see #PAGE_CONTAINER_SITE * @see #getPageSite(int) */ private IServiceLocator getPageContainerSite() { if (pageContainerSite == null) { IServiceLocatorCreator slc = (IServiceLocatorCreator) getSite().getService(IServiceLocatorCreator.class); pageContainerSite = slc.createServiceLocator(getSite(), null, new IDisposable() { public void dispose() { close(); } }); } return pageContainerSite; }
/** * This method can be used by implementors of {@link MultiPageEditorPart#createPageContainer(Composite)} to deactivate * the active inner editor services while their header has focus. A deactivateSite() must have a matching call to * activateSite() when appropriate. * <p> * An new inner editor will have its site activated on a {@link MultiPageEditorPart#pageChange(int)}. * </p> * <p> * <b>Note:</b> This API is evolving in 3.4 and this might not be its final form. * </p> * * @param immediate * immediately deactivate the legacy keybinding service * @param containerSiteActive * Leave the page container site active. * @since 3.4 * @see #activateSite() * @see #createPageContainer(Composite) * @see #getPageSite(int) * @see #PAGE_CONTAINER_SITE */ protected final void deactivateSite(boolean immediate, boolean containerSiteActive) { // Deactivate the nested services from the last active service locator. if (activeServiceLocator != null) { activeServiceLocator.deactivate(); activeServiceLocator = null; } final int pageIndex = getActivePage(); final IKeyBindingService service = getSite().getKeyBindingService(); if (pageIndex < 0 || pageIndex >= getPageCount() || immediate) { // There is no selected page, so deactivate the active service. if (service instanceof INestableKeyBindingService) { final INestableKeyBindingService nestableService = (INestableKeyBindingService) service; nestableService.activateKeyBindingService(null); } else { WorkbenchPlugin .log("MultiPageEditorPart.deactivateSite() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$ } } if (containerSiteActive) { IServiceLocator containerSite = getPageContainerSite(); if (containerSite instanceof INestable) { activeServiceLocator = (INestable) containerSite; activeServiceLocator.activate(); } } }
@Override public Object create(final Class serviceInterface, final IServiceLocator parentLocator, final IServiceLocator locator) { if (IFileMetaDataProvider.class.equals(serviceInterface)) return FileMetaDataProvider.getInstance(); return null; }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { IProject project = retrieveSelectedProject(); // Now check if project is a CMakeProject if(CMakeNature.isCMakeProject(project)) { additions.addContributionItem(new CMakeContributionMenu(), null); } else if(CMakeNature.canConvertProject(project)) additions.addContributionItem(new CMakeSetupContributionMenu(), null); }
@Override @SuppressWarnings("unchecked") public final void updateElement(UIElement element, Map parameters) { IServiceLocator serviceLocator = element.getServiceLocator(); IPartService partService = (IPartService) serviceLocator .getService(IPartService.class); installListeners(partService); updateEnablement(); }
public void init(IServiceLocator locator, List<String> lstRemove) { getEventManager().clear(); this.serviceLocator = locator; // filterDupliteBind(); fBindingManager = loadModelBackend(serviceLocator); contextModel = new ContextModel(this); contextModel.init(serviceLocator); fSchemeModel = new SchemeModel(this); fSchemeModel.init(fBindingManager); bindingModel = new BindingModel2(this); bindingModel.init(serviceLocator, fBindingManager, contextModel); HashSet<BindingElement> set = bindingModel.getBindings(); Iterator<BindingElement> iterator = set.iterator(); while (iterator.hasNext()) { BindingElement bindingElement = iterator.next(); if (lstRemove.contains(bindingElement.getId())) { iterator.remove(); } } bindingModel.setBindings(set); Map<Binding, BindingElement> mapBBe = bindingModel.getBindingToElement(); Iterator<Entry<Binding, BindingElement>> it = mapBBe.entrySet().iterator(); while (it.hasNext()) { Entry<Binding, BindingElement> entry = (Entry<Binding, BindingElement>) it.next(); if (lstRemove.contains(entry.getValue().getId())) { it.remove(); } } bindingModel.setBindingToElement(mapBBe); conflictModel = new ConflictModel2(this); conflictModel.init(fBindingManager, bindingModel); addSetContextListener(); addSetBindingListener(); addSetConflictListener(); addSetKeySequenceListener(); addSetSchemeListener(); addSetModelObjectListener(); }
@Override public Object create(@SuppressWarnings("rawtypes") Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) { if (serviceInterface==IImageService.class) { return new ImageServiceMock(); } return null; }
@Override public Object create(Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) { if (serviceInterface==IPlotImageService.class) { return new PlotImageServiceMock(); } else if (serviceInterface==IFileIconService.class) { return new PlotImageServiceMock(); } return null; }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { ISelectionService service = (ISelectionService)serviceLocator.getService(ISelectionService.class); ISelection selection = service.getSelection(); if (selection instanceof IStructuredSelection) { // TODO check for all elements in the selection Object selectedObject = ((IStructuredSelection)selection).getFirstElement(); Map<String, IConfigurationElement> extensions = extensionPointLauncher.getExtensions(); for (String name: extensions.keySet()) { IConfigurationElement extension = extensions.get(name); String enableFor = extension.getAttribute("enableFor"); if (enableFor != null) { try { Class<?> enableForClass = Thread.currentThread().getContextClassLoader().loadClass(enableFor); if (enableForClass.isAssignableFrom(selectedObject.getClass())) { addCommand(serviceLocator, additions, name); } } catch (ClassNotFoundException e) { logger.log(ILogger.WARNING, "enablefor class " + enableFor + " could not found.", e); } } else { addCommand(serviceLocator, additions, name); } } } }
@SuppressWarnings({ "unchecked" }) private void addCommand(IServiceLocator serviceLocator, IContributionRoot additions, String id) { CommandContributionItemParameter p = new CommandContributionItemParameter( serviceLocator, id, CommandId, SWT.PUSH); p.label = id; if (p.parameters == null) { p.parameters = new HashMap<Object, Object>(); } p.parameters.put("id", id); CommandContributionItem item = new CommandContributionItem(p); item.setVisible(true); additions.addContributionItem(item, null); }
@Override public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) { CommandContributionItemParameter p = new CommandContributionItemParameter( serviceLocator, "","org.eclipse.ui.file.exit", SWT.PUSH); p.label = "Exit the application"; CommandContributionItem item = new CommandContributionItem(p); item.setVisible(true); }