Revision 45331 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 | ||
---|---|---|
83 | 83 |
|
84 | 84 |
private static final Logger LOGGER = LoggerFactory.getLogger(SearchConditionFieldController.class); |
85 | 85 |
private static final Class LOAD_MORE_ELEMENTS = SearchConditionFieldController.class; |
86 |
|
|
86 | 87 |
private static class Field extends LabeledValueImpl<String> { |
87 | 88 |
|
88 | 89 |
FeatureAttributeDescriptor attrdesc; |
... | ... | |
165 | 166 |
private DropDown ddnLogicalOperators; |
166 | 167 |
private DropDown ddnRelationalOperators; |
167 | 168 |
private DropDown ddnNullBehavior; |
168 |
|
|
169 |
|
|
169 | 170 |
private LabeledValue[] relationalOperators; |
170 | 171 |
private LabeledValue[] logicalOperators; |
171 | 172 |
private LabeledValue[] nullBehaviors; |
... | ... | |
254 | 255 |
this.ddnLogicalOperators = toolsSwingManager.createDropDown(lblLogicalOperators); |
255 | 256 |
this.ddnLogicalOperators.setVisibleDropdownArrow(false); |
256 | 257 |
} |
257 |
|
|
258 |
|
|
258 | 259 |
DefaultComboBoxModel modelRelationalOperators = new DefaultComboBoxModel(); |
259 | 260 |
for (LabeledValue op : relationalOperators) { |
260 | 261 |
modelRelationalOperators.addElement(op); |
... | ... | |
263 | 264 |
this.ddnRelationalOperators.addItemListener(new ItemListener() { |
264 | 265 |
@Override |
265 | 266 |
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 |
} |
|
267 |
doUpdateControllerByRelationalOperator(); |
|
280 | 268 |
} |
281 | 269 |
}); |
282 |
|
|
270 |
|
|
283 | 271 |
if (this.ddnLogicalOperators != null) { |
284 | 272 |
DefaultComboBoxModel modelLogicalOperators = new DefaultComboBoxModel(); |
285 | 273 |
for (LabeledValue op : logicalOperators) { |
... | ... | |
288 | 276 |
this.ddnLogicalOperators.setModel(modelLogicalOperators); |
289 | 277 |
this.ddnLogicalOperators.setSelectedIndex(1); |
290 | 278 |
} |
291 |
|
|
279 |
|
|
292 | 280 |
// this.ddnNullOperators = new DropDownLabelIcon(lblNull); |
293 | 281 |
this.ddnNullBehavior = toolsSwingManager.createDropDownIcon(lblNull); |
294 | 282 |
this.ddnNullBehavior.setVisibleDropdownArrow(false); |
... | ... | |
360 | 348 |
doSelectMoreFields(); |
361 | 349 |
} |
362 | 350 |
}); |
363 |
|
|
351 |
doUpdateControllerByRelationalOperator(); |
|
364 | 352 |
// clear(); |
365 | 353 |
} catch (Exception ex) { |
366 | 354 |
throw new RuntimeException(ex); |
367 | 355 |
} |
368 | 356 |
} |
369 | 357 |
|
358 |
private void doUpdateControllerByRelationalOperator() { |
|
359 |
Object item = ((LabeledValue) ddnRelationalOperators.getSelectedItem()).getValue(); |
|
360 |
if (ExpressionBuilder.OPERATOR_IS_NULL.equals(item) || ExpressionBuilder.OPERATOR_IS_NOT_NULL.equals(item)) { |
|
361 |
lblNull.setEnabled(false); |
|
362 |
cboValue.setEnabled(false); |
|
363 |
cboValue.setSelectedIndex(-1); |
|
364 |
} else { |
|
365 |
lblNull.setEnabled(true); |
|
366 |
cboValue.setEnabled(true); |
|
367 |
} |
|
368 |
|
|
369 |
} |
|
370 |
|
|
370 | 371 |
private FeatureType getFeatureType() { |
371 | 372 |
try { |
372 | 373 |
return this.store.getDefaultFeatureType(); |
... | ... | |
474 | 475 |
} |
475 | 476 |
this.cboValue.setSelectedIndex(-1); |
476 | 477 |
this.ddnNullBehavior.setSelectedIndex(0); |
478 |
doUpdateControllerByRelationalOperator(); |
|
477 | 479 |
} |
478 | 480 |
|
479 | 481 |
private void doUpdateValuesList() { |
... | ... | |
525 | 527 |
@Override |
526 | 528 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
527 | 529 |
Object value = ((Feature) o).get(field.getDescriptor().getName()); |
528 |
if (!values.contains(value)) { |
|
530 |
if (value!=null && !values.contains(value)) {
|
|
529 | 531 |
values.add(value); |
530 | 532 |
} |
531 | 533 |
if (System.currentTimeMillis() > timeLimit) { |
... | ... | |
598 | 600 |
ddnRelationalOperators.setEnabled(enabled); |
599 | 601 |
lblExtraFields.setEnabled(enabled); |
600 | 602 |
cboValue.setEnabled(enabled); |
603 |
doUpdateControllerByRelationalOperator(); |
|
601 | 604 |
} |
602 | 605 |
|
603 | 606 |
public String getRelationalOperator() { |
... | ... | |
620 | 623 |
return -1; |
621 | 624 |
} |
622 | 625 |
this.ddnRelationalOperators.setSelectedIndex(n); |
626 |
doUpdateControllerByRelationalOperator(); |
|
623 | 627 |
return n; |
624 | 628 |
} |
625 | 629 |
|
... | ... | |
922 | 926 |
ExpressionBuilder.Value filter = null; |
923 | 927 |
|
924 | 928 |
Object value = this.getValue(); |
925 |
if (value == null) { |
|
929 |
if (value == null |
|
930 |
&& this.getRelationalOperator() != ExpressionBuilder.OPERATOR_IS_NULL |
|
931 |
&& this.getRelationalOperator() != ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
|
926 | 932 |
return null; |
927 | 933 |
} |
928 | 934 |
Field field = this.getCurrentField(); |
... | ... | |
941 | 947 |
ExpressionBuilder.Constant value_constant = null; |
942 | 948 |
|
943 | 949 |
switch (this.getRelationalOperator()) { |
950 |
case ExpressionBuilder.OPERATOR_IS_NULL: |
|
951 |
filter = getFilterForOperatorNull(parentDescriptor, descriptor, builder, field); |
|
952 |
return filter; |
|
953 |
case ExpressionBuilder.OPERATOR_IS_NOT_NULL: |
|
954 |
filter = getFilterForOperatorNotNull(parentDescriptor, descriptor, builder, field); |
|
955 |
return filter; |
|
944 | 956 |
case ExpressionBuilder.OPERATOR_EQ: |
945 | 957 |
case ExpressionBuilder.OPERATOR_NE: |
946 | 958 |
case ExpressionBuilder.OPERATOR_GT: |
... | ... | |
963 | 975 |
} |
964 | 976 |
|
965 | 977 |
if (parentDescriptor == null) { |
966 |
if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NULL) { |
|
967 |
filter = builder.expression().is_null(builder.expression().column(this.store.getName(), descriptor.getName())); |
|
968 |
} else if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
|
969 |
filter = builder.expression().not_is_null(builder.expression().column(this.store.getName(), descriptor.getName())); |
|
970 |
} else { |
|
971 |
// Se busca en campos de la misma tabla. |
|
972 |
filter = builder.expression().binaryOperator( |
|
973 |
this.getRelationalOperator(), |
|
974 |
builder.expression().column(this.store.getName(), descriptor.getName()), |
|
975 |
value_constant |
|
976 |
); |
|
977 |
} |
|
978 |
// Se busca en campos de la misma tabla. |
|
979 |
filter = builder.expression().binaryOperator( |
|
980 |
this.getRelationalOperator(), |
|
981 |
builder.expression().column(this.store.getName(), descriptor.getName()), |
|
982 |
value_constant |
|
983 |
); |
|
978 | 984 |
|
979 |
ExpressionBuilder.Value null_value_constant = null; |
|
980 |
ExpressionBuilder.Function null_function = null; |
|
981 |
if (this.getRelationalOperator() != ExpressionBuilder.OPERATOR_IS_NULL && this.getRelationalOperator() != ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
|
982 |
if (this.getNullBehavior() == NULL_AS_TRUE) { |
|
983 |
null_value_constant = builder.expression().column(this.store.getName(), descriptor.getName()); |
|
984 |
null_function = builder.expression().is_null(null_value_constant); |
|
985 |
filter = builder.expression().or(null_function, filter); |
|
986 |
} else if (this.getNullBehavior() == NULL_AS_FALSE) { |
|
987 |
null_value_constant = builder.expression().column(this.store.getName(), descriptor.getName()); |
|
988 |
null_function = builder.expression().not_is_null(null_value_constant); |
|
989 |
filter = builder.expression().and(null_function, filter); |
|
990 |
} |
|
991 |
} |
|
985 |
ExpressionBuilder.Value nullValue = builder.expression().column(this.store.getName(), descriptor.getName()); |
|
986 |
filter = addNullBehavior(builder, filter, nullValue); |
|
992 | 987 |
|
993 | 988 |
} else { |
994 | 989 |
// Se busca en campos de una tabla relacionada. |
995 | 990 |
switch (parentDescriptor.getRelationType()) { |
996 | 991 |
case DynField.RELATION_TYPE_COLLABORATION: |
997 | 992 |
case DynField.RELATION_TYPE_IDENTITY: |
998 |
if (this.getRelationalOperator() ==ExpressionBuilder.OPERATOR_IS_NULL) { |
|
999 |
filter = builder.expression().is_null(builder.foreing_value( |
|
1000 |
parentDescriptor.getName(), |
|
1001 |
descriptor.getName() |
|
1002 |
)); |
|
1003 |
} else if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
|
1004 |
filter = builder.expression().not_is_null(builder.foreing_value( |
|
1005 |
parentDescriptor.getName(), |
|
1006 |
descriptor.getName() |
|
1007 |
)); |
|
1008 |
} else { |
|
1009 |
filter = builder.expression().binaryOperator( |
|
1010 |
this.getRelationalOperator(), |
|
1011 |
builder.foreing_value( |
|
1012 |
parentDescriptor.getName(), |
|
1013 |
descriptor.getName() |
|
1014 |
), |
|
1015 |
value_constant |
|
1016 |
); |
|
1017 |
ExpressionBuilder.Value null_value_constant = null; |
|
1018 |
ExpressionBuilder.Function null_function = null; |
|
1019 |
if (this.getNullBehavior() == NULL_AS_TRUE) { |
|
1020 |
null_value_constant = builder.foreing_value( |
|
993 |
filter = builder.expression().binaryOperator( |
|
994 |
this.getRelationalOperator(), |
|
995 |
builder.foreing_value( |
|
1021 | 996 |
parentDescriptor.getName(), |
1022 | 997 |
descriptor.getName() |
1023 |
); |
|
1024 |
null_function = builder.expression().is_null(null_value_constant); |
|
1025 |
filter = builder.expression().or(null_function, filter); |
|
1026 |
} else if (this.getNullBehavior() == NULL_AS_FALSE) { |
|
1027 |
null_value_constant = builder.foreing_value( |
|
1028 |
parentDescriptor.getName(), |
|
1029 |
descriptor.getName() |
|
1030 |
); |
|
1031 |
null_function = builder.expression().not_is_null(null_value_constant); |
|
1032 |
filter = builder.expression().and(null_function, filter); |
|
1033 |
} |
|
1034 |
|
|
1035 |
} |
|
998 |
), |
|
999 |
value_constant |
|
1000 |
); |
|
1001 |
ExpressionBuilder.Value nullValue = builder.foreing_value( |
|
1002 |
parentDescriptor.getName(), |
|
1003 |
descriptor.getName() |
|
1004 |
); |
|
1005 |
filter = addNullBehavior(builder, filter, nullValue); |
|
1036 | 1006 |
break; |
1037 | 1007 |
|
1038 | 1008 |
case DynField.RELATION_TYPE_AGGREGATE: |
1039 | 1009 |
case DynField.RELATION_TYPE_COMPOSITION: |
1040 | 1010 |
ExpressionBuilder.Value op_composition = null; |
1041 |
if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NULL) { |
|
1042 |
op_composition = builder.expression().is_null(builder.expression().column( |
|
1043 |
field.getFeatureStore().getName(), |
|
1044 |
descriptor.getName() |
|
1045 |
)); |
|
1046 |
} else if (this.getRelationalOperator() == ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
|
1047 |
op_composition = builder.expression().not_is_null(builder.expression().column( |
|
1048 |
field.getFeatureStore().getName(), |
|
1049 |
descriptor.getName() |
|
1050 |
)); |
|
1051 |
} else { |
|
1052 |
op_composition = builder.expression().binaryOperator( |
|
1053 |
this.getRelationalOperator(), |
|
1054 |
builder.expression().column( |
|
1055 |
field.getFeatureStore().getName(), |
|
1056 |
descriptor.getName() |
|
1057 |
), |
|
1058 |
value_constant |
|
1059 |
); |
|
1060 |
ExpressionBuilder.Value null_value_constant = null; |
|
1061 |
ExpressionBuilder.Function null_function = null; |
|
1062 |
if (this.getNullBehavior() == NULL_AS_TRUE) { |
|
1063 |
null_value_constant = builder.expression().column( |
|
1011 |
op_composition = builder.expression().binaryOperator( |
|
1012 |
this.getRelationalOperator(), |
|
1013 |
builder.expression().column( |
|
1064 | 1014 |
field.getFeatureStore().getName(), |
1065 | 1015 |
descriptor.getName() |
1066 |
); |
|
1067 |
null_function = builder.expression().is_null(null_value_constant); |
|
1068 |
op_composition = builder.expression().or(null_function, op_composition); |
|
1069 |
} else if (this.getNullBehavior() == NULL_AS_FALSE) { |
|
1070 |
null_value_constant = builder.expression().column( |
|
1071 |
field.getFeatureStore().getName(), |
|
1072 |
descriptor.getName() |
|
1073 |
); |
|
1074 |
null_function = builder.expression().not_is_null(null_value_constant); |
|
1075 |
op_composition = builder.expression().and(null_function, op_composition); |
|
1076 |
} |
|
1077 |
} |
|
1016 |
), |
|
1017 |
value_constant |
|
1018 |
); |
|
1019 |
ExpressionBuilder.Value null_value = builder.expression().column( |
|
1020 |
field.getFeatureStore().getName(), |
|
1021 |
descriptor.getName() |
|
1022 |
); |
|
1023 |
op_composition = addNullBehavior(builder, filter, null_value); |
|
1078 | 1024 |
|
1079 | 1025 |
filter = builder.exists(builder.select() |
1080 | 1026 |
.column(parentDescriptor.getFeatureType().getPrimaryKey()[0].getName()) |
... | ... | |
1100 | 1046 |
break; |
1101 | 1047 |
} |
1102 | 1048 |
} |
1103 |
|
|
1049 |
|
|
1104 | 1050 |
filter = builder.expression().group(filter); |
1105 | 1051 |
return filter; |
1106 | 1052 |
} |
... | ... | |
1188 | 1134 |
public int getNullBehavior() { |
1189 | 1135 |
return (int) ((LabeledValue) this.ddnNullBehavior.getSelectedItem()).getValue(); |
1190 | 1136 |
} |
1191 |
|
|
1192 |
|
|
1137 |
|
|
1193 | 1138 |
public int setNullBehavior(int nullBehaviorValue) { |
1194 |
int n = 0; |
|
1139 |
int n = 0;
|
|
1195 | 1140 |
for (LabeledValue nullBehavior : nullBehaviors) { |
1196 | 1141 |
int toInt = (int) nullBehavior.getValue(); |
1197 | 1142 |
if (nullBehaviorValue == toInt) { |
... | ... | |
1205 | 1150 |
this.ddnNullBehavior.setSelectedIndex(n); |
1206 | 1151 |
return n; |
1207 | 1152 |
} |
1153 |
|
|
1154 |
private ExpressionBuilder.Value addNullBehavior(DALExpressionBuilder builder, ExpressionBuilder.Value filter, ExpressionBuilder.Value nullValue) { |
|
1155 |
if (this.getRelationalOperator() != ExpressionBuilder.OPERATOR_IS_NULL && this.getRelationalOperator() != ExpressionBuilder.OPERATOR_IS_NOT_NULL) { |
|
1156 |
if (this.getNullBehavior() == NULL_AS_TRUE) { |
|
1157 |
ExpressionBuilder.Function null_function = builder.expression().is_null(nullValue); |
|
1158 |
filter = builder.expression().or(null_function, filter); |
|
1159 |
} else if (this.getNullBehavior() == NULL_AS_FALSE) { |
|
1160 |
ExpressionBuilder.Function null_function = builder.expression().not_is_null(nullValue); |
|
1161 |
filter = builder.expression().and(null_function, filter); |
|
1162 |
} |
|
1163 |
} |
|
1164 |
return filter; |
|
1165 |
} |
|
1166 |
|
|
1167 |
private ExpressionBuilder.Value getFilterForOperatorNull( |
|
1168 |
FeatureAttributeDescriptor parentDescriptor, |
|
1169 |
FeatureAttributeDescriptor descriptor, |
|
1170 |
DALExpressionBuilder builder, |
|
1171 |
Field field) { |
|
1172 |
|
|
1173 |
ExpressionBuilder.Value filter = null; |
|
1174 |
if (parentDescriptor == null) { |
|
1175 |
filter = builder.expression().is_null(builder.expression().column(this.store.getName(), descriptor.getName())); |
|
1176 |
} else { |
|
1177 |
// Se busca en campos de una tabla relacionada. |
|
1178 |
switch (parentDescriptor.getRelationType()) { |
|
1179 |
case DynField.RELATION_TYPE_COLLABORATION: |
|
1180 |
case DynField.RELATION_TYPE_IDENTITY: |
|
1181 |
filter = builder.expression().is_null(builder.foreing_value( |
|
1182 |
parentDescriptor.getName(), |
|
1183 |
descriptor.getName() |
|
1184 |
)); |
|
1185 |
case DynField.RELATION_TYPE_AGGREGATE: |
|
1186 |
case DynField.RELATION_TYPE_COMPOSITION: |
|
1187 |
ExpressionBuilder.Value op_composition = null; |
|
1188 |
op_composition = builder.expression().is_null(builder.expression().column( |
|
1189 |
field.getFeatureStore().getName(), |
|
1190 |
descriptor.getName() |
|
1191 |
)); |
|
1192 |
filter = builder.exists(builder.select() |
|
1193 |
.column(parentDescriptor.getFeatureType().getPrimaryKey()[0].getName()) |
|
1194 |
.from(field.getFeatureStore().getName()) |
|
1195 |
.limit(1) |
|
1196 |
.where( |
|
1197 |
builder.expression().and( |
|
1198 |
builder.expression().eq( |
|
1199 |
builder.expression().column( |
|
1200 |
field.getFeatureStore().getName(), |
|
1201 |
getForeingKeyName(field.getFeatureStore(), this.store) |
|
1202 |
), |
|
1203 |
builder.expression().column( |
|
1204 |
this.store.getName(), |
|
1205 |
getPrimaryKeyName(this.store) |
|
1206 |
) |
|
1207 |
), |
|
1208 |
op_composition |
|
1209 |
) |
|
1210 |
) |
|
1211 |
.toValue() |
|
1212 |
); |
|
1213 |
} |
|
1214 |
} |
|
1215 |
|
|
1216 |
filter = builder.expression().group(filter); |
|
1217 |
return filter; |
|
1218 |
} |
|
1219 |
|
|
1220 |
private ExpressionBuilder.Value getFilterForOperatorNotNull( |
|
1221 |
FeatureAttributeDescriptor parentDescriptor, |
|
1222 |
FeatureAttributeDescriptor descriptor, |
|
1223 |
DALExpressionBuilder builder, |
|
1224 |
Field field) { |
|
1225 |
|
|
1226 |
ExpressionBuilder.Value filter = null; |
|
1227 |
if (parentDescriptor == null) { |
|
1228 |
filter = builder.expression().not_is_null(builder.expression().column(this.store.getName(), descriptor.getName())); |
|
1229 |
} else { |
|
1230 |
// Se busca en campos de una tabla relacionada. |
|
1231 |
switch (parentDescriptor.getRelationType()) { |
|
1232 |
case DynField.RELATION_TYPE_COLLABORATION: |
|
1233 |
case DynField.RELATION_TYPE_IDENTITY: |
|
1234 |
filter = builder.expression().not_is_null(builder.foreing_value( |
|
1235 |
parentDescriptor.getName(), |
|
1236 |
descriptor.getName() |
|
1237 |
)); |
|
1238 |
case DynField.RELATION_TYPE_AGGREGATE: |
|
1239 |
case DynField.RELATION_TYPE_COMPOSITION: |
|
1240 |
ExpressionBuilder.Value op_composition = null; |
|
1241 |
op_composition = builder.expression().not_is_null(builder.expression().column( |
|
1242 |
field.getFeatureStore().getName(), |
|
1243 |
descriptor.getName() |
|
1244 |
)); |
|
1245 |
|
|
1246 |
filter = builder.exists(builder.select() |
|
1247 |
.column(parentDescriptor.getFeatureType().getPrimaryKey()[0].getName()) |
|
1248 |
.from(field.getFeatureStore().getName()) |
|
1249 |
.limit(1) |
|
1250 |
.where( |
|
1251 |
builder.expression().and( |
|
1252 |
builder.expression().eq( |
|
1253 |
builder.expression().column( |
|
1254 |
field.getFeatureStore().getName(), |
|
1255 |
getForeingKeyName(field.getFeatureStore(), this.store) |
|
1256 |
), |
|
1257 |
builder.expression().column( |
|
1258 |
this.store.getName(), |
|
1259 |
getPrimaryKeyName(this.store) |
|
1260 |
) |
|
1261 |
), |
|
1262 |
op_composition |
|
1263 |
) |
|
1264 |
) |
|
1265 |
.toValue() |
|
1266 |
); |
|
1267 |
} |
|
1268 |
} |
|
1269 |
|
|
1270 |
filter = builder.expression().group(filter); |
|
1271 |
return filter; |
|
1272 |
} |
|
1208 | 1273 |
} |
Also available in: Unified diff