Rational Developer for System z

处理定制参数

RAM 开发者能够定制现有 CARMA 操作或创建全新操作。这些操作可能具有定制参数或返回值,如 CARMA 主机的配置所定义。

存在若干辅助类可用,以便您可很方便地使用下列定制操作:

CustomActionParameterManager
针对元数据查询缺省值、已存储值以及链接值(按 CARMA 首选项中指定的顺序检索)
CustomActionParameterDialog
仅要求用户为定制参数输入值的便利对话框
CustomActionUtil
提供各种便利方法的辅助类

使用定制操作辅助类

用于为定制参数获取值的最简单方法是使用 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 开发者定义的参数的名称。


使用条款 | 反馈

本信息中心基于 Eclipse 技术。(http://www.eclipse.org)