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

improves constraint context menu in case no specific error messages have been defined

refs 2553
parent c53f12ba
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@
+-----------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.views;
import static org.eclipse.jface.dialogs.MessageDialog.openError;
import static org.eclipse.jface.resource.ImageDescriptor.createFromImage;
import java.util.Collections;
......@@ -26,12 +27,14 @@ import org.eclipse.jface.viewers.DecorationOverlayIcon;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.fortiss.tooling.kernel.model.constraints.ConstrainedWithChecksum;
import org.fortiss.tooling.kernel.model.constraints.ErrorVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.FailVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.IConstrained;
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.service.ICommandStackService;
import org.fortiss.tooling.kernel.service.IConstraintVerificationService;
......@@ -52,7 +55,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: B817A3E9DF60439556DDA0454A6E1010
* @ConQAT.Rating YELLOW Hash: 6B633E486D2B054E8398EF36F0420AFB
*/
public class ConstraintMenu implements IContextMenuContributor {
......@@ -78,16 +81,23 @@ public class ConstraintMenu implements IContextMenuContributor {
*/
private IContributionItem constraintToAction(IConstraint c, IConstrained elt) {
IConstraintVerificationStatus status = c.getVerificationStatus();
ConstraintSubMenuBase m;
if(status instanceof FailVerificationStatus) {
CheckFailingConstraintAction m = new CheckFailingConstraintAction(c, elt);
return m.getItems().length != 0 ? m : new ActionContributionItem(new FailedAction(c));
m = new CheckFailingConstraintAction(c, elt);
} else if(status instanceof ErrorVerificationStatus) {
CheckErrorConstraintAction m = new CheckErrorConstraintAction(c, elt);
return m.getItems().length != 0 ? m : new ActionContributionItem(new ErrorAction(c));
m = new CheckErrorConstraintAction(c, elt);
} else {
CheckOutdatedConstraintAction m = new CheckOutdatedConstraintAction(c, elt);
return m.getItems().length != 0 ? m : new ActionContributionItem(new OutdatedAction(c));
m = new CheckOutdatedConstraintAction(c, elt);
}
if(m.getItems().length > 1) {
return m;
}
IAction uniqueAction = m.getTopActionContribution().getAction();
String txt = m.getMenuText();
String newText = txt.substring(0, txt.length() - 1) + " -> " + uniqueAction.getText();
uniqueAction.setText(newText);
uniqueAction.setImageDescriptor(m.getImageDescriptor());
return m.getTopActionContribution();
}
/** {@inheritDoc} */
......@@ -119,70 +129,6 @@ public class ConstraintMenu implements IContextMenuContributor {
}
}
/********************************************************************************************
* Simple actions: no submenus. Normally should not be used: every constraint verifier should
* provide sufficient information to populate the menu with decent information. But this
* provides at least a default.
*/
/** Base class. */
private class InformationAsAction extends Action {
/** Constructor. */
public InformationAsAction(IConstraint c, String prefix, ImageDescriptor overlay) {
super(getName(c, prefix), getIcon(c, overlay));
}
}
/** Information action for outdated constraints. */
private class OutdatedAction extends InformationAsAction {
/** Constructor. */
public OutdatedAction(IConstraint c) {
super(c, "Outdated constraint: ", ESharedImages.WARNING_OVERLAY.getImageDescriptor());
}
/** {@inheritDoc} */
@Override
public void run() {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Outdated constraint",
this.getText());
}
}
/** Information action for failing constraints. */
private class FailedAction extends InformationAsAction {
/** Constructor. */
public FailedAction(IConstraint c) {
super(c, "Unsatisfied constraint: ", ESharedImages.ERROR_OVERLAY.getImageDescriptor());
}
/** {@inheritDoc} */
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(),
"Unsatisfied constraint", this.getText());
}
}
/** Information action for failing constraints. */
private class ErrorAction extends InformationAsAction {
/** Constructor. */
public ErrorAction(IConstraint c) {
super(c, "Error while checking constraint: ", ESharedImages.ERROR_OVERLAY
.getImageDescriptor());
}
/** {@inheritDoc} */
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(),
"Error while checking constraint", this.getText());
}
}
/** Get the icon of the prototype. */
public static String getName(IConstraint c, String prefix) {
String name = IModelElementHandlerService.INSTANCE.getName(c);
......@@ -200,10 +146,6 @@ public class ConstraintMenu implements IContextMenuContributor {
return new DecorationOverlayIcon(img, descriptors);
}
/********************************************************************************************
* Submenus.
*/
/** Action for creating a new prototype. */
private static class ConstraintSubMenuBase extends MenuManager {
......@@ -223,10 +165,8 @@ public class ConstraintMenu implements IContextMenuContributor {
ImageDescriptor overlay) {
super(getName(c, prefix), getIcon(c, overlay), null);
this.c = c;
if(IConstraintVerificationUIService.INSTANCE.canOpen(c.getVerificationStatus())) {
moreInfoAction = new ActionContributionItem(new OpenStatusAction());
this.add(moreInfoAction);
}
moreInfoAction = new ActionContributionItem(new OpenStatusAction());
this.add(moreInfoAction);
for(ConstrainedWithChecksum cwc : c.getConstrainedsWithChecksum()) {
if(!selectedElt.equals(cwc.getConstrained())) {
this.add(new ActionContributionItem(new GoToConstrained(cwc.getConstrained())));
......@@ -234,6 +174,14 @@ public class ConstraintMenu implements IContextMenuContributor {
}
}
/**
* @return The top action contribution. Useful in case we get aware that there is only one
* contribution and we therefore want to present it without going through a submenu.
*/
public ActionContributionItem getTopActionContribution() {
return moreInfoAction;
}
/** Action to update a constraint. */
protected class OpenStatusAction extends Action {
......@@ -246,14 +194,40 @@ public class ConstraintMenu implements IContextMenuContributor {
/** {@inheritDoc} */
@Override
public void run() {
ICommandStackService.INSTANCE.runAsCommand(c, new Runnable() {
@Override
public void run() {
IConstraintVerificationUIService.INSTANCE.openStatus(c
.getVerificationStatus());
IConstraintVerificationStatus status = c.getVerificationStatus();
if(c.getVerificationStatus() instanceof OutdatedVerificationStatus &&
IConstraintVerificationUIService.INSTANCE.canOpen(status)) {
ICommandStackService.INSTANCE.runAsCommand(c, new Runnable() {
@Override
public void run() {
IConstraintVerificationUIService.INSTANCE.openStatus(status);
}
});
return;
}
if(IConstraintVerificationUIService.INSTANCE.canOpen(status)) {
IConstraintVerificationUIService.INSTANCE.openStatus(status);
} else {
// In the very rare cases where the status cannot be open (if the defaults are
// used, this should not happen), we provide some defaults.
Shell sh = Display.getCurrent().getActiveShell();
String name = IModelElementHandlerService.INSTANCE.getName(c);
String fullName = name == null ? "constraint" : name;
if(status instanceof FailVerificationStatus) {
String msg = (name == null ? "The " : fullName);
msg += " is not satisfied.";
MessageDialog.openInformation(sh, "Unsatisfied constraint", msg);
} else if(status instanceof ErrorVerificationStatus) {
String msg = "There was an error while verifying ";
msg += (name == null ? "the " : "") + fullName + ".";
openError(sh, "Error while verifying constraint", msg);
}
});
if(status instanceof OutdatedVerificationStatus) {
String msg = (name == null ? "The " : fullName) + " is outdated.";
MessageDialog.openWarning(sh, "Outdated constraint", msg);
}
}
}
}
}
......
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