Time for action – adding a combobox
Implement the initCombo
method of your TimeItUI
class as shown in the following code snippet:
private void initCombo() { for(TestSet testSet : testSets) { combo.addItem(testSet); combo.setItemCaption(testSet, testSet.getTitle()); } combo.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { TestSet testSet = (TestSet) combo.getValue(); textField.setValue("" + testSet.getDefaultTimes()); button.setDescription(testSet.getDescription()); } }); combo.setImmediate(true); }
What just happened?
It's not that complicated. If we isolate the for
portion of the previous code, we'll get this:
for(TestSet testSet : testSets) { combo.addItem(testSet); combo.setItemCaption(testSet, testSet.getTitle()); }
For each TestSet
instance in our array, we add a TestSet
instance and then we say, "Okay, Vaadin for this testSet
array I just added, please show what testSet...