存在若干辅助类可用,以便您可很方便地使用下列定制操作:
用于为定制参数获取值的最简单方法是使用 CustomActionUtil 内其中一个方法;例如 getCustomParameters:
CustomActionUtil.getCustomParameters(resource, "101");
对于给定资源,这会检索操作标识为 101 的操作的定制参数。如果计划为不同但相似的资源重复地使用同一任务,那么可使用 getCustomParametersForTask,如下所示:
CARMAContent[] resources = getResources();
CarmaTaskMemento taskMemento = new CarmaTaskMemento();
for (int i = 0; i < resources.length; i++) {
CustomActionUtil.getCustomParametersForTask(taskMemento, resources[i], "101");
}
在以上示例中,taskMemento 用来存储用户已输入以供操作调用之间使用的信息。如果此处不要使用 taskMemento,那么对于每个资源,将出现相同提示对用户进行询问。
如果您将改为使用另一机制来访存参数值(例如另一用户界面),那么可直接与 CustomActionParameterManager 类进行交互,如以下示例中所说明:
CustomActionParameterManager manager = CustomActionParameterManager.getManager();
Object[] paramsToPass = manager.getCustomParameters(resource, actionId); // parameters to pass to the command
//this method will tell us whether or not the manager has all the information it needs
if (manager.isPromptNeeded(resource, actionId)) {
final Action action = resource.findActionFor(actionId);
Iterator parameters = action.getParameters().iterator();
//find the parameter you want to change this way, or look for it to be null in paramsToPass
int index = 0;
while (it.hasNext()) {
Parameter param = (Parameter) it.next();
if (param.getName().equals(targetName))
break;
index++;
}
paramsToPass[index] = new Boolean(false);
//optionally store the parameter for later
Object[] paramsToStore = new Object[paramsToPass.length];
for (int i = 0; i < paramsToStore.length; i++) {
paramsToStore[i] = null;
if (i == index)
paramsToStore[i] = new Boolean(false);
}
manager.setUserStoredParamValues(resource.getRepository(), paramsToStore);
}
在以上示例中,targetName 是如 RAM 开发者定义的参数的名称。