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