Revision 585
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/dynobject/dynfield/JNDynFieldComponent.java | ||
---|---|---|
38 | 38 |
import java.awt.Insets; |
39 | 39 |
import java.awt.event.ActionEvent; |
40 | 40 |
import java.awt.event.ActionListener; |
41 |
import java.util.ArrayList; |
|
41 | 42 |
import java.util.Iterator; |
42 | 43 |
import java.util.List; |
43 | 44 |
|
... | ... | |
47 | 48 |
import javax.swing.JComponent; |
48 | 49 |
import javax.swing.JList; |
49 | 50 |
import javax.swing.JPanel; |
50 |
import javax.swing.JScrollPane; |
|
51 | 51 |
import javax.swing.ListSelectionModel; |
52 | 52 |
import javax.swing.event.ListSelectionEvent; |
53 | 53 |
import javax.swing.event.ListSelectionListener; |
... | ... | |
72 | 72 |
|
73 | 73 |
private JButton addButton; |
74 | 74 |
|
75 |
private JScrollPane listScrollPane; |
|
76 |
|
|
77 | 75 |
private JPanel subPanel; |
78 | 76 |
|
79 | 77 |
/** |
... | ... | |
142 | 140 |
if (getSize() <= 0) { |
143 | 141 |
return null; |
144 | 142 |
} |
145 |
if (this.getDynField().getType() == DataTypes.STRING) { |
|
146 |
return this.list.getSelectedValue(); |
|
143 |
|
|
144 |
Object valueItem; |
|
145 |
List listItems = new ArrayList(); |
|
146 |
for (int i = 0; i < this.list.getModel().getSize(); i++) { |
|
147 |
valueItem = this.list.getModel().getElementAt(i); |
|
148 |
listItems.add(valueItem); |
|
147 | 149 |
} |
148 |
return this.list.getSelectedIndex();
|
|
150 |
return listItems;
|
|
149 | 151 |
} |
150 | 152 |
|
151 | 153 |
/* |
... | ... | |
159 | 161 |
public void handleValueChanged(JDynFieldComponent component) { |
160 | 162 |
if (getComponent().isValid() && getComponent().getValue() != null) { |
161 | 163 |
int index = this.list.getSelectedIndex(); |
162 |
if (index > -1) {
|
|
164 |
if (index >= 0) {
|
|
163 | 165 |
setListValue(getComponent().getValue(), index); |
164 | 166 |
} |
165 | 167 |
} else { |
166 | 168 |
this.list.setSelectedIndex(-1); |
167 | 169 |
} |
168 |
refresh(); |
|
169 | 170 |
} |
170 | 171 |
|
171 | 172 |
/** |
... | ... | |
175 | 176 |
subPanel = new JPanel(new GridBagLayout()); |
176 | 177 |
subPanel.setBorder(BorderFactory.createTitledBorder("")); |
177 | 178 |
list.setVisibleRowCount(4); |
178 |
// list.setBorder(new LineBorder(Color.blue,3)); |
|
179 |
|
|
179 |
|
|
180 | 180 |
list.setBorder(BorderFactory.createTitledBorder("")); |
181 | 181 |
// listScrollPane = new JScrollPane(list); |
182 | 182 |
// listScrollPane.setViewportView(this.list); |
... | ... | |
254 | 254 |
public void actionPerformed(ActionEvent e) { |
255 | 255 |
removeElement(list.getSelectedIndex()); |
256 | 256 |
refresh(); |
257 |
|
|
258 |
fireValueChangedEvent(); |
|
257 | 259 |
} |
258 | 260 |
}); |
259 | 261 |
|
... | ... | |
268 | 270 |
addElement(getComponent()); |
269 | 271 |
} |
270 | 272 |
refresh(); |
273 |
fireValueChangedEvent(); |
|
271 | 274 |
} |
272 | 275 |
}); |
273 | 276 |
} |
... | ... | |
313 | 316 |
|
314 | 317 |
public void refresh() { |
315 | 318 |
this.setEnabled(!isEmpty()); |
316 |
this.fireValueChangedEvent(); |
|
319 |
// this.fireValueChangedEvent();
|
|
317 | 320 |
} |
318 | 321 |
|
319 | 322 |
protected void removeElement(int ind) { |
... | ... | |
336 | 339 |
|
337 | 340 |
public void setEnabled(boolean isEnabled) { |
338 | 341 |
|
339 |
this.removeButton.setEnabled(isEnabled);
|
|
342 |
this.removeButton.setEnabled(isEnabled);
|
|
340 | 343 |
if ((getModel().isEmpty()) || (list.getSelectedIndex() < 0)) { |
341 |
|
|
342 |
this.getComponent().requestFocus(); |
|
344 |
if (this.getComponent().getDynField().getType() != DataTypes.DYNOBJECT) { |
|
345 |
this.getComponent().requestFocus(); |
|
346 |
} |
|
343 | 347 |
} |
344 | 348 |
|
345 | 349 |
this.list.updateUI(); |
346 | 350 |
getComponent().asJComponent().updateUI(); |
347 | 351 |
|
348 | 352 |
this.removeButton.setEnabled(isEnabled); |
349 |
|
|
350 |
if (this.getDynField().isReadOnly()) { |
|
353 |
if (isReadOnly()) { |
|
351 | 354 |
if (this.getValue() == null) { |
352 | 355 |
this.addButton.setEnabled(true); |
353 | 356 |
this.getComponent().setEnabled(true); |
... | ... | |
362 | 365 |
this.list.updateUI(); |
363 | 366 |
getComponent().asJComponent().updateUI(); |
364 | 367 |
|
365 |
}
|
|
368 |
}
|
|
366 | 369 |
|
367 | 370 |
private boolean isEmpty() { |
368 | 371 |
return (getModel().isEmpty() || (list.getSelectedIndex() < 0)); |
... | ... | |
417 | 420 |
public void valueChanged(ListSelectionEvent e) { |
418 | 421 |
|
419 | 422 |
int index = list.getSelectedIndex(); |
420 |
int size = getSize(); |
|
421 | 423 |
if (index >= 0) { |
422 | 424 |
this.getComponent().setValue( |
423 | 425 |
getModel().getElementAt(list.getSelectedIndex())); |
424 |
this.removeButton.setEnabled(true); |
|
425 |
// this.listScrollPane.setEnabled(true); |
|
426 |
} else { |
|
427 |
if (size >= 0) { |
|
426 |
}else{ |
|
427 |
int size = getSize(); |
|
428 |
if (size > 0) { |
|
428 | 429 |
index = getModel().indexOf(getModel().firstElement()); |
429 | 430 |
if (index != this.list.getSelectedIndex()) { |
430 | 431 |
this.list.setSelectedIndex(index); |
431 | 432 |
} |
432 |
} else { |
|
433 |
this.removeButton.setEnabled(false); |
|
434 |
this.listScrollPane.setEnabled(false); |
|
435 | 433 |
} |
436 | 434 |
} |
437 | 435 |
refresh(); |
438 |
this.fireValueChangedEvent(); |
|
439 | 436 |
} |
440 | 437 |
|
441 | 438 |
public String getValidationMessage() { |
... | ... | |
447 | 444 |
if (this.list == null) { |
448 | 445 |
return super.getModel(); |
449 | 446 |
} |
450 |
|
|
451 | 447 |
return (DefaultListModel) this.list.getModel(); |
452 | 448 |
} |
453 | 449 |
|
Also available in: Unified diff