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

context menu for constraints

refs 2553
parent 6b92dba4
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
+-----------------------------------------------------------------------*/ +-----------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.views; package org.fortiss.tooling.kernel.ui.internal.views;
import static org.eclipse.jface.resource.ImageDescriptor.createFromImage;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -21,29 +23,41 @@ import java.util.stream.Collectors; ...@@ -21,29 +23,41 @@ import java.util.stream.Collectors;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DecorationOverlayIcon; import org.eclipse.jface.viewers.DecorationOverlayIcon;
import org.eclipse.jface.viewers.IDecoration; import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
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.IConstrained;
import org.fortiss.tooling.kernel.model.constraints.IConstraint; 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.OutdatedVerificationStatus;
import org.fortiss.tooling.kernel.model.constraints.SuccessVerificationStatus;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.service.IConstraintVerificationService;
import org.fortiss.tooling.kernel.service.IConstraintVerificationService.IFix;
import org.fortiss.tooling.kernel.ui.ESharedImages; import org.fortiss.tooling.kernel.ui.ESharedImages;
import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor; import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler; import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider; import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
import org.fortiss.tooling.kernel.ui.service.IConstraintVerificationUIService;
import org.fortiss.tooling.kernel.ui.service.IContextMenuService; import org.fortiss.tooling.kernel.ui.service.IContextMenuService;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/** /**
* The contributor for the dynamic new menu of the navigator view based on model * Context menu for constraints.
* element composition.
* *
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: 49C26BBDB13EC81195004EDDE740E2C3 * @ConQAT.Rating YELLOW Hash: 480E689337B14B883F1AA3967CA73AEC
*/ */
public class ConstraintMenu implements IContextMenuContributor { public class ConstraintMenu implements IContextMenuContributor {
...@@ -55,60 +69,196 @@ public class ConstraintMenu implements IContextMenuContributor { ...@@ -55,60 +69,196 @@ 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 OutdatedVerificationStatus) .filter(c -> !(c.getVerificationStatus() instanceof SuccessVerificationStatus))
.map(c -> new ActionContributionItem(new CheckOutdatedConstraintAction(c))) .map(c -> constraintToAction(c, (IConstrained)selectedObject))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* @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).
*/
private IContributionItem constraintToAction(IConstraint c, IConstrained elt) {
IConstraintVerificationStatus status = c.getVerificationStatus();
if(status instanceof OutdatedVerificationStatus) {
return new CheckOutdatedConstraintAction(c, elt);
} else if(status instanceof FailVerificationStatus) {
return new CheckFailingConstraintAction(c, elt);
} else if(status instanceof ErrorVerificationStatus) {
return new CheckErrorConstraintAction(c, elt);
} else {
return null;
}
}
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public String getMenuSectionID() { public String getMenuSectionID() {
return IContextMenuService.TOP_MOST_MENU_SECTION_ID; return IContextMenuService.TOP_MOST_MENU_SECTION_ID;
} }
/** Action for creating a new prototype. */ /** Action to "go to" a given constrained element. */
private static class CheckOutdatedConstraintAction extends Action { private static class GoToConstrained extends Action {
/** The constrained element to open. */
private IConstrained c;
/** Constructor. */ /** Constructor. */
public CheckOutdatedConstraintAction(IConstraint c) { public GoToConstrained(IConstrained c) {
super(getName(c), getIcon(c)); super("Go to " + IModelElementHandlerService.INSTANCE.getName(c),
createFromImage(IModelElementHandlerService.INSTANCE.getIcon(c)));
this.c = c;
} }
/** Get the icon of the prototype. */ /** {@inheritDoc} */
public static String getName(IConstraint c) { @Override
public void run() {
IModelElementHandler<EObject> handler = IModelElementHandler<EObject> handler =
IModelElementHandlerService.INSTANCE.getModelElementHandler(c); IModelElementHandlerService.INSTANCE.getModelElementHandler(c);
EObject eltToOpen = handler == null ? c : handler.handleOpenModelElementRequest(c);
IModelEditorBindingService.INSTANCE.openInEditor(eltToOpen);
}
}
/** Action for creating a new prototype. */
private static class ConstraintSubMenuBase extends MenuManager {
/** The constraint. */
protected IConstraint c;
return handler == null ? "[Outdated constraint]" : handler.getName(c); /**
* The action to get more information about the constraint status.
* The same action allows to update an outdated constraint status (there is no
* "more information" to get out of an outdated constraint); it is stored in a field to
* allow the "update" action to change the icon and the text going with it.
*/
protected ActionContributionItem moreInfoAction;
/** Constructor. */
public ConstraintSubMenuBase(IConstraint c, IConstrained selectedElt, String prefix,
ImageDescriptor overlay) {
super(getName(c, prefix), getIcon(c, overlay), null);
this.c = c;
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())));
}
}
} }
/** Get the icon of the prototype. */ /** Get the icon of the prototype. */
public static ImageDescriptor getIcon(IConstraint c) { public static String getName(IConstraint c, String prefix) {
IModelElementHandler<EObject> handler = String name = IModelElementHandlerService.INSTANCE.getName(c);
IModelElementHandlerService.INSTANCE.getModelElementHandler(c); return prefix + (name == null ? "Constraint" : name);
if(handler == null) { }
return null;
} /** Get the icon of the prototype. */
Image img = handler.getIcon(c); public static ImageDescriptor getIcon(IConstraint c, ImageDescriptor overlay) {
Image img = IModelElementHandlerService.INSTANCE.getIcon(c);
if(img == null) { if(img == null) {
return null; return null;
} }
ImageDescriptor overlay = ESharedImages.WARNING_OVERLAY.getImageDescriptor();
ImageDescriptor[] descriptors = new ImageDescriptor[5]; ImageDescriptor[] descriptors = new ImageDescriptor[5];
descriptors[IDecoration.BOTTOM_LEFT] = overlay; descriptors[IDecoration.BOTTOM_LEFT] = overlay;
return new DecorationOverlayIcon(img, descriptors); return new DecorationOverlayIcon(img, descriptors);
} }
/** {@inheritDoc} */ /** Action to update a constraint. */
@Override protected class OpenStatusAction extends Action {
public void run() {
// ICommandStackService.INSTANCE.runAsCommand(container, new Runnable() { /** Constructor. */
// public OpenStatusAction() {
// @Override super("Get more information", ToolingKernelUIActivator
// public void run() { .getImageDescriptor("icons/info.gif"));
// }
// }
// }); /** {@inheritDoc} */
@Override
public void run() {
ICommandStackService.INSTANCE.runAsCommand(c, new Runnable() {
@Override
public void run() {
IConstraintVerificationUIService.INSTANCE.openStatus(c
.getVerificationStatus());
}
});
}
}
}
/** Action for creating a new prototype. */
private static class CheckOutdatedConstraintAction extends ConstraintSubMenuBase {
/** Constructor. */
public CheckOutdatedConstraintAction(IConstraint c, IConstrained selectedElt) {
super(c, selectedElt, "Outdated constraint: ", ESharedImages.WARNING_OVERLAY
.getImageDescriptor());
IAction action = moreInfoAction.getAction();
action.setImageDescriptor(ToolingKernelUIActivator.getImageDescriptor("icons/ok.png"));
action.setText("Check");
}
}
/** Action for creating a new prototype. */
private static class CheckUnsuccessfulConstraintAction extends ConstraintSubMenuBase {
/** Constructor. */
public CheckUnsuccessfulConstraintAction(IConstraint c, IConstrained selectedElt,
String prefix) {
super(c, selectedElt, prefix, ESharedImages.ERROR_OVERLAY.getImageDescriptor());
for(IFix fix : IConstraintVerificationService.INSTANCE.fixes(c.getVerificationStatus())) {
this.add(new ActionContributionItem(new FixAction(fix)));
}
}
/** Action to update a constraint. */
private class FixAction extends Action {
/** The fix to achieve. */
IFix fix;
/** Constructor. */
public FixAction(IFix fix) {
super(fix.getDescription(), ToolingKernelUIActivator
.getImageDescriptor("icons/fix.png"));
this.fix = fix;
}
/** {@inheritDoc} */
@Override
public void run() {
ICommandStackService.INSTANCE.runAsCommand(c, new Runnable() {
@Override
public void run() {
fix.runFix(c.getVerificationStatus());
}
});
}
}
}
/** Action for creating a new prototype. */
private static class CheckFailingConstraintAction extends CheckUnsuccessfulConstraintAction {
/** Constructor. */
public CheckFailingConstraintAction(IConstraint c, IConstrained selectedElt) {
super(c, selectedElt, "Unsatisfied constraint: ");
}
}
/** Action for creating a new prototype. */
private static class CheckErrorConstraintAction extends CheckUnsuccessfulConstraintAction {
/** Constructor. */
public CheckErrorConstraintAction(IConstraint c, IConstrained selectedElt) {
super(c, selectedElt, "Error while checking constraint: ");
} }
} }
} }
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