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 / searchpanel / SearchConditionFieldController.java @ 45329
History | View | Annotate | Download (51.6 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.searchpanel; |
---|---|
2 |
|
3 |
import java.awt.Cursor; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ItemEvent; |
6 |
import java.awt.event.ItemListener; |
7 |
import java.awt.event.MouseAdapter; |
8 |
import java.awt.event.MouseEvent; |
9 |
import java.text.DateFormat; |
10 |
import java.util.ArrayList; |
11 |
import java.util.Arrays; |
12 |
import java.util.Date; |
13 |
import java.util.HashMap; |
14 |
import java.util.List; |
15 |
import java.util.Locale; |
16 |
import java.util.Map; |
17 |
import java.util.Objects; |
18 |
import javax.json.Json; |
19 |
import javax.json.JsonArray; |
20 |
import javax.json.JsonArrayBuilder; |
21 |
import javax.json.JsonObject; |
22 |
import javax.json.JsonObjectBuilder; |
23 |
import javax.swing.ComboBoxModel; |
24 |
import javax.swing.DefaultComboBoxModel; |
25 |
import javax.swing.ImageIcon; |
26 |
import javax.swing.JComboBox; |
27 |
import javax.swing.JLabel; |
28 |
import javax.swing.JOptionPane; |
29 |
import javax.swing.SwingUtilities; |
30 |
import javax.swing.text.JTextComponent; |
31 |
import org.apache.commons.lang3.StringUtils; |
32 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
33 |
import org.gvsig.fmap.dal.DALLocator; |
34 |
import org.gvsig.fmap.dal.DataManager; |
35 |
import org.gvsig.fmap.dal.DataStore; |
36 |
import org.gvsig.fmap.dal.complements.Search; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
38 |
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder; |
39 |
import org.gvsig.fmap.dal.feature.Feature; |
40 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
41 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
42 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
43 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
44 |
import org.gvsig.fmap.dal.feature.FeatureType; |
45 |
import org.gvsig.fmap.dal.feature.ForeingKey; |
46 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributeSelectionPanel; |
47 |
import static org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel.getAttributeDescriptorLabel; |
48 |
import static org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel.NOT_HANDLE_NULL; |
49 |
import static org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel.NULL_AS_FALSE; |
50 |
import static org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel.NULL_AS_TRUE; |
51 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters; |
52 |
import org.gvsig.tools.ToolsLocator; |
53 |
import org.gvsig.tools.dataTypes.Coercion; |
54 |
import org.gvsig.tools.dataTypes.CoercionException; |
55 |
import org.gvsig.tools.dataTypes.DataTypeUtils; |
56 |
import org.gvsig.tools.dataTypes.DataTypes; |
57 |
import org.gvsig.tools.dispose.DisposeUtils; |
58 |
import org.gvsig.tools.dynobject.DynField; |
59 |
import org.gvsig.tools.exception.BaseException; |
60 |
import org.gvsig.tools.i18n.I18nManager; |
61 |
import org.gvsig.tools.swing.api.DropDown; |
62 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
63 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
64 |
import org.gvsig.tools.swing.api.pickercontroller.DatePickerController; |
65 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
66 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
67 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
68 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
69 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
70 |
import org.gvsig.tools.util.LabeledValue; |
71 |
import org.gvsig.tools.util.LabeledValueImpl; |
72 |
import org.gvsig.tools.visitor.VisitCanceledException; |
73 |
import org.gvsig.tools.visitor.Visitor; |
74 |
import org.slf4j.Logger; |
75 |
import org.slf4j.LoggerFactory; |
76 |
|
77 |
/**
|
78 |
*
|
79 |
* @author jjdelcerro
|
80 |
*/
|
81 |
@SuppressWarnings("UseSpecificCatch") |
82 |
public class SearchConditionFieldController { |
83 |
|
84 |
private static final Logger LOGGER = LoggerFactory.getLogger(SearchConditionFieldController.class); |
85 |
private static final Class LOAD_MORE_ELEMENTS = SearchConditionFieldController.class; |
86 |
private static class Field extends LabeledValueImpl<String> { |
87 |
|
88 |
FeatureAttributeDescriptor attrdesc; |
89 |
private final FeatureStore store; |
90 |
private final int presentationMode; |
91 |
private final boolean showStoreName; |
92 |
private final FeatureAttributeDescriptor[] path; |
93 |
|
94 |
public Field(FeatureAttributeDescriptor[] path, FeatureStore store, FeatureAttributeDescriptor attrdesc, int presentationMode) { |
95 |
this(path, store, attrdesc, presentationMode, false); |
96 |
} |
97 |
|
98 |
public Field( |
99 |
FeatureAttributeDescriptor[] path,
|
100 |
FeatureStore store, |
101 |
FeatureAttributeDescriptor attrdesc, |
102 |
int presentationMode,
|
103 |
boolean showStoreName
|
104 |
) { |
105 |
super(
|
106 |
getAttributeDescriptorLabel(attrdesc, store.getName()), |
107 |
attrdesc.getName() |
108 |
); |
109 |
this.path = path;
|
110 |
this.store = store;
|
111 |
this.attrdesc = attrdesc;
|
112 |
this.presentationMode = presentationMode;
|
113 |
this.showStoreName = showStoreName;
|
114 |
} |
115 |
|
116 |
public FeatureAttributeDescriptor[] getPath() { |
117 |
return this.path; |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public String getLabel() { |
122 |
String theLabel = getAttributeDescriptorLabel(attrdesc, showStoreName ? store.getName() : null); |
123 |
switch (this.presentationMode) { |
124 |
case Search.OrderedAttribute.TYPE_REGURAL:
|
125 |
break;
|
126 |
case Search.OrderedAttribute.TYPE_FAVORITE:
|
127 |
theLabel = "<html><b>" + theLabel + "</b></html>"; |
128 |
break;
|
129 |
case Search.OrderedAttribute.TYPE_RECENT:
|
130 |
theLabel = "<html><i><b>" + theLabel + "</b></i></html>"; |
131 |
break;
|
132 |
} |
133 |
return theLabel;
|
134 |
} |
135 |
|
136 |
public FeatureAttributeDescriptor getParentDescriptor() {
|
137 |
int l = this.path.length; |
138 |
if (l < 2) { |
139 |
return null; |
140 |
} |
141 |
return this.path[l - 2]; |
142 |
} |
143 |
|
144 |
public FeatureAttributeDescriptor getDescriptor() {
|
145 |
return this.attrdesc; |
146 |
} |
147 |
|
148 |
public FeatureStore getFeatureStore() {
|
149 |
return this.store; |
150 |
} |
151 |
|
152 |
} |
153 |
|
154 |
private FeatureStore store;
|
155 |
private SearchParameters parameters;
|
156 |
private final JLabel lblFields; |
157 |
private final JLabel lblExtraFields; |
158 |
private final JLabel lblLogicalOperators; |
159 |
private final JLabel lblRelationalOperators; |
160 |
private final JComboBox cboValue; |
161 |
private final JLabel lblNull; |
162 |
private Object valueAssigned = null; |
163 |
|
164 |
private DropDown ddnFields;
|
165 |
private DropDown ddnLogicalOperators;
|
166 |
private DropDown ddnRelationalOperators;
|
167 |
private DropDown ddnNullBehavior;
|
168 |
|
169 |
private LabeledValue[] relationalOperators; |
170 |
private LabeledValue[] logicalOperators; |
171 |
private LabeledValue[] nullBehaviors; |
172 |
private ArrayList<ImageIcon> nullOperatorsIcons; |
173 |
|
174 |
private final int SIZE_ORDERED_ATTRIBUTES = 20; |
175 |
private DatePickerController dateController = null; |
176 |
|
177 |
private int updateValuesTimeLimit; |
178 |
private int updateValuesFeaturesLimit; |
179 |
private boolean canHasMoreElements; |
180 |
|
181 |
public SearchConditionFieldController(
|
182 |
SearchParameters parameters, |
183 |
FeatureStore store, |
184 |
JLabel lblFields,
|
185 |
JLabel lblExtraFields,
|
186 |
JLabel lblRelationalOperators,
|
187 |
JComboBox cboValue,
|
188 |
JLabel lblNull,
|
189 |
JLabel lblLogicalOperators
|
190 |
) { |
191 |
this.parameters = parameters;
|
192 |
this.store = store;
|
193 |
this.lblFields = lblFields;
|
194 |
this.lblExtraFields = lblExtraFields;
|
195 |
this.lblRelationalOperators = lblRelationalOperators;
|
196 |
this.cboValue = cboValue;
|
197 |
this.lblNull = lblNull;
|
198 |
this.lblLogicalOperators = lblLogicalOperators;
|
199 |
this.updateValuesTimeLimit = 60; |
200 |
this.updateValuesFeaturesLimit = 1000; |
201 |
this.canHasMoreElements = false; |
202 |
this.initComponents();
|
203 |
} |
204 |
|
205 |
public boolean isAValidRelationOperator(String name) { |
206 |
for (LabeledValue relationalOperator : relationalOperators) {
|
207 |
if (StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
208 |
return true; |
209 |
} |
210 |
} |
211 |
return false; |
212 |
} |
213 |
|
214 |
private void initComponents() { |
215 |
try {
|
216 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
217 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
218 |
|
219 |
relationalOperators = new LabeledValue[]{ |
220 |
new LabeledValueImpl(i18n.getTranslation("_Equals_to"), ExpressionBuilder.OPERATOR_EQ), |
221 |
new LabeledValueImpl(i18n.getTranslation("_Like_to"), ExpressionBuilder.OPERATOR_ILIKE), |
222 |
new LabeledValueImpl(i18n.getTranslation("_Not_equals_to"), ExpressionBuilder.OPERATOR_NE), |
223 |
new LabeledValueImpl(i18n.getTranslation("_Greater_than"), ExpressionBuilder.OPERATOR_GT), |
224 |
new LabeledValueImpl(i18n.getTranslation("_Greater_or_equal_to"), ExpressionBuilder.OPERATOR_GE), |
225 |
new LabeledValueImpl(i18n.getTranslation("_Less_than"), ExpressionBuilder.OPERATOR_LT), |
226 |
new LabeledValueImpl(i18n.getTranslation("_Less_or_equal_to"), ExpressionBuilder.OPERATOR_LE), |
227 |
new LabeledValueImpl(i18n.getTranslation("_Is_null"), ExpressionBuilder.OPERATOR_IS_NULL), |
228 |
new LabeledValueImpl(i18n.getTranslation("_Is_not_null"), ExpressionBuilder.OPERATOR_IS_NOT_NULL) |
229 |
}; |
230 |
|
231 |
logicalOperators = new LabeledValue[]{ |
232 |
new LabeledValueImpl(i18n.getTranslation("_Or"), ExpressionBuilder.OPERATOR_OR), |
233 |
new LabeledValueImpl(i18n.getTranslation("_And"), ExpressionBuilder.OPERATOR_AND) |
234 |
}; |
235 |
|
236 |
nullBehaviors = new LabeledValue[]{ |
237 |
new LabeledValueImpl(i18n.getTranslation("_Not_handle_null_values"), NOT_HANDLE_NULL), |
238 |
new LabeledValueImpl(i18n.getTranslation("_Null_values_as_true"), NULL_AS_TRUE), |
239 |
new LabeledValueImpl(i18n.getTranslation("_Null_values_as_false"), NULL_AS_FALSE) |
240 |
}; |
241 |
|
242 |
nullOperatorsIcons = new ArrayList<ImageIcon>(); |
243 |
nullOperatorsIcons.add(ToolsSwingLocator.getIconThemeManager().getCurrent().get("search-nullbehavior-null"));
|
244 |
nullOperatorsIcons.add(ToolsSwingLocator.getIconThemeManager().getCurrent().get("search-nullbehavior-true"));
|
245 |
nullOperatorsIcons.add(ToolsSwingLocator.getIconThemeManager().getCurrent().get("search-nullbehavior-false2"));
|
246 |
|
247 |
this.lblExtraFields.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
248 |
|
249 |
this.ddnFields = toolsSwingManager.createDropDown(lblFields);
|
250 |
this.ddnFields.setVisibleDropdownArrow(false); |
251 |
this.ddnRelationalOperators = toolsSwingManager.createDropDown(lblRelationalOperators);
|
252 |
this.ddnRelationalOperators.setVisibleDropdownArrow(false); |
253 |
if (lblLogicalOperators != null) { |
254 |
this.ddnLogicalOperators = toolsSwingManager.createDropDown(lblLogicalOperators);
|
255 |
this.ddnLogicalOperators.setVisibleDropdownArrow(false); |
256 |
} |
257 |
|
258 |
DefaultComboBoxModel modelRelationalOperators = new DefaultComboBoxModel(); |
259 |
for (LabeledValue op : relationalOperators) {
|
260 |
modelRelationalOperators.addElement(op); |
261 |
} |
262 |
this.ddnRelationalOperators.setModel(modelRelationalOperators);
|
263 |
this.ddnRelationalOperators.addItemListener(new ItemListener() { |
264 |
@Override
|
265 |
public void itemStateChanged(ItemEvent ie) { |
266 |
if (ie.getStateChange() == ItemEvent.SELECTED) { |
267 |
Object item = ((LabeledValue)ie.getItemSelectable().getSelectedObjects()[0]).getValue(); |
268 |
if (ExpressionBuilder.OPERATOR_IS_NULL.equals(item) || ExpressionBuilder.OPERATOR_IS_NOT_NULL.equals(item)) {
|
269 |
lblNull.setEnabled(false);
|
270 |
lblNull.setVisible(false);
|
271 |
cboValue.setEnabled(false);
|
272 |
cboValue.setVisible(false);
|
273 |
} else {
|
274 |
lblNull.setEnabled(true);
|
275 |
lblNull.setVisible(true);
|
276 |
cboValue.setEnabled(true);
|
277 |
cboValue.setVisible(true);
|
278 |
} |
279 |
} |
280 |
} |
281 |
}); |
282 |
|
283 |
if (this.ddnLogicalOperators != null) { |
284 |
DefaultComboBoxModel modelLogicalOperators = new DefaultComboBoxModel(); |
285 |
for (LabeledValue op : logicalOperators) {
|
286 |
modelLogicalOperators.addElement(op); |
287 |
} |
288 |
this.ddnLogicalOperators.setModel(modelLogicalOperators);
|
289 |
this.ddnLogicalOperators.setSelectedIndex(1); |
290 |
} |
291 |
|
292 |
// this.ddnNullOperators = new DropDownLabelIcon(lblNull);
|
293 |
this.ddnNullBehavior = toolsSwingManager.createDropDownIcon(lblNull);
|
294 |
this.ddnNullBehavior.setVisibleDropdownArrow(false); |
295 |
DefaultComboBoxModel modelNullOperators = new DefaultComboBoxModel(); |
296 |
for (LabeledValue op : nullBehaviors) {
|
297 |
modelNullOperators.addElement(op); |
298 |
} |
299 |
this.ddnNullBehavior.setModel(modelNullOperators);
|
300 |
this.ddnNullBehavior.setIcons(nullOperatorsIcons);
|
301 |
this.ddnNullBehavior.setSelectedIndex(0); |
302 |
FeatureType featureType = parameters.getFeatureType(store); |
303 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
304 |
Search.COMPLEMENT_MANE, featureType |
305 |
); |
306 |
List<Search.OrderedAttribute> orderedAttributes = search.getOrderedAttributes(
|
307 |
Search.BASIC_TYPES_FILTER, |
308 |
Search.STR_INT_LONG_LABEL_ORDER, |
309 |
SIZE_ORDERED_ATTRIBUTES |
310 |
); |
311 |
List<ImageIcon> icons = new ArrayList<>(); |
312 |
// DataTypesManager dataTypeManager = ToolsLocator.getDataTypesManager();
|
313 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
314 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
315 |
for (Search.OrderedAttribute attr : orderedAttributes) {
|
316 |
FeatureAttributeDescriptor attrdesc = attr.getDescriptor(); |
317 |
Field field = new Field( |
318 |
new FeatureAttributeDescriptor[]{attrdesc}, |
319 |
this.store,
|
320 |
attrdesc, |
321 |
attr.getType() |
322 |
); |
323 |
model.addElement(field); |
324 |
String iconName = attrdesc.getDataType().getIconName();
|
325 |
if (iconTheme.exists(iconName)) {
|
326 |
icons.add(iconTheme.get(iconName)); |
327 |
} else {
|
328 |
icons.add(null);
|
329 |
} |
330 |
} |
331 |
|
332 |
this.ddnFields.setIcons(icons);
|
333 |
this.ddnFields.setModel(model);
|
334 |
this.ddnFields.addItemListener(new ItemListener() { |
335 |
@Override
|
336 |
public void itemStateChanged(ItemEvent e) { |
337 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
338 |
doUpdateValuesList(); |
339 |
} |
340 |
|
341 |
} |
342 |
}); |
343 |
|
344 |
this.cboValue.addItemListener(new ItemListener() { |
345 |
@Override
|
346 |
public void itemStateChanged(ItemEvent e) { |
347 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
348 |
if (cboValue.getSelectedItem() != null && cboValue.getSelectedItem() instanceof LabeledValue) { |
349 |
if (Objects.equals(((LabeledValue) cboValue.getSelectedItem()).getValue(), LOAD_MORE_ELEMENTS)) {
|
350 |
setUpdateValuesLimits(updateValuesTimeLimit + 10, updateValuesFeaturesLimit + 20000); |
351 |
} |
352 |
} |
353 |
} |
354 |
} |
355 |
}); |
356 |
|
357 |
this.lblExtraFields.addMouseListener(new MouseAdapter() { |
358 |
@Override
|
359 |
public void mouseClicked(MouseEvent e) { |
360 |
doSelectMoreFields(); |
361 |
} |
362 |
}); |
363 |
|
364 |
// clear();
|
365 |
} catch (Exception ex) { |
366 |
throw new RuntimeException(ex); |
367 |
} |
368 |
} |
369 |
|
370 |
private FeatureType getFeatureType() {
|
371 |
try {
|
372 |
return this.store.getDefaultFeatureType(); |
373 |
} catch (DataException ex) {
|
374 |
return null; |
375 |
} |
376 |
} |
377 |
|
378 |
private void doSelectMoreFields() { |
379 |
DefaultFeatureAttributeSelectionPanel panel = new DefaultFeatureAttributeSelectionPanel(store, parameters.getFeatureType(store));
|
380 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
381 |
final Dialog dialog = winManager.createDialog( |
382 |
panel, |
383 |
"Select attribute",
|
384 |
null,
|
385 |
WindowManager_v2.BUTTONS_OK_CANCEL |
386 |
); |
387 |
dialog.addActionListener((ActionEvent e) -> {
|
388 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) {
|
389 |
doAddAndSelect( |
390 |
panel.getSelectedStore(), |
391 |
panel.getSelectedAttributeDescriptor(), |
392 |
panel.getSelectedPath() |
393 |
); |
394 |
} |
395 |
}); |
396 |
dialog.show(WindowManager.MODE.DIALOG); |
397 |
|
398 |
} |
399 |
|
400 |
private void doAddAndSelect(FeatureStore theStore, FeatureAttributeDescriptor attrdesc, FeatureAttributeDescriptor[] path) { |
401 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
402 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
403 |
DefaultComboBoxModel<Field> model = (DefaultComboBoxModel) this.ddnFields.getModel(); |
404 |
if (attrdesc == null) { |
405 |
dialogManager.messageDialog( |
406 |
i18n.getTranslation("_It_is_not_supported_to_search_through_this_field") + "\n" |
407 |
+ i18n.getTranslation("_Field_not_found"),
|
408 |
"_Warning",
|
409 |
JOptionPane.WARNING_MESSAGE
|
410 |
); |
411 |
return;
|
412 |
} |
413 |
|
414 |
for (int i = 0; i < model.getSize(); i++) { |
415 |
Field field = model.getElementAt(i);
|
416 |
FeatureAttributeDescriptor attrdescN = field.getDescriptor(); |
417 |
if (isTheSameStore(theStore, attrdescN.getStore())
|
418 |
&& StringUtils.equalsIgnoreCase(attrdesc.getName(), attrdescN.getName())) { |
419 |
this.setAttribute(i);
|
420 |
return;
|
421 |
} |
422 |
} |
423 |
Field field = new Field( |
424 |
path, |
425 |
theStore, |
426 |
attrdesc, |
427 |
Search.OrderedAttribute.TYPE_REGURAL, |
428 |
!isTheSameStore(store, theStore) |
429 |
); |
430 |
if (field.getPath().length > 2) { |
431 |
dialogManager.messageDialog( |
432 |
i18n.getTranslation("_It_is_not_supported_to_search_through_this_field") + "\n" |
433 |
+ i18n.getTranslation("_To_many_links"),
|
434 |
"_Warning",
|
435 |
JOptionPane.WARNING_MESSAGE
|
436 |
); |
437 |
return;
|
438 |
} |
439 |
FeatureAttributeDescriptor parentDescriptor = field.getParentDescriptor(); |
440 |
if (parentDescriptor != null) { |
441 |
switch (parentDescriptor.getRelationType()) {
|
442 |
case DynField.RELATION_TYPE_AGGREGATE:
|
443 |
case DynField.RELATION_TYPE_COMPOSITION:
|
444 |
if (getForeingKeyName(field.getFeatureStore(), this.store) == null) { |
445 |
dialogManager.messageDialog( |
446 |
"It not supported to search through this field." + "\n" |
447 |
+ "The link field was not found.",
|
448 |
"_Warning",
|
449 |
JOptionPane.WARNING_MESSAGE
|
450 |
); |
451 |
return;
|
452 |
} |
453 |
if (getPrimaryKeyName(this.store) == null) { |
454 |
dialogManager.messageDialog( |
455 |
"It not supported to search through this field." + "\n" |
456 |
+ "A simple primary key was not found.",
|
457 |
"_Warning",
|
458 |
JOptionPane.WARNING_MESSAGE
|
459 |
); |
460 |
return;
|
461 |
} |
462 |
} |
463 |
} |
464 |
model.addElement(field); |
465 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
466 |
this.ddnFields.getIcons().add(iconTheme.get(attrdesc.getDataType().getIconName()));
|
467 |
this.setAttribute(model.getSize() - 1); |
468 |
} |
469 |
|
470 |
public void clear() { |
471 |
this.ddnRelationalOperators.setSelectedIndex(0); |
472 |
if (this.ddnLogicalOperators != null) { |
473 |
this.ddnLogicalOperators.setSelectedIndex(1); |
474 |
} |
475 |
this.cboValue.setSelectedIndex(-1); |
476 |
this.ddnNullBehavior.setSelectedIndex(0); |
477 |
} |
478 |
|
479 |
private void doUpdateValuesList() { |
480 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
481 |
if (field == null) { |
482 |
return;
|
483 |
} |
484 |
FeatureAttributeDescriptor descriptor = field.getDescriptor(); |
485 |
if (descriptor.getType() == DataTypes.DATE) {
|
486 |
if (this.dateController == null) { |
487 |
this.dateController = ToolsSwingLocator.getToolsSwingManager().createDatePickerController(
|
488 |
(JTextComponent) this.cboValue.getEditor().getEditorComponent(), |
489 |
null
|
490 |
); |
491 |
} |
492 |
} else {
|
493 |
if (this.dateController != null) { |
494 |
this.dateController.uninstall();
|
495 |
this.dateController = null; |
496 |
} |
497 |
} |
498 |
|
499 |
final List<Object> values = new ArrayList<>(); |
500 |
final DefaultComboBoxModel model = new DefaultComboBoxModel(); |
501 |
final FeatureStore theStore = field.getFeatureStore();
|
502 |
final FeatureQuery query;
|
503 |
if (this.store == theStore) { |
504 |
query = parameters.getQuery().getCopy(); // theStore.createFeatureQuery();
|
505 |
} else {
|
506 |
query = theStore.createFeatureQuery(); |
507 |
} |
508 |
query.addAttributeName(field.getDescriptor().getName()); |
509 |
query.setFilter("");
|
510 |
query.setLimit(updateValuesFeaturesLimit); |
511 |
query.getGroupByColumns().clear(); |
512 |
query.getAggregateFunctions().clear(); |
513 |
Thread th = new Thread(new Runnable() { |
514 |
@Override
|
515 |
public void run() { |
516 |
FeatureSet set = null;
|
517 |
try {
|
518 |
canHasMoreElements = false;
|
519 |
set = theStore.getFeatureSet(query); |
520 |
if (set.size() >= updateValuesFeaturesLimit) {
|
521 |
canHasMoreElements = true;
|
522 |
} |
523 |
final long timeLimit = System.currentTimeMillis() + updateValuesTimeLimit * 1000; |
524 |
set.accept(new Visitor() {
|
525 |
@Override
|
526 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
527 |
Object value = ((Feature) o).get(field.getDescriptor().getName());
|
528 |
if (!values.contains(value)) {
|
529 |
values.add(value); |
530 |
} |
531 |
if (System.currentTimeMillis() > timeLimit) { |
532 |
canHasMoreElements = true;
|
533 |
throw new VisitCanceledException(); |
534 |
} |
535 |
if (values.size() > 1000) { |
536 |
canHasMoreElements = true;
|
537 |
throw new VisitCanceledException(); |
538 |
} |
539 |
} |
540 |
}); |
541 |
} catch (VisitCanceledException ex) {
|
542 |
canHasMoreElements = true;
|
543 |
} catch (Exception ex) { |
544 |
LOGGER.warn("Can't update list of values of '" + field.getLabel() + "'.", ex); |
545 |
} finally {
|
546 |
DisposeUtils.disposeQuietly(set); |
547 |
} |
548 |
List<LabeledValue> elements = new ArrayList<>(); |
549 |
if (!values.isEmpty()) {
|
550 |
LabeledValue[] availableValues = field.getDescriptor().getAvailableValues();
|
551 |
Map<String, String> availableValuesMap = new HashMap<>(); |
552 |
if (availableValues != null) { |
553 |
for (LabeledValue availableValue : availableValues) {
|
554 |
availableValuesMap.put( |
555 |
Objects.toString(availableValue.getValue()), |
556 |
availableValue.getLabel() |
557 |
); |
558 |
} |
559 |
} |
560 |
elements.add(new LabeledValueImpl("", null)); |
561 |
for (Object value : values) { |
562 |
String key;
|
563 |
key = DataTypeUtils.toString(value); |
564 |
String label = availableValuesMap.getOrDefault(key, key);
|
565 |
elements.add(new LabeledValueImpl(label, value));
|
566 |
} |
567 |
elements.sort(null);
|
568 |
|
569 |
} |
570 |
for (LabeledValue element : elements) {
|
571 |
model.addElement(element); |
572 |
} |
573 |
if (canHasMoreElements) {
|
574 |
model.addElement(new LabeledValueImpl("...", LOAD_MORE_ELEMENTS)); |
575 |
} |
576 |
SwingUtilities.invokeLater(new Runnable() { |
577 |
@Override
|
578 |
public void run() { |
579 |
setEnabled(false);
|
580 |
cboValue.setModel(model); |
581 |
if (valueAssigned != null) { |
582 |
cboValue.setSelectedItem(valueAssigned); |
583 |
valueAssigned = null;
|
584 |
} |
585 |
setEnabled(true);
|
586 |
} |
587 |
}); |
588 |
} |
589 |
}); |
590 |
th.start(); |
591 |
} |
592 |
|
593 |
public void setEnabled(boolean enabled) { |
594 |
ddnFields.setEnabled(enabled); |
595 |
if (ddnLogicalOperators != null) { |
596 |
ddnLogicalOperators.setEnabled(enabled); |
597 |
} |
598 |
ddnRelationalOperators.setEnabled(enabled); |
599 |
lblExtraFields.setEnabled(enabled); |
600 |
cboValue.setEnabled(enabled); |
601 |
} |
602 |
|
603 |
public String getRelationalOperator() { |
604 |
LabeledValue<String> op = (LabeledValue) this.ddnRelationalOperators.getSelectedItem(); |
605 |
if (op == null) { |
606 |
return null; |
607 |
} |
608 |
return op.getValue();
|
609 |
} |
610 |
|
611 |
public int setRelationalOperator(String name) { |
612 |
int n = 0; |
613 |
for (LabeledValue relationalOperator : relationalOperators) {
|
614 |
if (StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
615 |
break;
|
616 |
} |
617 |
n++; |
618 |
} |
619 |
if (this.relationalOperators.length <= n) { |
620 |
return -1; |
621 |
} |
622 |
this.ddnRelationalOperators.setSelectedIndex(n);
|
623 |
return n;
|
624 |
} |
625 |
|
626 |
public String getLogicalOperator() { |
627 |
if (this.ddnLogicalOperators == null) { |
628 |
return null; |
629 |
} |
630 |
LabeledValue<String> rel = (LabeledValue) this.ddnLogicalOperators.getSelectedItem(); |
631 |
if (rel == null) { |
632 |
return null; |
633 |
} |
634 |
return rel.getValue();
|
635 |
} |
636 |
|
637 |
public void setLogicalOperator(String operator) { |
638 |
if (this.ddnLogicalOperators == null) { |
639 |
return;
|
640 |
} |
641 |
ComboBoxModel model = this.ddnLogicalOperators.getModel(); |
642 |
for (int i = 0; i < model.getSize(); i++) { |
643 |
LabeledValue modelValue = (LabeledValue) model.getElementAt(i); |
644 |
String value = (String) modelValue.getValue(); |
645 |
if (StringUtils.equals(value, operator)) {
|
646 |
this.ddnLogicalOperators.setSelectedIndex(i);
|
647 |
break;
|
648 |
} |
649 |
} |
650 |
} |
651 |
|
652 |
public Object getValue() { |
653 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
654 |
if (field == null) { |
655 |
return null; |
656 |
} |
657 |
Object v;
|
658 |
if (this.dateController == null) { |
659 |
v = this.cboValue.getSelectedItem();
|
660 |
} else {
|
661 |
v = this.dateController.get();
|
662 |
} |
663 |
if (v == null) { |
664 |
return null; |
665 |
} |
666 |
if (v instanceof LabeledValue) { |
667 |
v = ((LabeledValue) v).getValue(); |
668 |
if (v == null) { |
669 |
return null; |
670 |
} |
671 |
} |
672 |
if (v instanceof CharSequence) { |
673 |
if (StringUtils.isBlank((CharSequence) v)) { |
674 |
return null; |
675 |
} |
676 |
} |
677 |
Coercion coercion = field.getDescriptor().getDataType().getCoercion(); |
678 |
try {
|
679 |
return coercion.coerce(v);
|
680 |
} catch (CoercionException ex) {
|
681 |
return null; |
682 |
} |
683 |
} |
684 |
|
685 |
public void setValue(Object value) { |
686 |
//this.cboValue.setSelectedItem(value);
|
687 |
SwingUtilities.invokeLater(new Runnable() { |
688 |
@Override
|
689 |
public void run() { |
690 |
DefaultComboBoxModel model = (DefaultComboBoxModel) cboValue.getModel(); |
691 |
for (int i = 0; i < model.getSize(); i++) { |
692 |
Object item = model.getElementAt(i);
|
693 |
if (item.equals(value)) {
|
694 |
cboValue.setSelectedIndex(i); |
695 |
valueAssigned = value; |
696 |
return;
|
697 |
} |
698 |
} |
699 |
// si no lo encuentra en el modelo lo a?ade
|
700 |
final Field field = (Field) ddnFields.getSelectedItem(); |
701 |
if (field == null) { |
702 |
return;
|
703 |
} else {
|
704 |
LabeledValue[] availableValues = field.getDescriptor().getAvailableValues();
|
705 |
Map<String, String> availableValuesMap = new HashMap<>(); |
706 |
if (availableValues != null) { |
707 |
for (LabeledValue availableValue : availableValues) {
|
708 |
availableValuesMap.put( |
709 |
Objects.toString(availableValue.getValue()), |
710 |
availableValue.getLabel() |
711 |
); |
712 |
} |
713 |
} |
714 |
String key;
|
715 |
if (value instanceof Date) { |
716 |
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); |
717 |
df.setLenient(false);
|
718 |
key = df.format(value); |
719 |
} else {
|
720 |
key = Objects.toString(value); |
721 |
} |
722 |
String label = availableValuesMap.getOrDefault(key, key);
|
723 |
LabeledValueImpl newItem = new LabeledValueImpl(label, value);
|
724 |
model.addElement(newItem); |
725 |
cboValue.setSelectedItem(newItem); |
726 |
valueAssigned = newItem; |
727 |
} |
728 |
} |
729 |
}); |
730 |
} |
731 |
|
732 |
private Field getCurrentField() { |
733 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
734 |
return field;
|
735 |
} |
736 |
|
737 |
public int setAttribute(String name) { |
738 |
ComboBoxModel<Field> model = this.ddnFields.getModel(); |
739 |
for (int i = 0; i < model.getSize(); i++) { |
740 |
Field x = model.getElementAt(i);
|
741 |
if (StringUtils.equalsIgnoreCase(name, x.getValue())) {
|
742 |
this.setAttribute(i);
|
743 |
return i;
|
744 |
} |
745 |
} |
746 |
this.setAttribute(-1); |
747 |
return -1; |
748 |
} |
749 |
|
750 |
public void setAttribute(int index) { |
751 |
try {
|
752 |
this.ddnFields.setSelectedIndex(index);
|
753 |
} catch (Exception ex) { |
754 |
this.ddnFields.setSelectedIndex(-1); |
755 |
} |
756 |
doUpdateValuesList(); |
757 |
} |
758 |
|
759 |
public int setAttributePath(String[][] pathNames) { |
760 |
// [[attributeName, storeName],...]
|
761 |
try {
|
762 |
if (pathNames.length == 1) { |
763 |
String[] path = pathNames[pathNames.length - 1]; |
764 |
String name = path[0]; |
765 |
int index = this.setAttribute(name); |
766 |
if (index == -1) { |
767 |
try {
|
768 |
FeatureAttributeDescriptor attrDescriptor = store.getDefaultFeatureType().getAttributeDescriptor(name); |
769 |
FeatureAttributeDescriptor[] attributePath = new FeatureAttributeDescriptor[]{attrDescriptor}; |
770 |
if (attrDescriptor == null) { |
771 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
772 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
773 |
dialogManager.messageDialog( |
774 |
i18n.getTranslation("_It_is_not_supported_to_search_through_this_field") + ":\n " + name + "\n" |
775 |
+ i18n.getTranslation("_Field_not_found_in_this_table"),
|
776 |
"_Warning",
|
777 |
JOptionPane.WARNING_MESSAGE
|
778 |
); |
779 |
this.cboValue.setModel(new DefaultComboBoxModel()); |
780 |
} else {
|
781 |
doAddAndSelect(store, store.getDefaultFeatureType().getAttributeDescriptor(name), attributePath); |
782 |
} |
783 |
} catch (Exception ex) { |
784 |
LOGGER.warn("Not able to set single path into controller", ex);
|
785 |
return -1; |
786 |
} |
787 |
} |
788 |
return index;
|
789 |
} else {
|
790 |
ComboBoxModel<Field> model = this.ddnFields.getModel(); |
791 |
String[] singleArrayPathNameDescriptors = new String[pathNames.length]; |
792 |
for (int i = 0; i < pathNames.length; i++) { |
793 |
singleArrayPathNameDescriptors[i] = pathNames[i][0];
|
794 |
} |
795 |
// check the drop
|
796 |
for (int i = 0; i < model.getSize(); i++) { |
797 |
Field x = model.getElementAt(i);
|
798 |
String[] arrayDescriptors = new String[x.getPath().length]; |
799 |
FeatureAttributeDescriptor[] path = x.getPath();
|
800 |
for (int j = 0; j < path.length; j++) { |
801 |
arrayDescriptors[j] = path[j].getName(); |
802 |
} |
803 |
if (Arrays.equals(singleArrayPathNameDescriptors, arrayDescriptors)) { |
804 |
this.setAttribute(i);
|
805 |
return i;
|
806 |
} |
807 |
} |
808 |
// if not, addit to the drop
|
809 |
DataManager dataManager = DALLocator.getDataManager(); |
810 |
String tableName = pathNames[pathNames.length - 1][1]; // del ultimo path, coger el nombre tabla |
811 |
FeatureStore theStore = (FeatureStore) dataManager.getStoresRepository().getStore(tableName); |
812 |
String attributeName = pathNames[pathNames.length - 1][0]; // del ultimo path, coger el nombre attribute |
813 |
if (theStore != null) { |
814 |
FeatureAttributeDescriptor attr; |
815 |
try {
|
816 |
attr = theStore.getDefaultFeatureType().getAttributeDescriptor(attributeName); |
817 |
FeatureAttributeDescriptor[] attributePath = new FeatureAttributeDescriptor[2]; |
818 |
String firstAttrName = pathNames[0][0]; |
819 |
FeatureAttributeDescriptor firstAttr = store.getDefaultFeatureType().getAttributeDescriptor(firstAttrName); |
820 |
attributePath[0] = firstAttr;
|
821 |
|
822 |
attributePath[1] = attr;
|
823 |
doAddAndSelect(theStore, attr, attributePath); |
824 |
return SIZE_ORDERED_ATTRIBUTES - 1; |
825 |
} catch (Exception ex) { |
826 |
LOGGER.warn("Not able to set foreign path into controller", ex);
|
827 |
} |
828 |
|
829 |
} |
830 |
|
831 |
} |
832 |
} catch (Exception ex) { |
833 |
LOGGER.warn("Controller not set.", ex);
|
834 |
} |
835 |
this.setAttribute(-1); |
836 |
return -1; |
837 |
} |
838 |
|
839 |
private boolean isTheSameStore(DataStore store1, DataStore store2) { |
840 |
String store1FullName = store1.getFullName();
|
841 |
String store2FullName = store2.getFullName();
|
842 |
return StringUtils.equalsIgnoreCase(store1FullName, store2FullName);
|
843 |
} |
844 |
|
845 |
private String getPrimaryKeyName(FeatureStore store) { |
846 |
try {
|
847 |
FeatureAttributeDescriptor[] pk = store.getDefaultFeatureType().getPrimaryKey();
|
848 |
if (pk == null || pk.length != 1) { |
849 |
return null; |
850 |
} |
851 |
return pk[0].getName(); |
852 |
} catch (DataException ex) {
|
853 |
return null; |
854 |
} |
855 |
} |
856 |
|
857 |
private String getForeingKeyName(FeatureStore store, FeatureStore foreingStore) { |
858 |
try {
|
859 |
for (FeatureAttributeDescriptor descriptor : store.getDefaultFeatureType()) {
|
860 |
if (descriptor.isForeingKey()) {
|
861 |
ForeingKey foreingKey = descriptor.getForeingKey(); |
862 |
if (isTheSameStore(foreingStore, foreingKey.getFeatureStore(null))) { |
863 |
return descriptor.getName();
|
864 |
} |
865 |
} |
866 |
} |
867 |
} catch (DataException ex) {
|
868 |
return null; |
869 |
} |
870 |
return null; |
871 |
} |
872 |
|
873 |
public boolean isValid(StringBuilder message) { |
874 |
try {
|
875 |
Object value = this.getValue(); |
876 |
if (value == null) { |
877 |
return true; |
878 |
} |
879 |
Field field = this.getCurrentField(); |
880 |
if (field == null) { |
881 |
return true; |
882 |
} |
883 |
if (field.getPath().length > 2) { |
884 |
message.append("Invalid field '").append(field.getLabel()).append("'.\n"); |
885 |
return false; |
886 |
} |
887 |
FeatureAttributeDescriptor descriptor = field.getDescriptor(); |
888 |
switch (this.getRelationalOperator()) { |
889 |
case ExpressionBuilder.OPERATOR_EQ:
|
890 |
case ExpressionBuilder.OPERATOR_NE:
|
891 |
case ExpressionBuilder.OPERATOR_GT:
|
892 |
case ExpressionBuilder.OPERATOR_GE:
|
893 |
case ExpressionBuilder.OPERATOR_LT:
|
894 |
case ExpressionBuilder.OPERATOR_LE:
|
895 |
try {
|
896 |
descriptor.getDataType().coerce(value); |
897 |
} catch (CoercionException ex) {
|
898 |
message.append("Invalid value '")
|
899 |
.append(Objects.toString(value)) |
900 |
.append("' for field '")
|
901 |
.append(descriptor.getLabel()) |
902 |
.append("'.");
|
903 |
message.append("\n");
|
904 |
message.append(ex.getMessage()); |
905 |
message.append("\n");
|
906 |
return false; |
907 |
} |
908 |
break;
|
909 |
|
910 |
default:
|
911 |
case ExpressionBuilder.OPERATOR_ILIKE:
|
912 |
break;
|
913 |
} |
914 |
return true; |
915 |
} catch (Exception ex) { |
916 |
message.append("Invalid values '").append(ex.toString());
|
917 |
return false; |
918 |
} |
919 |
} |
920 |
|
921 |
public ExpressionBuilder.Value getFilter() {
|
922 |
ExpressionBuilder.Value filter = null;
|
923 |
|
924 |
Object value = this.getValue(); |
925 |
if (value == null) { |
926 |
return null; |
927 |
} |
928 |
Field field = this.getCurrentField(); |
929 |
if (field == null) { |
930 |
return null; |
931 |
} |
932 |
if (field.getPath().length > 2) { |
933 |
// No soportado
|
934 |
return null; |
935 |
} |
936 |
DataManager dataManager = DALLocator.getDataManager(); |
937 |
DALExpressionBuilder builder = dataManager.createDALExpressionBuilder(); |
938 |
FeatureAttributeDescriptor parentDescriptor = field.getParentDescriptor(); |
939 |
FeatureAttributeDescriptor descriptor = field.getDescriptor(); |
940 |
|
941 |
ExpressionBuilder.Constant value_constant = null;
|
942 |
|
943 |
switch (this.getRelationalOperator()) { |
944 |
case ExpressionBuilder.OPERATOR_EQ:
|
945 |
case ExpressionBuilder.OPERATOR_NE:
|
946 |
case ExpressionBuilder.OPERATOR_GT:
|
947 |
case ExpressionBuilder.OPERATOR_GE:
|
948 |
case ExpressionBuilder.OPERATOR_LT:
|
949 |
case ExpressionBuilder.OPERATOR_LE:
|
950 |
try {
|
951 |
value_constant = builder.expression().constant( |
952 |
descriptor.getDataType().coerce(value) |
953 |
); |
954 |
} catch (CoercionException ex) {
|
955 |
return null; |
956 |
} |
957 |
break;
|
958 |
|
959 |
default:
|
960 |
case ExpressionBuilder.OPERATOR_ILIKE:
|
961 |
value_constant = builder.expression().constant(value); |
962 |
break;
|
963 |
} |
964 |
|
965 |
if (parentDescriptor == null) { |
966 |
if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NULL) { |
967 |
filter = builder.expression().is_null(builder.expression().column(this.store.getName(), descriptor.getName()));
|
968 |
} else if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
969 |
filter = builder.expression().not_is_null(builder.expression().column(this.store.getName(), descriptor.getName()));
|
970 |
} else {
|
971 |
// Se busca en campos de la misma tabla.
|
972 |
filter = builder.expression().binaryOperator( |
973 |
this.getRelationalOperator(),
|
974 |
builder.expression().column(this.store.getName(), descriptor.getName()),
|
975 |
value_constant |
976 |
); |
977 |
} |
978 |
|
979 |
ExpressionBuilder.Value null_value_constant = null;
|
980 |
ExpressionBuilder.Function null_function = null;
|
981 |
if (this.getRelationalOperator() != ExpressionBuilder.OPERATOR_IS_NULL && this.getRelationalOperator() != ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
982 |
if (this.getNullBehavior() == NULL_AS_TRUE) { |
983 |
null_value_constant = builder.expression().column(this.store.getName(), descriptor.getName());
|
984 |
null_function = builder.expression().is_null(null_value_constant); |
985 |
filter = builder.expression().or(null_function, filter); |
986 |
} else if (this.getNullBehavior() == NULL_AS_FALSE) { |
987 |
null_value_constant = builder.expression().column(this.store.getName(), descriptor.getName());
|
988 |
null_function = builder.expression().not_is_null(null_value_constant); |
989 |
filter = builder.expression().and(null_function, filter); |
990 |
} |
991 |
} |
992 |
|
993 |
} else {
|
994 |
// Se busca en campos de una tabla relacionada.
|
995 |
switch (parentDescriptor.getRelationType()) {
|
996 |
case DynField.RELATION_TYPE_COLLABORATION:
|
997 |
case DynField.RELATION_TYPE_IDENTITY:
|
998 |
if (this.getRelationalOperator() ==ExpressionBuilder.OPERATOR_IS_NULL) { |
999 |
filter = builder.expression().is_null(builder.foreing_value( |
1000 |
parentDescriptor.getName(), |
1001 |
descriptor.getName() |
1002 |
)); |
1003 |
} else if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
1004 |
filter = builder.expression().not_is_null(builder.foreing_value( |
1005 |
parentDescriptor.getName(), |
1006 |
descriptor.getName() |
1007 |
)); |
1008 |
} else {
|
1009 |
filter = builder.expression().binaryOperator( |
1010 |
this.getRelationalOperator(),
|
1011 |
builder.foreing_value( |
1012 |
parentDescriptor.getName(), |
1013 |
descriptor.getName() |
1014 |
), |
1015 |
value_constant |
1016 |
); |
1017 |
ExpressionBuilder.Value null_value_constant = null;
|
1018 |
ExpressionBuilder.Function null_function = null;
|
1019 |
if (this.getNullBehavior() == NULL_AS_TRUE) { |
1020 |
null_value_constant = builder.foreing_value( |
1021 |
parentDescriptor.getName(), |
1022 |
descriptor.getName() |
1023 |
); |
1024 |
null_function = builder.expression().is_null(null_value_constant); |
1025 |
filter = builder.expression().or(null_function, filter); |
1026 |
} else if (this.getNullBehavior() == NULL_AS_FALSE) { |
1027 |
null_value_constant = builder.foreing_value( |
1028 |
parentDescriptor.getName(), |
1029 |
descriptor.getName() |
1030 |
); |
1031 |
null_function = builder.expression().not_is_null(null_value_constant); |
1032 |
filter = builder.expression().and(null_function, filter); |
1033 |
} |
1034 |
|
1035 |
} |
1036 |
break;
|
1037 |
|
1038 |
case DynField.RELATION_TYPE_AGGREGATE:
|
1039 |
case DynField.RELATION_TYPE_COMPOSITION:
|
1040 |
ExpressionBuilder.Value op_composition = null;
|
1041 |
if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NULL) { |
1042 |
op_composition = builder.expression().is_null(builder.expression().column( |
1043 |
field.getFeatureStore().getName(), |
1044 |
descriptor.getName() |
1045 |
)); |
1046 |
} else if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
1047 |
op_composition = builder.expression().not_is_null(builder.expression().column( |
1048 |
field.getFeatureStore().getName(), |
1049 |
descriptor.getName() |
1050 |
)); |
1051 |
} else {
|
1052 |
op_composition = builder.expression().binaryOperator( |
1053 |
this.getRelationalOperator(),
|
1054 |
builder.expression().column( |
1055 |
field.getFeatureStore().getName(), |
1056 |
descriptor.getName() |
1057 |
), |
1058 |
value_constant |
1059 |
); |
1060 |
ExpressionBuilder.Value null_value_constant = null;
|
1061 |
ExpressionBuilder.Function null_function = null;
|
1062 |
if (this.getNullBehavior() == NULL_AS_TRUE) { |
1063 |
null_value_constant = builder.expression().column( |
1064 |
field.getFeatureStore().getName(), |
1065 |
descriptor.getName() |
1066 |
); |
1067 |
null_function = builder.expression().is_null(null_value_constant); |
1068 |
op_composition = builder.expression().or(null_function, op_composition); |
1069 |
} else if (this.getNullBehavior() == NULL_AS_FALSE) { |
1070 |
null_value_constant = builder.expression().column( |
1071 |
field.getFeatureStore().getName(), |
1072 |
descriptor.getName() |
1073 |
); |
1074 |
null_function = builder.expression().not_is_null(null_value_constant); |
1075 |
op_composition = builder.expression().and(null_function, op_composition); |
1076 |
} |
1077 |
} |
1078 |
|
1079 |
filter = builder.exists(builder.select() |
1080 |
.column(parentDescriptor.getFeatureType().getPrimaryKey()[0].getName())
|
1081 |
.from(field.getFeatureStore().getName()) |
1082 |
.limit(1)
|
1083 |
.where( |
1084 |
builder.expression().and( |
1085 |
builder.expression().eq( |
1086 |
builder.expression().column( |
1087 |
field.getFeatureStore().getName(), |
1088 |
getForeingKeyName(field.getFeatureStore(), this.store)
|
1089 |
), |
1090 |
builder.expression().column( |
1091 |
this.store.getName(),
|
1092 |
getPrimaryKeyName(this.store)
|
1093 |
) |
1094 |
), |
1095 |
op_composition |
1096 |
) |
1097 |
) |
1098 |
.toValue() |
1099 |
); |
1100 |
break;
|
1101 |
} |
1102 |
} |
1103 |
|
1104 |
filter = builder.expression().group(filter); |
1105 |
return filter;
|
1106 |
} |
1107 |
|
1108 |
public JsonObject toJson() {
|
1109 |
JsonObjectBuilder fieldBuilder = Json.createObjectBuilder(); |
1110 |
|
1111 |
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); |
1112 |
for (FeatureAttributeDescriptor featureAttributeDescriptor : this.getCurrentField().getPath()) { |
1113 |
JsonArrayBuilder pathArray = Json.createArrayBuilder(); |
1114 |
|
1115 |
//first value: name field
|
1116 |
String fieldName = featureAttributeDescriptor.getName();
|
1117 |
pathArray.add(fieldName); |
1118 |
//second value: name store
|
1119 |
String storeName = featureAttributeDescriptor.getFeatureType().getStore().getName();
|
1120 |
pathArray.add(storeName); |
1121 |
|
1122 |
arrayBuilder.add(pathArray.build()); |
1123 |
} |
1124 |
String relational = this.getRelationalOperator(); |
1125 |
Object value = this.getValue(); |
1126 |
String strValue = DataTypeUtils.toString(value);
|
1127 |
String logical = this.getLogicalOperator(); |
1128 |
|
1129 |
fieldBuilder.add("fieldPath", arrayBuilder.build());
|
1130 |
fieldBuilder.add("relational", relational);
|
1131 |
if (!StringUtils.isEmpty(strValue)) {
|
1132 |
fieldBuilder.add("strValue", strValue);
|
1133 |
} |
1134 |
if (!StringUtils.isEmpty(logical)) {
|
1135 |
fieldBuilder.add("logical", logical);
|
1136 |
} |
1137 |
int nullBehavior = this.getNullBehavior(); |
1138 |
fieldBuilder.add("nullBehavior", nullBehavior);
|
1139 |
return fieldBuilder.build();
|
1140 |
} |
1141 |
|
1142 |
public void fromJson(JsonObject jsonState) { |
1143 |
if (jsonState == null) { |
1144 |
return;
|
1145 |
} |
1146 |
|
1147 |
JsonArray fieldPath = jsonState.getJsonArray("fieldPath");
|
1148 |
|
1149 |
// array of arrays
|
1150 |
String[][] arrayNew = new String[fieldPath.size()][2]; |
1151 |
for (int i = 0; i < fieldPath.size(); i++) { |
1152 |
String[] arrayField = new String[2]; |
1153 |
arrayField[0] = fieldPath.getJsonArray(i).getString(0); |
1154 |
arrayField[1] = fieldPath.getJsonArray(i).getString(1); |
1155 |
arrayNew[i] = arrayField; |
1156 |
} |
1157 |
this.setAttributePath(arrayNew); //usar el doAddAndSelect |
1158 |
|
1159 |
String relational = jsonState.getString("relational"); |
1160 |
this.setRelationalOperator(relational);
|
1161 |
|
1162 |
if (jsonState.containsKey("strValue")) { |
1163 |
String strValue = jsonState.getString("strValue"); |
1164 |
// SwingUtilities.invokeLater(new Runnable() {
|
1165 |
// @Override
|
1166 |
// public void run() {
|
1167 |
setValue(strValue); |
1168 |
// }
|
1169 |
// });
|
1170 |
} |
1171 |
if (jsonState.containsKey("logical")) { |
1172 |
String logical = jsonState.getString("logical"); |
1173 |
this.setLogicalOperator(logical);
|
1174 |
} |
1175 |
if (jsonState.containsKey("nullBehavior")) { |
1176 |
int nullBehavior = jsonState.getInt("nullBehavior"); |
1177 |
this.setNullBehavior(nullBehavior);
|
1178 |
} |
1179 |
|
1180 |
} |
1181 |
|
1182 |
public void setUpdateValuesLimits(int limit, int featuresLimit) { |
1183 |
this.updateValuesTimeLimit = limit;
|
1184 |
this.updateValuesFeaturesLimit = featuresLimit;
|
1185 |
doUpdateValuesList(); |
1186 |
} |
1187 |
|
1188 |
public int getNullBehavior() { |
1189 |
return (int) ((LabeledValue) this.ddnNullBehavior.getSelectedItem()).getValue(); |
1190 |
} |
1191 |
|
1192 |
|
1193 |
public int setNullBehavior(int nullBehaviorValue) { |
1194 |
int n = 0; |
1195 |
for (LabeledValue nullBehavior : nullBehaviors) {
|
1196 |
int toInt = (int) nullBehavior.getValue(); |
1197 |
if (nullBehaviorValue == toInt) {
|
1198 |
break;
|
1199 |
} |
1200 |
n++; |
1201 |
} |
1202 |
if (this.nullBehaviors.length <= n) { |
1203 |
return -1; |
1204 |
} |
1205 |
this.ddnNullBehavior.setSelectedIndex(n);
|
1206 |
return n;
|
1207 |
} |
1208 |
} |