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 / DefaultDataSwingManager.java @ 44603
History | View | Annotate | Download (13.9 KB)
1 | 42112 | jjdelcerro | /* gvSIG. Desktop Geographic Information System.
|
---|---|---|---|
2 | *
|
||
3 | * Copyright ? 2007-2014 gvSIG Association
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
18 | * MA 02110-1301, USA.
|
||
19 | *
|
||
20 | * For any additional information, do not hesitate to contact us
|
||
21 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
22 | */
|
||
23 | package org.gvsig.fmap.dal.swing.impl; |
||
24 | |||
25 | 44410 | jjdelcerro | import java.awt.Component; |
26 | 44263 | jjdelcerro | import java.util.Collection; |
27 | import java.util.Collections; |
||
28 | import java.util.LinkedHashMap; |
||
29 | 44340 | jjdelcerro | import java.util.List; |
30 | 44263 | jjdelcerro | import java.util.Map; |
31 | 44128 | jjdelcerro | import java.util.function.Predicate; |
32 | 44410 | jjdelcerro | import javax.swing.AbstractButton; |
33 | import javax.swing.Action; |
||
34 | 44077 | jjdelcerro | import javax.swing.JButton; |
35 | 44096 | jjdelcerro | import javax.swing.JComboBox; |
36 | 44215 | jjdelcerro | import javax.swing.JList; |
37 | 44077 | jjdelcerro | import javax.swing.JTextField; |
38 | 44340 | jjdelcerro | import javax.swing.table.TableModel; |
39 | 44128 | jjdelcerro | import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
40 | import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
||
41 | import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
||
42 | 42112 | jjdelcerro | import org.gvsig.featureform.swing.CreateJFeatureFormException; |
43 | 42775 | jjdelcerro | import org.gvsig.featureform.swing.JFeatureForm; |
44 | 42112 | jjdelcerro | |
45 | 42775 | jjdelcerro | import org.gvsig.featureform.swing.JFeaturesForm; |
46 | 42112 | jjdelcerro | import org.gvsig.featureform.swing.impl.DefaultJFeatureForm; |
47 | 42775 | jjdelcerro | import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm; |
48 | import org.gvsig.fmap.dal.DALLocator; |
||
49 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.DataManager; |
50 | 44191 | jjdelcerro | import org.gvsig.fmap.dal.DataStoreProviderFactory; |
51 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.exception.DataException; |
52 | import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
||
53 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.feature.Feature; |
54 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
55 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureQuery; |
56 | 42112 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
57 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
58 | import org.gvsig.fmap.dal.feature.FeatureTypeDefinitionsManager; |
||
59 | import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
||
60 | 44308 | jjdelcerro | import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
61 | 42112 | jjdelcerro | import org.gvsig.fmap.dal.swing.DataSwingManager; |
62 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.swing.FeatureTableModel; |
63 | import org.gvsig.fmap.dal.swing.JFeatureTable; |
||
64 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
65 | 44096 | jjdelcerro | import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController; |
66 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
67 | import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel; |
||
68 | 44263 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.expressionevaluator.DefaultFeatureStoreElement2; |
69 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretable.FeatureTablePanel; |
70 | import org.gvsig.fmap.dal.swing.impl.featuretable.table.DefaultFeatureTableModel; |
||
71 | import org.gvsig.fmap.dal.swing.impl.featuretable.table.EmptyFeatureTableModel; |
||
72 | 44096 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultAttributeDescriptorPickerController; |
73 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypeAttributePanel; |
74 | import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypePanel; |
||
75 | 42112 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionPanel; |
76 | 44259 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
77 | 44281 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.actions.SelectionAddAction.SelectionAddActionFactory; |
78 | import org.gvsig.fmap.dal.swing.impl.actions.SelectionFilterAction.SelectionFilterActionFactory; |
||
79 | import org.gvsig.fmap.dal.swing.impl.actions.SelectionSetAction.SelectionSetActionFactory; |
||
80 | import org.gvsig.fmap.dal.swing.impl.actions.ShowFormAction.ShowFormActionFactory; |
||
81 | 42112 | jjdelcerro | import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel; |
82 | 44259 | jjdelcerro | import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
83 | 42620 | jjdelcerro | import org.gvsig.tools.dynform.DynFormLocator; |
84 | import org.gvsig.tools.dynobject.DynClass; |
||
85 | 42775 | jjdelcerro | import org.gvsig.tools.dynobject.DynStruct; |
86 | import org.gvsig.tools.exception.BaseException; |
||
87 | 44281 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALActionFactory; |
88 | 44410 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext; |
89 | 44340 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel; |
90 | 44308 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionDialog; |
91 | import org.gvsig.fmap.dal.swing.impl.jdbc.JDBCConnectionPickerController; |
||
92 | import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog; |
||
93 | import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
||
94 | 42112 | jjdelcerro | |
95 | |||
96 | /**
|
||
97 | * @author fdiaz
|
||
98 | *
|
||
99 | */
|
||
100 | 44128 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
101 | 42775 | jjdelcerro | public class DefaultDataSwingManager implements DataSwingManager { |
102 | 42112 | jjdelcerro | |
103 | 44281 | jjdelcerro | private final Map<String,DALActionFactory> featureStoreSearchActions; |
104 | 44263 | jjdelcerro | |
105 | public DefaultDataSwingManager() {
|
||
106 | this.featureStoreSearchActions = new LinkedHashMap<>(); |
||
107 | 44281 | jjdelcerro | this.registerStoreAction(new SelectionAddActionFactory()); |
108 | this.registerStoreAction(new SelectionFilterActionFactory()); |
||
109 | this.registerStoreAction(new SelectionSetActionFactory()); |
||
110 | this.registerStoreAction(new ShowFormActionFactory()); |
||
111 | 44263 | jjdelcerro | } |
112 | |||
113 | 42512 | jjdelcerro | @Override
|
114 | 42775 | jjdelcerro | public JFeaturesForm createJFeaturesForm(FeatureStore store) throws CreateJFeatureFormException { |
115 | 42112 | jjdelcerro | try {
|
116 | 42775 | jjdelcerro | FeatureType featureType = store.getDefaultFeatureType(); |
117 | |||
118 | DefaultJFeaturesForm form = new DefaultJFeaturesForm();
|
||
119 | 44202 | jjdelcerro | form.bind(store, featureType2DynClass(store, featureType)); |
120 | 42775 | jjdelcerro | return form;
|
121 | |||
122 | } catch (Exception ex) { |
||
123 | throw new CreateJFeatureFormException(ex); |
||
124 | 42112 | jjdelcerro | } |
125 | } |
||
126 | |||
127 | 44202 | jjdelcerro | public DynClass featureType2DynClass(FeatureStore store, FeatureType type) {
|
128 | FeatureTypeDefinitionsManager featureTypeDefinitionsManager = DALLocator.getFeatureTypeDefinitionsManager(); |
||
129 | if( featureTypeDefinitionsManager.contains(store,type) ) {
|
||
130 | // Force reload next call to get.
|
||
131 | featureTypeDefinitionsManager.remove(store,type); |
||
132 | } |
||
133 | DynClass dynClass = featureTypeDefinitionsManager.get(store,type); |
||
134 | // Force reload next call to get.
|
||
135 | DynFormLocator.getDynFormManager().removeDefinition(dynClass.getName()); |
||
136 | return dynClass;
|
||
137 | } |
||
138 | |||
139 | 42512 | jjdelcerro | @Override
|
140 | 42112 | jjdelcerro | public JDBCConnectionPanel createJDBCConnectionPanel() {
|
141 | JDBCConnectionPanel x = new DefaultJDBCConnectionPanel();
|
||
142 | return x;
|
||
143 | } |
||
144 | |||
145 | 42512 | jjdelcerro | @Override
|
146 | 44308 | jjdelcerro | public JDBCConnectionDialog createJDBCConectionDialog() {
|
147 | JDBCConnectionDialog x = new DefaultJDBCConnectionDialog();
|
||
148 | return x;
|
||
149 | } |
||
150 | |||
151 | @Override
|
||
152 | 44128 | jjdelcerro | public JExpressionBuilder createQueryFilterExpresion(FeatureStore store) {
|
153 | DataManager dataManager = DALLocator.getDataManager(); |
||
154 | ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
||
155 | 44202 | jjdelcerro | FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
156 | 44128 | jjdelcerro | |
157 | Feature sampleFeature = null;
|
||
158 | try {
|
||
159 | sampleFeature = store.getFeatureSelection().first(); |
||
160 | if( sampleFeature == null ) { |
||
161 | sampleFeature = store.first(); |
||
162 | } |
||
163 | } catch (DataException ex) {
|
||
164 | } |
||
165 | final JExpressionBuilder builder = swingManager.createJExpressionBuilder();
|
||
166 | if( sampleFeature!=null ) { |
||
167 | featureSymbolTable.setFeature(sampleFeature); |
||
168 | builder.setPreviewSymbolTable(featureSymbolTable.createParent()); |
||
169 | } |
||
170 | 44202 | jjdelcerro | builder.addSymbolTable(featureSymbolTable); |
171 | 44263 | jjdelcerro | FeatureStoreElement storeElement = new DefaultFeatureStoreElement2(store);
|
172 | 44209 | jjdelcerro | builder.addElement(storeElement); |
173 | 44191 | jjdelcerro | if( store.getProviderFactory().hasSQLSupport()==DataStoreProviderFactory.YES ) {
|
174 | 44259 | jjdelcerro | builder.getPreferences().setSQLCompatible(true);
|
175 | 44191 | jjdelcerro | } |
176 | 44209 | jjdelcerro | builder.expandElement(storeElement); |
177 | 44128 | jjdelcerro | return builder;
|
178 | 42489 | jjdelcerro | } |
179 | 42112 | jjdelcerro | |
180 | 42775 | jjdelcerro | @Override
|
181 | public JFeatureForm createJFeatureForm(FeatureStore store) throws CreateJFeatureFormException { |
||
182 | JFeatureForm form = new DefaultJFeatureForm();
|
||
183 | form.setStore(store); |
||
184 | return form;
|
||
185 | } |
||
186 | |||
187 | @Override
|
||
188 | public JFeatureForm createJFeatureForm(Feature feature) throws CreateJFeatureFormException { |
||
189 | JFeatureForm form = new DefaultJFeatureForm();
|
||
190 | form.setFeature(feature); |
||
191 | return form;
|
||
192 | } |
||
193 | |||
194 | 44202 | jjdelcerro | @Override
|
195 | 42775 | jjdelcerro | public JFeatureTable createJFeatureTable(FeatureTableModel model) {
|
196 | return this.createJFeatureTable(model, true); |
||
197 | } |
||
198 | |||
199 | 44202 | jjdelcerro | @Override
|
200 | 42775 | jjdelcerro | public JFeatureTable createJFeatureTable(FeatureTableModel model, boolean isDoubleBuffered) { |
201 | return new FeatureTablePanel(model, isDoubleBuffered); |
||
202 | } |
||
203 | |||
204 | 44202 | jjdelcerro | @Override
|
205 | 42775 | jjdelcerro | public FeatureTableModel createEmptyFeatureTableModel(DynStruct struct) {
|
206 | return new EmptyFeatureTableModel(struct); |
||
207 | } |
||
208 | |||
209 | 44202 | jjdelcerro | @Override
|
210 | 42775 | jjdelcerro | public FeatureTableModel createFeatureTableModel(FeatureStore featureStore,
|
211 | FeatureQuery featureQuery) { |
||
212 | try {
|
||
213 | FeaturePagingHelper pager = DALLocator.getDataManager().createFeaturePagingHelper( |
||
214 | featureStore, featureQuery, |
||
215 | FeaturePagingHelper.DEFAULT_PAGE_SIZE |
||
216 | ); |
||
217 | return this.createFeatureTableModel(pager); |
||
218 | } catch (BaseException ex) {
|
||
219 | throw new RuntimeException("Can't create a FeatureTableModel.", ex); |
||
220 | } |
||
221 | } |
||
222 | |||
223 | 44202 | jjdelcerro | @Override
|
224 | 42775 | jjdelcerro | public FeatureTableModel createFeatureTableModel(FeaturePagingHelper featurePager) {
|
225 | return new DefaultFeatureTableModel(featurePager); |
||
226 | } |
||
227 | 44077 | jjdelcerro | |
228 | 44202 | jjdelcerro | @Override
|
229 | 44077 | jjdelcerro | public ProjectionPickerController createProjectionPickerController(
|
230 | JTextField txtProjection,
|
||
231 | JButton btnSelectProjection
|
||
232 | ) { |
||
233 | ProjectionPickerController picker = new ProjectionPickerController(txtProjection, btnSelectProjection);
|
||
234 | return picker;
|
||
235 | } |
||
236 | 44096 | jjdelcerro | |
237 | 44202 | jjdelcerro | @Override
|
238 | 44096 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo) { |
239 | 44128 | jjdelcerro | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, null); |
240 | 44096 | jjdelcerro | return controller;
|
241 | } |
||
242 | 44128 | jjdelcerro | |
243 | 44202 | jjdelcerro | @Override
|
244 | 44215 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list) { |
245 | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, null); |
||
246 | return controller;
|
||
247 | } |
||
248 | |||
249 | @Override
|
||
250 | 44128 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo, Predicate<FeatureAttributeDescriptor> filter) { |
251 | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, filter);
|
||
252 | return controller;
|
||
253 | } |
||
254 | |||
255 | 44202 | jjdelcerro | @Override
|
256 | 44215 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list, Predicate<FeatureAttributeDescriptor> filter) { |
257 | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, filter);
|
||
258 | return controller;
|
||
259 | } |
||
260 | |||
261 | @Override
|
||
262 | 44128 | jjdelcerro | public FeatureTypePanel createFeatureTypePanel() {
|
263 | FeatureTypePanel panel = new DefaultFeatureTypePanel();
|
||
264 | return panel;
|
||
265 | } |
||
266 | |||
267 | 44202 | jjdelcerro | @Override
|
268 | 44128 | jjdelcerro | public FeatureTypeAttributePanel createFeatureTypeAttributePanel() {
|
269 | FeatureTypeAttributePanel panel = new DefaultFeatureTypeAttributePanel();
|
||
270 | return panel;
|
||
271 | } |
||
272 | |||
273 | 44202 | jjdelcerro | @Override
|
274 | 44259 | jjdelcerro | public FeatureStoreElement createFeatureStoreElement() {
|
275 | 44263 | jjdelcerro | FeatureStoreElement e = new DefaultFeatureStoreElement2(null); |
276 | 44128 | jjdelcerro | return e;
|
277 | } |
||
278 | 44259 | jjdelcerro | |
279 | @Override
|
||
280 | 44285 | jjdelcerro | public FeatureStoreElement createFeatureStoreElement(FeatureStore store) {
|
281 | FeatureStoreElement e = new DefaultFeatureStoreElement2(store);
|
||
282 | return e;
|
||
283 | } |
||
284 | |||
285 | @Override
|
||
286 | 44259 | jjdelcerro | public FeatureStoreSearchPanel createFeatureStoreSearchPanel(FeatureStore store) {
|
287 | DefaultSearchPanel e = new DefaultSearchPanel(store);
|
||
288 | return e;
|
||
289 | } |
||
290 | |||
291 | 44263 | jjdelcerro | @Override
|
292 | 44281 | jjdelcerro | public final void registerStoreAction(DALActionFactory action) { |
293 | 44263 | jjdelcerro | this.featureStoreSearchActions.put(action.getName().toLowerCase(), action);
|
294 | } |
||
295 | 44259 | jjdelcerro | |
296 | 44263 | jjdelcerro | @Override
|
297 | 44281 | jjdelcerro | public Collection<DALActionFactory> getStoreActions() { |
298 | 44263 | jjdelcerro | return Collections.unmodifiableCollection(this.featureStoreSearchActions.values()); |
299 | } |
||
300 | 44308 | jjdelcerro | |
301 | @Override
|
||
302 | 44340 | jjdelcerro | public DALActionFactory getStoreAction(String name) { |
303 | DALActionFactory action = this.featureStoreSearchActions.get(name.toLowerCase());
|
||
304 | return action;
|
||
305 | } |
||
306 | 44410 | jjdelcerro | |
307 | @Override
|
||
308 | public void setStoreAction(AbstractButton component, String name, boolean preserveLabel, DALActionContext context) { |
||
309 | DALActionFactory factory = this.getStoreAction(name);
|
||
310 | Action action = factory.createAction(context);
|
||
311 | if( preserveLabel ) {
|
||
312 | String s = component.getText();
|
||
313 | component.setAction(action); |
||
314 | component.setText(s); |
||
315 | } else {
|
||
316 | component.setAction(action); |
||
317 | } |
||
318 | } |
||
319 | 44340 | jjdelcerro | |
320 | 44410 | jjdelcerro | |
321 | 44340 | jjdelcerro | @Override
|
322 | 44308 | jjdelcerro | public PickerController<JDBCServerExplorerParameters> createJDBCConnectionPickerController(
|
323 | JComboBox cboConnection, JButton btnConnection |
||
324 | ) { |
||
325 | JDBCConnectionPickerController x = new JDBCConnectionPickerController(cboConnection, btnConnection);
|
||
326 | return x;
|
||
327 | } |
||
328 | 44340 | jjdelcerro | |
329 | @Override
|
||
330 | public TableModel createSimpleFeaturesTableModel(FeatureStore store) { |
||
331 | try {
|
||
332 | SimpleFeaturesTableModel m = new SimpleFeaturesTableModel(store);
|
||
333 | return m;
|
||
334 | } catch (DataException ex) {
|
||
335 | throw new RuntimeException("Can't creatre SimpleFeaturesTableModel.", ex); |
||
336 | } |
||
337 | } |
||
338 | 44308 | jjdelcerro | |
339 | 44340 | jjdelcerro | @Override
|
340 | public TableModel createSimpleFeaturesTableModel(FeatureType featureType, List<String> columnNames, List<Feature> features) { |
||
341 | SimpleFeaturesTableModel m = new SimpleFeaturesTableModel(featureType, columnNames, features);
|
||
342 | return m;
|
||
343 | } |
||
344 | 44308 | jjdelcerro | |
345 | 42112 | jjdelcerro | } |