Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added problem decorators in the Project Explorer.
Files with compilation errors and warnings are now decorated with a little icon. The icons were borrowed from the JDT.
- Loading branch information
Showing
7 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...lipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/decorators/ProblemsLabelDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package net.sf.eclipsefp.haskell.ui.decorators; | ||
|
||
import net.sf.eclipsefp.haskell.core.util.ResourceUtil; | ||
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin; | ||
import net.sf.eclipsefp.haskell.ui.util.HaskellUIImages; | ||
import net.sf.eclipsefp.haskell.ui.util.IImageNames; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IFolder; | ||
import org.eclipse.core.resources.IMarker; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.ListenerList; | ||
import org.eclipse.jface.resource.ImageDescriptor; | ||
import org.eclipse.jface.viewers.IDecoration; | ||
import org.eclipse.jface.viewers.ILabelProviderListener; | ||
import org.eclipse.jface.viewers.ILightweightLabelDecorator; | ||
|
||
/** | ||
* LabelDecorator that decorates an element's image with error and warning | ||
* overlays that represent the severity of markers attached to the element's | ||
* underlying resource. To see a problem decoration for a marker, the marker | ||
* needs to be a subtype of <code>IMarker.PROBLEM</code>. | ||
* | ||
* @author Thomas ten Cate | ||
*/ | ||
public class ProblemsLabelDecorator implements ILightweightLabelDecorator { | ||
|
||
private final ListenerList listeners = new ListenerList(); | ||
|
||
public void decorate( final Object element, final IDecoration decoration ) { | ||
int adornmentFlags = computeAdornmentFlags( element ); | ||
ImageDescriptor desc; | ||
switch (adornmentFlags) { | ||
case IMarker.SEVERITY_ERROR: | ||
desc = getImageDescriptor( IImageNames.ERROR_OVERLAY ); | ||
break; | ||
case IMarker.SEVERITY_WARNING: | ||
desc = getImageDescriptor( IImageNames.WARNING_OVERLAY ); | ||
break; | ||
default: | ||
desc = null; // unchanged | ||
break; | ||
} | ||
if (desc != null) { | ||
decoration.addOverlay( desc, IDecoration.BOTTOM_LEFT ); | ||
} | ||
} | ||
|
||
protected int computeAdornmentFlags( final Object obj ) { | ||
try { | ||
if( obj instanceof IFile | ||
&& ResourceUtil.hasHaskellExtension( ( IResource )obj ) ) { | ||
return ( ( IResource )obj ).findMaxProblemSeverity( IMarker.PROBLEM, | ||
true, IResource.DEPTH_ZERO ); | ||
} else if( obj instanceof IFolder | ||
&& ResourceUtil.isSourceFolder( ( IFolder )obj ) ) { | ||
return ( ( IResource )obj ).findMaxProblemSeverity( IMarker.PROBLEM, | ||
true, IResource.DEPTH_INFINITE ); | ||
} | ||
} catch( CoreException e ) { | ||
HaskellUIPlugin.log( e ); | ||
} | ||
return 0; | ||
} | ||
|
||
private ImageDescriptor getImageDescriptor(final String name) { | ||
return HaskellUIImages.getImageDescriptor( name ); | ||
} | ||
|
||
public boolean isLabelProperty( final Object element, final String property ) { | ||
// We currently only support labelling (some kinds of) resources | ||
return element instanceof IResource; | ||
} | ||
|
||
public void dispose() { | ||
// nothing to dispose | ||
} | ||
|
||
public void removeListener( final ILabelProviderListener listener ) { | ||
listeners.remove(listener); | ||
} | ||
|
||
public void addListener( final ILabelProviderListener listener ) { | ||
listeners.add(listener); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters