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 @ 44644
History | View | Annotate | Download (14.5 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 | 44263 | jjdelcerro | import java.util.Collection; |
26 | import java.util.Collections; |
||
27 | import java.util.LinkedHashMap; |
||
28 | 44340 | jjdelcerro | import java.util.List; |
29 | 44263 | jjdelcerro | import java.util.Map; |
30 | 44128 | jjdelcerro | import java.util.function.Predicate; |
31 | 44410 | jjdelcerro | import javax.swing.AbstractButton; |
32 | import javax.swing.Action; |
||
33 | 44077 | jjdelcerro | import javax.swing.JButton; |
34 | 44096 | jjdelcerro | import javax.swing.JComboBox; |
35 | 44215 | jjdelcerro | import javax.swing.JList; |
36 | 44077 | jjdelcerro | import javax.swing.JTextField; |
37 | 44644 | jjdelcerro | import javax.swing.ListCellRenderer; |
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 | 44644 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributeListCellRenderer; |
91 | 44308 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionDialog; |
92 | import org.gvsig.fmap.dal.swing.impl.jdbc.JDBCConnectionPickerController; |
||
93 | 44644 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.orderpanel.DefaultFeatureStoreOrderPanel; |
94 | 44308 | jjdelcerro | import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog; |
95 | 44644 | jjdelcerro | import org.gvsig.fmap.dal.swing.orderpanel.FeatureStoreOrderPanel; |
96 | 44308 | jjdelcerro | import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
97 | 42112 | jjdelcerro | |
98 | |||
99 | /**
|
||
100 | * @author fdiaz
|
||
101 | *
|
||
102 | */
|
||
103 | 44128 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
104 | 42775 | jjdelcerro | public class DefaultDataSwingManager implements DataSwingManager { |
105 | 42112 | jjdelcerro | |
106 | 44281 | jjdelcerro | private final Map<String,DALActionFactory> featureStoreSearchActions; |
107 | 44263 | jjdelcerro | |
108 | public DefaultDataSwingManager() {
|
||
109 | this.featureStoreSearchActions = new LinkedHashMap<>(); |
||
110 | 44281 | jjdelcerro | this.registerStoreAction(new SelectionAddActionFactory()); |
111 | this.registerStoreAction(new SelectionFilterActionFactory()); |
||
112 | this.registerStoreAction(new SelectionSetActionFactory()); |
||
113 | this.registerStoreAction(new ShowFormActionFactory()); |
||
114 | 44263 | jjdelcerro | } |
115 | |||
116 | 42512 | jjdelcerro | @Override
|
117 | 42775 | jjdelcerro | public JFeaturesForm createJFeaturesForm(FeatureStore store) throws CreateJFeatureFormException { |
118 | 42112 | jjdelcerro | try {
|
119 | 42775 | jjdelcerro | FeatureType featureType = store.getDefaultFeatureType(); |
120 | |||
121 | DefaultJFeaturesForm form = new DefaultJFeaturesForm();
|
||
122 | 44202 | jjdelcerro | form.bind(store, featureType2DynClass(store, featureType)); |
123 | 42775 | jjdelcerro | return form;
|
124 | |||
125 | } catch (Exception ex) { |
||
126 | throw new CreateJFeatureFormException(ex); |
||
127 | 42112 | jjdelcerro | } |
128 | } |
||
129 | |||
130 | 44202 | jjdelcerro | public DynClass featureType2DynClass(FeatureStore store, FeatureType type) {
|
131 | FeatureTypeDefinitionsManager featureTypeDefinitionsManager = DALLocator.getFeatureTypeDefinitionsManager(); |
||
132 | if( featureTypeDefinitionsManager.contains(store,type) ) {
|
||
133 | // Force reload next call to get.
|
||
134 | featureTypeDefinitionsManager.remove(store,type); |
||
135 | } |
||
136 | DynClass dynClass = featureTypeDefinitionsManager.get(store,type); |
||
137 | // Force reload next call to get.
|
||
138 | DynFormLocator.getDynFormManager().removeDefinition(dynClass.getName()); |
||
139 | return dynClass;
|
||
140 | } |
||
141 | |||
142 | 42512 | jjdelcerro | @Override
|
143 | 42112 | jjdelcerro | public JDBCConnectionPanel createJDBCConnectionPanel() {
|
144 | JDBCConnectionPanel x = new DefaultJDBCConnectionPanel();
|
||
145 | return x;
|
||
146 | } |
||
147 | |||
148 | 42512 | jjdelcerro | @Override
|
149 | 44308 | jjdelcerro | public JDBCConnectionDialog createJDBCConectionDialog() {
|
150 | JDBCConnectionDialog x = new DefaultJDBCConnectionDialog();
|
||
151 | return x;
|
||
152 | } |
||
153 | |||
154 | @Override
|
||
155 | 44128 | jjdelcerro | public JExpressionBuilder createQueryFilterExpresion(FeatureStore store) {
|
156 | DataManager dataManager = DALLocator.getDataManager(); |
||
157 | ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
||
158 | 44202 | jjdelcerro | FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
159 | 44128 | jjdelcerro | |
160 | Feature sampleFeature = null;
|
||
161 | try {
|
||
162 | sampleFeature = store.getFeatureSelection().first(); |
||
163 | if( sampleFeature == null ) { |
||
164 | sampleFeature = store.first(); |
||
165 | } |
||
166 | } catch (DataException ex) {
|
||
167 | } |
||
168 | final JExpressionBuilder builder = swingManager.createJExpressionBuilder();
|
||
169 | if( sampleFeature!=null ) { |
||
170 | featureSymbolTable.setFeature(sampleFeature); |
||
171 | builder.setPreviewSymbolTable(featureSymbolTable.createParent()); |
||
172 | } |
||
173 | 44202 | jjdelcerro | builder.addSymbolTable(featureSymbolTable); |
174 | 44263 | jjdelcerro | FeatureStoreElement storeElement = new DefaultFeatureStoreElement2(store);
|
175 | 44209 | jjdelcerro | builder.addElement(storeElement); |
176 | 44191 | jjdelcerro | if( store.getProviderFactory().hasSQLSupport()==DataStoreProviderFactory.YES ) {
|
177 | 44259 | jjdelcerro | builder.getPreferences().setSQLCompatible(true);
|
178 | 44191 | jjdelcerro | } |
179 | 44209 | jjdelcerro | builder.expandElement(storeElement); |
180 | 44128 | jjdelcerro | return builder;
|
181 | 42489 | jjdelcerro | } |
182 | 42112 | jjdelcerro | |
183 | 42775 | jjdelcerro | @Override
|
184 | public JFeatureForm createJFeatureForm(FeatureStore store) throws CreateJFeatureFormException { |
||
185 | JFeatureForm form = new DefaultJFeatureForm();
|
||
186 | form.setStore(store); |
||
187 | return form;
|
||
188 | } |
||
189 | |||
190 | @Override
|
||
191 | public JFeatureForm createJFeatureForm(Feature feature) throws CreateJFeatureFormException { |
||
192 | JFeatureForm form = new DefaultJFeatureForm();
|
||
193 | form.setFeature(feature); |
||
194 | return form;
|
||
195 | } |
||
196 | |||
197 | 44202 | jjdelcerro | @Override
|
198 | 42775 | jjdelcerro | public JFeatureTable createJFeatureTable(FeatureTableModel model) {
|
199 | return this.createJFeatureTable(model, true); |
||
200 | } |
||
201 | |||
202 | 44202 | jjdelcerro | @Override
|
203 | 42775 | jjdelcerro | public JFeatureTable createJFeatureTable(FeatureTableModel model, boolean isDoubleBuffered) { |
204 | return new FeatureTablePanel(model, isDoubleBuffered); |
||
205 | } |
||
206 | |||
207 | 44202 | jjdelcerro | @Override
|
208 | 42775 | jjdelcerro | public FeatureTableModel createEmptyFeatureTableModel(DynStruct struct) {
|
209 | return new EmptyFeatureTableModel(struct); |
||
210 | } |
||
211 | |||
212 | 44202 | jjdelcerro | @Override
|
213 | 42775 | jjdelcerro | public FeatureTableModel createFeatureTableModel(FeatureStore featureStore,
|
214 | FeatureQuery featureQuery) { |
||
215 | try {
|
||
216 | FeaturePagingHelper pager = DALLocator.getDataManager().createFeaturePagingHelper( |
||
217 | featureStore, featureQuery, |
||
218 | FeaturePagingHelper.DEFAULT_PAGE_SIZE |
||
219 | ); |
||
220 | return this.createFeatureTableModel(pager); |
||
221 | } catch (BaseException ex) {
|
||
222 | throw new RuntimeException("Can't create a FeatureTableModel.", ex); |
||
223 | } |
||
224 | } |
||
225 | |||
226 | 44202 | jjdelcerro | @Override
|
227 | 42775 | jjdelcerro | public FeatureTableModel createFeatureTableModel(FeaturePagingHelper featurePager) {
|
228 | return new DefaultFeatureTableModel(featurePager); |
||
229 | } |
||
230 | 44077 | jjdelcerro | |
231 | 44202 | jjdelcerro | @Override
|
232 | 44077 | jjdelcerro | public ProjectionPickerController createProjectionPickerController(
|
233 | JTextField txtProjection,
|
||
234 | JButton btnSelectProjection
|
||
235 | ) { |
||
236 | ProjectionPickerController picker = new ProjectionPickerController(txtProjection, btnSelectProjection);
|
||
237 | return picker;
|
||
238 | } |
||
239 | 44096 | jjdelcerro | |
240 | 44202 | jjdelcerro | @Override
|
241 | 44096 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo) { |
242 | 44128 | jjdelcerro | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, null); |
243 | 44096 | jjdelcerro | return controller;
|
244 | } |
||
245 | 44128 | jjdelcerro | |
246 | 44202 | jjdelcerro | @Override
|
247 | 44215 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list) { |
248 | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, null); |
||
249 | return controller;
|
||
250 | } |
||
251 | |||
252 | @Override
|
||
253 | 44128 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo, Predicate<FeatureAttributeDescriptor> filter) { |
254 | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, filter);
|
||
255 | return controller;
|
||
256 | } |
||
257 | |||
258 | 44202 | jjdelcerro | @Override
|
259 | 44215 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list, Predicate<FeatureAttributeDescriptor> filter) { |
260 | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, filter);
|
||
261 | return controller;
|
||
262 | } |
||
263 | |||
264 | @Override
|
||
265 | 44128 | jjdelcerro | public FeatureTypePanel createFeatureTypePanel() {
|
266 | FeatureTypePanel panel = new DefaultFeatureTypePanel();
|
||
267 | return panel;
|
||
268 | } |
||
269 | |||
270 | 44202 | jjdelcerro | @Override
|
271 | 44128 | jjdelcerro | public FeatureTypeAttributePanel createFeatureTypeAttributePanel() {
|
272 | FeatureTypeAttributePanel panel = new DefaultFeatureTypeAttributePanel();
|
||
273 | return panel;
|
||
274 | } |
||
275 | |||
276 | 44202 | jjdelcerro | @Override
|
277 | 44259 | jjdelcerro | public FeatureStoreElement createFeatureStoreElement() {
|
278 | 44263 | jjdelcerro | FeatureStoreElement e = new DefaultFeatureStoreElement2(null); |
279 | 44128 | jjdelcerro | return e;
|
280 | } |
||
281 | 44259 | jjdelcerro | |
282 | @Override
|
||
283 | 44285 | jjdelcerro | public FeatureStoreElement createFeatureStoreElement(FeatureStore store) {
|
284 | FeatureStoreElement e = new DefaultFeatureStoreElement2(store);
|
||
285 | return e;
|
||
286 | } |
||
287 | |||
288 | @Override
|
||
289 | 44259 | jjdelcerro | public FeatureStoreSearchPanel createFeatureStoreSearchPanel(FeatureStore store) {
|
290 | DefaultSearchPanel e = new DefaultSearchPanel(store);
|
||
291 | return e;
|
||
292 | } |
||
293 | |||
294 | 44263 | jjdelcerro | @Override
|
295 | 44281 | jjdelcerro | public final void registerStoreAction(DALActionFactory action) { |
296 | 44263 | jjdelcerro | this.featureStoreSearchActions.put(action.getName().toLowerCase(), action);
|
297 | } |
||
298 | 44259 | jjdelcerro | |
299 | 44263 | jjdelcerro | @Override
|
300 | 44281 | jjdelcerro | public Collection<DALActionFactory> getStoreActions() { |
301 | 44263 | jjdelcerro | return Collections.unmodifiableCollection(this.featureStoreSearchActions.values()); |
302 | } |
||
303 | 44308 | jjdelcerro | |
304 | @Override
|
||
305 | 44340 | jjdelcerro | public DALActionFactory getStoreAction(String name) { |
306 | DALActionFactory action = this.featureStoreSearchActions.get(name.toLowerCase());
|
||
307 | return action;
|
||
308 | } |
||
309 | 44410 | jjdelcerro | |
310 | @Override
|
||
311 | public void setStoreAction(AbstractButton component, String name, boolean preserveLabel, DALActionContext context) { |
||
312 | DALActionFactory factory = this.getStoreAction(name);
|
||
313 | Action action = factory.createAction(context);
|
||
314 | if( preserveLabel ) {
|
||
315 | String s = component.getText();
|
||
316 | component.setAction(action); |
||
317 | component.setText(s); |
||
318 | } else {
|
||
319 | component.setAction(action); |
||
320 | } |
||
321 | } |
||
322 | 44340 | jjdelcerro | |
323 | 44410 | jjdelcerro | |
324 | 44340 | jjdelcerro | @Override
|
325 | 44308 | jjdelcerro | public PickerController<JDBCServerExplorerParameters> createJDBCConnectionPickerController(
|
326 | JComboBox cboConnection, JButton btnConnection |
||
327 | ) { |
||
328 | JDBCConnectionPickerController x = new JDBCConnectionPickerController(cboConnection, btnConnection);
|
||
329 | return x;
|
||
330 | } |
||
331 | 44340 | jjdelcerro | |
332 | @Override
|
||
333 | public TableModel createSimpleFeaturesTableModel(FeatureStore store) { |
||
334 | try {
|
||
335 | SimpleFeaturesTableModel m = new SimpleFeaturesTableModel(store);
|
||
336 | return m;
|
||
337 | } catch (DataException ex) {
|
||
338 | throw new RuntimeException("Can't creatre SimpleFeaturesTableModel.", ex); |
||
339 | } |
||
340 | } |
||
341 | 44308 | jjdelcerro | |
342 | 44340 | jjdelcerro | @Override
|
343 | public TableModel createSimpleFeaturesTableModel(FeatureType featureType, List<String> columnNames, List<Feature> features) { |
||
344 | SimpleFeaturesTableModel m = new SimpleFeaturesTableModel(featureType, columnNames, features);
|
||
345 | return m;
|
||
346 | } |
||
347 | 44644 | jjdelcerro | |
348 | @Override
|
||
349 | public ListCellRenderer createDefaultFeatureAttributeListCellRenderer() { |
||
350 | ListCellRenderer r = new DefaultFeatureAttributeListCellRenderer(); |
||
351 | return r;
|
||
352 | } |
||
353 | |||
354 | @Override
|
||
355 | public FeatureStoreOrderPanel createFeatureStoreOrderPanel() {
|
||
356 | DefaultFeatureStoreOrderPanel p = new DefaultFeatureStoreOrderPanel();
|
||
357 | return p;
|
||
358 | } |
||
359 | 44308 | jjdelcerro | |
360 | 42112 | jjdelcerro | } |