Do you know that creating a custom markers view is very simple and requires very less code? I didn't know it till few weeks back. I've been exploring this Marker view since then. It may not be very useful in an Eclipse/Eclipse based IDE, as we already have Problems View, Markers View and Task View. But this might come handy in an RCP where you want to have more control. I'll explain how to create a basic markers view and then move on to customize it. You would at least require Ganymede (Eclipse 3.4) for all the samples here to work. First lets create a view:

<extension point="org.eclipse.ui.views">
<view
class="com.eclipse_tips.markers.MyCustomMarkersView"
icon="icons/sample.gif"
id="com.eclipse-tips.markers.customMarker"
name="My Custom Markers">
</view>
</extension>

There is no much code in the View class, its just a constructor:

public class MyCustomMarkersView extends MarkerSupportView {
public MyCustomMarkersView() {
super("com.eclipse-tips.markers.myCustomMarkerGenerator");
}
}

The string that we pass in the constructor is the id of the content generator. It should be defined thru the extension point org.eclipse.ui.ide.markerSupport:

<extension point="org.eclipse.ui.ide.markerSupport">
<markerContentGenerator
id="com.eclipse-tips.markers.myCustomMarkerGenerator"
name="My Marker Generator">

<markerTypeReference id="org.eclipse.core.resources.marker"/>
<markerFieldReference id="org.eclipse.ui.ide.descriptionField"/>
</markerContentGenerator>
</extension>

The above is the minimum configuration the marker view requires. The markerContentGenerator needs at least one markerTypeReference and one markerFieldReference. Before digging into what all that refers to, lets have a look at the custom marker view:

Custom Markers View

As you have seen in the above picture, the table just displays only one field - Description. If we want more fields, we need to add more markerFieldReferences. Eclipse provides you most frequently used fields like severity, icon, location, etc. We can add all those fields:

<markerContentGenerator 
id="com.eclipse-tips.markers.myCustomMarkerGenerator"
name="My Marker Generator">

<markerTypeReference id="org.eclipse.core.resources.marker"/>
<markerFieldReference id="org.eclipse.ui.ide.severityAndDescriptionField"/>
<markerFieldReference id="org.eclipse.ui.ide.locationField"/>
<markerFieldReference id="org.eclipse.ui.ide.markerType"/>
<markerFieldReference id="org.eclipse.ui.ide.priorityField"/>
<markerFieldReference id="org.eclipse.ui.ide.resourceField"/>
</markerContentGenerator>

Now our view looks like:

image

Note earlier we used org.eclipse.ui.ide.descriptionField field, so just the description was displayed. To get the icon and the description, we need to use the org.eclipse.ui.ide.severityAndDescriptionField. So far we have been using the fields defined by Eclipse. Creating our own field is also possible. Lets try to create a field called Project, which will display the project name of the marker's resource. You need to extend org.eclipse.ui.ide.markerSupport's markerField:

<markerField
class="com.eclipse_tips.markers.ProjectField"
id="com.eclipse-tips.markers.projectField"
name="Project">
</markerField>

In the class, you just need to extend one method - getValue()

public String getValue(MarkerItem item) {
return item.getMarker().getResource().getProject().getName(); }

The MarkerItem is the UI representation of IMarkers (and the categories as well). Once you get the IMarker, you can navigate and get the project name. Now to add this field in our view, just add a markerFieldReference in our markerContentGenerator:

 

<markerContentGenerator id="com.eclipse-tips.markers.myCustomMarkerGenerator" name="My Marker Generator">
.. other items ...
<markerFieldReference id="com.eclipse-tips.markers.projectField"/>

image

Subscribe To

Unless stated, all the text contents of this site is available under Eclipse Public License