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

makes use of the new service

refs 2620
parent 07034df2
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; ...@@ -55,7 +55,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating YELLOW Hash: B2B88D03669D73EC77D1D69F51E62B54 * @ConQAT.Rating YELLOW Hash: 265A5183E7E403DDC53A61F5B27D8B5A
*/ */
public class ConstraintMenu implements IContextMenuContributor { public class ConstraintMenu implements IContextMenuContributor {
...@@ -67,11 +67,22 @@ public class ConstraintMenu implements IContextMenuContributor { ...@@ -67,11 +67,22 @@ public class ConstraintMenu implements IContextMenuContributor {
return Collections.emptyList(); return Collections.emptyList();
} }
return ((IConstrained)selectedObject).getConstraints().stream() return ((IConstrained)selectedObject).getConstraints().stream()
.filter(c -> !(c.getVerificationStatus() instanceof SuccessVerificationStatus)) .filter(c -> shouldGetMenuEntry(c))
.map(c -> constraintToAction(c, (IConstrained)selectedObject)) .map(c -> constraintToAction(c, (IConstrained)selectedObject))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* @param c
* @return <code>true</code> iff <code>c</code> should get a menu entry, i.e., if not successful
* and activated.
*/
private boolean shouldGetMenuEntry(IConstraint c) {
IConstraintVerificationStatus status =
IConstraintVerificationUIService.getInstance().getStatus(c);
return !(status == null || status instanceof SuccessVerificationStatus);
}
/** /**
* @param c * @param c
* @param elt * @param elt
...@@ -80,14 +91,18 @@ public class ConstraintMenu implements IContextMenuContributor { ...@@ -80,14 +91,18 @@ public class ConstraintMenu implements IContextMenuContributor {
* (not hurtful, but useless, since the user is already seeing it). * (not hurtful, but useless, since the user is already seeing it).
*/ */
private IContributionItem constraintToAction(IConstraint c, IConstrained elt) { private IContributionItem constraintToAction(IConstraint c, IConstrained elt) {
IConstraintVerificationStatus status = c.getVerificationStatus(); IConstraintVerificationStatus status =
IConstraintVerificationUIService.getInstance().getStatus(c);
ConstraintSubMenuBase m; ConstraintSubMenuBase m;
if(status instanceof FailVerificationStatus) { if(status instanceof FailVerificationStatus) {
m = new CheckFailingConstraintAction(c, elt); m = new CheckFailingConstraintAction(c, elt);
} else if(status instanceof ErrorVerificationStatus) { } else if(status instanceof ErrorVerificationStatus) {
m = new CheckErrorConstraintAction(c, elt); m = new CheckErrorConstraintAction(c, elt);
} else { } else if(status instanceof OutdatedVerificationStatus) {
m = new CheckOutdatedConstraintAction(c, elt); m = new CheckOutdatedConstraintAction(c, elt);
} else {
// should not happen
return null;
} }
if(m.getItems().length > 1) { if(m.getItems().length > 1) {
return m; return m;
...@@ -194,19 +209,20 @@ public class ConstraintMenu implements IContextMenuContributor { ...@@ -194,19 +209,20 @@ public class ConstraintMenu implements IContextMenuContributor {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void run() { public void run() {
IConstraintVerificationStatus status = c.getVerificationStatus(); IConstraintVerificationStatus status =
if(c.getVerificationStatus() instanceof OutdatedVerificationStatus && IConstraintVerificationUIService.getInstance().getStatus(c);
IConstraintVerificationUIService.getInstance().canOpen(status)) { if(status instanceof OutdatedVerificationStatus &&
IConstraintVerificationUIService.getInstance().canOpen(c)) {
ICommandStackService.getInstance().runAsCommand(c, new Runnable() { ICommandStackService.getInstance().runAsCommand(c, new Runnable() {
@Override @Override
public void run() { public void run() {
IConstraintVerificationUIService.getInstance().openStatus(status); IConstraintVerificationUIService.getInstance().openStatus(c);
} }
}); });
return; return;
} }
if(IConstraintVerificationUIService.getInstance().canOpen(status)) { if(IConstraintVerificationUIService.getInstance().canOpen(c)) {
IConstraintVerificationUIService.getInstance().openStatus(status); IConstraintVerificationUIService.getInstance().openStatus(c);
} else { } else {
// In the very rare cases where the status cannot be open (if the defaults are // In the very rare cases where the status cannot be open (if the defaults are
// used, this should not happen), we provide some defaults. // used, this should not happen), we provide some defaults.
...@@ -221,8 +237,7 @@ public class ConstraintMenu implements IContextMenuContributor { ...@@ -221,8 +237,7 @@ public class ConstraintMenu implements IContextMenuContributor {
String msg = "There was an error while verifying "; String msg = "There was an error while verifying ";
msg += (name == null ? "the " : "") + fullName + "."; msg += (name == null ? "the " : "") + fullName + ".";
openError(sh, "Error while verifying constraint", msg); openError(sh, "Error while verifying constraint", msg);
} } else if(status instanceof OutdatedVerificationStatus) {
if(status instanceof OutdatedVerificationStatus) {
String msg = (name == null ? "The " : fullName) + " is outdated."; String msg = (name == null ? "The " : fullName) + " is outdated.";
MessageDialog.openWarning(sh, "Outdated constraint", msg); MessageDialog.openWarning(sh, "Outdated constraint", msg);
} }
...@@ -251,8 +266,7 @@ public class ConstraintMenu implements IContextMenuContributor { ...@@ -251,8 +266,7 @@ public class ConstraintMenu implements IContextMenuContributor {
public CheckUnsuccessfulConstraintAction(IConstraint c, IConstrained selectedElt, public CheckUnsuccessfulConstraintAction(IConstraint c, IConstrained selectedElt,
String prefix) { String prefix) {
super(c, selectedElt, prefix, ESharedImages.ERROR_OVERLAY.getImageDescriptor()); super(c, selectedElt, prefix, ESharedImages.ERROR_OVERLAY.getImageDescriptor());
List<IFix> fixes = List<IFix> fixes = IConstraintVerificationService.getInstance().fixes(c);
IConstraintVerificationService.getInstance().fixes(c.getVerificationStatus());
if(fixes != null) { if(fixes != null) {
for(IFix fix : fixes) { for(IFix fix : fixes) {
this.add(new ActionContributionItem(new FixAction(fix))); this.add(new ActionContributionItem(new FixAction(fix)));
...@@ -280,7 +294,7 @@ public class ConstraintMenu implements IContextMenuContributor { ...@@ -280,7 +294,7 @@ public class ConstraintMenu implements IContextMenuContributor {
@Override @Override
public void run() { public void run() {
fix.runFix(c.getVerificationStatus()); fix.runFix(IConstraintVerificationUIService.getInstance().getStatus(c));
} }
}); });
} }
......
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