Rational Developer for System z


课程 1:创建 CustomContextProvider

本课程基于您在练习 5 中已创建并且在练习 6 中已修改的插件项目。在本课程中,您将创建 CustomContextProvider 类,可以定制此类以满足您需要的任何查看器。例如,如果您需要字段查看器,那么上下文提供程序可以扩展 CarmaFieldsContentProvider

要创建 CARMAContextProvider 类,请执行下列操作:

  1. 确保您处于插件开发透视图中。在包资源管理器视图中,展开您已用于练习 5 和练习 6 的 com.ibm.carma.plugin.view 插件项目。
  2. 右键单击其中包含 CARMADeveloperViewCustomLabelProvider 类的 view 包,然后选择新建 >
  3. 在打开的新建 Java 类对话框中,在名称文本字段中输入 CustomContextProvider
  4. 单击位于超类文本字段右边的浏览按钮。在打开的选择超类对话框中,输入过滤器文本 CARMATreeContentProvider。选择相匹配的类,然后单击确定
  5. 选中来自超类的构造函数复选框,然后单击完成新建 Java 类对话框将关闭,并且将创建 CustomContentProvider 类。
  6. 从确保此 Java™ 类中包括下列 import 语句开始。添加缺少的任何内容。
    import java.util.Vector;
    
    import com.ibm.carma.model.RepositoryInstance;
    import com.ibm.carma.ui.view.CarmaTreeContentProvider;
  7. 您将需要修改 getChildren 方法以更改对查看器提供的内容。此提供程序可以通过此方法来控制在展开 RAM 时要将哪些项发送至查看器。在本教程中,您将实现 getChildren 方法,以仅返回其名称中具有 CARMA 标记的存储库实例,并且这些存储库实例不是列表、对象或装入存储库实例。

    以下伪码演示了 getChildren 方法应当执行的操作:

    get the children of the object that would normally be returned;
    for each child
    {
       	if(the child is a repository instance)
       {
          		if(the repository instance has a CARMA token and is not a listing, object, or load repository instance)
              			add the child to the list of displayable children;
       }
    }
    getChildren 方法使用以下样本代码:
    public Object[] getChildren(Object parent)
    {
       	Object[] children = super.getChildren(parent);
    
       	//Do not parse non-existant children
       	if(children == null)
       {
          		return children;
       }
    
       	Vector<Object> displayChildren = new Vector<Object>();
       	for(int i = 0; i < children.length; i++)
       {
          		if(children[i] instanceof RepositoryInstance)
          {
             			RepositoryInstance myContainer = (RepositoryInstance) children[i];
             			if (myContainer.getName().contains("CARMA"))
             {
                				displayChildren.add(children[i]);
             }
          }
          else
          {
             			displayChildren.add(children[i]);
          }
       }
       	return displayChildren.toArray();
    }
  8. 保存源代码,并调试存在的任何错误。

使用条款 | 反馈



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