Rational Developer for System z


レッスン 1: CustomContextProvider クラスの作成

このレッスンは、演習 5 で作成し、演習 6 で変更したプラグイン・プロジェクトを基に行います。このレッスンでは、必要なビューアーに合うようにカスタマイズできる CustomContextProvider クラスを作成します。例えば、フィールド・ビューアーが必要な場合は、コンテキスト・プロバイダーは CarmaFieldsContentProvider を拡張できます。

CARMAContextProvider クラスを作成するには、次のようにします。

  1. 「プラグイン開発」パースペクティブ内にいることを確認します。「パッケージ・エクスプローラー」ビューで、演習 5 と 6 で使用した com.ibm.carma.plugin.view プラグイン・プロジェクトを展開します。
  2. CARMADeveloperView クラスと CustomLabelProvider クラスを含む view パッケージを右クリックして、「新規」>「クラス」を選択します。
  3. 表示される「新規 Java クラス (New Java Class)」ダイアログ・ボックスで、「名前」テキスト・フィールドに CustomContextProvider と入力します。
  4. 「スーパークラス (Superclass)」テキスト・フィールドの右側の「参照」ボタンをクリックします。表示される「スーパークラスの選択 (Superclass Selection)」ダイアログ・ボックスに、フィルター・テキスト CARMATreeContentProvider を入力します。一致するクラスを選択して、「OK」をクリックします。
  5. 「スーパークラスからのコンストラクター (Constructors from superclass)」チェック・ボックスを選択して、「終了」をクリックします。「新規 Java クラス (New Java Class)」ダイアログが閉じ、CustomContentProvider クラスが作成されます。
  6. まず、次のインポートが Java クラスに含まれていることを確認します。欠落しているものがあれば追加します。
    import java.util.Vector;
    
    import com.ibm.carma.model.RepositoryInstance;
    import com.ibm.carma.ui.view.CarmaTreeContentProvider;
  7. getChildren メソッドを変更して、ビューアーに提供されているコンテンツを変更します。このメソッドで、RAM を展開したときにどの項目がビューアーに送信されるかをプロバイダーが制御できます。このチュートリアルでは、名前に CARMA トークンが含まれ、リスト、オブジェクト、およびロードのいずれのリポジトリー・インスタンスでもないリポジトリー・インスタンスのみを返す getChildren メソッドを実装します。

    次の疑似コードは、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)