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 @ 44259
History | View | Annotate | Download (10.2 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 | 44128 | jjdelcerro | import java.util.function.Predicate; |
26 | 44077 | jjdelcerro | import javax.swing.JButton; |
27 | 44096 | jjdelcerro | import javax.swing.JComboBox; |
28 | 44215 | jjdelcerro | import javax.swing.JList; |
29 | 44077 | jjdelcerro | import javax.swing.JTextField; |
30 | 44128 | jjdelcerro | import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
31 | import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
||
32 | import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
||
33 | import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
||
34 | 42112 | jjdelcerro | import org.gvsig.featureform.swing.CreateJFeatureFormException; |
35 | 42775 | jjdelcerro | import org.gvsig.featureform.swing.JFeatureForm; |
36 | 42112 | jjdelcerro | |
37 | 42775 | jjdelcerro | import org.gvsig.featureform.swing.JFeaturesForm; |
38 | 42112 | jjdelcerro | import org.gvsig.featureform.swing.impl.DefaultJFeatureForm; |
39 | 42775 | jjdelcerro | import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm; |
40 | import org.gvsig.fmap.dal.DALLocator; |
||
41 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.DataManager; |
42 | 44191 | jjdelcerro | import org.gvsig.fmap.dal.DataStoreProviderFactory; |
43 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.exception.DataException; |
44 | import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
||
45 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.feature.Feature; |
46 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
47 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureQuery; |
48 | 42112 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
49 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
50 | import org.gvsig.fmap.dal.feature.FeatureTypeDefinitionsManager; |
||
51 | import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
||
52 | 42112 | jjdelcerro | import org.gvsig.fmap.dal.swing.DataSwingManager; |
53 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.swing.FeatureTableModel; |
54 | import org.gvsig.fmap.dal.swing.JFeatureTable; |
||
55 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
56 | 44096 | jjdelcerro | import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController; |
57 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
58 | import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel; |
||
59 | import org.gvsig.fmap.dal.swing.impl.expressionevaluator.DefaultFeatureStoreElement; |
||
60 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretable.FeatureTablePanel; |
61 | import org.gvsig.fmap.dal.swing.impl.featuretable.table.DefaultFeatureTableModel; |
||
62 | import org.gvsig.fmap.dal.swing.impl.featuretable.table.EmptyFeatureTableModel; |
||
63 | 44096 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultAttributeDescriptorPickerController; |
64 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypeAttributePanel; |
65 | import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypePanel; |
||
66 | 42112 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionPanel; |
67 | 44259 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
68 | 42112 | jjdelcerro | import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel; |
69 | 44259 | jjdelcerro | import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
70 | 42620 | jjdelcerro | import org.gvsig.tools.dynform.DynFormLocator; |
71 | import org.gvsig.tools.dynobject.DynClass; |
||
72 | 42775 | jjdelcerro | import org.gvsig.tools.dynobject.DynStruct; |
73 | import org.gvsig.tools.exception.BaseException; |
||
74 | 42112 | jjdelcerro | |
75 | |||
76 | /**
|
||
77 | * @author fdiaz
|
||
78 | *
|
||
79 | */
|
||
80 | 44128 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
81 | 42775 | jjdelcerro | public class DefaultDataSwingManager implements DataSwingManager { |
82 | 42112 | jjdelcerro | |
83 | 42512 | jjdelcerro | @Override
|
84 | 42775 | jjdelcerro | public JFeaturesForm createJFeaturesForm(FeatureStore store) throws CreateJFeatureFormException { |
85 | 42112 | jjdelcerro | try {
|
86 | 42775 | jjdelcerro | FeatureType featureType = store.getDefaultFeatureType(); |
87 | |||
88 | DefaultJFeaturesForm form = new DefaultJFeaturesForm();
|
||
89 | 44202 | jjdelcerro | form.bind(store, featureType2DynClass(store, featureType)); |
90 | 42775 | jjdelcerro | return form;
|
91 | |||
92 | } catch (Exception ex) { |
||
93 | throw new CreateJFeatureFormException(ex); |
||
94 | 42112 | jjdelcerro | } |
95 | } |
||
96 | |||
97 | 44202 | jjdelcerro | public DynClass featureType2DynClass(FeatureStore store, FeatureType type) {
|
98 | FeatureTypeDefinitionsManager featureTypeDefinitionsManager = DALLocator.getFeatureTypeDefinitionsManager(); |
||
99 | if( featureTypeDefinitionsManager.contains(store,type) ) {
|
||
100 | // Force reload next call to get.
|
||
101 | featureTypeDefinitionsManager.remove(store,type); |
||
102 | } |
||
103 | DynClass dynClass = featureTypeDefinitionsManager.get(store,type); |
||
104 | // Force reload next call to get.
|
||
105 | DynFormLocator.getDynFormManager().removeDefinition(dynClass.getName()); |
||
106 | return dynClass;
|
||
107 | } |
||
108 | |||
109 | 42512 | jjdelcerro | @Override
|
110 | 42112 | jjdelcerro | public JDBCConnectionPanel createJDBCConnectionPanel() {
|
111 | JDBCConnectionPanel x = new DefaultJDBCConnectionPanel();
|
||
112 | return x;
|
||
113 | } |
||
114 | |||
115 | 42512 | jjdelcerro | @Override
|
116 | 44128 | jjdelcerro | public JExpressionBuilder createQueryFilterExpresion(FeatureStore store) {
|
117 | DataManager dataManager = DALLocator.getDataManager(); |
||
118 | ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
||
119 | 44202 | jjdelcerro | FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
120 | 44128 | jjdelcerro | |
121 | Feature sampleFeature = null;
|
||
122 | try {
|
||
123 | sampleFeature = store.getFeatureSelection().first(); |
||
124 | if( sampleFeature == null ) { |
||
125 | sampleFeature = store.first(); |
||
126 | } |
||
127 | } catch (DataException ex) {
|
||
128 | } |
||
129 | final JExpressionBuilder builder = swingManager.createJExpressionBuilder();
|
||
130 | if( sampleFeature!=null ) { |
||
131 | featureSymbolTable.setFeature(sampleFeature); |
||
132 | builder.setPreviewSymbolTable(featureSymbolTable.createParent()); |
||
133 | } |
||
134 | 44202 | jjdelcerro | builder.addSymbolTable(featureSymbolTable); |
135 | 44259 | jjdelcerro | DefaultFeatureStoreElement storeElement = new DefaultFeatureStoreElement(store);
|
136 | 44209 | jjdelcerro | builder.addElement(storeElement); |
137 | 44191 | jjdelcerro | if( store.getProviderFactory().hasSQLSupport()==DataStoreProviderFactory.YES ) {
|
138 | 44259 | jjdelcerro | builder.getPreferences().setSQLCompatible(true);
|
139 | 44191 | jjdelcerro | } |
140 | 44209 | jjdelcerro | builder.expandElement(storeElement); |
141 | 44128 | jjdelcerro | return builder;
|
142 | 42489 | jjdelcerro | } |
143 | 42112 | jjdelcerro | |
144 | 42775 | jjdelcerro | @Override
|
145 | public JFeatureForm createJFeatureForm(FeatureStore store) throws CreateJFeatureFormException { |
||
146 | JFeatureForm form = new DefaultJFeatureForm();
|
||
147 | form.setStore(store); |
||
148 | return form;
|
||
149 | } |
||
150 | |||
151 | @Override
|
||
152 | public JFeatureForm createJFeatureForm(Feature feature) throws CreateJFeatureFormException { |
||
153 | JFeatureForm form = new DefaultJFeatureForm();
|
||
154 | form.setFeature(feature); |
||
155 | return form;
|
||
156 | } |
||
157 | |||
158 | 44202 | jjdelcerro | @Override
|
159 | 42775 | jjdelcerro | public JFeatureTable createJFeatureTable(FeatureTableModel model) {
|
160 | return this.createJFeatureTable(model, true); |
||
161 | } |
||
162 | |||
163 | 44202 | jjdelcerro | @Override
|
164 | 42775 | jjdelcerro | public JFeatureTable createJFeatureTable(FeatureTableModel model, boolean isDoubleBuffered) { |
165 | return new FeatureTablePanel(model, isDoubleBuffered); |
||
166 | } |
||
167 | |||
168 | 44202 | jjdelcerro | @Override
|
169 | 42775 | jjdelcerro | public FeatureTableModel createEmptyFeatureTableModel(DynStruct struct) {
|
170 | return new EmptyFeatureTableModel(struct); |
||
171 | } |
||
172 | |||
173 | 44202 | jjdelcerro | @Override
|
174 | 42775 | jjdelcerro | public FeatureTableModel createFeatureTableModel(FeatureStore featureStore,
|
175 | FeatureQuery featureQuery) { |
||
176 | try {
|
||
177 | FeaturePagingHelper pager = DALLocator.getDataManager().createFeaturePagingHelper( |
||
178 | featureStore, featureQuery, |
||
179 | FeaturePagingHelper.DEFAULT_PAGE_SIZE |
||
180 | ); |
||
181 | return this.createFeatureTableModel(pager); |
||
182 | } catch (BaseException ex) {
|
||
183 | throw new RuntimeException("Can't create a FeatureTableModel.", ex); |
||
184 | } |
||
185 | } |
||
186 | |||
187 | 44202 | jjdelcerro | @Override
|
188 | 42775 | jjdelcerro | public FeatureTableModel createFeatureTableModel(FeaturePagingHelper featurePager) {
|
189 | return new DefaultFeatureTableModel(featurePager); |
||
190 | } |
||
191 | 44077 | jjdelcerro | |
192 | 44202 | jjdelcerro | @Override
|
193 | 44077 | jjdelcerro | public ProjectionPickerController createProjectionPickerController(
|
194 | JTextField txtProjection,
|
||
195 | JButton btnSelectProjection
|
||
196 | ) { |
||
197 | ProjectionPickerController picker = new ProjectionPickerController(txtProjection, btnSelectProjection);
|
||
198 | return picker;
|
||
199 | } |
||
200 | 44096 | jjdelcerro | |
201 | 44202 | jjdelcerro | @Override
|
202 | 44096 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo) { |
203 | 44128 | jjdelcerro | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, null); |
204 | 44096 | jjdelcerro | return controller;
|
205 | } |
||
206 | 44128 | jjdelcerro | |
207 | 44202 | jjdelcerro | @Override
|
208 | 44215 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list) { |
209 | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, null); |
||
210 | return controller;
|
||
211 | } |
||
212 | |||
213 | @Override
|
||
214 | 44128 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo, Predicate<FeatureAttributeDescriptor> filter) { |
215 | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, filter);
|
||
216 | return controller;
|
||
217 | } |
||
218 | |||
219 | 44202 | jjdelcerro | @Override
|
220 | 44215 | jjdelcerro | public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list, Predicate<FeatureAttributeDescriptor> filter) { |
221 | AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, filter);
|
||
222 | return controller;
|
||
223 | } |
||
224 | |||
225 | @Override
|
||
226 | 44128 | jjdelcerro | public FeatureTypePanel createFeatureTypePanel() {
|
227 | FeatureTypePanel panel = new DefaultFeatureTypePanel();
|
||
228 | return panel;
|
||
229 | } |
||
230 | |||
231 | 44202 | jjdelcerro | @Override
|
232 | 44128 | jjdelcerro | public FeatureTypeAttributePanel createFeatureTypeAttributePanel() {
|
233 | FeatureTypeAttributePanel panel = new DefaultFeatureTypeAttributePanel();
|
||
234 | return panel;
|
||
235 | } |
||
236 | |||
237 | 44202 | jjdelcerro | @Override
|
238 | 44259 | jjdelcerro | public FeatureStoreElement createFeatureStoreElement() {
|
239 | FeatureStoreElement e = new DefaultFeatureStoreElement(null); |
||
240 | 44128 | jjdelcerro | return e;
|
241 | } |
||
242 | 44259 | jjdelcerro | |
243 | @Override
|
||
244 | public FeatureStoreSearchPanel createFeatureStoreSearchPanel(FeatureStore store) {
|
||
245 | DefaultSearchPanel e = new DefaultSearchPanel(store);
|
||
246 | return e;
|
||
247 | } |
||
248 | |||
249 | |||
250 | 42112 | jjdelcerro | } |