mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
@Override annotations and spaces
This commit is contained in:
parent
b62f1b0e6a
commit
72bf0af67c
1 changed files with 46 additions and 38 deletions
|
@ -46,19 +46,19 @@ import org.eclipse.cdt.internal.ui.util.IProblemChangedListener;
|
||||||
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
|
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LabelDecorator that decorates an element's image with error and warning overlays that
|
* 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
|
* 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>.
|
* a problem decoration for a marker, the marker needs to be a subtype of <code>IMarker.PROBLEM</code>.
|
||||||
* <p>
|
* <p>
|
||||||
* Note: Only images for elements in Java projects are currently updated on marker changes.
|
* Note: Only images for elements in Java projects are currently updated on marker changes.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabelDecorator {
|
public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabelDecorator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a special <code>LabelProviderChangedEvent</code> carring additional
|
* This is a special <code>LabelProviderChangedEvent</code> carring additional
|
||||||
* information whether the event orgins from a maker change.
|
* information whether the event orgins from a maker change.
|
||||||
* <p>
|
* <p>
|
||||||
* <code>ProblemsLabelChangedEvent</code>s are only generated by <code>
|
* <code>ProblemsLabelChangedEvent</code>s are only generated by <code>
|
||||||
|
@ -76,12 +76,12 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
super(source, changedResource);
|
super(source, changedResource);
|
||||||
fMarkerChange= isMarkerChange;
|
fMarkerChange= isMarkerChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this event origins from marker changes. If <code>false</code> an annotation
|
* Returns whether this event origins from marker changes. If <code>false</code> an annotation
|
||||||
* model change is the origin. In this case viewers not displaying working copies can ignore these
|
* model change is the origin. In this case viewers not displaying working copies can ignore these
|
||||||
* events.
|
* events.
|
||||||
*
|
*
|
||||||
* @return if this event origins from a marker change.
|
* @return if this event origins from a marker change.
|
||||||
*/
|
*/
|
||||||
public boolean isMarkerChange() {
|
public boolean isMarkerChange() {
|
||||||
|
@ -91,13 +91,13 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int ERRORTICK_WARNING= CElementImageDescriptor.WARNING;
|
private static final int ERRORTICK_WARNING= CElementImageDescriptor.WARNING;
|
||||||
private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR;
|
private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR;
|
||||||
private static final int TICK_CONFIGURATION = CElementImageDescriptor.SETTINGS;
|
private static final int TICK_CONFIGURATION = CElementImageDescriptor.SETTINGS;
|
||||||
|
|
||||||
private ImageDescriptorRegistry fRegistry;
|
private ImageDescriptorRegistry fRegistry;
|
||||||
private boolean fUseNewRegistry= false;
|
private boolean fUseNewRegistry= false;
|
||||||
private IProblemChangedListener fProblemChangedListener;
|
private IProblemChangedListener fProblemChangedListener;
|
||||||
|
|
||||||
private ListenerList fListeners;
|
private ListenerList fListeners;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,10 +107,10 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
this(null);
|
this(null);
|
||||||
fUseNewRegistry= true;
|
fUseNewRegistry= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates decorator with a shared image registry.
|
* Creates decorator with a shared image registry.
|
||||||
*
|
*
|
||||||
* @param registry The registry to use or <code>null</code> to use the Java plugin's
|
* @param registry The registry to use or <code>null</code> to use the Java plugin's
|
||||||
* image registry.
|
* image registry.
|
||||||
*/
|
*/
|
||||||
|
@ -121,25 +121,27 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
fRegistry= registry;
|
fRegistry= registry;
|
||||||
fProblemChangedListener= null;
|
fProblemChangedListener= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageDescriptorRegistry getRegistry() {
|
private ImageDescriptorRegistry getRegistry() {
|
||||||
if (fRegistry == null) {
|
if (fRegistry == null) {
|
||||||
fRegistry= fUseNewRegistry ? new ImageDescriptorRegistry() : CUIPlugin.getImageDescriptorRegistry();
|
fRegistry= fUseNewRegistry ? new ImageDescriptorRegistry() : CUIPlugin.getImageDescriptorRegistry();
|
||||||
}
|
}
|
||||||
return fRegistry;
|
return fRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see ILabelDecorator#decorateText(String, Object)
|
* @see ILabelDecorator#decorateText(String, Object)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String decorateText(String text, Object element) {
|
public String decorateText(String text, Object element) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see ILabelDecorator#decorateImage(Image, Object)
|
* @see ILabelDecorator#decorateImage(Image, Object)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Image decorateImage(Image image, Object obj) {
|
public Image decorateImage(Image image, Object obj) {
|
||||||
int adornmentFlags= computeAdornmentFlags(obj);
|
int adornmentFlags= computeAdornmentFlags(obj);
|
||||||
if (adornmentFlags != 0) {
|
if (adornmentFlags != 0) {
|
||||||
|
@ -188,7 +190,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
if (e.getStatus().getCode() == IResourceStatus.MARKER_NOT_FOUND) {
|
if (e.getStatus().getCode() == IResourceStatus.MARKER_NOT_FOUND) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUIPlugin.log(e);
|
CUIPlugin.log(e);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -199,7 +201,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int info= 0;
|
int info= 0;
|
||||||
|
|
||||||
IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth);
|
IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth);
|
||||||
if (markers != null) {
|
if (markers != null) {
|
||||||
for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) {
|
for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) {
|
||||||
|
@ -212,7 +214,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
info= ERRORTICK_ERROR;
|
info= ERRORTICK_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@ -227,12 +229,12 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isInside(pos, -1, sourceElement);
|
return isInside(pos, -1, sourceElement);
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// private int getErrorTicksFromWorkingCopy(ITranslationUnit original, ISourceReference sourceElement) throws CoreException {
|
// private int getErrorTicksFromWorkingCopy(ITranslationUnit original, ISourceReference sourceElement) throws CoreException {
|
||||||
// int info= 0;
|
// int info= 0;
|
||||||
// FileEditorInput editorInput= new FileEditorInput((IFile) original.getResource());
|
// FileEditorInput editorInput= new FileEditorInput((IFile) original.getResource());
|
||||||
|
@ -254,7 +256,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
// }
|
// }
|
||||||
// return info;
|
// return info;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// private IMarker isAnnotationInRange(IAnnotationModel model, Annotation annot, ISourceReference sourceElement) throws CoreException {
|
// private IMarker isAnnotationInRange(IAnnotationModel model, Annotation annot, ISourceReference sourceElement) throws CoreException {
|
||||||
// if (annot instanceof MarkerAnnotation) {
|
// if (annot instanceof MarkerAnnotation) {
|
||||||
// IMarker marker= ((MarkerAnnotation) annot).getMarker();
|
// IMarker marker= ((MarkerAnnotation) annot).getMarker();
|
||||||
|
@ -267,17 +269,17 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
// }
|
// }
|
||||||
// return null;
|
// return null;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests if a position is inside the source range of an element. Usually this is done
|
* Tests if a position is inside the source range of an element. Usually this is done
|
||||||
* by looking at the offset. In case the offset equals <code>-1</code>, the line is
|
* by looking at the offset. In case the offset equals <code>-1</code>, the line is
|
||||||
* tested.
|
* tested.
|
||||||
* @param offSet offset to be tested
|
* @param offSet offset to be tested
|
||||||
* @param line line to be tested
|
* @param line line to be tested
|
||||||
* @param sourceElement Source element (must be a ICElement)
|
* @param sourceElement Source element (must be a ICElement)
|
||||||
* @return boolean Return <code>true</code> if position is located inside the source element.
|
* @return boolean Return <code>true</code> if position is located inside the source element.
|
||||||
* @throws CoreException Exception thrown if element range could not be accessed.
|
* @throws CoreException Exception thrown if element range could not be accessed.
|
||||||
*
|
*
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
*/
|
*/
|
||||||
protected boolean isInside(int offSet, int line, ISourceReference sourceElement) throws CoreException {
|
protected boolean isInside(int offSet, int line, ISourceReference sourceElement) throws CoreException {
|
||||||
|
@ -287,14 +289,15 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
return (line >= range.getStartLine() && line <= range.getEndLine());
|
return (line >= range.getStartLine() && line <= range.getEndLine());
|
||||||
}
|
}
|
||||||
int rangeOffset= range.getStartPos();
|
int rangeOffset= range.getStartPos();
|
||||||
return (rangeOffset <= offSet && rangeOffset + range.getLength() > offSet);
|
return (rangeOffset <= offSet && rangeOffset + range.getLength() > offSet);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see IBaseLabelProvider#dispose()
|
* @see IBaseLabelProvider#dispose()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if (fProblemChangedListener != null) {
|
if (fProblemChangedListener != null) {
|
||||||
CUIPlugin.getDefault().getProblemMarkerManager().removeListener(fProblemChangedListener);
|
CUIPlugin.getDefault().getProblemMarkerManager().removeListener(fProblemChangedListener);
|
||||||
|
@ -308,13 +311,15 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see IBaseLabelProvider#isLabelProperty(Object, String)
|
* @see IBaseLabelProvider#isLabelProperty(Object, String)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean isLabelProperty(Object element, String property) {
|
public boolean isLabelProperty(Object element, String property) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see IBaseLabelProvider#addListener(ILabelProviderListener)
|
* @see IBaseLabelProvider#addListener(ILabelProviderListener)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void addListener(ILabelProviderListener listener) {
|
public void addListener(ILabelProviderListener listener) {
|
||||||
if (fListeners == null) {
|
if (fListeners == null) {
|
||||||
fListeners= new ListenerList();
|
fListeners= new ListenerList();
|
||||||
|
@ -322,17 +327,19 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
fListeners.add(listener);
|
fListeners.add(listener);
|
||||||
if (fProblemChangedListener == null) {
|
if (fProblemChangedListener == null) {
|
||||||
fProblemChangedListener= new IProblemChangedListener() {
|
fProblemChangedListener= new IProblemChangedListener() {
|
||||||
|
@Override
|
||||||
public void problemsChanged(IResource[] changedResources, boolean isMarkerChange) {
|
public void problemsChanged(IResource[] changedResources, boolean isMarkerChange) {
|
||||||
fireProblemsChanged(changedResources, isMarkerChange);
|
fireProblemsChanged(changedResources, isMarkerChange);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
CUIPlugin.getDefault().getProblemMarkerManager().addListener(fProblemChangedListener);
|
CUIPlugin.getDefault().getProblemMarkerManager().addListener(fProblemChangedListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see IBaseLabelProvider#removeListener(ILabelProviderListener)
|
* @see IBaseLabelProvider#removeListener(ILabelProviderListener)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void removeListener(ILabelProviderListener listener) {
|
public void removeListener(ILabelProviderListener listener) {
|
||||||
if (fListeners != null) {
|
if (fListeners != null) {
|
||||||
fListeners.remove(listener);
|
fListeners.remove(listener);
|
||||||
|
@ -342,7 +349,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fireProblemsChanged(IResource[] changedResources, boolean isMarkerChange) {
|
protected void fireProblemsChanged(IResource[] changedResources, boolean isMarkerChange) {
|
||||||
if (fListeners != null && !fListeners.isEmpty()) {
|
if (fListeners != null && !fListeners.isEmpty()) {
|
||||||
LabelProviderChangedEvent event= new ProblemsLabelChangedEvent(this, changedResources, isMarkerChange);
|
LabelProviderChangedEvent event= new ProblemsLabelChangedEvent(this, changedResources, isMarkerChange);
|
||||||
|
@ -352,23 +359,24 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration)
|
* @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration)
|
||||||
*/
|
*/
|
||||||
public void decorate(Object element, IDecoration decoration) {
|
@Override
|
||||||
|
public void decorate(Object element, IDecoration decoration) {
|
||||||
int adornmentFlags= computeAdornmentFlags(element);
|
int adornmentFlags= computeAdornmentFlags(element);
|
||||||
|
|
||||||
if ((adornmentFlags & TICK_CONFIGURATION) != 0) {
|
if ((adornmentFlags & TICK_CONFIGURATION) != 0) {
|
||||||
decoration.addOverlay(CPluginImages.DESC_OVR_SETTING);
|
decoration.addOverlay(CPluginImages.DESC_OVR_SETTING);
|
||||||
adornmentFlags &= ~TICK_CONFIGURATION;
|
adornmentFlags &= ~TICK_CONFIGURATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adornmentFlags == ERRORTICK_ERROR) {
|
if (adornmentFlags == ERRORTICK_ERROR) {
|
||||||
decoration.addOverlay(CPluginImages.DESC_OVR_ERROR);
|
decoration.addOverlay(CPluginImages.DESC_OVR_ERROR);
|
||||||
} else if (adornmentFlags == ERRORTICK_WARNING) {
|
} else if (adornmentFlags == ERRORTICK_WARNING) {
|
||||||
decoration.addOverlay(CPluginImages.DESC_OVR_WARNING);
|
decoration.addOverlay(CPluginImages.DESC_OVR_WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue