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

defines "onOutdate"

refs 2553
parent e0752e9c
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,9 @@ public interface IConstraintVerifierUI<T extends IConstraint> extends IEObjectAw
/** True if the given status can be open. */
public boolean canOpen(IConstraintVerificationStatus status);
/** Method to execute when a constraint gets outdated. */
public void onOutdate(T constraint);
/**
* @param status
* @return a short user-friendly description explaining the status.
......
......@@ -19,6 +19,10 @@ package org.fortiss.tooling.kernel.ui.extension.base;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
......@@ -41,6 +45,7 @@ import org.fortiss.tooling.kernel.service.IConstraintVerificationService;
import org.fortiss.tooling.kernel.service.IConstraintVerificationService.IFix;
import org.fortiss.tooling.kernel.ui.extension.IConstraintVerifierUI;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
import org.fortiss.tooling.kernel.ui.util.ConstraintsUIUtils;
/**
* Base class for constraint verification GUI.
......@@ -48,125 +53,163 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author vincent
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 2A312426A51C9EC5DA5F5520111FAED6
* @ConQAT.Rating YELLOW Hash: C5B7A42314634675038E8C625160CAAE
*/
public class ConstraintVerifierUIBase<T extends IConstraint> implements IConstraintVerifierUI<T> {
public class ConstraintVerifierUIBases {
/** {@inheritDoc} */
@Override
public boolean openStatus(IConstraintVerificationStatus status) {
if(!canOpen(status)) {
return false;
}
if(status instanceof OutdatedVerificationStatus) {
IConstraint constraint = status.getConstraint();
IConstraintVerificationService.INSTANCE.verify(constraint);
IConstraintVerificationStatus currentStatus = constraint.getVerificationStatus();
if(currentStatus instanceof ErrorVerificationStatus & canOpen(currentStatus)) {
openStatus(currentStatus);
/** Base class for constraint verification GUI. */
public static class ConstraintVerifierUIBase<T extends IConstraint> implements
IConstraintVerifierUI<T> {
/** {@inheritDoc} */
@Override
public boolean openStatus(IConstraintVerificationStatus status) {
if(!canOpen(status)) {
return false;
}
return true;
}
if(status instanceof FailVerificationStatus || status instanceof ErrorVerificationStatus) {
List<IFix> fixes = IConstraintVerificationService.INSTANCE.fixes(status);
Shell shell = Display.getCurrent().getActiveShell();
int result = new FixDialog(shell, status, getMessage(status), fixes).open();
if(fixes.size() == 1 && result == 0) {
// get(0) because the size is equal to 1 by the previous test
fixes.get(0).runFix(status);
} else if(result > 1) {
fixes.get(result - 2).runFix(status);
if(status instanceof OutdatedVerificationStatus) {
IConstraint constraint = status.getConstraint();
IConstraintVerificationService.INSTANCE.verify(constraint);
IConstraintVerificationStatus currentStatus = constraint.getVerificationStatus();
if(currentStatus instanceof ErrorVerificationStatus & canOpen(currentStatus)) {
openStatus(currentStatus);
}
return true;
}
return true;
if(status instanceof FailVerificationStatus ||
status instanceof ErrorVerificationStatus) {
List<IFix> fixes = IConstraintVerificationService.INSTANCE.fixes(status);
Shell shell = Display.getCurrent().getActiveShell();
int result = new FixDialog(shell, status, getMessage(status), fixes).open();
if(fixes.size() == 1 && result == 0) {
// get(0) because the size is equal to 1 by the previous test
fixes.get(0).runFix(status);
} else if(result > 1) {
fixes.get(result - 2).runFix(status);
}
return true;
}
return false;
}
return false;
}
/** {@inheritDoc} */
@Override
public boolean canOpen(IConstraintVerificationStatus status) {
return(!(status instanceof SuccessVerificationStatus));
}
/** {@inheritDoc} */
@Override
public boolean canOpen(IConstraintVerificationStatus status) {
return(!(status instanceof SuccessVerificationStatus));
}
/** Dialog presenting the error/failure and the possible fix(es). */
private static class FixDialog extends MessageDialog {
/** Dialog presenting the error/failure and the possible fix(es). */
private static class FixDialog extends MessageDialog {
/** List of possible fixes. */
List<IFix> fixes;
/** List of possible fixes. */
List<IFix> fixes;
/** Constructor. */
public FixDialog(Shell parentShell, IConstraintVerificationStatus s, String msg,
List<IFix> fixes) {
super(parentShell, getTitle(s), null, msg, getIconType(s), getButtons(fixes), 1);
this.fixes = fixes;
}
/** Constructor. */
public FixDialog(Shell parentShell, IConstraintVerificationStatus s, String msg,
List<IFix> fixes) {
super(parentShell, getTitle(s), null, msg, getIconType(s), getButtons(fixes), 1);
this.fixes = fixes;
}
/**
* @param fixes
* @return Buttons to display: "OK" is always displayed. In addition, if there is *only one
* fix*, we provide one button for this fix. If there is more than one possible fix,
* they will displayed instead horizontally (via getCustomArea).
*/
private static String[] getButtons(List<IFix> fixes) {
String[] res = new String[fixes.size() == 1 ? 2 : 1];
if(fixes.size() == 1) {
// get(0) because the size is equal to 1 by the previous test
res[0] = "Fix: " + fixes.get(0).getDescription();
/**
* @param fixes
* @return Buttons to display: "OK" is always displayed. In addition, if there is *only
* one
* fix*, we provide one button for this fix. If there is more than one possible
* fix,
* they will displayed instead horizontally (via getCustomArea).
*/
private static String[] getButtons(List<IFix> fixes) {
String[] res = new String[fixes.size() == 1 ? 2 : 1];
if(fixes.size() == 1) {
// get(0) because the size is equal to 1 by the previous test
res[0] = "Fix: " + fixes.get(0).getDescription();
}
res[res.length - 1] = "OK";
return res;
}
/**
* @param s
* @return the icon type corresponding to <code>s</code>.
*/
private static String getTitle(IConstraintVerificationStatus s) {
if(s instanceof FailVerificationStatus) {
return "Verification of constraint failed";
}
return "Error during constraint verification";
}
res[res.length - 1] = "OK";
return res;
}
/**
* @param s
* @return the icon type corresponding to <code>s</code>.
*/
private static String getTitle(IConstraintVerificationStatus s) {
if(s instanceof FailVerificationStatus) {
return "Verification of constraint failed";
/**
* @param s
* @return the icon type corresponding to <code>s</code>.
*/
private static int getIconType(IConstraintVerificationStatus s) {
return s instanceof FailVerificationStatus ? MessageDialog.WARNING : ERROR;
}
/** {@inheritDoc} */
@Override
protected Control createCustomArea(Composite parent) {
if(fixes.size() <= 1) {
return null;
}
Group buttonGroup = new Group(parent, SWT.NONE);
buttonGroup.setLayout(new GridLayout());
buttonGroup.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false));
buttonGroup.setText("Possible fixes");
for(IFix fix : fixes) {
Button button = new Button(buttonGroup, SWT.None);
button.setText(fix.getDescription());
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
buttonPressed(fixes.indexOf(fix) + 1);
}
});
}
// Does not matter what we return as long as it's not null
return buttonGroup;
}
return "Error during constraint verification";
}
/**
* @param s
* @return the icon type corresponding to <code>s</code>.
*/
private static int getIconType(IConstraintVerificationStatus s) {
return s instanceof FailVerificationStatus ? MessageDialog.WARNING : ERROR;
/** {@inheritDoc} */
@Override
public String getMessage(IConstraintVerificationStatus s) {
// Default message. Inheriting classes SHOULD specialize.
String name = IModelElementHandlerService.INSTANCE.getName(s.getConstraint());
String pre =
s instanceof ErrorVerificationStatus ? "Error while checking" : "Unsatisfied";
return pre + " constraint" + (name == null ? "." : ": \"" + name + "\"");
}
/** {@inheritDoc} */
@Override
protected Control createCustomArea(Composite parent) {
if(fixes.size() <= 1) {
return null;
}
Group buttonGroup = new Group(parent, SWT.NONE);
buttonGroup.setLayout(new GridLayout());
buttonGroup.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false));
buttonGroup.setText("Possible fixes");
for(IFix fix : fixes) {
Button button = new Button(buttonGroup, SWT.None);
button.setText(fix.getDescription());
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
buttonPressed(fixes.indexOf(fix) + 1);
}
});
}
// Does not matter what we return as long as it's not null
return buttonGroup;
public void onOutdate(T constraint) {
// By default do nothing
}
}
/** {@inheritDoc} */
@Override
public String getMessage(IConstraintVerificationStatus s) {
// Default message. Inheriting classes SHOULD specialize.
String name = IModelElementHandlerService.INSTANCE.getName(s.getConstraint());
String pre = s instanceof ErrorVerificationStatus ? "Error while checking" : "Unsatisfied";
return pre + " constraint" + (name == null ? "." : ": \"" + name + "\"");
/**
* Base class for constraint verifier UIs which automatically trigger a new check when the
* constraint gets outdated.
*/
public static class ConstraintVerifierUIBaseAutocheck<T extends IConstraint> extends
ConstraintVerifierUIBase<T> {
/** {@inheritDoc} */
@Override
public void onOutdate(T constraint) {
Display display = Display.getCurrent();
(new Job("Constraint verification job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
synchronized(constraint) {
IConstraintVerificationService.INSTANCE.verify(constraint);
}
display.asyncExec(() -> ConstraintsUIUtils.triggerMarkersRefresh(constraint));
return Status.OK_STATUS;
}
}).schedule();
}
}
}
package org.fortiss.tooling.kernel.ui.internal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.TreeIterator;
......@@ -16,12 +11,10 @@ import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
import org.fortiss.tooling.kernel.introspection.KernelIntrospectionSystemService;
import org.fortiss.tooling.kernel.model.IIdLabeled;
import org.fortiss.tooling.kernel.model.constraints.ConstrainedWithChecksum;
import org.fortiss.tooling.kernel.model.constraints.ConstraintsPackage;
import org.fortiss.tooling.kernel.model.constraints.IConstrained;
......@@ -29,7 +22,6 @@ 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.service.IConstraintVerificationService;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.service.base.EObjectAwareServiceBase;
import org.fortiss.tooling.kernel.ui.extension.IConstraintVerifierUI;
import org.fortiss.tooling.kernel.ui.internal.introspection.items.ConstraintVerificationUIServiceIntrospectionDetailsItem;
......@@ -45,7 +37,7 @@ import org.fortiss.tooling.kernel.utils.LoggingUtils;
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: FE1A803DA840B0859B77581F656FCAD8
* @ConQAT.Rating YELLOW Hash: ED5A17BE7E2FCB66B36AA7F8954DEEE3
*/
public final class ConstraintVerificationUIService extends
EObjectAwareServiceBase<IConstraintVerifierUI<IConstraint>> implements
......@@ -127,7 +119,7 @@ public final class ConstraintVerificationUIService extends
}
/** Adapter for changes on constrained elements. */
private static class ConstrainedAdapters {
private class ConstrainedAdapters {
/** Map containing the adapter of each constrained element. */
Map<IConstrained, Adapter> constrainedAdapterMap;
......@@ -171,25 +163,8 @@ public final class ConstraintVerificationUIService extends
}
if(!IConstraintVerificationService.INSTANCE.isUpToDate(constraint)) {
if(constraint.isAutoCheck()) {
ITopLevelElement modelContext =
IPersistencyService.INSTANCE.getTopLevelElementFor(constraint);
// IDs can be in a bad state if the notification is triggered during some
// composition
if(!checkIDs(modelContext)) {
return false;
}
Display display = Display.getCurrent();
(new Job("Constraint verification job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
synchronized(constraint) {
IConstraintVerificationService.INSTANCE.verify(constraint);
}
display.asyncExec(() -> ConstraintsUIUtils
.triggerMarkersRefresh(constraint));
return Status.OK_STATUS;
}
}).schedule();
IConstraintVerifierUI<IConstraint> verifier = getFirstVerifier(constraint);
verifier.onOutdate(constraint);
} else if(!(constraint.getVerificationStatus() instanceof OutdatedVerificationStatus)) {
ConstraintsUtils.createOutdatedVerificationStatus(constraint);
ConstraintsUIUtils.triggerMarkersRefresh(constraint);
......@@ -257,18 +232,6 @@ public final class ConstraintVerificationUIService extends
return false;
}
/** Checks whether elements necessitating IDs do have an ID. */
private static boolean checkIDs(ITopLevelElement modelContext) {
Iterator<EObject> i = modelContext.getRootModelElement().eAllContents();
while(i.hasNext()) {
EObject eo = i.next();
if(eo instanceof IIdLabeled && ((IIdLabeled)eo).getId() <= 0) {
return false;
}
}
return true;
}
/** {@inheritDoc} */
@Override
protected String getExtensionPointName() {
......
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