01: package org.osbl.agent.gui.condition;
02:
03: import java.util.List;
04:
05: import org.conform.PropertyMeta;
06: import org.osbl.agent.model.condition.PropertyCondition;
07: import org.wings.SComboBox;
08: import org.wings.SComponent;
09: import org.wings.SLabel;
10: import org.wings.SListCellRenderer;
11:
12: /**
13: * The class EnumConditionController models the EnumCondition, presenting the user
14: * with the usual operators (as a combo-box, inherited from PropertyConditionController)
15: * and an aditional combo-box with all possible values of the enum.
16: *
17: * @author Sebastian Nozzi.
18: */
19: public class EnumConditionController extends
20: PropertyConditionController {
21:
22: /** The values combo. */
23: SComboBox valuesCombo;
24:
25: /**
26: * Instantiates a new EnumConditionController.
27: */
28: public EnumConditionController() {
29: super ();
30:
31: valuesCombo = new SComboBox();
32:
33: valuesCombo.setRenderer(new SListCellRenderer() {
34:
35: SLabel label = new SLabel();
36:
37: public SComponent getListCellRendererComponent(
38: SComponent list, java.lang.Object value,
39: boolean isSelected, int index) {
40:
41: label.setText(propertyMeta.getFormat().format(value));
42:
43: return label;
44: }
45:
46: });
47: }
48:
49: /* (non-Javadoc)
50: * @see org.osbl.agent.gui.condition.PropertyConditionController#setPropertyMeta(org.conform.PropertyMeta)
51: */
52: public void setPropertyMeta(PropertyMeta propertyMeta) {
53: super .setPropertyMeta(propertyMeta);
54:
55: valuesCombo.removeAllItems();
56:
57: for (Object element : propertyMeta.getDomainProvider()
58: .getDomain())
59: valuesCombo.addItem(element);
60: }
61:
62: /* (non-Javadoc)
63: * @see org.osbl.agent.gui.condition.PropertyConditionController#populateComponentList(java.util.List)
64: */
65: protected void populateComponentList(List<SComponent> componentList) {
66: super .populateComponentList(componentList);
67: componentList.add(valuesCombo);
68:
69: }
70:
71: /* (non-Javadoc)
72: * @see org.osbl.agent.gui.condition.PropertyConditionController#getValueToCompareTo()
73: */
74: public Object getValueToCompareTo() {
75: return valuesCombo.getSelectedItem();
76: }
77:
78: /* (non-Javadoc)
79: * @see org.osbl.agent.gui.condition.PropertyConditionController#setValueToCompareTo(org.osbl.agent.model.condition.PropertyCondition)
80: */
81: public void setValueToCompareTo(PropertyCondition condition) {
82:
83: Object enumValue = condition.getValueToCompareTo();
84:
85: // iterate over all values in the combo-box...
86: for (int i = 0; i < valuesCombo.getItemCount(); i++) {
87: Object candidateValue = valuesCombo.getItemAt(i);
88:
89: // ...until we find the one that matches...
90: if (candidateValue.equals(enumValue))
91: // ...and make it the selected item in the combo-box.
92: valuesCombo.setSelectedIndex(i);
93: }
94:
95: }
96:
97: }
|