diff --git a/de.prob.ui/src/de/prob/ui/operationview/CustomPreconditionInputDialog.java b/de.prob.ui/src/de/prob/ui/operationview/CustomPreconditionInputDialog.java index 68b6b5db830d66cd9d5746bb39ce324bf25420c0..b6391a9f29bd1d4dba0562045b86d2c3412ed945 100644 --- a/de.prob.ui/src/de/prob/ui/operationview/CustomPreconditionInputDialog.java +++ b/de.prob.ui/src/de/prob/ui/operationview/CustomPreconditionInputDialog.java @@ -6,6 +6,10 @@ package de.prob.ui.operationview; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.swt.widgets.Shell; @@ -13,6 +17,7 @@ import de.be4.classicalb.core.parser.exceptions.BException; import de.prob.core.Animator; import de.prob.core.command.*; import de.prob.core.domainobjects.Operation; +import de.prob.core.domainobjects.OperationInfo; import de.prob.exceptions.ProBException; import de.prob.unicode.UnicodeTranslator; @@ -21,23 +26,25 @@ public class CustomPreconditionInputDialog extends InputDialog { private final Animator animator; private final Operation op; - public CustomPreconditionInputDialog(final Shell parentShell, Operation op) { - super(parentShell, "Execute with additional Guard", getMenuText(op), + public CustomPreconditionInputDialog(final Shell parentShell, Operation op, Animator a) { + super(parentShell, "Execute with additional Guard Constraint", getMenuText(op,a), "", new EventBInputValidator()); this.op = op; - animator = Animator.getAnimator(); + animator = a; } - private static String getMenuText(Operation op) { + private static String getMenuText(Operation op, Animator animator) { StringBuffer sb = new StringBuffer(); - sb.append("Enter Guard to be added to the Event \""); + sb.append("Enter Guard Constraint to be added to the Event \""); sb.append(op.getName()); sb.append("\" before execution."); + sb.append("\nParameters are: "); + sb.append(getOperationParams(op,animator)); if (op.getArguments().size()>0) { - sb.append("\nParameters are:"); + sb.append("\nValues are:"); for (String arg : op.getArguments()) { sb.append(" "); - sb.append(arg); + sb.append(arg); // these are the parameter values not the parameter names !!! } } @@ -73,12 +80,39 @@ public class CustomPreconditionInputDialog extends InputDialog { } public static Operation getOperation(Operation op) { + CustomPreconditionInputDialog osd = new CustomPreconditionInputDialog( - new Shell(), op); + new Shell(), op, Animator.getAnimator()); if (osd.open() == InputDialog.OK) return osd.getCustomOperation(); else return null; } + + // copy from Paramter OperationTableViewer + private static List<String> getOperationParams(final Operation op, Animator animator) { + Collection<OperationInfo> infos = null; + try { + infos = GetOperationNamesCommand.getNames(animator); + } catch (ProBException e) { + e.notifyUserOnce(); + } + final OperationInfo params = infos == null ? null : OperationInfo + .getParams(op.getName(), infos); + final List<String> result; + if (params != null) { + result = params.getParameters(); + } else { + // If we cannot see the parameter names, we just use the operation's + // number of arguments and use empty titles + final int numArgs = op.getArguments().size(); + result = new ArrayList<String>(numArgs); + for (int i = 0; i < numArgs; i++) { + result.add(""); + } + } + return result; + } + }