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