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