Revision 44202 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/featuretype/DefaultFeatureTypeAttributePanel.java
DefaultFeatureTypeAttributePanel.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.swing.impl.featuretype; |
2 | 2 |
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.awt.event.ActionListener; |
|
3 | 5 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
4 | 6 |
import java.awt.event.ItemEvent; |
5 | 7 |
import java.awt.event.ItemListener; |
6 | 8 |
import java.util.ArrayList; |
7 | 9 |
import java.util.Comparator; |
8 | 10 |
import java.util.List; |
11 |
import java.util.Objects; |
|
12 |
import javax.swing.ComboBoxModel; |
|
9 | 13 |
import javax.swing.DefaultComboBoxModel; |
14 |
import javax.swing.JButton; |
|
15 |
import javax.swing.JComboBox; |
|
10 | 16 |
import javax.swing.JComponent; |
11 | 17 |
import javax.swing.JOptionPane; |
12 | 18 |
import javax.swing.SwingUtilities; |
13 | 19 |
import javax.swing.event.ChangeEvent; |
14 | 20 |
import javax.swing.event.ChangeListener; |
15 |
import org.apache.commons.lang3.ArrayUtils;
|
|
21 |
import javax.swing.text.JTextComponent;
|
|
16 | 22 |
import org.apache.commons.lang3.StringUtils; |
17 | 23 |
import org.cresques.cts.IProjection; |
18 | 24 |
import org.gvsig.expressionevaluator.Expression; |
... | ... | |
43 | 49 |
import org.gvsig.timesupport.RelativeInterval; |
44 | 50 |
import org.gvsig.tools.ToolsLocator; |
45 | 51 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
52 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
|
46 | 53 |
import org.gvsig.tools.i18n.I18nManager; |
47 | 54 |
import org.gvsig.tools.swing.api.ListElement; |
48 | 55 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
... | ... | |
63 | 70 |
implements FeatureTypeAttributePanel { |
64 | 71 |
|
65 | 72 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultFeatureTypeAttributePanel.class); |
73 |
|
|
74 |
private static class AvailableValuesController { |
|
75 |
private final JComboBox cboValues; |
|
76 |
private final JTextComponent txtLabel; |
|
77 |
private final JTextComponent txtValue; |
|
78 |
private final JButton btnAdd; |
|
79 |
private final JButton btnUpdate; |
|
80 |
private final JButton btnRemove; |
|
81 |
|
|
82 |
public AvailableValuesController( |
|
83 |
JComboBox cblValues, |
|
84 |
JTextComponent txtLabel, |
|
85 |
JTextComponent txtValue, |
|
86 |
JButton btnAdd, |
|
87 |
JButton btnUpdate, |
|
88 |
JButton btnRemove |
|
89 |
) { |
|
90 |
this.cboValues = cblValues; |
|
91 |
this.txtLabel = txtLabel; |
|
92 |
this.txtValue = txtValue; |
|
93 |
this.btnAdd = btnAdd; |
|
94 |
this.btnUpdate = btnUpdate; |
|
95 |
this.btnRemove = btnRemove; |
|
96 |
|
|
97 |
this.cboValues.addItemListener(new ItemListener() { |
|
98 |
@Override |
|
99 |
public void itemStateChanged(ItemEvent e) { |
|
100 |
doValuesChanged(); |
|
101 |
} |
|
102 |
}); |
|
103 |
this.btnAdd.addActionListener(new ActionListener() { |
|
104 |
@Override |
|
105 |
public void actionPerformed(ActionEvent e) { |
|
106 |
doAdd(); |
|
107 |
} |
|
108 |
}); |
|
109 |
this.btnUpdate.addActionListener(new ActionListener() { |
|
110 |
@Override |
|
111 |
public void actionPerformed(ActionEvent e) { |
|
112 |
doUpdate(); |
|
113 |
} |
|
114 |
}); |
|
115 |
this.btnRemove.addActionListener(new ActionListener() { |
|
116 |
@Override |
|
117 |
public void actionPerformed(ActionEvent e) { |
|
118 |
doRemove(); |
|
119 |
} |
|
120 |
}); |
|
121 |
} |
|
122 |
|
|
123 |
public void clean() { |
|
124 |
this.cboValues.setModel(new DefaultComboBoxModel()); |
|
125 |
this.txtLabel.setText(""); |
|
126 |
this.txtValue.setText(""); |
|
127 |
this.cboValues.setSelectedIndex(-1); |
|
128 |
} |
|
129 |
|
|
130 |
public DynObjectValueItem[] get() { |
|
131 |
ComboBoxModel<DynObjectValueItem> model = this.cboValues.getModel(); |
|
132 |
DynObjectValueItem[] values = new DynObjectValueItem[model.getSize()]; |
|
133 |
for (int i = 0; i < model.getSize(); i++) { |
|
134 |
values[i] = model.getElementAt(i); |
|
135 |
} |
|
136 |
return values; |
|
137 |
} |
|
138 |
|
|
139 |
public void set(DynObjectValueItem[] availableValues) { |
|
140 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
141 |
if( availableValues!=null ) { |
|
142 |
for (DynObjectValueItem availableValue : availableValues) { |
|
143 |
model.addElement(availableValue); |
|
144 |
} |
|
145 |
} |
|
146 |
this.cboValues.setModel(model); |
|
147 |
if(model.getSize()>0 ) { |
|
148 |
this.cboValues.setSelectedIndex(0); |
|
149 |
} else { |
|
150 |
this.cboValues.setSelectedIndex(-1); |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
public void setEditable(boolean editable) { |
|
155 |
this.cboValues.setEnabled(editable); |
|
156 |
this.txtLabel.setEditable(editable); |
|
157 |
this.txtValue.setEditable(editable); |
|
158 |
this.btnAdd.setEnabled(editable); |
|
159 |
this.btnUpdate.setEnabled(editable); |
|
160 |
this.btnRemove.setEnabled(editable); |
|
161 |
} |
|
162 |
|
|
163 |
private void doValuesChanged() { |
|
164 |
DynObjectValueItem value = (DynObjectValueItem) this.cboValues.getSelectedItem(); |
|
165 |
if( value == null ) { |
|
166 |
this.txtLabel.setText(""); |
|
167 |
this.txtValue.setText(""); |
|
168 |
this.btnAdd.setEnabled(true); |
|
169 |
this.btnUpdate.setEnabled(false); |
|
170 |
this.btnRemove.setEnabled(false); |
|
171 |
return; |
|
172 |
} |
|
173 |
this.txtLabel.setText(value.getLabel()); |
|
174 |
this.txtValue.setText(Objects.toString(value.getValue(),"")); |
|
175 |
this.btnAdd.setEnabled(true); |
|
176 |
this.btnUpdate.setEnabled(true); |
|
177 |
this.btnRemove.setEnabled(true); |
|
178 |
} |
|
179 |
|
|
180 |
private void doAdd() { |
|
181 |
DynObjectValueItem value = new DynObjectValueItem("Value", "Label"); |
|
182 |
DefaultComboBoxModel model = (DefaultComboBoxModel) this.cboValues.getModel(); |
|
183 |
model.addElement(value); |
|
184 |
this.cboValues.setSelectedIndex(model.getSize()-1); |
|
185 |
} |
|
186 |
|
|
187 |
private void doUpdate() { |
|
188 |
DynObjectValueItem value = (DynObjectValueItem) this.cboValues.getSelectedItem(); |
|
189 |
if( value == null ) { |
|
190 |
return; // EEhh?? esto no deberia pasar |
|
191 |
} |
|
192 |
value.setLabel(this.txtLabel.getText()); |
|
193 |
value.setValue(this.txtValue.getText()); |
|
194 |
} |
|
195 |
|
|
196 |
private void doRemove() { |
|
197 |
int n = this.cboValues.getSelectedIndex(); |
|
198 |
if( n<0 ) { |
|
199 |
return; // EEhh?? esto no deberia pasar |
|
200 |
} |
|
201 |
DefaultComboBoxModel model = (DefaultComboBoxModel) this.cboValues.getModel(); |
|
202 |
model.removeElementAt(n); |
|
203 |
if( --n <0 ) { |
|
204 |
n = 0; |
|
205 |
} |
|
206 |
this.cboValues.setSelectedIndex(n); |
|
207 |
} |
|
208 |
|
|
209 |
} |
|
210 |
|
|
66 | 211 |
|
67 | 212 |
private final List<ListElement<Integer>> fieldTypes; |
68 | 213 |
private final List<ListElement<Integer>> geometryTypes; |
... | ... | |
75 | 220 |
private CalculatorController<Object> pickerDefaultValue; |
76 | 221 |
private PickerController<IProjection> pickerCRS; |
77 | 222 |
private ExpressionPickerController pickerVirtualField; |
223 |
private CalculatorController<Integer> pickerOrder; |
|
224 |
private AvailableValuesController availableValuesController; |
|
78 | 225 |
|
79 | 226 |
private boolean editable; |
80 | 227 |
private FeatureStoreElement featureStoreElement; |
... | ... | |
173 | 320 |
swingManager.translate(this.lblSize); |
174 | 321 |
swingManager.translate(this.chkVirtualField); |
175 | 322 |
swingManager.translate(this.tabAditionalFields); |
323 |
swingManager.translate(this.tabLayout); |
|
324 |
swingManager.translate(this.lblGroup); |
|
325 |
swingManager.translate(this.lblOrder); |
|
326 |
swingManager.translate(this.lblHidden); |
|
327 |
swingManager.translate(this.lblLabel); |
|
328 |
swingManager.translate(this.lblDescription); |
|
329 |
swingManager.translate(this.lblMinValue); |
|
330 |
swingManager.translate(this.lblMaxValue); |
|
331 |
swingManager.translate(this.lblAvailableValues); |
|
332 |
swingManager.translate(this.lblAvailableValuesLabel); |
|
333 |
swingManager.translate(this.lblAvailableValuesValue); |
|
334 |
swingManager.translate(this.btnAvailableValuesAdd); |
|
335 |
swingManager.translate(this.btnAvailableValuesUpdate); |
|
336 |
swingManager.translate(this.btnAvailableValuesRemove); |
|
337 |
|
|
176 | 338 |
|
177 | 339 |
swingManager.addClearButton(this.txtDefaultValue); |
178 | 340 |
swingManager.addClearButton(this.txtFieldName); |
... | ... | |
180 | 342 |
swingManager.addClearButton(this.txtIntervalStart); |
181 | 343 |
swingManager.addClearButton(this.txtPrecision); |
182 | 344 |
swingManager.addClearButton(this.txtSize); |
183 |
|
|
345 |
swingManager.addClearButton(this.txtLabel); |
|
346 |
swingManager.addClearButton(this.txtDescription); |
|
347 |
swingManager.addClearButton(this.cboGroup); |
|
348 |
swingManager.addClearButton(this.txtMaxValue); |
|
349 |
swingManager.addClearButton(this.txtMinValue); |
|
350 |
swingManager.addClearButton(this.txtAvailableValuesLabel); |
|
351 |
swingManager.addClearButton(this.txtAvailableValuesValue); |
|
352 |
|
|
353 |
|
|
184 | 354 |
swingManager.setDefaultPopupMenu(this.txtDefaultValue); |
185 | 355 |
swingManager.setDefaultPopupMenu(this.txtFieldName); |
186 | 356 |
swingManager.setDefaultPopupMenu(this.txtIntervalEnd); |
... | ... | |
193 | 363 |
swingManager.setDefaultPopupMenu(this.cboGeometryType); |
194 | 364 |
swingManager.setDefaultPopupMenu(this.cboDataProfile); |
195 | 365 |
|
366 |
swingManager.setDefaultPopupMenu(this.cboGroup); |
|
367 |
swingManager.setDefaultPopupMenu(this.txtOrder); |
|
368 |
swingManager.setDefaultPopupMenu(this.txtLabel); |
|
369 |
swingManager.setDefaultPopupMenu(this.txtDescription); |
|
370 |
swingManager.setDefaultPopupMenu(this.txtMinValue); |
|
371 |
swingManager.setDefaultPopupMenu(this.txtMaxValue); |
|
372 |
swingManager.setDefaultPopupMenu(this.txtAvailableValuesLabel); |
|
373 |
swingManager.setDefaultPopupMenu(this.txtAvailableValuesValue); |
|
374 |
|
|
196 | 375 |
this.pickerIntervalEnd = swingManager.createDatePickerController( |
197 | 376 |
this.txtIntervalEnd, |
198 | 377 |
this.btnIntervalEnd |
... | ... | |
210 | 389 |
this.pickerDefaultValue = evaluatorManager.createCalculatorController( |
211 | 390 |
this.txtDefaultValue, DataTypes.OBJECT |
212 | 391 |
); |
392 |
this.pickerOrder = evaluatorManager.createCalculatorController( |
|
393 |
this.txtOrder, DataTypes.INT |
|
394 |
); |
|
213 | 395 |
|
214 |
|
|
396 |
this.availableValuesController = new AvailableValuesController( |
|
397 |
cboAvailableValues, |
|
398 |
txtAvailableValuesLabel, |
|
399 |
txtAvailableValuesValue, |
|
400 |
btnAvailableValuesAdd, |
|
401 |
btnAvailableValuesUpdate, |
|
402 |
btnAvailableValuesRemove |
|
403 |
); |
|
404 |
this.txtMinValue.setEnabled(false); |
|
405 |
this.txtMaxValue.setEnabled(false); |
|
406 |
|
|
215 | 407 |
this.btnVirtualField.setText(""); |
216 | 408 |
this.pickerVirtualField = ExpressionEvaluatorSwingLocator.getManager() |
217 | 409 |
.createExpressionPickerController(txtVirtualField, btnVirtualField); |
... | ... | |
384 | 576 |
); |
385 | 577 |
return null; |
386 | 578 |
} |
579 |
|
|
580 |
descriptor.setGroup(StringUtils.defaultIfBlank((String) this.cboGroup.getSelectedItem(), null)); |
|
581 |
descriptor.setOrder(this.pickerOrder.get(0)); |
|
582 |
descriptor.setHidden(this.chkHidden.isSelected()); |
|
583 |
descriptor.setLabel(StringUtils.defaultIfBlank(this.txtLabel.getText(), null)); |
|
584 |
descriptor.setDescription(StringUtils.defaultIfBlank(this.txtDescription.getText(), null)); |
|
585 |
|
|
586 |
// this.txtMinValue.setText(Objects.toString(descriptor.getMinValue(), "")); |
|
587 |
// this.txtMinValue.setText(Objects.toString(descriptor.getMaxValue(), "")); |
|
588 |
|
|
589 |
descriptor.setAvailableValues(this.availableValuesController.get()); |
|
590 |
|
|
591 |
|
|
387 | 592 |
return descriptor; |
388 | 593 |
} |
389 | 594 |
|
595 |
@Override |
|
390 | 596 |
public void clean() { |
391 | 597 |
this.pickerDefaultValue.set(null); |
392 | 598 |
this.txtFieldName.setText(""); |
... | ... | |
411 | 617 |
ListElement.setSelected(cboFieldType, DataTypes.STRING); |
412 | 618 |
|
413 | 619 |
this.cboDataProfile.setSelectedIndex(-1); |
620 |
|
|
621 |
this.cboGroup.setSelectedIndex(-1); |
|
622 |
this.pickerOrder.set(null); |
|
623 |
this.chkHidden.setSelected(false); |
|
624 |
this.txtLabel.setText(""); |
|
625 |
this.txtDescription.setText(""); |
|
626 |
this.txtMinValue.setText(""); |
|
627 |
this.txtMaxValue.setText(""); |
|
628 |
this.availableValuesController.clean(); |
|
629 |
|
|
414 | 630 |
} |
415 | 631 |
|
416 | 632 |
@Override |
... | ... | |
419 | 635 |
this.clean(); |
420 | 636 |
return; |
421 | 637 |
} |
422 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
|
423 |
if( descriptor.getFeatureType()!=null ) { |
|
638 |
FeatureType featureType = descriptor.getFeatureType(); |
|
639 |
DefaultComboBoxModel groupModel = new DefaultComboBoxModel(); |
|
640 |
|
|
641 |
if( featureType!=null ) { |
|
424 | 642 |
FeatureStore store = descriptor.getFeatureType().getStore(); |
425 | 643 |
this.featureStoreElement.setFeatureStore(store); |
426 | 644 |
if( store != null ) { |
... | ... | |
438 | 656 |
this.pickerVirtualField.setPreviewSymbolTable(featureSymbolTable.createParent()); |
439 | 657 |
} |
440 | 658 |
} |
659 |
List<String> groups = new ArrayList<>(); |
|
660 |
for (FeatureAttributeDescriptor otherdesc : featureType) { |
|
661 |
String group = otherdesc.getGroup(); |
|
662 |
if( !StringUtils.isBlank(group) && !groups.contains(group) ) { |
|
663 |
groups.add(group); |
|
664 |
} |
|
665 |
} |
|
666 |
for (String group : groups) { |
|
667 |
groupModel.addElement(group); |
|
668 |
} |
|
441 | 669 |
} |
442 | 670 |
if (!(descriptor instanceof EditableFeatureAttributeDescriptor)) { |
443 | 671 |
this.setEditable(false); |
... | ... | |
493 | 721 |
} else { |
494 | 722 |
this.cboDataProfile.setSelectedItem(profile); |
495 | 723 |
} |
724 |
|
|
725 |
this.cboGroup.setModel(groupModel); |
|
726 |
this.cboGroup.setSelectedItem(StringUtils.defaultIfBlank(descriptor.getGroup(),"")); |
|
727 |
this.pickerOrder.set(descriptor.getOder()); |
|
728 |
this.chkHidden.setSelected(descriptor.isHidden()); |
|
729 |
this.txtLabel.setText(StringUtils.defaultIfBlank(descriptor.getLabel(),"")); |
|
730 |
this.txtDescription.setText(StringUtils.defaultIfBlank(descriptor.getDescription(),"")); |
|
731 |
this.txtMinValue.setText(Objects.toString(descriptor.getMinValue(), "")); |
|
732 |
this.txtMinValue.setText(Objects.toString(descriptor.getMaxValue(), "")); |
|
733 |
this.availableValuesController.set(descriptor.getAvailableValues()); |
|
734 |
|
|
735 |
|
|
496 | 736 |
} |
497 | 737 |
|
498 | 738 |
private void doFieldTypeChanged() { |
... | ... | |
604 | 844 |
|
605 | 845 |
} |
606 | 846 |
|
847 |
@Override |
|
607 | 848 |
public void setEditable(boolean editable) { |
608 | 849 |
this.editable = editable; |
609 | 850 |
this.pickerDefaultValue.setEditable(editable); |
... | ... | |
628 | 869 |
this.cboGeometrySubtype.setEnabled(editable); |
629 | 870 |
this.pickerCRS.setEditable(editable); |
630 | 871 |
|
872 |
this.cboGroup.setEnabled(editable); |
|
873 |
this.pickerOrder.setEditable(editable); |
|
874 |
this.chkHidden.setEnabled(editable); |
|
875 |
this.txtLabel.setEditable(editable); |
|
876 |
this.txtDescription.setEditable(editable); |
|
877 |
this.txtMinValue.setEditable(false); |
|
878 |
this.txtMaxValue.setEditable(false); |
|
879 |
this.availableValuesController.setEditable(editable); |
|
631 | 880 |
} |
632 | 881 |
|
633 | 882 |
private int getMaxSizeOfType(int dataType) { |
Also available in: Unified diff