Lesson 3: Develop the code for the CustomLabelProvider class
In this lesson, you develop the code for the CustomLabelProvider class,
which controls how the items in the CARMA Developer View are displayed.
About this task
To develop this code:
Procedure
- Open the
ContextLabelProviderclass. From the Package Explorer view, navigatecom.ibm.carma.plugin.view>src>view, and double-click on theCustomLabelProviderclass. - First, you 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; } - The next method that 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 path name passed as a parameter to thegetImageDescriptormethod should match your directory and image name. - Finally, make sure that you have the following packages
that are 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.*; - Save the source and debug any errors.