Revision 45222 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 org.gvsig.fmap.dal.swing.searchpanel.SearchParameters; |
|
48 | 49 |
import org.gvsig.tools.ToolsLocator; |
49 | 50 |
import org.gvsig.tools.dataTypes.Coercion; |
50 | 51 |
import org.gvsig.tools.dataTypes.CoercionException; |
... | ... | |
78 | 79 |
public class SearchConditionFieldController { |
79 | 80 |
|
80 | 81 |
private static final Logger LOGGER = LoggerFactory.getLogger(SearchConditionFieldController.class); |
81 |
|
|
82 |
private static final Class LOAD_MORE_ELEMENTS = SearchConditionFieldController.class; |
|
82 | 83 |
private static class Field extends LabeledValueImpl<String> { |
83 | 84 |
|
84 | 85 |
FeatureAttributeDescriptor attrdesc; |
... | ... | |
148 | 149 |
} |
149 | 150 |
|
150 | 151 |
private FeatureStore store; |
152 |
private SearchParameters parameters; |
|
151 | 153 |
private final JLabel lblFields; |
152 | 154 |
private final JLabel lblExtraFields; |
153 | 155 |
private final JLabel lblLogicalOperators; |
... | ... | |
164 | 166 |
private final int SIZE_ORDERED_ATTRIBUTES = 20; |
165 | 167 |
|
166 | 168 |
private DatePickerController dateController = null; |
169 |
|
|
170 |
|
|
171 |
private int updateValuesTimeLimit; |
|
172 |
private int updateValuesFeaturesLimit; |
|
173 |
private boolean canHasMoreElements; |
|
167 | 174 |
|
175 |
|
|
168 | 176 |
public SearchConditionFieldController( |
177 |
SearchParameters parameters, |
|
169 | 178 |
FeatureStore store, |
170 | 179 |
JLabel lblFields, |
171 | 180 |
JLabel lblExtraFields, |
... | ... | |
173 | 182 |
JComboBox cboValue, |
174 | 183 |
JLabel lblLogicalOperators |
175 | 184 |
) { |
185 |
this.parameters = parameters; |
|
176 | 186 |
this.store = store; |
177 | 187 |
this.lblFields = lblFields; |
178 | 188 |
this.lblExtraFields = lblExtraFields; |
179 | 189 |
this.lblRelationalOperators = lblRelationalOperators; |
180 | 190 |
this.cboValue = cboValue; |
181 | 191 |
this.lblLogicalOperators = lblLogicalOperators; |
192 |
this.updateValuesTimeLimit = 60; |
|
193 |
this.updateValuesFeaturesLimit = 1000; |
|
194 |
this.canHasMoreElements = false; |
|
182 | 195 |
this.initComponents(); |
183 | 196 |
} |
184 | 197 |
|
... | ... | |
235 | 248 |
} |
236 | 249 |
this.ddnLogicalOperators.setModel(modelLogicalOperators); |
237 | 250 |
} |
238 |
FeatureType featureType = store.getDefaultFeatureType();
|
|
251 |
FeatureType featureType = parameters.getFeatureType(store);
|
|
239 | 252 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
240 | 253 |
Search.COMPLEMENT_MANE, featureType |
241 | 254 |
); |
... | ... | |
275 | 288 |
|
276 | 289 |
} |
277 | 290 |
}); |
278 |
|
|
291 |
|
|
292 |
this.cboValue.addItemListener(new ItemListener() { |
|
293 |
@Override |
|
294 |
public void itemStateChanged(ItemEvent e) { |
|
295 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
296 |
if (cboValue.getSelectedItem()!=null && cboValue.getSelectedItem() instanceof LabeledValue ) { |
|
297 |
if (Objects.equals(((LabeledValue)cboValue.getSelectedItem()).getValue(), LOAD_MORE_ELEMENTS)) { |
|
298 |
setUpdateValuesLimits(updateValuesTimeLimit+10, updateValuesFeaturesLimit+20000); |
|
299 |
} |
|
300 |
} |
|
301 |
} |
|
302 |
} |
|
303 |
}); |
|
304 |
|
|
279 | 305 |
this.lblExtraFields.addMouseListener(new MouseAdapter() { |
280 | 306 |
@Override |
281 | 307 |
public void mouseClicked(MouseEvent e) { |
... | ... | |
297 | 323 |
} |
298 | 324 |
|
299 | 325 |
private void doSelectMoreFields() { |
300 |
DefaultFeatureAttributeSelectionPanel panel = new DefaultFeatureAttributeSelectionPanel(store); |
|
326 |
DefaultFeatureAttributeSelectionPanel panel = new DefaultFeatureAttributeSelectionPanel(store, parameters.getFeatureType(store));
|
|
301 | 327 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
302 | 328 |
final Dialog dialog = winManager.createDialog( |
303 | 329 |
panel, |
... | ... | |
319 | 345 |
} |
320 | 346 |
|
321 | 347 |
private void doAddAndSelect(FeatureStore theStore, FeatureAttributeDescriptor attrdesc, FeatureAttributeDescriptor[] path) { |
348 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
349 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
322 | 350 |
DefaultComboBoxModel<Field> model = (DefaultComboBoxModel) this.ddnFields.getModel(); |
351 |
if (attrdesc ==null) { |
|
352 |
dialogManager.messageDialog( |
|
353 |
i18n.getTranslation("_It_is_not_supported_to_search_through_this_field")+"\n"+ |
|
354 |
i18n.getTranslation("_Field_not_found"), |
|
355 |
"_Warning", |
|
356 |
JOptionPane.WARNING_MESSAGE |
|
357 |
); |
|
358 |
return; |
|
359 |
} |
|
360 |
|
|
323 | 361 |
for (int i = 0; i < model.getSize(); i++) { |
324 | 362 |
Field field = model.getElementAt(i); |
325 | 363 |
FeatureAttributeDescriptor attrdescN = field.getDescriptor(); |
... | ... | |
336 | 374 |
Search.OrderedAttribute.TYPE_REGURAL, |
337 | 375 |
!isTheSameStore(store, theStore) |
338 | 376 |
); |
339 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
340 | 377 |
if (field.getPath().length > 2) { |
341 | 378 |
dialogManager.messageDialog( |
342 |
"It not supported to search through this field." + "\n"
|
|
343 |
+ "Too many links.",
|
|
379 |
i18n.getTranslation("_It_is_not_supported_to_search_through_this_field") + "\n"
|
|
380 |
+ i18n.getTranslation("_To_many_links"),
|
|
344 | 381 |
"_Warning", |
345 | 382 |
JOptionPane.WARNING_MESSAGE |
346 | 383 |
); |
... | ... | |
406 | 443 |
} |
407 | 444 |
|
408 | 445 |
final List<Object> values = new ArrayList<>(); |
409 |
final int limit = 60; |
|
410 |
final long timeLimit = System.currentTimeMillis() + limit * 1000; |
|
411 | 446 |
final DefaultComboBoxModel model = new DefaultComboBoxModel(); |
412 | 447 |
this.setEnabled(false); |
413 | 448 |
final FeatureStore theStore = field.getFeatureStore(); |
414 |
final FeatureQuery query = theStore.createFeatureQuery(); |
|
449 |
final FeatureQuery query = parameters.getQuery().getCopy(); // theStore.createFeatureQuery();
|
|
415 | 450 |
query.addAttributeName(field.getDescriptor().getName()); |
416 |
query.setLimit(1000); |
|
451 |
query.setFilter(""); |
|
452 |
query.setLimit(updateValuesFeaturesLimit); |
|
453 |
query.getGroupByColumns().clear(); |
|
454 |
query.getAggregateFunctions().clear(); |
|
417 | 455 |
Thread th = new Thread(new Runnable() { |
418 | 456 |
@Override |
419 | 457 |
public void run() { |
420 | 458 |
FeatureSet set = null; |
421 | 459 |
try { |
460 |
canHasMoreElements = false; |
|
422 | 461 |
set = theStore.getFeatureSet(query); |
462 |
if (set.size()>=updateValuesFeaturesLimit) { |
|
463 |
canHasMoreElements = true; |
|
464 |
} |
|
465 |
final long timeLimit = System.currentTimeMillis() + updateValuesTimeLimit * 1000; |
|
423 | 466 |
set.accept(new Visitor() { |
424 | 467 |
@Override |
425 | 468 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
... | ... | |
428 | 471 |
values.add(value); |
429 | 472 |
} |
430 | 473 |
if (System.currentTimeMillis() > timeLimit) { |
474 |
canHasMoreElements = true; |
|
431 | 475 |
throw new VisitCanceledException(); |
432 | 476 |
} |
433 | 477 |
if (values.size() > 1000) { |
478 |
canHasMoreElements = true; |
|
434 | 479 |
throw new VisitCanceledException(); |
435 | 480 |
} |
436 | 481 |
} |
437 | 482 |
}); |
438 | 483 |
} catch (VisitCanceledException ex) { |
439 |
|
|
484 |
canHasMoreElements = true; |
|
440 | 485 |
} catch (Exception ex) { |
441 | 486 |
LOGGER.warn("Can't update list of values of '" + field.getLabel() + "'.", ex); |
442 | 487 |
} finally { |
... | ... | |
473 | 518 |
for (LabeledValue element : elements) { |
474 | 519 |
model.addElement(element); |
475 | 520 |
} |
521 |
if (canHasMoreElements) { |
|
522 |
model.addElement(new LabeledValueImpl("...", LOAD_MORE_ELEMENTS)); |
|
523 |
} |
|
476 | 524 |
SwingUtilities.invokeLater(new Runnable() { |
477 | 525 |
@Override |
478 | 526 |
public void run() { |
... | ... | |
926 | 974 |
} |
927 | 975 |
|
928 | 976 |
} |
977 |
|
|
978 |
public void setUpdateValuesLimits(int limit, int featuresLimit) { |
|
979 |
this.updateValuesTimeLimit = limit; |
|
980 |
this.updateValuesFeaturesLimit = featuresLimit; |
|
981 |
doUpdateValuesList(); |
|
982 |
} |
|
929 | 983 |
} |
Also available in: Unified diff