From e567a9f874f1f8e8d37d88b7a9280a52e2824f1d Mon Sep 17 00:00:00 2001 From: Vincent Aravantinos <aravantinos@fortiss.org> Date: Mon, 25 Apr 2016 14:44:00 +0000 Subject: [PATCH] new actions in case there is not enough information for submenus refs 2553 --- .../ui/internal/views/ConstraintMenu.java | 135 +++++++++++++----- 1 file changed, 102 insertions(+), 33 deletions(-) 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 36c23c7ca..e242503f5 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 @@ -3,14 +3,8 @@ | | $Id$ | | - | Copyright (c) 2004-2008 Technische Universitaet Muenchen | + | Copyright (c) 2016-today fortiss GmbH | | | - | Technische Universitaet Muenchen ######### ########## | - | Institut fuer Informatik - Lehrstuhl IV ## ## ## ## ## | - | Prof. Dr. Manfred Broy ## ## ## ## ## | - | Boltzmannstr. 3 ## ## ## ## ## | - | 85748 Garching bei Muenchen ## ## ## ## ## | - | Germany ## ###### ## ## | +-----------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.ui.internal.views; @@ -26,10 +20,12 @@ import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; 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.fortiss.tooling.kernel.model.constraints.ConstrainedWithChecksum; import org.fortiss.tooling.kernel.model.constraints.ErrorVerificationStatus; import org.fortiss.tooling.kernel.model.constraints.FailVerificationStatus; @@ -56,7 +52,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; * @author hoelzl * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: 0F49BEEDC5B047EB57A50736B039DA00 + * @ConQAT.Rating YELLOW Hash: B817A3E9DF60439556DDA0454A6E1010 */ public class ConstraintMenu implements IContextMenuContributor { @@ -76,18 +72,21 @@ public class ConstraintMenu implements IContextMenuContributor { /** * @param c * @param elt - * @return The submenu corresponding to the status of <code>c</code>. <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). + * @return The submenu or menu entry corresponding to the status of <code>c</code>. + * <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) { IConstraintVerificationStatus status = c.getVerificationStatus(); if(status instanceof FailVerificationStatus) { - return new CheckFailingConstraintAction(c, elt); + CheckFailingConstraintAction m = new CheckFailingConstraintAction(c, elt); + return m.getItems().length != 0 ? m : new ActionContributionItem(new FailedAction(c)); } else if(status instanceof ErrorVerificationStatus) { - return new CheckErrorConstraintAction(c, elt); + CheckErrorConstraintAction m = new CheckErrorConstraintAction(c, elt); + return m.getItems().length != 0 ? m : new ActionContributionItem(new ErrorAction(c)); } else { - return new CheckOutdatedConstraintAction(c, elt); + CheckOutdatedConstraintAction m = new CheckOutdatedConstraintAction(c, elt); + return m.getItems().length != 0 ? m : new ActionContributionItem(new OutdatedAction(c)); } } @@ -120,6 +119,91 @@ 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); + return prefix + (name == null ? "Constraint" : name); + } + + /** Get the icon of the prototype. */ + public static ImageDescriptor getIcon(IConstraint c, ImageDescriptor overlay) { + Image img = IModelElementHandlerService.INSTANCE.getIcon(c); + if(img == null) { + return null; + } + ImageDescriptor[] descriptors = new ImageDescriptor[5]; + descriptors[IDecoration.BOTTOM_LEFT] = overlay; + return new DecorationOverlayIcon(img, descriptors); + } + + /******************************************************************************************** + * Submenus. + */ + /** Action for creating a new prototype. */ private static class ConstraintSubMenuBase extends MenuManager { @@ -139,8 +223,10 @@ public class ConstraintMenu implements IContextMenuContributor { ImageDescriptor overlay) { super(getName(c, prefix), getIcon(c, overlay), null); this.c = c; - moreInfoAction = new ActionContributionItem(new OpenStatusAction()); - this.add(moreInfoAction); + if(IConstraintVerificationUIService.INSTANCE.canOpen(c.getVerificationStatus())) { + 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()))); @@ -148,23 +234,6 @@ public class ConstraintMenu implements IContextMenuContributor { } } - /** Get the icon of the prototype. */ - public static String getName(IConstraint c, String prefix) { - String name = IModelElementHandlerService.INSTANCE.getName(c); - return prefix + (name == null ? "Constraint" : name); - } - - /** Get the icon of the prototype. */ - public static ImageDescriptor getIcon(IConstraint c, ImageDescriptor overlay) { - Image img = IModelElementHandlerService.INSTANCE.getIcon(c); - if(img == null) { - return null; - } - ImageDescriptor[] descriptors = new ImageDescriptor[5]; - descriptors[IDecoration.BOTTOM_LEFT] = overlay; - return new DecorationOverlayIcon(img, descriptors); - } - /** Action to update a constraint. */ protected class OpenStatusAction extends Action { -- GitLab