org.eclipse.core.commands.Parameterization Java Examples

The following examples show how to use org.eclipse.core.commands.Parameterization. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommandUtils.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: ErstelleRnnCommand.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public static Object ExecuteWithParams(IViewSite origin, Tree<?> tSelection){
	IHandlerService handlerService = (IHandlerService) origin.getService(IHandlerService.class);
	ICommandService cmdService = (ICommandService) origin.getService(ICommandService.class);
	try {
		Command command = cmdService.getCommand(ID);
		Parameterization px =
			new Parameterization(command.getParameter("ch.elexis.RechnungErstellen.parameter"), //$NON-NLS-1$
				new TreeToStringConverter().convertToString(tSelection));
		ParameterizedCommand parmCommand =
			new ParameterizedCommand(command, new Parameterization[] {
				px
			});
		
		return handlerService.executeCommand(parmCommand, null);
		
	} catch (Exception ex) {
		throw new RuntimeException("add.command not found"); //$NON-NLS-1$
	}
}
 
Example #3
Source File: Handler.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private static Object execute(IViewSite origin, String commandID, Map<String, Object> params){
	if (origin == null) {
		log.error("origin is null");
		return null;
	}
	IHandlerService handlerService = (IHandlerService) origin.getService(IHandlerService.class);
	ICommandService cmdService = (ICommandService) origin.getService(ICommandService.class);
	try {
		Command command = cmdService.getCommand(commandID);
		String name = StringTool.unique("CommandHandler"); //$NON-NLS-1$
		paramMap.put(name, params);
		Parameterization px = new Parameterization(new DefaultParameter(), name);
		ParameterizedCommand parmCommand =
			new ParameterizedCommand(command, new Parameterization[] {
				px
		});
		
		return handlerService.executeCommand(parmCommand, null);
		
	} catch (Exception ex) {
		throw new RuntimeException("add.command not found"); //$NON-NLS-1$
	}
}
 
Example #4
Source File: ConfigurationHelper.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
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[] {} ) );
}
 
Example #5
Source File: TrendControlImage.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected void startHdView ()
{
    try
    {
        final ICommandService commandService = (ICommandService)PlatformUI.getWorkbench ().getService ( ICommandService.class );
        final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class );

        final Command command = commandService.getCommand ( "org.eclipse.scada.ui.chart.view.commands.OpenParametersChartView" ); //$NON-NLS-1$

        final Parameterization[] parameterizations = new Parameterization[4];
        parameterizations[0] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.connectionId" ), this.connectionId ); //$NON-NLS-1$
        parameterizations[1] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.itemId" ), this.itemId ); //$NON-NLS-1$
        if ( this.queryString == null || this.queryString.isEmpty () )
        {
            parameterizations[2] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.queryTimespec" ), "2400000:600000" ); //$NON-NLS-1$ //$NON-NLS-2$
        }
        else
        {
            parameterizations[2] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.queryTimespec" ), this.queryString ); //$NON-NLS-1$ 
        }
        parameterizations[3] = new Parameterization ( command.getParameter ( "org.eclipse.scada.ui.chart.itemType" ), "hd" ); //$NON-NLS-1$ //$NON-NLS-2$

        final ParameterizedCommand parameterCommand = new ParameterizedCommand ( command, parameterizations );

        handlerService.executeCommand ( parameterCommand, null );
    }
    catch ( final Exception e )
    {
        logger.debug ( "Failed to open view", e );
        StatusManager.getManager ().handle ( new Status ( IStatus.ERROR, Activator.PLUGIN_ID, Messages.TrendControlImage_TrendError, e ), StatusManager.BLOCK );
    }
}
 
Example #6
Source File: SymbolContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Execute an Eclipse command
 *
 * @param commandId
 *            the command to execute
 * @param eventData
 *            the parameter event data (depends on the command)
 */
public void executeCommand ( final String commandId, final Map<String, String> eventData )
{
    try
    {
        final ICommandService commandService = (ICommandService)PlatformUI.getWorkbench ().getService ( ICommandService.class );
        final IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench ().getService ( IHandlerService.class );

        final Command command = commandService.getCommand ( commandId );

        final Parameterization[] parameterizations = new Parameterization[eventData.size ()];

        int i = 0;
        for ( final Map.Entry<String, String> entry : eventData.entrySet () )
        {
            parameterizations[i] = new Parameterization ( command.getParameter ( entry.getKey () ), entry.getValue () );
            i++;
        }
        final ParameterizedCommand parameterCommand = new ParameterizedCommand ( command, parameterizations );

        handlerService.executeCommand ( parameterCommand, null );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to execute command", e );
        StatusManager.getManager ().handle ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ), StatusManager.BLOCK );
    }
}
 
Example #7
Source File: CommandUtils.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static Object executeCommand( String commandId, Map paramMap )
		throws NotDefinedException, ExecutionException,
		ParameterValueConversionException, NotEnabledException,
		NotHandledException
{
	Command cmd = CommandUtils.getCommand( commandId );
	List paramList = new ArrayList( );
	if ( paramMap != null )
	{
		for ( Iterator iter = paramMap.entrySet( ).iterator( ); iter.hasNext( ); )
		{
			Map.Entry entry = (Entry) iter.next( );
			String paramId = entry.getKey( ).toString( );
			Object value = entry.getValue( );
			if ( value != null )
			{
				paramList.add( createParameter( cmd, paramId, value ) );
			}
		}
	}
	if ( paramList.size( ) > 0 )
	{
		ParameterizedCommand paramCommand = new ParameterizedCommand( cmd,
				(Parameterization[]) paramList.toArray( new Parameterization[paramList.size( )] ) );

		return getHandlerService( ).executeCommand( paramCommand, null );
	}
	else
	{
		return getHandlerService( ).executeCommand( commandId, null );
	}
}
 
Example #8
Source File: CodeAssistAdvancedConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
String getKeybindingAsString() {
	final Parameterization[] params= { new Parameterization(fParam, fCategory.getId()) };
	final ParameterizedCommand pCmd= new ParameterizedCommand(fCommand, params);
	String key= getKeyboardShortcut(pCmd);
	return key;
}