public ConfigWidget(final Scenario sc,
ScenarioWidgetComponentCreator scenarioWidgetComponentCreator) {
this.scenarioWidgetComponentCreator = scenarioWidgetComponentCreator;
final ListBox box = new ListBox(true);
for (int i = 0; i < sc.getRules().size(); i++) {
box.addItem(sc.getRules().get(i));
}
HorizontalPanel filter = new HorizontalPanel();
final Image add = ItemAltedImages.INSTANCE.NewItem();
add.setAltText( TestScenarioConstants.INSTANCE.AddANewRule());
add.setTitle(TestScenarioConstants.INSTANCE.AddANewRule());
add.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
showRulePopup(
box,
sc.getRules());
}
});
final Image remove = Images.INSTANCE.Trash();
remove.setAltText(TestScenarioConstants.INSTANCE.RemoveSelectedRule());
remove.setTitle(TestScenarioConstants.INSTANCE.RemoveSelectedRule());
remove.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (box.getSelectedIndex() == -1) {
Window.alert(TestScenarioConstants.INSTANCE.PleaseChooseARuleToRemove());
} else {
String r = box.getItemText(box.getSelectedIndex());
sc.getRules().remove(r);
box.removeItem(box.getSelectedIndex());
}
}
});
VerticalPanel actions = new VerticalPanel();
actions.add(add);
actions.add(remove);
final ListBox drop = new ListBox();
drop.addItem(TestScenarioConstants.INSTANCE.AllowTheseRulesToFire(),
"inc"); //NON-NLS
drop.addItem(TestScenarioConstants.INSTANCE.PreventTheseRulesFromFiring(),
"exc"); //NON-NLS
drop.addItem(TestScenarioConstants.INSTANCE.AllRulesMayFire());
drop.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
String s = drop.getValue(drop.getSelectedIndex());
if (s.equals("inc")) { //NON-NLS
sc.setInclusive(true);
add.setVisible(true);
remove.setVisible(true);
box.setVisible(true);
} else if (s.equals("exc")) { //NON-NLS
sc.setInclusive(false);
add.setVisible(true);
remove.setVisible(true);
box.setVisible(true);
} else {
sc.getRules().clear();
box.clear();
box.setVisible(false);
add.setVisible(false);
remove.setVisible(false);
}
}
});
if (sc.getRules().size() > 0) {
drop.setSelectedIndex((sc.isInclusive()) ? 0 : 1);
} else {
drop.setSelectedIndex(2);
box.setVisible(false);
add.setVisible(false);
remove.setVisible(false);
}