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 by using a template. A
clock.ui
plug-in will be created to host the clock widgets and views.
com.packtpub.e4.clock.ui
3.5 or greater
com.packtpub.e4.clock.ui
1.0.0.qualifier
Clock
PacktPub
com.packtpub.e4.clock.ui.Activator
No
com.packtpub.e4.clock.ui.views
ClockView
Clock View
com.packtpub.e4.clock.ui
Timekeeping
Table Viewer
It's not usual to create a plug-in project per view (or per action) but often plug-ins are encapsulated and provide functionality specific to that particular plug-in. In this case, clocks aren't related to the Hello World one created before, so a new plug-in was created to host them.
The plug-in wizard created an empty plug-in project, as well as two key files.
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 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 one time. For plug-ins which 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 classpath. Any additional plug-in dependencies need to be added 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 devices 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:
<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 Eclipse 3.x.
E4: The Eclipse 4 model defines views in a different way, which is covered in more detail in Chapter 7, Understanding the Eclipse 4 Model. 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.