本文整理匯總了Java中org.eclipse.ui.commands.ICommandService.getCommand方法的典型用法代碼示例。如果您正苦於以下問題:Java ICommandService.getCommand方法的具體用法?Java ICommandService.getCommand怎麽用?Java ICommandService.getCommand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.ui.commands.ICommandService
的用法示例。
在下文中一共展示了ICommandService.getCommand方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hookToCommands
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
private void hookToCommands(final ToolItem lastEdit, final ToolItem nextEdit) {
final UIJob job = new UIJob("Hooking to commands") {
@Override
public IStatus runInUIThread(final IProgressMonitor monitor) {
final ICommandService service = WorkbenchHelper.getService(ICommandService.class);
final Command nextCommand = service.getCommand(IWorkbenchCommandConstants.NAVIGATE_FORWARD_HISTORY);
nextEdit.setEnabled(nextCommand.isEnabled());
final ICommandListener nextListener = e -> nextEdit.setEnabled(nextCommand.isEnabled());
nextCommand.addCommandListener(nextListener);
final Command lastCommand = service.getCommand(IWorkbenchCommandConstants.NAVIGATE_BACKWARD_HISTORY);
final ICommandListener lastListener = e -> lastEdit.setEnabled(lastCommand.isEnabled());
lastEdit.setEnabled(lastCommand.isEnabled());
lastCommand.addCommandListener(lastListener);
// Attaching dispose listeners to the toolItems so that they remove the
// command listeners properly
lastEdit.addDisposeListener(e -> lastCommand.removeCommandListener(lastListener));
nextEdit.addDisposeListener(e -> nextCommand.removeCommandListener(nextListener));
return Status.OK_STATUS;
}
};
job.schedule();
}
示例2: execute
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchSite site = HandlerUtil.getActiveSite(event);
final ICommandService cs = (ICommandService) site
.getService(ICommandService.class);
final IHandlerService hs = (IHandlerService) site
.getService(IHandlerService.class);
final Command command = cs
.getCommand(IWorkbenchCommandConstants.FILE_IMPORT);
try {
hs.executeCommand(ParameterizedCommand.generateCommand(command,
Collections.singletonMap(
IWorkbenchCommandConstants.FILE_IMPORT_PARM_WIZARDID,
SessionImportWizard.ID)),
null);
} catch (CommandException e) {
EclEmmaUIPlugin.log(e);
}
return null;
}
示例3: execute
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchSite site = HandlerUtil.getActiveSite(event);
final ICommandService cs = (ICommandService) site
.getService(ICommandService.class);
final IHandlerService hs = (IHandlerService) site
.getService(IHandlerService.class);
final Command command = cs
.getCommand(IWorkbenchCommandConstants.FILE_EXPORT);
try {
hs.executeCommand(ParameterizedCommand.generateCommand(command,
Collections.singletonMap(
IWorkbenchCommandConstants.FILE_EXPORT_PARM_WIZARDID,
SessionExportWizard.ID)),
null);
} catch (CommandException e) {
EclEmmaUIPlugin.log(e);
}
return null;
}
示例4: performDrop
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的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;
}
示例5: isElogAvailable
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
public static boolean isElogAvailable() {
try {
if (LogbookClientManager.getLogbookClientFactory() == null)
return false;
// Check if logbook dialog is available
ICommandService commandService = PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
.getService(ICommandService.class);
Command command = commandService
.getCommand(OPEN_LOGENTRY_BUILDER_DIALOG_ID);
if (command == null) {
return false;
}
return true;
} catch (Exception e) {
return false;
}
}
示例6: executeCommand
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
private static void executeCommand(IWorkbench workbench, String commandName, Map<String, Object> params) {
if (workbench == null) {
workbench = PlatformUI.getWorkbench();
}
// get command
ICommandService commandService = (ICommandService)workbench.getService(ICommandService.class);
Command command = commandService != null ? commandService.getCommand(commandName) : null;
// get handler service
//IBindingService bindingService = (IBindingService)workbench.getService(IBindingService.class);
//TriggerSequence[] triggerSequenceArray = bindingService.getActiveBindingsFor("de.anbos.eclipse.easyshell.plugin.commands.open");
IHandlerService handlerService = (IHandlerService)workbench.getService(IHandlerService.class);
if (command != null && handlerService != null) {
ParameterizedCommand paramCommand = ParameterizedCommand.generateCommand(command, params);
try {
handlerService.executeCommand(paramCommand, null);
} catch (Exception e) {
Activator.logError(Activator.getResourceString("easyshell.message.error.handlerservice.execution"), paramCommand.toString(), e, true);
}
}
}
示例7: run
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的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();
}
}
示例8: getCommand
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
/**
* Get the current command for this handler. The command instance can change
* based on the command service, which changes based on the active workbench
* window.
*
* @return the current command for this handler.
*/
protected org.eclipse.core.commands.Command getCommand() {
org.eclipse.core.commands.Command command = null;
IWorkbench workbench = PlatformUI.getWorkbench();
if(workbench != null) {
IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
if(activeWorkbenchWindow != null) {
Object service = activeWorkbenchWindow.getService(ICommandService.class);
if(service != null && service instanceof ICommandService) {
ICommandService commandService = (ICommandService)service;
command = commandService.getCommand(getCommandId());
}
}
}
return command;
}
示例9: executeCommand
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
private static Object executeCommand(String commandId, Map<String,?> parameters, Event event, ICommandService ics, IHandlerService ihs)
throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException, CommandException {
Object result = null;
if (ics != null && ihs != null) {
Command command = ics.getCommand(commandId);
if (command != null) {
try {
MarkUtils.setIgnoreDispatchId(true);
ParameterizedCommand pcommand = ParameterizedCommand.generateCommand(command, parameters);
if (pcommand != null) {
result = ihs.executeCommand(pcommand, event);
}
} finally {
MarkUtils.setIgnoreDispatchId(false);
}
}
}
return result;
}
示例10: callRuleGenerationCommand
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的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;
}
}
示例11: execute
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的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;
}
}
示例12: test
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的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;
}
示例13: createCommand
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
/**
* Build a command from the executable extension information.
*
* @param commandService
* to get the Command object
* @param commandId
* the command id for this action
* @param parameterMap
*/
private void createCommand(ICommandService commandService,
String commandId, Map parameterMap) {
Command cmd = commandService.getCommand(commandId);
if (!cmd.isDefined()) {
WorkbenchPlugin.log("Command " + commandId + " is undefined"); //$NON-NLS-1$//$NON-NLS-2$
return;
}
if (parameterMap == null) {
parameterizedCommand = new ParameterizedCommand(cmd, null);
return;
}
parameterizedCommand = ParameterizedCommand.generateCommand(cmd,
parameterMap);
}
示例14: createDefaultLabel
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
private void createDefaultLabel(Composite composite, int h_span) {
final ICommandService commandSvc= (ICommandService) PlatformUI.getWorkbench().getAdapter(ICommandService.class);
final Command command= commandSvc.getCommand(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
ParameterizedCommand pCmd= new ParameterizedCommand(command, null);
String key= getKeyboardShortcut(pCmd);
if (key == null)
key= PreferencesMessages.CodeAssistAdvancedConfigurationBlock_no_shortcut;
PixelConverter pixelConverter= new PixelConverter(composite);
int width= pixelConverter.convertWidthInCharsToPixels(40);
Label label= new Label(composite, SWT.NONE | SWT.WRAP);
label.setText(Messages.format(PreferencesMessages.CodeAssistAdvancedConfigurationBlock_page_description, new Object[] { key }));
GridData gd= new GridData(GridData.FILL, GridData.FILL, true, false, h_span, 1);
gd.widthHint= width;
label.setLayoutData(gd);
createFiller(composite, h_span);
label= new Label(composite, SWT.NONE | SWT.WRAP);
label.setText(PreferencesMessages.CodeAssistAdvancedConfigurationBlock_default_table_description);
gd= new GridData(GridData.FILL, GridData.FILL, true, false, h_span, 1);
gd.widthHint= width;
label.setLayoutData(gd);
}
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion-Juno38,代碼行數:26,代碼來源:CodeAssistAdvancedConfigurationBlock.java
示例15: removeExecutionListeners
import org.eclipse.ui.commands.ICommandService; //導入方法依賴的package包/類
private static void removeExecutionListeners(ITextEditor editor) {
ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class);
if (ics != null) {
if (execExecListener != null) {
ics.removeExecutionListener(execExecListener);
}
if (copyCmdExecListener != null) {
Command com = ics.getCommand(EMP_COPY);
if (com != null) {
com.removeExecutionListener(copyCmdExecListener);
}
}
}
copyCmdExecListener = null;
execExecListener = null;
}