Revision 44748 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
SearchConditionFieldController.java | ||
---|---|---|
11 | 11 |
import java.util.List; |
12 | 12 |
import java.util.Map; |
13 | 13 |
import java.util.Objects; |
14 |
import java.util.UUID; |
|
14 | 15 |
import javax.swing.ComboBoxModel; |
15 | 16 |
import javax.swing.DefaultComboBoxModel; |
16 | 17 |
import javax.swing.ImageIcon; |
17 | 18 |
import javax.swing.JComboBox; |
18 | 19 |
import javax.swing.JLabel; |
20 |
import javax.swing.JOptionPane; |
|
19 | 21 |
import javax.swing.SwingUtilities; |
20 |
import org.apache.commons.lang3.ObjectUtils; |
|
21 | 22 |
import org.apache.commons.lang3.StringUtils; |
22 | 23 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
23 | 24 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
24 | 25 |
import org.gvsig.fmap.dal.DataManager; |
26 |
import org.gvsig.fmap.dal.DataStore; |
|
25 | 27 |
import org.gvsig.fmap.dal.complements.Search; |
26 | 28 |
import org.gvsig.fmap.dal.exception.DataException; |
27 | 29 |
import org.gvsig.fmap.dal.feature.Feature; |
... | ... | |
30 | 32 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
31 | 33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
32 | 34 |
import org.gvsig.fmap.dal.feature.FeatureType; |
35 |
import org.gvsig.fmap.dal.feature.ForeingKey; |
|
33 | 36 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributeSelectionPanel; |
34 | 37 |
import static org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel.getAttributeDescriptorLabel; |
35 | 38 |
import org.gvsig.tools.ToolsLocator; |
36 | 39 |
import org.gvsig.tools.dataTypes.Coercion; |
37 | 40 |
import org.gvsig.tools.dataTypes.CoercionException; |
41 |
import org.gvsig.tools.dynobject.DynField; |
|
38 | 42 |
import org.gvsig.tools.exception.BaseException; |
39 | 43 |
import org.gvsig.tools.i18n.I18nManager; |
40 | 44 |
import org.gvsig.tools.swing.api.DropDown; |
41 | 45 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
42 | 46 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
47 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
|
43 | 48 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
44 | 49 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
45 | 50 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
... | ... | |
58 | 63 |
@SuppressWarnings("UseSpecificCatch") |
59 | 64 |
public class SearchConditionFieldController { |
60 | 65 |
|
61 |
private static final Logger LOGGER = LoggerFactory.getLogger(SearchConditionFieldController.class); |
|
62 |
|
|
63 |
private static class FeatureAttribute extends LabeledValueImpl<String> { |
|
66 |
private static final Logger LOGGER = LoggerFactory.getLogger(SearchConditionFieldController.class); |
|
64 | 67 |
|
65 |
FeatureAttributeDescriptor attrdesc; |
|
66 |
private final FeatureStore store; |
|
67 |
private final int type; |
|
68 |
private final boolean showStoreName; |
|
68 |
private static class Field extends LabeledValueImpl<String> { |
|
69 | 69 |
|
70 |
public FeatureAttribute(FeatureStore store, FeatureAttributeDescriptor attrdesc, int type) { |
|
71 |
this(store, attrdesc, null, type, false); |
|
72 |
} |
|
70 |
FeatureAttributeDescriptor attrdesc; |
|
71 |
private final FeatureStore store; |
|
72 |
private final int presentationMode; |
|
73 |
private final boolean showStoreName; |
|
74 |
private final FeatureAttributeDescriptor[] path; |
|
73 | 75 |
|
74 |
public FeatureAttribute( |
|
75 |
FeatureStore store, |
|
76 |
FeatureAttributeDescriptor attrdesc, |
|
77 |
String value, |
|
78 |
int type, |
|
79 |
boolean showStoreName |
|
80 |
) { |
|
81 |
super( |
|
82 |
getAttributeDescriptorLabel(attrdesc, store.getName()), |
|
83 |
ObjectUtils.defaultIfNull(value, attrdesc.getName()) |
|
84 |
); |
|
85 |
this.store = store; |
|
86 |
this.attrdesc = attrdesc; |
|
87 |
this.type = type; |
|
88 |
this.showStoreName = showStoreName; |
|
89 |
} |
|
76 |
public Field(FeatureAttributeDescriptor[] path, FeatureStore store, FeatureAttributeDescriptor attrdesc, int presentationMode) { |
|
77 |
this(path, store, attrdesc, presentationMode, false); |
|
78 |
} |
|
90 | 79 |
|
91 |
@Override |
|
92 |
public String getLabel() { |
|
93 |
String theLabel = getAttributeDescriptorLabel(attrdesc, showStoreName? store.getName():null); |
|
94 |
switch(this.type) { |
|
95 |
case Search.OrderedAttribute.TYPE_REGURAL: |
|
96 |
break; |
|
97 |
case Search.OrderedAttribute.TYPE_FAVORITE: |
|
98 |
theLabel = "<html><b>"+theLabel+"</b></html>"; |
|
99 |
break; |
|
100 |
case Search.OrderedAttribute.TYPE_RECENT: |
|
101 |
theLabel = "<html><i><b>"+theLabel+"</b></i></html>"; |
|
102 |
break; |
|
103 |
} |
|
104 |
return theLabel; |
|
105 |
} |
|
106 |
|
|
107 |
public FeatureAttributeDescriptor getDescriptor() { |
|
108 |
return this.attrdesc; |
|
109 |
} |
|
80 |
public Field( |
|
81 |
FeatureAttributeDescriptor[] path, |
|
82 |
FeatureStore store, |
|
83 |
FeatureAttributeDescriptor attrdesc, |
|
84 |
int presentationMode, |
|
85 |
boolean showStoreName |
|
86 |
) { |
|
87 |
super( |
|
88 |
getAttributeDescriptorLabel(attrdesc, store.getName()), |
|
89 |
attrdesc.getName() |
|
90 |
); |
|
91 |
this.path = path; |
|
92 |
this.store = store; |
|
93 |
this.attrdesc = attrdesc; |
|
94 |
this.presentationMode = presentationMode; |
|
95 |
this.showStoreName = showStoreName; |
|
96 |
} |
|
97 |
|
|
98 |
public FeatureAttributeDescriptor[] getPath() { |
|
99 |
return this.path; |
|
100 |
} |
|
110 | 101 |
|
111 |
public FeatureStore getFeatureStore() { |
|
112 |
return this.store; |
|
113 |
} |
|
114 |
|
|
115 |
public boolean isExpression() { |
|
116 |
FeatureType type = this.attrdesc.getFeatureType(); |
|
117 |
if (type == null) { |
|
118 |
return false; |
|
119 |
} |
|
120 |
Object x = type.get(this.getValue()); |
|
121 |
return x == null; |
|
122 |
} |
|
102 |
@Override |
|
103 |
public String getLabel() { |
|
104 |
String theLabel = getAttributeDescriptorLabel(attrdesc, showStoreName ? store.getName() : null); |
|
105 |
switch (this.presentationMode) { |
|
106 |
case Search.OrderedAttribute.TYPE_REGURAL: |
|
107 |
break; |
|
108 |
case Search.OrderedAttribute.TYPE_FAVORITE: |
|
109 |
theLabel = "<html><b>" + theLabel + "</b></html>"; |
|
110 |
break; |
|
111 |
case Search.OrderedAttribute.TYPE_RECENT: |
|
112 |
theLabel = "<html><i><b>" + theLabel + "</b></i></html>"; |
|
113 |
break; |
|
114 |
} |
|
115 |
return theLabel; |
|
116 |
} |
|
123 | 117 |
|
118 |
public FeatureAttributeDescriptor getParentDescriptor() { |
|
119 |
int l = this.path.length; |
|
120 |
if( l < 2 ) { |
|
121 |
return null; |
|
122 |
} |
|
123 |
return this.path[l-2]; |
|
124 | 124 |
} |
125 |
|
|
126 |
public FeatureAttributeDescriptor getDescriptor() { |
|
127 |
return this.attrdesc; |
|
128 |
} |
|
125 | 129 |
|
126 |
private FeatureStore store; |
|
127 |
private final JLabel lblFields; |
|
128 |
private final JLabel lblExtraFields; |
|
129 |
private final JLabel lblLogicalOperators; |
|
130 |
private final JLabel lblRelationalOperators; |
|
131 |
private final JComboBox cboValue; |
|
132 |
private Object valueAssigned = null; |
|
130 |
public FeatureStore getFeatureStore() { |
|
131 |
return this.store; |
|
132 |
} |
|
133 | 133 |
|
134 |
private DropDown ddnFields; |
|
135 |
private DropDown ddnLogicalOperators; |
|
136 |
private DropDown ddnRelationalOperators; |
|
134 |
} |
|
137 | 135 |
|
138 |
private LabeledValue[] relationalOperators; |
|
139 |
private LabeledValue[] logicalOperators; |
|
136 |
private FeatureStore store; |
|
137 |
private final JLabel lblFields; |
|
138 |
private final JLabel lblExtraFields; |
|
139 |
private final JLabel lblLogicalOperators; |
|
140 |
private final JLabel lblRelationalOperators; |
|
141 |
private final JComboBox cboValue; |
|
142 |
private Object valueAssigned = null; |
|
140 | 143 |
|
141 |
public SearchConditionFieldController( |
|
142 |
FeatureStore store, |
|
143 |
JLabel lblFields, |
|
144 |
JLabel lblExtraFields, |
|
145 |
JLabel lblRelationalOperators, |
|
146 |
JComboBox cboValue, |
|
147 |
JLabel lblLogicalOperators |
|
148 |
) { |
|
149 |
this.store = store; |
|
150 |
this.lblFields = lblFields; |
|
151 |
this.lblExtraFields = lblExtraFields; |
|
152 |
this.lblRelationalOperators = lblRelationalOperators; |
|
153 |
this.cboValue = cboValue; |
|
154 |
this.lblLogicalOperators = lblLogicalOperators; |
|
155 |
this.initComponents(); |
|
156 |
} |
|
144 |
private DropDown ddnFields; |
|
145 |
private DropDown ddnLogicalOperators; |
|
146 |
private DropDown ddnRelationalOperators; |
|
157 | 147 |
|
158 |
public boolean isAValidRelationOperator(String name) { |
|
159 |
for (LabeledValue relationalOperator : relationalOperators) { |
|
160 |
if( StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
|
161 |
return true; |
|
162 |
} |
|
163 |
} |
|
164 |
return false; |
|
148 |
private LabeledValue[] relationalOperators; |
|
149 |
private LabeledValue[] logicalOperators; |
|
150 |
|
|
151 |
public SearchConditionFieldController( |
|
152 |
FeatureStore store, |
|
153 |
JLabel lblFields, |
|
154 |
JLabel lblExtraFields, |
|
155 |
JLabel lblRelationalOperators, |
|
156 |
JComboBox cboValue, |
|
157 |
JLabel lblLogicalOperators |
|
158 |
) { |
|
159 |
this.store = store; |
|
160 |
this.lblFields = lblFields; |
|
161 |
this.lblExtraFields = lblExtraFields; |
|
162 |
this.lblRelationalOperators = lblRelationalOperators; |
|
163 |
this.cboValue = cboValue; |
|
164 |
this.lblLogicalOperators = lblLogicalOperators; |
|
165 |
this.initComponents(); |
|
166 |
} |
|
167 |
|
|
168 |
public boolean isAValidRelationOperator(String name) { |
|
169 |
for (LabeledValue relationalOperator : relationalOperators) { |
|
170 |
if (StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
|
171 |
return true; |
|
172 |
} |
|
165 | 173 |
} |
166 |
|
|
167 |
private void initComponents() { |
|
168 |
try { |
|
169 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
170 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
171 |
|
|
172 |
relationalOperators = new LabeledValue[] { |
|
173 |
new LabeledValueImpl(i18n.getTranslation("_Equals_to"), ExpressionBuilder.OPERATOR_EQ), |
|
174 |
new LabeledValueImpl(i18n.getTranslation("_Like_to"), ExpressionBuilder.OPERATOR_ILIKE), |
|
175 |
new LabeledValueImpl(i18n.getTranslation("_Not_equals_to"), ExpressionBuilder.OPERATOR_NE), |
|
176 |
new LabeledValueImpl(i18n.getTranslation("_Greater_than"), ExpressionBuilder.OPERATOR_GT), |
|
177 |
new LabeledValueImpl(i18n.getTranslation("_Greater_or_equal_to"), ExpressionBuilder.OPERATOR_GE), |
|
178 |
new LabeledValueImpl(i18n.getTranslation("_Less_than"), ExpressionBuilder.OPERATOR_LT), |
|
179 |
new LabeledValueImpl(i18n.getTranslation("_Less_or_equal_to"), ExpressionBuilder.OPERATOR_LE) |
|
180 |
}; |
|
174 |
return false; |
|
175 |
} |
|
181 | 176 |
|
182 |
logicalOperators = new LabeledValue[] { |
|
183 |
new LabeledValueImpl(i18n.getTranslation("_Or"), ExpressionBuilder.OPERATOR_OR), |
|
184 |
new LabeledValueImpl(i18n.getTranslation("_And"), ExpressionBuilder.OPERATOR_AND) |
|
185 |
}; |
|
186 |
|
|
187 |
this.lblExtraFields.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
|
177 |
private void initComponents() { |
|
178 |
try { |
|
179 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
180 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
188 | 181 |
|
189 |
this.ddnFields = toolsSwingManager.createDropDown(lblFields); |
|
190 |
this.ddnFields.setVisibleDropdownArrow(false); |
|
191 |
this.ddnRelationalOperators = toolsSwingManager.createDropDown(lblRelationalOperators); |
|
192 |
this.ddnRelationalOperators.setVisibleDropdownArrow(false); |
|
193 |
if (lblLogicalOperators != null) { |
|
194 |
this.ddnLogicalOperators = toolsSwingManager.createDropDown(lblLogicalOperators); |
|
195 |
this.ddnLogicalOperators.setVisibleDropdownArrow(false); |
|
196 |
} |
|
182 |
relationalOperators = new LabeledValue[]{ |
|
183 |
new LabeledValueImpl(i18n.getTranslation("_Equals_to"), ExpressionBuilder.OPERATOR_EQ), |
|
184 |
new LabeledValueImpl(i18n.getTranslation("_Like_to"), ExpressionBuilder.OPERATOR_ILIKE), |
|
185 |
new LabeledValueImpl(i18n.getTranslation("_Not_equals_to"), ExpressionBuilder.OPERATOR_NE), |
|
186 |
new LabeledValueImpl(i18n.getTranslation("_Greater_than"), ExpressionBuilder.OPERATOR_GT), |
|
187 |
new LabeledValueImpl(i18n.getTranslation("_Greater_or_equal_to"), ExpressionBuilder.OPERATOR_GE), |
|
188 |
new LabeledValueImpl(i18n.getTranslation("_Less_than"), ExpressionBuilder.OPERATOR_LT), |
|
189 |
new LabeledValueImpl(i18n.getTranslation("_Less_or_equal_to"), ExpressionBuilder.OPERATOR_LE) |
|
190 |
}; |
|
197 | 191 |
|
198 |
DefaultComboBoxModel modelRelationalOperators = new DefaultComboBoxModel(); |
|
199 |
for (LabeledValue op : relationalOperators) { |
|
200 |
modelRelationalOperators.addElement(op); |
|
201 |
} |
|
202 |
this.ddnRelationalOperators.setModel(modelRelationalOperators); |
|
192 |
logicalOperators = new LabeledValue[]{ |
|
193 |
new LabeledValueImpl(i18n.getTranslation("_Or"), ExpressionBuilder.OPERATOR_OR), |
|
194 |
new LabeledValueImpl(i18n.getTranslation("_And"), ExpressionBuilder.OPERATOR_AND) |
|
195 |
}; |
|
203 | 196 |
|
204 |
if (this.ddnLogicalOperators != null) { |
|
205 |
DefaultComboBoxModel modelLogicalOperators = new DefaultComboBoxModel(); |
|
206 |
for (LabeledValue op : logicalOperators) { |
|
207 |
modelLogicalOperators.addElement(op); |
|
208 |
} |
|
209 |
this.ddnLogicalOperators.setModel(modelLogicalOperators); |
|
210 |
} |
|
211 |
FeatureType featureType = store.getDefaultFeatureType(); |
|
212 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
|
213 |
Search.COMPLEMENT_MANE, featureType |
|
214 |
); |
|
215 |
List<Search.OrderedAttribute> orderedAttributes = search.getOrderedAttributes( |
|
216 |
Search.BASIC_TYPES_FILTER, |
|
217 |
Search.STR_INT_LONG_LABEL_ORDER, |
|
218 |
20 |
|
219 |
); |
|
220 |
List<ImageIcon>icons = new ArrayList<>(); |
|
197 |
this.lblExtraFields.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
|
198 |
|
|
199 |
this.ddnFields = toolsSwingManager.createDropDown(lblFields); |
|
200 |
this.ddnFields.setVisibleDropdownArrow(false); |
|
201 |
this.ddnRelationalOperators = toolsSwingManager.createDropDown(lblRelationalOperators); |
|
202 |
this.ddnRelationalOperators.setVisibleDropdownArrow(false); |
|
203 |
if (lblLogicalOperators != null) { |
|
204 |
this.ddnLogicalOperators = toolsSwingManager.createDropDown(lblLogicalOperators); |
|
205 |
this.ddnLogicalOperators.setVisibleDropdownArrow(false); |
|
206 |
} |
|
207 |
|
|
208 |
DefaultComboBoxModel modelRelationalOperators = new DefaultComboBoxModel(); |
|
209 |
for (LabeledValue op : relationalOperators) { |
|
210 |
modelRelationalOperators.addElement(op); |
|
211 |
} |
|
212 |
this.ddnRelationalOperators.setModel(modelRelationalOperators); |
|
213 |
|
|
214 |
if (this.ddnLogicalOperators != null) { |
|
215 |
DefaultComboBoxModel modelLogicalOperators = new DefaultComboBoxModel(); |
|
216 |
for (LabeledValue op : logicalOperators) { |
|
217 |
modelLogicalOperators.addElement(op); |
|
218 |
} |
|
219 |
this.ddnLogicalOperators.setModel(modelLogicalOperators); |
|
220 |
} |
|
221 |
FeatureType featureType = store.getDefaultFeatureType(); |
|
222 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
|
223 |
Search.COMPLEMENT_MANE, featureType |
|
224 |
); |
|
225 |
List<Search.OrderedAttribute> orderedAttributes = search.getOrderedAttributes( |
|
226 |
Search.BASIC_TYPES_FILTER, |
|
227 |
Search.STR_INT_LONG_LABEL_ORDER, |
|
228 |
20 |
|
229 |
); |
|
230 |
List<ImageIcon> icons = new ArrayList<>(); |
|
221 | 231 |
// DataTypesManager dataTypeManager = ToolsLocator.getDataTypesManager(); |
222 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
|
223 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
224 |
for (Search.OrderedAttribute attr : orderedAttributes) { |
|
225 |
FeatureAttributeDescriptor attrdesc = attr.getDescriptor(); |
|
226 |
model.addElement(new FeatureAttribute(this.store, attrdesc, attr.getType())); |
|
227 |
String iconName = attrdesc.getDataType().getIconName(); |
|
228 |
if( iconTheme.exists(iconName) ) { |
|
229 |
icons.add(iconTheme.get(iconName)); |
|
230 |
} else { |
|
231 |
icons.add(null); |
|
232 |
} |
|
233 |
} |
|
234 |
this.ddnFields.setIcons(icons); |
|
235 |
this.ddnFields.setModel(model); |
|
236 |
this.ddnFields.addItemListener(new ItemListener() { |
|
237 |
@Override |
|
238 |
public void itemStateChanged(ItemEvent e) { |
|
239 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
240 |
doUpdateValuesList(); |
|
241 |
} |
|
232 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
|
233 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
234 |
for (Search.OrderedAttribute attr : orderedAttributes) { |
|
235 |
FeatureAttributeDescriptor attrdesc = attr.getDescriptor(); |
|
236 |
Field field = new Field( |
|
237 |
new FeatureAttributeDescriptor[] { attrdesc }, |
|
238 |
this.store, |
|
239 |
attrdesc, |
|
240 |
attr.getType() |
|
241 |
); |
|
242 |
model.addElement(field); |
|
243 |
String iconName = attrdesc.getDataType().getIconName(); |
|
244 |
if (iconTheme.exists(iconName)) { |
|
245 |
icons.add(iconTheme.get(iconName)); |
|
246 |
} else { |
|
247 |
icons.add(null); |
|
248 |
} |
|
249 |
} |
|
250 |
this.ddnFields.setIcons(icons); |
|
251 |
this.ddnFields.setModel(model); |
|
252 |
this.ddnFields.addItemListener(new ItemListener() { |
|
253 |
@Override |
|
254 |
public void itemStateChanged(ItemEvent e) { |
|
255 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
256 |
doUpdateValuesList(); |
|
257 |
} |
|
242 | 258 |
|
243 |
}
|
|
244 |
});
|
|
259 |
} |
|
260 |
}); |
|
245 | 261 |
|
246 |
this.lblExtraFields.addMouseListener(new MouseAdapter() { |
|
247 |
@Override |
|
248 |
public void mouseClicked(MouseEvent e) { |
|
249 |
doSelectExtraField(); |
|
250 |
} |
|
251 |
}); |
|
252 |
clear(); |
|
253 |
} catch (Exception ex) { |
|
254 |
throw new RuntimeException(ex); |
|
262 |
this.lblExtraFields.addMouseListener(new MouseAdapter() { |
|
263 |
@Override |
|
264 |
public void mouseClicked(MouseEvent e) { |
|
265 |
doSelectMoreFields(); |
|
255 | 266 |
} |
267 |
}); |
|
268 |
clear(); |
|
269 |
} catch (Exception ex) { |
|
270 |
throw new RuntimeException(ex); |
|
256 | 271 |
} |
272 |
} |
|
257 | 273 |
|
258 |
private FeatureType getFeatureType() { |
|
259 |
try { |
|
260 |
return this.store.getDefaultFeatureType(); |
|
261 |
} catch (DataException ex) { |
|
262 |
return null; |
|
263 |
} |
|
274 |
private FeatureType getFeatureType() { |
|
275 |
try { |
|
276 |
return this.store.getDefaultFeatureType(); |
|
277 |
} catch (DataException ex) { |
|
278 |
return null; |
|
264 | 279 |
} |
280 |
} |
|
265 | 281 |
|
266 |
private void doSelectExtraField() { |
|
267 |
DefaultFeatureAttributeSelectionPanel panel = new DefaultFeatureAttributeSelectionPanel(store); |
|
268 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
269 |
final Dialog dialog = winManager.createDialog( |
|
270 |
panel, |
|
271 |
"Select attribute", |
|
272 |
null, |
|
273 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
282 |
private void doSelectMoreFields() { |
|
283 |
DefaultFeatureAttributeSelectionPanel panel = new DefaultFeatureAttributeSelectionPanel(store); |
|
284 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
285 |
final Dialog dialog = winManager.createDialog( |
|
286 |
panel, |
|
287 |
"Select attribute", |
|
288 |
null, |
|
289 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
290 |
); |
|
291 |
dialog.addActionListener((ActionEvent e) -> { |
|
292 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) { |
|
293 |
doAddAndSelect( |
|
294 |
panel.getSelectedStore(), |
|
295 |
panel.getSelectedAttributeDescriptor(), |
|
296 |
panel.getSelectedPath() |
|
274 | 297 |
); |
275 |
dialog.addActionListener((ActionEvent e) -> { |
|
276 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) { |
|
277 |
doAddAndSelect( |
|
278 |
panel.getSelectedStore(), |
|
279 |
panel.getSelectedAttributeDescriptor(), |
|
280 |
panel.getSelectedPath() |
|
281 |
); |
|
282 |
} |
|
283 |
}); |
|
284 |
dialog.show(WindowManager.MODE.DIALOG); |
|
298 |
} |
|
299 |
}); |
|
300 |
dialog.show(WindowManager.MODE.DIALOG); |
|
285 | 301 |
|
302 |
} |
|
303 |
|
|
304 |
private void doAddAndSelect(FeatureStore theStore, FeatureAttributeDescriptor attrdesc, FeatureAttributeDescriptor[] path) { |
|
305 |
DefaultComboBoxModel<Field> model = (DefaultComboBoxModel) this.ddnFields.getModel(); |
|
306 |
for (int i = 0; i < model.getSize(); i++) { |
|
307 |
Field field = model.getElementAt(i); |
|
308 |
FeatureAttributeDescriptor attrdescN = field.getDescriptor(); |
|
309 |
if ( isTheSameStore(theStore, attrdescN.getStore()) |
|
310 |
&& StringUtils.equalsIgnoreCase(attrdesc.getName(), attrdescN.getName())) { |
|
311 |
this.setAttribute(i); |
|
312 |
return; |
|
313 |
} |
|
286 | 314 |
} |
287 |
|
|
288 |
private void doAddAndSelect(FeatureStore theStore, FeatureAttributeDescriptor attrdesc, FeatureAttributeDescriptor[] attributes) { |
|
289 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
|
290 |
List<String> list = new ArrayList<>(); |
|
291 |
for (FeatureAttributeDescriptor attribute : attributes) { |
|
292 |
list.add(attribute.getName()); |
|
315 |
Field field = new Field( |
|
316 |
path, |
|
317 |
theStore, |
|
318 |
attrdesc, |
|
319 |
Search.OrderedAttribute.TYPE_REGURAL, |
|
320 |
!isTheSameStore(store, theStore) |
|
321 |
); |
|
322 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
323 |
if( field.getPath().length>2 ) { |
|
324 |
dialogManager.messageDialog( |
|
325 |
"It not supported to search through this field." + "\n" |
|
326 |
+ "Too many links.", |
|
327 |
"_Warning", |
|
328 |
JOptionPane.WARNING_MESSAGE |
|
329 |
); |
|
330 |
return; |
|
331 |
} |
|
332 |
FeatureAttributeDescriptor parentDescriptor = field.getParentDescriptor(); |
|
333 |
switch(parentDescriptor.getRelationType()) { |
|
334 |
case DynField.RELATION_TYPE_AGGREGATE: |
|
335 |
case DynField.RELATION_TYPE_COMPOSITION: |
|
336 |
if( getForeingKeyName(field.getFeatureStore(), this.store)==null ) { |
|
337 |
dialogManager.messageDialog( |
|
338 |
"It not supported to search through this field." + "\n" |
|
339 |
+ "The link field was not found.", |
|
340 |
"_Warning", |
|
341 |
JOptionPane.WARNING_MESSAGE |
|
342 |
); |
|
343 |
return; |
|
293 | 344 |
} |
294 |
String storeFullName = theStore.getFullName(); |
|
295 |
DefaultComboBoxModel<FeatureAttribute> model = (DefaultComboBoxModel) this.ddnFields.getModel(); |
|
296 |
for (int i = 0; i < model.getSize(); i++) { |
|
297 |
FeatureAttribute attr = model.getElementAt(i); |
|
298 |
FeatureAttributeDescriptor attrdescN = attr.getDescriptor(); |
|
299 |
if (StringUtils.equalsIgnoreCase(storeFullName, attrdescN.getStore().getFullName()) |
|
300 |
&& StringUtils.equalsIgnoreCase(attrdesc.getName(), attrdescN.getName())) { |
|
301 |
this.setAttribute(i); |
|
302 |
return; |
|
303 |
} |
|
345 |
if( getPrimaryKeyName(this.store)==null ) { |
|
346 |
dialogManager.messageDialog( |
|
347 |
"It not supported to search through this field." + "\n" |
|
348 |
+ "A simple primary key was not found.", |
|
349 |
"_Warning", |
|
350 |
JOptionPane.WARNING_MESSAGE |
|
351 |
); |
|
352 |
return; |
|
304 | 353 |
} |
305 |
String formula; |
|
306 |
boolean showStoreName; |
|
307 |
if (StringUtils.equalsIgnoreCase(storeFullName, this.store.getFullName())) { |
|
308 |
formula = attrdesc.getName(); |
|
309 |
showStoreName = false; |
|
310 |
} else { |
|
311 |
formula = builder.function( |
|
312 |
DataManager.FUNCTION_FOREING_VALUE, |
|
313 |
builder.constant(StringUtils.join(list,".")) |
|
314 |
).toString(); |
|
315 |
showStoreName = true; |
|
316 |
} |
|
317 |
FeatureAttribute attribute = new FeatureAttribute(theStore, attrdesc, formula, Search.OrderedAttribute.TYPE_REGURAL, showStoreName); |
|
318 |
model.addElement(attribute); |
|
319 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
|
320 |
this.ddnFields.getIcons().add(iconTheme.get(attrdesc.getDataType().getIconName())); |
|
321 |
this.setAttribute(model.getSize() - 1); |
|
322 | 354 |
} |
355 |
model.addElement(field); |
|
356 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
|
357 |
this.ddnFields.getIcons().add(iconTheme.get(attrdesc.getDataType().getIconName())); |
|
358 |
this.setAttribute(model.getSize() - 1); |
|
359 |
} |
|
323 | 360 |
|
324 |
public void clear() { |
|
325 |
this.ddnRelationalOperators.setSelectedIndex(0); |
|
326 |
if (this.ddnLogicalOperators != null) { |
|
327 |
this.ddnLogicalOperators.setSelectedIndex(0); |
|
328 |
} |
|
329 |
this.cboValue.setSelectedIndex(-1); |
|
361 |
public void clear() { |
|
362 |
this.ddnRelationalOperators.setSelectedIndex(0); |
|
363 |
if (this.ddnLogicalOperators != null) { |
|
364 |
this.ddnLogicalOperators.setSelectedIndex(0); |
|
330 | 365 |
} |
366 |
this.cboValue.setSelectedIndex(-1); |
|
367 |
} |
|
331 | 368 |
|
332 |
private void doUpdateValuesList() {
|
|
333 |
final FeatureAttribute attribute = (FeatureAttribute) this.ddnFields.getSelectedItem();
|
|
334 |
if (attribute == null) {
|
|
335 |
return;
|
|
336 |
}
|
|
369 |
private void doUpdateValuesList() { |
|
370 |
final Field field = (Field) this.ddnFields.getSelectedItem();
|
|
371 |
if (field == null) {
|
|
372 |
return; |
|
373 |
} |
|
337 | 374 |
|
338 |
final List<Object> values = new ArrayList<>(); |
|
339 |
final int limit = 60; |
|
340 |
final long timeLimit = System.currentTimeMillis() + limit * 1000; |
|
341 |
final DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
342 |
this.setEnabled(false); |
|
343 |
final FeatureStore theStore = attribute.getFeatureStore(); |
|
344 |
final FeatureQuery query = theStore.createFeatureQuery(); |
|
345 |
query.addAttributeName(attribute.getDescriptor().getName()); |
|
346 |
query.setLimit(1000); |
|
347 |
Thread th = new Thread(new Runnable() { |
|
375 |
final List<Object> values = new ArrayList<>(); |
|
376 |
final int limit = 60; |
|
377 |
final long timeLimit = System.currentTimeMillis() + limit * 1000; |
|
378 |
final DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
379 |
this.setEnabled(false); |
|
380 |
final FeatureStore theStore = field.getFeatureStore(); |
|
381 |
final FeatureQuery query = theStore.createFeatureQuery(); |
|
382 |
query.addAttributeName(field.getDescriptor().getName()); |
|
383 |
query.setLimit(1000); |
|
384 |
Thread th = new Thread(new Runnable() { |
|
385 |
@Override |
|
386 |
public void run() { |
|
387 |
try { |
|
388 |
FeatureSet set = theStore.getFeatureSet(query); |
|
389 |
set.accept(new Visitor() { |
|
348 | 390 |
@Override |
349 |
public void run() { |
|
350 |
try { |
|
351 |
FeatureSet set = theStore.getFeatureSet(query); |
|
352 |
set.accept(new Visitor() { |
|
353 |
@Override |
|
354 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
|
355 |
Object value = ((Feature) o).get(attribute.getDescriptor().getName()); |
|
356 |
if (!values.contains(value)) { |
|
357 |
values.add(value); |
|
358 |
} |
|
359 |
if (System.currentTimeMillis() > timeLimit) { |
|
360 |
throw new VisitCanceledException(); |
|
361 |
} |
|
362 |
if (values.size() > 1000) { |
|
363 |
throw new VisitCanceledException(); |
|
364 |
} |
|
365 |
} |
|
366 |
}); |
|
367 |
} catch (VisitCanceledException ex) { |
|
391 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
|
392 |
Object value = ((Feature) o).get(field.getDescriptor().getName()); |
|
393 |
if (!values.contains(value)) { |
|
394 |
values.add(value); |
|
395 |
} |
|
396 |
if (System.currentTimeMillis() > timeLimit) { |
|
397 |
throw new VisitCanceledException(); |
|
398 |
} |
|
399 |
if (values.size() > 1000) { |
|
400 |
throw new VisitCanceledException(); |
|
401 |
} |
|
402 |
} |
|
403 |
}); |
|
404 |
} catch (VisitCanceledException ex) { |
|
368 | 405 |
|
369 |
} catch (Exception ex) { |
|
370 |
LOGGER.warn("Can't update list of values of '"+attribute.getLabel()+"'.", ex); |
|
371 |
} |
|
372 |
List<LabeledValue> elements = new ArrayList<>(); |
|
373 |
if (!values.isEmpty()) { |
|
374 |
LabeledValue[] availableValues = attribute.getDescriptor().getAvailableValues(); |
|
375 |
Map<String, String> availableValuesMap = new HashMap<>(); |
|
376 |
if (availableValues != null) { |
|
377 |
for (LabeledValue availableValue : availableValues) { |
|
378 |
availableValuesMap.put( |
|
379 |
Objects.toString(availableValue.getValue()), |
|
380 |
availableValue.getLabel() |
|
381 |
); |
|
382 |
} |
|
383 |
} |
|
384 |
elements.add(new LabeledValueImpl("", null)); |
|
385 |
for (Object value : values) { |
|
386 |
String key = Objects.toString(value); |
|
387 |
String label = availableValuesMap.getOrDefault(key, key); |
|
388 |
elements.add(new LabeledValueImpl(label, value)); |
|
389 |
} |
|
390 |
elements.sort(null); |
|
391 |
|
|
392 |
} |
|
393 |
for (LabeledValue element : elements) { |
|
394 |
model.addElement(element); |
|
395 |
} |
|
396 |
SwingUtilities.invokeLater(new Runnable() { |
|
397 |
@Override |
|
398 |
public void run() { |
|
399 |
cboValue.setModel(model); |
|
400 |
if( valueAssigned!=null ) { |
|
401 |
cboValue.setSelectedItem(valueAssigned); |
|
402 |
valueAssigned = null; |
|
403 |
} |
|
404 |
setEnabled(true); |
|
405 |
} |
|
406 |
}); |
|
406 |
} catch (Exception ex) { |
|
407 |
LOGGER.warn("Can't update list of values of '" + field.getLabel() + "'.", ex); |
|
408 |
} |
|
409 |
List<LabeledValue> elements = new ArrayList<>(); |
|
410 |
if (!values.isEmpty()) { |
|
411 |
LabeledValue[] availableValues = field.getDescriptor().getAvailableValues(); |
|
412 |
Map<String, String> availableValuesMap = new HashMap<>(); |
|
413 |
if (availableValues != null) { |
|
414 |
for (LabeledValue availableValue : availableValues) { |
|
415 |
availableValuesMap.put( |
|
416 |
Objects.toString(availableValue.getValue()), |
|
417 |
availableValue.getLabel() |
|
418 |
); |
|
407 | 419 |
} |
420 |
} |
|
421 |
elements.add(new LabeledValueImpl("", null)); |
|
422 |
for (Object value : values) { |
|
423 |
String key = Objects.toString(value); |
|
424 |
String label = availableValuesMap.getOrDefault(key, key); |
|
425 |
elements.add(new LabeledValueImpl(label, value)); |
|
426 |
} |
|
427 |
elements.sort(null); |
|
428 |
|
|
429 |
} |
|
430 |
for (LabeledValue element : elements) { |
|
431 |
model.addElement(element); |
|
432 |
} |
|
433 |
SwingUtilities.invokeLater(new Runnable() { |
|
434 |
@Override |
|
435 |
public void run() { |
|
436 |
cboValue.setModel(model); |
|
437 |
if (valueAssigned != null) { |
|
438 |
cboValue.setSelectedItem(valueAssigned); |
|
439 |
valueAssigned = null; |
|
440 |
} |
|
441 |
setEnabled(true); |
|
442 |
} |
|
408 | 443 |
}); |
409 |
th.start(); |
|
444 |
} |
|
445 |
}); |
|
446 |
th.start(); |
|
447 |
} |
|
448 |
|
|
449 |
public void setEnabled(boolean enabled) { |
|
450 |
this.ddnFields.setEnabled(enabled); |
|
451 |
if (this.ddnLogicalOperators != null) { |
|
452 |
this.ddnLogicalOperators.setEnabled(enabled); |
|
410 | 453 |
} |
454 |
this.ddnRelationalOperators.setEnabled(enabled); |
|
455 |
this.lblExtraFields.setEnabled(enabled); |
|
456 |
} |
|
411 | 457 |
|
412 |
public void setEnabled(boolean enabled) { |
|
413 |
this.ddnFields.setEnabled(enabled); |
|
414 |
if( this.ddnLogicalOperators!=null ) { |
|
415 |
this.ddnLogicalOperators.setEnabled(enabled); |
|
416 |
} |
|
417 |
this.ddnRelationalOperators.setEnabled(enabled); |
|
418 |
this.lblExtraFields.setEnabled(enabled); |
|
458 |
public String getRelationalOperator() { |
|
459 |
LabeledValue<String> op = (LabeledValue) this.ddnRelationalOperators.getSelectedItem(); |
|
460 |
if (op == null) { |
|
461 |
return null; |
|
419 | 462 |
} |
420 |
|
|
421 |
public String getRelationalOperator() { |
|
422 |
LabeledValue<String> op = (LabeledValue) this.ddnRelationalOperators.getSelectedItem(); |
|
423 |
if (op == null) { |
|
424 |
return null; |
|
425 |
} |
|
426 |
return op.getValue(); |
|
463 |
return op.getValue(); |
|
464 |
} |
|
465 |
|
|
466 |
public int setRelationalOperator(String name) { |
|
467 |
int n = 0; |
|
468 |
for (LabeledValue relationalOperator : relationalOperators) { |
|
469 |
if (StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
|
470 |
break; |
|
471 |
} |
|
472 |
n++; |
|
427 | 473 |
} |
474 |
if (this.relationalOperators.length <= n) { |
|
475 |
return -1; |
|
476 |
} |
|
477 |
this.ddnRelationalOperators.setSelectedIndex(n); |
|
478 |
return n; |
|
479 |
} |
|
428 | 480 |
|
429 |
public int setRelationalOperator(String name) { |
|
430 |
int n = 0; |
|
431 |
for (LabeledValue relationalOperator : relationalOperators) { |
|
432 |
if( StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
|
433 |
break; |
|
434 |
} |
|
435 |
n++; |
|
436 |
} |
|
437 |
if( this.relationalOperators.length<=n ) { |
|
438 |
return -1; |
|
439 |
} |
|
440 |
this.ddnRelationalOperators.setSelectedIndex(n); |
|
441 |
return n; |
|
481 |
public String getLogicalOperator() { |
|
482 |
if (this.ddnLogicalOperators == null) { |
|
483 |
return null; |
|
442 | 484 |
} |
443 |
|
|
444 |
public String getLogicalOperator() { |
|
445 |
if (this.ddnLogicalOperators == null) { |
|
446 |
return null; |
|
447 |
} |
|
448 |
LabeledValue<String> rel = (LabeledValue) this.ddnLogicalOperators.getSelectedItem(); |
|
449 |
if (rel == null) { |
|
450 |
return null; |
|
451 |
} |
|
452 |
return rel.getValue(); |
|
485 |
LabeledValue<String> rel = (LabeledValue) this.ddnLogicalOperators.getSelectedItem(); |
|
486 |
if (rel == null) { |
|
487 |
return null; |
|
453 | 488 |
} |
489 |
return rel.getValue(); |
|
490 |
} |
|
454 | 491 |
|
455 |
public Object getValue() { |
|
456 |
final FeatureAttribute attribute = (FeatureAttribute) this.ddnFields.getSelectedItem(); |
|
457 |
if (attribute == null) { |
|
458 |
return null; |
|
459 |
} |
|
460 |
Object v = this.cboValue.getSelectedItem(); |
|
461 |
if (v == null) { |
|
462 |
return null; |
|
463 |
} |
|
464 |
if (v instanceof LabeledValue) { |
|
465 |
v = ((LabeledValue) v).getValue(); |
|
466 |
if (v == null) { |
|
467 |
return null; |
|
468 |
} |
|
469 |
} |
|
470 |
if (v instanceof CharSequence) { |
|
471 |
if (StringUtils.isBlank((CharSequence) v)) { |
|
472 |
return null; |
|
473 |
} |
|
474 |
} |
|
475 |
Coercion coercion = attribute.getDescriptor().getDataType().getCoercion(); |
|
476 |
try { |
|
477 |
return coercion.coerce(v); |
|
478 |
} catch (CoercionException ex) { |
|
479 |
return null; |
|
480 |
} |
|
492 |
public Object getValue() { |
|
493 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
|
494 |
if (field == null) { |
|
495 |
return null; |
|
481 | 496 |
} |
482 |
|
|
483 |
public void setValue(Object value) { |
|
484 |
this.cboValue.setSelectedItem(value); |
|
485 |
this.valueAssigned = value; |
|
497 |
Object v = this.cboValue.getSelectedItem(); |
|
498 |
if (v == null) { |
|
499 |
return null; |
|
486 | 500 |
} |
487 |
|
|
488 |
public boolean isAttributeAnExpression() { |
|
489 |
final FeatureAttribute attribute = (FeatureAttribute) this.ddnFields.getSelectedItem(); |
|
490 |
if (attribute == null) { |
|
491 |
return false; |
|
492 |
} |
|
493 |
return attribute.isExpression(); |
|
501 |
if (v instanceof LabeledValue) { |
|
502 |
v = ((LabeledValue) v).getValue(); |
|
503 |
if (v == null) { |
|
504 |
return null; |
|
505 |
} |
|
494 | 506 |
} |
507 |
if (v instanceof CharSequence) { |
|
508 |
if (StringUtils.isBlank((CharSequence) v)) { |
|
509 |
return null; |
|
510 |
} |
|
511 |
} |
|
512 |
Coercion coercion = field.getDescriptor().getDataType().getCoercion(); |
|
513 |
try { |
|
514 |
return coercion.coerce(v); |
|
515 |
} catch (CoercionException ex) { |
|
516 |
return null; |
|
517 |
} |
|
518 |
} |
|
495 | 519 |
|
496 |
public String getAttribute() { |
|
497 |
final FeatureAttribute attribute = (FeatureAttribute) this.ddnFields.getSelectedItem(); |
|
498 |
if (attribute == null) { |
|
499 |
return null; |
|
500 |
} |
|
501 |
if( this.getValue()!=null ) { |
|
502 |
attribute.getDescriptor().recentUsed(); |
|
503 |
} |
|
504 |
return attribute.getValue(); |
|
520 |
public void setValue(Object value) { |
|
521 |
this.cboValue.setSelectedItem(value); |
|
522 |
this.valueAssigned = value; |
|
523 |
} |
|
524 |
|
|
525 |
private Field getCurrentField() { |
|
526 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
|
527 |
return field; |
|
528 |
} |
|
529 |
|
|
530 |
public int setAttribute(String name) { |
|
531 |
ComboBoxModel<Field> model = this.ddnFields.getModel(); |
|
532 |
for (int i = 0; i < model.getSize(); i++) { |
|
533 |
Field x = model.getElementAt(i); |
|
534 |
if (StringUtils.equalsIgnoreCase(name, x.getValue())) { |
|
535 |
this.setAttribute(i); |
|
536 |
return i; |
|
537 |
} |
|
505 | 538 |
} |
539 |
this.setAttribute(-1); |
|
540 |
return -1; |
|
541 |
} |
|
506 | 542 |
|
507 |
public int setAttribute(String name) { |
|
508 |
ComboBoxModel<FeatureAttribute> model = this.ddnFields.getModel(); |
|
509 |
for (int i = 0; i < model.getSize(); i++) { |
|
510 |
FeatureAttribute x = model.getElementAt(i); |
|
511 |
if (StringUtils.equalsIgnoreCase(name, x.getValue())) { |
|
512 |
this.setAttribute(i); |
|
513 |
return i; |
|
514 |
} |
|
515 |
} |
|
516 |
this.setAttribute(-1); |
|
517 |
return -1; |
|
543 |
public void setAttribute(int index) { |
|
544 |
try { |
|
545 |
this.ddnFields.setSelectedIndex(index); |
|
546 |
} catch (Exception ex) { |
|
547 |
this.ddnFields.setSelectedIndex(-1); |
|
518 | 548 |
} |
549 |
doUpdateValuesList(); |
|
550 |
} |
|
519 | 551 |
|
520 |
public void setAttribute(int index) { |
|
521 |
try { |
|
522 |
this.ddnFields.setSelectedIndex(index); |
|
523 |
} catch (Exception ex) { |
|
524 |
this.ddnFields.setSelectedIndex(-1); |
|
552 |
private boolean isTheSameStore(DataStore store1, DataStore store2) { |
|
553 |
String store1FullName = store1.getFullName(); |
|
554 |
String store2FullName = store2.getFullName(); |
|
555 |
return StringUtils.equalsIgnoreCase(store1FullName, store2FullName); |
|
556 |
} |
|
557 |
|
|
558 |
private String getPrimaryKeyName(FeatureStore store) { |
|
559 |
try { |
|
560 |
FeatureAttributeDescriptor[] pk = store.getDefaultFeatureType().getPrimaryKey(); |
|
561 |
if( pk == null || pk.length!=1 ) { |
|
562 |
return null; |
|
563 |
} |
|
564 |
return pk[0].getName(); |
|
565 |
} catch (DataException ex) { |
|
566 |
return null; |
|
567 |
} |
|
568 |
} |
|
569 |
|
|
570 |
private String getForeingKeyName(FeatureStore store, FeatureStore foreingStore) { |
|
571 |
try { |
|
572 |
for (FeatureAttributeDescriptor descriptor : store.getDefaultFeatureType()) { |
|
573 |
if( descriptor.isForeingKey() ) { |
|
574 |
ForeingKey foreingKey = descriptor.getForeingKey(); |
|
575 |
if( isTheSameStore(foreingStore, foreingKey.getFeatureStore(null)) ) { |
|
576 |
return descriptor.getName(); |
|
577 |
} |
|
525 | 578 |
} |
526 |
doUpdateValuesList(); |
|
579 |
} |
|
580 |
} catch (DataException ex) { |
|
581 |
return null; |
|
527 | 582 |
} |
583 |
return null; |
|
584 |
} |
|
585 |
|
|
586 |
public ExpressionBuilder.Value getFilter() { |
|
587 |
ExpressionBuilder.Value filter = null; |
|
588 |
|
|
589 |
Object value = this.getValue(); |
|
590 |
if( value == null ) { |
|
591 |
return null; |
|
592 |
} |
|
593 |
Field field = this.getCurrentField(); |
|
594 |
if( field == null ) { |
|
595 |
return filter; |
|
596 |
} |
|
597 |
if( field.getPath().length>2 ) { |
|
598 |
// No soportado |
|
599 |
return null; |
|
600 |
} |
|
601 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
|
602 |
FeatureAttributeDescriptor parentDescriptor = field.getParentDescriptor(); |
|
603 |
FeatureAttributeDescriptor descriptor = field.getDescriptor(); |
|
604 |
if( parentDescriptor==null ) { |
|
605 |
filter = builder.binaryOperator( |
|
606 |
this.getRelationalOperator(), |
|
607 |
builder.column(descriptor.getName()), |
|
608 |
builder.constant(value) |
|
609 |
); |
|
610 |
} else { |
|
611 |
switch(parentDescriptor.getRelationType()) { |
|
612 |
case DynField.RELATION_TYPE_COLLABORATION: |
|
613 |
case DynField.RELATION_TYPE_IDENTITY: |
|
614 |
ExpressionBuilder.Function foreing_value = builder.function( |
|
615 |
DataManager.FUNCTION_FOREING_VALUE, |
|
616 |
builder.tuple( |
|
617 |
builder.constant(parentDescriptor.getName()), |
|
618 |
builder.constant(descriptor.getName()) |
|
619 |
) |
|
620 |
); |
|
621 |
filter = builder.binaryOperator( |
|
622 |
this.getRelationalOperator(), |
|
623 |
builder.column(descriptor.getName()), |
|
624 |
foreing_value |
|
625 |
); |
|
626 |
break; |
|
528 | 627 |
|
628 |
|
|
629 |
case DynField.RELATION_TYPE_AGGREGATE: |
|
630 |
case DynField.RELATION_TYPE_COMPOSITION: |
|
631 |
ExpressionBuilder.Function select = builder.function("SELECT"); |
|
632 |
select.parameter( |
|
633 |
"TABLE", |
|
634 |
builder.constant(field.getFeatureStore().getName()) |
|
635 |
); |
|
636 |
select.parameter( |
|
637 |
"WHERE", |
|
638 |
builder.and( |
|
639 |
builder.eq( |
|
640 |
builder.getattr( |
|
641 |
builder.column(field.getFeatureStore().getName()), |
|
642 |
getForeingKeyName(field.getFeatureStore(), this.store) |
|
643 |
), |
|
644 |
builder.getattr( |
|
645 |
builder.column(this.store.getName()), |
|
646 |
getPrimaryKeyName(this.store) |
|
647 |
) |
|
648 |
), |
|
649 |
builder.binaryOperator( |
|
650 |
this.getRelationalOperator(), |
|
651 |
builder.column(descriptor.getName()), |
|
652 |
builder.constant(this.getValue()) |
|
653 |
) |
|
654 |
) |
|
655 |
); |
|
656 |
select.parameter("LIMIT",builder.constant(1)); |
|
657 |
|
|
658 |
String exists_id = "EXISTS"+UUID.randomUUID().toString().replaceAll("-", ""); |
|
659 |
filter = builder.function("EXISTS", select, builder.constant(exists_id)); |
|
660 |
break; |
|
661 |
} |
|
662 |
} |
|
663 |
return filter; |
|
664 |
} |
|
529 | 665 |
} |
Also available in: Unified diff