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 @ 44340
History | View | Annotate | Download (13.3 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.LinkedHashMap; |
28 |
import java.util.List; |
29 |
import java.util.Map; |
30 |
import java.util.function.Predicate; |
31 |
import javax.swing.JButton; |
32 |
import javax.swing.JComboBox; |
33 |
import javax.swing.JList; |
34 |
import javax.swing.JTextField; |
35 |
import javax.swing.table.TableModel; |
36 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
37 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
38 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
39 |
import org.gvsig.featureform.swing.CreateJFeatureFormException; |
40 |
import org.gvsig.featureform.swing.JFeatureForm; |
41 |
|
42 |
import org.gvsig.featureform.swing.JFeaturesForm; |
43 |
import org.gvsig.featureform.swing.impl.DefaultJFeatureForm; |
44 |
import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm; |
45 |
import org.gvsig.fmap.dal.DALLocator; |
46 |
import org.gvsig.fmap.dal.DataManager; |
47 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
48 |
import org.gvsig.fmap.dal.exception.DataException; |
49 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
50 |
import org.gvsig.fmap.dal.feature.Feature; |
51 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
52 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
53 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
54 |
import org.gvsig.fmap.dal.feature.FeatureType; |
55 |
import org.gvsig.fmap.dal.feature.FeatureTypeDefinitionsManager; |
56 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
57 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
58 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
59 |
import org.gvsig.fmap.dal.swing.FeatureTableModel; |
60 |
import org.gvsig.fmap.dal.swing.JFeatureTable; |
61 |
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
62 |
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController; |
63 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
64 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel; |
65 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.DefaultFeatureStoreElement2; |
66 |
import org.gvsig.fmap.dal.swing.impl.featuretable.FeatureTablePanel; |
67 |
import org.gvsig.fmap.dal.swing.impl.featuretable.table.DefaultFeatureTableModel; |
68 |
import org.gvsig.fmap.dal.swing.impl.featuretable.table.EmptyFeatureTableModel; |
69 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultAttributeDescriptorPickerController; |
70 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypeAttributePanel; |
71 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypePanel; |
72 |
import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionPanel; |
73 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
74 |
import org.gvsig.fmap.dal.swing.impl.actions.SelectionAddAction.SelectionAddActionFactory; |
75 |
import org.gvsig.fmap.dal.swing.impl.actions.SelectionFilterAction.SelectionFilterActionFactory; |
76 |
import org.gvsig.fmap.dal.swing.impl.actions.SelectionSetAction.SelectionSetActionFactory; |
77 |
import org.gvsig.fmap.dal.swing.impl.actions.ShowFormAction.ShowFormActionFactory; |
78 |
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel; |
79 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
80 |
import org.gvsig.tools.dynform.DynFormLocator; |
81 |
import org.gvsig.tools.dynobject.DynClass; |
82 |
import org.gvsig.tools.dynobject.DynStruct; |
83 |
import org.gvsig.tools.exception.BaseException; |
84 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
85 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel; |
86 |
import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionDialog; |
87 |
import org.gvsig.fmap.dal.swing.impl.jdbc.JDBCConnectionPickerController; |
88 |
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog; |
89 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
90 |
|
91 |
|
92 |
/**
|
93 |
* @author fdiaz
|
94 |
*
|
95 |
*/
|
96 |
@SuppressWarnings("UseSpecificCatch") |
97 |
public class DefaultDataSwingManager implements DataSwingManager { |
98 |
|
99 |
private final Map<String,DALActionFactory> featureStoreSearchActions; |
100 |
|
101 |
public DefaultDataSwingManager() {
|
102 |
this.featureStoreSearchActions = new LinkedHashMap<>(); |
103 |
this.registerStoreAction(new SelectionAddActionFactory()); |
104 |
this.registerStoreAction(new SelectionFilterActionFactory()); |
105 |
this.registerStoreAction(new SelectionSetActionFactory()); |
106 |
this.registerStoreAction(new ShowFormActionFactory()); |
107 |
} |
108 |
|
109 |
@Override
|
110 |
public JFeaturesForm createJFeaturesForm(FeatureStore store) throws CreateJFeatureFormException { |
111 |
try {
|
112 |
FeatureType featureType = store.getDefaultFeatureType(); |
113 |
|
114 |
DefaultJFeaturesForm form = new DefaultJFeaturesForm();
|
115 |
form.bind(store, featureType2DynClass(store, featureType)); |
116 |
return form;
|
117 |
|
118 |
} catch (Exception ex) { |
119 |
throw new CreateJFeatureFormException(ex); |
120 |
} |
121 |
} |
122 |
|
123 |
public DynClass featureType2DynClass(FeatureStore store, FeatureType type) {
|
124 |
FeatureTypeDefinitionsManager featureTypeDefinitionsManager = DALLocator.getFeatureTypeDefinitionsManager(); |
125 |
if( featureTypeDefinitionsManager.contains(store,type) ) {
|
126 |
// Force reload next call to get.
|
127 |
featureTypeDefinitionsManager.remove(store,type); |
128 |
} |
129 |
DynClass dynClass = featureTypeDefinitionsManager.get(store,type); |
130 |
// Force reload next call to get.
|
131 |
DynFormLocator.getDynFormManager().removeDefinition(dynClass.getName()); |
132 |
return dynClass;
|
133 |
} |
134 |
|
135 |
@Override
|
136 |
public JDBCConnectionPanel createJDBCConnectionPanel() {
|
137 |
JDBCConnectionPanel x = new DefaultJDBCConnectionPanel();
|
138 |
return x;
|
139 |
} |
140 |
|
141 |
@Override
|
142 |
public JDBCConnectionDialog createJDBCConectionDialog() {
|
143 |
JDBCConnectionDialog x = new DefaultJDBCConnectionDialog();
|
144 |
return x;
|
145 |
} |
146 |
|
147 |
@Override
|
148 |
public JExpressionBuilder createQueryFilterExpresion(FeatureStore store) {
|
149 |
DataManager dataManager = DALLocator.getDataManager(); |
150 |
ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
151 |
FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
152 |
|
153 |
Feature sampleFeature = null;
|
154 |
try {
|
155 |
sampleFeature = store.getFeatureSelection().first(); |
156 |
if( sampleFeature == null ) { |
157 |
sampleFeature = store.first(); |
158 |
} |
159 |
} catch (DataException ex) {
|
160 |
} |
161 |
final JExpressionBuilder builder = swingManager.createJExpressionBuilder();
|
162 |
if( sampleFeature!=null ) { |
163 |
featureSymbolTable.setFeature(sampleFeature); |
164 |
builder.setPreviewSymbolTable(featureSymbolTable.createParent()); |
165 |
} |
166 |
builder.addSymbolTable(featureSymbolTable); |
167 |
FeatureStoreElement storeElement = new DefaultFeatureStoreElement2(store);
|
168 |
builder.addElement(storeElement); |
169 |
if( store.getProviderFactory().hasSQLSupport()==DataStoreProviderFactory.YES ) {
|
170 |
builder.getPreferences().setSQLCompatible(true);
|
171 |
} |
172 |
builder.expandElement(storeElement); |
173 |
return builder;
|
174 |
} |
175 |
|
176 |
@Override
|
177 |
public JFeatureForm createJFeatureForm(FeatureStore store) throws CreateJFeatureFormException { |
178 |
JFeatureForm form = new DefaultJFeatureForm();
|
179 |
form.setStore(store); |
180 |
return form;
|
181 |
} |
182 |
|
183 |
@Override
|
184 |
public JFeatureForm createJFeatureForm(Feature feature) throws CreateJFeatureFormException { |
185 |
JFeatureForm form = new DefaultJFeatureForm();
|
186 |
form.setFeature(feature); |
187 |
return form;
|
188 |
} |
189 |
|
190 |
@Override
|
191 |
public JFeatureTable createJFeatureTable(FeatureTableModel model) {
|
192 |
return this.createJFeatureTable(model, true); |
193 |
} |
194 |
|
195 |
@Override
|
196 |
public JFeatureTable createJFeatureTable(FeatureTableModel model, boolean isDoubleBuffered) { |
197 |
return new FeatureTablePanel(model, isDoubleBuffered); |
198 |
} |
199 |
|
200 |
@Override
|
201 |
public FeatureTableModel createEmptyFeatureTableModel(DynStruct struct) {
|
202 |
return new EmptyFeatureTableModel(struct); |
203 |
} |
204 |
|
205 |
@Override
|
206 |
public FeatureTableModel createFeatureTableModel(FeatureStore featureStore,
|
207 |
FeatureQuery featureQuery) { |
208 |
try {
|
209 |
FeaturePagingHelper pager = DALLocator.getDataManager().createFeaturePagingHelper( |
210 |
featureStore, featureQuery, |
211 |
FeaturePagingHelper.DEFAULT_PAGE_SIZE |
212 |
); |
213 |
return this.createFeatureTableModel(pager); |
214 |
} catch (BaseException ex) {
|
215 |
throw new RuntimeException("Can't create a FeatureTableModel.", ex); |
216 |
} |
217 |
} |
218 |
|
219 |
@Override
|
220 |
public FeatureTableModel createFeatureTableModel(FeaturePagingHelper featurePager) {
|
221 |
return new DefaultFeatureTableModel(featurePager); |
222 |
} |
223 |
|
224 |
@Override
|
225 |
public ProjectionPickerController createProjectionPickerController(
|
226 |
JTextField txtProjection,
|
227 |
JButton btnSelectProjection
|
228 |
) { |
229 |
ProjectionPickerController picker = new ProjectionPickerController(txtProjection, btnSelectProjection);
|
230 |
return picker;
|
231 |
} |
232 |
|
233 |
@Override
|
234 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo) { |
235 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, null); |
236 |
return controller;
|
237 |
} |
238 |
|
239 |
@Override
|
240 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list) { |
241 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, null); |
242 |
return controller;
|
243 |
} |
244 |
|
245 |
@Override
|
246 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo, Predicate<FeatureAttributeDescriptor> filter) { |
247 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, filter);
|
248 |
return controller;
|
249 |
} |
250 |
|
251 |
@Override
|
252 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list, Predicate<FeatureAttributeDescriptor> filter) { |
253 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, filter);
|
254 |
return controller;
|
255 |
} |
256 |
|
257 |
@Override
|
258 |
public FeatureTypePanel createFeatureTypePanel() {
|
259 |
FeatureTypePanel panel = new DefaultFeatureTypePanel();
|
260 |
return panel;
|
261 |
} |
262 |
|
263 |
@Override
|
264 |
public FeatureTypeAttributePanel createFeatureTypeAttributePanel() {
|
265 |
FeatureTypeAttributePanel panel = new DefaultFeatureTypeAttributePanel();
|
266 |
return panel;
|
267 |
} |
268 |
|
269 |
@Override
|
270 |
public FeatureStoreElement createFeatureStoreElement() {
|
271 |
FeatureStoreElement e = new DefaultFeatureStoreElement2(null); |
272 |
return e;
|
273 |
} |
274 |
|
275 |
@Override
|
276 |
public FeatureStoreElement createFeatureStoreElement(FeatureStore store) {
|
277 |
FeatureStoreElement e = new DefaultFeatureStoreElement2(store);
|
278 |
return e;
|
279 |
} |
280 |
|
281 |
@Override
|
282 |
public FeatureStoreSearchPanel createFeatureStoreSearchPanel(FeatureStore store) {
|
283 |
DefaultSearchPanel e = new DefaultSearchPanel(store);
|
284 |
return e;
|
285 |
} |
286 |
|
287 |
@Override
|
288 |
public final void registerStoreAction(DALActionFactory action) { |
289 |
this.featureStoreSearchActions.put(action.getName().toLowerCase(), action);
|
290 |
} |
291 |
|
292 |
@Override
|
293 |
public Collection<DALActionFactory> getStoreActions() { |
294 |
return Collections.unmodifiableCollection(this.featureStoreSearchActions.values()); |
295 |
} |
296 |
|
297 |
@Override
|
298 |
public DALActionFactory getStoreAction(String name) { |
299 |
DALActionFactory action = this.featureStoreSearchActions.get(name.toLowerCase());
|
300 |
return action;
|
301 |
} |
302 |
|
303 |
@Override
|
304 |
public PickerController<JDBCServerExplorerParameters> createJDBCConnectionPickerController(
|
305 |
JComboBox cboConnection, JButton btnConnection |
306 |
) { |
307 |
JDBCConnectionPickerController x = new JDBCConnectionPickerController(cboConnection, btnConnection);
|
308 |
return x;
|
309 |
} |
310 |
|
311 |
@Override
|
312 |
public TableModel createSimpleFeaturesTableModel(FeatureStore store) { |
313 |
try {
|
314 |
SimpleFeaturesTableModel m = new SimpleFeaturesTableModel(store);
|
315 |
return m;
|
316 |
} catch (DataException ex) {
|
317 |
throw new RuntimeException("Can't creatre SimpleFeaturesTableModel.", ex); |
318 |
} |
319 |
} |
320 |
|
321 |
@Override
|
322 |
public TableModel createSimpleFeaturesTableModel(FeatureType featureType, List<String> columnNames, List<Feature> features) { |
323 |
SimpleFeaturesTableModel m = new SimpleFeaturesTableModel(featureType, columnNames, features);
|
324 |
return m;
|
325 |
} |
326 |
|
327 |
} |