ScenarioHelper hlp = new ScenarioHelper();
List fixtures = hlp.lumpyMap(scenario.fixtures);
int layoutRow = 1;
ExecutionTrace previousEx = null;
for (int i = 0; i < fixtures.size(); i++) {
final Object f = fixtures.get(i);
if (f instanceof ExecutionTrace) {
previousEx = (ExecutionTrace) f;
HorizontalPanel h = new HorizontalPanel();
h.add(getNewExpectationButton(previousEx, scenario));
h.add(new SmallLabel(constants.EXPECT()));
editorLayout.setWidget(layoutRow, 0, h);
final ExecutionTrace et = (ExecutionTrace) previousEx;
Image del = new ImageButton("images/delete_item_small.gif", constants.DeleteItem(), new ClickListener() {
public void onClick(Widget w) {
if ( Window.confirm(constants.AreYouSureYouWantToRemoveThisItem()) ) {
scenario.removeExecutionTrace( et );
renderEditor();
}
}
});
h.add(del);
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(new SmallLabel(constants.GIVEN()));
editorLayout.setWidget(layoutRow, 0, h);
layoutRow++;
Map facts = (Map) f;
VerticalPanel vert = new VerticalPanel();
for (Iterator iterator = facts.entrySet().iterator(); iterator.hasNext();) {
Map.Entry e = (Map.Entry) iterator.next();
List factList = (List) facts.get(e.getKey());
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));
}
}
if (facts.size() > 0) {
editorLayout.setWidget(layoutRow, 1, vert);
} else {
editorLayout.setWidget(layoutRow, 1, new HTML("<i><small>" + constants.AddInputDataAndExpectationsHere() + "</small></i>"));
}
} else {
List l = (List) f;
Fixture first = (Fixture) l.get(0);
if (first instanceof VerifyFact) {
doVerifyFacts(l, editorLayout, layoutRow, scenario);
} else if (first instanceof VerifyRuleFired) {
editorLayout.setWidget(layoutRow, 1, new VerifyRulesFiredWidget(l, scenario, showResults));
}
}
layoutRow++;
}
//add more execution sections.
Button addExecute = new Button(constants.MoreDotDot());
addExecute.setTitle(constants.AddAnotherSectionOfDataAndExpectations());
addExecute.addClickListener(new ClickListener() {
public void onClick(Widget w) {
scenario.fixtures.add(new ExecutionTrace());
renderEditor();
}
});
editorLayout.setWidget(layoutRow, 0, addExecute);
//layout.getFlexCellFormatter().setHorizontalAlignment(layoutRow, 1, HasHorizontalAlignment.ALIGN_CENTER);