The Eclipse UI consists of multiple views, which are the rectangular areas that display content, such as the Outline, Console, or Package Explorer. In Eclipse 3.x, views are created by adding an extension point to an existing plug-in, or using a template. A clock.ui
plug-in will be created to host the clock widgets and views.
com.packtpub.e4.clock.ui
.com.packtpub.e4.clock.ui
.1.0.0.qualifier
.com.packtpub.e4.clock.ui.Activator
.com.packtpub.e4.clock.ui.views
.ClockView
.com.packtpub.e4.clock.ui
.Timekeeping
.Functionality in Eclipse will typically be implemented in multiple plug-ins. Since the clock functionality developed in this chapter is unrelated to that of the hello
plug-in, a new plug-in was created to host the code. Plug-ins typically will have more than just one view or extension, grouped logically.
The plug-in wizard created an empty plug-in project as well as two key files: MANIFEST.MF
and plugin.xml
.
The manifest contains references to dependent plug-ins and interfaces, and includes the following:
Bundle-SymbolicName: com.packtpub.e4.clock.ui;singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-Activator: com.packtpub.e4.clock.ui.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime
Plug-ins that contribute to the user interface need to do two things:
org.eclipse.ui
;singleton:=true
after the bundle's symbolic nameThe dependency on the org.eclipse.ui
bundle gives access to the Standard Widget Toolkit and other key parts of the Eclipse framework.
The clause ;singleton:=true
is an OSGi directive, which means that only one version of this plug-in can be installed in Eclipse at a time. For plug-ins that add dependencies to the UI, there is a restriction that they must be singletons (this constraint is one of the main reasons why installing a new plug-requires the IDE to restart).
The manifest sets up the project's class path. Any additional plug-in dependencies need to be to the manifest.
The plugin.xml
file defines a list of extensions that this plug-in provides. Extension points are how Eclipse advertises the plug-in extensions, much like a USB hub provides a generic connector that allows many other types of device to be plugged in.
The Eclipse extension points are documented in the help system, and each has a point identifier, with optional children that are point-specific. In this case, the extension is defined using the org.eclipse.ui.views
point, which expects a combination of category
and view
elements. In this case, it will look like the following:
<plugin> <extension point="org.eclipse.ui.views"> <category name="Timekeeping" id="com.packtpub.e4.clock.ui"/> <view name="Clock View" icon="icons/sample.gif" category="com.packtpub.e4.clock.ui" class="com.packtpub.e4.clock.ui.views.ClockView" id="com.packtpub.e4.clock.ui.views.ClockView"/> </extension> </plugin>
The class in this case extends the ViewPart
abstract class, which is used for all views in the Eclipse 3.x model.
The Eclipse 4 (E4) model defines views in a different way, which is covered in more detail in Chapter 7, Creating Eclipse 4 Applications. The Eclipse 4.x SDK includes a 3.x compatibility layer, so these examples will work in Eclipse 4.x SDKs.
The viewer component is a default table view, which will be replaced in the next section.
18.227.0.249