本文整理汇总了Java中org.eclipse.ui.services.IServiceLocator.getService方法的典型用法代码示例。如果您正苦于以下问题:Java IServiceLocator.getService方法的具体用法?Java IServiceLocator.getService怎么用?Java IServiceLocator.getService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.ui.services.IServiceLocator
的用法示例。
在下文中一共展示了IServiceLocator.getService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContributionItems
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@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) {
}
});
}
}
示例2: createContributionItems
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@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) {
}
});
}
}
示例3: performDrop
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@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;
}
示例4: MultiPageToolbarEditorSite
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
/**
* 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();
}
示例5: run
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@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();
}
}
示例6: updateElement
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@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());
}
}
}
示例7: callRuleGenerationCommand
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
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;
}
}
示例8: execute
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@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;
}
}
示例9: test
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
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;
}
示例10: loadModelBackend
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
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;
}
示例11: updateElement
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@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();
}
示例12: createContributionItems
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@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);
}
}
}
}
示例13: initialize
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@Override
public void initialize(IServiceLocator serviceLocator) {
handlerService = serviceLocator.getService(IHandlerService.class);
}
示例14: findSourceProvider
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
/**
* Finds a source provider using the specified locator (for example, a
* workbench window)
*/
@SuppressWarnings("unchecked")
public static <T> T findSourceProvider(IServiceLocator locator, String sourceName, Class<T> expectedClass) {
ISourceProviderService service = (ISourceProviderService) locator.getService(ISourceProviderService.class);
return (T) service.getSourceProvider(sourceName);
}
示例15: createContributionItems
import org.eclipse.ui.services.IServiceLocator; //导入方法依赖的package包/类
@Override
public void createContributionItems(IServiceLocator serviceLocator,
IContributionRoot additions) {
// TODO Auto-generated method stub
ISelectionService serv = (ISelectionService) serviceLocator.getService(ISelectionService.class);
ISelection selection = serv.getSelection();
TreeSelection treeselection = (TreeSelection)selection;
Object firstelement = treeselection.getFirstElement();
if(firstelement instanceof IProject || firstelement instanceof IFolder){
IProject pro = null;
if(firstelement instanceof IProject)
pro = (IProject)firstelement;
if(firstelement instanceof IFolder)
pro = ((IFolder)firstelement).getProject();
try {
IProjectNature nature = pro.getNature(WTNewProjectNature.ID);
if(nature==null)
return;
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MenuManager menu = new MenuManager();
menu.setMenuText("New WT");
if(firstelement instanceof IProject)
{
CommandContributionItemParameter pcommand = new CommandContributionItemParameter(serviceLocator,
"", "org.eclipse.ui.newWizard", CommandContributionItem.STYLE_PUSH);
pcommand.parameters = new HashMap<String,String>();
pcommand.parameters.put("newWizardId", "org.mondo.wt.cstudy.collectioninputoutput.collectioninputoutputNewFile");
CommandContributionItem itemitsInputOutput = new CommandContributionItem(pcommand);
menu.add(itemitsInputOutput);
pcommand.parameters.put("newWizardId", "org.mondo.wt.cstudy.mainsubsystem.mainsubsystemNewFile");
CommandContributionItem itemitsSubsystems = new CommandContributionItem(pcommand);
menu.add(itemitsSubsystems);
}
else if(firstelement instanceof IFolder)
{
IFolder fol = (IFolder)firstelement;
IPath filePath = fol.getFullPath().append("/"+fol.getName().concat(".xmi"));
XMI_File file = new XMI_File(URI.createPlatformResourceURI(filePath.toString(), true), true);
EObject root = null;
try {
root = file.Get_Root();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(root!=null)
{
}
}
additions.addContributionItem(menu, null);
}
}