Rational Developer for System z


Lesson 3: Develop the code for the CustomLabelProvider class

In this lesson, you will develop the code for the CustomLabelProvider class, which will control how the items in the CARMA Developer View are displayed.

To develop this code:

  1. Open the ContextLabelProvider class. From the Package Explorer view, navigate com.ibm.carma.plugin.view > src > view, and double click on the CustomLabelProvider class.
  2. First, you will want to override the getText() method. This method should check to see if a repository manager is connected and add a label to the repository manager that shows the connected/disconnected state.

    The following is example pseudocode for the getText() method:

    if(the element passed to getText is a repository manager)
    {
       if(the repository manager is connected)
       {
          add connected label to the repository manager;
       }
       else
       {
          add disconnected label to the repository manager;
       }
    }

    Use the following example source to override the getText() method:

    public String getText(Object element)
    {
       String textLabel = super.getText(element);
       if(element instanceof RepositoryManager)
       {
          if( ((RepositoryManager)element).isConnected())
          {
             textLabel += " - (Connected)";
          }
          else
          {
             textLabel += " - (Disconnected)";
          }
    	}
    
      return textLabel;
    }
  3. The next method you will want to override is the getImage() method. This method should change the icon display for COBOL members.

    The following is pseudocode for the getImage() method:

    if( the element passed getImage is a CARMA Member)
    {
       if( the CARMA Member's extension is "cbl" )
       {
          decorate the CARMA Member;
       }
    }

    The following is example source code for the getImage() method:

    public Image getImage(Object element)
    {
       if(element instanceof CARMAMember)
       {
          if(((CARMAMember) element).getLocalExtension().equalsIgnoreCase("cbl"))
          {
             //replace the parameter of getImageDescriptor() with the path to your particular icon
             ImageDescriptor myDescriptor = Activator.getImageDescriptor("icons/cobol.gif");
             return myDescriptor.createImage();
          }
       }
       return super.getImage(element);
    }
    Note: The pathname passed as a parameter to the getImageDescriptor method should match your directory and image name.
  4. Finally, make sure you have the following packages listed in your import statements at the top of your Java class. Add any that are missing:
    import com.ibm.carma.plugin.view.Activator;
    
    import org.eclipse.jface.resource.ImageDescriptor;
    import org.eclipse.swt.graphics.Image;
    
    import com.ibm.carma.model.*;
    import com.ibm.carma.ui.view.*;
  5. Save the source and debug any errors.

Terms of use | Feedback



This information center is powered by Eclipse technology. (http://www.eclipse.org)