Lesson 3: Create a Java Decorator class

You create the Decorator class in this lesson, which will later be responsible for placing the graphics as decorators on CARMA members.

About this task

To create the Java™ Decorator class:

Procedure

  1. Start by setting the appropriate dependencies for the Eclipse plug-in project. Right click the com.ibm.carma.plugin.decorators Eclipse plug-in project, and select PDE Tools > Open Manifest. This opens the Plug-in Editor in the main editor window.
  2. From the bottom menu of tabs in the Plug-in Editor, select Dependencies. This opens the plug-in dependency editor.
  3. Ensure the following plug-ins are listed in the first panel:
    • org.eclipse.ui
    • org.eclipse.core.runtime
    • com.ibm.carma.core(9.0.0)
  4. If any of the plug-ins are missing, click the Add button. In the Plug-in Selection dialog box that opens, enter the name of the missing plug-in in the filter text field. When it appears in the panel, select it, and click OK.
  5. Now, you create a new package to contain the Decorator class. Placing relevant Java classes together in packages helps to keep your code organized. Right click the com.ibm.carma.plugin.decorators plug-in project, and select New Package.
  6. In the New Java Package dialog box that opens, enter decorator in the Name text field, and click Finish. You should see the package you just created appear in the src directory.
  7. Right click the decorator package you created, and select New > Class.
  8. In the Name text field, enter Decorator.
  9. Next, to the Superclass text field, click Browse to browse for the class that your Descriptor class extends.
  10. In the Superclass Selection dialog box that opens, enter LabelProvider in the text field. Select the class that is part of the org.eclipse.jface.viewers package, and click OK.
  11. Next, to the Interfaces panel, click Add. In the Implemented Interfaces Selection dialog box that opens, enter ILightweightLabelDecorator, and select the matching item that appears. Click OK.
  12. Click Finish to close out of the New Java Class dialog box.

Results

You should see the Decorator class appear under the decorator package and the source code for the Decorator class open in the editor.