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