svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / searchpanel / DefaultSearchPanel.java @ 44603
History | View | Annotate | Download (25.2 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.searchpanel; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Cursor; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.net.URL; |
10 |
import java.util.ArrayList; |
11 |
import java.util.Collection; |
12 |
import java.util.HashMap; |
13 |
import java.util.List; |
14 |
import java.util.Map; |
15 |
import javax.swing.AbstractAction; |
16 |
import javax.swing.Action; |
17 |
import static javax.swing.Action.ACTION_COMMAND_KEY; |
18 |
import static javax.swing.Action.NAME; |
19 |
import javax.swing.BorderFactory; |
20 |
import javax.swing.ImageIcon; |
21 |
import javax.swing.JButton; |
22 |
import javax.swing.JComponent; |
23 |
import javax.swing.SwingUtilities; |
24 |
import javax.swing.event.ListSelectionEvent; |
25 |
import javax.swing.event.ListSelectionListener; |
26 |
import javax.swing.table.TableModel; |
27 |
import org.apache.commons.io.FilenameUtils; |
28 |
import org.apache.commons.lang.mutable.MutableObject; |
29 |
import org.apache.commons.lang3.StringUtils; |
30 |
import org.gvsig.configurableactions.ConfigurableActionsMamager; |
31 |
import org.gvsig.expressionevaluator.Code; |
32 |
import org.gvsig.expressionevaluator.Expression; |
33 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
34 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_AND; |
35 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_OR; |
36 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
37 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
38 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
39 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
40 |
import static org.gvsig.fmap.dal.DataManager.DAL_USE_LABELS; |
41 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_BOTH; |
42 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_NO; |
43 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_YES; |
44 |
import org.gvsig.fmap.dal.DataStore; |
45 |
import org.gvsig.fmap.dal.complements.Search; |
46 |
import org.gvsig.fmap.dal.exception.DataException; |
47 |
import org.gvsig.fmap.dal.feature.Feature; |
48 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
49 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
50 |
import org.gvsig.fmap.dal.feature.FeatureType; |
51 |
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory.AbstractDALActionContext; |
52 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
53 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
54 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel; |
55 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
56 |
import org.gvsig.tools.ToolsLocator; |
57 |
import org.gvsig.tools.dynobject.Tags; |
58 |
import org.gvsig.tools.i18n.I18nManager; |
59 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
60 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
61 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
62 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
63 |
import org.gvsig.tools.util.ToolsUtilLocator; |
64 |
import org.slf4j.Logger; |
65 |
import org.slf4j.LoggerFactory; |
66 |
|
67 |
/**
|
68 |
*
|
69 |
* @author jjdelcerro
|
70 |
*/
|
71 |
@SuppressWarnings({"UseSpecificCatch","Convert2Lambda"}) |
72 |
public class DefaultSearchPanel |
73 |
extends DefaultSearchPanelView
|
74 |
implements FeatureStoreSearchPanel {
|
75 |
|
76 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class); |
77 |
private Expression currentSearch; |
78 |
|
79 |
static /* friend */ Integer useLabels = null; |
80 |
|
81 |
public static class UseLabelsYesAction extends AbstractAction { |
82 |
|
83 |
public UseLabelsYesAction() {
|
84 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
85 |
|
86 |
this.putValue(NAME, i18n.getTranslation("_Use_labels")); |
87 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsYes"); |
88 |
} |
89 |
|
90 |
@Override
|
91 |
public Object getValue(String key) { |
92 |
if( NAME.equals(key) ) {
|
93 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
94 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
95 |
return i18n.getTranslation("_Use_labels"); |
96 |
} |
97 |
return super.getValue(key); |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public void actionPerformed(ActionEvent ae) { |
102 |
DefaultSearchPanel.useLabels = USE_LABELS_YES; |
103 |
} |
104 |
} |
105 |
|
106 |
public static class UseLabelsNoAction extends AbstractAction { |
107 |
|
108 |
public UseLabelsNoAction() {
|
109 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
110 |
this.putValue(NAME, i18n.getTranslation("_Use_names")); |
111 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsNo"); |
112 |
} |
113 |
|
114 |
@Override
|
115 |
public Object getValue(String key) { |
116 |
if( NAME.equals(key) ) {
|
117 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
118 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
119 |
return i18n.getTranslation("_Use_names"); |
120 |
} |
121 |
return super.getValue(key); |
122 |
} |
123 |
|
124 |
@Override
|
125 |
public void actionPerformed(ActionEvent ae) { |
126 |
DefaultSearchPanel.useLabels = USE_LABELS_NO; |
127 |
} |
128 |
} |
129 |
|
130 |
public static class UseLabelsBothAction extends AbstractAction { |
131 |
|
132 |
public UseLabelsBothAction() {
|
133 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
134 |
|
135 |
this.putValue(NAME, i18n.getTranslation("_Use_labels_and_names")); |
136 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsBoth"); |
137 |
} |
138 |
|
139 |
@Override
|
140 |
public Object getValue(String key) { |
141 |
if( NAME.equals(key) ) {
|
142 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
143 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
144 |
return i18n.getTranslation("_Use_labels_and_names"); |
145 |
} |
146 |
return super.getValue(key); |
147 |
} |
148 |
|
149 |
@Override
|
150 |
public void actionPerformed(ActionEvent ae) { |
151 |
DefaultSearchPanel.useLabels = USE_LABELS_BOTH; |
152 |
} |
153 |
} |
154 |
|
155 |
|
156 |
private class ActionButtons { |
157 |
|
158 |
private final DALActionFactory factory; |
159 |
private final Action action; |
160 |
private final JButton button; |
161 |
|
162 |
public ActionButtons(DALActionFactory factory, Action action, JButton button) { |
163 |
this.factory = factory;
|
164 |
this.action = action;
|
165 |
this.button = button;
|
166 |
} |
167 |
} |
168 |
|
169 |
public static class SearchActionContext extends AbstractDALActionContext { |
170 |
|
171 |
private final DefaultSearchPanel panel; |
172 |
|
173 |
public SearchActionContext(DefaultSearchPanel panel) {
|
174 |
super(FeatureStoreSearchPanel.ACTION_CONTEXT_NAME);
|
175 |
this.panel = panel;
|
176 |
} |
177 |
|
178 |
@Override
|
179 |
public DataStore getStore() {
|
180 |
return this.panel.getStore(); |
181 |
} |
182 |
|
183 |
@Override
|
184 |
public Expression getFilter() { |
185 |
return this.panel.getCurrentSearch(); |
186 |
} |
187 |
|
188 |
@Override
|
189 |
public JComponent getActionButton(String actionName) { |
190 |
return this.panel.getActionButton(actionName); |
191 |
} |
192 |
|
193 |
@Override
|
194 |
public int getSelectedsCount() { |
195 |
return this.panel.getSelectedFeatureCount(); |
196 |
} |
197 |
|
198 |
@Override
|
199 |
public Expression getFilterForSelecteds() { |
200 |
return this.panel.getSearchForSelectedFeature(); |
201 |
} |
202 |
} |
203 |
|
204 |
private final FeatureStore store; |
205 |
private final ActionListenerSupport acctionListeners; |
206 |
private List<SearchFieldController> searchFields; |
207 |
private ExpressionPickerController advancedExpression;
|
208 |
private final Map<String, ActionButtons> actions; |
209 |
private boolean showActions = true; |
210 |
private int maxSearhFields = 4; |
211 |
private final I18nManager i18n = ToolsLocator.getI18nManager(); |
212 |
|
213 |
public DefaultSearchPanel(FeatureStore store) {
|
214 |
this.store = store;
|
215 |
this.acctionListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
|
216 |
this.searchFields = null; |
217 |
this.actions = new HashMap<>(); |
218 |
} |
219 |
|
220 |
@Override
|
221 |
public JComponent asJComponent() { |
222 |
if( this.searchFields==null ) { |
223 |
this.initComponents();
|
224 |
} |
225 |
return this; |
226 |
} |
227 |
|
228 |
private void addActions() { |
229 |
if( !this.showActions ) { |
230 |
return;
|
231 |
} |
232 |
this.pnlActions.removeAll();
|
233 |
this.pnlActions.setLayout(new FlowLayout(FlowLayout.TRAILING, 8, 4)); |
234 |
SearchActionContext actionContext = new SearchActionContext(this); |
235 |
Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions();
|
236 |
for (DALActionFactory factory : factories) {
|
237 |
Action action = factory.createAction(actionContext);
|
238 |
JButton button = new JButton(action); |
239 |
this.actions.put(factory.getName(), new ActionButtons(factory, action, button)); |
240 |
button.setBorder(BorderFactory.createEmptyBorder());
|
241 |
button.setBorderPainted(false);
|
242 |
button.setFocusPainted(false);
|
243 |
button.setContentAreaFilled(false);
|
244 |
button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
245 |
this.pnlActions.add(button);
|
246 |
} |
247 |
this.pnlActions.revalidate();
|
248 |
this.pnlActions.repaint();
|
249 |
} |
250 |
|
251 |
@Override
|
252 |
public void addActionListener(ActionListener listener) { |
253 |
this.acctionListeners.addActionListener(listener);
|
254 |
} |
255 |
|
256 |
@Override
|
257 |
public ActionListener[] getActionListeners() { |
258 |
return this.acctionListeners.getActionListeners(); |
259 |
} |
260 |
|
261 |
@Override
|
262 |
public void removeActionListener(ActionListener listener) { |
263 |
this.acctionListeners.removeActionListener(listener);
|
264 |
} |
265 |
|
266 |
@Override
|
267 |
public void removeAllActionListener() { |
268 |
this.acctionListeners.removeAllActionListener();
|
269 |
} |
270 |
|
271 |
@Override
|
272 |
public void fireActionEvent(ActionEvent event) { |
273 |
this.acctionListeners.fireActionEvent(event);
|
274 |
} |
275 |
|
276 |
@Override
|
277 |
public boolean hasActionListeners() { |
278 |
return this.acctionListeners.hasActionListeners(); |
279 |
} |
280 |
|
281 |
private void initComponents() { |
282 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
283 |
swingManager.translate(this.tabSearchMode);
|
284 |
swingManager.translate(this.btnSearch);
|
285 |
swingManager.translate(this.btnClear);
|
286 |
swingManager.translate(this.lblExpressionDeBusqueda);
|
287 |
|
288 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
289 |
JComponent c = cfgActionsManager.getConfigurableActionsComponent(CONFIGURABLE_PANEL_ID, this); |
290 |
this.pnlCfgActions.setLayout(new BorderLayout(0,0)); |
291 |
this.pnlCfgActions.add(c, BorderLayout.CENTER); |
292 |
|
293 |
this.searchFields = new ArrayList<>(); |
294 |
SearchFieldController controller = new SearchFieldController(
|
295 |
store, |
296 |
lblField1, |
297 |
lblExtraFields1, |
298 |
lblRelationalOperator1, |
299 |
cboValue1, |
300 |
lblLogicalOperators1 |
301 |
); |
302 |
this.searchFields.add(controller);
|
303 |
controller = new SearchFieldController(
|
304 |
store, |
305 |
lblField2, |
306 |
lblExtraFields2, |
307 |
lblRelationalOperator2, |
308 |
cboValue2, |
309 |
lblLogicalOperators2 |
310 |
); |
311 |
this.searchFields.add(controller);
|
312 |
controller = new SearchFieldController(
|
313 |
store, |
314 |
lblField3, |
315 |
lblExtraFields3, |
316 |
lblRelationalOperator3, |
317 |
cboValue3, |
318 |
lblLogicalOperators3 |
319 |
); |
320 |
this.searchFields.add(controller);
|
321 |
controller = new SearchFieldController(
|
322 |
store, |
323 |
lblField4, |
324 |
lblExtraFields4, |
325 |
lblRelationalOperator4, |
326 |
cboValue4, |
327 |
null
|
328 |
); |
329 |
this.searchFields.add(controller);
|
330 |
try {
|
331 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
332 |
Search.COMPLEMENT_MANE, this.store.getDefaultFeatureType()
|
333 |
); |
334 |
List<Search.OrderedAttribute> orderedAttributes = search.getOrderedAttributes(
|
335 |
Search.BASIC_TYPES_FILTER, |
336 |
Search.STR_INT_LONG_LABEL_ORDER, |
337 |
5
|
338 |
); |
339 |
this.maxSearhFields = Integer.min(orderedAttributes.size(), 4); |
340 |
int n = 0; |
341 |
for (SearchFieldController searchField : searchFields) {
|
342 |
if( n<this.maxSearhFields ) { |
343 |
searchField.setAttribute(orderedAttributes.get(n++).getDescriptor().getName()); |
344 |
} else {
|
345 |
searchField.setEnabled(false);
|
346 |
} |
347 |
} |
348 |
} catch (DataException ex) {
|
349 |
LOGGER.warn("Can't determine order of attributes", ex);
|
350 |
} |
351 |
|
352 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
353 |
this.advancedExpression = expressionSwingManager.createExpressionPickerController(
|
354 |
txtAdvancedExpression, |
355 |
btnAdvancedExpression, |
356 |
btnAdvancedExpressionHistory, |
357 |
btnAdvancedExpressionBookmarks |
358 |
); |
359 |
this.advancedExpression.addElement(
|
360 |
DALSwingLocator.getSwingManager().createFeatureStoreElement(store) |
361 |
); |
362 |
|
363 |
this.btnSearch.addActionListener(new ActionListener() { |
364 |
@Override
|
365 |
public void actionPerformed(ActionEvent e) { |
366 |
doSearch(); |
367 |
} |
368 |
}); |
369 |
|
370 |
this.tblResults.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
371 |
@Override
|
372 |
public void valueChanged(ListSelectionEvent e) { |
373 |
for (ActionButtons actionButton : actions.values()) {
|
374 |
if( actionButton.action instanceof ListSelectionListener) { |
375 |
((ListSelectionListener) actionButton.action).valueChanged(e);
|
376 |
} |
377 |
} |
378 |
} |
379 |
}); |
380 |
this.btnClear.addActionListener(new ActionListener() { |
381 |
@Override
|
382 |
public void actionPerformed(ActionEvent e) { |
383 |
clear(); |
384 |
} |
385 |
}); |
386 |
addActions(); |
387 |
this.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); |
388 |
|
389 |
doSearch(null);
|
390 |
} |
391 |
|
392 |
@Override
|
393 |
public void setEnabled(boolean enabled) { |
394 |
if( this.searchFields==null ) { |
395 |
initComponents(); |
396 |
} |
397 |
int n=0; |
398 |
for (SearchFieldController searchField : searchFields) {
|
399 |
if( n<this.maxSearhFields ) { |
400 |
searchField.setEnabled(enabled); |
401 |
} else {
|
402 |
searchField.setEnabled(false);
|
403 |
} |
404 |
n++; |
405 |
} |
406 |
this.btnClear.setEnabled(enabled);
|
407 |
this.btnSearch.setEnabled(enabled);
|
408 |
this.advancedExpression.setEnabled(enabled);
|
409 |
for (ActionButtons actionButton : actions.values()) {
|
410 |
actionButton.action.setEnabled(enabled); |
411 |
} |
412 |
} |
413 |
|
414 |
public void clear() { |
415 |
if( this.searchFields==null ) { |
416 |
return;
|
417 |
} |
418 |
for (SearchFieldController searchField : searchFields) {
|
419 |
searchField.clear(); |
420 |
} |
421 |
this.advancedExpression.set(null); |
422 |
} |
423 |
|
424 |
@Override
|
425 |
public Expression getFilter() { |
426 |
Expression filter;
|
427 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
428 |
if (searchMode == 1) { // Avanzada |
429 |
filter = this.advancedExpression.get();
|
430 |
} else {
|
431 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
432 |
String relational = OPERATOR_OR;
|
433 |
for (SearchFieldController searchField : searchFields) {
|
434 |
if (searchField.getAttribute() != null && searchField.getValue() != null) { |
435 |
ExpressionBuilder.BinaryOperator cond = builder.binaryOperator( |
436 |
searchField.getRelationalOperator(), |
437 |
searchField.isAttributeAnExpression() |
438 |
? builder.custom(searchField.getAttribute()) |
439 |
: builder.column(searchField.getAttribute()), |
440 |
builder.constant(searchField.getValue()) |
441 |
); |
442 |
if (relational.equals(OPERATOR_AND)) {
|
443 |
builder.and(cond); |
444 |
} else {
|
445 |
builder.or(cond); |
446 |
} |
447 |
relational = searchField.getLogicalOperator(); |
448 |
} |
449 |
} |
450 |
if (builder.isEmpty()) {
|
451 |
filter = null;
|
452 |
} else {
|
453 |
filter = ExpressionUtils.createExpression(builder.toString()); |
454 |
} |
455 |
} |
456 |
if (ExpressionUtils.isPhraseEmpty(filter)) {
|
457 |
return null; |
458 |
} |
459 |
return filter;
|
460 |
} |
461 |
|
462 |
private void doSearch() { |
463 |
Expression filter = this.getFilter(); |
464 |
doSearch(filter); |
465 |
} |
466 |
|
467 |
private void doSearch(final Expression exp) { |
468 |
final MutableObject model = new MutableObject(null); |
469 |
|
470 |
lblMsg.setText("Searching...");
|
471 |
setEnabled(false);
|
472 |
Thread th = new Thread(new Runnable() { |
473 |
@Override
|
474 |
public void run() { |
475 |
try {
|
476 |
final List<Feature> features; |
477 |
if (exp == null) { |
478 |
features = store.getFeatures(); |
479 |
} else {
|
480 |
features = store.getFeatures(exp); |
481 |
} |
482 |
currentSearch = exp; |
483 |
model.setValue( new SimpleFeaturesTableModel(
|
484 |
store.getDefaultFeatureType(), |
485 |
null,
|
486 |
features |
487 |
) |
488 |
); |
489 |
} catch (DataException ex) {
|
490 |
LOGGER.warn("Can't get features or create table model",ex);
|
491 |
} finally {
|
492 |
SwingUtilities.invokeLater(new Runnable() { |
493 |
@Override
|
494 |
public void run() { |
495 |
TableModel m = (TableModel) model.getValue(); |
496 |
tblResults.setModel(m); |
497 |
lblMsg.setText(String.format("%d "+i18n.getTranslation("_elements"), m.getRowCount())); |
498 |
setEnabled(true);
|
499 |
} |
500 |
}); |
501 |
} |
502 |
} |
503 |
}); |
504 |
th.start(); |
505 |
} |
506 |
|
507 |
@Override
|
508 |
public Expression getCurrentSearch() { |
509 |
return this.currentSearch; |
510 |
} |
511 |
|
512 |
@Override
|
513 |
public boolean setFilter(Expression filter) { |
514 |
try {
|
515 |
if( this.advancedExpression==null ) { |
516 |
this.initComponents();
|
517 |
} |
518 |
if( ExpressionUtils.isPhraseEmpty(filter) ) {
|
519 |
this.clear();
|
520 |
return true; |
521 |
} |
522 |
this.advancedExpression.set(filter);
|
523 |
this.tabSearchMode.setSelectedIndex(1); |
524 |
|
525 |
Code code = filter.getCode(); |
526 |
if( code.code()==Code.CALLER) {
|
527 |
SearchFieldController searchField = this.searchFields.get(0); |
528 |
Code.Caller caller = (Code.Caller)code; |
529 |
if( searchField.isAValidRelationOperator(caller.name())) {
|
530 |
Code op1 = caller.parameters().get(0);
|
531 |
Code op2 = caller.parameters().get(1);
|
532 |
if( op1.code()==Code.IDENTIFIER && op2.code()==Code.CONSTANT ) {
|
533 |
if( searchField.setAttribute(((Code.Identifier)op1).name())>=0 ) { |
534 |
searchField.setRelationalOperator(caller.name()); |
535 |
searchField.setValue(((Code.Constant)op2).value()); |
536 |
this.tabSearchMode.setSelectedIndex(0); |
537 |
} |
538 |
} |
539 |
} |
540 |
} |
541 |
SimpleFeaturesTableModel model = new SimpleFeaturesTableModel(this.getStore()); |
542 |
tblResults.setModel(model); |
543 |
lblMsg.setText("");
|
544 |
return true; |
545 |
} catch(Exception ex) { |
546 |
LOGGER.warn("Can't set current search", ex);
|
547 |
return false; |
548 |
} |
549 |
} |
550 |
|
551 |
@Override
|
552 |
public void setCurrentSearch(Expression filter) { |
553 |
if( this.setFilter(filter) ) { |
554 |
doSearch(); |
555 |
} |
556 |
} |
557 |
|
558 |
@Override
|
559 |
public Expression getSearchForSelectedFeature() { |
560 |
if( this.searchFields==null ) { |
561 |
return null; |
562 |
} |
563 |
int selectedRow = this.tblResults.getSelectedRow(); |
564 |
if (selectedRow < 0) { |
565 |
return null; |
566 |
} |
567 |
try {
|
568 |
List<Feature> features = ((SimpleFeaturesTableModel) this.tblResults.getModel()).getFeatures(); |
569 |
Feature feature = features.get(selectedRow); |
570 |
|
571 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
572 |
FeatureType ftype = this.store.getDefaultFeatureType();
|
573 |
for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
|
574 |
builder.and( |
575 |
builder.eq( |
576 |
builder.column(attrdesc.getName()), |
577 |
builder.constant(feature.get(attrdesc.getName())) |
578 |
) |
579 |
); |
580 |
} |
581 |
Expression filter = ExpressionUtils.createExpression(builder.toString());
|
582 |
return filter;
|
583 |
} catch (Exception ex) { |
584 |
LOGGER.warn("Can't build search for the selected feature.", ex);
|
585 |
return null; |
586 |
} |
587 |
} |
588 |
|
589 |
@Override
|
590 |
public FeatureStore getStore() {
|
591 |
return store;
|
592 |
} |
593 |
|
594 |
@Override
|
595 |
public ImageIcon loadImage(String imageName) { |
596 |
String name = FilenameUtils.getBaseName(imageName);
|
597 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
598 |
if (theme.exists(name)) {
|
599 |
return theme.get(name);
|
600 |
} |
601 |
URL url = this.getClass().getResource(name + ".png"); |
602 |
if (url == null) { |
603 |
return null; |
604 |
} |
605 |
return new ImageIcon(url); |
606 |
} |
607 |
|
608 |
public static void selfRegister() { |
609 |
String[][] iconNames = new String[][]{ |
610 |
new String[]{"dalswing", "featurestore-column"}, |
611 |
new String[]{"dalswing", "featurestore-foreing-key"}, |
612 |
new String[]{"dalswing", "featurestore-table"}, |
613 |
new String[]{"dalswing", "search-action-showform"}, |
614 |
new String[]{"dalswing", "search-action-select"}, |
615 |
new String[]{"dalswing", "search-action-select-add"}, |
616 |
new String[]{"dalswing", "search-action-select-filter"} |
617 |
}; |
618 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
619 |
for (String[] icon : iconNames) { |
620 |
URL url = DefaultSearchPanel.class.getResource(icon[1] + ".png"); |
621 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
622 |
} |
623 |
|
624 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
625 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsYesAction());
|
626 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsNoAction());
|
627 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsBothAction());
|
628 |
|
629 |
} |
630 |
|
631 |
@Override
|
632 |
public int getSelectedFeatureCount() { |
633 |
if( this.searchFields==null ) { |
634 |
return 0; |
635 |
} |
636 |
return this.tblResults.getSelectedRowCount(); |
637 |
} |
638 |
|
639 |
@Override
|
640 |
public JComponent getActionButton(String name) { |
641 |
ActionButtons actionButton = this.actions.get(name);
|
642 |
if( actionButton==null ) { |
643 |
return null; |
644 |
} |
645 |
return actionButton.button;
|
646 |
} |
647 |
|
648 |
@Override
|
649 |
public void setShowActions(boolean showActions) { |
650 |
this.showActions = showActions;
|
651 |
} |
652 |
|
653 |
@Override
|
654 |
public boolean isShowActions() { |
655 |
return this.showActions; |
656 |
} |
657 |
|
658 |
|
659 |
public static String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc, String tableName) { |
660 |
String theLabel;
|
661 |
int theUseLabels;
|
662 |
if( useLabels == null ) { |
663 |
Tags tags = attrdesc.getTags(); |
664 |
if( tags.has(DAL_USE_LABELS) ) {
|
665 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
666 |
} else {
|
667 |
tags = attrdesc.getFeatureType().getTags(); |
668 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
669 |
} |
670 |
} else {
|
671 |
theUseLabels = useLabels; |
672 |
} |
673 |
switch(theUseLabels) {
|
674 |
case USE_LABELS_YES:
|
675 |
if( StringUtils.isBlank(tableName) ) {
|
676 |
theLabel = attrdesc.getLocalizedLabel(); |
677 |
} else {
|
678 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), tableName); |
679 |
} |
680 |
break;
|
681 |
default:
|
682 |
case USE_LABELS_NO:
|
683 |
if( StringUtils.isBlank(tableName) ) {
|
684 |
theLabel = attrdesc.getName(); |
685 |
} else {
|
686 |
theLabel = String.format("%s [%s]", attrdesc.getName(), tableName); |
687 |
} |
688 |
break;
|
689 |
case USE_LABELS_BOTH:
|
690 |
if( StringUtils.isBlank(tableName) ) {
|
691 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName()); |
692 |
} else {
|
693 |
theLabel = String.format("%s [%s/%s]", attrdesc.getLocalizedLabel(), attrdesc.getName(), tableName); |
694 |
} |
695 |
break;
|
696 |
} |
697 |
return theLabel;
|
698 |
} |
699 |
|
700 |
} |