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:
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:
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"/>
28 comments: