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

fixes + improves naming conventions

refs 2701
parent ae2465e7
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,6 @@
+-----------------------------------------------------------------------*/
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;
......@@ -21,13 +20,10 @@ 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.eclipse.swt.widgets.Shell;
import org.fortiss.tooling.kernel.model.constraints.ConstrainedWithChecksum;
import org.fortiss.tooling.kernel.model.constraints.ConstraintInstance;
import org.fortiss.tooling.kernel.model.constraints.ErrorConstraintInstanceStatus;
......@@ -55,7 +51,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 1B21D22C8C6B64442A8C6719C03D8D4E
* @ConQAT.Rating YELLOW Hash: 08124620B9BD785A307D615579E646E2
*/
public class ConstraintMenu implements IContextMenuContributor {
......@@ -67,50 +63,53 @@ public class ConstraintMenu implements IContextMenuContributor {
return Collections.emptyList();
}
return ((IConstrained)selectedObject).getConstraintInstances().stream()
.filter(c -> shouldGetMenuEntry(c))
.map(c -> constraintToAction(c, (IConstrained)selectedObject))
.filter(ci -> shouldGetMenuEntry(ci))
.map(ci -> constraintToAction(ci, (IConstrained)selectedObject))
.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.
* <code>true</code> iff <code>ci</code> should get a menu entry, i.e., if not successful and
* activated.
*/
private boolean shouldGetMenuEntry(ConstraintInstance c) {
IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(c);
private boolean shouldGetMenuEntry(ConstraintInstance ci) {
IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(ci);
return !(status == null || status instanceof SuccessConstraintInstanceStatus);
}
/**
* @param c
* @param elt
* @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).
* Returns the submenu or menu entry corresponding to the status of <code>ci</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(ConstraintInstance c, IConstrained elt) {
IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(c);
private IContributionItem constraintToAction(ConstraintInstance ci, IConstrained elt) {
IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(ci);
ConstraintSubMenuBase m;
if(status instanceof FailedConstraintInstanceStatus) {
m = new CheckFailingConstraintAction(c, elt);
m = new KnowMoreAboutFailingConstraintAction(ci, elt);
} else if(status instanceof ErrorConstraintInstanceStatus) {
m = new CheckErrorConstraintAction(c, elt);
m = new CheckErrorConstraintAction(ci, elt);
} else if(status instanceof OutdatedConstraintInstanceStatus) {
m = new CheckOutdatedConstraintAction(c, elt);
m = new CheckOutdatedConstraintAction(ci, elt);
} else {
// should not happen
return null;
}
if(m.getItems().length > 1) {
return m;
if(m.getItems().length == 0) {
Action a = new Action(m.getMenuText(), m.getImageDescriptor()) {
// nothing to do
};
return new ActionContributionItem(a);
}
IAction uniqueAction = m.getTopActionContribution().getAction();
String txt = m.getMenuText();
String newText = txt + " -> " + uniqueAction.getText();
uniqueAction.setText(newText);
uniqueAction.setImageDescriptor(m.getImageDescriptor());
return m.getTopActionContribution();
if(m.getItems().length == 1) {
IAction uniqueAction = m.getTopActionContribution().getAction();
String txt = m.getMenuText();
String newText = txt + " -> " + uniqueAction.getText();
uniqueAction.setText(newText);
uniqueAction.setImageDescriptor(m.getImageDescriptor());
return m.getTopActionContribution();
}
return m;
}
/** {@inheritDoc} */
......@@ -123,21 +122,22 @@ public class ConstraintMenu implements IContextMenuContributor {
private static class GoToConstrained extends Action {
/** The constrained element to open. */
private IConstrained c;
private IConstrained cstrd;
/** Constructor. */
public GoToConstrained(IConstrained c) {
super("Go to " + IModelElementHandlerService.getInstance().getName(c),
createFromImage(IModelElementHandlerService.getInstance().getIcon(c)));
this.c = c;
public GoToConstrained(IConstrained cstrd) {
super("Go to " + IModelElementHandlerService.getInstance().getName(cstrd),
createFromImage(IModelElementHandlerService.getInstance().getIcon(cstrd)));
this.cstrd = cstrd;
}
/** {@inheritDoc} */
@Override
public void run() {
IModelElementHandler<EObject> handler =
IModelElementHandlerService.getInstance().getModelElementHandler(c);
EObject eltToOpen = handler == null ? c : handler.handleOpenModelElementRequest(c);
IModelElementHandlerService.getInstance().getModelElementHandler(cstrd);
EObject eltToOpen =
handler == null ? cstrd : handler.handleOpenModelElementRequest(cstrd);
IModelEditorBindingService.getInstance().openInEditor(eltToOpen);
}
}
......@@ -152,18 +152,29 @@ public class ConstraintMenu implements IContextMenuContributor {
ImageDescriptor imgd = IConstraintUIService.getInstance().getIconImageDescriptor(ci);
Image img = imgd == null ? null : imgd.createImage();
if(img == null) {
return null;
if(IConstraintUIService.getInstance().shallDisplayAsWarning(ci)) {
return ESharedImages.WARNING.getImageDescriptor();
}
return ESharedImages.ERROR.getImageDescriptor();
}
ImageDescriptor[] descriptors = new ImageDescriptor[5];
descriptors[IDecoration.BOTTOM_LEFT] = overlay;
return new DecorationOverlayIcon(img, descriptors);
}
/** Action for creating a new prototype. */
/** Get the correct overlay for the given constraint. */
private static ImageDescriptor getOverlay(ConstraintInstance ci) {
if(IConstraintUIService.getInstance().shallDisplayAsWarning(ci)) {
return ESharedImages.WARNING_OVERLAY.getImageDescriptor();
}
return ESharedImages.ERROR_OVERLAY.getImageDescriptor();
}
/** Base for action involved in a constraint submenu. */
private static class ConstraintSubMenuBase extends MenuManager {
/** The constraint. */
protected ConstraintInstance c;
protected ConstraintInstance ci;
/**
* The action to get more information about the constraint status.
......@@ -174,13 +185,15 @@ public class ConstraintMenu implements IContextMenuContributor {
protected ActionContributionItem moreInfoAction;
/** Constructor. */
public ConstraintSubMenuBase(ConstraintInstance c, IConstrained selectedElt, String suffix,
ImageDescriptor overlay) {
super(getText(c, suffix), getIcon(c, overlay), null);
this.c = c;
moreInfoAction = new ActionContributionItem(new OpenStatusAction());
this.add(moreInfoAction);
for(ConstrainedWithChecksum cwc : c.getConstrainedsWithChecksum()) {
public ConstraintSubMenuBase(ConstraintInstance ci, IConstrained selectedElt,
String suffix, ImageDescriptor overlay) {
super(getText(ci, suffix), getIcon(ci, overlay), null);
this.ci = ci;
if(IConstraintUIService.getInstance().canOpen(ci)) {
moreInfoAction = new ActionContributionItem(new OpenStatusAction());
this.add(moreInfoAction);
}
for(ConstrainedWithChecksum cwc : ci.getConstrainedsWithChecksum()) {
if(!selectedElt.equals(cwc.getConstrained())) {
this.add(new ActionContributionItem(new GoToConstrained(cwc.getConstrained())));
}
......@@ -195,7 +208,7 @@ public class ConstraintMenu implements IContextMenuContributor {
return moreInfoAction;
}
/** Action to update a constraint. */
/** Action to update a constraint. Assumes the status *can be open*. */
protected class OpenStatusAction extends Action {
/** Constructor. */
......@@ -207,36 +220,16 @@ public class ConstraintMenu implements IContextMenuContributor {
/** {@inheritDoc} */
@Override
public void run() {
IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(c);
if(status instanceof OutdatedConstraintInstanceStatus &&
IConstraintUIService.getInstance().canOpen(c)) {
ICommandStackService.getInstance().runAsCommand(c, new Runnable() {
IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(ci);
if(status instanceof OutdatedConstraintInstanceStatus) {
ICommandStackService.getInstance().runAsCommand(ci, new Runnable() {
@Override
public void run() {
IConstraintUIService.getInstance().openStatus(c);
IConstraintUIService.getInstance().openStatus(ci);
}
});
return;
}
if(IConstraintUIService.getInstance().canOpen(c)) {
IConstraintUIService.getInstance().openStatus(c);
} 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 = ConstraintMenu.getText(c, "");
if(status instanceof FailedConstraintInstanceStatus) {
String msg = (name == null ? "The " : name);
msg += " is not satisfied.";
MessageDialog.openInformation(sh, "Unsatisfied constraint", msg);
} else if(status instanceof ErrorConstraintInstanceStatus) {
String msg = "There was an error while verifying ";
msg += (name == null ? "the " : "") + name + ".";
openError(sh, "Error while verifying constraint", msg);
} else if(status instanceof OutdatedConstraintInstanceStatus) {
String msg = (name == null ? "The " : name) + " is outdated.";
MessageDialog.openWarning(sh, "Outdated constraint", msg);
}
IConstraintUIService.getInstance().openStatus(ci);
}
}
}
......@@ -246,22 +239,22 @@ public class ConstraintMenu implements IContextMenuContributor {
private static class CheckOutdatedConstraintAction extends ConstraintSubMenuBase {
/** Constructor. */
public CheckOutdatedConstraintAction(ConstraintInstance c, IConstrained selectedElt) {
super(c, selectedElt, "Outdated", ESharedImages.WARNING_OVERLAY.getImageDescriptor());
public CheckOutdatedConstraintAction(ConstraintInstance ci, IConstrained selectedElt) {
super(ci, selectedElt, "Outdated", 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 {
/** Action for knowing more about some unsuccessful constraint. */
private static class KnowMoreAboutUnsuccessfulConstraintAction extends ConstraintSubMenuBase {
/** Constructor. */
public CheckUnsuccessfulConstraintAction(ConstraintInstance c, IConstrained selectedElt,
String suffix) {
super(c, selectedElt, suffix, getOverlay(c));
List<IFix> fixes = IConstraintService.getInstance().fixes(c);
public KnowMoreAboutUnsuccessfulConstraintAction(ConstraintInstance ci,
IConstrained selectedElt, String suffix) {
super(ci, selectedElt, suffix, getOverlay(ci));
List<IFix> fixes = IConstraintService.getInstance().fixes(ci);
if(fixes != null) {
for(IFix fix : fixes) {
this.add(new ActionContributionItem(new FixAction(fix)));
......@@ -269,14 +262,6 @@ public class ConstraintMenu implements IContextMenuContributor {
}
}
/** Get the correct overlay for the given constraint. */
private static ImageDescriptor getOverlay(ConstraintInstance c) {
if(IConstraintUIService.getInstance().shallDisplayAsWarning(c)) {
return ESharedImages.WARNING_OVERLAY.getImageDescriptor();
}
return ESharedImages.ERROR_OVERLAY.getImageDescriptor();
}
/** Action to update a constraint. */
private class FixAction extends Action {
......@@ -293,32 +278,34 @@ public class ConstraintMenu implements IContextMenuContributor {
/** {@inheritDoc} */
@Override
public void run() {
ICommandStackService.getInstance().runAsCommand(c, new Runnable() {
ICommandStackService.getInstance().runAsCommand(ci, new Runnable() {
@Override
public void run() {
fix.runFix(IConstraintUIService.getInstance().getStatus(c));
fix.runFix(IConstraintUIService.getInstance().getStatus(ci));
}
});
}
}
}
/** Action for creating a new prototype. */
private static class CheckFailingConstraintAction extends CheckUnsuccessfulConstraintAction {
/** Action for knowing more about a failing constraint. */
private static class KnowMoreAboutFailingConstraintAction extends
KnowMoreAboutUnsuccessfulConstraintAction {
/** Constructor. */
public CheckFailingConstraintAction(ConstraintInstance c, IConstrained selectedElt) {
super(c, selectedElt, "Unsatisfied");
public KnowMoreAboutFailingConstraintAction(ConstraintInstance ci, IConstrained selectedElt) {
super(ci, selectedElt, "Unsatisfied");
}
}
/** Action for creating a new prototype. */
private static class CheckErrorConstraintAction extends CheckUnsuccessfulConstraintAction {
/** Action for knowing more about a constraint yielding an error. */
private static class CheckErrorConstraintAction extends
KnowMoreAboutUnsuccessfulConstraintAction {
/** Constructor. */
public CheckErrorConstraintAction(ConstraintInstance c, IConstrained selectedElt) {
super(c, selectedElt, "Error encountered");
public CheckErrorConstraintAction(ConstraintInstance ci, IConstrained selectedElt) {
super(ci, selectedElt, "Error encountered");
}
}
}
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