Skip to content
Snippets Groups Projects
Commit f14600bb authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

improves the warning icons

refs 2334
parent 94b1ffe3
No related branches found
No related tags found
No related merge requests found
...@@ -112,25 +112,12 @@ ...@@ -112,25 +112,12 @@
</extension> </extension>
<extension <extension
point="org.eclipse.ui.decorators"> point="org.eclipse.ui.decorators">
<decorator
class="org.fortiss.tooling.kernel.ui.internal.MarkerServiceLabelDecorator"
id="org.fortiss.tooling.kernel.ui.internal.MarkerServiceLabelDecorator"
label="Marker Service Decorator"
lightweight="true"
location="BOTTOM_LEFT"
state="true">
<enablement>
<objectClass
name="org.eclipse.emf.ecore.EObject">
</objectClass>
</enablement>
</decorator>
<decorator <decorator
class="org.fortiss.tooling.kernel.ui.internal.ConstraintLabelDecorator" class="org.fortiss.tooling.kernel.ui.internal.ConstraintLabelDecorator"
id="org.fortiss.tooling.kernel.ui.internal.ConstraintLabelDecorator" id="org.fortiss.tooling.kernel.ui.internal.ConstraintLabelDecorator"
label="Constraint Decorator" label="Constraint Decorator"
lightweight="true" lightweight="true"
location="TOP_LEFT" location="BOTTOM_LEFT"
state="true"> state="true">
<enablement> <enablement>
<objectClass <objectClass
......
...@@ -17,14 +17,14 @@ $Id$ ...@@ -17,14 +17,14 @@ $Id$
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal; package org.fortiss.tooling.kernel.ui.internal;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.BaseLabelProvider; import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.IDecoration; import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.ILightweightLabelDecorator; import org.eclipse.jface.viewers.ILightweightLabelDecorator;
import org.fortiss.tooling.kernel.model.constraints.IConstrained; import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity;
import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator; import org.fortiss.tooling.kernel.ui.ESharedImages;
import org.fortiss.tooling.kernel.ui.service.IMarkerService; import org.fortiss.tooling.kernel.ui.service.IMarkerService;
import org.fortiss.tooling.kernel.ui.util.ConstraintsUtils; import org.fortiss.tooling.kernel.ui.util.ConstraintsUtils;
import org.fortiss.tooling.kernel.ui.util.ConstraintsUtils.ClassifiedStatuses;
/** /**
* Label decorator for the {@link IMarkerService} decorations: errors, warnings, etc. * Label decorator for the {@link IMarkerService} decorations: errors, warnings, etc.
...@@ -40,21 +40,21 @@ public final class ConstraintLabelDecorator extends BaseLabelProvider implements ...@@ -40,21 +40,21 @@ public final class ConstraintLabelDecorator extends BaseLabelProvider implements
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void decorate(Object element, IDecoration decoration) { public void decorate(Object element, IDecoration decoration) {
if(element instanceof IConstrained) { if(element instanceof EObject) {
IConstrained constrained = (IConstrained)element; ESeverity sev = IMarkerService.INSTANCE.getHighestViolationSeverity((EObject)element);
ClassifiedStatuses classifiedStatuses = sev = ConstraintsUtils.augmentSeverityWithConstraintSeverity(sev, (EObject)element);
ConstraintsUtils.getClassifiedStatuses(constrained); switch(sev) {
if(!classifiedStatuses.failedStatuses.isEmpty()) { case FATAL:
decoration.addOverlay(ToolingKernelUIActivator decoration.addOverlay(ESharedImages.FATAL_OVERLAY.getImageDescriptor());
.getImageDescriptor("icons/constraintFailOverlay.png")); break;
} else if(!classifiedStatuses.errorStatuses.isEmpty()) { case ERROR:
decoration.addOverlay(ToolingKernelUIActivator decoration.addOverlay(ESharedImages.ERROR_OVERLAY.getImageDescriptor());
.getImageDescriptor("icons/constraintErrorOverlay.png")); break;
} else if(!classifiedStatuses.outdatedStatuses.isEmpty()) { case WARNING:
decoration.addOverlay(ToolingKernelUIActivator decoration.addOverlay(ESharedImages.WARNING_OVERLAY.getImageDescriptor());
.getImageDescriptor("icons/constraintOutdatedOverlay.png")); break;
} else if(!classifiedStatuses.failedStatuses.isEmpty()) { default:
decoration.addOverlay(null); // ignore info and debug
} }
} }
} }
......
...@@ -41,10 +41,12 @@ import org.eclipse.ui.progress.UIJob; ...@@ -41,10 +41,12 @@ import org.eclipse.ui.progress.UIJob;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation; import org.fortiss.tooling.kernel.extension.data.IConstraintViolation;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity; import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.model.constraints.IConstrained;
import org.fortiss.tooling.kernel.service.IPersistencyService; import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener; import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener;
import org.fortiss.tooling.kernel.ui.internal.views.MarkerViewPart; import org.fortiss.tooling.kernel.ui.internal.views.MarkerViewPart;
import org.fortiss.tooling.kernel.ui.service.IMarkerService; import org.fortiss.tooling.kernel.ui.service.IMarkerService;
import org.fortiss.tooling.kernel.ui.util.ConstraintsUtils;
/** /**
* This class implements the {@link IMarkerService} interface. * This class implements the {@link IMarkerService} interface.
...@@ -259,10 +261,10 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene ...@@ -259,10 +261,10 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene
/** Returns the highest severity for the given element. */ /** Returns the highest severity for the given element. */
public ESeverity getHighestSeverity(EObject element) { public ESeverity getHighestSeverity(EObject element) {
ESeverity sev = highestSeverityMap.get(element); ESeverity sev = highestSeverityMap.get(element);
if(sev == null) { if(element instanceof IConstrained) {
return ESeverity.lowest(); sev = ConstraintsUtils.augmentSeverityWithConstraintSeverity(sev, element);
} }
return sev; return sev == null ? ESeverity.lowest() : sev;
} }
/** Updates the cache entry. */ /** Updates the cache entry. */
......
...@@ -17,9 +17,14 @@ $Id$ ...@@ -17,9 +17,14 @@ $Id$
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.util; package org.fortiss.tooling.kernel.ui.util;
import static org.fortiss.tooling.kernel.extension.data.IConstraintViolation.SEVERITY_DIRECT_COMPARATOR;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation;
import org.fortiss.tooling.kernel.extension.data.IConstraintViolation.ESeverity;
import org.fortiss.tooling.kernel.model.constraints.ConstraintsFactory; import org.fortiss.tooling.kernel.model.constraints.ConstraintsFactory;
import org.fortiss.tooling.kernel.model.constraints.ErrorVerificationStatus; import org.fortiss.tooling.kernel.model.constraints.ErrorVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.FailVerificationStatus; import org.fortiss.tooling.kernel.model.constraints.FailVerificationStatus;
...@@ -101,4 +106,44 @@ public class ConstraintsUtils { ...@@ -101,4 +106,44 @@ public class ConstraintsUtils {
} }
return res; return res;
} }
/**
* @param c
* @return {@link ESeverity} corresponding to the status of the constraint <code>c</code>
*/
public static ESeverity getConstraintSeverity(IConstraint c) {
if(c.getVerificationStatus() instanceof FailVerificationStatus) {
return ESeverity.ERROR;
} else if(c.getVerificationStatus() instanceof ErrorVerificationStatus) {
return ESeverity.ERROR;
} else if(c.getVerificationStatus() instanceof OutdatedVerificationStatus) {
return ESeverity.WARNING;
} else {
return ESeverity.lowest();
}
}
/**
* @param c
* @return Severity corresponding to the status of the constraints of <code>c</code>.
*/
public static ESeverity getSeverity(IConstrained c) {
try {
return c.getConstraints().stream().map(cstr -> getConstraintSeverity(cstr))
.sorted(IConstraintViolation.SEVERITY_DIRECT_COMPARATOR).findFirst().get();
} catch(Exception e) {
return null;
}
}
public static ESeverity augmentSeverityWithConstraintSeverity(ESeverity sev,
EObject modelElement) {
if(modelElement instanceof IConstrained) {
ESeverity sev2 = ConstraintsUtils.getSeverity((IConstrained)modelElement);
if(sev == null || (sev2 != null && SEVERITY_DIRECT_COMPARATOR.compare(sev2, sev) < 0)) {
sev = sev2;
}
}
return sev == null ? ESeverity.lowest() : sev;
}
} }
...@@ -101,6 +101,16 @@ public interface IConstraintViolation<T extends EObject> extends IAdaptable { ...@@ -101,6 +101,16 @@ public interface IConstraintViolation<T extends EObject> extends IAdaptable {
void applyQuickFix(); void applyQuickFix();
} }
/** Severity comparator. To use directly with lists of severities. */
public static final Comparator<ESeverity> SEVERITY_DIRECT_COMPARATOR =
new Comparator<ESeverity>() {
/** {@inheritDoc} */
@Override
public int compare(ESeverity sev0, ESeverity sev1) {
return ESeverity.getIntSeverity(sev0) - ESeverity.getIntSeverity(sev1);
}
};
/** Stores the severity comparator used during violation sorting. */ /** Stores the severity comparator used during violation sorting. */
public static final Comparator<IConstraintViolation<? extends EObject>> SEVERITY_COMPARATOR = public static final Comparator<IConstraintViolation<? extends EObject>> SEVERITY_COMPARATOR =
new Comparator<IConstraintViolation<? extends EObject>>() { new Comparator<IConstraintViolation<? extends EObject>>() {
...@@ -108,9 +118,9 @@ public interface IConstraintViolation<T extends EObject> extends IAdaptable { ...@@ -108,9 +118,9 @@ public interface IConstraintViolation<T extends EObject> extends IAdaptable {
@Override @Override
public int compare(IConstraintViolation<? extends EObject> arg0, public int compare(IConstraintViolation<? extends EObject> arg0,
IConstraintViolation<? extends EObject> arg1) { IConstraintViolation<? extends EObject> arg1) {
int sev0 = ESeverity.getIntSeverity(arg0.getSeverity()); return SEVERITY_DIRECT_COMPARATOR.compare(arg0.getSeverity(),
int sev1 = ESeverity.getIntSeverity(arg1.getSeverity()); arg1.getSeverity());
return sev0 - sev1;
} }
}; };
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment