Monday, February 20, 2012

Decorating the Eclipse Editor with problem marks

Some time ago, I have managed to add the ProjectExplorer-style error markers into my Navigator.

Unfortunately, navigator extension did not add the Java Perspective-like error marks into the Editor's title. Today, I have accomplished the desired.

public class ErrorMarkEditor extends TextEditor {

 IResource getResource() {
  return ResourceUtil.getResource(getEditorInput());
  ResourcesPlugin.getWorkspace().addResourceChangeListener(new IResourceChangeListener() {

   public void resourceChanged(IResourceChangeEvent event) {
    IResource file = getResource();
    IResourceDelta delta= event.getDelta();
    if (delta != null && file != null) {
     IResourceDelta child = delta.findMember(file.getFullPath());
     if (child != null && (child.getFlags() & IResourceDelta.MARKERS) != 0) {
      Display.getDefault().syncExec(new Runnable() {
       public void run() {
  }, IResourceChangeEvent.POST_CHANGE);
    public Image getTitleImage() {
     final Image image = super.getTitleImage();
     IResource file = getResource();
     return (file != null) ? new ProblemsLabelDecorator().decorateImage(image, file) : image;  

Update The same applies to the NewProjectWizard. My perspective adds this wizard. But, it appears in PackageExplorer popup menu rather than in my Navigator!

Update2 I have to copy the
protected abstract class AbstractSelectionChangedListener implements ISelectionChangedListener  {

    public void install(ISelectionProvider selectionProvider) {
        if (selectionProvider == null)

        if (selectionProvider instanceof IPostSelectionProvider)  {
            IPostSelectionProvider provider= (IPostSelectionProvider) selectionProvider;
        } else  {

from JavaEditor to mine because they declare it privately rather than in AbstractTextEditor.

 KeyedHashSet is private in Eclipse. I like it so much that I created two journal records in this blog.

I do not understand why these markers are not in the core of Eclipse. Why JDT is required? Might be the default text editor shouldn't indicate the annotations in the Editor either? Why does JDT team builds common functionality on top of common eclipse objects, instead of incorporating this functionality into the basic objects so that everybody automatically benefits?


Open Project by Double-click in navigator. Yes, you know already. It exists in jdt's Package Explorer but not in Eclipse's common navigator.

     // Declare in CommonNavigator
    protected void handleDoubleClick(DoubleClickEvent anEvent) {
        super.handleDoubleClick(anEvent); // expand by default
        // Open project
        IActionBars ab = getViewSite().getActionBars();
        IAction op = ab.getGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId());;

1 comment:

kon said...

Great job! I was wondering for what reason you copied AbstractSelectionChangedListener from JavaEditor? Thanks!