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

label provider for constraint statuses

refs 2553
parent ea08c647
No related branches found
No related tags found
No related merge requests found
......@@ -21,8 +21,10 @@ import static org.fortiss.tooling.kernel.extension.data.IConstraintViolation.SEV
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
......@@ -36,6 +38,7 @@ import org.fortiss.tooling.kernel.model.constraints.IConstraint;
import org.fortiss.tooling.kernel.model.constraints.IConstraintVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.OutdatedVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.SuccessVerificationStatus;
import org.fortiss.tooling.kernel.ui.service.IConstraintVerificationUIService;
import org.fortiss.tooling.kernel.utils.EcoreUtils;
/**
......@@ -44,7 +47,7 @@ import org.fortiss.tooling.kernel.utils.EcoreUtils;
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 8DDA51FFF889B7476EF1FBDC78FA3CDF
* @ConQAT.Rating YELLOW Hash: 78F01666E8A80F35348F431EC6DA2895
*/
public class ConstraintsUIUtils {
......@@ -160,6 +163,9 @@ public class ConstraintsUIUtils {
* @return Standard text describing the status of <code>c</code>.
*/
public static String getText(IConstraint c) {
if(c == null) {
return "";
}
IConstraintVerificationStatus status = c.getVerificationStatus();
String mainMsg = "ERROR";
if(status instanceof SuccessVerificationStatus) {
......@@ -172,12 +178,32 @@ public class ConstraintsUIUtils {
return mainMsg;
}
/**
* @param c
* @return Standard "hint" indicating possible action on the status of <code>c</code>.
*/
public static String getHint(IConstraint c) {
if(c == null) {
return "";
}
IConstraintVerificationStatus status = c.getVerificationStatus();
if(status instanceof OutdatedVerificationStatus) {
return "(double-click to update)";
} else if(IConstraintVerificationUIService.INSTANCE.canOpen(status)) {
return "(double-click for more details)";
}
return "";
}
/**
* @param c
* @return Standard colour corresponding to the status of <code>c</code>.
*/
public static Color getColor(IConstraint c) {
Display display = Display.getCurrent();
if(c == null) {
return display.getSystemColor(SWT.COLOR_GRAY);
}
IConstraintVerificationStatus status = c.getVerificationStatus();
if(status instanceof FailVerificationStatus || status instanceof ErrorVerificationStatus) {
return display.getSystemColor(SWT.COLOR_RED);
......@@ -186,4 +212,46 @@ public class ConstraintsUIUtils {
}
return display.getSystemColor(SWT.COLOR_GRAY);
}
/** A label provider for the status of an {@link IConstraint}. */
public static class StatusLabelProvider extends ColumnLabelProvider {
/** See constructor. */
private boolean withHint;
/** Function to retrieve a constraint from the embedded objects. */
private Function<Object, IConstraint> getConstraint;
/**
* Constructor.
*
* @param withHint
* <code>true</code> if you want to display hints like "double-click for more
* details" in the status. If you set it to <code>true</code>, you are
* responsible for providing the corresponding behaviour (e.g., that
* double-clicking will open the status).
* @param getConstraint
* Function returning a constraint from the object to be provided.
*/
public StatusLabelProvider(boolean withHint, Function<Object, IConstraint> getConstraint) {
super();
this.getConstraint = getConstraint;
this.withHint = withHint;
}
/** {@inheritDoc} */
@Override
public String getText(Object element) {
IConstraint cstr = getConstraint.apply(element);
String mainMsg = ConstraintsUIUtils.getText(cstr);
return mainMsg + (withHint ? " " + ConstraintsUIUtils.getHint(cstr) : "");
}
/** {@inheritDoc} */
@Override
public Color getBackground(Object element) {
IConstraint cstr = getConstraint.apply(element);
return ConstraintsUIUtils.getColor(cstr);
}
}
}
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