@Override public Object execute(ExecutionEvent event) throws ExecutionException { try { IParameter configparameter = event.getCommand().getParameter(PARAMETER_LAUNCHCONFIG); IParameterValues values = configparameter.getValues(); if (values instanceof LaunchParameterValues){ LaunchParameterValues launchParameterValues = (LaunchParameterValues) values; taskAttributeOverride = launchParameterValues.getOverriddenTasks(); launch = launchParameterValues.getLaunch(); postJob = launchParameterValues.getPostJob(); }else{ IDEUtil.logWarning(getClass().getSimpleName()+":parameter values without being a launch parameter value was used !??! :"+ values); } } catch (NotDefinedException | ParameterValuesException e) { throw new IllegalStateException("Cannot fetch command parameter!", e); } return super.execute(event); }
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; } }
@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; } }
public static Parameterization createParameter( Command command, String parameterId, Object value ) throws NotDefinedException, ExecutionException, ParameterValueConversionException { ParameterType parameterType = command.getParameterType( parameterId ); if ( parameterType == null ) { throw new ExecutionException( "Command does not have a parameter type for the given parameter" ); //$NON-NLS-1$ } IParameter param = command.getParameter( parameterId ); AbstractParameterValueConverter valueConverter = parameterType.getValueConverter( ); if ( valueConverter == null ) { throw new ExecutionException( "Command does not have a value converter" ); //$NON-NLS-1$ } String valueString = valueConverter.convertToString( value ); Parameterization parm = new Parameterization( param, valueString ); return parm; }
/** * Define the Command to be used when executing the named kbd macro * * @param editor * @param id - the full command id * @param name - the short name * @param category - the category to use in the definition * @return the Command */ Command defineKbdMacro(ITextEditor editor, String id, String name, String category) { Command command = null; if (id != null) { // Now create the executable command ICommandService ics = (editor != null ) ? (ICommandService) editor.getSite().getService(ICommandService.class) : (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); command = ics.getCommand(id); IParameter[] parameters = null; try { // kludge: Eclipse has no way to dynamically define a parameter, so grab it from a known command IParameter p = ics.getCommand(PARAMETER_CMD).getParameter(PARAMETER); parameters = new IParameter[] { p }; } catch (Exception e) { } command.define(name, String.format(KBD_DESCRIPTION,name), ics.getCategory(category), parameters); command.setHandler(new KbdMacroNameExecuteHandler(name)); } return command; }
private static ParameterizedCommand convertCommand ( final IConfigurationElement commandElement ) throws NotDefinedException, InvalidRegistryObjectException { final ICommandService commandService = (ICommandService)PlatformUI.getWorkbench ().getService ( ICommandService.class ); final Command command = commandService.getCommand ( commandElement.getAttribute ( "id" ) ); //$NON-NLS-1$ final List<Parameterization> parameters = new ArrayList<Parameterization> (); for ( final IConfigurationElement parameter : commandElement.getChildren ( "parameter" ) ) //$NON-NLS-1$ { final IParameter name = command.getParameter ( parameter.getAttribute ( "name" ) ); //$NON-NLS-1$ final String value = parameter.getAttribute ( "value" ); //$NON-NLS-1$ parameters.add ( new Parameterization ( name, value ) ); } return new ParameterizedCommand ( command, parameters.toArray ( new Parameterization[] {} ) ); }
private final static void doExecuteEclipseCommand(String commandId, String... parameters) { final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); final IHandlerService handlerService = window.getService(IHandlerService.class); try { if (parameters.length % 2 != 0) throw new IllegalArgumentException("Parameterized commands must have " + "an equal number of keys and values"); if (parameters.length == 0) handlerService.executeCommand(commandId, null); else { final ICommandService commandService = window.getService(ICommandService.class); final Parameterization[] params = new Parameterization[parameters.length / 2]; final Command c = commandService.getCommand(commandId); for (int i = 0; i < parameters.length / 2; i++) { final String key = parameters[2 * i]; final String value = parameters[2 * i + 1]; final IParameter p = c.getParameter(key); final Parameterization pp = new Parameterization(p, value); params[i] = pp; } final ParameterizedCommand pc = new ParameterizedCommand(c, params); handlerService.executeCommand(pc, null); } } catch (Exception ex) { logger.log(Level.WARNING, "Failed to execute eclipse command '" + commandId + "' " + Arrays.toString(parameters), ex); } }
ModelElement(CompletionProposalCategory category, PreferenceModel model) { fCategory= category; ICommandService commandSvc= (ICommandService) PlatformUI.getWorkbench().getAdapter(ICommandService.class); fCommand= commandSvc.getCommand("org.eclipse.jdt.ui.specific_content_assist.command"); //$NON-NLS-1$ IParameter type; try { type= fCommand.getParameters()[0]; } catch (NotDefinedException x) { Assert.isTrue(false); type= null; } fParam= type; fPreferenceModel= model; }
public TreeMap<String, Command> getCommandList(IEditorPart editor, boolean all) { ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class); Command[] commands = ics.getDefinedCommands(); commandTree = new TreeMap<String, Command>(); try { HashSet<Category>catHash = (all ? null : getCategories(ics)); boolean isOk = all; for (int i = 0; i < commands.length; i++) { if (!isOk && catHash.contains(commands[i].getCategory())) { IParameter[] params = commands[i].getParameters(); isOk = commands[i].isHandled(); // if the command has parameters, they must all be optional if (isOk && params != null) { for (int j = 0; j < params.length; j++) { if (!(isOk = params[j].isOptional())) { break; } } } } if (isOk) { commandTree.put(fixName(commands[i].getName()), commands[i]); } isOk = all; } } catch (NotDefinedException e) {} // getContexts(editor); return commandTree; }
private Command adaptCommand(final ParameterizedCommand inCommand) { final Command out = inCommand.getCommand(); try { if (out.getParameters() == null) { out.define(out.getName(), out.getDescription(), out.getCategory(), new IParameter[] { new ToolBarParameter() }); } } catch (final NotDefinedException exc) { // intentionally left empty } return out; }
/** * <p> * Generates all the possible combinations of command parameterizations for * the given command. If the command has no parameters, then this is simply * a parameterized version of that command. If a parameter is optional, both * the included and not included cases are considered. * </p> * <p> * If one of the parameters cannot be loaded due to a * <code>ParameterValuesException</code>, then it is simply ignored. * </p> * * @param inCommand * {@link Command} The command for which the parameter * combinations should be generated; must not be * <code>null</code>. * @return A collection of <code>ParameterizedCommand</code> instances * representing all of the possible combinations. This value is * never empty and it is never <code>null</code>. * @throws NotDefinedException * If the command is not defined. */ public static Collection<ParameterizedCommand> generateCombinations( final Command inCommand) throws NotDefinedException { final IParameter[] lParameters = inCommand.getParameters(); if (lParameters == null) { return Collections .singleton(new ParameterizedCommand(inCommand, null)); } final Collection<List<Parameterization>> lExpansion = expandParameters( 0, lParameters); final Collection<ParameterizedCommand> outCombinations = new ArrayList<ParameterizedCommand>( lExpansion.size()); final Iterator<List<Parameterization>> lExpansionItr = lExpansion .iterator(); while (lExpansionItr.hasNext()) { final List<Parameterization> lCombination = lExpansionItr.next(); if (lCombination == null) { outCombinations.add(new ParameterizedCommand(inCommand, null)); } else { while (lCombination.remove(null)) { // Just keep removing while there are null entries left. } if (lCombination.isEmpty()) { outCombinations .add(new ParameterizedCommand(inCommand, null)); } else { final Parameterization[] lParameterizations = lCombination .toArray(new Parameterization[lCombination.size()]); outCombinations.add(new ParameterizedCommand(inCommand, lParameterizations)); } } } return outCombinations; }
/** * * Execute command with parameters without parameter id. * Prameters are filled into command in order - from first to last. * * @param id : command id * @param param : array of parameters */ public boolean execute(String id, IEclipseContext staticContext, String... params){ Command command = commandService.getCommand(id); if(command == null){ logger.warning("execute("+ id +"): Command with specified ID was not found!"); return false; } try { if(command.getParameters() == null){ return execute(id); } } catch (NotDefinedException e1) { e1.printStackTrace(); } Map<String, Object> paramsMap = new HashMap<String, Object>(); try { for(int i=0; i<command.getParameters().length && i<params.length; i++){ IParameter p = command.getParameters()[i]; paramsMap.put(p.getId(), params[i]); } } catch (NotDefinedException e) { e.printStackTrace(); } ParameterizedCommand pc = ParameterizedCommand.generateCommand(command, paramsMap); if(pc == null){ logger.warning("execute("+ id +"): Can not create parameterized command!"); return false; } if(staticContext == null){ if(handlerService.canExecute(pc)){ handlerService.executeHandler(pc); return true; } } else{ if(handlerService.canExecute(pc, CloudscaleContext.getActiveContext())){ handlerService.executeHandler(pc, CloudscaleContext.getActiveContext()); return true; } } return false; }
@Override public void notifySpeech(String speech) { System.out.println("Speech recongized: " + speech); if (HELLO.equalsIgnoreCase(speech)) { showText("Welcome back. What would you like to do?"); } else if (DEBUG_START.equalsIgnoreCase(speech)) { DebugHelper.runLastDebug(); } else if (STEP_OVER.equalsIgnoreCase(speech)) { DebugHelper.stepOver(); } else if (STEP_INTO.equalsIgnoreCase(speech)) { DebugHelper.stepInto(); } else if (STEP_RETURN.equalsIgnoreCase(speech)) { DebugHelper.stepReturn(); } else if (RESUME.equalsIgnoreCase(speech)) { DebugHelper.resume(); } else if (JAVA_PERSPECTIVE.equalsIgnoreCase(speech)) { Display.getDefault().syncExec(new Runnable() { public void run() { IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command showView = commandService.getCommand("org.eclipse.ui.perspectives.showPerspective"); try { IParameter persIdParm = showView.getParameter("org.eclipse.ui.perspectives.showPerspective.perspectiveId"); Parameterization parm = new Parameterization(persIdParm, "org.eclipse.jdt.ui.JavaPerspective"); ParameterizedCommand parmCommand = new ParameterizedCommand(showView, new Parameterization[] { parm }); handlerService.executeCommand(parmCommand, null); } catch (Exception e) { } } }); } else if (EXIT.equalsIgnoreCase(speech)) { showText("See you soon!"); } else if (STOP_SPEECH_RECOGNITION.equalsIgnoreCase(speech)) { KinectManager.INSTANCE.stopSpeechRecognition(); } else if (OPEN_TYPE.equalsIgnoreCase(speech)) { openTypeDialog(); } }