[jboss-svn-commits] JBL Code SVN: r30282 - in labs/jbossrules/trunk: drools-guvnor/src/main/java/org/drools/guvnor/client/qa and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Nov 22 10:50:29 EST 2009
Author: nheron
Date: 2009-11-22 10:50:28 -0500 (Sun, 22 Nov 2009)
New Revision: 30282
Added:
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ConfigWidget.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/DataInputWidget.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ExecutionWidget.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/FieldDataConstraintEditor.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/RetractWidget.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/RuleSelectionEvent.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/TestRunnerWidget.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyFactWidget.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyFieldConstraintEditor.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyRulesFiredWidget.java
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/FieldData.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/Scenario.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/VerifyField.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ScenarioWidget.java
Log:
https://jira.jboss.org/jira/browse/GUVNOR-331
https://jira.jboss.org/jira/browse/GUVNOR-332
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/FieldData.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/FieldData.java 2009-11-22 14:22:23 UTC (rev 30281)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/FieldData.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -12,8 +12,40 @@
* Or if it starts with an "=" then it is an EL that will be evaluated to yield a value.
*/
public String value;
+ public long nature;
+ /**
+ * This is used only when action is first created.
+ * This means that there is no value yet for the constraint.
+ */
+ public static final int TYPE_UNDEFINED = 0;
+ /**
+ * This may be string, or number, anything really.
+ */
+ public static final int TYPE_LITERAL = 1;
+ /**
+ * This is when it is set to a valid previously bound variable.
+ */
+ public static final int TYPE_VARIABLE = 2;
+
+ /**
+ * This is for a "formula" that calculates a value.
+ */
+ public static final int TYPE_FORMULA = 3;
+
+ /**
+ * This is not used yet. ENUMs are not suitable for business rules
+ * until we can get data driven non code enums.
+ */
+ public static final int TYPE_ENUM = 4;
+
+ /**
+ * The fieldName and fieldBinding is not used in the case of a predicate.
+ */
+ public static final int TYPE_PREDICATE = 5;
+
+
public FieldData() {}
public FieldData(String name, String value) {
this.name = name;
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/Scenario.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/Scenario.java 2009-11-22 14:22:23 UTC (rev 30281)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/Scenario.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -1,15 +1,9 @@
package org.drools.guvnor.client.modeldriven.testing;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
import org.drools.guvnor.client.modeldriven.brl.PortableObject;
+import java.util.*;
+
/**
* This represents a test scenario.
* It also encapsulates the result of a scenario run.
@@ -143,6 +137,22 @@
Collections.reverse( fixtures );
}
+ /**
+ *
+ * @return A mapping of variable names to their fact type.
+ */
+ public Map getFactTypes() {
+ Map m = new HashMap();
+ int p = this.fixtures.size();
+ for ( int i = 0; i < p; i++ ) {
+ Fixture f = (Fixture) fixtures.get( i );
+ if ( f instanceof FactData ) {
+ FactData fd = (FactData) f;
+ m.put( fd.name,fd );
+ }
+ }
+ return m;
+ }
/**
*
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/VerifyField.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/VerifyField.java 2009-11-22 14:22:23 UTC (rev 30281)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/testing/VerifyField.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -19,7 +19,40 @@
* Operator is generally "==" or "!=" - an MVEL operator.
*/
public String operator = "==";
+ public long nature;
+ /**
+ * This is used only when action is first created.
+ * This means that there is no value yet for the constraint.
+ */
+ public static final int TYPE_UNDEFINED = 0;
+ /**
+ * This may be string, or number, anything really.
+ */
+ public static final int TYPE_LITERAL = 1;
+
+ /**
+ * This is when it is set to a valid previously bound variable.
+ */
+ public static final int TYPE_VARIABLE = 2;
+
+ /**
+ * This is for a "formula" that calculates a value.
+ */
+ public static final int TYPE_FORMULA = 3;
+
+ /**
+ * This is not used yet. ENUMs are not suitable for business rules
+ * until we can get data driven non code enums.
+ */
+ public static final int TYPE_ENUM = 4;
+
+ /**
+ * The fieldName and fieldBinding is not used in the case of a predicate.
+ */
+ public static final int TYPE_PREDICATE = 5;
+
+
public VerifyField() {}
public VerifyField(String fieldName, String expected, String operator) {
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ConfigWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ConfigWidget.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ConfigWidget.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,114 @@
+package org.drools.guvnor.client.qa;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.*;
+import org.drools.guvnor.client.common.FormStylePopup;
+import org.drools.guvnor.client.common.ImageButton;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.modeldriven.testing.Scenario;
+
+import java.util.List;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: nheron
+ * Date: 7 nov. 2009
+ * Time: 19:33:37
+ * To change this template use File | Settings | File Templates.
+ */
+public class ConfigWidget extends Composite {
+ private final Constants constants = ((Constants) GWT.create(Constants.class));
+
+ public ConfigWidget(final Scenario sc, final String packageName, final ScenarioWidget scWidget) {
+
+ final ListBox box = new ListBox(true);
+
+ for (int i = 0; i < sc.rules.size(); i++) {
+ box.addItem((String)sc.rules.get(i));
+ }
+ HorizontalPanel filter = new HorizontalPanel();
+
+
+ final Image add = new ImageButton("images/new_item.gif", constants.AddANewRule());
+ add.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ showRulePopup(w, box, packageName, sc.rules, scWidget);
+ }
+ });
+
+ final Image remove = new ImageButton("images/trash.gif", constants.RemoveSelectedRule());
+ remove.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ if (box.getSelectedIndex() == -1) {
+ Window.alert(constants.PleaseChooseARuleToRemove());
+ } else {
+ String r = box.getItemText(box.getSelectedIndex());
+ sc.rules.remove(r);
+ box.removeItem(box.getSelectedIndex());
+ }
+ }
+ });
+ VerticalPanel actions = new VerticalPanel();
+ actions.add(add); actions.add(remove);
+
+
+
+
+ final ListBox drop = new ListBox();
+ drop.addItem(constants.AllowTheseRulesToFire(), "inc"); //NON-NLS
+ drop.addItem(constants.PreventTheseRulesFromFiring(), "exc"); //NON-NLS
+ drop.addItem(constants.AllRulesMayFire());
+ drop.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ String s = drop.getValue(drop.getSelectedIndex());
+ if (s.equals("inc")) { //NON-NLS
+ sc.inclusive = true;
+ add.setVisible(true); remove.setVisible(true); box.setVisible(true);
+ } else if (s.equals("exc")) { //NON-NLS
+ sc.inclusive = false;
+ add.setVisible(true); remove.setVisible(true); box.setVisible(true);
+ } else {
+ sc.rules.clear();
+ box.clear();
+ box.setVisible(false); add.setVisible(false); remove.setVisible(false);
+ }
+ }
+ });
+
+ if (sc.rules.size() > 0) {
+ drop.setSelectedIndex((sc.inclusive) ? 0 : 1);
+ } else {
+ drop.setSelectedIndex(2);
+ box.setVisible(false); add.setVisible(false); remove.setVisible(false);
+ }
+
+
+ filter.add(drop);
+ filter.add(box);
+ filter.add(actions);
+
+ initWidget(filter);
+ }
+
+ private void showRulePopup(Widget w, final ListBox box, String packageName, final List filterList, ScenarioWidget scw) {
+ final FormStylePopup pop = new FormStylePopup("images/rule_asset.gif", constants.SelectRule()); //NON-NLS
+
+ Widget ruleSelector = scw.getRuleSelectionWidget(packageName, new RuleSelectionEvent() {
+ public void ruleSelected(String r) {
+ filterList.add(r);
+ box.addItem(r);
+ pop.hide();
+
+ }
+ });
+
+ pop.addRow(ruleSelector);
+
+ pop.show();
+
+ }
+
+
+}
+
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/DataInputWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/DataInputWidget.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/DataInputWidget.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,256 @@
+package org.drools.guvnor.client.qa;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.*;
+import com.gwtext.client.util.Format;
+import org.drools.guvnor.client.common.*;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
+import org.drools.guvnor.client.modeldriven.testing.ExecutionTrace;
+import org.drools.guvnor.client.modeldriven.testing.FactData;
+import org.drools.guvnor.client.modeldriven.testing.FieldData;
+import org.drools.guvnor.client.modeldriven.testing.Scenario;
+
+import java.util.*;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: nheron
+ * Date: 7 nov. 2009
+ * Time: 19:34:49
+ * To change this template use File | Settings | File Templates.
+ */
+public class DataInputWidget extends DirtyableComposite {
+
+
+ private Grid outer;
+ private Scenario scenario;
+ private SuggestionCompletionEngine sce;
+ private String type;
+ private ScenarioWidget parent;
+ private Constants constants = ((Constants) GWT.create(Constants.class));
+ private ExecutionTrace executionTrace;
+
+ public DataInputWidget(String factType, List<FactData> defList, boolean isGlobal, Scenario sc, SuggestionCompletionEngine sce, ScenarioWidget parent,ExecutionTrace executionTrace) {
+
+ outer = new Grid(2, 1);
+ scenario = sc;
+ this.sce = sce;
+ this.type = factType;
+
+ this.parent = parent;
+ this.executionTrace = executionTrace;
+ outer.getCellFormatter().setStyleName(0, 0, "modeller-fact-TypeHeader"); //NON-NLS
+ outer.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE );
+ outer.setStyleName("modeller-fact-pattern-Widget"); //NON-NLS
+
+
+ if (isGlobal) {
+ outer.setWidget(0, 0, getLabel(Format.format(constants.globalForScenario(), factType), defList, parent, sc));
+ } else {
+ FactData first = (FactData) defList.get(0);
+ if (first.isModify) {
+ outer.setWidget(0, 0, getLabel(Format.format(constants.modifyForScenario(), factType), defList, parent, sc));
+ } else {
+ outer.setWidget(0, 0, getLabel(Format.format(constants.insertForScenario(), factType), defList, parent, sc));
+ }
+ }
+
+ FlexTable t = render(defList, parent, sc);
+
+
+
+ //parent.renderEditor();
+
+
+
+ //outer.setWidget(1, 1, new Button("Remove"));
+
+
+ outer.setWidget(1, 0, t);
+ initWidget(outer);
+ }
+
+ private Widget getLabel(String text, final List defList, ScenarioWidget parent, Scenario sc) {
+ //now we put in button to add new fields
+ //Image newField = new ImageButton("images/add_field_to_fact.gif", "Add a field.");
+ //Image newField = getNewFieldButton(defList);
+ ClickableLabel clbl = new ClickableLabel(text, addFieldCL(defList, parent, sc));
+ //HorizontalPanel h = new HorizontalPanel();
+ //h.add(new SmallLabel(text)); h.add(newField);
+ return clbl;
+ }
+
+ /*
+ private ImageButton getNewFieldButton(final List defList) {
+ ImageButton newField = new ImageButton("images/add_field_to_fact.gif", constants.AddAField()); //NON-NLS
+ newField.addClickListener(addFieldCL(defList));
+ return newField;
+ }
+ */
+
+ private ClickListener addFieldCL(final List<FactData> defList, final ScenarioWidget parent, final Scenario sc) {
+ return new ClickListener() {
+ public void onClick(Widget w) {
+
+ //build up a list of what we have got, don't want to add it twice
+ HashSet existingFields = new HashSet();
+ if (defList.size() > 0) {
+ FactData d = (FactData) defList.get(0);
+ for (Iterator iterator = d.fieldData.iterator(); iterator.hasNext();) {
+ FieldData f = (FieldData) iterator.next();
+ existingFields.add(f.name);
+ }
+
+ }
+ String[] fields = (String[]) sce.fieldsForType.get(type);
+ final FormStylePopup pop = new FormStylePopup(); //NON-NLS
+ pop.setTitle(constants.ChooseDotDotDot());
+ final ListBox b = new ListBox();
+ for (int i = 0; i < fields.length; i++) {
+ String fld = fields[i];
+ if (!existingFields.contains(fld)) b.addItem(fld);
+ }
+
+ Button ok = new Button(constants.OK());
+ ok.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ String f = b.getItemText(b.getSelectedIndex());
+ for (Iterator iterator = defList.iterator(); iterator.hasNext();) {
+ FactData fd = (FactData) iterator.next();
+ fd.fieldData.add(new FieldData(f, ""));
+ }
+ outer.setWidget(1, 0, render(defList, parent, sc));
+ pop.hide();
+ }
+ });
+ HorizontalPanel h = new HorizontalPanel();
+ h.add(b);
+ h.add(ok);
+ pop.addAttribute(constants.ChooseAFieldToAdd(), h);
+
+
+ Button remove = new Button(constants.RemoveThisBlockOfData());
+ remove.addClickListener(new ClickListener() {
+ public void onClick(Widget sender) {
+ if (Window.confirm(constants.AreYouSureYouWantToRemoveThisBlockOfData())) {
+ scenario.globals.removeAll( defList );
+ parent.renderEditor();
+ pop.hide();
+ }
+ }
+ });
+ pop.addAttribute("", remove);
+
+
+ pop.show();
+ }
+ };
+ }
+
+ private FlexTable render(final List defList, final ScenarioWidget parent, final Scenario sc) {
+ DirtyableFlexTable t = new DirtyableFlexTable();
+ if (defList.size() == 0) {
+ parent.renderEditor();
+ }
+
+ //This will work out what row is for what field, addin labels and remove icons
+
+ Map fields = new HashMap();
+ int col = 0;
+ int totalCols = defList.size();
+ for (Iterator iterator = defList.iterator(); iterator.hasNext();) {
+ final FactData d = (FactData) iterator.next();
+
+ for (int i = 0; i < d.fieldData.size(); i++) {
+ final FieldData fd = d.fieldData.get(i);
+ if (!fields.containsKey(fd.name)) {
+ int idx = fields.size() + 1;
+ fields.put(fd.name, new Integer(idx));
+ t.setWidget(idx, 0, new SmallLabel(fd.name + ":"));
+ Image del = new ImageButton("images/delete_item_small.gif", constants.RemoveThisRow(), new ClickListener() {
+ public void onClick(Widget w) {
+ if (Window.confirm(constants.AreYouSureYouWantToRemoveThisRow())) {
+ ScenarioHelper.removeFields(defList, fd.name);
+ outer.setWidget(1, 0, render(defList, parent, sc));
+
+ }
+ }
+ });
+ t.setWidget(idx, totalCols + 1, del);
+ t.getCellFormatter().setHorizontalAlignment(idx, 0, HasHorizontalAlignment.ALIGN_RIGHT);
+ }
+ }
+ }
+
+ int totalRows = fields.size();
+
+ t.getFlexCellFormatter().setHorizontalAlignment(totalRows + 1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
+
+ //now we go through the facts and the fields, adding them to the grid
+ //if a fact is missing a FieldData, we will add it in (so people can enter data later on)
+ col = 0;
+ for (Iterator iterator = defList.iterator(); iterator.hasNext();) {
+ final FactData d = (FactData) iterator.next();
+ t.setWidget(0, ++col, new SmallLabel("[" + d.name + "]"));
+ Image del = new ImageButton("images/delete_item_small.gif", Format.format(constants.RemoveTheColumnForScenario(), d.name), new ClickListener() {
+ public void onClick(Widget w) {
+ if (scenario.isFactNameUsed(d)) {
+ Window.alert(Format.format(constants.CanTRemoveThisColumnAsTheName0IsBeingUsed(), d.name));
+ } else if (Window.confirm(constants.AreYouSureYouWantToRemoveThisColumn())) {
+ scenario.removeFixture(d);
+ defList.remove(d);
+ outer.setWidget(1, 0, render(defList, parent, sc));
+ }
+ }
+ });
+ t.setWidget(totalRows + 1, col, del);
+ Map presentFields = new HashMap(fields);
+ for (int i = 0; i < d.fieldData.size(); i++) {
+ FieldData fd = d.fieldData.get(i);
+ int fldRow = ((Integer) fields.get(fd.name)).intValue();
+ t.setWidget(fldRow, col, editableCell(fd, d,d.type,this.executionTrace));
+ presentFields.remove(fd.name);
+ }
+
+ for (Iterator missing = presentFields.entrySet().iterator(); missing.hasNext();) {
+ Map.Entry e = (Map.Entry) missing.next();
+ int fldRow = ((Integer) e.getValue()).intValue();
+ FieldData fd = new FieldData((String) e.getKey(), "");
+ d.fieldData.add(fd);
+ t.setWidget(fldRow, col, editableCell(fd, d,d.type,this.executionTrace));
+ }
+ }
+
+ if (fields.size() == 0) {
+ //HorizontalPanel h = new HorizontalPanel();
+ Button b = new Button(constants.AddAField());
+ b.addClickListener(addFieldCL(defList, parent, sc));
+
+ //h.add(new HTML("<i><small>Add fields:</small></i>"));
+ //h.add(getNewFieldButton(defList));
+ t.setWidget(1, 1, b);
+ }
+ return t;
+ }
+
+
+ /**
+ * This will provide a cell editor. It will filter non numerics, show choices etc as appropriate.
+ * @param fd
+ * @param factType
+ * @return
+ */
+ private Widget editableCell(final FieldData fd,FactData factData, String factType,ExecutionTrace executionTrace) {
+ return new FieldDataConstraintEditor(factType, new ValueChanged() {
+ public void valueChanged(String newValue) {
+ fd.value = newValue;
+ makeDirty();
+ }
+ }, fd,factData,sce,scenario,executionTrace);
+ }
+}
+
+
+
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ExecutionWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ExecutionWidget.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ExecutionWidget.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,130 @@
+package org.drools.guvnor.client.qa;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.*;
+import com.gwtext.client.util.Format;
+import org.drools.guvnor.client.common.ErrorPopup;
+import org.drools.guvnor.client.common.SmallLabel;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.modeldriven.testing.ExecutionTrace;
+
+import java.util.Date;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: nheron
+ * Date: 7 nov. 2009
+ * Time: 19:32:35
+ * To change this template use File | Settings | File Templates.
+ */
+public class ExecutionWidget extends Composite {
+ private Constants constants = ((Constants) GWT.create(Constants.class));
+
+ public ExecutionWidget(final ExecutionTrace ext, boolean showResults) {
+
+
+ final Widget dt = simulDate(ext);
+ dt.setVisible(ext.scenarioSimulatedDate != null);
+
+ final ListBox choice = new ListBox();
+
+ choice.addItem(constants.UseRealDateAndTime());
+ choice.addItem(constants.UseASimulatedDateAndTime());
+ choice.setSelectedIndex((ext.scenarioSimulatedDate == null) ? 0 : 1);
+ choice.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ if (choice.getSelectedIndex() == 0) {
+ dt.setVisible( false );
+ ext.scenarioSimulatedDate = null;
+ } else {
+ dt.setVisible(true);
+ }
+ }
+ });
+
+ HorizontalPanel p = new HorizontalPanel();
+ p.add(new Image("images/execution_trace.gif")); //NON-NLS
+ p.add(choice);
+ p.add(dt);
+
+ VerticalPanel vert = new VerticalPanel();
+ if (showResults && ext.executionTimeResult != null
+ && ext.numberOfRulesFired != null) {
+ HTML rep = new HTML("<i><small>" + Format.format(constants.property0RulesFiredIn1Ms(), ext.numberOfRulesFired.toString(), ext.executionTimeResult.toString()) + "</small></i>");
+
+
+ final HorizontalPanel h = new HorizontalPanel();
+ h.add(rep);
+ vert.add(h);
+
+ final Button show = new Button(constants.ShowRulesFired());
+ show.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ ListBox rules = new ListBox(true);
+ for (int i = 0; i < ext.rulesFired.length; i++) {
+ rules.addItem(ext.rulesFired[i]);
+ }
+ h.add(new SmallLabel(" :" + constants.RulesFired()));
+ h.add(rules);
+ show.setVisible(false);
+ }
+ });
+ h.add(show);
+
+
+ vert.add(p);
+ initWidget(vert);
+ } else {
+ initWidget(p);
+ }
+ }
+
+
+
+ private Widget simulDate(final ExecutionTrace ext) {
+ HorizontalPanel ab = new HorizontalPanel();
+ final String fmt = "dd-MMM-YYYY"; //NON-NLS
+ final TextBox dt = new TextBox();
+ if (ext.scenarioSimulatedDate == null) {
+ dt.setText("<" + fmt + ">");
+ } else {
+ dt.setText(ext.scenarioSimulatedDate.toLocaleString());
+ }
+ final SmallLabel dateHint = new SmallLabel();
+ dt.addKeyboardListener(new KeyboardListener() {
+ public void onKeyDown(Widget arg0, char arg1, int arg2) {}
+ public void onKeyPress(Widget arg0, char arg1, int arg2) {}
+ public void onKeyUp(Widget w, char arg1, int arg2) {
+ try {
+ Date d = new Date(dt.getText());
+ dateHint.setText(d.toLocaleString());
+ } catch (Exception e) {
+ dateHint.setText("...");
+ }
+ }
+ });
+
+ dt.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ if (dt.getText().trim().equals("")) {
+ dt.setText(constants.currentDateAndTime());
+ } else {
+ try {
+ Date d = new Date(dt.getText());
+ ext.scenarioSimulatedDate = d;
+ dt.setText(d.toLocaleString());
+ dateHint.setText("");
+ } catch (Exception e) {
+ ErrorPopup.showMessage(Format.format(constants.BadDateFormatPleaseTryAgainTryTheFormatOf0(), fmt));
+ }
+ }
+ }
+ });
+ ab.add(dt);
+ ab.add(dateHint);
+ return ab;
+ }
+
+
+}
+
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/FieldDataConstraintEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/FieldDataConstraintEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/FieldDataConstraintEditor.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,232 @@
+package org.drools.guvnor.client.qa;
+
+import java.util.List;
+import java.util.Map;
+
+import org.drools.guvnor.client.common.DirtyableComposite;
+import org.drools.guvnor.client.common.FormStylePopup;
+import org.drools.guvnor.client.common.InfoPopup;
+import org.drools.guvnor.client.common.SmallLabel;
+import org.drools.guvnor.client.common.ValueChanged;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.modeldriven.DropDownData;
+import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
+import org.drools.guvnor.client.modeldriven.testing.ExecutionTrace;
+import org.drools.guvnor.client.modeldriven.testing.FactData;
+import org.drools.guvnor.client.modeldriven.testing.FieldData;
+import org.drools.guvnor.client.modeldriven.testing.Scenario;
+import org.drools.guvnor.client.modeldriven.ui.ActionValueEditor;
+import org.drools.guvnor.client.modeldriven.ui.ConstraintValueEditor;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.ChangeListener;
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.SimplePanel;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.Widget;
+import com.gwtext.client.util.Format;
+
+/**
+ * Constraint editor for the FieldData in the Given Section
+ *
+ * @author Nicolas Heron
+ */
+
+public class FieldDataConstraintEditor extends DirtyableComposite {
+
+ private String factType;
+ private FieldData field;
+ private FactData givenFact;
+ private final Panel panel;
+ private Scenario scenario;
+ private ExecutionTrace executionTrace;
+ private SuggestionCompletionEngine sce;
+ private ValueChanged callback;
+ private Constants constants = ((Constants) GWT.create(Constants.class));
+
+ public FieldDataConstraintEditor(String factType, ValueChanged callback,
+ FieldData field,FactData givenFact, SuggestionCompletionEngine sce, Scenario scenario,ExecutionTrace exec) {
+ this.field = field;
+ this.sce = sce;
+ this.factType = factType;
+ this.callback = callback;
+ this.scenario = scenario;
+ this.executionTrace = exec;
+ this.givenFact = givenFact;
+ panel = new SimplePanel();
+ refreshEditor();
+ initWidget(panel);
+ }
+
+ private void refreshEditor() {
+ String key = factType + "." + field.name;
+ String flType = sce.fieldTypes.get(key);
+ panel.clear();
+ if (flType.equals(SuggestionCompletionEngine.TYPE_NUMERIC)) {
+ final TextBox box = editableTextBox(callback, field.name,
+ field.value);
+ box.addKeyboardListener(ActionValueEditor.getNumericFilter(box));
+ panel.add(box);
+ } else if (flType.equals(SuggestionCompletionEngine.TYPE_BOOLEAN)) {
+ String[] c = new String[] { "true", "false" };
+ panel.add(ConstraintValueEditor.enumDropDown(field.value, callback,
+ DropDownData.create(c)));
+ } else {
+ String[] enums = sce.dataEnumLists.get(key);
+ if (enums != null) {
+ panel.add(ConstraintValueEditor.enumDropDown(field.value,
+ callback, DropDownData.create(enums)));
+
+ } else {
+ if (field.nature == FieldData.TYPE_UNDEFINED
+ && isThereABoundVariableToSet() == true) {
+ Image clickme = new Image("images/edit.gif"); // NON-NLS
+ clickme.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ showTypeChoice(w, field);
+ }
+ });
+ panel.add(clickme);
+ } else if (field.nature == FieldData.TYPE_VARIABLE) {
+ panel.add(variableEditor());
+ } else {
+ panel
+ .add(editableTextBox(callback, field.name,
+ field.value));
+ }
+ }
+ }
+
+ }
+
+ private static TextBox editableTextBox(final ValueChanged changed,
+ String fieldName, String initialValue) {
+ // Fixme nheron
+ final TextBox tb = new TextBox();
+ tb.setText(initialValue);
+ String m = Format.format(((Constants) GWT.create(Constants.class))
+ .ValueFor0(), fieldName);
+ tb.setTitle(m);
+ tb.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ changed.valueChanged(tb.getText());
+ }
+ });
+
+ return tb;
+ }
+
+ private Widget variableEditor() {
+ // sce.
+ List vars = this.scenario.getFactNamesInScope(
+ this.executionTrace,true);
+
+ final ListBox box = new ListBox();
+
+ if (this.field.value == null) {
+ box.addItem(constants.Choose());
+ }
+ int j=0;
+ for (int i = 0; i < vars.size(); i++) {
+ String var = (String) vars.get(i);
+ Map m = this.scenario.getVariableTypes();
+ FactData f = (FactData) this.scenario.getFactTypes().get(var);
+ String fieldType = sce.getFieldType(this.factType, field.name);
+ if (f.type.equals(fieldType)) {
+ if (box.getItemCount() == 0) {
+ box.addItem("...");
+ j++;
+ }
+ box.addItem("="+var);
+ if (this.field.value != null && this.field.value.equals("="+var)) {
+ box.setSelectedIndex(j);
+
+ }
+ j++;
+ }
+ }
+
+ box.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ field.value = box.getItemText(box.getSelectedIndex());
+ }
+ });
+
+ return box;
+ }
+
+ private void showTypeChoice(Widget w, final FieldData con) {
+ final FormStylePopup form = new FormStylePopup("images/newex_wiz.gif",
+ constants.FieldValue());
+
+ Button lit = new Button(constants.LiteralValue());
+ lit.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ con.nature = FieldData.TYPE_LITERAL;
+ doTypeChosen(form);
+ }
+
+ });
+ form.addAttribute(constants.LiteralValue() + ":", widgets(lit,
+ new InfoPopup(constants.LiteralValue(), constants
+ .LiteralValTip())));
+
+ form.addRow(new HTML("<hr/>"));
+ form.addRow(new SmallLabel(constants.AdvancedOptions()));
+
+ // If we are here, then there must be a bound variable compatible with
+ // me
+
+ Button variable = new Button(constants.BoundVariable());
+ variable.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ con.nature = FieldData.TYPE_VARIABLE;
+ doTypeChosen(form);
+ }
+ });
+ form.addAttribute(constants.AVariable(), widgets(variable,
+ new InfoPopup(constants.ABoundVariable(), constants
+ .BoundVariableTip())));
+
+ form.show();
+ }
+
+ private boolean isThereABoundVariableToSet() {
+ boolean retour = false;
+ List vars = scenario.getFactNamesInScope(
+ this.executionTrace,true);
+ if (vars.size() > 0) {
+ for (int i = 0; i < vars.size(); i++) {
+ String var = (String) vars.get(i);
+ Map m = this.scenario.getVariableTypes();
+ FactData f = (FactData) scenario.getFactTypes().get(var);
+ String fieldType = sce.getFieldType(this.factType, field.name);
+ if (f.type.equals(fieldType)) {
+ retour = true;
+ break;
+ }
+ }
+ }
+ return retour;
+ }
+
+ private void doTypeChosen(final FormStylePopup form) {
+ refreshEditor();
+ form.hide();
+ }
+
+ private Panel widgets(Widget left, Widget right) {
+ HorizontalPanel panel = new HorizontalPanel();
+ panel.add(left);
+ panel.add(right);
+ panel.setWidth("100%");
+ return panel;
+ }
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/RetractWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/RetractWidget.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/RetractWidget.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,55 @@
+package org.drools.guvnor.client.qa;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.*;
+import org.drools.guvnor.client.common.ImageButton;
+import org.drools.guvnor.client.common.SmallLabel;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.modeldriven.testing.RetractFact;
+import org.drools.guvnor.client.modeldriven.testing.Scenario;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: nheron
+ * Date: 7 nov. 2009
+ * Time: 19:29:06
+ * To change this template use File | Settings | File Templates.
+ */
+public class RetractWidget extends Composite {
+ private Constants constants = ((Constants) GWT.create(Constants.class));
+
+ public RetractWidget(List retList, Scenario sc) {
+ FlexTable outer = new FlexTable();
+ render(retList, outer, sc);
+
+ initWidget(outer);
+ }
+
+ private void render(final List retList, final FlexTable outer, final Scenario sc) {
+ outer.clear();
+ outer.getCellFormatter().setStyleName(0, 0, "modeller-fact-TypeHeader");
+ outer.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE );
+ outer.setStyleName("modeller-fact-pattern-Widget");
+ outer.setWidget(0, 0, new SmallLabel(constants.RetractFacts()));
+ outer.getFlexCellFormatter().setColSpan(0, 0, 2);
+
+ int row = 1;
+ for (Iterator iterator = retList.iterator(); iterator.hasNext();) {
+ final RetractFact r = (RetractFact) iterator.next();
+ outer.setWidget(row, 0, new SmallLabel(r.name));
+ Image del = new ImageButton("images/delete_item_small.gif", constants.RemoveThisRetractStatement(), new ClickListener() {
+ public void onClick(Widget w) {
+ retList.remove(r);
+ sc.fixtures.remove(r);
+ render(retList, outer, sc);
+ }
+ });
+ outer.setWidget(row, 1, del);
+
+ row++;
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/RuleSelectionEvent.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/RuleSelectionEvent.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/RuleSelectionEvent.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,13 @@
+package org.drools.guvnor.client.qa;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: nheron
+ * Date: 7 nov. 2009
+ * Time: 19:35:30
+ * To change this template use File | Settings | File Templates.
+ */
+public interface RuleSelectionEvent {
+ public void ruleSelected(String name);
+}
+
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ScenarioWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ScenarioWidget.java 2009-11-22 14:22:23 UTC (rev 30281)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/ScenarioWidget.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -115,9 +115,15 @@
this.layout.add(editorLayout);
ScenarioHelper hlp = new ScenarioHelper();
List fixtures = hlp.lumpyMap(scenario.fixtures);
-
-
+ List<ExecutionTrace> listExecutionTrace = new ArrayList<ExecutionTrace>();
+ for (int i = 0; i < fixtures.size(); i++) {
+ final Object f = fixtures.get(i);
+ if (f instanceof ExecutionTrace) {
+ listExecutionTrace.add((ExecutionTrace)f);
+ }
+ }
int layoutRow = 1;
+ int executionTraceLine=0;
ExecutionTrace previousEx = null;
for (int i = 0; i < fixtures.size(); i++) {
final Object f = fixtures.get(i);
@@ -138,14 +144,17 @@
}
});
h.add(del);
-
+ executionTraceLine++;
+ if (executionTraceLine>= listExecutionTrace.size()){
+ executionTraceLine= listExecutionTrace.size()-1;
+ }
editorLayout.setWidget(layoutRow, 1, new ExecutionWidget(previousEx, showResults));
//layout.setWidget(layoutRow, 2, getNewExpectationButton(previousEx, scenario, availableRules));
editorLayout.getFlexCellFormatter().setHorizontalAlignment(layoutRow, 2, HasHorizontalAlignment.ALIGN_LEFT);
} else if (f instanceof Map) {
HorizontalPanel h = new HorizontalPanel();
- h.add(getNewDataButton(previousEx, scenario));
+ h.add(getNewDataButton(previousEx, scenario,listExecutionTrace.get(executionTraceLine)));
h.add(new SmallLabel(constants.GIVEN()));
@@ -160,8 +169,8 @@
if (e.getKey().equals(ScenarioHelper.RETRACT_KEY)) {
vert.add(new RetractWidget(factList, scenario));
} else {
- vert.add(new DataInputWidget((String)e.getKey(), factList, false, scenario, sce, this));
- }
+ vert.add(new DataInputWidget((String)e.getKey(), factList, false, scenario, sce, this,listExecutionTrace.get(executionTraceLine)));
+ }
}
@@ -174,7 +183,7 @@
List l = (List) f;
Fixture first = (Fixture) l.get(0);
if (first instanceof VerifyFact) {
- doVerifyFacts(l, editorLayout, layoutRow, scenario);
+ doVerifyFacts(l, editorLayout, layoutRow, scenario,listExecutionTrace.get(executionTraceLine));
} else if (first instanceof VerifyRuleFired) {
editorLayout.setWidget(layoutRow, 1, new VerifyRulesFiredWidget(l, scenario, showResults));
}
@@ -211,7 +220,7 @@
VerticalPanel globalPanel = new VerticalPanel();
for (Iterator iterator = globals.entrySet().iterator(); iterator.hasNext();) {
Map.Entry e = (Map.Entry) iterator.next();
- globalPanel.add(new DataInputWidget((String)e.getKey(), (List) globals.get(e.getKey()), true, scenario, sce, this));
+ globalPanel.add(new DataInputWidget((String)e.getKey(), (List) globals.get(e.getKey()), true, scenario, sce, this,previousEx));
}
HorizontalPanel h = new HorizontalPanel();
h.add(getNewGlobalButton(scenario));
@@ -269,7 +278,7 @@
* This button gives a choice of modifying data, based on the positional context.
* @param previousEx
*/
- private Widget getNewDataButton(final ExecutionTrace previousEx, final Scenario scenario) {
+ private Widget getNewDataButton(final ExecutionTrace previousEx, final Scenario scenario,final ExecutionTrace currentEx) {
Image newItem = new ImageButton("images/new_item.gif", constants.AddANewDataInputToThisScenario(), new ClickListener() {
public void onClick(Widget w) {
@@ -305,7 +314,7 @@
insertFact.add(factTypes); insertFact.add(new SmallLabel(constants.FactName())); insertFact.add(factName); insertFact.add(add);
pop.addAttribute(constants.InsertANewFact1(), insertFact);
- List varsInScope = scenario.getFactNamesInScope(previousEx, false);
+ List varsInScope = scenario.getFactNamesInScope(currentEx, false);
//now we do modifies & retracts
if (varsInScope.size() > 0) {
final ListBox modifyFacts = new ListBox();
@@ -434,12 +443,12 @@
- private void doVerifyFacts(List l, FlexTable layout, int layoutRow, final Scenario scenario) {
+ private void doVerifyFacts(List l, FlexTable layout, int layoutRow, final Scenario scenario,ExecutionTrace executionTrace) {
VerticalPanel vert = new VerticalPanel();
for (Iterator iterator = l.iterator(); iterator.hasNext();) {
final VerifyFact f = (VerifyFact) iterator.next();
HorizontalPanel h = new HorizontalPanel();
- h.add(new VerifyFactWidget(f, scenario, sce, showResults));
+ h.add(new VerifyFactWidget(f, scenario, sce,executionTrace,showResults));
Image del = new ImageButton("images/delete_item_small.gif", constants.DeleteTheExpectationForThisFact(), new ClickListener() { //NON-NLS
public void onClick(Widget w) {
if (Window.confirm(constants.AreYouSureYouWantToRemoveThisExpectation())) {
@@ -532,43 +541,43 @@
return h;
}
- public static Widget editableCell(final ValueChanged changeEvent, String factType, String fieldName, String initialValue, SuggestionCompletionEngine sce) {
- String key = factType + "." + fieldName;
- String flType = sce.fieldTypes.get(key);
- if ( flType != null && flType.equals( SuggestionCompletionEngine.TYPE_NUMERIC ) ) {
- final TextBox box = editableTextBox(changeEvent, fieldName, initialValue);
- box.addKeyboardListener(ActionValueEditor.getNumericFilter(box));
- return box;
- } else if ( flType != null && flType.equals( SuggestionCompletionEngine.TYPE_BOOLEAN ) ) {
- String[] c = new String[] {"true", "false"};
- return ConstraintValueEditor.enumDropDown(initialValue, changeEvent, DropDownData.create(c));
- } else {
- String[] enums = sce.dataEnumLists.get(key);
- if (enums != null) {
- return ConstraintValueEditor.enumDropDown(initialValue, changeEvent, DropDownData.create(enums));
+// public static Widget editableCell(final ValueChanged changeEvent, String factType, String fieldName, String initialValue, SuggestionCompletionEngine sce) {
+// String key = factType + "." + fieldName;
+// String flType = sce.fieldTypes.get(key);
+// if ( flType != null && flType.equals( SuggestionCompletionEngine.TYPE_NUMERIC ) ) {
+// final TextBox box = editableTextBox(changeEvent, fieldName, initialValue);
+// box.addKeyboardListener(ActionValueEditor.getNumericFilter(box));
+// return box;
+// } else if ( flType != null && flType.equals( SuggestionCompletionEngine.TYPE_BOOLEAN ) ) {
+// String[] c = new String[] {"true", "false"};
+// return ConstraintValueEditor.enumDropDown(initialValue, changeEvent, DropDownData.create(c));
+// } else {
+// String[] enums = sce.dataEnumLists.get(key);
+// if (enums != null) {
+// return ConstraintValueEditor.enumDropDown(initialValue, changeEvent, DropDownData.create(enums));
+//
+// } else {
+// return editableTextBox(changeEvent, fieldName, initialValue);
+// }
+// }
+//
+// }
+//
+// private static TextBox editableTextBox(final ValueChanged changed, String fieldName, String initialValue) {
+// final TextBox tb = new TextBox();
+// tb.setText(initialValue);
+// String m = Format.format(((Constants) GWT.create(Constants.class)).ValueFor0(), fieldName);
+// tb.setTitle(m);
+// tb.addChangeListener(new ChangeListener() {
+// public void onChange(Widget w) {
+// changed.valueChanged(tb.getText());
+// }
+// });
+//
+// return tb;
+// }
- } else {
- return editableTextBox(changeEvent, fieldName, initialValue);
- }
- }
- }
-
- private static TextBox editableTextBox(final ValueChanged changed, String fieldName, String initialValue) {
- final TextBox tb = new TextBox();
- tb.setText(initialValue);
- String m = Format.format(((Constants) GWT.create(Constants.class)).ValueFor0(), fieldName);
- tb.setTitle(m);
- tb.addChangeListener(new ChangeListener() {
- public void onChange(Widget w) {
- changed.valueChanged(tb.getText());
- }
- });
-
- return tb;
- }
-
-
/**
* Use some CSS trickery to get a percent bar.
*/
@@ -599,943 +608,10 @@
-interface RuleSelectionEvent {
- public void ruleSelected(String name);
-}
-/**
- * For capturing input for all the facts of a given type.
- * @author Michael Neale
- */
-class DataInputWidget extends DirtyableComposite {
- private Grid outer;
- private Scenario scenario;
- private SuggestionCompletionEngine sce;
- private String type;
- private ScenarioWidget parent;
- private Constants constants = ((Constants) GWT.create(Constants.class));
- public DataInputWidget(String factType, List<FactData> defList, boolean isGlobal, Scenario sc, SuggestionCompletionEngine sce, ScenarioWidget parent) {
- outer = new Grid(2, 1);
- scenario = sc;
- this.sce = sce;
- this.type = factType;
- this.parent = parent;
- outer.getCellFormatter().setStyleName(0, 0, "modeller-fact-TypeHeader"); //NON-NLS
- outer.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE );
- outer.setStyleName("modeller-fact-pattern-Widget"); //NON-NLS
-
-
- if (isGlobal) {
- outer.setWidget(0, 0, getLabel(Format.format(constants.globalForScenario(), factType), defList, parent, sc));
- } else {
- FactData first = (FactData) defList.get(0);
- if (first.isModify) {
- outer.setWidget(0, 0, getLabel(Format.format(constants.modifyForScenario(), factType), defList, parent, sc));
- } else {
- outer.setWidget(0, 0, getLabel(Format.format(constants.insertForScenario(), factType), defList, parent, sc));
- }
- }
-
- FlexTable t = render(defList, parent, sc);
-
-
-
- //parent.renderEditor();
-
-
-
- //outer.setWidget(1, 1, new Button("Remove"));
-
-
- outer.setWidget(1, 0, t);
- initWidget(outer);
- }
-
- private Widget getLabel(String text, final List defList, ScenarioWidget parent, Scenario sc) {
- //now we put in button to add new fields
- //Image newField = new ImageButton("images/add_field_to_fact.gif", "Add a field.");
- //Image newField = getNewFieldButton(defList);
- ClickableLabel clbl = new ClickableLabel(text, addFieldCL(defList, parent, sc));
- //HorizontalPanel h = new HorizontalPanel();
- //h.add(new SmallLabel(text)); h.add(newField);
- return clbl;
- }
-
- /*
- private ImageButton getNewFieldButton(final List defList) {
- ImageButton newField = new ImageButton("images/add_field_to_fact.gif", constants.AddAField()); //NON-NLS
- newField.addClickListener(addFieldCL(defList));
- return newField;
- }
- */
-
- private ClickListener addFieldCL(final List<FactData> defList, final ScenarioWidget parent, final Scenario sc) {
- return new ClickListener() {
- public void onClick(Widget w) {
-
- //build up a list of what we have got, don't want to add it twice
- HashSet existingFields = new HashSet();
- if (defList.size() > 0) {
- FactData d = (FactData) defList.get(0);
- for (Iterator iterator = d.fieldData.iterator(); iterator.hasNext();) {
- FieldData f = (FieldData) iterator.next();
- existingFields.add(f.name);
- }
-
- }
- String[] fields = (String[]) sce.fieldsForType.get(type);
- final FormStylePopup pop = new FormStylePopup(); //NON-NLS
- pop.setTitle(constants.ChooseDotDotDot());
- final ListBox b = new ListBox();
- for (int i = 0; i < fields.length; i++) {
- String fld = fields[i];
- if (!existingFields.contains(fld)) b.addItem(fld);
- }
-
- Button ok = new Button(constants.OK());
- ok.addClickListener(new ClickListener() {
- public void onClick(Widget w) {
- String f = b.getItemText(b.getSelectedIndex());
- for (Iterator iterator = defList.iterator(); iterator.hasNext();) {
- FactData fd = (FactData) iterator.next();
- fd.fieldData.add(new FieldData(f, ""));
- }
- outer.setWidget(1, 0, render(defList, parent, sc));
- pop.hide();
- }
- });
- HorizontalPanel h = new HorizontalPanel();
- h.add(b);
- h.add(ok);
- pop.addAttribute(constants.ChooseAFieldToAdd(), h);
-
-
- Button remove = new Button(constants.RemoveThisBlockOfData());
- remove.addClickListener(new ClickListener() {
- public void onClick(Widget sender) {
- if (Window.confirm(constants.AreYouSureYouWantToRemoveThisBlockOfData())) {
- scenario.globals.removeAll( defList );
- parent.renderEditor();
- pop.hide();
- }
- }
- });
- pop.addAttribute("", remove);
-
-
- pop.show();
- }
- };
- }
-
- private FlexTable render(final List defList, final ScenarioWidget parent, final Scenario sc) {
- DirtyableFlexTable t = new DirtyableFlexTable();
- if (defList.size() == 0) {
- parent.renderEditor();
- }
-
- //This will work out what row is for what field, addin labels and remove icons
-
- Map fields = new HashMap();
- int col = 0;
- int totalCols = defList.size();
- for (Iterator iterator = defList.iterator(); iterator.hasNext();) {
- final FactData d = (FactData) iterator.next();
-
- for (int i = 0; i < d.fieldData.size(); i++) {
- final FieldData fd = d.fieldData.get(i);
- if (!fields.containsKey(fd.name)) {
- int idx = fields.size() + 1;
- fields.put(fd.name, new Integer(idx));
- t.setWidget(idx, 0, new SmallLabel(fd.name + ":"));
- Image del = new ImageButton("images/delete_item_small.gif", constants.RemoveThisRow(), new ClickListener() {
- public void onClick(Widget w) {
- if (Window.confirm(constants.AreYouSureYouWantToRemoveThisRow())) {
- ScenarioHelper.removeFields(defList, fd.name);
- outer.setWidget(1, 0, render(defList, parent, sc));
-
- }
- }
- });
- t.setWidget(idx, totalCols + 1, del);
- t.getCellFormatter().setHorizontalAlignment(idx, 0, HasHorizontalAlignment.ALIGN_RIGHT);
- }
- }
- }
-
- int totalRows = fields.size();
-
- t.getFlexCellFormatter().setHorizontalAlignment(totalRows + 1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
-
- //now we go through the facts and the fields, adding them to the grid
- //if a fact is missing a FieldData, we will add it in (so people can enter data later on)
- col = 0;
- for (Iterator iterator = defList.iterator(); iterator.hasNext();) {
- final FactData d = (FactData) iterator.next();
- t.setWidget(0, ++col, new SmallLabel("[" + d.name + "]"));
- Image del = new ImageButton("images/delete_item_small.gif", Format.format(constants.RemoveTheColumnForScenario(), d.name), new ClickListener() {
- public void onClick(Widget w) {
- if (scenario.isFactNameUsed(d)) {
- Window.alert(Format.format(constants.CanTRemoveThisColumnAsTheName0IsBeingUsed(), d.name));
- } else if (Window.confirm(constants.AreYouSureYouWantToRemoveThisColumn())) {
- scenario.removeFixture(d);
- defList.remove(d);
- outer.setWidget(1, 0, render(defList, parent, sc));
- }
- }
- });
- t.setWidget(totalRows + 1, col, del);
- Map presentFields = new HashMap(fields);
- for (int i = 0; i < d.fieldData.size(); i++) {
- FieldData fd = d.fieldData.get(i);
- int fldRow = ((Integer) fields.get(fd.name)).intValue();
- t.setWidget(fldRow, col, editableCell(fd, d.type));
- presentFields.remove(fd.name);
- }
-
- for (Iterator missing = presentFields.entrySet().iterator(); missing.hasNext();) {
- Map.Entry e = (Map.Entry) missing.next();
- int fldRow = ((Integer) e.getValue()).intValue();
- FieldData fd = new FieldData((String) e.getKey(), "");
- d.fieldData.add(fd);
- t.setWidget(fldRow, col, editableCell(fd, d.type));
- }
- }
-
- if (fields.size() == 0) {
- //HorizontalPanel h = new HorizontalPanel();
- Button b = new Button(constants.AddAField());
- b.addClickListener(addFieldCL(defList, parent, sc));
-
- //h.add(new HTML("<i><small>Add fields:</small></i>"));
- //h.add(getNewFieldButton(defList));
- t.setWidget(1, 1, b);
- }
- return t;
- }
-
-
- /**
- * This will provide a cell editor. It will filter non numerics, show choices etc as appropriate.
- * @param fd
- * @param factType
- * @return
- */
- private Widget editableCell(final FieldData fd, String factType) {
-
- return ScenarioWidget.editableCell(new ValueChanged() {
- public void valueChanged(String newValue) {
- fd.value = newValue;
- makeDirty();
- }
- }, factType, fd.name, fd.value, sce);
- }
-
-
-
-
-
-
-
-
-}
-
-class ConfigWidget extends Composite {
- private final Constants constants = ((Constants) GWT.create(Constants.class));
-
- public ConfigWidget(final Scenario sc, final String packageName, final ScenarioWidget scWidget) {
-
- final ListBox box = new ListBox(true);
-
- for (int i = 0; i < sc.rules.size(); i++) {
- box.addItem((String)sc.rules.get(i));
- }
- HorizontalPanel filter = new HorizontalPanel();
-
-
- final Image add = new ImageButton("images/new_item.gif", constants.AddANewRule());
- add.addClickListener(new ClickListener() {
- public void onClick(Widget w) {
- showRulePopup(w, box, packageName, sc.rules, scWidget);
- }
- });
-
- final Image remove = new ImageButton("images/trash.gif", constants.RemoveSelectedRule());
- remove.addClickListener(new ClickListener() {
- public void onClick(Widget w) {
- if (box.getSelectedIndex() == -1) {
- Window.alert(constants.PleaseChooseARuleToRemove());
- } else {
- String r = box.getItemText(box.getSelectedIndex());
- sc.rules.remove(r);
- box.removeItem(box.getSelectedIndex());
- }
- }
- });
- VerticalPanel actions = new VerticalPanel();
- actions.add(add); actions.add(remove);
-
-
-
-
- final ListBox drop = new ListBox();
- drop.addItem(constants.AllowTheseRulesToFire(), "inc"); //NON-NLS
- drop.addItem(constants.PreventTheseRulesFromFiring(), "exc"); //NON-NLS
- drop.addItem(constants.AllRulesMayFire());
- drop.addChangeListener(new ChangeListener() {
- public void onChange(Widget w) {
- String s = drop.getValue(drop.getSelectedIndex());
- if (s.equals("inc")) { //NON-NLS
- sc.inclusive = true;
- add.setVisible(true); remove.setVisible(true); box.setVisible(true);
- } else if (s.equals("exc")) { //NON-NLS
- sc.inclusive = false;
- add.setVisible(true); remove.setVisible(true); box.setVisible(true);
- } else {
- sc.rules.clear();
- box.clear();
- box.setVisible(false); add.setVisible(false); remove.setVisible(false);
- }
- }
- });
-
- if (sc.rules.size() > 0) {
- drop.setSelectedIndex((sc.inclusive) ? 0 : 1);
- } else {
- drop.setSelectedIndex(2);
- box.setVisible(false); add.setVisible(false); remove.setVisible(false);
- }
-
-
- filter.add(drop);
- filter.add(box);
- filter.add(actions);
-
- initWidget(filter);
- }
-
- private void showRulePopup(Widget w, final ListBox box, String packageName, final List filterList, ScenarioWidget scw) {
- final FormStylePopup pop = new FormStylePopup("images/rule_asset.gif", constants.SelectRule()); //NON-NLS
-
- Widget ruleSelector = scw.getRuleSelectionWidget(packageName, new RuleSelectionEvent() {
- public void ruleSelected(String r) {
- filterList.add(r);
- box.addItem(r);
- pop.hide();
-
- }
- });
-
- pop.addRow(ruleSelector);
-
- pop.show();
-
- }
-
-
-}
-
-class ExecutionWidget extends Composite {
- private Constants constants = ((Constants) GWT.create(Constants.class));
-
- public ExecutionWidget(final ExecutionTrace ext, boolean showResults) {
-
-
- final Widget dt = simulDate(ext);
- dt.setVisible(ext.scenarioSimulatedDate != null);
-
- final ListBox choice = new ListBox();
-
- choice.addItem(constants.UseRealDateAndTime());
- choice.addItem(constants.UseASimulatedDateAndTime());
- choice.setSelectedIndex((ext.scenarioSimulatedDate == null) ? 0 : 1);
- choice.addChangeListener(new ChangeListener() {
- public void onChange(Widget w) {
- if (choice.getSelectedIndex() == 0) {
- dt.setVisible( false );
- ext.scenarioSimulatedDate = null;
- } else {
- dt.setVisible(true);
- }
- }
- });
-
- HorizontalPanel p = new HorizontalPanel();
- p.add(new Image("images/execution_trace.gif")); //NON-NLS
- p.add(choice);
- p.add(dt);
-
- VerticalPanel vert = new VerticalPanel();
- if (showResults && ext.executionTimeResult != null
- && ext.numberOfRulesFired != null) {
- HTML rep = new HTML("<i><small>" + Format.format(constants.property0RulesFiredIn1Ms(), ext.numberOfRulesFired.toString(), ext.executionTimeResult.toString()) + "</small></i>");
-
-
- final HorizontalPanel h = new HorizontalPanel();
- h.add(rep);
- vert.add(h);
-
- final Button show = new Button(constants.ShowRulesFired());
- show.addClickListener(new ClickListener() {
- public void onClick(Widget w) {
- ListBox rules = new ListBox(true);
- for (int i = 0; i < ext.rulesFired.length; i++) {
- rules.addItem(ext.rulesFired[i]);
- }
- h.add(new SmallLabel(" :" + constants.RulesFired()));
- h.add(rules);
- show.setVisible(false);
- }
- });
- h.add(show);
-
-
- vert.add(p);
- initWidget(vert);
- } else {
- initWidget(p);
- }
- }
-
-
-
- private Widget simulDate(final ExecutionTrace ext) {
- HorizontalPanel ab = new HorizontalPanel();
- final String fmt = "dd-MMM-YYYY"; //NON-NLS
- final TextBox dt = new TextBox();
- if (ext.scenarioSimulatedDate == null) {
- dt.setText("<" + fmt + ">");
- } else {
- dt.setText(ext.scenarioSimulatedDate.toLocaleString());
- }
- final SmallLabel dateHint = new SmallLabel();
- dt.addKeyboardListener(new KeyboardListener() {
- public void onKeyDown(Widget arg0, char arg1, int arg2) {}
- public void onKeyPress(Widget arg0, char arg1, int arg2) {}
- public void onKeyUp(Widget w, char arg1, int arg2) {
- try {
- Date d = new Date(dt.getText());
- dateHint.setText(d.toLocaleString());
- } catch (Exception e) {
- dateHint.setText("...");
- }
- }
- });
-
- dt.addChangeListener(new ChangeListener() {
- public void onChange(Widget w) {
- if (dt.getText().trim().equals("")) {
- dt.setText(constants.currentDateAndTime());
- } else {
- try {
- Date d = new Date(dt.getText());
- ext.scenarioSimulatedDate = d;
- dt.setText(d.toLocaleString());
- dateHint.setText("");
- } catch (Exception e) {
- ErrorPopup.showMessage(Format.format(constants.BadDateFormatPleaseTryAgainTryTheFormatOf0(), fmt));
- }
- }
- }
- });
- ab.add(dt);
- ab.add(dateHint);
- return ab;
- }
-
-
-}
-
-class VerifyFactWidget extends Composite {
- private Grid outer;
- private boolean showResults;
- private String type;
- private SuggestionCompletionEngine sce;
- private Constants constants = ((Constants) GWT.create(Constants.class));
-
- public VerifyFactWidget(final VerifyFact vf, final Scenario sc, final SuggestionCompletionEngine sce, boolean showResults) {
- outer = new Grid(2, 1);
- outer.getCellFormatter().setStyleName(0, 0, "modeller-fact-TypeHeader"); //NON-NLS
- outer.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE );
- outer.setStyleName("modeller-fact-pattern-Widget"); //NON-NLS
- this.sce = sce;
- HorizontalPanel ab = new HorizontalPanel();
- if (!vf.anonymous) {
- type = (String) sc.getVariableTypes().get(vf.name);
- ab.add(new SmallLabel(Format.format(constants.scenarioFactTypeHasValues(), type, vf.name)));
- } else {
- type = vf.name;
- ab.add(new SmallLabel(Format.format(constants.AFactOfType0HasValues(), vf.name)));
- }
- this.showResults = showResults;
-
- Image add = new ImageButton("images/add_field_to_fact.gif", constants.AddAFieldToThisExpectation(), new ClickListener() { //NON-NLS
- public void onClick(Widget w) {
-
- String[] fields = (String[]) sce.fieldsForType.get(type);
- final FormStylePopup pop = new FormStylePopup("images/rule_asset.gif", constants.ChooseAFieldToAdd()); //NON-NLS
- final ListBox b = new ListBox();
- for (int i = 0; i < fields.length; i++) {
- b.addItem(fields[i]);
- }
- pop.addRow(b);
- Button ok = new Button(constants.OK());
- ok.addClickListener(new ClickListener() {
- public void onClick(Widget w) {
- String f = b.getItemText(b.getSelectedIndex());
- vf.fieldValues.add(new VerifyField(f, "", "=="));
- FlexTable data = render(vf);
- outer.setWidget(1, 0, data);
- pop.hide();
- }
- });
- pop.addRow(ok);
- pop.show();
-
- }
- });
-
- ab.add(add);
- outer.setWidget(0, 0, ab);
- initWidget(outer);
-
- FlexTable data = render(vf);
- outer.setWidget(1, 0, data);
-
- }
-
- private FlexTable render(final VerifyFact vf) {
- FlexTable data = new FlexTable();
- for (int i = 0; i < vf.fieldValues.size(); i++) {
- final VerifyField fld = (VerifyField) vf.fieldValues.get(i);
- data.setWidget(i, 1, new SmallLabel(fld.fieldName + ":"));
- data.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_RIGHT);
-
- final ListBox opr = new ListBox();
- opr.addItem(constants.equalsScenario(), "==");
- opr.addItem(constants.doesNotEqualScenario(), "!=");
- if (fld.operator.equals("==")) {
- opr.setSelectedIndex(0);
- } else {
- opr.setSelectedIndex(1);
- }
- opr.addChangeListener(new ChangeListener() {
- public void onChange(Widget w) {
- fld.operator = opr.getValue(opr.getSelectedIndex());
- }
- });
-
- data.setWidget(i, 2, opr);
-
- Widget cellEditor = ScenarioWidget.editableCell(new ValueChanged() {
-
- public void valueChanged(String newValue) {
- fld.expected = newValue;
- }
-
- }, type, fld.fieldName, fld.expected, sce);
-
- data.setWidget(i, 3, cellEditor);
-
- Image del = new ImageButton("images/delete_item_small.gif", constants.RemoveThisFieldExpectation(), new ClickListener() {
- public void onClick(Widget w) {
- if (Window.confirm(constants.AreYouSureYouWantToRemoveThisFieldExpectation())) {
- vf.fieldValues.remove(fld);
- FlexTable data = render(vf);
- outer.setWidget(1, 0, data);
- }
- }
- });
- data.setWidget(i, 4, del);
-
- if (showResults && fld.successResult != null) {
- if (!fld.successResult.booleanValue()) {
- data.setWidget(i, 0, new Image("images/warning.gif")); //NON-NLS
- data.setWidget(i, 5, new HTML(Format.format(constants.ActualResult(), fld.actualResult )));
-
- data.getCellFormatter().addStyleName(i, 5, "testErrorValue"); //NON-NLS
-
- } else {
- data.setWidget(i, 0, new Image("images/test_passed.png")); //NON-NLS
- }
- }
-
-
-
- }
- return data;
- }
-
-}
-
-class VerifyRulesFiredWidget extends Composite {
- private Grid outer;
- private boolean showResults;
- private Constants constants = ((Constants) GWT.create(Constants.class));
-
- /**
- * @param rfl List<VeryfyRuleFired>
- * @param scenario = the scenario to add/remove from
- */
- public VerifyRulesFiredWidget(final List rfl, final Scenario scenario, boolean showResults) {
- outer = new Grid(2, 1);
- this.showResults = showResults;
- outer.getCellFormatter().setStyleName(0, 0, "modeller-fact-TypeHeader"); //NON-NLS
- outer.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE );
- outer.setStyleName("modeller-fact-pattern-Widget"); //NON-NLS
-
- outer.setWidget(0, 0, new SmallLabel(constants.ExpectRules()));
- initWidget(outer);
-
- FlexTable data = render(rfl, scenario);
- outer.setWidget(1, 0, data);
- }
-
-
-
- private FlexTable render(final List rfl, final Scenario sc) {
- FlexTable data = new DirtyableFlexTable();
-
-
- for (int i = 0; i < rfl.size(); i++) {
- final VerifyRuleFired v = (VerifyRuleFired) rfl.get(i);
-
- if (showResults && v.successResult != null) {
- if (!v.successResult.booleanValue()) {
- data.setWidget(i, 0, new Image("images/warning.gif")); //NON-NLS
- data.setWidget(i, 4, new HTML(Format.format(constants.ActualResult(), v.actualResult)));
-
- data.getCellFormatter().addStyleName(i, 4, "testErrorValue"); //NON-NLS
-
- } else {
- data.setWidget(i, 0, new Image("images/test_passed.png")); //NON-NLS
- }
-
- }
- data.setWidget(i, 1, new SmallLabel(v.ruleName + ":"));
- data.getFlexCellFormatter().setAlignment(i, 1, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
-
-
- final ListBox b = new ListBox();
- b.addItem(constants.firedAtLeastOnce(), "y");
- b.addItem(constants.didNotFire(), "n");
- b.addItem(constants.firedThisManyTimes(), "e");
- final TextBox num = new TextBox();
- num.setVisibleLength(5);
-
- if (v.expectedFire != null ) {
- b.setSelectedIndex((v.expectedFire.booleanValue()) ? 0 : 1);
- num.setVisible(false);
- } else {
- b.setSelectedIndex(2);
- String xc = (v.expectedCount != null)? "" + v.expectedCount.intValue() : "0";
- num.setText(xc);
- }
-
- b.addChangeListener(new ChangeListener() {
- public void onChange(Widget w) {
- String s = b.getValue(b.getSelectedIndex());
- if (s.equals("y") || s.equals("n")) {
- num.setVisible(false);
- v.expectedFire = (s.equals("y")) ? Boolean.TRUE : Boolean.FALSE;
- v.expectedCount = null;
- } else {
- num.setVisible(true);
- v.expectedFire = null;
- num.setText("1"); v.expectedCount = new Integer(1);
- }
- }
- });
-
- b.addItem(constants.ChooseDotDotDot());
-
- num.addChangeListener(new ChangeListener() {
- public void onChange(Widget w) {
- v.expectedCount = new Integer(num.getText());
- }
- });
-
- HorizontalPanel h = new HorizontalPanel();
- h.add(b); h.add(num);
- data.setWidget(i, 2, h);
-
- Image del = new ImageButton("images/delete_item_small.gif", constants.RemoveThisRuleExpectation(), new ClickListener() {
- public void onClick(Widget w) {
- if (Window.confirm(constants.AreYouSureYouWantToRemoveThisRuleExpectation())) {
- rfl.remove(v);
- sc.removeFixture(v);
- outer.setWidget(1, 0, render(rfl, sc));
- }
- }
- });
-
- data.setWidget(i, 3, del);
-
-
-
- //we only want numbers here...
- num.addKeyboardListener(new KeyboardListener() {
- public void onKeyDown(Widget arg0, char arg1, int arg2) {}
- public void onKeyPress(Widget w, char c, int i) {
- if (Character.isLetter( c ) ) {
- ((TextBox) w).cancelKey();
- }
- }
- public void onKeyUp(Widget arg0, char arg1, int arg2) {}
- } );
- }
- return data;
- }
-}
-
-class RetractWidget extends Composite {
- private Constants constants = ((Constants) GWT.create(Constants.class));
-
- public RetractWidget(List retList, Scenario sc) {
- FlexTable outer = new FlexTable();
- render(retList, outer, sc);
-
- initWidget(outer);
- }
-
- private void render(final List retList, final FlexTable outer, final Scenario sc) {
- outer.clear();
- outer.getCellFormatter().setStyleName(0, 0, "modeller-fact-TypeHeader");
- outer.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE );
- outer.setStyleName("modeller-fact-pattern-Widget");
- outer.setWidget(0, 0, new SmallLabel(constants.RetractFacts()));
- outer.getFlexCellFormatter().setColSpan(0, 0, 2);
-
- int row = 1;
- for (Iterator iterator = retList.iterator(); iterator.hasNext();) {
- final RetractFact r = (RetractFact) iterator.next();
- outer.setWidget(row, 0, new SmallLabel(r.name));
- Image del = new ImageButton("images/delete_item_small.gif", constants.RemoveThisRetractStatement(), new ClickListener() {
- public void onClick(Widget w) {
- retList.remove(r);
- sc.fixtures.remove(r);
- render(retList, outer, sc);
- }
- });
- outer.setWidget(row, 1, del);
-
- row++;
- }
- }
-}
-
-/**
- * Runs the test, plus shows a summary view of the results.
- */
-class TestRunnerWidget extends Composite {
-
- FlexTable results = new FlexTable();
- //Grid layout = new Grid(2, 1);
- VerticalPanel layout = new VerticalPanel();
-
- //private HorizontalPanel busy = new HorizontalPanel();
- private SimplePanel actions = new SimplePanel();
- private Constants constants = ((Constants) GWT.create(Constants.class));
-
- public TestRunnerWidget(final ScenarioWidget parent, final String packageName) {
-
- final Button run = new Button(constants.RunScenario());
- run.setTitle(constants.RunScenarioTip());
- run.addClickListener(new ClickListener() {
- public void onClick(Widget w) {
- LoadingPopup.showMessage(constants.BuildingAndRunningScenario());
- RepositoryServiceFactory.getService().runScenario(parent.asset.metaData.packageName, (Scenario) parent.asset.content, new GenericCallback<SingleScenarioResult> () {
- public void onSuccess(SingleScenarioResult data) {
- LoadingPopup.close();
- layout.clear();
- layout.add(actions);
- layout.add(results);
- actions.setVisible(true);
- ScenarioRunResult result = data.result;
- if (result.errors != null) {
- showErrors(result.errors);
- } else {
- showResults(parent, data);
- }
- }
- });
- }
- });
-
- actions.add(run);
- layout.add(actions);
- initWidget(layout);
- }
-
-
- private void showErrors(BuilderResult[] rs) {
- results.clear();
- results.setVisible(true);
-
- FlexTable errTable = new FlexTable();
- errTable.setStyleName( "build-Results" );
- for ( int i = 0; i < rs.length; i++ ) {
- int row = i;
- final BuilderResult res = rs[i];
- errTable.setWidget( row, 0, new Image("images/error.gif"));
- if( res.assetFormat.equals( "package" )) {
- errTable.setText( row, 1, constants.packageConfigurationProblem1() + res.message );
- } else {
- errTable.setText( row, 1, "[" + res.assetName + "] " + res.message );
- }
-
- }
- ScrollPanel scroll = new ScrollPanel(errTable);
-
- scroll.setWidth( "100%" );
- results.setWidget(0, 0, scroll);
-
- }
-
- private void showResults(final ScenarioWidget parent,
- final SingleScenarioResult data) {
- results.clear();
- results.setVisible(true);
-
- parent.asset.content = data.result.scenario;
- parent.showResults = true;
- parent.renderEditor();
-
- int failures = 0;
- int total = 0;
- VerticalPanel resultsDetail = new VerticalPanel();
-
-
- for (Iterator iterator = data.result.scenario.fixtures.iterator(); iterator.hasNext();) {
- Fixture f = (Fixture) iterator.next();
- if (f instanceof VerifyRuleFired) {
-
- VerifyRuleFired vr = (VerifyRuleFired)f;
- HorizontalPanel h = new HorizontalPanel();
- if (!vr.successResult.booleanValue()) {
- h.add(new Image("images/warning.gif"));
- failures++;
- } else {
- h.add(new Image("images/test_passed.png"));
- }
- h.add(new SmallLabel(vr.explanation));
- resultsDetail.add(h);
- total++;
- } else if (f instanceof VerifyFact) {
- VerifyFact vf = (VerifyFact)f;
- for (Iterator it = vf.fieldValues.iterator(); it.hasNext();) {
- total++;
- VerifyField vfl = (VerifyField) it.next();
- HorizontalPanel h = new HorizontalPanel();
- if (!vfl.successResult.booleanValue()) {
- h.add(new Image("images/warning.gif"));
- failures++;
- } else {
- h.add(new Image("images/test_passed.png"));
- }
- h.add(new SmallLabel(vfl.explanation));
- resultsDetail.add(h);
- }
-
-
- } else if (f instanceof ExecutionTrace) {
- ExecutionTrace ex = (ExecutionTrace) f;
- if (ex.numberOfRulesFired == data.result.scenario.maxRuleFirings) {
- Window.alert(Format.format(constants.MaxRuleFiringsReachedWarning(), data.result.scenario.maxRuleFirings));
- }
- }
-
-
- }
-
- results.setWidget(0, 0, new SmallLabel(constants.Results()));
- results.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
- if (failures > 0) {
- results.setWidget(0, 1, ScenarioWidget.getBar("#CC0000" , 150, failures, total));
- } else {
- results.setWidget(0, 1, ScenarioWidget.getBar("GREEN" , 150, failures, total));
- }
-
- results.setWidget(1, 0, new SmallLabel(constants.SummaryColon()));
- results.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
- results.setWidget(1, 1, resultsDetail);
- results.setWidget(2, 0, new SmallLabel(constants.AuditLogColon()));
-
- final Button showExp = new Button(constants.ShowEventsButton());
- results.setWidget(2, 1, showExp);
- showExp.addClickListener(new ClickListener() {
- public void onClick(Widget w) {
- showExp.setVisible(false);
- results.setWidget(2, 1, doAuditView(data.auditLog));
- }
- });
-
-
-
- }
-
-
-
- private Widget doAuditView(List<String[]> auditLog) {
- VerticalPanel vp = new VerticalPanel();
- vp.add(new HTML("<hr/>"));
- FlexTable g = new FlexTable();
- String indent = "";
- int row = 0;
- boolean firing = false;
- for (int i = 0; i < auditLog.size(); i++) {
- String[] lg = auditLog.get(i);
-
- int id = Integer.parseInt(lg[0]);
- if (id <= 7) {
- if (id <= 3) {
- if (!firing) {
- g.setWidget(row, 0, new Image("images/audit_events/" + lg[0] + ".gif"));
- g.setWidget(row, 1, new SmallLabel(lg[1]));
- } else {
- g.setWidget(row, 1, hz(new Image("images/audit_events/" + lg[0] + ".gif"), new SmallLabel(lg[1])));
- }
- row++;
- } else if (id == 6) {
- firing = true;
- g.setWidget(row, 0, new Image("images/audit_events/" + lg[0] + ".gif"));
- g.setWidget(row, 1, new SmallLabel("<b>" + lg[1] + "</b>"));
- row++;
- } else if (id == 7) {
- firing = false;
- } else {
- g.setWidget(row, 0, new Image("images/audit_events/" + lg[0] + ".gif"));
- g.setWidget(row, 1, new SmallLabel("<font color='grey'>" + lg[1] + "</font>"));
- row++;
- }
- } else {
- g.setWidget(row, 0, new Image("images/audit_events/misc_event.gif"));
- g.setWidget(row, 1, new SmallLabel("<font color='grey'>" + lg[1] + "</font>"));
- row++;
- }
- }
- vp.add(g);
- vp.add(new HTML("<hr/>"));
- return vp;
- }
-
-
- private Widget hz(Image image, SmallLabel smallLabel) {
- HorizontalPanel h = new HorizontalPanel();
- h.add(image);
- h.add(smallLabel);
- return h;
- }
-
-
-
-
-
-
-}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/TestRunnerWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/TestRunnerWidget.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/TestRunnerWidget.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,229 @@
+package org.drools.guvnor.client.qa;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.*;
+import com.gwtext.client.util.Format;
+import org.drools.guvnor.client.common.GenericCallback;
+import org.drools.guvnor.client.common.LoadingPopup;
+import org.drools.guvnor.client.common.SmallLabel;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.modeldriven.testing.*;
+import org.drools.guvnor.client.rpc.BuilderResult;
+import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
+import org.drools.guvnor.client.rpc.ScenarioRunResult;
+import org.drools.guvnor.client.rpc.SingleScenarioResult;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: nheron
+ * Date: 7 nov. 2009
+ * Time: 19:27:09
+ * To change this template use File | Settings | File Templates.
+ */
+public /**
+ * Runs the test, plus shows a summary view of the results.
+ */
+class TestRunnerWidget extends Composite {
+
+ FlexTable results = new FlexTable();
+ //Grid layout = new Grid(2, 1);
+ VerticalPanel layout = new VerticalPanel();
+
+ //private HorizontalPanel busy = new HorizontalPanel();
+ private SimplePanel actions = new SimplePanel();
+ private Constants constants = ((Constants) GWT.create(Constants.class));
+
+ public TestRunnerWidget(final ScenarioWidget parent, final String packageName) {
+
+ final Button run = new Button(constants.RunScenario());
+ run.setTitle(constants.RunScenarioTip());
+ run.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ LoadingPopup.showMessage(constants.BuildingAndRunningScenario());
+ RepositoryServiceFactory.getService().runScenario(parent.asset.metaData.packageName, (Scenario) parent.asset.content, new GenericCallback<SingleScenarioResult>() {
+ public void onSuccess(SingleScenarioResult data) {
+ LoadingPopup.close();
+ layout.clear();
+ layout.add(actions);
+ layout.add(results);
+ actions.setVisible(true);
+ ScenarioRunResult result = data.result;
+ if (result.errors != null) {
+ showErrors(result.errors);
+ } else {
+ showResults(parent, data);
+ }
+ }
+ });
+ }
+ });
+
+ actions.add(run);
+ layout.add(actions);
+ initWidget(layout);
+ }
+
+
+ private void showErrors(BuilderResult[] rs) {
+ results.clear();
+ results.setVisible(true);
+
+ FlexTable errTable = new FlexTable();
+ errTable.setStyleName( "build-Results" );
+ for ( int i = 0; i < rs.length; i++ ) {
+ int row = i;
+ final BuilderResult res = rs[i];
+ errTable.setWidget( row, 0, new Image("images/error.gif"));
+ if( res.assetFormat.equals( "package" )) {
+ errTable.setText( row, 1, constants.packageConfigurationProblem1() + res.message );
+ } else {
+ errTable.setText( row, 1, "[" + res.assetName + "] " + res.message );
+ }
+
+ }
+ ScrollPanel scroll = new ScrollPanel(errTable);
+
+ scroll.setWidth( "100%" );
+ results.setWidget(0, 0, scroll);
+
+ }
+
+ private void showResults(final ScenarioWidget parent,
+ final SingleScenarioResult data) {
+ results.clear();
+ results.setVisible(true);
+
+ parent.asset.content = data.result.scenario;
+ parent.showResults = true;
+ parent.renderEditor();
+
+ int failures = 0;
+ int total = 0;
+ VerticalPanel resultsDetail = new VerticalPanel();
+
+
+ for (Iterator iterator = data.result.scenario.fixtures.iterator(); iterator.hasNext();) {
+ Fixture f = (Fixture) iterator.next();
+ if (f instanceof VerifyRuleFired) {
+
+ VerifyRuleFired vr = (VerifyRuleFired)f;
+ HorizontalPanel h = new HorizontalPanel();
+ if (!vr.successResult.booleanValue()) {
+ h.add(new Image("images/warning.gif"));
+ failures++;
+ } else {
+ h.add(new Image("images/test_passed.png"));
+ }
+ h.add(new SmallLabel(vr.explanation));
+ resultsDetail.add(h);
+ total++;
+ } else if (f instanceof VerifyFact) {
+ VerifyFact vf = (VerifyFact)f;
+ for (Iterator it = vf.fieldValues.iterator(); it.hasNext();) {
+ total++;
+ VerifyField vfl = (VerifyField) it.next();
+ HorizontalPanel h = new HorizontalPanel();
+ if (!vfl.successResult.booleanValue()) {
+ h.add(new Image("images/warning.gif"));
+ failures++;
+ } else {
+ h.add(new Image("images/test_passed.png"));
+ }
+ h.add(new SmallLabel(vfl.explanation));
+ resultsDetail.add(h);
+ }
+
+
+ } else if (f instanceof ExecutionTrace) {
+ ExecutionTrace ex = (ExecutionTrace) f;
+ if (ex.numberOfRulesFired == data.result.scenario.maxRuleFirings) {
+ Window.alert(Format.format(constants.MaxRuleFiringsReachedWarning(), data.result.scenario.maxRuleFirings));
+ }
+ }
+
+
+ }
+
+ results.setWidget(0, 0, new SmallLabel(constants.Results()));
+ results.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
+ if (failures > 0) {
+ results.setWidget(0, 1, ScenarioWidget.getBar("#CC0000" , 150, failures, total));
+ } else {
+ results.setWidget(0, 1, ScenarioWidget.getBar("GREEN" , 150, failures, total));
+ }
+
+ results.setWidget(1, 0, new SmallLabel(constants.SummaryColon()));
+ results.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
+ results.setWidget(1, 1, resultsDetail);
+ results.setWidget(2, 0, new SmallLabel(constants.AuditLogColon()));
+
+ final Button showExp = new Button(constants.ShowEventsButton());
+ results.setWidget(2, 1, showExp);
+ showExp.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ showExp.setVisible(false);
+ results.setWidget(2, 1, doAuditView(data.auditLog));
+ }
+ });
+
+
+
+ }
+
+
+
+ private Widget doAuditView(List<String[]> auditLog) {
+ VerticalPanel vp = new VerticalPanel();
+ vp.add(new HTML("<hr/>"));
+ FlexTable g = new FlexTable();
+ String indent = "";
+ int row = 0;
+ boolean firing = false;
+ for (int i = 0; i < auditLog.size(); i++) {
+ String[] lg = auditLog.get(i);
+
+ int id = Integer.parseInt(lg[0]);
+ if (id <= 7) {
+ if (id <= 3) {
+ if (!firing) {
+ g.setWidget(row, 0, new Image("images/audit_events/" + lg[0] + ".gif"));
+ g.setWidget(row, 1, new SmallLabel(lg[1]));
+ } else {
+ g.setWidget(row, 1, hz(new Image("images/audit_events/" + lg[0] + ".gif"), new SmallLabel(lg[1])));
+ }
+ row++;
+ } else if (id == 6) {
+ firing = true;
+ g.setWidget(row, 0, new Image("images/audit_events/" + lg[0] + ".gif"));
+ g.setWidget(row, 1, new SmallLabel("<b>" + lg[1] + "</b>"));
+ row++;
+ } else if (id == 7) {
+ firing = false;
+ } else {
+ g.setWidget(row, 0, new Image("images/audit_events/" + lg[0] + ".gif"));
+ g.setWidget(row, 1, new SmallLabel("<font color='grey'>" + lg[1] + "</font>"));
+ row++;
+ }
+ } else {
+ g.setWidget(row, 0, new Image("images/audit_events/misc_event.gif"));
+ g.setWidget(row, 1, new SmallLabel("<font color='grey'>" + lg[1] + "</font>"));
+ row++;
+ }
+ }
+ vp.add(g);
+ vp.add(new HTML("<hr/>"));
+ return vp;
+ }
+
+
+ private Widget hz(Image image, SmallLabel smallLabel) {
+ HorizontalPanel h = new HorizontalPanel();
+ h.add(image);
+ h.add(smallLabel);
+ return h;
+ }
+}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyFactWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyFactWidget.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyFactWidget.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,150 @@
+package org.drools.guvnor.client.qa;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.*;
+import com.gwtext.client.util.Format;
+import org.drools.guvnor.client.common.FormStylePopup;
+import org.drools.guvnor.client.common.ImageButton;
+import org.drools.guvnor.client.common.SmallLabel;
+import org.drools.guvnor.client.common.ValueChanged;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
+import org.drools.guvnor.client.modeldriven.testing.ExecutionTrace;
+import org.drools.guvnor.client.modeldriven.testing.Scenario;
+import org.drools.guvnor.client.modeldriven.testing.VerifyFact;
+import org.drools.guvnor.client.modeldriven.testing.VerifyField;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: nheron
+ * Date: 7 nov. 2009
+ * Time: 19:31:47
+ * To change this template use File | Settings | File Templates.
+ */
+public class VerifyFactWidget extends Composite {
+ private Grid outer;
+ private boolean showResults;
+ private String type;
+ private SuggestionCompletionEngine sce;
+ private Scenario scenario;
+ private ExecutionTrace executionTrace;
+ private Constants constants = ((Constants) GWT.create(Constants.class));
+
+ public VerifyFactWidget(final VerifyFact vf, final Scenario sc, final SuggestionCompletionEngine sce, ExecutionTrace executionTrace,boolean showResults) {
+ outer = new Grid(2, 1);
+ outer.getCellFormatter().setStyleName(0, 0, "modeller-fact-TypeHeader"); //NON-NLS
+ outer.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE );
+ outer.setStyleName("modeller-fact-pattern-Widget"); //NON-NLS
+ this.sce = sce;
+ this.scenario = sc;
+ this.executionTrace =executionTrace;
+ HorizontalPanel ab = new HorizontalPanel();
+ if (!vf.anonymous) {
+ type = (String) sc.getVariableTypes().get(vf.name);
+ ab.add(new SmallLabel(Format.format(constants.scenarioFactTypeHasValues(), type, vf.name)));
+ } else {
+ type = vf.name;
+ ab.add(new SmallLabel(Format.format(constants.AFactOfType0HasValues(), vf.name)));
+ }
+ this.showResults = showResults;
+
+ Image add = new ImageButton("images/add_field_to_fact.gif", constants.AddAFieldToThisExpectation(), new ClickListener() { //NON-NLS
+ public void onClick(Widget w) {
+
+ String[] fields = (String[]) sce.fieldsForType.get(type);
+ final FormStylePopup pop = new FormStylePopup("images/rule_asset.gif", constants.ChooseAFieldToAdd()); //NON-NLS
+ final ListBox b = new ListBox();
+ for (int i = 0; i < fields.length; i++) {
+ b.addItem(fields[i]);
+ }
+ pop.addRow(b);
+ Button ok = new Button(constants.OK());
+ ok.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ String f = b.getItemText(b.getSelectedIndex());
+ vf.fieldValues.add(new VerifyField(f, "", "=="));
+ FlexTable data = render(vf);
+ outer.setWidget(1, 0, data);
+ pop.hide();
+ }
+ });
+ pop.addRow(ok);
+ pop.show();
+
+ }
+ });
+
+ ab.add(add);
+ outer.setWidget(0, 0, ab);
+ initWidget(outer);
+
+ FlexTable data = render(vf);
+ outer.setWidget(1, 0, data);
+
+ }
+
+ private FlexTable render(final VerifyFact vf) {
+ FlexTable data = new FlexTable();
+ for (int i = 0; i < vf.fieldValues.size(); i++) {
+ final VerifyField fld = (VerifyField) vf.fieldValues.get(i);
+ data.setWidget(i, 1, new SmallLabel(fld.fieldName + ":"));
+ data.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_RIGHT);
+
+ final ListBox opr = new ListBox();
+ opr.addItem(constants.equalsScenario(), "==");
+ opr.addItem(constants.doesNotEqualScenario(), "!=");
+ if (fld.operator.equals("==")) {
+ opr.setSelectedIndex(0);
+ } else {
+ opr.setSelectedIndex(1);
+ }
+ opr.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ fld.operator = opr.getValue(opr.getSelectedIndex());
+ }
+ });
+
+ data.setWidget(i, 2, opr);
+ //fix nheron
+ Widget cellEditor = new VerifyFieldConstraintEditor(type,
+ new ValueChanged() {
+ public void valueChanged(String newValue) {
+ fld.expected = newValue;
+ }
+
+ }, fld, sce,this.scenario,this.executionTrace);
+
+ data.setWidget(i, 3, cellEditor);
+
+ Image del = new ImageButton("images/delete_item_small.gif", constants.RemoveThisFieldExpectation(), new ClickListener() {
+ public void onClick(Widget w) {
+ if (Window.confirm(constants.AreYouSureYouWantToRemoveThisFieldExpectation())) {
+ vf.fieldValues.remove(fld);
+ FlexTable data = render(vf);
+ outer.setWidget(1, 0, data);
+ }
+ }
+ });
+ data.setWidget(i, 4, del);
+
+ if (showResults && fld.successResult != null) {
+ if (!fld.successResult.booleanValue()) {
+ data.setWidget(i, 0, new Image("images/warning.gif")); //NON-NLS
+ data.setWidget(i, 5, new HTML(Format.format(constants.ActualResult(), fld.actualResult )));
+
+ data.getCellFormatter().addStyleName(i, 5, "testErrorValue"); //NON-NLS
+
+ } else {
+ data.setWidget(i, 0, new Image("images/test_passed.png")); //NON-NLS
+ }
+ }
+
+
+
+ }
+ return data;
+ }
+
+}
+
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyFieldConstraintEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyFieldConstraintEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyFieldConstraintEditor.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,237 @@
+package org.drools.guvnor.client.qa;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: nheron
+ * Date: 8 nov. 2009
+ * Time: 19:12:24
+ * To change this template use File | Settings | File Templates.
+ */
+
+import java.util.List;
+import java.util.Map;
+
+import org.drools.guvnor.client.common.DirtyableComposite;
+import org.drools.guvnor.client.common.FormStylePopup;
+import org.drools.guvnor.client.common.InfoPopup;
+import org.drools.guvnor.client.common.SmallLabel;
+import org.drools.guvnor.client.common.ValueChanged;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.modeldriven.DropDownData;
+import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
+import org.drools.guvnor.client.modeldriven.testing.ExecutionTrace;
+import org.drools.guvnor.client.modeldriven.testing.FactData;
+import org.drools.guvnor.client.modeldriven.testing.FieldData;
+import org.drools.guvnor.client.modeldriven.testing.Scenario;
+import org.drools.guvnor.client.modeldriven.testing.VerifyField;
+import org.drools.guvnor.client.modeldriven.ui.ActionValueEditor;
+import org.drools.guvnor.client.modeldriven.ui.ConstraintValueEditor;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.ChangeListener;
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.SimplePanel;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.Widget;
+import com.gwtext.client.util.Format;
+
+/**
+ * Constraint editor for the VerifyField of the expect part
+ *
+ * @author Nicolas Heron
+ */
+public class VerifyFieldConstraintEditor extends DirtyableComposite {
+ private String factType;
+ private VerifyField field;
+ private final Panel panel;
+ private Scenario scenario;
+ private SuggestionCompletionEngine sce;
+ private ValueChanged callback;
+ private Constants constants = ((Constants) GWT.create(Constants.class));
+ private ExecutionTrace executionTrace;
+
+ public VerifyFieldConstraintEditor(String factType, ValueChanged callback,
+ VerifyField field, SuggestionCompletionEngine sce, Scenario scenario,ExecutionTrace executionTrace) {
+ this.field = field;
+ this.sce = sce;
+ this.factType = factType;
+ this.callback = callback;
+ this.scenario = scenario;
+ this.executionTrace = executionTrace;
+ panel = new SimplePanel();
+ refreshEditor();
+ initWidget(panel);
+ }
+
+ private void refreshEditor() {
+ String key = factType + "." + field.fieldName;
+ String flType = sce.fieldTypes.get(key);
+ panel.clear();
+ if (flType.equals(SuggestionCompletionEngine.TYPE_NUMERIC)) {
+ final TextBox box = editableTextBox(callback, field.fieldName,
+ field.expected);
+ box.addKeyboardListener(ActionValueEditor.getNumericFilter(box));
+ panel.add(box);
+ } else if (flType.equals(SuggestionCompletionEngine.TYPE_BOOLEAN)) {
+ String[] c = new String[] { "true", "false" };
+ panel.add(ConstraintValueEditor.enumDropDown(field.expected,
+ callback, DropDownData.create(c)));
+ } else {
+ String[] enums = sce.dataEnumLists.get(key);
+ if (enums != null) {
+ panel.add(ConstraintValueEditor.enumDropDown(field.expected,
+ callback, DropDownData.create(enums)));
+
+ } else {
+
+ if (field.nature == FieldData.TYPE_UNDEFINED
+ && isThereABoundVariableToSet() == true) {
+ Image clickme = new Image("images/edit.gif"); // NON-NLS
+ clickme.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ showTypeChoice(w, field);
+ }
+ });
+ panel.add(clickme);
+ } else if (field.nature == FieldData.TYPE_VARIABLE) {
+ panel.add(variableEditor());
+ } else {
+ panel.add(editableTextBox(callback, field.fieldName,
+ field.expected));
+ }
+
+ }
+ }
+ }
+
+ private Widget variableEditor() {
+ // sce.
+ List vars = this.scenario.getFactNamesInScope(
+ this.executionTrace, true);
+
+ final ListBox box = new ListBox();
+
+ if (this.field.expected == null) {
+ box.addItem(constants.Choose());
+ }
+ int j = 0;
+ for (int i = 0; i < vars.size(); i++) {
+ String var = (String) vars.get(i);
+ Map m = this.scenario.getVariableTypes();
+ FactData f = (FactData) scenario.getFactTypes().get(var);
+ String fieldType = sce.getFieldType(this.factType, field.fieldName);
+ if (f.type.equals(fieldType)) {
+ if (box.getItemCount() == 0) {
+ box.addItem("...");
+ j++;
+ }
+ box.addItem("="+var);
+ if (this.field.expected != null && this.field.expected.equals("="+var)) {
+ box.setSelectedIndex(j);
+ }
+ j++;
+ }
+ }
+
+ box.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ field.expected = box.getItemText(box.getSelectedIndex());
+ }
+ });
+
+ return box;
+ }
+
+
+ private static TextBox editableTextBox(final ValueChanged changed,
+ String fieldName, String initialValue) {
+ // Fixme nheron
+ final TextBox tb = new TextBox();
+ tb.setText(initialValue);
+ String m = Format.format(((Constants) GWT.create(Constants.class))
+ .ValueFor0(), fieldName);
+ tb.setTitle(m);
+ tb.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ changed.valueChanged(tb.getText());
+ }
+ });
+
+ return tb;
+ }
+
+ private void showTypeChoice(Widget w, final VerifyField con) {
+ final FormStylePopup form = new FormStylePopup("images/newex_wiz.gif",
+ constants.FieldValue());
+
+ Button lit = new Button(constants.LiteralValue());
+ lit.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ con.nature = FieldData.TYPE_LITERAL;
+ doTypeChosen(form);
+ }
+
+ });
+ form.addAttribute(constants.LiteralValue() + ":", widgets(lit,
+ new InfoPopup(constants.LiteralValue(), constants
+ .LiteralValTip())));
+
+ form.addRow(new HTML("<hr/>"));
+ form.addRow(new SmallLabel(constants.AdvancedOptions()));
+
+ // If we are here, then there must be a bound variable compatible with
+ // me
+
+ Button variable = new Button(constants.BoundVariable());
+ variable.addClickListener(new ClickListener() {
+ public void onClick(Widget w) {
+ con.nature = FieldData.TYPE_VARIABLE;
+ doTypeChosen(form);
+ }
+ });
+ form.addAttribute(constants.AVariable(), widgets(variable,
+ new InfoPopup(constants.ABoundVariable(), constants
+ .BoundVariableTip())));
+
+ form.show();
+ }
+
+ private boolean isThereABoundVariableToSet() {
+ boolean retour = false;
+ List vars = this.scenario.getFactNamesInScope(
+ executionTrace, true);
+ if (vars.size() > 0) {
+ for (int i = 0; i < vars.size(); i++) {
+ String var = (String) vars.get(i);
+ Map m = this.scenario.getVariableTypes();
+ FactData f = (FactData) scenario.getFactTypes().get(var);
+ String fieldType = sce.getFieldType(this.factType, field.fieldName);
+ if (f.type.equals(fieldType)) {
+ retour = true;
+ break;
+ }
+ }
+ }
+ return retour;
+ }
+
+ private void doTypeChosen(final FormStylePopup form) {
+ refreshEditor();
+ form.hide();
+ }
+
+ private Panel widgets(Widget left, Widget right) {
+ HorizontalPanel panel = new HorizontalPanel();
+ panel.add(left);
+ panel.add(right);
+ panel.setWidth("100%");
+ return panel;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyRulesFiredWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyRulesFiredWidget.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/qa/VerifyRulesFiredWidget.java 2009-11-22 15:50:28 UTC (rev 30282)
@@ -0,0 +1,142 @@
+package org.drools.guvnor.client.qa;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.*;
+import com.gwtext.client.util.Format;
+import org.drools.guvnor.client.common.DirtyableFlexTable;
+import org.drools.guvnor.client.common.ImageButton;
+import org.drools.guvnor.client.common.SmallLabel;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.modeldriven.testing.Scenario;
+import org.drools.guvnor.client.modeldriven.testing.VerifyRuleFired;
+
+import java.util.List;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: nheron
+ * Date: 7 nov. 2009
+ * Time: 19:30:04
+ * To change this template use File | Settings | File Templates.
+ */
+public class VerifyRulesFiredWidget extends Composite {
+ private Grid outer;
+ private boolean showResults;
+ private Constants constants = ((Constants) GWT.create(Constants.class));
+
+ /**
+ * @param rfl List<VeryfyRuleFired>
+ * @param scenario = the scenario to add/remove from
+ */
+ public VerifyRulesFiredWidget(final List rfl, final Scenario scenario, boolean showResults) {
+ outer = new Grid(2, 1);
+ this.showResults = showResults;
+ outer.getCellFormatter().setStyleName(0, 0, "modeller-fact-TypeHeader"); //NON-NLS
+ outer.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE );
+ outer.setStyleName("modeller-fact-pattern-Widget"); //NON-NLS
+
+ outer.setWidget(0, 0, new SmallLabel(constants.ExpectRules()));
+ initWidget(outer);
+
+ FlexTable data = render(rfl, scenario);
+ outer.setWidget(1, 0, data);
+ }
+
+
+
+ private FlexTable render(final List rfl, final Scenario sc) {
+ FlexTable data = new DirtyableFlexTable();
+
+
+ for (int i = 0; i < rfl.size(); i++) {
+ final VerifyRuleFired v = (VerifyRuleFired) rfl.get(i);
+
+ if (showResults && v.successResult != null) {
+ if (!v.successResult.booleanValue()) {
+ data.setWidget(i, 0, new Image("images/warning.gif")); //NON-NLS
+ data.setWidget(i, 4, new HTML(Format.format(constants.ActualResult(), v.actualResult)));
+
+ data.getCellFormatter().addStyleName(i, 4, "testErrorValue"); //NON-NLS
+
+ } else {
+ data.setWidget(i, 0, new Image("images/test_passed.png")); //NON-NLS
+ }
+
+ }
+ data.setWidget(i, 1, new SmallLabel(v.ruleName + ":"));
+ data.getFlexCellFormatter().setAlignment(i, 1, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
+
+
+ final ListBox b = new ListBox();
+ b.addItem(constants.firedAtLeastOnce(), "y");
+ b.addItem(constants.didNotFire(), "n");
+ b.addItem(constants.firedThisManyTimes(), "e");
+ final TextBox num = new TextBox();
+ num.setVisibleLength(5);
+
+ if (v.expectedFire != null ) {
+ b.setSelectedIndex((v.expectedFire.booleanValue()) ? 0 : 1);
+ num.setVisible(false);
+ } else {
+ b.setSelectedIndex(2);
+ String xc = (v.expectedCount != null)? "" + v.expectedCount.intValue() : "0";
+ num.setText(xc);
+ }
+
+ b.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ String s = b.getValue(b.getSelectedIndex());
+ if (s.equals("y") || s.equals("n")) {
+ num.setVisible(false);
+ v.expectedFire = (s.equals("y")) ? Boolean.TRUE : Boolean.FALSE;
+ v.expectedCount = null;
+ } else {
+ num.setVisible(true);
+ v.expectedFire = null;
+ num.setText("1"); v.expectedCount = new Integer(1);
+ }
+ }
+ });
+
+ b.addItem(constants.ChooseDotDotDot());
+
+ num.addChangeListener(new ChangeListener() {
+ public void onChange(Widget w) {
+ v.expectedCount = new Integer(num.getText());
+ }
+ });
+
+ HorizontalPanel h = new HorizontalPanel();
+ h.add(b); h.add(num);
+ data.setWidget(i, 2, h);
+
+ Image del = new ImageButton("images/delete_item_small.gif", constants.RemoveThisRuleExpectation(), new ClickListener() {
+ public void onClick(Widget w) {
+ if (Window.confirm(constants.AreYouSureYouWantToRemoveThisRuleExpectation())) {
+ rfl.remove(v);
+ sc.removeFixture(v);
+ outer.setWidget(1, 0, render(rfl, sc));
+ }
+ }
+ });
+
+ data.setWidget(i, 3, del);
+
+
+
+ //we only want numbers here...
+ num.addKeyboardListener(new KeyboardListener() {
+ public void onKeyDown(Widget arg0, char arg1, int arg2) {}
+ public void onKeyPress(Widget w, char c, int i) {
+ if (Character.isLetter( c ) ) {
+ ((TextBox) w).cancelKey();
+ }
+ }
+ public void onKeyUp(Widget arg0, char arg1, int arg2) {}
+ } );
+ }
+ return data;
+ }
+}
+
More information about the jboss-svn-commits
mailing list