diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java index 83b91934d3411d36656b7a67fab471dc78b1e4bc..fe0210e6ba0a318bf899860af4a0996eba754b7f 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java @@ -29,10 +29,10 @@ 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.Constraint; 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; @@ -55,7 +55,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: 265A5183E7E403DDC53A61F5B27D8B5A + * @ConQAT.Rating YELLOW Hash: 3F5A89AA4B903D0407589F4EC4E7E7B9 */ public class ConstraintMenu implements IContextMenuContributor { @@ -77,7 +77,7 @@ public class ConstraintMenu implements IContextMenuContributor { * @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) { + private boolean shouldGetMenuEntry(Constraint c) { IConstraintVerificationStatus status = IConstraintVerificationUIService.getInstance().getStatus(c); return !(status == null || status instanceof SuccessVerificationStatus); @@ -90,7 +90,7 @@ public class ConstraintMenu implements IContextMenuContributor { * <code>elt</code> is needed to prevent displaying an entry to go to <code>elt</code> * (not hurtful, but useless, since the user is already seeing it). */ - private IContributionItem constraintToAction(IConstraint c, IConstrained elt) { + private IContributionItem constraintToAction(Constraint c, IConstrained elt) { IConstraintVerificationStatus status = IConstraintVerificationUIService.getInstance().getStatus(c); ConstraintSubMenuBase m; @@ -109,7 +109,7 @@ public class ConstraintMenu implements IContextMenuContributor { } IAction uniqueAction = m.getTopActionContribution().getAction(); String txt = m.getMenuText(); - String newText = txt.substring(0, txt.length() - 1) + " -> " + uniqueAction.getText(); + String newText = txt + " -> " + uniqueAction.getText(); uniqueAction.setText(newText); uniqueAction.setImageDescriptor(m.getImageDescriptor()); return m.getTopActionContribution(); @@ -145,14 +145,18 @@ public class ConstraintMenu implements IContextMenuContributor { } /** Get the icon of the prototype. */ - public static String getName(IConstraint c, String prefix) { - String name = IModelElementHandlerService.getInstance().getName(c); - return prefix + (name == null ? "Constraint" : name); + public static String getText(Constraint c, String suffix) { + String id = c.getConstraintTypeID(); + String desc = IConstraintVerificationUIService.getInstance().getDescription(id); + return "\"" + desc + "\": " + suffix; } /** Get the icon of the prototype. */ - public static ImageDescriptor getIcon(IConstraint c, ImageDescriptor overlay) { - Image img = IModelElementHandlerService.getInstance().getIcon(c); + public static ImageDescriptor getIcon(Constraint c, ImageDescriptor overlay) { + String id = c.getConstraintTypeID(); + ImageDescriptor imgd = + IConstraintVerificationUIService.getInstance().getIconImageDescriptor(id); + Image img = imgd == null ? null : imgd.createImage(); if(img == null) { return null; } @@ -165,7 +169,7 @@ public class ConstraintMenu implements IContextMenuContributor { private static class ConstraintSubMenuBase extends MenuManager { /** The constraint. */ - protected IConstraint c; + protected Constraint c; /** * The action to get more information about the constraint status. @@ -176,9 +180,9 @@ public class ConstraintMenu implements IContextMenuContributor { protected ActionContributionItem moreInfoAction; /** Constructor. */ - public ConstraintSubMenuBase(IConstraint c, IConstrained selectedElt, String prefix, + public ConstraintSubMenuBase(Constraint c, IConstrained selectedElt, String suffix, ImageDescriptor overlay) { - super(getName(c, prefix), getIcon(c, overlay), null); + super(getText(c, suffix), getIcon(c, overlay), null); this.c = c; moreInfoAction = new ActionContributionItem(new OpenStatusAction()); this.add(moreInfoAction); @@ -202,7 +206,7 @@ public class ConstraintMenu implements IContextMenuContributor { /** Constructor. */ public OpenStatusAction() { - super("Get more information", ToolingKernelUIActivator + super("More information...", ToolingKernelUIActivator .getImageDescriptor("icons/info.gif")); } @@ -227,18 +231,17 @@ public class ConstraintMenu implements IContextMenuContributor { // 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.getInstance().getName(c); - String fullName = name == null ? "constraint" : name; + String name = ConstraintMenu.getText(c, ""); if(status instanceof FailVerificationStatus) { - String msg = (name == null ? "The " : fullName); + String msg = (name == null ? "The " : name); 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 + "."; + msg += (name == null ? "the " : "") + name + "."; openError(sh, "Error while verifying constraint", msg); } else if(status instanceof OutdatedVerificationStatus) { - String msg = (name == null ? "The " : fullName) + " is outdated."; + String msg = (name == null ? "The " : name) + " is outdated."; MessageDialog.openWarning(sh, "Outdated constraint", msg); } } @@ -250,9 +253,8 @@ public class ConstraintMenu implements IContextMenuContributor { private static class CheckOutdatedConstraintAction extends ConstraintSubMenuBase { /** Constructor. */ - public CheckOutdatedConstraintAction(IConstraint c, IConstrained selectedElt) { - super(c, selectedElt, "Outdated constraint: ", ESharedImages.WARNING_OVERLAY - .getImageDescriptor()); + public CheckOutdatedConstraintAction(Constraint c, IConstrained selectedElt) { + super(c, selectedElt, "Outdated", ESharedImages.WARNING_OVERLAY.getImageDescriptor()); IAction action = moreInfoAction.getAction(); action.setImageDescriptor(ToolingKernelUIActivator.getImageDescriptor("icons/ok.png")); action.setText("Check"); @@ -263,9 +265,9 @@ public class ConstraintMenu implements IContextMenuContributor { private static class CheckUnsuccessfulConstraintAction extends ConstraintSubMenuBase { /** Constructor. */ - public CheckUnsuccessfulConstraintAction(IConstraint c, IConstrained selectedElt, - String prefix) { - super(c, selectedElt, prefix, ESharedImages.ERROR_OVERLAY.getImageDescriptor()); + public CheckUnsuccessfulConstraintAction(Constraint c, IConstrained selectedElt, + String suffix) { + super(c, selectedElt, suffix, getOverlay(c)); List<IFix> fixes = IConstraintVerificationService.getInstance().fixes(c); if(fixes != null) { for(IFix fix : fixes) { @@ -274,6 +276,14 @@ public class ConstraintMenu implements IContextMenuContributor { } } + /** Get the correct overlay for the given constraint. */ + private static ImageDescriptor getOverlay(Constraint c) { + if(IConstraintVerificationUIService.getInstance().shallDisplayAsWarning(c)) { + return ESharedImages.WARNING_OVERLAY.getImageDescriptor(); + } + return ESharedImages.ERROR_OVERLAY.getImageDescriptor(); + } + /** Action to update a constraint. */ private class FixAction extends Action { @@ -305,8 +315,8 @@ public class ConstraintMenu implements IContextMenuContributor { private static class CheckFailingConstraintAction extends CheckUnsuccessfulConstraintAction { /** Constructor. */ - public CheckFailingConstraintAction(IConstraint c, IConstrained selectedElt) { - super(c, selectedElt, "Unsatisfied constraint: "); + public CheckFailingConstraintAction(Constraint c, IConstrained selectedElt) { + super(c, selectedElt, "Unsatisfied"); } } @@ -314,8 +324,8 @@ public class ConstraintMenu implements IContextMenuContributor { private static class CheckErrorConstraintAction extends CheckUnsuccessfulConstraintAction { /** Constructor. */ - public CheckErrorConstraintAction(IConstraint c, IConstrained selectedElt) { - super(c, selectedElt, "Error while checking constraint: "); + public CheckErrorConstraintAction(Constraint c, IConstrained selectedElt) { + super(c, selectedElt, "Error encountered"); } } }