Time for action – adding the clock

To add the clock to the Eclipse 4 application, a new part will be added which has a ClockWidget as its only content.

  1. To use the ClockWidget in a different plug-in, the package needs to be exported. Open the MANIFEST.MF from the com.packtpub.e4.clock.ui project, and on the Runtime tab, click on Add to add the com.packtpub.e4.clock.ui package to the list of Exported Packages.
  2. Create a new class called ClockPart in the com.packtpub.e4.application.parts package.
  3. Add a create method with a @PostConstruct annotation that takes a Composite parent argument.
  4. In the body of the create method, instantiate a new ClockWidget instance with arguments parent, SWT.NONE, and new RGB(255,0,0). This will require that the com.packtpub.e4.clock.ui package is imported into the com.packtpub.e4.application plug-in. A quick-fix should offer this automatically, but it can be added by opening the MANIFEST.MF, going to the Dependencies tab, and adding the com.packtpub.e4.clock.ui package to the list of Imported Packages. At this point, the code should look like:
    public class ClockPart {
      @PostConstruct
      public void create(Composite parent) {
        new ClockWidget(parent, SWT.NONE, new RGB(255, 0, 0));
      }
    }
  5. To add the part to the application, open the Application.e4xmi file in the model editor, and navigate inside to Application | Windows and Dialogs | Trimmed Window | Controls | Perspective Stack | Perspective | Controls | Part Sash Container | Part Stack.
  6. Right-click on the Part Stack node and choose Add Child | Part.
  7. Click on the newly created Part and add Clock as the label, and click on Find next to the Class URI field to select the newly created ClockPart class. It should fill the field with a URI reference bundleclass://com.packtpub.e4.application/com.packtpub.e4.application.parts.ClockPart.
  8. Add the com.packtpub.e4.clock.ui plug-in to the product, and update the launch configuration (or delete it so that it is re-created automatically).
  9. Run the application and a Clock tab should be seen, with the clock widget shown.

What just happened?

Adding a part was covered previously in Chapter 2, Drawing a Custom View, and now the Eclipse 4 application has a Clock part with the ClockWidget. It takes up the entire space of the application window and will be used to test setting the color of the second hand:

What just happened?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.147.53