本文整理匯總了Java中org.eclipse.ui.commands.ICommandService類的典型用法代碼示例。如果您正苦於以下問題:Java ICommandService類的具體用法?Java ICommandService怎麽用?Java ICommandService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ICommandService類屬於org.eclipse.ui.commands包,在下文中一共展示了ICommandService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getParameterizedCommand
import org.eclipse.ui.commands.ICommandService; //導入依賴的package包/類
public ParameterizedCommand getParameterizedCommand() {
IWorkbenchWindow activeWorkbenchWindow = Activator.getDefault()
.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
ICommandService commandService = (ICommandService) activeWorkbenchWindow
.getService(ICommandService.class);
if (commandService != null) {
ParameterizedCommand parameterizedCommand = ParameterizedCommand
.generateCommand(commandService.getCommand(_commandID),
_params);
return parameterizedCommand;
}
}
return null;
}
示例2: 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();
}
示例3: execute
import org.eclipse.ui.commands.ICommandService; //導入依賴的package包/類
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
this.decoratorManager = Activator.getDefault().getWorkbench().getDecoratorManager();
if (!this.isHidden) {
this.isHidden = true;
this.setStore(false);
this.setDecorator(false);
} else {
this.isHidden = false;
this.setStore(true);
this.setDecorator(true);
}
this.store.needsSaving();
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final ICommandService commandService = window.getService(ICommandService.class);
if (commandService != null) {
commandService.refreshElements(COMMAND_ID, null);
}
return null;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
}
示例8: 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);
}
}
}
示例9: getCommand
import org.eclipse.ui.commands.ICommandService; //導入依賴的package包/類
public ParameterizedCommand getCommand() {
IWorkbenchWindow activeWorkbenchWindow = Activator.getDefault()
.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
ICommandService commandService = (ICommandService) activeWorkbenchWindow
.getService(ICommandService.class);
if (commandService != null) {
// commandService.
ParameterizedCommand parameterizedCommand = ParameterizedCommand
.generateCommand(commandService.getCommand(_commandID),
_params);
return parameterizedCommand;
}
}
return null;
}
示例10: 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();
}
}
示例11: run
import org.eclipse.ui.commands.ICommandService; //導入依賴的package包/類
@Override
public void run(IAction action) {
System.err.println("In run(IACtion)");
if (serviceLocator == null) {
serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
// Create an ExecutionEvent using Eclipse machinery.
ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.COMPARE_WITH_ROUTE_ACTION), null);
// Fill it my current active selection.
if (event.getApplicationContext() instanceof IEvaluationContext) {
((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
}
try {
handler.execute(event);
} catch (ExecutionException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
示例12: run
import org.eclipse.ui.commands.ICommandService; //導入依賴的package包/類
@Override
public void run(IAction action) {
if (serviceLocator == null) {
serviceLocator = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
// Create an ExecutionEvent using Eclipse machinery.
ICommandService srv = (ICommandService) serviceLocator.getService(ICommandService.class);
IHandlerService hsrv = (IHandlerService) serviceLocator.getService(IHandlerService.class);
ExecutionEvent event = hsrv.createExecutionEvent(srv.getCommand(ActionCommands.PERSIST_TO_ROUTE_MODEL_ACTION), null);
// Fill it my current active selection.
if (event.getApplicationContext() instanceof IEvaluationContext) {
((IEvaluationContext) event.getApplicationContext()).addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, mySelection);
}
try {
handler.execute(event);
} catch (ExecutionException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
示例13: setup
import org.eclipse.ui.commands.ICommandService; //導入依賴的package包/類
/**
* setup
*/
private void setup()
{
try
{
// listen for execution events
Object service = PlatformUI.getWorkbench().getService(ICommandService.class);
if (service instanceof ICommandService)
{
ICommandService commandService = (ICommandService) service;
commandService.addExecutionListener(this);
}
}
catch (IllegalStateException e)
{
// workbench not yet started, or may be running headless (like in core unit tests)
}
// listen for element visibility events
BundleManager manager = BundleManager.getInstance();
manager.addElementVisibilityListener(this);
}
示例14: tearDown
import org.eclipse.ui.commands.ICommandService; //導入依賴的package包/類
/**
* tearDown
*/
private void tearDown()
{
// stop listening for visibility events
BundleManager manager = BundleManager.getInstance();
manager.removeElementVisibilityListener(this);
// stop listening for execution events
Object service = PlatformUI.getWorkbench().getService(ICommandService.class);
if (service instanceof ICommandService)
{
ICommandService commandService = (ICommandService) service;
commandService.removeExecutionListener(this);
}
// drop all references
this._commandToIdsMap.clear();
this._idToCommandsMap.clear();
this._nonlimitedCommands.clear();
}
示例15: setCoolBarVisibility
import org.eclipse.ui.commands.ICommandService; //導入依賴的package包/類
public static void setCoolBarVisibility(boolean visible)
{
IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
if (activeWorkbenchWindow instanceof WorkbenchWindow)
{
WorkbenchWindow workbenchWindow = (WorkbenchWindow) activeWorkbenchWindow;
workbenchWindow.setCoolBarVisible(visible);
workbenchWindow.setPerspectiveBarVisible(visible);
// Try to force a refresh of the text on the action
IWorkbenchPart activePart = getActivePart();
if (activePart != null)
{
ICommandService cmdService = (ICommandService) activePart.getSite().getService(ICommandService.class);
cmdService.refreshElements("org.eclipse.ui.ToggleCoolbarAction", null); //$NON-NLS-1$
}
}
}