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