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 @ 44410
History | View | Annotate | Download (13.9 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.awt.Component; |
26 |
import java.util.Collection; |
27 |
import java.util.Collections; |
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.table.TableModel; |
39 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
40 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
41 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
42 |
import org.gvsig.featureform.swing.CreateJFeatureFormException; |
43 |
import org.gvsig.featureform.swing.JFeatureForm; |
44 |
|
45 |
import org.gvsig.featureform.swing.JFeaturesForm; |
46 |
import org.gvsig.featureform.swing.impl.DefaultJFeatureForm; |
47 |
import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm; |
48 |
import org.gvsig.fmap.dal.DALLocator; |
49 |
import org.gvsig.fmap.dal.DataManager; |
50 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
51 |
import org.gvsig.fmap.dal.exception.DataException; |
52 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
53 |
import org.gvsig.fmap.dal.feature.Feature; |
54 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
55 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
56 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
57 |
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 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
61 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
62 |
import org.gvsig.fmap.dal.swing.FeatureTableModel; |
63 |
import org.gvsig.fmap.dal.swing.JFeatureTable; |
64 |
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
65 |
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController; |
66 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
67 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel; |
68 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.DefaultFeatureStoreElement2; |
69 |
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 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultAttributeDescriptorPickerController; |
73 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypeAttributePanel; |
74 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypePanel; |
75 |
import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionPanel; |
76 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
77 |
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 |
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel; |
82 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
83 |
import org.gvsig.tools.dynform.DynFormLocator; |
84 |
import org.gvsig.tools.dynobject.DynClass; |
85 |
import org.gvsig.tools.dynobject.DynStruct; |
86 |
import org.gvsig.tools.exception.BaseException; |
87 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
88 |
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext; |
89 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel; |
90 |
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 |
|
95 |
|
96 |
/**
|
97 |
* @author fdiaz
|
98 |
*
|
99 |
*/
|
100 |
@SuppressWarnings("UseSpecificCatch") |
101 |
public class DefaultDataSwingManager implements DataSwingManager { |
102 |
|
103 |
private final Map<String,DALActionFactory> featureStoreSearchActions; |
104 |
|
105 |
public DefaultDataSwingManager() {
|
106 |
this.featureStoreSearchActions = new LinkedHashMap<>(); |
107 |
this.registerStoreAction(new SelectionAddActionFactory()); |
108 |
this.registerStoreAction(new SelectionFilterActionFactory()); |
109 |
this.registerStoreAction(new SelectionSetActionFactory()); |
110 |
this.registerStoreAction(new ShowFormActionFactory()); |
111 |
} |
112 |
|
113 |
@Override
|
114 |
public JFeaturesForm createJFeaturesForm(FeatureStore store) throws CreateJFeatureFormException { |
115 |
try {
|
116 |
FeatureType featureType = store.getDefaultFeatureType(); |
117 |
|
118 |
DefaultJFeaturesForm form = new DefaultJFeaturesForm();
|
119 |
form.bind(store, featureType2DynClass(store, featureType)); |
120 |
return form;
|
121 |
|
122 |
} catch (Exception ex) { |
123 |
throw new CreateJFeatureFormException(ex); |
124 |
} |
125 |
} |
126 |
|
127 |
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 |
@Override
|
140 |
public JDBCConnectionPanel createJDBCConnectionPanel() {
|
141 |
JDBCConnectionPanel x = new DefaultJDBCConnectionPanel();
|
142 |
return x;
|
143 |
} |
144 |
|
145 |
@Override
|
146 |
public JDBCConnectionDialog createJDBCConectionDialog() {
|
147 |
JDBCConnectionDialog x = new DefaultJDBCConnectionDialog();
|
148 |
return x;
|
149 |
} |
150 |
|
151 |
@Override
|
152 |
public JExpressionBuilder createQueryFilterExpresion(FeatureStore store) {
|
153 |
DataManager dataManager = DALLocator.getDataManager(); |
154 |
ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
155 |
FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
156 |
|
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 |
builder.addSymbolTable(featureSymbolTable); |
171 |
FeatureStoreElement storeElement = new DefaultFeatureStoreElement2(store);
|
172 |
builder.addElement(storeElement); |
173 |
if( store.getProviderFactory().hasSQLSupport()==DataStoreProviderFactory.YES ) {
|
174 |
builder.getPreferences().setSQLCompatible(true);
|
175 |
} |
176 |
builder.expandElement(storeElement); |
177 |
return builder;
|
178 |
} |
179 |
|
180 |
@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 |
@Override
|
195 |
public JFeatureTable createJFeatureTable(FeatureTableModel model) {
|
196 |
return this.createJFeatureTable(model, true); |
197 |
} |
198 |
|
199 |
@Override
|
200 |
public JFeatureTable createJFeatureTable(FeatureTableModel model, boolean isDoubleBuffered) { |
201 |
return new FeatureTablePanel(model, isDoubleBuffered); |
202 |
} |
203 |
|
204 |
@Override
|
205 |
public FeatureTableModel createEmptyFeatureTableModel(DynStruct struct) {
|
206 |
return new EmptyFeatureTableModel(struct); |
207 |
} |
208 |
|
209 |
@Override
|
210 |
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 |
@Override
|
224 |
public FeatureTableModel createFeatureTableModel(FeaturePagingHelper featurePager) {
|
225 |
return new DefaultFeatureTableModel(featurePager); |
226 |
} |
227 |
|
228 |
@Override
|
229 |
public ProjectionPickerController createProjectionPickerController(
|
230 |
JTextField txtProjection,
|
231 |
JButton btnSelectProjection
|
232 |
) { |
233 |
ProjectionPickerController picker = new ProjectionPickerController(txtProjection, btnSelectProjection);
|
234 |
return picker;
|
235 |
} |
236 |
|
237 |
@Override
|
238 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo) { |
239 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, null); |
240 |
return controller;
|
241 |
} |
242 |
|
243 |
@Override
|
244 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list) { |
245 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, null); |
246 |
return controller;
|
247 |
} |
248 |
|
249 |
@Override
|
250 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo, Predicate<FeatureAttributeDescriptor> filter) { |
251 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, filter);
|
252 |
return controller;
|
253 |
} |
254 |
|
255 |
@Override
|
256 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list, Predicate<FeatureAttributeDescriptor> filter) { |
257 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, filter);
|
258 |
return controller;
|
259 |
} |
260 |
|
261 |
@Override
|
262 |
public FeatureTypePanel createFeatureTypePanel() {
|
263 |
FeatureTypePanel panel = new DefaultFeatureTypePanel();
|
264 |
return panel;
|
265 |
} |
266 |
|
267 |
@Override
|
268 |
public FeatureTypeAttributePanel createFeatureTypeAttributePanel() {
|
269 |
FeatureTypeAttributePanel panel = new DefaultFeatureTypeAttributePanel();
|
270 |
return panel;
|
271 |
} |
272 |
|
273 |
@Override
|
274 |
public FeatureStoreElement createFeatureStoreElement() {
|
275 |
FeatureStoreElement e = new DefaultFeatureStoreElement2(null); |
276 |
return e;
|
277 |
} |
278 |
|
279 |
@Override
|
280 |
public FeatureStoreElement createFeatureStoreElement(FeatureStore store) {
|
281 |
FeatureStoreElement e = new DefaultFeatureStoreElement2(store);
|
282 |
return e;
|
283 |
} |
284 |
|
285 |
@Override
|
286 |
public FeatureStoreSearchPanel createFeatureStoreSearchPanel(FeatureStore store) {
|
287 |
DefaultSearchPanel e = new DefaultSearchPanel(store);
|
288 |
return e;
|
289 |
} |
290 |
|
291 |
@Override
|
292 |
public final void registerStoreAction(DALActionFactory action) { |
293 |
this.featureStoreSearchActions.put(action.getName().toLowerCase(), action);
|
294 |
} |
295 |
|
296 |
@Override
|
297 |
public Collection<DALActionFactory> getStoreActions() { |
298 |
return Collections.unmodifiableCollection(this.featureStoreSearchActions.values()); |
299 |
} |
300 |
|
301 |
@Override
|
302 |
public DALActionFactory getStoreAction(String name) { |
303 |
DALActionFactory action = this.featureStoreSearchActions.get(name.toLowerCase());
|
304 |
return action;
|
305 |
} |
306 |
|
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 |
|
320 |
|
321 |
@Override
|
322 |
public PickerController<JDBCServerExplorerParameters> createJDBCConnectionPickerController(
|
323 |
JComboBox cboConnection, JButton btnConnection |
324 |
) { |
325 |
JDBCConnectionPickerController x = new JDBCConnectionPickerController(cboConnection, btnConnection);
|
326 |
return x;
|
327 |
} |
328 |
|
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 |
|
339 |
@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 |
|
345 |
} |