|
31 | 31 |
|
32 | 32 | import java.awt.event.ActionEvent;
|
33 | 33 | import java.awt.event.ActionListener;
|
| 34 | +import java.util.Arrays; |
34 | 35 |
|
35 | 36 | import javax.swing.JComboBox;
|
36 | 37 | import javax.swing.JPanel;
|
@@ -67,7 +68,10 @@ public void actionPerformed(final ActionEvent e) {
|
67 | 68 |
|
68 | 69 | @Override
|
69 | 70 | public String getValue() {
|
70 |
| - return comboBox.getSelectedItem().toString(); |
| 71 | + if (comboBox.getItemCount() > 0) |
| 72 | + return comboBox.getSelectedItem().toString(); |
| 73 | + else |
| 74 | + return null; |
71 | 75 | }
|
72 | 76 |
|
73 | 77 | // -- WrapperPlugin methods --
|
@@ -97,8 +101,24 @@ public boolean supports(final WidgetModel model) {
|
97 | 101 |
|
98 | 102 | @Override
|
99 | 103 | public void doRefresh() {
|
100 |
| - final Object value = get().getValue(); |
101 |
| - if (value.equals(comboBox.getSelectedItem())) return; // no change |
102 |
| - comboBox.setSelectedItem(value); |
| 104 | + final String[] choices = get().getChoices(); |
| 105 | + |
| 106 | + if (!Arrays.equals(choices, comboBoxItems())) { |
| 107 | + comboBox.removeAllItems(); |
| 108 | + for (int i=0; i<choices.length; i++) |
| 109 | + comboBox.addItem(choices[i]); |
| 110 | + } else { |
| 111 | + final Object value = get().getValue(); |
| 112 | + if (value.equals(comboBox.getSelectedItem())) return; |
| 113 | + comboBox.setSelectedItem(value); |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + private String[] comboBoxItems() { |
| 118 | + String[] comboItems = new String[comboBox.getItemCount()]; |
| 119 | + for (int i=0; i <comboBox.getItemCount(); i++) |
| 120 | + comboItems[i] = comboBox.getItemAt(i); |
| 121 | + |
| 122 | + return comboItems; |
103 | 123 | }
|
104 | 124 | }
|
0 commit comments