Pages

Thursday, 3 June 2010

Change types in Eclipse Problems View using EMF

An interesting problem that I recently faced was to change the type for the messages appearing in the Type column of Eclipse Problems view. I am working with EMF plugins at the moment and had to come up with a solution that suits the EMF environment. By default any validation message in EMF has a type of 'EMF Problem' associated with it but in certain situations we need to change that to meet our business needs. So, here is what you need to do -

  • Define your own Resource Markers in some plugin as shown -


  • Override the validate action present in the ActionBarContributor class of your EMF editor plugin. By default it points to the "org.eclipse.emf.edit.ui.action.ValidateAction", create your own class extending this one.
  • In the extended class, override the method "Diagnostic validate(final IProgressMonitor progressMonitor)" in the following manner -
protected Diagnostic validate(final IProgressMonitor progressMonitor) 

    /* Overridden the utility to supply the new Marker ID */
    eclipseResourcesUtil = EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE ?
     new EclipseResourcesUtil() {
               @Override
                protected String getMarkerID() {
                 return "New Resource Marker ID" ;
                 }
       } : null;
               /*Changes finished*/
  }
  • When you will now execute the validate action, the custom type specified while defining your own resource marker shall be shown instead of 'EMF Problem'.

0 comments:

Post a Comment