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 @ 45234
History | View | Annotate | Download (18.6 KB)
1 |
/* 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 |
import java.util.Collection; |
26 |
import java.util.Collections; |
27 |
import java.util.HashMap; |
28 |
import java.util.LinkedHashMap; |
29 |
import java.util.List; |
30 |
import java.util.Map; |
31 |
import java.util.function.Predicate; |
32 |
import javax.swing.AbstractButton; |
33 |
import javax.swing.Action; |
34 |
import javax.swing.JButton; |
35 |
import javax.swing.JComboBox; |
36 |
import javax.swing.JList; |
37 |
import javax.swing.JTextField; |
38 |
import javax.swing.ListCellRenderer; |
39 |
import javax.swing.table.TableModel; |
40 |
import javax.swing.text.JTextComponent; |
41 |
import org.apache.commons.lang3.StringUtils; |
42 |
import org.gvsig.expressionevaluator.swing.Element; |
43 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
44 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
45 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
46 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
47 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
48 |
import org.gvsig.featureform.swing.CreateJFeatureFormException; |
49 |
import org.gvsig.featureform.swing.JFeatureForm; |
50 |
|
51 |
import org.gvsig.featureform.swing.JFeaturesForm; |
52 |
import org.gvsig.featureform.swing.impl.DefaultJFeatureForm; |
53 |
import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm; |
54 |
import org.gvsig.fmap.dal.DALLocator; |
55 |
import org.gvsig.fmap.dal.DataManager; |
56 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
57 |
import org.gvsig.fmap.dal.exception.DataException; |
58 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
59 |
import org.gvsig.fmap.dal.feature.Feature; |
60 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
61 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
62 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
63 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
64 |
import org.gvsig.fmap.dal.feature.FeatureType; |
65 |
import org.gvsig.fmap.dal.feature.FeatureTypeDefinitionsManager; |
66 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
67 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
68 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
69 |
import org.gvsig.fmap.dal.swing.FeatureTableModel; |
70 |
import org.gvsig.fmap.dal.swing.JFeatureTable; |
71 |
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
72 |
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController; |
73 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
74 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel; |
75 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.DefaultFeatureStoreElement2; |
76 |
import org.gvsig.fmap.dal.swing.impl.featuretable.FeatureTablePanel; |
77 |
import org.gvsig.fmap.dal.swing.impl.featuretable.table.DefaultFeatureTableModel; |
78 |
import org.gvsig.fmap.dal.swing.impl.featuretable.table.EmptyFeatureTableModel; |
79 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultAttributeDescriptorPickerController; |
80 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributePanel; |
81 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypePanel; |
82 |
import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionPanel; |
83 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
84 |
import org.gvsig.fmap.dal.swing.impl.actions.SelectionAddAction.SelectionAddActionFactory; |
85 |
import org.gvsig.fmap.dal.swing.impl.actions.SelectionFilterAction.SelectionFilterActionFactory; |
86 |
import org.gvsig.fmap.dal.swing.impl.actions.SelectionSetAction.SelectionSetActionFactory; |
87 |
import org.gvsig.fmap.dal.swing.impl.actions.ShowFormAction.ShowFormActionFactory; |
88 |
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel; |
89 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
90 |
import org.gvsig.tools.dynform.DynFormLocator; |
91 |
import org.gvsig.tools.dynobject.DynClass; |
92 |
import org.gvsig.tools.dynobject.DynStruct; |
93 |
import org.gvsig.tools.exception.BaseException; |
94 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
95 |
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext; |
96 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel; |
97 |
import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeListCellRenderer; |
98 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributesSelectionPanel; |
99 |
import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionDialog; |
100 |
import org.gvsig.fmap.dal.swing.impl.jdbc.JDBCConnectionPickerController; |
101 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryOrderPanel; |
102 |
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog; |
103 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory; |
104 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
105 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryOrderPanel; |
106 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel; |
107 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.CheckTableFieldsSuggestionProviderFactory; |
108 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.QuotesForFieldNameSuggestionProviderFactory; |
109 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.StorePointFieldSuggestionProviderFactory; |
110 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.WrongNameFieldSuggestionProviderFactory; |
111 |
|
112 |
|
113 |
/**
|
114 |
* @author fdiaz
|
115 |
*
|
116 |
*/
|
117 |
@SuppressWarnings("UseSpecificCatch") |
118 |
public class DefaultDataSwingManager implements DataSwingManager { |
119 |
|
120 |
private final Map<String,DALActionFactory> featureStoreSearchActions; |
121 |
private Map<String,SearchConditionPanelFactory> searchConditionPanelFactories; |
122 |
|
123 |
public DefaultDataSwingManager() {
|
124 |
this.featureStoreSearchActions = new LinkedHashMap<>(); |
125 |
this.registerStoreAction(new SelectionAddActionFactory()); |
126 |
this.registerStoreAction(new SelectionFilterActionFactory()); |
127 |
this.registerStoreAction(new SelectionSetActionFactory()); |
128 |
this.registerStoreAction(new ShowFormActionFactory()); |
129 |
} |
130 |
|
131 |
@Override
|
132 |
public JFeaturesForm createJFeaturesForm(FeatureStore store) throws CreateJFeatureFormException { |
133 |
try {
|
134 |
FeatureType featureType = store.getDefaultFeatureType(); |
135 |
|
136 |
DefaultJFeaturesForm form = new DefaultJFeaturesForm();
|
137 |
form.bind(store, featureType2DynClass(store, featureType)); |
138 |
return form;
|
139 |
|
140 |
} catch (Exception ex) { |
141 |
throw new CreateJFeatureFormException(ex); |
142 |
} |
143 |
} |
144 |
|
145 |
public DynClass featureType2DynClass(FeatureStore store, FeatureType type) {
|
146 |
FeatureTypeDefinitionsManager featureTypeDefinitionsManager = DALLocator.getFeatureTypeDefinitionsManager(); |
147 |
if( featureTypeDefinitionsManager.contains(store,type) ) {
|
148 |
// Force reload next call to get.
|
149 |
featureTypeDefinitionsManager.remove(store,type); |
150 |
} |
151 |
DynClass dynClass = featureTypeDefinitionsManager.get(store,type); |
152 |
// Force reload next call to get.
|
153 |
DynFormLocator.getDynFormManager().removeDefinition(dynClass.getName()); |
154 |
return dynClass;
|
155 |
} |
156 |
|
157 |
@Override
|
158 |
public JDBCConnectionPanel createJDBCConnectionPanel() {
|
159 |
JDBCConnectionPanel x = new DefaultJDBCConnectionPanel();
|
160 |
return x;
|
161 |
} |
162 |
|
163 |
@Override
|
164 |
public JDBCConnectionDialog createJDBCConectionDialog() {
|
165 |
JDBCConnectionDialog x = new DefaultJDBCConnectionDialog();
|
166 |
return x;
|
167 |
} |
168 |
|
169 |
@Override
|
170 |
public void configureExpressionBuilder(ExpressionBuilderConfig builder, FeatureStore store) { |
171 |
DataManager dataManager = DALLocator.getDataManager(); |
172 |
ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
173 |
FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
174 |
|
175 |
FeatureStoreProviderFactory storeFactory = (FeatureStoreProviderFactory) store.getProviderFactory(); |
176 |
Feature sampleFeature = null;
|
177 |
try {
|
178 |
sampleFeature = store.getFeatureSelection().first(); |
179 |
if( sampleFeature == null ) { |
180 |
sampleFeature = store.first(); |
181 |
} |
182 |
} catch (DataException ex) {
|
183 |
} |
184 |
builder.setAllowedFunctions(storeFactory.allowFunction()); |
185 |
if( sampleFeature!=null ) { |
186 |
featureSymbolTable.setFeature(sampleFeature); |
187 |
builder.setPreviewSymbolTable(featureSymbolTable.createParent()); |
188 |
} |
189 |
builder.addSymbolTable(featureSymbolTable); |
190 |
FeatureStoreElement storeElement = new DefaultFeatureStoreElement2(store);
|
191 |
builder.addElement(storeElement); |
192 |
if( store.getProviderFactory().hasSQLSupport()==DataStoreProviderFactory.YES ) {
|
193 |
builder.getPreferences().setSQLCompatible(true);
|
194 |
} |
195 |
builder.addSuggestionFactory(new StorePointFieldSuggestionProviderFactory(store));
|
196 |
builder.addSuggestionFactory(new QuotesForFieldNameSuggestionProviderFactory(store));
|
197 |
builder.addSuggestionFactory(new WrongNameFieldSuggestionProviderFactory(store));
|
198 |
builder.addSuggestionFactory(new CheckTableFieldsSuggestionProviderFactory(store));
|
199 |
} |
200 |
|
201 |
@Override
|
202 |
public JExpressionBuilder createQueryFilterExpresion(FeatureStore store) {
|
203 |
return this.createJExpressionBuilder(store); |
204 |
} |
205 |
|
206 |
@Override
|
207 |
public JExpressionBuilder createJExpressionBuilder(final FeatureStore store) { |
208 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
209 |
final JExpressionBuilder builder = expressionSwingManager.createJExpressionBuilder();
|
210 |
this.configureExpressionBuilder(builder, store);
|
211 |
builder.expandElement( |
212 |
(Element t) -> t!=null && StringUtils.equals(t.getName(),store.getName()) |
213 |
); |
214 |
return builder;
|
215 |
} |
216 |
|
217 |
@Override
|
218 |
public ExpressionPickerController createExpressionPickerController(FeatureStore store, JTextComponent text, JButton button, JButton bookmarks, JButton history) { |
219 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
220 |
ExpressionPickerController builder = expressionSwingManager.createExpressionPickerController(text, button, bookmarks, history); |
221 |
this.configureExpressionBuilder(builder, store);
|
222 |
return builder;
|
223 |
} |
224 |
|
225 |
@Override
|
226 |
public JFeatureForm createJFeatureForm(FeatureStore store) throws CreateJFeatureFormException { |
227 |
JFeatureForm form = new DefaultJFeatureForm();
|
228 |
form.setStore(store); |
229 |
return form;
|
230 |
} |
231 |
|
232 |
@Override
|
233 |
public JFeatureForm createJFeatureForm(Feature feature) throws CreateJFeatureFormException { |
234 |
JFeatureForm form = new DefaultJFeatureForm();
|
235 |
form.setFeature(feature); |
236 |
return form;
|
237 |
} |
238 |
|
239 |
@Override
|
240 |
public JFeatureTable createJFeatureTable(FeatureTableModel model) {
|
241 |
return this.createJFeatureTable(model, true); |
242 |
} |
243 |
|
244 |
@Override
|
245 |
public JFeatureTable createJFeatureTable(FeatureTableModel model, boolean isDoubleBuffered) { |
246 |
return new FeatureTablePanel(model, isDoubleBuffered); |
247 |
} |
248 |
|
249 |
@Override
|
250 |
public FeatureTableModel createEmptyFeatureTableModel(DynStruct struct) {
|
251 |
return new EmptyFeatureTableModel(struct); |
252 |
} |
253 |
|
254 |
@Override
|
255 |
public FeatureTableModel createFeatureTableModel(FeatureStore featureStore,
|
256 |
FeatureQuery featureQuery) { |
257 |
try {
|
258 |
FeaturePagingHelper pager = DALLocator.getDataManager().createFeaturePagingHelper( |
259 |
featureStore, featureQuery, |
260 |
FeaturePagingHelper.DEFAULT_PAGE_SIZE |
261 |
); |
262 |
return this.createFeatureTableModel(pager); |
263 |
} catch (BaseException ex) {
|
264 |
throw new RuntimeException("Can't create a FeatureTableModel.", ex); |
265 |
} |
266 |
} |
267 |
|
268 |
@Override
|
269 |
public FeatureTableModel createFeatureTableModel(FeaturePagingHelper featurePager) {
|
270 |
return new DefaultFeatureTableModel(featurePager); |
271 |
} |
272 |
|
273 |
@Override
|
274 |
public ProjectionPickerController createProjectionPickerController(
|
275 |
JTextField txtProjection,
|
276 |
JButton btnSelectProjection
|
277 |
) { |
278 |
ProjectionPickerController picker = new ProjectionPickerController(txtProjection, btnSelectProjection);
|
279 |
return picker;
|
280 |
} |
281 |
|
282 |
@Override
|
283 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo) { |
284 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, null); |
285 |
return controller;
|
286 |
} |
287 |
|
288 |
@Override
|
289 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list) { |
290 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, null); |
291 |
return controller;
|
292 |
} |
293 |
|
294 |
@Override
|
295 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo, Predicate<FeatureAttributeDescriptor> filter) { |
296 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, filter);
|
297 |
return controller;
|
298 |
} |
299 |
|
300 |
@Override
|
301 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list, Predicate<FeatureAttributeDescriptor> filter) { |
302 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, filter);
|
303 |
return controller;
|
304 |
} |
305 |
|
306 |
@Override
|
307 |
public FeatureTypePanel createFeatureTypePanel() {
|
308 |
FeatureTypePanel panel = new DefaultFeatureTypePanel();
|
309 |
return panel;
|
310 |
} |
311 |
|
312 |
@Override
|
313 |
public FeatureTypeAttributePanel createFeatureTypeAttributePanel() {
|
314 |
FeatureTypeAttributePanel panel = new DefaultFeatureAttributePanel();
|
315 |
return panel;
|
316 |
} |
317 |
|
318 |
@Override
|
319 |
public FeatureStoreElement createFeatureStoreElement() {
|
320 |
FeatureStoreElement e = new DefaultFeatureStoreElement2(null); |
321 |
return e;
|
322 |
} |
323 |
|
324 |
@Override
|
325 |
public FeatureStoreElement createFeatureStoreElement(FeatureStore store) {
|
326 |
FeatureStoreElement e = new DefaultFeatureStoreElement2(store);
|
327 |
return e;
|
328 |
} |
329 |
|
330 |
@Override
|
331 |
public ExpressionPickerController createExpressionPickerController(FeatureStore store, JTextComponent text, JButton button) { |
332 |
FeatureSymbolTable previewSymbolTable = DALLocator.getManager().createFeatureSymbolTable(); |
333 |
previewSymbolTable.setFeature(store.getSampleFeature()); |
334 |
|
335 |
ExpressionPickerController controller = ExpressionEvaluatorSwingLocator.getManager().createExpressionPickerController(text, button); |
336 |
controller.addElement(this.createFeatureStoreElement(store));
|
337 |
controller.setPreviewSymbolTable(previewSymbolTable); |
338 |
|
339 |
return controller;
|
340 |
} |
341 |
|
342 |
|
343 |
@Override
|
344 |
public FeatureStoreSearchPanel createFeatureStoreSearchPanel(FeatureStore store) {
|
345 |
DefaultSearchPanel e = new DefaultSearchPanel(store);
|
346 |
return e;
|
347 |
} |
348 |
|
349 |
@Override
|
350 |
public final void registerStoreAction(DALActionFactory action) { |
351 |
this.featureStoreSearchActions.put(action.getName().toLowerCase(), action);
|
352 |
} |
353 |
|
354 |
@Override
|
355 |
public Collection<DALActionFactory> getStoreActions() { |
356 |
return Collections.unmodifiableCollection(this.featureStoreSearchActions.values()); |
357 |
} |
358 |
|
359 |
@Override
|
360 |
public DALActionFactory getStoreAction(String name) { |
361 |
DALActionFactory action = this.featureStoreSearchActions.get(name.toLowerCase());
|
362 |
return action;
|
363 |
} |
364 |
|
365 |
@Override
|
366 |
public void setStoreAction(AbstractButton component, String name, boolean preserveLabel, DALActionContext context) { |
367 |
DALActionFactory factory = this.getStoreAction(name);
|
368 |
Action action = factory.createAction(context);
|
369 |
if( preserveLabel ) {
|
370 |
String s = component.getText();
|
371 |
component.setAction(action); |
372 |
component.setText(s); |
373 |
} else {
|
374 |
component.setAction(action); |
375 |
} |
376 |
} |
377 |
|
378 |
|
379 |
@Override
|
380 |
public PickerController<JDBCServerExplorerParameters> createJDBCConnectionPickerController(
|
381 |
JComboBox cboConnection, JButton btnConnection |
382 |
) { |
383 |
JDBCConnectionPickerController x = new JDBCConnectionPickerController(cboConnection, btnConnection);
|
384 |
return x;
|
385 |
} |
386 |
|
387 |
@Override
|
388 |
public TableModel createSimpleFeaturesTableModel(FeatureStore store) { |
389 |
try {
|
390 |
SimpleFeaturesTableModel m = new SimpleFeaturesTableModel(store);
|
391 |
return m;
|
392 |
} catch (DataException ex) {
|
393 |
throw new RuntimeException("Can't creatre SimpleFeaturesTableModel.", ex); |
394 |
} |
395 |
} |
396 |
|
397 |
@Override
|
398 |
public TableModel createSimpleFeaturesTableModel(FeatureType featureType, List<String> columnNames, List<Feature> features) { |
399 |
SimpleFeaturesTableModel m = new SimpleFeaturesTableModel(featureType, columnNames, features);
|
400 |
return m;
|
401 |
} |
402 |
|
403 |
@Override
|
404 |
public ListCellRenderer createDefaultFeatureAttributeListCellRenderer() { |
405 |
ListCellRenderer r = new FeatureAttributeListCellRenderer(); |
406 |
return r;
|
407 |
} |
408 |
|
409 |
@Override
|
410 |
public FeatureQueryOrderPanel createFeatureStoreOrderPanel() {
|
411 |
DefaultFeatureQueryOrderPanel p = new DefaultFeatureQueryOrderPanel();
|
412 |
return p;
|
413 |
} |
414 |
|
415 |
@Override
|
416 |
public Iterable<SearchConditionPanelFactory> getSearchConditionPanels() { |
417 |
if( this.searchConditionPanelFactories==null ) { |
418 |
return Collections.EMPTY_LIST; |
419 |
} |
420 |
return this.searchConditionPanelFactories.values(); |
421 |
} |
422 |
|
423 |
@Override
|
424 |
public void registerSearchConditionPanel(SearchConditionPanelFactory factory) { |
425 |
if( this.searchConditionPanelFactories==null ) { |
426 |
this.searchConditionPanelFactories = new HashMap<>(); |
427 |
} |
428 |
this.searchConditionPanelFactories.put(factory.getName(), factory);
|
429 |
} |
430 |
|
431 |
@Override
|
432 |
public FeatureAttributesSelectionPanel createFeatureAttributeSelectionPanel() {
|
433 |
FeatureAttributesSelectionPanel p = new DefaultFeatureAttributesSelectionPanel();
|
434 |
return p;
|
435 |
} |
436 |
|
437 |
} |