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