Skip to content
Snippets Groups Projects
Commit 090b7ffb authored by Michael Leuschel's avatar Michael Leuschel
Browse files

show parameter names in custom execute dialog

parent ee6ab585
No related branches found
No related tags found
No related merge requests found
......@@ -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.");
if (op.getArguments().size()>0) {
sb.append("\nParameters are: ");
sb.append(getOperationParams(op,animator));
if (op.getArguments().size()>0) {
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment