當前位置: 首頁>>代碼示例>>Java>>正文


Java ICommandService.getCommand方法代碼示例

本文整理匯總了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();

}
 
開發者ID:gama-platform,項目名稱:gama,代碼行數:26,代碼來源:EditorToolbar.java

示例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;
  }
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:23,代碼來源:ImportSessionHandler.java

示例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;
  }
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:23,代碼來源:ExportSessionHandler.java

示例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;
}
 
開發者ID:insweat,項目名稱:hssd,代碼行數:25,代碼來源:DropEntryHandler.java

示例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;
    }
}
 
開發者ID:kasemir,項目名稱:org.csstudio.display.builder,代碼行數:21,代碼來源:SendToElogAction.java

示例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);
        }
    }
}
 
開發者ID:anb0s,項目名稱:EasyShell,代碼行數:21,代碼來源:Utils.java

示例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();
	}

}
 
開發者ID:gama-platform,項目名稱:gama,代碼行數:25,代碼來源:DelegateForAllElements.java

示例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;		
}
 
開發者ID:nasa,項目名稱:OpenSPIFe,代碼行數:26,代碼來源:AbstractTimelineCommandHandler.java

示例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;
}
 
開發者ID:MulgaSoft,項目名稱:e4macs,代碼行數:20,代碼來源:EmacsPlusUtils.java

示例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;
	}
}
 
開發者ID:FTSRG,項目名稱:mondo-collab-framework,代碼行數:18,代碼來源:MACLIncQueryGenerator.java

示例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;
	}
}
 
開發者ID:FTSRG,項目名稱:mondo-collab-framework,代碼行數:20,代碼來源:MACLPatternImplementation.java

示例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;
}
 
開發者ID:heartsome,項目名稱:translationstudio8,代碼行數:20,代碼來源:CommandsPropertyTester.java

示例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);
}
 
開發者ID:ghillairet,項目名稱:gef-gwt,代碼行數:26,代碼來源:CommandAction.java

示例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;
}
 
開發者ID:MulgaSoft,項目名稱:e4macs,代碼行數:17,代碼來源:MarkUtils.java


注:本文中的org.eclipse.ui.commands.ICommandService.getCommand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。