Revision 45326 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 | ||
---|---|---|
45 | 45 |
import org.gvsig.fmap.dal.feature.ForeingKey; |
46 | 46 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributeSelectionPanel; |
47 | 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; |
|
48 | 51 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters; |
49 | 52 |
import org.gvsig.tools.ToolsLocator; |
50 | 53 |
import org.gvsig.tools.dataTypes.Coercion; |
... | ... | |
78 | 81 |
@SuppressWarnings("UseSpecificCatch") |
79 | 82 |
public class SearchConditionFieldController { |
80 | 83 |
|
81 |
private static final Logger LOGGER = LoggerFactory.getLogger(SearchConditionFieldController.class); |
|
82 |
private static final Class LOAD_MORE_ELEMENTS = SearchConditionFieldController.class; |
|
83 |
private static class Field extends LabeledValueImpl<String> { |
|
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> {
|
|
84 | 87 |
|
85 |
FeatureAttributeDescriptor attrdesc; |
|
86 |
private final FeatureStore store; |
|
87 |
private final int presentationMode; |
|
88 |
private final boolean showStoreName; |
|
89 |
private final FeatureAttributeDescriptor[] path; |
|
88 |
FeatureAttributeDescriptor attrdesc;
|
|
89 |
private final FeatureStore store;
|
|
90 |
private final int presentationMode;
|
|
91 |
private final boolean showStoreName;
|
|
92 |
private final FeatureAttributeDescriptor[] path;
|
|
90 | 93 |
|
91 |
public Field(FeatureAttributeDescriptor[] path, FeatureStore store, FeatureAttributeDescriptor attrdesc, int presentationMode) { |
|
92 |
this(path, store, attrdesc, presentationMode, false); |
|
93 |
} |
|
94 |
public Field(FeatureAttributeDescriptor[] path, FeatureStore store, FeatureAttributeDescriptor attrdesc, int presentationMode) {
|
|
95 |
this(path, store, attrdesc, presentationMode, false);
|
|
96 |
}
|
|
94 | 97 |
|
95 |
public Field( |
|
96 |
FeatureAttributeDescriptor[] path, |
|
97 |
FeatureStore store, |
|
98 |
FeatureAttributeDescriptor attrdesc, |
|
99 |
int presentationMode, |
|
100 |
boolean showStoreName |
|
101 |
) { |
|
102 |
super( |
|
103 |
getAttributeDescriptorLabel(attrdesc, store.getName()), |
|
104 |
attrdesc.getName() |
|
105 |
); |
|
106 |
this.path = path; |
|
107 |
this.store = store; |
|
108 |
this.attrdesc = attrdesc; |
|
109 |
this.presentationMode = presentationMode; |
|
110 |
this.showStoreName = showStoreName; |
|
111 |
} |
|
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 |
}
|
|
112 | 115 |
|
113 |
public FeatureAttributeDescriptor[] getPath() { |
|
114 |
return this.path; |
|
115 |
} |
|
116 |
public FeatureAttributeDescriptor[] getPath() {
|
|
117 |
return this.path;
|
|
118 |
}
|
|
116 | 119 |
|
117 |
@Override |
|
118 |
public String getLabel() { |
|
119 |
String theLabel = getAttributeDescriptorLabel(attrdesc, showStoreName ? store.getName() : null); |
|
120 |
switch (this.presentationMode) { |
|
121 |
case Search.OrderedAttribute.TYPE_REGURAL: |
|
122 |
break; |
|
123 |
case Search.OrderedAttribute.TYPE_FAVORITE: |
|
124 |
theLabel = "<html><b>" + theLabel + "</b></html>"; |
|
125 |
break; |
|
126 |
case Search.OrderedAttribute.TYPE_RECENT: |
|
127 |
theLabel = "<html><i><b>" + theLabel + "</b></i></html>"; |
|
128 |
break; |
|
129 |
} |
|
130 |
return theLabel; |
|
131 |
} |
|
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 |
}
|
|
132 | 135 |
|
133 |
public FeatureAttributeDescriptor getParentDescriptor() { |
|
134 |
int l = this.path.length; |
|
135 |
if (l < 2) { |
|
136 |
return null; |
|
137 |
} |
|
138 |
return this.path[l - 2]; |
|
139 |
} |
|
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 |
}
|
|
140 | 143 |
|
141 |
public FeatureAttributeDescriptor getDescriptor() { |
|
142 |
return this.attrdesc; |
|
143 |
} |
|
144 |
public FeatureAttributeDescriptor getDescriptor() {
|
|
145 |
return this.attrdesc;
|
|
146 |
}
|
|
144 | 147 |
|
145 |
public FeatureStore getFeatureStore() { |
|
146 |
return this.store; |
|
148 |
public FeatureStore getFeatureStore() { |
|
149 |
return this.store; |
|
150 |
} |
|
151 |
|
|
147 | 152 |
} |
148 | 153 |
|
149 |
} |
|
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; |
|
150 | 163 |
|
151 |
private FeatureStore store; |
|
152 |
private SearchParameters parameters; |
|
153 |
private final JLabel lblFields; |
|
154 |
private final JLabel lblExtraFields; |
|
155 |
private final JLabel lblLogicalOperators; |
|
156 |
private final JLabel lblRelationalOperators; |
|
157 |
private final JComboBox cboValue; |
|
158 |
private Object valueAssigned = null; |
|
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; |
|
159 | 173 |
|
160 |
private DropDown ddnFields; |
|
161 |
private DropDown ddnLogicalOperators; |
|
162 |
private DropDown ddnRelationalOperators; |
|
174 |
private final int SIZE_ORDERED_ATTRIBUTES = 20; |
|
175 |
private DatePickerController dateController = null; |
|
163 | 176 |
|
164 |
private LabeledValue[] relationalOperators; |
|
165 |
private LabeledValue[] logicalOperators; |
|
166 |
private final int SIZE_ORDERED_ATTRIBUTES = 20; |
|
167 |
|
|
168 |
private DatePickerController dateController = null; |
|
169 |
|
|
170 |
|
|
171 |
private int updateValuesTimeLimit; |
|
172 |
private int updateValuesFeaturesLimit; |
|
173 |
private boolean canHasMoreElements; |
|
177 |
private int updateValuesTimeLimit; |
|
178 |
private int updateValuesFeaturesLimit; |
|
179 |
private boolean canHasMoreElements; |
|
174 | 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 |
} |
|
175 | 204 |
|
176 |
public SearchConditionFieldController( |
|
177 |
SearchParameters parameters, |
|
178 |
FeatureStore store, |
|
179 |
JLabel lblFields, |
|
180 |
JLabel lblExtraFields, |
|
181 |
JLabel lblRelationalOperators, |
|
182 |
JComboBox cboValue, |
|
183 |
JLabel lblLogicalOperators |
|
184 |
) { |
|
185 |
this.parameters = parameters; |
|
186 |
this.store = store; |
|
187 |
this.lblFields = lblFields; |
|
188 |
this.lblExtraFields = lblExtraFields; |
|
189 |
this.lblRelationalOperators = lblRelationalOperators; |
|
190 |
this.cboValue = cboValue; |
|
191 |
this.lblLogicalOperators = lblLogicalOperators; |
|
192 |
this.updateValuesTimeLimit = 60; |
|
193 |
this.updateValuesFeaturesLimit = 1000; |
|
194 |
this.canHasMoreElements = false; |
|
195 |
this.initComponents(); |
|
196 |
} |
|
197 |
|
|
198 |
public boolean isAValidRelationOperator(String name) { |
|
199 |
for (LabeledValue relationalOperator : relationalOperators) { |
|
200 |
if (StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
|
201 |
return true; |
|
202 |
} |
|
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; |
|
203 | 212 |
} |
204 |
return false; |
|
205 |
} |
|
206 | 213 |
|
207 |
private void initComponents() { |
|
208 |
try { |
|
209 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
210 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
214 |
private void initComponents() {
|
|
215 |
try {
|
|
216 |
I18nManager i18n = ToolsLocator.getI18nManager();
|
|
217 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
|
|
211 | 218 |
|
212 |
relationalOperators = new LabeledValue[]{ |
|
213 |
new LabeledValueImpl(i18n.getTranslation("_Equals_to"), ExpressionBuilder.OPERATOR_EQ), |
|
214 |
new LabeledValueImpl(i18n.getTranslation("_Like_to"), ExpressionBuilder.OPERATOR_ILIKE), |
|
215 |
new LabeledValueImpl(i18n.getTranslation("_Not_equals_to"), ExpressionBuilder.OPERATOR_NE), |
|
216 |
new LabeledValueImpl(i18n.getTranslation("_Greater_than"), ExpressionBuilder.OPERATOR_GT), |
|
217 |
new LabeledValueImpl(i18n.getTranslation("_Greater_or_equal_to"), ExpressionBuilder.OPERATOR_GE), |
|
218 |
new LabeledValueImpl(i18n.getTranslation("_Less_than"), ExpressionBuilder.OPERATOR_LT), |
|
219 |
new LabeledValueImpl(i18n.getTranslation("_Less_or_equal_to"), ExpressionBuilder.OPERATOR_LE) |
|
220 |
}; |
|
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 |
}; |
|
221 | 230 |
|
222 |
logicalOperators = new LabeledValue[]{ |
|
223 |
new LabeledValueImpl(i18n.getTranslation("_Or"), ExpressionBuilder.OPERATOR_OR), |
|
224 |
new LabeledValueImpl(i18n.getTranslation("_And"), ExpressionBuilder.OPERATOR_AND) |
|
225 |
}; |
|
231 |
logicalOperators = new LabeledValue[]{
|
|
232 |
new LabeledValueImpl(i18n.getTranslation("_Or"), ExpressionBuilder.OPERATOR_OR),
|
|
233 |
new LabeledValueImpl(i18n.getTranslation("_And"), ExpressionBuilder.OPERATOR_AND)
|
|
234 |
};
|
|
226 | 235 |
|
227 |
this.lblExtraFields.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
|
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 |
}; |
|
228 | 241 |
|
229 |
this.ddnFields = toolsSwingManager.createDropDown(lblFields); |
|
230 |
this.ddnFields.setVisibleDropdownArrow(false); |
|
231 |
this.ddnRelationalOperators = toolsSwingManager.createDropDown(lblRelationalOperators); |
|
232 |
this.ddnRelationalOperators.setVisibleDropdownArrow(false); |
|
233 |
if (lblLogicalOperators != null) { |
|
234 |
this.ddnLogicalOperators = toolsSwingManager.createDropDown(lblLogicalOperators); |
|
235 |
this.ddnLogicalOperators.setVisibleDropdownArrow(false); |
|
236 |
} |
|
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")); |
|
237 | 246 |
|
238 |
DefaultComboBoxModel modelRelationalOperators = new DefaultComboBoxModel(); |
|
239 |
for (LabeledValue op : relationalOperators) { |
|
240 |
modelRelationalOperators.addElement(op); |
|
241 |
} |
|
242 |
this.ddnRelationalOperators.setModel(modelRelationalOperators); |
|
247 |
this.lblExtraFields.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
|
243 | 248 |
|
244 |
if (this.ddnLogicalOperators != null) { |
|
245 |
DefaultComboBoxModel modelLogicalOperators = new DefaultComboBoxModel(); |
|
246 |
for (LabeledValue op : logicalOperators) { |
|
247 |
modelLogicalOperators.addElement(op); |
|
248 |
} |
|
249 |
this.ddnLogicalOperators.setModel(modelLogicalOperators); |
|
250 |
this.ddnLogicalOperators.setSelectedIndex(1); |
|
251 |
} |
|
252 |
FeatureType featureType = parameters.getFeatureType(store); |
|
253 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
|
254 |
Search.COMPLEMENT_MANE, featureType |
|
255 |
); |
|
256 |
List<Search.OrderedAttribute> orderedAttributes = search.getOrderedAttributes( |
|
257 |
Search.BASIC_TYPES_FILTER, |
|
258 |
Search.STR_INT_LONG_LABEL_ORDER, |
|
259 |
SIZE_ORDERED_ATTRIBUTES |
|
260 |
); |
|
261 |
List<ImageIcon> icons = new ArrayList<>(); |
|
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<>(); |
|
262 | 312 |
// DataTypesManager dataTypeManager = ToolsLocator.getDataTypesManager(); |
263 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
|
264 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
265 |
for (Search.OrderedAttribute attr : orderedAttributes) { |
|
266 |
FeatureAttributeDescriptor attrdesc = attr.getDescriptor(); |
|
267 |
Field field = new Field( |
|
268 |
new FeatureAttributeDescriptor[]{attrdesc}, |
|
269 |
this.store, |
|
270 |
attrdesc, |
|
271 |
attr.getType() |
|
272 |
); |
|
273 |
model.addElement(field); |
|
274 |
String iconName = attrdesc.getDataType().getIconName(); |
|
275 |
if (iconTheme.exists(iconName)) { |
|
276 |
icons.add(iconTheme.get(iconName)); |
|
277 |
} else { |
|
278 |
icons.add(null); |
|
279 |
} |
|
280 |
} |
|
281 |
|
|
282 |
this.ddnFields.setIcons(icons); |
|
283 |
this.ddnFields.setModel(model); |
|
284 |
this.ddnFields.addItemListener(new ItemListener() { |
|
285 |
@Override |
|
286 |
public void itemStateChanged(ItemEvent e) { |
|
287 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
288 |
doUpdateValuesList(); |
|
289 |
} |
|
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 |
} |
|
290 | 331 |
|
291 |
} |
|
292 |
}); |
|
293 |
|
|
294 |
this.cboValue.addItemListener(new ItemListener() { |
|
295 |
@Override |
|
296 |
public void itemStateChanged(ItemEvent e) { |
|
297 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
298 |
if (cboValue.getSelectedItem()!=null && cboValue.getSelectedItem() instanceof LabeledValue ) { |
|
299 |
if (Objects.equals(((LabeledValue)cboValue.getSelectedItem()).getValue(), LOAD_MORE_ELEMENTS)) { |
|
300 |
setUpdateValuesLimits(updateValuesTimeLimit+10, updateValuesFeaturesLimit+20000); |
|
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 |
|
|
301 | 341 |
} |
302 |
} |
|
303 |
} |
|
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); |
|
304 | 367 |
} |
305 |
}); |
|
306 |
|
|
307 |
this.lblExtraFields.addMouseListener(new MouseAdapter() { |
|
308 |
@Override |
|
309 |
public void mouseClicked(MouseEvent e) { |
|
310 |
doSelectMoreFields(); |
|
311 |
} |
|
312 |
}); |
|
313 |
|
|
314 |
// clear(); |
|
315 |
} catch (Exception ex) { |
|
316 |
throw new RuntimeException(ex); |
|
317 | 368 |
} |
318 |
} |
|
319 | 369 |
|
320 |
private FeatureType getFeatureType() { |
|
321 |
try { |
|
322 |
return this.store.getDefaultFeatureType(); |
|
323 |
} catch (DataException ex) { |
|
324 |
return null; |
|
370 |
private FeatureType getFeatureType() { |
|
371 |
try { |
|
372 |
return this.store.getDefaultFeatureType(); |
|
373 |
} catch (DataException ex) { |
|
374 |
return null; |
|
375 |
} |
|
325 | 376 |
} |
326 |
} |
|
327 | 377 |
|
328 |
private void doSelectMoreFields() { |
|
329 |
DefaultFeatureAttributeSelectionPanel panel = new DefaultFeatureAttributeSelectionPanel(store, parameters.getFeatureType(store)); |
|
330 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
331 |
final Dialog dialog = winManager.createDialog( |
|
332 |
panel, |
|
333 |
"Select attribute", |
|
334 |
null, |
|
335 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
336 |
); |
|
337 |
dialog.addActionListener((ActionEvent e) -> { |
|
338 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) { |
|
339 |
doAddAndSelect( |
|
340 |
panel.getSelectedStore(), |
|
341 |
panel.getSelectedAttributeDescriptor(), |
|
342 |
panel.getSelectedPath() |
|
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 |
|
343 | 386 |
); |
344 |
} |
|
345 |
}); |
|
346 |
dialog.show(WindowManager.MODE.DIALOG); |
|
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); |
|
347 | 397 |
|
348 |
} |
|
349 |
|
|
350 |
private void doAddAndSelect(FeatureStore theStore, FeatureAttributeDescriptor attrdesc, FeatureAttributeDescriptor[] path) { |
|
351 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
352 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
353 |
DefaultComboBoxModel<Field> model = (DefaultComboBoxModel) this.ddnFields.getModel(); |
|
354 |
if (attrdesc ==null) { |
|
355 |
dialogManager.messageDialog( |
|
356 |
i18n.getTranslation("_It_is_not_supported_to_search_through_this_field")+"\n"+ |
|
357 |
i18n.getTranslation("_Field_not_found"), |
|
358 |
"_Warning", |
|
359 |
JOptionPane.WARNING_MESSAGE |
|
360 |
); |
|
361 |
return; |
|
362 | 398 |
} |
363 | 399 |
|
364 |
for (int i = 0; i < model.getSize(); i++) { |
|
365 |
Field field = model.getElementAt(i); |
|
366 |
FeatureAttributeDescriptor attrdescN = field.getDescriptor(); |
|
367 |
if (isTheSameStore(theStore, attrdescN.getStore()) |
|
368 |
&& StringUtils.equalsIgnoreCase(attrdesc.getName(), attrdescN.getName())) { |
|
369 |
this.setAttribute(i); |
|
370 |
return; |
|
371 |
} |
|
372 |
} |
|
373 |
Field field = new Field( |
|
374 |
path, |
|
375 |
theStore, |
|
376 |
attrdesc, |
|
377 |
Search.OrderedAttribute.TYPE_REGURAL, |
|
378 |
!isTheSameStore(store, theStore) |
|
379 |
); |
|
380 |
if (field.getPath().length > 2) { |
|
381 |
dialogManager.messageDialog( |
|
382 |
i18n.getTranslation("_It_is_not_supported_to_search_through_this_field") + "\n" |
|
383 |
+ i18n.getTranslation("_To_many_links"), |
|
384 |
"_Warning", |
|
385 |
JOptionPane.WARNING_MESSAGE |
|
386 |
); |
|
387 |
return; |
|
388 |
} |
|
389 |
FeatureAttributeDescriptor parentDescriptor = field.getParentDescriptor(); |
|
390 |
if( parentDescriptor!=null ) { |
|
391 |
switch (parentDescriptor.getRelationType()) { |
|
392 |
case DynField.RELATION_TYPE_AGGREGATE: |
|
393 |
case DynField.RELATION_TYPE_COMPOSITION: |
|
394 |
if (getForeingKeyName(field.getFeatureStore(), this.store) == null) { |
|
395 |
dialogManager.messageDialog( |
|
396 |
"It not supported to search through this field." + "\n" |
|
397 |
+ "The link field was not found.", |
|
398 |
"_Warning", |
|
399 |
JOptionPane.WARNING_MESSAGE |
|
400 |
); |
|
401 |
return; |
|
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; |
|
402 | 421 |
} |
403 |
if (getPrimaryKeyName(this.store) == null) { |
|
404 |
dialogManager.messageDialog( |
|
405 |
"It not supported to search through this field." + "\n" |
|
406 |
+ "A simple primary key was not found.", |
|
407 |
"_Warning", |
|
408 |
JOptionPane.WARNING_MESSAGE |
|
409 |
); |
|
410 |
return; |
|
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 |
} |
|
411 | 462 |
} |
412 | 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); |
|
413 | 468 |
} |
414 |
model.addElement(field); |
|
415 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
|
416 |
this.ddnFields.getIcons().add(iconTheme.get(attrdesc.getDataType().getIconName())); |
|
417 |
this.setAttribute(model.getSize() - 1); |
|
418 |
} |
|
419 | 469 |
|
420 |
public void clear() { |
|
421 |
this.ddnRelationalOperators.setSelectedIndex(0); |
|
422 |
if (this.ddnLogicalOperators != null) { |
|
423 |
this.ddnLogicalOperators.setSelectedIndex(1); |
|
424 |
} |
|
425 |
this.cboValue.setSelectedIndex(-1); |
|
426 |
} |
|
427 |
|
|
428 |
private void doUpdateValuesList() { |
|
429 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
|
430 |
if (field == null) { |
|
431 |
return; |
|
432 |
} |
|
433 |
FeatureAttributeDescriptor descriptor = field.getDescriptor(); |
|
434 |
if( descriptor.getType()==DataTypes.DATE ) { |
|
435 |
if( this.dateController == null ) { |
|
436 |
this.dateController = ToolsSwingLocator.getToolsSwingManager().createDatePickerController( |
|
437 |
(JTextComponent) this.cboValue.getEditor().getEditorComponent(), |
|
438 |
null |
|
439 |
); |
|
470 |
public void clear() { |
|
471 |
this.ddnRelationalOperators.setSelectedIndex(0); |
|
472 |
if (this.ddnLogicalOperators != null) { |
|
473 |
this.ddnLogicalOperators.setSelectedIndex(1); |
|
440 | 474 |
} |
441 |
} else { |
|
442 |
if( this.dateController != null ) { |
|
443 |
this.dateController.uninstall(); |
|
444 |
this.dateController = null; |
|
445 |
} |
|
475 |
this.cboValue.setSelectedIndex(-1); |
|
476 |
this.ddnNullBehavior.setSelectedIndex(0); |
|
446 | 477 |
} |
447 | 478 |
|
448 |
final List<Object> values = new ArrayList<>(); |
|
449 |
final DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
450 |
final FeatureStore theStore = field.getFeatureStore(); |
|
451 |
final FeatureQuery query; |
|
452 |
if (this.store == theStore) { |
|
453 |
query = parameters.getQuery().getCopy(); // theStore.createFeatureQuery(); |
|
454 |
} else { |
|
455 |
query = theStore.createFeatureQuery(); |
|
456 |
} |
|
457 |
query.addAttributeName(field.getDescriptor().getName()); |
|
458 |
query.setFilter(""); |
|
459 |
query.setLimit(updateValuesFeaturesLimit); |
|
460 |
query.getGroupByColumns().clear(); |
|
461 |
query.getAggregateFunctions().clear(); |
|
462 |
Thread th = new Thread(new Runnable() { |
|
463 |
@Override |
|
464 |
public void run() { |
|
465 |
FeatureSet set = null; |
|
466 |
try { |
|
467 |
canHasMoreElements = false; |
|
468 |
set = theStore.getFeatureSet(query); |
|
469 |
if (set.size()>=updateValuesFeaturesLimit) { |
|
470 |
canHasMoreElements = true; |
|
471 |
} |
|
472 |
final long timeLimit = System.currentTimeMillis() + updateValuesTimeLimit * 1000; |
|
473 |
set.accept(new Visitor() { |
|
474 |
@Override |
|
475 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
|
476 |
Object value = ((Feature) o).get(field.getDescriptor().getName()); |
|
477 |
if (!values.contains(value)) { |
|
478 |
values.add(value); |
|
479 |
} |
|
480 |
if (System.currentTimeMillis() > timeLimit) { |
|
481 |
canHasMoreElements = true; |
|
482 |
throw new VisitCanceledException(); |
|
483 |
} |
|
484 |
if (values.size() > 1000) { |
|
485 |
canHasMoreElements = true; |
|
486 |
throw new VisitCanceledException(); |
|
487 |
} |
|
488 |
} |
|
489 |
}); |
|
490 |
} catch (VisitCanceledException ex) { |
|
491 |
canHasMoreElements = true; |
|
492 |
} catch (Exception ex) { |
|
493 |
LOGGER.warn("Can't update list of values of '" + field.getLabel() + "'.", ex); |
|
494 |
} finally { |
|
495 |
DisposeUtils.disposeQuietly(set); |
|
479 |
private void doUpdateValuesList() { |
|
480 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
|
481 |
if (field == null) { |
|
482 |
return; |
|
496 | 483 |
} |
497 |
List<LabeledValue> elements = new ArrayList<>(); |
|
498 |
if (!values.isEmpty()) { |
|
499 |
LabeledValue[] availableValues = field.getDescriptor().getAvailableValues(); |
|
500 |
Map<String, String> availableValuesMap = new HashMap<>(); |
|
501 |
if (availableValues != null) { |
|
502 |
for (LabeledValue availableValue : availableValues) { |
|
503 |
availableValuesMap.put( |
|
504 |
Objects.toString(availableValue.getValue()), |
|
505 |
availableValue.getLabel() |
|
506 |
); |
|
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 |
); |
|
507 | 491 |
} |
508 |
} |
|
509 |
elements.add(new LabeledValueImpl("", null)); |
|
510 |
for (Object value : values) { |
|
511 |
String key; |
|
512 |
if (value instanceof Date) { |
|
513 |
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); |
|
514 |
df.setLenient(false); |
|
515 |
key = df.format(value); |
|
516 |
} else { |
|
517 |
key = Objects.toString(value); |
|
492 |
} else { |
|
493 |
if (this.dateController != null) { |
|
494 |
this.dateController.uninstall(); |
|
495 |
this.dateController = null; |
|
518 | 496 |
} |
519 |
String label = availableValuesMap.getOrDefault(key, key); |
|
520 |
elements.add(new LabeledValueImpl(label, value)); |
|
521 |
} |
|
522 |
elements.sort(null); |
|
497 |
} |
|
523 | 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(); |
|
524 | 507 |
} |
525 |
for (LabeledValue element : elements) { |
|
526 |
model.addElement(element); |
|
527 |
} |
|
528 |
if (canHasMoreElements) { |
|
529 |
model.addElement(new LabeledValueImpl("...", LOAD_MORE_ELEMENTS)); |
|
530 |
} |
|
531 |
SwingUtilities.invokeLater(new Runnable() { |
|
532 |
@Override |
|
533 |
public void run() { |
|
534 |
setEnabled(false); |
|
535 |
cboValue.setModel(model); |
|
536 |
if (valueAssigned != null) { |
|
537 |
cboValue.setSelectedItem(valueAssigned); |
|
538 |
valueAssigned = null; |
|
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 |
if (value instanceof Date) { |
|
564 |
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); |
|
565 |
df.setLenient(false); |
|
566 |
key = df.format(value); |
|
567 |
} else { |
|
568 |
key = Objects.toString(value); |
|
569 |
} |
|
570 |
String label = availableValuesMap.getOrDefault(key, key); |
|
571 |
elements.add(new LabeledValueImpl(label, value)); |
|
572 |
} |
|
573 |
elements.sort(null); |
|
574 |
|
|
575 |
} |
|
576 |
for (LabeledValue element : elements) { |
|
577 |
model.addElement(element); |
|
578 |
} |
|
579 |
if (canHasMoreElements) { |
|
580 |
model.addElement(new LabeledValueImpl("...", LOAD_MORE_ELEMENTS)); |
|
581 |
} |
|
582 |
SwingUtilities.invokeLater(new Runnable() { |
|
583 |
@Override |
|
584 |
public void run() { |
|
585 |
setEnabled(false); |
|
586 |
cboValue.setModel(model); |
|
587 |
if (valueAssigned != null) { |
|
588 |
cboValue.setSelectedItem(valueAssigned); |
|
589 |
valueAssigned = null; |
|
590 |
} |
|
591 |
setEnabled(true); |
|
592 |
} |
|
593 |
}); |
|
539 | 594 |
} |
540 |
setEnabled(true); |
|
541 |
} |
|
542 | 595 |
}); |
543 |
} |
|
544 |
}); |
|
545 |
th.start(); |
|
546 |
} |
|
596 |
th.start(); |
|
597 |
} |
|
547 | 598 |
|
548 |
public void setEnabled(boolean enabled) { |
|
549 |
ddnFields.setEnabled(enabled); |
|
550 |
if (ddnLogicalOperators != null) { |
|
551 |
ddnLogicalOperators.setEnabled(enabled); |
|
552 |
} |
|
553 |
ddnRelationalOperators.setEnabled(enabled); |
|
554 |
lblExtraFields.setEnabled(enabled); |
|
555 |
cboValue.setEnabled(enabled); |
|
556 |
} |
|
599 |
public void setEnabled(boolean enabled) {
|
|
600 |
ddnFields.setEnabled(enabled);
|
|
601 |
if (ddnLogicalOperators != null) {
|
|
602 |
ddnLogicalOperators.setEnabled(enabled);
|
|
603 |
}
|
|
604 |
ddnRelationalOperators.setEnabled(enabled);
|
|
605 |
lblExtraFields.setEnabled(enabled);
|
|
606 |
cboValue.setEnabled(enabled);
|
|
607 |
}
|
|
557 | 608 |
|
558 |
public String getRelationalOperator() { |
|
559 |
LabeledValue<String> op = (LabeledValue) this.ddnRelationalOperators.getSelectedItem(); |
|
560 |
if (op == null) { |
|
561 |
return null; |
|
609 |
public String getRelationalOperator() { |
|
610 |
LabeledValue<String> op = (LabeledValue) this.ddnRelationalOperators.getSelectedItem(); |
|
611 |
if (op == null) { |
|
612 |
return null; |
|
613 |
} |
|
614 |
return op.getValue(); |
|
562 | 615 |
} |
563 |
return op.getValue(); |
|
564 |
} |
|
565 | 616 |
|
566 |
public int setRelationalOperator(String name) { |
|
567 |
int n = 0; |
|
568 |
for (LabeledValue relationalOperator : relationalOperators) { |
|
569 |
if (StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
|
570 |
break; |
|
571 |
} |
|
572 |
n++; |
|
617 |
public int setRelationalOperator(String name) { |
|
618 |
int n = 0; |
|
619 |
for (LabeledValue relationalOperator : relationalOperators) { |
|
620 |
if (StringUtils.equalsIgnoreCase(name, (CharSequence) relationalOperator.getValue())) { |
|
621 |
break; |
|
622 |
} |
|
623 |
n++; |
|
624 |
} |
|
625 |
if (this.relationalOperators.length <= n) { |
|
626 |
return -1; |
|
627 |
} |
|
628 |
this.ddnRelationalOperators.setSelectedIndex(n); |
|
629 |
return n; |
|
573 | 630 |
} |
574 |
if (this.relationalOperators.length <= n) { |
|
575 |
return -1; |
|
576 |
} |
|
577 |
this.ddnRelationalOperators.setSelectedIndex(n); |
|
578 |
return n; |
|
579 |
} |
|
580 | 631 |
|
581 |
public String getLogicalOperator() { |
|
582 |
if (this.ddnLogicalOperators == null) { |
|
583 |
return null; |
|
632 |
public String getLogicalOperator() { |
|
633 |
if (this.ddnLogicalOperators == null) { |
|
634 |
return null; |
|
635 |
} |
|
636 |
LabeledValue<String> rel = (LabeledValue) this.ddnLogicalOperators.getSelectedItem(); |
|
637 |
if (rel == null) { |
|
638 |
return null; |
|
639 |
} |
|
640 |
return rel.getValue(); |
|
584 | 641 |
} |
585 |
LabeledValue<String> rel = (LabeledValue) this.ddnLogicalOperators.getSelectedItem(); |
|
586 |
if (rel == null) { |
|
587 |
return null; |
|
588 |
} |
|
589 |
return rel.getValue(); |
|
590 |
} |
|
591 | 642 |
|
592 |
public void setLogicalOperator(String operator) { |
|
593 |
if (this.ddnLogicalOperators == null) { |
|
594 |
return; |
|
643 |
public void setLogicalOperator(String operator) { |
|
644 |
if (this.ddnLogicalOperators == null) { |
|
645 |
return; |
|
646 |
} |
|
647 |
ComboBoxModel model = this.ddnLogicalOperators.getModel(); |
|
648 |
for (int i = 0; i < model.getSize(); i++) { |
|
649 |
LabeledValue modelValue = (LabeledValue) model.getElementAt(i); |
|
650 |
String value = (String) modelValue.getValue(); |
|
651 |
if (StringUtils.equals(value, operator)) { |
|
652 |
this.ddnLogicalOperators.setSelectedIndex(i); |
|
653 |
break; |
|
654 |
} |
|
655 |
} |
|
595 | 656 |
} |
596 |
ComboBoxModel model = this.ddnLogicalOperators.getModel(); |
|
597 |
for (int i = 0; i < model.getSize(); i++) { |
|
598 |
LabeledValue modelValue = (LabeledValue) model.getElementAt(i); |
|
599 |
String value = (String) modelValue.getValue(); |
|
600 |
if (StringUtils.equals(value, operator)) { |
|
601 |
this.ddnLogicalOperators.setSelectedIndex(i); |
|
602 |
break; |
|
603 |
} |
|
604 |
} |
|
605 |
} |
|
606 | 657 |
|
607 |
public Object getValue() { |
|
608 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
|
609 |
if (field == null) { |
|
610 |
return null; |
|
658 |
public Object getValue() { |
|
659 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
|
660 |
if (field == null) { |
|
661 |
return null; |
|
662 |
} |
|
663 |
Object v; |
|
664 |
if (this.dateController == null) { |
|
665 |
v = this.cboValue.getSelectedItem(); |
|
666 |
} else { |
|
667 |
v = this.dateController.get(); |
|
668 |
} |
|
669 |
if (v == null) { |
|
670 |
return null; |
|
671 |
} |
|
672 |
if (v instanceof LabeledValue) { |
|
673 |
v = ((LabeledValue) v).getValue(); |
|
674 |
if (v == null) { |
|
675 |
return null; |
|
676 |
} |
|
677 |
} |
|
678 |
if (v instanceof CharSequence) { |
|
679 |
if (StringUtils.isBlank((CharSequence) v)) { |
|
680 |
return null; |
|
681 |
} |
|
682 |
} |
|
683 |
Coercion coercion = field.getDescriptor().getDataType().getCoercion(); |
|
684 |
try { |
|
685 |
return coercion.coerce(v); |
|
686 |
} catch (CoercionException ex) { |
|
687 |
return null; |
|
688 |
} |
|
611 | 689 |
} |
612 |
Object v; |
|
613 |
if( this.dateController==null ) { |
|
614 |
v = this.cboValue.getSelectedItem(); |
|
615 |
} else { |
|
616 |
v = this.dateController.get(); |
|
617 |
} |
|
618 |
if (v == null) { |
|
619 |
return null; |
|
620 |
} |
|
621 |
if (v instanceof LabeledValue) { |
|
622 |
v = ((LabeledValue) v).getValue(); |
|
623 |
if (v == null) { |
|
624 |
return null; |
|
625 |
} |
|
626 |
} |
|
627 |
if (v instanceof CharSequence) { |
|
628 |
if (StringUtils.isBlank((CharSequence) v)) { |
|
629 |
return null; |
|
630 |
} |
|
631 |
} |
|
632 |
Coercion coercion = field.getDescriptor().getDataType().getCoercion(); |
|
633 |
try { |
|
634 |
return coercion.coerce(v); |
|
635 |
} catch (CoercionException ex) { |
|
636 |
return null; |
|
637 |
} |
|
638 |
} |
|
639 | 690 |
|
640 | 691 |
public void setValue(Object value) { |
641 | 692 |
//this.cboValue.setSelectedItem(value); |
642 | 693 |
SwingUtilities.invokeLater(new Runnable() { |
643 | 694 |
@Override |
644 | 695 |
public void run() { |
645 |
DefaultComboBoxModel model = (DefaultComboBoxModel) cboValue.getModel(); |
|
646 |
for (int i = 0; i < model.getSize(); i++) { |
|
647 |
Object item = model.getElementAt(i); |
|
696 |
DefaultComboBoxModel model = (DefaultComboBoxModel) cboValue.getModel();
|
|
697 |
for (int i = 0; i < model.getSize(); i++) {
|
|
698 |
Object item = model.getElementAt(i);
|
|
648 | 699 |
if (item.equals(value)) { |
649 |
cboValue.setSelectedIndex(i); |
|
650 |
valueAssigned = value; |
|
651 |
return; |
|
652 |
} |
|
653 |
} |
|
654 |
// si no lo encuentra en el modelo lo a?ade |
|
655 |
final Field field = (Field) ddnFields.getSelectedItem(); |
|
656 |
if (field == null) { |
|
657 |
return; |
|
658 |
} else { |
|
659 |
LabeledValue[] availableValues = field.getDescriptor().getAvailableValues(); |
|
660 |
Map<String, String> availableValuesMap = new HashMap<>(); |
|
661 |
if (availableValues != null) { |
|
662 |
for (LabeledValue availableValue : availableValues) { |
|
663 |
availableValuesMap.put( |
|
664 |
Objects.toString(availableValue.getValue()), |
|
665 |
availableValue.getLabel() |
|
666 |
); |
|
700 |
cboValue.setSelectedIndex(i); |
|
701 |
valueAssigned = value; |
|
702 |
return; |
|
703 |
} |
|
667 | 704 |
} |
705 |
// si no lo encuentra en el modelo lo a?ade |
|
706 |
final Field field = (Field) ddnFields.getSelectedItem(); |
|
707 |
if (field == null) { |
|
708 |
return; |
|
709 |
} else { |
|
710 |
LabeledValue[] availableValues = field.getDescriptor().getAvailableValues(); |
|
711 |
Map<String, String> availableValuesMap = new HashMap<>(); |
|
712 |
if (availableValues != null) { |
|
713 |
for (LabeledValue availableValue : availableValues) { |
|
714 |
availableValuesMap.put( |
|
715 |
Objects.toString(availableValue.getValue()), |
|
716 |
availableValue.getLabel() |
|
717 |
); |
|
718 |
} |
|
719 |
} |
|
720 |
String key; |
|
721 |
if (value instanceof Date) { |
|
722 |
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); |
|
723 |
df.setLenient(false); |
|
724 |
key = df.format(value); |
|
725 |
} else { |
|
726 |
key = Objects.toString(value); |
|
727 |
} |
|
728 |
String label = availableValuesMap.getOrDefault(key, key); |
|
729 |
LabeledValueImpl newItem = new LabeledValueImpl(label, value); |
|
730 |
model.addElement(newItem); |
|
731 |
cboValue.setSelectedItem(newItem); |
|
732 |
valueAssigned = newItem; |
|
733 |
} |
|
668 | 734 |
} |
669 |
String key; |
|
670 |
if (value instanceof Date) { |
|
671 |
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); |
|
672 |
df.setLenient(false); |
|
673 |
key = df.format(value); |
|
674 |
} else { |
|
675 |
key = Objects.toString(value); |
|
676 |
} |
|
677 |
String label = availableValuesMap.getOrDefault(key, key); |
|
678 |
LabeledValueImpl newItem = new LabeledValueImpl(label, value); |
|
679 |
model.addElement(newItem); |
|
680 |
cboValue.setSelectedItem(newItem); |
|
681 |
valueAssigned = newItem; |
|
682 |
} |
|
683 |
} |
|
684 | 735 |
}); |
685 | 736 |
} |
686 | 737 |
|
687 |
private Field getCurrentField() { |
|
688 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
|
689 |
return field; |
|
690 |
} |
|
691 |
|
|
692 |
public int setAttribute(String name) { |
|
693 |
ComboBoxModel<Field> model = this.ddnFields.getModel(); |
|
694 |
for (int i = 0; i < model.getSize(); i++) { |
|
695 |
Field x = model.getElementAt(i); |
|
696 |
if (StringUtils.equalsIgnoreCase(name, x.getValue())) { |
|
697 |
this.setAttribute(i); |
|
698 |
return i; |
|
699 |
} |
|
738 |
private Field getCurrentField() { |
|
739 |
final Field field = (Field) this.ddnFields.getSelectedItem(); |
|
740 |
return field; |
|
700 | 741 |
} |
701 |
this.setAttribute(-1); |
|
702 |
return -1; |
|
703 |
} |
|
704 | 742 |
|
705 |
public void setAttribute(int index) { |
|
706 |
try { |
|
707 |
this.ddnFields.setSelectedIndex(index); |
|
708 |
} catch (Exception ex) { |
|
709 |
this.ddnFields.setSelectedIndex(-1); |
|
710 |
} |
|
711 |
doUpdateValuesList(); |
|
712 |
} |
|
713 |
|
|
714 |
public int setAttributePath(String[][] pathNames) { |
|
715 |
// [[attributeName, storeName],...] |
|
716 |
try { |
|
717 |
if (pathNames.length == 1) { |
|
718 |
String[] path = pathNames[pathNames.length - 1]; |
|
719 |
String name = path[0]; |
|
720 |
int index = this.setAttribute(name); |
|
721 |
if (index == -1) { |
|
722 |
try { |
|
723 |
FeatureAttributeDescriptor attrDescriptor = store.getDefaultFeatureType().getAttributeDescriptor(name); |
|
724 |
FeatureAttributeDescriptor[] attributePath = new FeatureAttributeDescriptor[]{attrDescriptor}; |
|
725 |
if (attrDescriptor==null) { |
|
726 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
727 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
728 |
dialogManager.messageDialog( |
|
729 |
i18n.getTranslation("_It_is_not_supported_to_search_through_this_field")+":\n "+ name+"\n"+ |
|
730 |
i18n.getTranslation("_Field_not_found_in_this_table"), |
|
731 |
"_Warning", |
|
732 |
JOptionPane.WARNING_MESSAGE |
|
733 |
); |
|
734 |
this.cboValue.setModel(new DefaultComboBoxModel()); |
|
735 |
} else { |
|
736 |
doAddAndSelect(store, store.getDefaultFeatureType().getAttributeDescriptor(name), attributePath); |
|
737 |
} |
|
738 |
} catch (Exception ex) { |
|
739 |
LOGGER.warn("Not able to set single path into controller", ex); |
|
740 |
return -1; |
|
741 |
} |
|
742 |
} |
|
743 |
return index; |
|
744 |
} else { |
|
743 |
public int setAttribute(String name) { |
|
745 | 744 |
ComboBoxModel<Field> model = this.ddnFields.getModel(); |
746 |
String[] singleArrayPathNameDescriptors = new String[pathNames.length]; |
|
747 |
for (int i = 0; i < pathNames.length; i++) { |
|
748 |
singleArrayPathNameDescriptors[i] = pathNames[i][0]; |
|
749 |
} |
|
750 |
// check the drop |
|
751 | 745 |
for (int i = 0; i < model.getSize(); i++) { |
752 |
Field x = model.getElementAt(i); |
|
753 |
String[] arrayDescriptors = new String[x.getPath().length]; |
|
754 |
FeatureAttributeDescriptor[] path = x.getPath(); |
|
755 |
for (int j = 0; j < path.length; j++) { |
|
756 |
arrayDescriptors[j] = path[j].getName(); |
|
757 |
} |
|
758 |
if (Arrays.equals(singleArrayPathNameDescriptors, arrayDescriptors)) { |
|
759 |
this.setAttribute(i); |
|
760 |
return i; |
|
761 |
} |
|
746 |
Field x = model.getElementAt(i); |
|
747 |
if (StringUtils.equalsIgnoreCase(name, x.getValue())) { |
|
748 |
this.setAttribute(i); |
|
749 |
return i; |
|
750 |
} |
|
762 | 751 |
} |
763 |
// if not, addit to the drop |
|
764 |
DataManager dataManager = DALLocator.getDataManager(); |
|
765 |
String tableName = pathNames[pathNames.length - 1][1]; // del ultimo path, coger el nombre tabla |
|
766 |
FeatureStore theStore = (FeatureStore) dataManager.getStoresRepository().getStore(tableName); |
|
767 |
String attributeName = pathNames[pathNames.length - 1][0]; // del ultimo path, coger el nombre attribute |
|
768 |
if (theStore != null) { |
|
769 |
FeatureAttributeDescriptor attr; |
|
770 |
try { |
|
771 |
attr = theStore.getDefaultFeatureType().getAttributeDescriptor(attributeName); |
|
772 |
FeatureAttributeDescriptor[] attributePath = new FeatureAttributeDescriptor[2]; |
|
773 |
String firstAttrName = pathNames[0][0]; |
|
774 |
FeatureAttributeDescriptor firstAttr = store.getDefaultFeatureType().getAttributeDescriptor(firstAttrName); |
|
775 |
attributePath[0] = firstAttr; |
|
752 |
this.setAttribute(-1); |
|
753 |
return -1; |
|
754 |
} |
|
776 | 755 |
|
777 |
attributePath[1] = attr; |
|
778 |
doAddAndSelect(theStore, attr, attributePath); |
|
779 |
return SIZE_ORDERED_ATTRIBUTES - 1; |
|
780 |
} catch (Exception ex) { |
|
781 |
LOGGER.warn("Not able to set foreign path into controller", ex); |
|
782 |
} |
|
783 |
|
|
756 |
public void setAttribute(int index) { |
|
757 |
try { |
|
758 |
this.ddnFields.setSelectedIndex(index); |
|
759 |
} catch (Exception ex) { |
|
760 |
this.ddnFields.setSelectedIndex(-1); |
|
784 | 761 |
} |
785 |
|
|
786 |
} |
|
787 |
} catch (Exception ex) { |
|
788 |
LOGGER.warn("Controller not set.", ex); |
|
762 |
doUpdateValuesList(); |
|
789 | 763 |
} |
790 |
this.setAttribute(-1); |
|
791 |
return -1; |
|
792 |
} |
|
793 | 764 |
|
794 |
private boolean isTheSameStore(DataStore store1, DataStore store2) { |
|
795 |
String store1FullName = store1.getFullName(); |
|
796 |
String store2FullName = store2.getFullName(); |
|
797 |
return StringUtils.equalsIgnoreCase(store1FullName, store2FullName); |
|
798 |
} |
|
765 |
public int setAttributePath(String[][] pathNames) { |
|
766 |
// [[attributeName, storeName],...] |
|
767 |
try { |
|
768 |
if (pathNames.length == 1) { |
|
769 |
String[] path = pathNames[pathNames.length - 1]; |
|
770 |
String name = path[0]; |
|
771 |
int index = this.setAttribute(name); |
|
772 |
if (index == -1) { |
|
773 |
try { |
|
774 |
FeatureAttributeDescriptor attrDescriptor = store.getDefaultFeatureType().getAttributeDescriptor(name); |
|
775 |
FeatureAttributeDescriptor[] attributePath = new FeatureAttributeDescriptor[]{attrDescriptor}; |
|
776 |
if (attrDescriptor == null) { |
|
777 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
778 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
779 |
dialogManager.messageDialog( |
|
780 |
i18n.getTranslation("_It_is_not_supported_to_search_through_this_field") + ":\n " + name + "\n" |
|
781 |
+ i18n.getTranslation("_Field_not_found_in_this_table"), |
|
782 |
"_Warning", |
|
783 |
JOptionPane.WARNING_MESSAGE |
|
784 |
); |
|
785 |
this.cboValue.setModel(new DefaultComboBoxModel()); |
|
786 |
} else { |
|
787 |
doAddAndSelect(store, store.getDefaultFeatureType().getAttributeDescriptor(name), attributePath); |
|
788 |
} |
|
789 |
} catch (Exception ex) { |
|
790 |
LOGGER.warn("Not able to set single path into controller", ex); |
|
791 |
return -1; |
|
792 |
} |
|
793 |
} |
|
794 |
return index; |
|
795 |
} else { |
|
796 |
ComboBoxModel<Field> model = this.ddnFields.getModel(); |
|
797 |
String[] singleArrayPathNameDescriptors = new String[pathNames.length]; |
|
798 |
for (int i = 0; i < pathNames.length; i++) { |
|
799 |
singleArrayPathNameDescriptors[i] = pathNames[i][0]; |
|
800 |
} |
|
801 |
// check the drop |
|
802 |
for (int i = 0; i < model.getSize(); i++) { |
|
803 |
Field x = model.getElementAt(i); |
|
804 |
String[] arrayDescriptors = new String[x.getPath().length]; |
|
805 |
FeatureAttributeDescriptor[] path = x.getPath(); |
|
806 |
for (int j = 0; j < path.length; j++) { |
|
807 |
arrayDescriptors[j] = path[j].getName(); |
|
808 |
} |
|
809 |
if (Arrays.equals(singleArrayPathNameDescriptors, arrayDescriptors)) { |
|
810 |
this.setAttribute(i); |
|
811 |
return i; |
|
812 |
} |
|
813 |
} |
|
814 |
// if not, addit to the drop |
|
815 |
DataManager dataManager = DALLocator.getDataManager(); |
|
816 |
String tableName = pathNames[pathNames.length - 1][1]; // del ultimo path, coger el nombre tabla |
|
817 |
FeatureStore theStore = (FeatureStore) dataManager.getStoresRepository().getStore(tableName); |
|
818 |
String attributeName = pathNames[pathNames.length - 1][0]; // del ultimo path, coger el nombre attribute |
|
819 |
if (theStore != null) { |
|
820 |
FeatureAttributeDescriptor attr; |
|
821 |
try { |
|
822 |
attr = theStore.getDefaultFeatureType().getAttributeDescriptor(attributeName); |
|
823 |
FeatureAttributeDescriptor[] attributePath = new FeatureAttributeDescriptor[2]; |
|
824 |
String firstAttrName = pathNames[0][0]; |
|
825 |
FeatureAttributeDescriptor firstAttr = store.getDefaultFeatureType().getAttributeDescriptor(firstAttrName); |
|
826 |
attributePath[0] = firstAttr; |
|
799 | 827 |
|
800 |
private String getPrimaryKeyName(FeatureStore store) { |
|
801 |
try { |
|
802 |
FeatureAttributeDescriptor[] pk = store.getDefaultFeatureType().getPrimaryKey(); |
|
803 |
if (pk == null || pk.length != 1) { |
|
804 |
return null; |
|
805 |
} |
|
806 |
return pk[0].getName(); |
|
807 |
} catch (DataException ex) { |
|
808 |
return null; |
|
809 |
} |
|
810 |
} |
|
828 |
attributePath[1] = attr; |
|
829 |
doAddAndSelect(theStore, attr, attributePath); |
|
830 |
return SIZE_ORDERED_ATTRIBUTES - 1; |
|
831 |
} catch (Exception ex) { |
|
832 |
LOGGER.warn("Not able to set foreign path into controller", ex); |
|
833 |
} |
|
811 | 834 |
|
812 |
private String getForeingKeyName(FeatureStore store, FeatureStore foreingStore) { |
|
813 |
try { |
|
814 |
for (FeatureAttributeDescriptor descriptor : store.getDefaultFeatureType()) { |
|
815 |
if (descriptor.isForeingKey()) { |
|
816 |
ForeingKey foreingKey = descriptor.getForeingKey(); |
|
817 |
if (isTheSameStore(foreingStore, foreingKey.getFeatureStore(null))) { |
|
818 |
return descriptor.getName(); |
|
819 |
} |
|
835 |
} |
|
836 |
|
|
837 |
} |
|
838 |
} catch (Exception ex) { |
|
839 |
LOGGER.warn("Controller not set.", ex); |
|
820 | 840 |
} |
821 |
} |
|
822 |
} catch (DataException ex) { |
|
823 |
return null; |
|
841 |
this.setAttribute(-1); |
|
842 |
return -1; |
|
824 | 843 |
} |
825 |
return null; |
|
826 |
} |
|
827 | 844 |
|
828 |
public boolean isValid(StringBuilder message) { |
|
829 |
try { |
|
830 |
Object value = this.getValue(); |
|
831 |
if (value == null) { |
|
832 |
return true; |
|
845 |
private boolean isTheSameStore(DataStore store1, DataStore store2) { |
|
846 |
String store1FullName = store1.getFullName(); |
|
847 |
String store2FullName = store2.getFullName(); |
|
848 |
return StringUtils.equalsIgnoreCase(store1FullName, store2FullName); |
|
833 | 849 |
} |
834 |
Field field = this.getCurrentField(); |
|
835 |
if (field == null) { |
|
836 |
return true; |
|
850 |
|
|
851 |
private String getPrimaryKeyName(FeatureStore store) { |
|
852 |
try { |
|
853 |
FeatureAttributeDescriptor[] pk = store.getDefaultFeatureType().getPrimaryKey(); |
|
854 |
if (pk == null || pk.length != 1) { |
|
855 |
return null; |
|
856 |
} |
|
857 |
return pk[0].getName(); |
|
858 |
} catch (DataException ex) { |
|
859 |
return null; |
|
860 |
} |
|
837 | 861 |
} |
838 |
if (field.getPath().length > 2) { |
|
839 |
message.append("Invalid field '").append(field.getLabel()).append("'.\n"); |
|
840 |
return false; |
|
862 |
|
|
863 |
private String getForeingKeyName(FeatureStore store, FeatureStore foreingStore) { |
|
864 |
try { |
|
865 |
for (FeatureAttributeDescriptor descriptor : store.getDefaultFeatureType()) { |
|
866 |
if (descriptor.isForeingKey()) { |
|
867 |
ForeingKey foreingKey = descriptor.getForeingKey(); |
|
868 |
if (isTheSameStore(foreingStore, foreingKey.getFeatureStore(null))) { |
|
869 |
return descriptor.getName(); |
|
870 |
} |
|
871 |
} |
|
872 |
} |
|
873 |
} catch (DataException ex) { |
|
874 |
return null; |
|
875 |
} |
|
876 |
return null; |
|
841 | 877 |
} |
842 |
FeatureAttributeDescriptor descriptor = field.getDescriptor(); |
|
843 |
switch (this.getRelationalOperator()) { |
|
844 |
case ExpressionBuilder.OPERATOR_EQ: |
|
845 |
case ExpressionBuilder.OPERATOR_NE: |
|
846 |
case ExpressionBuilder.OPERATOR_GT: |
|
847 |
case ExpressionBuilder.OPERATOR_GE: |
|
848 |
case ExpressionBuilder.OPERATOR_LT: |
|
849 |
case ExpressionBuilder.OPERATOR_LE: |
|
878 |
|
|
879 |
public boolean isValid(StringBuilder message) { |
|
850 | 880 |
try { |
851 |
descriptor.getDataType().coerce(value); |
|
852 |
} catch (CoercionException ex) { |
|
853 |
message.append("Invalid value '") |
|
854 |
.append(Objects.toString(value)) |
|
855 |
.append("' for field '") |
|
856 |
.append(descriptor.getLabel()) |
|
857 |
.append("'."); |
Also available in: Unified diff