svn-gvsig-desktop / 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 @ 44338
History | View | Annotate | Download (50.7 KB)
1 | 44077 | jjdelcerro | package org.gvsig.fmap.dal.swing.impl.featuretype; |
---|---|---|---|
2 | |||
3 | 44202 | jjdelcerro | import java.awt.event.ActionEvent; |
4 | import java.awt.event.ActionListener; |
||
5 | 44096 | jjdelcerro | import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
6 | 44085 | jjdelcerro | import java.awt.event.ItemEvent; |
7 | import java.awt.event.ItemListener; |
||
8 | 44077 | jjdelcerro | import java.util.ArrayList; |
9 | import java.util.Comparator; |
||
10 | import java.util.List; |
||
11 | 44202 | jjdelcerro | import java.util.Objects; |
12 | import javax.swing.ComboBoxModel; |
||
13 | 44077 | jjdelcerro | import javax.swing.DefaultComboBoxModel; |
14 | 44202 | jjdelcerro | import javax.swing.JButton; |
15 | 44262 | jjdelcerro | import javax.swing.JCheckBox; |
16 | 44202 | jjdelcerro | import javax.swing.JComboBox; |
17 | 44077 | jjdelcerro | import javax.swing.JComponent; |
18 | 44085 | jjdelcerro | import javax.swing.JOptionPane; |
19 | 44262 | jjdelcerro | import javax.swing.JTextField; |
20 | 44085 | jjdelcerro | import javax.swing.SwingUtilities; |
21 | import javax.swing.event.ChangeEvent; |
||
22 | import javax.swing.event.ChangeListener; |
||
23 | 44202 | jjdelcerro | import javax.swing.text.JTextComponent; |
24 | 44128 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
25 | 44077 | jjdelcerro | import org.cresques.cts.IProjection; |
26 | import org.gvsig.expressionevaluator.Expression; |
||
27 | 44262 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionUtils; |
28 | 44077 | jjdelcerro | import org.gvsig.expressionevaluator.swing.CalculatorController; |
29 | import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
||
30 | import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
||
31 | import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
||
32 | 44085 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
33 | import org.gvsig.fmap.dal.DataManager; |
||
34 | 44262 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
35 | 44077 | jjdelcerro | import org.gvsig.fmap.dal.DataTypes; |
36 | 44262 | jjdelcerro | import org.gvsig.fmap.dal.StoresRepository; |
37 | import org.gvsig.fmap.dal.complements.Search; |
||
38 | 44100 | jjdelcerro | import org.gvsig.fmap.dal.exception.DataException; |
39 | 44077 | jjdelcerro | import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
40 | 44100 | jjdelcerro | import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
41 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.feature.DataProfile; |
42 | 44077 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
43 | 44262 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableForeingKey; |
44 | 44100 | jjdelcerro | import org.gvsig.fmap.dal.feature.Feature; |
45 | 44077 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
46 | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
||
47 | 44100 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
48 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
49 | 44262 | jjdelcerro | import org.gvsig.fmap.dal.feature.ForeingKey; |
50 | 44077 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALSwingLocator; |
51 | 44085 | jjdelcerro | import org.gvsig.fmap.dal.swing.DataSwingManager; |
52 | 44149 | jjdelcerro | import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
53 | 44077 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
54 | 44085 | jjdelcerro | import org.gvsig.fmap.geom.GeometryLocator; |
55 | import org.gvsig.fmap.geom.GeometryManager; |
||
56 | import org.gvsig.fmap.geom.type.GeometryType; |
||
57 | 44077 | jjdelcerro | import org.gvsig.timesupport.RelativeInterval; |
58 | import org.gvsig.tools.ToolsLocator; |
||
59 | import org.gvsig.tools.dataTypes.DataTypesManager; |
||
60 | 44202 | jjdelcerro | import org.gvsig.tools.dynobject.DynObjectValueItem; |
61 | 44152 | jjdelcerro | import org.gvsig.tools.i18n.I18nManager; |
62 | 44077 | jjdelcerro | import org.gvsig.tools.swing.api.ListElement; |
63 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
64 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
65 | import org.gvsig.tools.swing.api.pickercontroller.DatePickerController; |
||
66 | import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
||
67 | 44085 | jjdelcerro | import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
68 | 44128 | jjdelcerro | import org.slf4j.Logger; |
69 | import org.slf4j.LoggerFactory; |
||
70 | 44077 | jjdelcerro | |
71 | /**
|
||
72 | *
|
||
73 | * @author jjdelcerro
|
||
74 | */
|
||
75 | 44085 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
76 | public class DefaultFeatureTypeAttributePanel |
||
77 | extends FeatureTypeAttributePanelView
|
||
78 | implements FeatureTypeAttributePanel {
|
||
79 | 44077 | jjdelcerro | |
80 | 44128 | jjdelcerro | private static final Logger LOGGER = LoggerFactory.getLogger(DefaultFeatureTypeAttributePanel.class); |
81 | 44202 | jjdelcerro | |
82 | 44262 | jjdelcerro | private static class ForeingKeyController { |
83 | |||
84 | private final JCheckBox chkIsForeingKey; |
||
85 | 44338 | jjdelcerro | private final JCheckBox chkIsClosedList; |
86 | 44262 | jjdelcerro | private final JComboBox cboTable; |
87 | private final JComboBox cboCode; |
||
88 | private final JTextField txtFormula; |
||
89 | private final JButton btnFormula; |
||
90 | private ExpressionPickerController pickerFormula;
|
||
91 | private boolean editable; |
||
92 | private FeatureStoreElement featureStoreElement;
|
||
93 | |||
94 | public ForeingKeyController(
|
||
95 | JCheckBox chkIsForeingKey,
|
||
96 | 44338 | jjdelcerro | JCheckBox chkIsClosedList,
|
97 | 44262 | jjdelcerro | JComboBox cboTable,
|
98 | JComboBox cboCode,
|
||
99 | JTextField txtFormula,
|
||
100 | JButton btnFormula
|
||
101 | ) { |
||
102 | this.chkIsForeingKey = chkIsForeingKey;
|
||
103 | 44338 | jjdelcerro | this.chkIsClosedList = chkIsClosedList;
|
104 | 44262 | jjdelcerro | this.cboTable = cboTable;
|
105 | this.cboCode = cboCode;
|
||
106 | this.txtFormula = txtFormula;
|
||
107 | this.btnFormula = btnFormula;
|
||
108 | this.initComponents();
|
||
109 | } |
||
110 | |||
111 | private void initComponents() { |
||
112 | DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager(); |
||
113 | |||
114 | this.editable = true; |
||
115 | |||
116 | DefaultComboBoxModel<String> model = new DefaultComboBoxModel(); |
||
117 | StoresRepository repository = DALLocator.getDataManager().getStoresRepository(); |
||
118 | for (String tableName : repository.keySet()) { |
||
119 | model.addElement(tableName); |
||
120 | } |
||
121 | this.cboTable.setModel(model);
|
||
122 | this.cboTable.addItemListener(new ItemListener() { |
||
123 | @Override
|
||
124 | public void itemStateChanged(ItemEvent e) { |
||
125 | if (e.getStateChange() != ItemEvent.SELECTED) { |
||
126 | return;
|
||
127 | } |
||
128 | Thread th = new Thread(new Runnable() { |
||
129 | @Override
|
||
130 | public void run() { |
||
131 | doPopulateComboCode(); |
||
132 | } |
||
133 | }, "FeatureTypePanelForeingKeyPopulateComboCode");
|
||
134 | th.start(); |
||
135 | } |
||
136 | }); |
||
137 | this.btnFormula.setText(""); |
||
138 | this.featureStoreElement = dataSwingManager.createFeatureStoreElement();
|
||
139 | this.pickerFormula = ExpressionEvaluatorSwingLocator.getManager()
|
||
140 | .createExpressionPickerController(txtFormula, btnFormula); |
||
141 | this.pickerFormula.addElement(this.featureStoreElement); |
||
142 | |||
143 | // this.chkIsForeingKey.addChangeListener(new ChangeListener() {
|
||
144 | // @Override
|
||
145 | // public void stateChanged(ChangeEvent e) {
|
||
146 | // if (chkIsForeingKey.isSelected()) {
|
||
147 | // setEnabled(editable);
|
||
148 | // } else {
|
||
149 | // setEnabled(false);
|
||
150 | // }
|
||
151 | // }
|
||
152 | // });
|
||
153 | } |
||
154 | |||
155 | private void doPopulateComboCode() { |
||
156 | String tableName = (String) this.cboTable.getSelectedItem(); |
||
157 | if( StringUtils.isBlank(tableName) ) {
|
||
158 | return;
|
||
159 | } |
||
160 | StoresRepository repository = DALLocator.getDataManager().getStoresRepository(); |
||
161 | 44304 | jjdelcerro | DataStore store = repository.getStore(tableName); |
162 | 44262 | jjdelcerro | if( !(store instanceof FeatureStore) ) { |
163 | return;
|
||
164 | } |
||
165 | this.featureStoreElement.setFeatureStore((FeatureStore) store);
|
||
166 | FeatureType featureType; |
||
167 | try {
|
||
168 | featureType = ((FeatureStore)store).getDefaultFeatureType(); |
||
169 | } catch (DataException ex) {
|
||
170 | return;
|
||
171 | } |
||
172 | Search search = (Search) ToolsLocator.getComplementsManager().get( |
||
173 | Search.COMPLEMENT_MANE, featureType |
||
174 | ); |
||
175 | 44337 | jjdelcerro | List<Search.OrderedAttribute> attributes = search.getOrderedAttributes(
|
176 | 44262 | jjdelcerro | Search.BASIC_TYPES_FILTER, |
177 | Search.LABEL_ORDER, |
||
178 | -1
|
||
179 | ); |
||
180 | final DefaultComboBoxModel model = new DefaultComboBoxModel(); |
||
181 | 44337 | jjdelcerro | for (Search.OrderedAttribute attribute : attributes) {
|
182 | model.addElement(attribute.getDescriptor().getName()); |
||
183 | 44262 | jjdelcerro | } |
184 | SwingUtilities.invokeLater(new Runnable() { |
||
185 | @Override
|
||
186 | public void run() { |
||
187 | cboCode.setModel(model); |
||
188 | } |
||
189 | }); |
||
190 | } |
||
191 | |||
192 | public void setEditable(boolean editable) { |
||
193 | this.chkIsForeingKey.setEnabled(editable);
|
||
194 | 44338 | jjdelcerro | this.chkIsClosedList.setEnabled(editable);
|
195 | 44262 | jjdelcerro | this.cboTable.setEnabled(editable);
|
196 | this.cboCode.setEnabled(editable);
|
||
197 | this.btnFormula.setEnabled(editable);
|
||
198 | this.txtFormula.setEditable(editable);
|
||
199 | this.editable = editable;
|
||
200 | } |
||
201 | |||
202 | public void setEnabled(boolean enabled) { |
||
203 | if( !editable ) {
|
||
204 | enabled = false;
|
||
205 | } |
||
206 | this.chkIsForeingKey.setEnabled(enabled);
|
||
207 | 44338 | jjdelcerro | this.chkIsClosedList.setEnabled(enabled);
|
208 | 44262 | jjdelcerro | this.cboTable.setEnabled(enabled);
|
209 | this.cboCode.setEnabled(enabled);
|
||
210 | this.btnFormula.setEnabled(enabled);
|
||
211 | this.txtFormula.setEnabled(enabled);
|
||
212 | } |
||
213 | |||
214 | public void clean() { |
||
215 | this.chkIsForeingKey.setSelected(false); |
||
216 | 44338 | jjdelcerro | this.chkIsClosedList.setSelected(false); |
217 | 44262 | jjdelcerro | this.cboTable.setSelectedItem(""); |
218 | this.cboCode.setSelectedItem(""); |
||
219 | this.pickerFormula.set(null); |
||
220 | } |
||
221 | |||
222 | public void put(ForeingKey foreingKey) { |
||
223 | if( foreingKey==null ) { |
||
224 | this.clean();
|
||
225 | return;
|
||
226 | } |
||
227 | this.chkIsForeingKey.setSelected(foreingKey.isForeingKey());
|
||
228 | 44338 | jjdelcerro | this.chkIsClosedList.setSelected(foreingKey.isClosedList());
|
229 | 44262 | jjdelcerro | this.cboTable.setSelectedItem(foreingKey.getTableName());
|
230 | this.cboCode.setSelectedItem(foreingKey.getCodeName());
|
||
231 | this.pickerFormula.set(foreingKey.getLabelExpression(null)); |
||
232 | } |
||
233 | |||
234 | public void fetch(EditableForeingKey foreingKey) { |
||
235 | if( foreingKey==null ) { |
||
236 | return;
|
||
237 | } |
||
238 | foreingKey.setForeingKey(this.chkIsForeingKey.isSelected());
|
||
239 | 44338 | jjdelcerro | foreingKey.setClosedList(this.chkIsClosedList.isSelected());
|
240 | 44262 | jjdelcerro | foreingKey.setTableName((String) this.cboTable.getSelectedItem()); |
241 | foreingKey.setCodeName((String) this.cboCode.getSelectedItem()); |
||
242 | Expression exp = this.pickerFormula.get(); |
||
243 | if( ExpressionUtils.isPhraseEmpty(exp) ) {
|
||
244 | foreingKey.setLabelFormula("");
|
||
245 | } else {
|
||
246 | foreingKey.setLabelFormula(exp.getPhrase()); |
||
247 | } |
||
248 | } |
||
249 | } |
||
250 | |||
251 | |||
252 | 44202 | jjdelcerro | private static class AvailableValuesController { |
253 | 44262 | jjdelcerro | |
254 | 44202 | jjdelcerro | private final JComboBox cboValues; |
255 | private final JTextComponent txtLabel; |
||
256 | private final JTextComponent txtValue; |
||
257 | private final JButton btnAdd; |
||
258 | private final JButton btnUpdate; |
||
259 | private final JButton btnRemove; |
||
260 | 44262 | jjdelcerro | |
261 | public AvailableValuesController(
|
||
262 | 44202 | jjdelcerro | JComboBox cblValues,
|
263 | JTextComponent txtLabel,
|
||
264 | JTextComponent txtValue,
|
||
265 | JButton btnAdd,
|
||
266 | JButton btnUpdate,
|
||
267 | JButton btnRemove
|
||
268 | 44262 | jjdelcerro | ) { |
269 | 44202 | jjdelcerro | this.cboValues = cblValues;
|
270 | this.txtLabel = txtLabel;
|
||
271 | this.txtValue = txtValue;
|
||
272 | this.btnAdd = btnAdd;
|
||
273 | this.btnUpdate = btnUpdate;
|
||
274 | this.btnRemove = btnRemove;
|
||
275 | 44262 | jjdelcerro | |
276 | 44202 | jjdelcerro | this.cboValues.addItemListener(new ItemListener() { |
277 | @Override
|
||
278 | public void itemStateChanged(ItemEvent e) { |
||
279 | doValuesChanged(); |
||
280 | } |
||
281 | }); |
||
282 | this.btnAdd.addActionListener(new ActionListener() { |
||
283 | @Override
|
||
284 | public void actionPerformed(ActionEvent e) { |
||
285 | doAdd(); |
||
286 | } |
||
287 | }); |
||
288 | this.btnUpdate.addActionListener(new ActionListener() { |
||
289 | @Override
|
||
290 | public void actionPerformed(ActionEvent e) { |
||
291 | doUpdate(); |
||
292 | } |
||
293 | }); |
||
294 | this.btnRemove.addActionListener(new ActionListener() { |
||
295 | @Override
|
||
296 | public void actionPerformed(ActionEvent e) { |
||
297 | doRemove(); |
||
298 | } |
||
299 | }); |
||
300 | } |
||
301 | |||
302 | public void clean() { |
||
303 | this.cboValues.setModel(new DefaultComboBoxModel()); |
||
304 | this.txtLabel.setText(""); |
||
305 | this.txtValue.setText(""); |
||
306 | this.cboValues.setSelectedIndex(-1); |
||
307 | } |
||
308 | |||
309 | public DynObjectValueItem[] get() { |
||
310 | ComboBoxModel<DynObjectValueItem> model = this.cboValues.getModel(); |
||
311 | DynObjectValueItem[] values = new DynObjectValueItem[model.getSize()]; |
||
312 | for (int i = 0; i < model.getSize(); i++) { |
||
313 | values[i] = model.getElementAt(i); |
||
314 | } |
||
315 | 44262 | jjdelcerro | return values;
|
316 | 44202 | jjdelcerro | } |
317 | |||
318 | public void set(DynObjectValueItem[] availableValues) { |
||
319 | DefaultComboBoxModel model = new DefaultComboBoxModel(); |
||
320 | 44262 | jjdelcerro | if (availableValues != null) { |
321 | 44202 | jjdelcerro | for (DynObjectValueItem availableValue : availableValues) {
|
322 | model.addElement(availableValue); |
||
323 | } |
||
324 | } |
||
325 | this.cboValues.setModel(model);
|
||
326 | 44262 | jjdelcerro | if (model.getSize() > 0) { |
327 | 44202 | jjdelcerro | this.cboValues.setSelectedIndex(0); |
328 | } else {
|
||
329 | this.cboValues.setSelectedIndex(-1); |
||
330 | } |
||
331 | } |
||
332 | 44262 | jjdelcerro | |
333 | 44202 | jjdelcerro | public void setEditable(boolean editable) { |
334 | this.cboValues.setEnabled(editable);
|
||
335 | this.txtLabel.setEditable(editable);
|
||
336 | this.txtValue.setEditable(editable);
|
||
337 | this.btnAdd.setEnabled(editable);
|
||
338 | this.btnUpdate.setEnabled(editable);
|
||
339 | this.btnRemove.setEnabled(editable);
|
||
340 | } |
||
341 | |||
342 | private void doValuesChanged() { |
||
343 | DynObjectValueItem value = (DynObjectValueItem) this.cboValues.getSelectedItem();
|
||
344 | 44262 | jjdelcerro | if (value == null) { |
345 | 44202 | jjdelcerro | this.txtLabel.setText(""); |
346 | this.txtValue.setText(""); |
||
347 | this.btnAdd.setEnabled(true); |
||
348 | this.btnUpdate.setEnabled(false); |
||
349 | this.btnRemove.setEnabled(false); |
||
350 | return;
|
||
351 | } |
||
352 | this.txtLabel.setText(value.getLabel());
|
||
353 | 44262 | jjdelcerro | this.txtValue.setText(Objects.toString(value.getValue(), "")); |
354 | 44202 | jjdelcerro | this.btnAdd.setEnabled(true); |
355 | this.btnUpdate.setEnabled(true); |
||
356 | this.btnRemove.setEnabled(true); |
||
357 | } |
||
358 | 44262 | jjdelcerro | |
359 | 44202 | jjdelcerro | private void doAdd() { |
360 | DynObjectValueItem value = new DynObjectValueItem("Value", "Label"); |
||
361 | DefaultComboBoxModel model = (DefaultComboBoxModel) this.cboValues.getModel(); |
||
362 | model.addElement(value); |
||
363 | 44262 | jjdelcerro | this.cboValues.setSelectedIndex(model.getSize() - 1); |
364 | 44202 | jjdelcerro | } |
365 | 44262 | jjdelcerro | |
366 | 44202 | jjdelcerro | private void doUpdate() { |
367 | DynObjectValueItem value = (DynObjectValueItem) this.cboValues.getSelectedItem();
|
||
368 | 44262 | jjdelcerro | if (value == null) { |
369 | 44202 | jjdelcerro | return; // EEhh?? esto no deberia pasar |
370 | } |
||
371 | value.setLabel(this.txtLabel.getText());
|
||
372 | value.setValue(this.txtValue.getText());
|
||
373 | } |
||
374 | 44262 | jjdelcerro | |
375 | 44202 | jjdelcerro | private void doRemove() { |
376 | int n = this.cboValues.getSelectedIndex(); |
||
377 | 44262 | jjdelcerro | if (n < 0) { |
378 | 44202 | jjdelcerro | return; // EEhh?? esto no deberia pasar |
379 | } |
||
380 | DefaultComboBoxModel model = (DefaultComboBoxModel) this.cboValues.getModel(); |
||
381 | model.removeElementAt(n); |
||
382 | 44262 | jjdelcerro | if (--n < 0) { |
383 | 44202 | jjdelcerro | n = 0;
|
384 | } |
||
385 | this.cboValues.setSelectedIndex(n);
|
||
386 | } |
||
387 | |||
388 | } |
||
389 | |||
390 | 44077 | jjdelcerro | private final List<ListElement<Integer>> fieldTypes; |
391 | private final List<ListElement<Integer>> geometryTypes; |
||
392 | private final List<ListElement<Integer>> geometrySubtypes; |
||
393 | 44085 | jjdelcerro | |
394 | 44077 | jjdelcerro | private DatePickerController pickerIntervalEnd;
|
395 | private DatePickerController pickerIntervalStart;
|
||
396 | private CalculatorController<Integer> pickerSize; |
||
397 | private CalculatorController<Integer> pickerPrecision; |
||
398 | private CalculatorController<Object> pickerDefaultValue; |
||
399 | private PickerController<IProjection> pickerCRS;
|
||
400 | private ExpressionPickerController pickerVirtualField;
|
||
401 | 44202 | jjdelcerro | private CalculatorController<Integer> pickerOrder; |
402 | private AvailableValuesController availableValuesController;
|
||
403 | 44253 | jjdelcerro | private TagsController tagsController;
|
404 | 44262 | jjdelcerro | private ForeingKeyController foreingKeyController;
|
405 | 44077 | jjdelcerro | |
406 | 44085 | jjdelcerro | private boolean editable; |
407 | 44149 | jjdelcerro | private FeatureStoreElement featureStoreElement;
|
408 | 44077 | jjdelcerro | |
409 | public DefaultFeatureTypeAttributePanel() {
|
||
410 | 44085 | jjdelcerro | this.editable = true; |
411 | 44077 | jjdelcerro | DataTypesManager dataManager = ToolsLocator.getDataTypesManager(); |
412 | this.fieldTypes = new ArrayList<>(); |
||
413 | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.BOOLEAN), DataTypes.BOOLEAN)); |
||
414 | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.DATE), DataTypes.DATE)); |
||
415 | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.TIME), DataTypes.TIME)); |
||
416 | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.TIMESTAMP), DataTypes.TIMESTAMP)); |
||
417 | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.INT), DataTypes.INT)); |
||
418 | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.DOUBLE), DataTypes.DOUBLE)); |
||
419 | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.LONG), DataTypes.LONG)); |
||
420 | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.INTERVAL), DataTypes.INTERVAL)); |
||
421 | 44085 | jjdelcerro | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.INSTANT), DataTypes.INSTANT)); |
422 | 44077 | jjdelcerro | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.STRING), DataTypes.STRING)); |
423 | 44085 | jjdelcerro | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.GEOMETRY), DataTypes.GEOMETRY)); |
424 | 44187 | jjdelcerro | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.BYTEARRAY), DataTypes.BYTEARRAY)); |
425 | 44262 | jjdelcerro | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.OBJECT), DataTypes.OBJECT)); |
426 | this.fieldTypes.add(new ListElement<>(dataManager.getTypeName(DataTypes.LIST), DataTypes.LIST)); |
||
427 | 44077 | jjdelcerro | this.fieldTypes.sort(new Comparator<ListElement<Integer>>() { |
428 | @Override
|
||
429 | public int compare(ListElement<Integer> o1, ListElement<Integer> o2) { |
||
430 | return o1.toString().compareTo(o2.toString());
|
||
431 | } |
||
432 | }); |
||
433 | |||
434 | this.geometryTypes = new ArrayList<>(); |
||
435 | this.geometryTypes.add(new ListElement("Point", Geometry.TYPES.POINT)); |
||
436 | this.geometryTypes.add(new ListElement("Line", Geometry.TYPES.LINE)); |
||
437 | this.geometryTypes.add(new ListElement("Polygon", Geometry.TYPES.POLYGON)); |
||
438 | this.geometryTypes.add(new ListElement("MultiPoint", Geometry.TYPES.MULTIPOINT)); |
||
439 | this.geometryTypes.add(new ListElement("MultiLine", Geometry.TYPES.MULTILINE)); |
||
440 | this.geometryTypes.add(new ListElement("MultiPolygon", Geometry.TYPES.MULTIPOLYGON)); |
||
441 | this.geometryTypes.sort(new Comparator<ListElement<Integer>>() { |
||
442 | @Override
|
||
443 | public int compare(ListElement<Integer> o1, ListElement<Integer> o2) { |
||
444 | return o1.toString().compareTo(o2.toString());
|
||
445 | } |
||
446 | }); |
||
447 | 44085 | jjdelcerro | |
448 | 44077 | jjdelcerro | this.geometrySubtypes = new ArrayList<>(); |
449 | this.geometrySubtypes.add(new ListElement("2D", Geometry.SUBTYPES.GEOM2D)); |
||
450 | this.geometrySubtypes.add(new ListElement("2DM", Geometry.SUBTYPES.GEOM3D)); |
||
451 | this.geometrySubtypes.add(new ListElement("3D", Geometry.SUBTYPES.GEOM2DM)); |
||
452 | this.geometrySubtypes.add(new ListElement("3DM", Geometry.SUBTYPES.GEOM3DM)); |
||
453 | this.geometrySubtypes.sort(new Comparator<ListElement<Integer>>() { |
||
454 | @Override
|
||
455 | public int compare(ListElement<Integer> o1, ListElement<Integer> o2) { |
||
456 | return o1.toString().compareTo(o2.toString());
|
||
457 | } |
||
458 | }); |
||
459 | 44085 | jjdelcerro | |
460 | 44077 | jjdelcerro | this.initComponents();
|
461 | } |
||
462 | 44085 | jjdelcerro | |
463 | 44077 | jjdelcerro | private void initComponents() { |
464 | ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
||
465 | ExpressionEvaluatorSwingManager evaluatorManager = ExpressionEvaluatorSwingLocator.getManager(); |
||
466 | 44149 | jjdelcerro | DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager(); |
467 | 44262 | jjdelcerro | |
468 | 44077 | jjdelcerro | DefaultComboBoxModel<ListElement<Integer>> modelTypes = new DefaultComboBoxModel<>(); |
469 | for (ListElement<Integer> element : fieldTypes) { |
||
470 | modelTypes.addElement(element); |
||
471 | } |
||
472 | this.cboFieldType.setModel(modelTypes);
|
||
473 | |||
474 | DefaultComboBoxModel<ListElement<Integer>> modelGeomTypes = new DefaultComboBoxModel<>(); |
||
475 | for (ListElement<Integer> element : this.geometryTypes) { |
||
476 | modelGeomTypes.addElement(element); |
||
477 | } |
||
478 | this.cboGeometryType.setModel(modelGeomTypes);
|
||
479 | |||
480 | DefaultComboBoxModel<ListElement<Integer>> modelGeomSubtypes = new DefaultComboBoxModel<>(); |
||
481 | for (ListElement<Integer> element : this.geometrySubtypes) { |
||
482 | modelGeomSubtypes.addElement(element); |
||
483 | } |
||
484 | 44085 | jjdelcerro | |
485 | this.cboGeometrySubtype.setModel(modelGeomSubtypes);
|
||
486 | |||
487 | 44128 | jjdelcerro | swingManager.translate(this.lblAllowNulls);
|
488 | swingManager.translate(this.lblCRS);
|
||
489 | swingManager.translate(this.lblDataProfile);
|
||
490 | swingManager.translate(this.lblDateFormat);
|
||
491 | swingManager.translate(this.lblDefaultValue);
|
||
492 | swingManager.translate(this.lblFieldName);
|
||
493 | swingManager.translate(this.lblFieldType);
|
||
494 | swingManager.translate(this.lblGeometrySubtype);
|
||
495 | swingManager.translate(this.lblGeometryType);
|
||
496 | swingManager.translate(this.lblInterval);
|
||
497 | swingManager.translate(this.lblIntervalEnd);
|
||
498 | swingManager.translate(this.lblIntervalStart);
|
||
499 | swingManager.translate(this.lblIsAutomatic);
|
||
500 | swingManager.translate(this.lblIsPrimaryKey);
|
||
501 | swingManager.translate(this.lblPrecision);
|
||
502 | swingManager.translate(this.lblSize);
|
||
503 | swingManager.translate(this.chkVirtualField);
|
||
504 | swingManager.translate(this.tabAditionalFields);
|
||
505 | 44202 | jjdelcerro | swingManager.translate(this.tabLayout);
|
506 | swingManager.translate(this.lblGroup);
|
||
507 | swingManager.translate(this.lblOrder);
|
||
508 | swingManager.translate(this.lblHidden);
|
||
509 | swingManager.translate(this.lblLabel);
|
||
510 | swingManager.translate(this.lblDescription);
|
||
511 | swingManager.translate(this.lblMinValue);
|
||
512 | swingManager.translate(this.lblMaxValue);
|
||
513 | swingManager.translate(this.lblAvailableValues);
|
||
514 | swingManager.translate(this.lblAvailableValuesLabel);
|
||
515 | swingManager.translate(this.lblAvailableValuesValue);
|
||
516 | swingManager.translate(this.btnAvailableValuesAdd);
|
||
517 | swingManager.translate(this.btnAvailableValuesUpdate);
|
||
518 | swingManager.translate(this.btnAvailableValuesRemove);
|
||
519 | 44253 | jjdelcerro | swingManager.translate(this.lblTagsName);
|
520 | swingManager.translate(this.lblTagsValue);
|
||
521 | |||
522 | 44262 | jjdelcerro | swingManager.translate(this.lblForeingKeyCodeName);
|
523 | swingManager.translate(this.lblForeingKeyLabelFormula);
|
||
524 | swingManager.translate(this.lblForeingKeyTableName);
|
||
525 | 44338 | jjdelcerro | swingManager.translate(this.lblIsClosedList);
|
526 | 44262 | jjdelcerro | swingManager.translate(this.chkIsForeingKey);
|
527 | |||
528 | 44077 | jjdelcerro | swingManager.addClearButton(this.txtDefaultValue);
|
529 | swingManager.addClearButton(this.txtFieldName);
|
||
530 | swingManager.addClearButton(this.txtIntervalEnd);
|
||
531 | swingManager.addClearButton(this.txtIntervalStart);
|
||
532 | swingManager.addClearButton(this.txtPrecision);
|
||
533 | swingManager.addClearButton(this.txtSize);
|
||
534 | 44202 | jjdelcerro | swingManager.addClearButton(this.txtLabel);
|
535 | swingManager.addClearButton(this.txtDescription);
|
||
536 | swingManager.addClearButton(this.cboGroup);
|
||
537 | swingManager.addClearButton(this.txtMaxValue);
|
||
538 | swingManager.addClearButton(this.txtMinValue);
|
||
539 | swingManager.addClearButton(this.txtAvailableValuesLabel);
|
||
540 | 44262 | jjdelcerro | swingManager.addClearButton(this.txtAvailableValuesValue);
|
541 | |||
542 | 44077 | jjdelcerro | swingManager.setDefaultPopupMenu(this.txtDefaultValue);
|
543 | swingManager.setDefaultPopupMenu(this.txtFieldName);
|
||
544 | swingManager.setDefaultPopupMenu(this.txtIntervalEnd);
|
||
545 | swingManager.setDefaultPopupMenu(this.txtIntervalStart);
|
||
546 | swingManager.setDefaultPopupMenu(this.txtPrecision);
|
||
547 | swingManager.setDefaultPopupMenu(this.txtSize);
|
||
548 | swingManager.setDefaultPopupMenu(this.cboDateFormat);
|
||
549 | swingManager.setDefaultPopupMenu(this.cboFieldType);
|
||
550 | swingManager.setDefaultPopupMenu(this.cboGeometrySubtype);
|
||
551 | swingManager.setDefaultPopupMenu(this.cboGeometryType);
|
||
552 | 44128 | jjdelcerro | swingManager.setDefaultPopupMenu(this.cboDataProfile);
|
553 | 44085 | jjdelcerro | |
554 | 44262 | jjdelcerro | swingManager.setDefaultPopupMenu(this.cboForeingKeyCodeName);
|
555 | swingManager.setDefaultPopupMenu(this.cboForeingKeyTableName);
|
||
556 | |||
557 | 44202 | jjdelcerro | swingManager.setDefaultPopupMenu(this.cboGroup);
|
558 | swingManager.setDefaultPopupMenu(this.txtOrder);
|
||
559 | swingManager.setDefaultPopupMenu(this.txtLabel);
|
||
560 | swingManager.setDefaultPopupMenu(this.txtDescription);
|
||
561 | swingManager.setDefaultPopupMenu(this.txtMinValue);
|
||
562 | swingManager.setDefaultPopupMenu(this.txtMaxValue);
|
||
563 | swingManager.setDefaultPopupMenu(this.txtAvailableValuesLabel);
|
||
564 | swingManager.setDefaultPopupMenu(this.txtAvailableValuesValue);
|
||
565 | 44262 | jjdelcerro | |
566 | this.foreingKeyController = new ForeingKeyController( |
||
567 | chkIsForeingKey, |
||
568 | 44338 | jjdelcerro | chkIsClosedList, |
569 | 44262 | jjdelcerro | cboForeingKeyTableName, |
570 | cboForeingKeyCodeName, |
||
571 | txtForeingKeyFormula, |
||
572 | btnForeingKeyFormula |
||
573 | ); |
||
574 | 44077 | jjdelcerro | this.pickerIntervalEnd = swingManager.createDatePickerController(
|
575 | 44085 | jjdelcerro | this.txtIntervalEnd,
|
576 | 44077 | jjdelcerro | this.btnIntervalEnd
|
577 | ); |
||
578 | this.pickerIntervalStart = swingManager.createDatePickerController(
|
||
579 | 44085 | jjdelcerro | this.txtIntervalStart,
|
580 | 44077 | jjdelcerro | this.btnIntervalStart
|
581 | ); |
||
582 | this.pickerSize = evaluatorManager.createCalculatorController(
|
||
583 | 44085 | jjdelcerro | this.txtSize, DataTypes.INT
|
584 | 44077 | jjdelcerro | ); |
585 | this.pickerPrecision = evaluatorManager.createCalculatorController(
|
||
586 | 44085 | jjdelcerro | this.txtPrecision, DataTypes.INT
|
587 | 44077 | jjdelcerro | ); |
588 | this.pickerDefaultValue = evaluatorManager.createCalculatorController(
|
||
589 | 44085 | jjdelcerro | this.txtDefaultValue, DataTypes.OBJECT
|
590 | 44077 | jjdelcerro | ); |
591 | 44202 | jjdelcerro | this.pickerOrder = evaluatorManager.createCalculatorController(
|
592 | this.txtOrder, DataTypes.INT
|
||
593 | ); |
||
594 | 44085 | jjdelcerro | |
595 | 44202 | jjdelcerro | this.availableValuesController = new AvailableValuesController( |
596 | 44262 | jjdelcerro | cboAvailableValues, |
597 | txtAvailableValuesLabel, |
||
598 | txtAvailableValuesValue, |
||
599 | btnAvailableValuesAdd, |
||
600 | btnAvailableValuesUpdate, |
||
601 | 44202 | jjdelcerro | btnAvailableValuesRemove |
602 | ); |
||
603 | 44253 | jjdelcerro | this.tagsController = new TagsController( |
604 | 44262 | jjdelcerro | tblTags, |
605 | cboTagsName, |
||
606 | txtTagsValue, |
||
607 | btnTagsAdd, |
||
608 | btnTagsUpdate, |
||
609 | 44253 | jjdelcerro | btnTagsRemove, |
610 | lblTagsDescription |
||
611 | ); |
||
612 | 44202 | jjdelcerro | this.txtMinValue.setEnabled(false); |
613 | this.txtMaxValue.setEnabled(false); |
||
614 | 44262 | jjdelcerro | |
615 | 44085 | jjdelcerro | this.btnVirtualField.setText(""); |
616 | 44259 | jjdelcerro | this.featureStoreElement = dataSwingManager.createFeatureStoreElement();
|
617 | 44077 | jjdelcerro | this.pickerVirtualField = ExpressionEvaluatorSwingLocator.getManager()
|
618 | .createExpressionPickerController(txtVirtualField, btnVirtualField); |
||
619 | 44149 | jjdelcerro | this.pickerVirtualField.addElement(this.featureStoreElement); |
620 | this.chkVirtualField.addChangeListener(new ChangeListener() { |
||
621 | @Override
|
||
622 | public void stateChanged(ChangeEvent e) { |
||
623 | if (chkVirtualField.isSelected()) {
|
||
624 | pickerVirtualField.setEnabled(editable); |
||
625 | } else {
|
||
626 | pickerVirtualField.setEnabled(false);
|
||
627 | } |
||
628 | } |
||
629 | }); |
||
630 | 44077 | jjdelcerro | |
631 | 44149 | jjdelcerro | this.pickerCRS = dataSwingManager.createProjectionPickerController(
|
632 | this.txtCRS, this.btnCRS |
||
633 | ); |
||
634 | |||
635 | 44085 | jjdelcerro | this.cboFieldType.addItemListener(new ItemListener() { |
636 | @Override
|
||
637 | public void itemStateChanged(ItemEvent e) { |
||
638 | SwingUtilities.invokeLater(new Runnable() { |
||
639 | @Override
|
||
640 | public void run() { |
||
641 | doFieldTypeChanged(); |
||
642 | } |
||
643 | }); |
||
644 | |||
645 | } |
||
646 | }); |
||
647 | |||
648 | 44100 | jjdelcerro | this.pickerPrecision.addChangeListener(new ChangeListener() { |
649 | @Override
|
||
650 | public void stateChanged(ChangeEvent e) { |
||
651 | doCheckSizeAndPrecision(); |
||
652 | } |
||
653 | }); |
||
654 | this.pickerSize.addChangeListener(new ChangeListener() { |
||
655 | @Override
|
||
656 | public void stateChanged(ChangeEvent e) { |
||
657 | doCheckSizeAndPrecision(); |
||
658 | } |
||
659 | }); |
||
660 | 44262 | jjdelcerro | |
661 | 44253 | jjdelcerro | DefaultComboBoxModel dataProfilesModel = new DefaultComboBoxModel<>(); |
662 | 44262 | jjdelcerro | dataProfilesModel.addElement(new ListElement<>("", null)); |
663 | 44128 | jjdelcerro | for (DataProfile profile : DALLocator.getDataManager().getDataProfiles()) {
|
664 | 44253 | jjdelcerro | dataProfilesModel.addElement(new ListElement<>(profile.getName(), profile.getID()));
|
665 | 44128 | jjdelcerro | } |
666 | this.cboDataProfile.setModel(dataProfilesModel);
|
||
667 | 44077 | jjdelcerro | } |
668 | 44085 | jjdelcerro | |
669 | 44077 | jjdelcerro | @Override
|
670 | public JComponent asJComponent() { |
||
671 | return this; |
||
672 | } |
||
673 | |||
674 | @Override
|
||
675 | public EditableFeatureAttributeDescriptor fetch(EditableFeatureAttributeDescriptor descriptor) {
|
||
676 | 44152 | jjdelcerro | I18nManager i18n = ToolsLocator.getI18nManager(); |
677 | 44085 | jjdelcerro | try {
|
678 | 44262 | jjdelcerro | if (!this.chkAllowNulls.isSelected()) { |
679 | if (descriptor.allowNull()) {
|
||
680 | 44223 | jjdelcerro | ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
681 | dialogs.messageDialog( |
||
682 | 44262 | jjdelcerro | i18n.getTranslation("_You_have_marked_not_allow_nulls") + "\n" |
683 | + i18n.getTranslation("If_you_are_not_fully_aware_of_the_repercussions_of_this_it_is_advisable_to_allow_nulls"),
|
||
684 | 44223 | jjdelcerro | null,
|
685 | 44262 | jjdelcerro | i18n.getTranslation("_Warning"),
|
686 | 44223 | jjdelcerro | JOptionPane.INFORMATION_MESSAGE,
|
687 | "AllowNullsInFeatureTypeEditing"
|
||
688 | ); |
||
689 | } |
||
690 | } |
||
691 | 44085 | jjdelcerro | descriptor.setDataType((int) ListElement.getSelected(this.cboFieldType)); |
692 | descriptor.setName(this.txtFieldName.getText());
|
||
693 | descriptor.setAllowNull(this.chkAllowNulls.isSelected());
|
||
694 | descriptor.setIsPrimaryKey(this.chkIsPrimaryKey.isSelected());
|
||
695 | descriptor.setIsAutomatic(this.chkIsAutomatic.isSelected());
|
||
696 | 44152 | jjdelcerro | descriptor.setSize(this.pickerSize.get(0)); |
697 | descriptor.setPrecision(this.pickerPrecision.get(0)); |
||
698 | 44085 | jjdelcerro | descriptor.setDefaultValue(this.pickerDefaultValue.get());
|
699 | 44253 | jjdelcerro | descriptor.setDataProfileName((String) ListElement.getSelected(this.cboDataProfile)); |
700 | 44085 | jjdelcerro | switch (descriptor.getType()) {
|
701 | case DataTypes.GEOMETRY:
|
||
702 | GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
||
703 | GeometryType geomType = geomManager.getGeometryType( |
||
704 | (int) ListElement.getSelected(this.cboGeometryType), |
||
705 | (int) ListElement.getSelected(this.cboGeometrySubtype) |
||
706 | ); |
||
707 | descriptor.setGeometryType(geomType); |
||
708 | descriptor.setSRS(this.pickerCRS.get());
|
||
709 | break;
|
||
710 | case DataTypes.INSTANT:
|
||
711 | case DataTypes.INTERVAL:
|
||
712 | case DataTypes.DATE:
|
||
713 | case DataTypes.TIME:
|
||
714 | case DataTypes.TIMESTAMP:
|
||
715 | // FIXME
|
||
716 | break;
|
||
717 | default:
|
||
718 | break;
|
||
719 | } |
||
720 | 44154 | jjdelcerro | descriptor.setDataProfileName( |
721 | 44262 | jjdelcerro | StringUtils.defaultIfBlank((String) ListElement.getSelected(cboDataProfile), null) |
722 | 44154 | jjdelcerro | ); |
723 | |||
724 | 44262 | jjdelcerro | if (this.chkVirtualField.isSelected() && this.pickerVirtualField.isEnabled()) { |
725 | 44085 | jjdelcerro | Expression expression = this.pickerVirtualField.get(); |
726 | 44262 | jjdelcerro | if (expression == null) { |
727 | descriptor.setFeatureAttributeEmulator((String) null); |
||
728 | 44085 | jjdelcerro | } else {
|
729 | DataManager dataManager = DALLocator.getDataManager(); |
||
730 | FeatureAttributeEmulatorExpression emulator = dataManager.createFeatureAttributeEmulatorExpression( |
||
731 | descriptor.getFeatureType(), |
||
732 | expression |
||
733 | ); |
||
734 | 44262 | jjdelcerro | if (!emulator.isValid()) {
|
735 | 44154 | jjdelcerro | ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
736 | dialogs.messageDialog( |
||
737 | 44262 | jjdelcerro | i18n.getTranslation("_The_expression_of_virtual_field_is_not_valid")
|
738 | + "\n"
|
||
739 | + emulator.getErrorMessage(), |
||
740 | i18n.getTranslation("_Warning"),
|
||
741 | 44154 | jjdelcerro | JOptionPane.WARNING_MESSAGE
|
742 | ); |
||
743 | return null; |
||
744 | } |
||
745 | for (String requiredFieldName : emulator.getRequiredFieldNames()) { |
||
746 | 44262 | jjdelcerro | if (StringUtils.equalsIgnoreCase(requiredFieldName, descriptor.getName())) {
|
747 | 44154 | jjdelcerro | ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
748 | dialogs.messageDialog( |
||
749 | 44262 | jjdelcerro | i18n.getTranslation("_The_expression_of_virtual_field_is_not_valid")
|
750 | + "\n\n"
|
||
751 | + i18n.getTranslation("_The_expression_contains_a_reference_to_itself"),
|
||
752 | i18n.getTranslation("_Warning"),
|
||
753 | 44154 | jjdelcerro | JOptionPane.WARNING_MESSAGE
|
754 | ); |
||
755 | return null; |
||
756 | } |
||
757 | } |
||
758 | 44155 | jjdelcerro | descriptor.setFeatureAttributeEmulator(emulator); |
759 | 44154 | jjdelcerro | //
|
760 | // No se porque esto de abajo no funciona.
|
||
761 | // Nunca se lanza la excepcion en el get(Feature) de
|
||
762 | // DefaultFeatureAttributeEmulatorExpression.
|
||
763 | //
|
||
764 | // try {
|
||
765 | // emulator.setEnableExceptions(true);
|
||
766 | // descriptor.setFeatureAttributeEmulator(emulator);
|
||
767 | // this.pickerVirtualField.getPreviewSymbolTable().value(descriptor.getName());
|
||
768 | // } catch(Throwable ex) {
|
||
769 | // emulator.setEnableExceptions(false);
|
||
770 | // descriptor.setFeatureAttributeEmulator(null);
|
||
771 | // ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
|
||
772 | // dialogs.messageDialog(
|
||
773 | // i18n.getTranslation("_The_expression_of_virtual_field_is_not_valid")+
|
||
774 | // "\n"+
|
||
775 | // ex.getMessage(),
|
||
776 | // i18n.getTranslation("_Warning"),
|
||
777 | // JOptionPane.WARNING_MESSAGE
|
||
778 | // );
|
||
779 | // return null;
|
||
780 | // } finally {
|
||
781 | // emulator.setEnableExceptions(false);
|
||
782 | // }
|
||
783 | 44085 | jjdelcerro | } |
784 | } |
||
785 | } catch (Exception ex) { |
||
786 | 44262 | jjdelcerro | LOGGER.warn("Can't retrieve information from user form.", ex);
|
787 | 44085 | jjdelcerro | ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
788 | dialogs.messageDialog( |
||
789 | 44262 | jjdelcerro | i18n.getTranslation("_Cant_retrieve_information_from_user_form")
|
790 | + "\n"
|
||
791 | + i18n.getTranslation("_See_log_for_details"),
|
||
792 | i18n.getTranslation("_Warning"),
|
||
793 | 44085 | jjdelcerro | JOptionPane.WARNING_MESSAGE
|
794 | ); |
||
795 | 44152 | jjdelcerro | return null; |
796 | 44085 | jjdelcerro | } |
797 | 44262 | jjdelcerro | |
798 | 44202 | jjdelcerro | descriptor.setGroup(StringUtils.defaultIfBlank((String) this.cboGroup.getSelectedItem(), null)); |
799 | descriptor.setOrder(this.pickerOrder.get(0)); |
||
800 | descriptor.setHidden(this.chkHidden.isSelected());
|
||
801 | descriptor.setLabel(StringUtils.defaultIfBlank(this.txtLabel.getText(), null)); |
||
802 | descriptor.setDescription(StringUtils.defaultIfBlank(this.txtDescription.getText(), null)); |
||
803 | 44262 | jjdelcerro | |
804 | 44202 | jjdelcerro | // this.txtMinValue.setText(Objects.toString(descriptor.getMinValue(), ""));
|
805 | // this.txtMinValue.setText(Objects.toString(descriptor.getMaxValue(), ""));
|
||
806 | 44262 | jjdelcerro | descriptor.setAvailableValues(this.availableValuesController.get());
|
807 | 44202 | jjdelcerro | |
808 | 44253 | jjdelcerro | this.tagsController.fetch(descriptor.getTags());
|
809 | 44262 | jjdelcerro | this.foreingKeyController.fetch(descriptor.getForeingKey());
|
810 | 44077 | jjdelcerro | return descriptor;
|
811 | } |
||
812 | |||
813 | 44202 | jjdelcerro | @Override
|
814 | 44077 | jjdelcerro | public void clean() { |
815 | this.pickerDefaultValue.set(null); |
||
816 | 44100 | jjdelcerro | this.txtFieldName.setText(""); |
817 | // this.pickerFieldName.set(null);
|
||
818 | 44077 | jjdelcerro | this.pickerIntervalEnd.set(null); |
819 | this.pickerIntervalStart.set(null); |
||
820 | this.pickerPrecision.set(null); |
||
821 | this.pickerSize.set(null); |
||
822 | |||
823 | this.chkAllowNulls.setSelected(false); |
||
824 | this.chkIsAutomatic.setSelected(false); |
||
825 | this.chkIsPrimaryKey.setSelected(false); |
||
826 | 44085 | jjdelcerro | |
827 | 44077 | jjdelcerro | this.chkVirtualField.setSelected(false); |
828 | 44085 | jjdelcerro | this.chkVirtualField.setEnabled(editable);
|
829 | 44077 | jjdelcerro | this.pickerVirtualField.setEnabled(false); |
830 | this.pickerVirtualField.set(null); |
||
831 | |||
832 | ListElement.setSelected(cboGeometryType, null);
|
||
833 | ListElement.setSelected(cboGeometrySubtype, null);
|
||
834 | 44085 | jjdelcerro | |
835 | ListElement.setSelected(cboFieldType, DataTypes.STRING); |
||
836 | 44262 | jjdelcerro | |
837 | 44128 | jjdelcerro | this.cboDataProfile.setSelectedIndex(-1); |
838 | 44262 | jjdelcerro | |
839 | 44202 | jjdelcerro | this.cboGroup.setSelectedIndex(-1); |
840 | this.pickerOrder.set(null); |
||
841 | this.chkHidden.setSelected(false); |
||
842 | this.txtLabel.setText(""); |
||
843 | this.txtDescription.setText(""); |
||
844 | this.txtMinValue.setText(""); |
||
845 | this.txtMaxValue.setText(""); |
||
846 | this.availableValuesController.clean();
|
||
847 | 44262 | jjdelcerro | this.tagsController.clean();
|
848 | this.foreingKeyController.clean();
|
||
849 | 44077 | jjdelcerro | } |
850 | 44085 | jjdelcerro | |
851 | 44077 | jjdelcerro | @Override
|
852 | public void put(FeatureAttributeDescriptor descriptor) { |
||
853 | 44085 | jjdelcerro | if (descriptor == null) { |
854 | 44077 | jjdelcerro | this.clean();
|
855 | return;
|
||
856 | } |
||
857 | 44202 | jjdelcerro | FeatureType featureType = descriptor.getFeatureType(); |
858 | DefaultComboBoxModel groupModel = new DefaultComboBoxModel(); |
||
859 | 44262 | jjdelcerro | |
860 | if (featureType != null) { |
||
861 | 44100 | jjdelcerro | FeatureStore store = descriptor.getFeatureType().getStore(); |
862 | 44149 | jjdelcerro | this.featureStoreElement.setFeatureStore(store);
|
863 | 44262 | jjdelcerro | if (store != null) { |
864 | 44100 | jjdelcerro | Feature sampleFeature = null;
|
865 | try {
|
||
866 | sampleFeature = store.getFeatureSelection().first(); |
||
867 | 44262 | jjdelcerro | if (sampleFeature == null) { |
868 | 44100 | jjdelcerro | sampleFeature = store.first(); |
869 | } |
||
870 | } catch (DataException ex) {
|
||
871 | } |
||
872 | 44262 | jjdelcerro | if (sampleFeature != null) { |
873 | 44100 | jjdelcerro | FeatureSymbolTable featureSymbolTable = DALLocator.getDataManager().createFeatureSymbolTable(); |
874 | featureSymbolTable.setFeature(sampleFeature); |
||
875 | this.pickerVirtualField.setPreviewSymbolTable(featureSymbolTable.createParent());
|
||
876 | } |
||
877 | } |
||
878 | 44202 | jjdelcerro | List<String> groups = new ArrayList<>(); |
879 | for (FeatureAttributeDescriptor otherdesc : featureType) {
|
||
880 | String group = otherdesc.getGroup();
|
||
881 | 44262 | jjdelcerro | if (!StringUtils.isBlank(group) && !groups.contains(group)) {
|
882 | 44202 | jjdelcerro | groups.add(group); |
883 | } |
||
884 | } |
||
885 | for (String group : groups) { |
||
886 | groupModel.addElement(group); |
||
887 | } |
||
888 | 44085 | jjdelcerro | } |
889 | 44094 | jjdelcerro | if (!(descriptor instanceof EditableFeatureAttributeDescriptor)) { |
890 | this.setEditable(false); |
||
891 | } |
||
892 | 44262 | jjdelcerro | |
893 | 44077 | jjdelcerro | this.pickerDefaultValue.set(descriptor.getDefaultValue());
|
894 | 44100 | jjdelcerro | this.txtFieldName.setText(descriptor.getName());
|
895 | 44077 | jjdelcerro | RelativeInterval interval = (RelativeInterval) descriptor.getInterval(); |
896 | 44085 | jjdelcerro | if (interval == null) { |
897 | this.pickerIntervalEnd.set(null); |
||
898 | this.pickerIntervalStart.set(null); |
||
899 | 44077 | jjdelcerro | } else {
|
900 | this.pickerIntervalEnd.set(interval.getEnd().toDate());
|
||
901 | this.pickerIntervalStart.set(interval.getStart().toDate());
|
||
902 | } |
||
903 | this.pickerPrecision.set(descriptor.getPrecision());
|
||
904 | this.pickerSize.set(descriptor.getSize());
|
||
905 | 44085 | jjdelcerro | |
906 | 44077 | jjdelcerro | this.chkAllowNulls.setSelected(descriptor.allowNull());
|
907 | this.chkIsAutomatic.setSelected(descriptor.isAutomatic());
|
||
908 | this.chkIsPrimaryKey.setSelected(descriptor.isPrimaryKey());
|
||
909 | 44085 | jjdelcerro | |
910 | 44077 | jjdelcerro | FeatureAttributeEmulator attrEmulator = descriptor.getFeatureAttributeEmulator(); |
911 | 44085 | jjdelcerro | if (attrEmulator instanceof FeatureAttributeEmulatorExpression) { |
912 | 44077 | jjdelcerro | Expression expression = ((FeatureAttributeEmulatorExpression) attrEmulator).getExpression();
|
913 | 44085 | jjdelcerro | this.chkVirtualField.setEnabled(editable);
|
914 | 44077 | jjdelcerro | this.chkVirtualField.setSelected(true); |
915 | 44085 | jjdelcerro | this.pickerVirtualField.setEnabled(editable);
|
916 | 44077 | jjdelcerro | this.pickerVirtualField.set(expression);
|
917 | 44085 | jjdelcerro | } else if (descriptor.isComputed()) { |
918 | this.chkVirtualField.setEnabled(false); |
||
919 | 44077 | jjdelcerro | this.chkVirtualField.setSelected(true); |
920 | this.pickerVirtualField.setEnabled(false); |
||
921 | this.pickerVirtualField.set(null); |
||
922 | } else {
|
||
923 | 44085 | jjdelcerro | this.chkVirtualField.setEnabled(editable);
|
924 | 44077 | jjdelcerro | this.chkVirtualField.setSelected(false); |
925 | this.pickerVirtualField.setEnabled(false); |
||
926 | this.pickerVirtualField.set(null); |
||
927 | } |
||
928 | 44085 | jjdelcerro | |
929 | 44077 | jjdelcerro | this.pickerCRS.set(descriptor.getSRS());
|
930 | 44085 | jjdelcerro | |
931 | if (descriptor.getGeomType() != null) { |
||
932 | 44079 | jjdelcerro | ListElement.setSelected(cboGeometryType, descriptor.getGeomType().getType()); |
933 | ListElement.setSelected(cboGeometrySubtype, descriptor.getGeomType().getSubType()); |
||
934 | } |
||
935 | 44085 | jjdelcerro | ListElement.setSelected(cboFieldType, descriptor.getType()); |
936 | |||
937 | 44128 | jjdelcerro | String profile = descriptor.getDataProfileName();
|
938 | 44262 | jjdelcerro | if (StringUtils.isBlank(profile)) {
|
939 | this.cboDataProfile.setSelectedIndex(-1); |
||
940 | 44128 | jjdelcerro | } else {
|
941 | 44262 | jjdelcerro | ListElement.setSelected(this.cboDataProfile, profile);
|
942 | 44128 | jjdelcerro | } |
943 | 44202 | jjdelcerro | |
944 | this.cboGroup.setModel(groupModel);
|
||
945 | 44262 | jjdelcerro | this.cboGroup.setSelectedItem(StringUtils.defaultIfBlank(descriptor.getGroup(), "")); |
946 | 44202 | jjdelcerro | this.pickerOrder.set(descriptor.getOder());
|
947 | this.chkHidden.setSelected(descriptor.isHidden());
|
||
948 | 44262 | jjdelcerro | this.txtLabel.setText(StringUtils.defaultIfBlank(descriptor.getLabel(), "")); |
949 | this.txtDescription.setText(StringUtils.defaultIfBlank(descriptor.getDescription(), "")); |
||
950 | 44202 | jjdelcerro | this.txtMinValue.setText(Objects.toString(descriptor.getMinValue(), "")); |
951 | this.txtMinValue.setText(Objects.toString(descriptor.getMaxValue(), "")); |
||
952 | this.availableValuesController.set(descriptor.getAvailableValues());
|
||
953 | 44253 | jjdelcerro | this.tagsController.set(descriptor.getTags());
|
954 | 44202 | jjdelcerro | |
955 | 44262 | jjdelcerro | this.foreingKeyController.put(descriptor.getForeingKey());
|
956 | 44077 | jjdelcerro | } |
957 | |||
958 | 44085 | jjdelcerro | private void doFieldTypeChanged() { |
959 | try {
|
||
960 | Integer fieldType = (Integer) ListElement.getSelected(this.cboFieldType); |
||
961 | if (fieldType == null) { |
||
962 | fieldType = DataTypes.UNKNOWN; |
||
963 | } |
||
964 | 44128 | jjdelcerro | Integer size = this.pickerSize.get(); |
965 | 44262 | jjdelcerro | if (fieldType == DataTypes.STRING) {
|
966 | if (size == null) { |
||
967 | 44128 | jjdelcerro | this.pickerSize.set(50); |
968 | } |
||
969 | } else {
|
||
970 | 44100 | jjdelcerro | int maxsize = this.getMaxSizeOfType(fieldType); |
971 | 44262 | jjdelcerro | if (size == null || (maxsize > 0 && size > maxsize)) { |
972 | 44100 | jjdelcerro | this.pickerSize.set(maxsize);
|
973 | } |
||
974 | } |
||
975 | 44128 | jjdelcerro | Integer precision = this.pickerPrecision.get(); |
976 | 44262 | jjdelcerro | if (precision == null) { |
977 | 44128 | jjdelcerro | int defaultPrecision = this.getDefaultPrecisionOfType(fieldType); |
978 | 44262 | jjdelcerro | if (defaultPrecision > 0) { |
979 | 44128 | jjdelcerro | this.pickerPrecision.set(defaultPrecision);
|
980 | } |
||
981 | } |
||
982 | 44262 | jjdelcerro | |
983 | 44085 | jjdelcerro | switch (fieldType) {
|
984 | case DataTypes.GEOMETRY:
|
||
985 | this.cboGeometryType.setEnabled(editable);
|
||
986 | this.cboGeometrySubtype.setEnabled(editable);
|
||
987 | this.pickerCRS.setEnabled(editable);
|
||
988 | this.cboDateFormat.setEnabled(false); |
||
989 | this.pickerIntervalStart.setEnabled(false); |
||
990 | this.pickerIntervalEnd.setEditable(false); |
||
991 | this.tabAditionalFields.setEnabledAt(1, true); |
||
992 | this.tabAditionalFields.setEnabledAt(2, false); |
||
993 | 44100 | jjdelcerro | this.pickerSize.set(null); |
994 | this.pickerPrecision.set(null); |
||
995 | this.pickerSize.setEnabled(false); |
||
996 | this.pickerPrecision.setEnabled(false); |
||
997 | 44085 | jjdelcerro | break;
|
998 | case DataTypes.INSTANT:
|
||
999 | case DataTypes.INTERVAL:
|
||
1000 | case DataTypes.DATE:
|
||
1001 | case DataTypes.TIME:
|
||
1002 | case DataTypes.TIMESTAMP:
|
||
1003 | this.cboGeometryType.setEnabled(false); |
||
1004 | this.cboGeometrySubtype.setEnabled(false); |
||
1005 | this.pickerCRS.setEnabled(false); |
||
1006 | this.cboDateFormat.setEnabled(editable);
|
||
1007 | this.pickerIntervalStart.setEnabled(editable);
|
||
1008 | 44100 | jjdelcerro | this.pickerIntervalEnd.setEnabled(editable);
|
1009 | 44085 | jjdelcerro | this.tabAditionalFields.setEnabledAt(1, false); |
1010 | this.tabAditionalFields.setEnabledAt(2, true); |
||
1011 | 44100 | jjdelcerro | this.pickerSize.set(null); |
1012 | this.pickerPrecision.set(null); |
||
1013 | this.pickerSize.setEnabled(false); |
||
1014 | this.pickerPrecision.setEnabled(false); |
||
1015 | 44085 | jjdelcerro | break;
|
1016 | 44100 | jjdelcerro | case DataTypes.BYTE:
|
1017 | case DataTypes.INT:
|
||
1018 | 44262 | jjdelcerro | case DataTypes.LONG:
|
1019 | case DataTypes.STRING:
|
||
1020 | 44100 | jjdelcerro | this.cboGeometryType.setEnabled(false); |
1021 | this.cboGeometrySubtype.setEnabled(false); |
||
1022 | this.pickerCRS.setEnabled(false); |
||
1023 | this.cboDateFormat.setEnabled(false); |
||
1024 | this.pickerIntervalStart.setEnabled(false); |
||
1025 | this.pickerIntervalEnd.setEditable(false); |
||
1026 | this.tabAditionalFields.setEnabledAt(1, false); |
||
1027 | this.tabAditionalFields.setEnabledAt(2, false); |
||
1028 | |||
1029 | this.pickerPrecision.set(null); |
||
1030 | this.pickerSize.setEnabled(true); |
||
1031 | this.pickerPrecision.setEnabled(false); |
||
1032 | break;
|
||
1033 | case DataTypes.FLOAT:
|
||
1034 | case DataTypes.DOUBLE:
|
||
1035 | this.cboGeometryType.setEnabled(false); |
||
1036 | this.cboGeometrySubtype.setEnabled(false); |
||
1037 | this.pickerCRS.setEnabled(false); |
||
1038 | this.cboDateFormat.setEnabled(false); |
||
1039 | this.pickerIntervalStart.setEnabled(false); |
||
1040 | this.pickerIntervalEnd.setEditable(false); |
||
1041 | this.tabAditionalFields.setEnabledAt(1, false); |
||
1042 | this.tabAditionalFields.setEnabledAt(2, false); |
||
1043 | |||
1044 | this.pickerSize.setEnabled(true); |
||
1045 | this.pickerPrecision.setEnabled(true); |
||
1046 | break;
|
||
1047 | 44085 | jjdelcerro | default:
|
1048 | this.cboGeometryType.setEnabled(false); |
||
1049 | this.cboGeometrySubtype.setEnabled(false); |
||
1050 | this.pickerCRS.setEnabled(false); |
||
1051 | this.cboDateFormat.setEnabled(false); |
||
1052 | this.pickerIntervalStart.setEnabled(false); |
||
1053 | this.pickerIntervalEnd.setEditable(false); |
||
1054 | this.tabAditionalFields.setEnabledAt(1, false); |
||
1055 | this.tabAditionalFields.setEnabledAt(2, false); |
||
1056 | 44100 | jjdelcerro | this.pickerSize.set(null); |
1057 | this.pickerPrecision.set(null); |
||
1058 | this.pickerSize.setEnabled(false); |
||
1059 | this.pickerPrecision.setEnabled(false); |
||
1060 | 44085 | jjdelcerro | } |
1061 | } catch (Exception ex) { |
||
1062 | 44262 | jjdelcerro | LOGGER.warn("Problems changing field type.", ex);
|
1063 | 44085 | jjdelcerro | } |
1064 | 44262 | jjdelcerro | |
1065 | 44077 | jjdelcerro | } |
1066 | 44085 | jjdelcerro | |
1067 | 44202 | jjdelcerro | @Override
|
1068 | 44085 | jjdelcerro | public void setEditable(boolean editable) { |
1069 | this.editable = editable;
|
||
1070 | this.pickerDefaultValue.setEditable(editable);
|
||
1071 | 44100 | jjdelcerro | this.txtFieldName.setEditable(editable);
|
1072 | // this.pickerFieldName.setEditable(editable);
|
||
1073 | 44085 | jjdelcerro | this.pickerIntervalEnd.setEditable(editable);
|
1074 | this.pickerIntervalStart.setEditable(editable);
|
||
1075 | this.pickerPrecision.setEditable(editable);
|
||
1076 | this.pickerSize.setEditable(editable);
|
||
1077 | 44128 | jjdelcerro | this.cboDataProfile.setEnabled(editable);
|
1078 | 44085 | jjdelcerro | |
1079 | this.chkAllowNulls.setEnabled(editable);
|
||
1080 | this.chkIsAutomatic.setEnabled(editable);
|
||
1081 | this.chkIsPrimaryKey.setEnabled(editable);
|
||
1082 | |||
1083 | this.chkVirtualField.setEnabled(editable);
|
||
1084 | this.pickerVirtualField.setEditable(editable);
|
||
1085 | |||
1086 | this.cboDateFormat.setEnabled(editable);
|
||
1087 | this.cboFieldType.setEnabled(editable);
|
||
1088 | this.cboGeometryType.setEnabled(editable);
|
||
1089 | this.cboGeometrySubtype.setEnabled(editable);
|
||
1090 | 44191 | jjdelcerro | this.pickerCRS.setEditable(editable);
|
1091 | 44085 | jjdelcerro | |
1092 | 44202 | jjdelcerro | this.cboGroup.setEnabled(editable);
|
1093 | this.pickerOrder.setEditable(editable);
|
||
1094 | this.chkHidden.setEnabled(editable);
|
||
1095 | this.txtLabel.setEditable(editable);
|
||
1096 | this.txtDescription.setEditable(editable);
|
||
1097 | this.txtMinValue.setEditable(false); |
||
1098 | this.txtMaxValue.setEditable(false); |
||
1099 | this.availableValuesController.setEditable(editable);
|
||
1100 | 44253 | jjdelcerro | this.tagsController.setEditable(editable);
|
1101 | 44262 | jjdelcerro | this.foreingKeyController.setEditable(editable);
|
1102 | 44085 | jjdelcerro | } |
1103 | 44262 | jjdelcerro | |
1104 | 44100 | jjdelcerro | private int getMaxSizeOfType(int dataType) { |
1105 | 44262 | jjdelcerro | switch (dataType) {
|
1106 | 44100 | jjdelcerro | case DataTypes.BOOLEAN:
|
1107 | return 1; |
||
1108 | case DataTypes.BYTE:
|
||
1109 | return 3; |
||
1110 | case DataTypes.INT:
|
||
1111 | return 9; |
||
1112 | case DataTypes.LONG:
|
||
1113 | return 19; |
||
1114 | case DataTypes.FLOAT:
|
||
1115 | return 20; |
||
1116 | case DataTypes.DOUBLE:
|
||
1117 | return 20; |
||
1118 | case DataTypes.DATE:
|
||
1119 | return 8; |
||
1120 | default:
|
||
1121 | return -1; |
||
1122 | } |
||
1123 | } |
||
1124 | |||
1125 | 44128 | jjdelcerro | private int getDefaultPrecisionOfType(int dataType) { |
1126 | 44262 | jjdelcerro | switch (dataType) {
|
1127 | 44128 | jjdelcerro | case DataTypes.FLOAT:
|
1128 | return 6; |
||
1129 | case DataTypes.DOUBLE:
|
||
1130 | return 6; |
||
1131 | default:
|
||
1132 | return -1; |
||
1133 | } |
||
1134 | } |
||
1135 | |||
1136 | 44100 | jjdelcerro | private void doCheckSizeAndPrecision() { |
1137 | Integer size = this.pickerSize.get(); |
||
1138 | 44262 | jjdelcerro | if (size == null) { |
1139 | 44100 | jjdelcerro | return;
|
1140 | } |
||
1141 | int maxsize = this.getMaxSizeOfType((int) ListElement.getSelected(cboFieldType)); |
||
1142 | 44262 | jjdelcerro | if (size < 1 || (maxsize > 0 && size > maxsize)) { |
1143 | 44100 | jjdelcerro | this.pickerSize.setWarning(true, "The size is not valid for the selected type"); |
1144 | } else {
|
||
1145 | this.pickerSize.setWarning(false); |
||
1146 | } |
||
1147 | 44262 | jjdelcerro | if (this.pickerPrecision.isEnabled()) { |
1148 | 44100 | jjdelcerro | Integer precision = this.pickerPrecision.get(); |
1149 | 44262 | jjdelcerro | if (precision == null) { |
1150 | return;
|
||
1151 | 44100 | jjdelcerro | } |
1152 | 44262 | jjdelcerro | if (precision < 0) { |
1153 | 44100 | jjdelcerro | this.pickerPrecision.setWarning(true, "the precision can not have a negative value"); |
1154 | 44262 | jjdelcerro | } else if (precision > size) { |
1155 | 44100 | jjdelcerro | this.pickerPrecision.setWarning(true, "the precision can not have a value greater than the size"); |
1156 | } else {
|
||
1157 | this.pickerPrecision.setWarning(false); |
||
1158 | } |
||
1159 | } |
||
1160 | } |
||
1161 | |||
1162 | 44128 | jjdelcerro | @Override
|
1163 | public void setNameAsNew(FeatureType featureType) { |
||
1164 | this.txtFieldName.setText(DefaultFeatureTypePanel.getNewFieldName(featureType));
|
||
1165 | } |
||
1166 | |||
1167 | @Override
|
||
1168 | public String getName() { |
||
1169 | return StringUtils.defaultIfBlank(this.txtFieldName.getText(), null); |
||
1170 | } |
||
1171 | 44262 | jjdelcerro | |
1172 | 44077 | jjdelcerro | } |