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 / SearchConditionPanelAdvanced.java @ 47184
History | View | Annotate | Download (5.24 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.searchpanel; |
---|---|
2 |
|
3 |
import javax.swing.JButton; |
4 |
import javax.swing.JComponent; |
5 |
import javax.swing.event.ChangeListener; |
6 |
import javax.swing.text.JTextComponent; |
7 |
import org.gvsig.expressionevaluator.Expression; |
8 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
9 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
10 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
12 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
13 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
14 |
import org.gvsig.fmap.dal.swing.searchpanel.AbstractSearchConditionPanel; |
15 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel; |
16 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters; |
17 |
import org.gvsig.tools.swing.api.ChangeListenerHelper; |
18 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
19 |
|
20 |
/**
|
21 |
*
|
22 |
* @author jjdelcerro
|
23 |
*/
|
24 |
public class SearchConditionPanelAdvanced |
25 |
extends AbstractSearchConditionPanel
|
26 |
implements SearchConditionPanel {
|
27 |
|
28 |
@Override
|
29 |
public JComponent asJComponent() { |
30 |
return null; |
31 |
} |
32 |
|
33 |
@Override
|
34 |
public void put(SearchParameters params) { |
35 |
Expression filter = null; |
36 |
if (params.getQuery().getExpressionFilter()!=null) { |
37 |
try {
|
38 |
filter = params.getQuery().getExpressionFilter().clone(); |
39 |
} catch (CloneNotSupportedException ex) { |
40 |
throw new RuntimeException("Not able to clone advanced parameters", ex); |
41 |
} |
42 |
} |
43 |
this.set(filter);
|
44 |
} |
45 |
|
46 |
@Override
|
47 |
public SearchParameters fetch(SearchParameters params) {
|
48 |
if (params == null) { |
49 |
return params;
|
50 |
} |
51 |
Expression exp = this.get(); |
52 |
if (exp == null){ |
53 |
params.getQuery().setFilter((Expression) null); |
54 |
}else if (exp.isEmpty()) { |
55 |
params.getQuery().clearFilter(); |
56 |
} else {
|
57 |
try {
|
58 |
exp = this.get().clone();
|
59 |
} catch (CloneNotSupportedException ex) { |
60 |
throw new RuntimeException("Not able to clone advanced parameters", ex); |
61 |
} |
62 |
params.getQuery().setFilter(exp); |
63 |
} |
64 |
return params;
|
65 |
} |
66 |
|
67 |
private static class SearchConditionPanelAdvancedFactory |
68 |
implements SearchConditionPanelFactory {
|
69 |
|
70 |
@Override
|
71 |
public boolean isApplicable(FeatureStore store) { |
72 |
return true; |
73 |
} |
74 |
|
75 |
@Override
|
76 |
public SearchConditionPanel create(Object... os) { |
77 |
return null; |
78 |
} |
79 |
|
80 |
@Override
|
81 |
public String getName() { |
82 |
return "Advanced"; |
83 |
} |
84 |
|
85 |
} |
86 |
|
87 |
private static final SearchConditionPanelFactory FACTORY = new SearchConditionPanelAdvancedFactory(); |
88 |
|
89 |
private final ExpressionPickerController advancedExpression; |
90 |
private final FeatureStore store; |
91 |
private final ChangeListenerHelper changeListenerHelper; |
92 |
|
93 |
public SearchConditionPanelAdvanced(
|
94 |
FeatureStore store, |
95 |
JTextComponent text,
|
96 |
JButton button,
|
97 |
JButton bookmarks,
|
98 |
JButton history
|
99 |
) { |
100 |
this.changeListenerHelper = ToolsSwingLocator.getToolsSwingManager().createChangeListenerHelper();
|
101 |
this.store = store;
|
102 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
103 |
DataSwingManager dataSwingManager = DALSwingLocator.getManager(); |
104 |
this.advancedExpression = dataSwingManager.createExpressionPickerController(
|
105 |
this.store,
|
106 |
text, |
107 |
button, |
108 |
bookmarks, |
109 |
history |
110 |
); |
111 |
initComponents(); |
112 |
} |
113 |
|
114 |
@Override
|
115 |
public SearchConditionPanelFactory getFactory() {
|
116 |
return FACTORY;
|
117 |
} |
118 |
|
119 |
private void initComponents() { |
120 |
} |
121 |
|
122 |
@Override
|
123 |
public void clear() { |
124 |
this.advancedExpression.set(null); |
125 |
this.changeListenerHelper.fireEvent();
|
126 |
} |
127 |
|
128 |
@Override
|
129 |
public Expression get() { |
130 |
return this.advancedExpression.get(); |
131 |
} |
132 |
|
133 |
@Override
|
134 |
public boolean isValid(StringBuilder message) { |
135 |
if (this.advancedExpression.isValid()) { |
136 |
return true; |
137 |
} |
138 |
message.append("The expression entered is not valid.");
|
139 |
return false; |
140 |
} |
141 |
|
142 |
@Override
|
143 |
public boolean set(Expression filter) { |
144 |
this.advancedExpression.set(filter);
|
145 |
this.changeListenerHelper.fireEvent();
|
146 |
return true; |
147 |
} |
148 |
|
149 |
@Override
|
150 |
public void setEnabled(boolean enabled) { |
151 |
this.advancedExpression.setEnabled(enabled);
|
152 |
} |
153 |
|
154 |
@Override
|
155 |
public void addChangeListener(ChangeListener listener) { |
156 |
this.changeListenerHelper.addChangeListener(listener);
|
157 |
} |
158 |
|
159 |
@Override
|
160 |
public ChangeListener[] getChangeListeners() { |
161 |
return this.changeListenerHelper.getChangeListeners(); |
162 |
} |
163 |
|
164 |
@Override
|
165 |
public void removeChangeListener(ChangeListener listener) { |
166 |
this.changeListenerHelper.removeChangeListener(listener);
|
167 |
} |
168 |
|
169 |
@Override
|
170 |
public void removeAllChangeListener() { |
171 |
this.changeListenerHelper.removeAllChangeListener();
|
172 |
} |
173 |
|
174 |
@Override
|
175 |
public boolean hasChangeListeners() { |
176 |
return this.changeListenerHelper.hasChangeListeners(); |
177 |
} |
178 |
|
179 |
} |