org.eclipse.ui.services.IServiceLocator Java Examples

The following examples show how to use org.eclipse.ui.services.IServiceLocator. 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: LabelProviderFactory.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@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) {
			DEBUG.ERR("Exception in initializing injector: " + e.getMessage());
		}
	}
	return serviceProvider.get(serviceInterface);
}
 
Example #2
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: CommandsPropertyTester.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: DefineCommands.java    From EasyShell with Eclipse Public License 2.0 6 votes vote down vote up
@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();
        }
    }
}
 
Example #6
Source File: ReviewMarkerContributionFactory.java    From git-appraise-eclipse with Eclipse Public License 1.0 6 votes vote down vote up
@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);
  }
}
 
Example #7
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: CommandsPropertyTester.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: ImageServiceMock.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object create(@SuppressWarnings("rawtypes") Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) {
	
	if (serviceInterface==IImageService.class) {
		return new ImageServiceMock();
	} 
	return null;
}
 
Example #10
Source File: MetaDataServiceFactory.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object create(final Class serviceInterface, final IServiceLocator parentLocator,
		final IServiceLocator locator) {
	if (IFileMetaDataProvider.class.equals(serviceInterface))
		return FileMetaDataProvider.getInstance();
	return null;
}
 
Example #11
Source File: TextEditorContextContributionFactory.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
  ITextEditor editor = (ITextEditor)
      PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();

  additions.addContributionItem(new TextEditorContextMenuContribution(editor), null);
}
 
Example #12
Source File: DefineCommands.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example #13
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static CommandContributionItemParameter contribItemParameter(IServiceLocator svLocator, String commandId,
		String contribId) {
	return new CommandContributionItemParameter(svLocator, 
		contribId, 
		commandId, 
		CommandContributionItem.STYLE_PUSH
	);
}
 
Example #14
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static CommandContributionItemParameter contribItemParameter2(IServiceLocator svLocator, String commandId,
		ImageDescriptor icon) {
	CommandContributionItemParameter cip = new CommandContributionItemParameter(svLocator, 
		commandId, 
		commandId, 
		CommandContributionItem.STYLE_PUSH
	);
	cip.icon = icon;
	return cip;
}
 
Example #15
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static CommandContributionItemParameter contribItemParameter(IServiceLocator svLocator, String commandId) {
	return new CommandContributionItemParameter(svLocator, 
		commandId, 
		commandId, 
		CommandContributionItem.STYLE_PUSH
	);
}
 
Example #16
Source File: KeyInstanceProvider.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void initialize ( final IServiceLocator locator )
{
    super.initialize ( locator );
    this.mgr = KeyInstanceManager.getInstance ( Display.getCurrent () );
    this.mgr.addStatusListener ( this );
}
 
Example #17
Source File: PlotImageServiceMock.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #18
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example #19
Source File: WizardMenuContributions.java    From depan with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #20
Source File: KeyController2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example #21
Source File: KeyController2.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example #22
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static CommandContributionItem pushItem(IServiceLocator svLocator, String commandId, String contribId) {
	return new CommandContributionItem(contribItemParameter(svLocator, commandId, contribId));
}
 
Example #23
Source File: ICEExtensionContributionFactory.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void createContributionItems(IServiceLocator serviceLoc, IContributionRoot additions) {

	// Local Declarations
	HashMap<String, MenuManager> categoryMenus = new HashMap<String, MenuManager>();
	String codeName = "", category = "";
	MenuManager codeMenu = null;

	// Set the ServiceLocator
	serviceLocator = serviceLoc;

	// Create the Developer Menu Item
	developerMenu = new MenuManager("&Developer", "iceDev");

	// Get the registry and the extensions
	registry = Platform.getExtensionRegistry();

	// Create the category sub-menus
	for (CodeCategory c : CodeCategory.values()) {
		MenuManager manager = new MenuManager(c.name(), c.name() + "ID");
		manager.setVisible(true);
		categoryMenus.put(c.name(), manager);
		developerMenu.add(manager);
	}

	// Get the Extension Points
	IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.ice.developer.code");
	IExtension[] codeExtensions = extensionPoint.getExtensions();

	// Loop over the rest of the Extensions and create
	// their sub-menus.
	for (IExtension code : codeExtensions) {
		// Get the name of the bundle this extension comes from
		// so we can instantiate its AbstractHandlers
		String contributingPlugin = code.getContributor().getName();

		// Get the elements of this extension
		IConfigurationElement[] elements = code.getConfigurationElements();
		for (IConfigurationElement e : elements) {
			// Get the Code Name
			codeName = e.getAttribute("codeName");
			
			// Get whether this is the ICE declaration
			boolean isICE = "ICE".equals(codeName);
			
			// Get the Code Category - Framework, Physics, etc...
			category = isICE ? codeName : e.getAttribute("codeCategory");

			// Create a sub menu for the code in the
			// correct category, if this is not ICE ( we've already done it for ICE)
			codeMenu = isICE ? categoryMenus.get(codeName)
					: new MenuManager(codeName, codeName + "ID");

			// Generate the IParameters for the Command
			generateParameters(e);

			// Create a menu item for each extra command they provided
			for (IConfigurationElement command : e.getChildren("command")) {
				generateParameters(command);
				createCommand(contributingPlugin, command.getAttribute("implementation"), codeMenu);
			}

			// Add it to the correct category menu
			if (!"ICE".equals(codeName)) {
				categoryMenus.get(category).add(codeMenu);
			}
		}
		
		parameters.clear();
	}

	// Add the newly constructed developer menu
	additions.addContributionItem(developerMenu, null);

	return;
}
 
Example #24
Source File: CommandsHelper.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static CommandContributionItem pushItem(IServiceLocator svLocator, String commandId) {
	return new CommandContributionItem(contribItemParameter(svLocator, commandId));
}
 
Example #25
Source File: OpenGLInitializer.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Object create(final Class serviceInterface, final IServiceLocator parentLocator,
		final IServiceLocator locator) {
	return this;
}
 
Example #26
Source File: LangEditorContextMenuContributor.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public LangEditorContextMenuContributor(IServiceLocator svcLocator) {
	this.svcLocator = assertNotNull(svcLocator);
}
 
Example #27
Source File: LangEditorActionContributorHelper.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
protected IServiceLocator getServiceLocator() {
	return getPage().getWorkbenchWindow();
}
 
Example #28
Source File: GoEditorContextMenuContributor.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public GoEditorContextMenuContributor(IServiceLocator svcLocator) {
	super(svcLocator);
}
 
Example #29
Source File: EditorSettings_Actual.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static LangEditorContextMenuContributor createCommandsContribHelper(IServiceLocator svcLocator) {
	return new GoEditorContextMenuContributor(svcLocator);
}
 
Example #30
Source File: DummyEditorSite.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public IActionBars getActionBars() {
    return new EditorActionBars((WorkbenchPage) getPage(),
            (IServiceLocator) PlatformUI.getWorkbench().getService(IServiceLocator.class), GroovyEditor.EDITOR_ID);
}