Bug 121709 [Commands] parameters: Add types
I'm going to attach a patch that adds support for typed command parameters. This addresses several issues: - parameter values are strings, but handlers may want to work on objects - multiple handlers of a command should have a consistent way of converting string parameter values to objects - tooling to construct parameterized commands that starts with object parameter values needs a way of producing string parameter values that will work when the command is executed - there should be a way to classify commands by their object parameter types so, given an object, a set of commands that may work with it can be suggested To address these issues, the patch allows parameter types to be declared in the extension-point XML. The example below defines a command for negating integers and a parameter type that works with it. <extension point="org.eclipse.ui.commands"> <command id="org.example.commands.negateInteger" defaultHandler="org.example.commands.NegateIntegerHandler" name="Negate an Integer"> <commandParameter id="param" name="the param" optional="false" typeId="org.example.commands.Integer"/> </command> <commandParameterType id="org.example.commands.Integer" converter="org.example.commands.IntegerConverter" type="java.lang.Integer"/> </extension> In addition to extending the schema for org.eclipse.ui.commands, code has been added to a number of plugins (primarily org.eclipse.core.commands) to support the notion of typed parameters.
bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Command.java
final boolean categoryChanged = category != null;
		category = null;
		final boolean parametersChanged = parameters != null;
		parameters = null;
		final String[] stateIds = getStateIds();
		if (stateIds != null) {
			if (handler instanceof IObjectWithState) {
				final IObjectWithState handlerWithState = (IObjectWithState) handler;
				for (int i = 0; i < stateIds.length; i++) {
					final String stateId = stateIds[i];
					handlerWithState.removeState(stateId);
					final IState state = getState(stateId);
					removeState(stateId);
					state.dispose();
				}
			} else {
				for (int i = 0; i < stateIds.length; i++) {
					final String stateId = stateIds[i];
					final IState state = getState(stateId);
					removeState(stateId);
					state.dispose();
				}
			}
		}
		fireCommandChanged(new CommandEvent(this, categoryChanged,
				definedChanged, descriptionChanged, false, nameChanged,
				parametersChanged));
	}
}