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 @ 46901
History | View | Annotate | Download (37.2 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.awt.event.ActionEvent; |
27 |
import java.net.URL; |
28 |
import java.util.ArrayList; |
29 |
import java.util.Collection; |
30 |
import java.util.Collections; |
31 |
import java.util.HashMap; |
32 |
import java.util.LinkedHashMap; |
33 |
import java.util.List; |
34 |
import java.util.Map; |
35 |
import java.util.function.Predicate; |
36 |
import javax.swing.AbstractButton; |
37 |
import javax.swing.Action; |
38 |
import javax.swing.Icon; |
39 |
import javax.swing.ImageIcon; |
40 |
import javax.swing.JButton; |
41 |
import javax.swing.JComboBox; |
42 |
import javax.swing.JList; |
43 |
import javax.swing.JOptionPane; |
44 |
import javax.swing.JTextField; |
45 |
import javax.swing.JTree; |
46 |
import javax.swing.text.JTextComponent; |
47 |
import javax.swing.tree.TreeModel; |
48 |
import org.apache.commons.lang3.StringUtils; |
49 |
import org.gvsig.expressionevaluator.Expression; |
50 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
51 |
import org.gvsig.expressionevaluator.swing.Element; |
52 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
53 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
54 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
55 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
56 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
57 |
import org.gvsig.featureform.swing.CreateJFeatureFormException; |
58 |
import org.gvsig.featureform.swing.FeaturesFormContext; |
59 |
import org.gvsig.featureform.swing.JFeatureForm; |
60 |
import org.gvsig.featureform.swing.JFeatureReferencesForm; |
61 |
import org.gvsig.featureform.swing.JFeaturesForm; |
62 |
import org.gvsig.featureform.swing.impl.DefaultFeaturesFormContext; |
63 |
import org.gvsig.featureform.swing.impl.DefaultJFeatureForm; |
64 |
import org.gvsig.featureform.swing.impl.DefaultJFeatureReferencesForm; |
65 |
import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm; |
66 |
import org.gvsig.fmap.dal.DALLocator; |
67 |
import org.gvsig.fmap.dal.DataManager; |
68 |
import static org.gvsig.fmap.dal.DataManager.DAL_USE_LABELS; |
69 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_BOTH; |
70 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_NO; |
71 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_YES; |
72 |
import org.gvsig.fmap.dal.DataStore; |
73 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
74 |
import org.gvsig.fmap.dal.StoresRepository; |
75 |
import org.gvsig.fmap.dal.exception.DataException; |
76 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
77 |
import org.gvsig.fmap.dal.feature.Feature; |
78 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
79 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
80 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
81 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
82 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
83 |
import org.gvsig.fmap.dal.feature.FeatureType; |
84 |
import org.gvsig.fmap.dal.feature.FeatureTypeDefinitionsManager; |
85 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
86 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
87 |
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory; |
88 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
89 |
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext; |
90 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
91 |
import org.gvsig.fmap.dal.swing.FeatureTableModel; |
92 |
import org.gvsig.fmap.dal.swing.JFeatureTable; |
93 |
import org.gvsig.fmap.dal.swing.ProjectionPickerController; |
94 |
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement; |
95 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryOrderPanel; |
96 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryPickerController; |
97 |
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel; |
98 |
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorAndExpressionPickerController; |
99 |
import org.gvsig.fmap.dal.swing.featuretype.AttributeDescriptorPickerController; |
100 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeListCellRenderer; |
101 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeTableCellRenderer; |
102 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel; |
103 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypeAttributePanel; |
104 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel; |
105 |
import org.gvsig.fmap.dal.swing.impl.actions.CopyFormAction; |
106 |
import org.gvsig.fmap.dal.swing.impl.actions.CopyFormAction.CopyFormActionFactory; |
107 |
import org.gvsig.fmap.dal.swing.impl.actions.GraphAction.GraphActionFactory; |
108 |
import org.gvsig.fmap.dal.swing.impl.actions.SelectionAddAction.SelectionAddActionFactory; |
109 |
import org.gvsig.fmap.dal.swing.impl.actions.SelectionFilterAction.SelectionFilterActionFactory; |
110 |
import org.gvsig.fmap.dal.swing.impl.actions.SelectionSetAction.SelectionSetActionFactory; |
111 |
import org.gvsig.fmap.dal.swing.impl.actions.ShowFormAction.ShowFormActionFactory; |
112 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.DefaultFeatureStoreElement2; |
113 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.CheckTableFieldsSuggestionProviderFactory; |
114 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.DivSuggestionProviderFactory; |
115 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.QuotesForFieldNameSuggestionProviderFactory; |
116 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.StorePointFieldSuggestionProviderFactory; |
117 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.suggestions.WrongNameFieldSuggestionProviderFactory; |
118 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryOrderPanel; |
119 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryPickerController; |
120 |
import org.gvsig.fmap.dal.swing.impl.featuretable.FeatureTablePanel; |
121 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleEditedFeaturesTableModelImpl; |
122 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModelImpl; |
123 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleSelectedFeaturesTableModelImpl; |
124 |
import org.gvsig.fmap.dal.swing.impl.featuretable.table.DefaultFeatureTableModel; |
125 |
import org.gvsig.fmap.dal.swing.impl.featuretable.table.EmptyFeatureTableModel; |
126 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultAttributeDescriptorAndExpressionPickerController; |
127 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultAttributeDescriptorPickerController; |
128 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributePanel; |
129 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureAttributesSelectionPanel; |
130 |
import org.gvsig.fmap.dal.swing.impl.featuretype.DefaultFeatureTypePanel; |
131 |
import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeListCellRendererImpl; |
132 |
import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeTableCellRendererImpl; |
133 |
import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionDialog; |
134 |
import org.gvsig.fmap.dal.swing.impl.jdbc.DefaultJDBCConnectionPanel; |
135 |
import org.gvsig.fmap.dal.swing.impl.jdbc.JDBCConnectionPickerController; |
136 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
137 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchParameters; |
138 |
import org.gvsig.fmap.dal.swing.impl.storesrepository.StoresRepositoryControllerImpl; |
139 |
import org.gvsig.fmap.dal.swing.impl.storesrepository.StoresRepositoryTreeModel; |
140 |
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionDialog; |
141 |
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel; |
142 |
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory; |
143 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
144 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory; |
145 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters; |
146 |
import org.gvsig.fmap.dal.swing.storesrepository.StoresRepositoryController; |
147 |
import org.gvsig.fmap.geom.Geometry; |
148 |
import org.gvsig.tools.ToolsLocator; |
149 |
import org.gvsig.tools.dynform.DynFormDefinition; |
150 |
import org.gvsig.tools.dynform.DynFormLocator; |
151 |
import org.gvsig.tools.dynobject.DynClass; |
152 |
import org.gvsig.tools.dynobject.DynStruct; |
153 |
import org.gvsig.tools.dynobject.Tags; |
154 |
import org.gvsig.tools.exception.BaseException; |
155 |
import org.gvsig.tools.i18n.I18nManager; |
156 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
157 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
158 |
import org.slf4j.Logger; |
159 |
import org.slf4j.LoggerFactory; |
160 |
|
161 |
|
162 |
/**
|
163 |
* @author fdiaz
|
164 |
*
|
165 |
*/
|
166 |
@SuppressWarnings("UseSpecificCatch") |
167 |
public class DefaultDataSwingManager implements DataSwingManager { |
168 |
|
169 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataSwingManager.class); |
170 |
|
171 |
private final Map<String,DALActionFactory> featureStoreSearchActions; |
172 |
private final Map<String,SearchPostProcessFactory> searchPostProcess; |
173 |
private Map<String,SearchConditionPanelFactory> searchConditionPanelFactories; |
174 |
private Integer useLabels; |
175 |
|
176 |
public DefaultDataSwingManager() {
|
177 |
this.featureStoreSearchActions = new LinkedHashMap<>(); |
178 |
this.registerStoreAction(new SelectionAddActionFactory()); |
179 |
this.registerStoreAction(new SelectionFilterActionFactory()); |
180 |
this.registerStoreAction(new SelectionSetActionFactory()); |
181 |
this.registerStoreAction(new ShowFormActionFactory()); |
182 |
this.registerStoreAction(new GraphActionFactory()); |
183 |
this.registerStoreAction(new CopyFormActionFactory()); |
184 |
|
185 |
this.searchPostProcess = new HashMap<>(); |
186 |
} |
187 |
|
188 |
@Override
|
189 |
public JFeaturesForm createJFeaturesForm(FeatureStore store) throws CreateJFeatureFormException { |
190 |
try {
|
191 |
FeatureType featureType = store.getDefaultFeatureType(); |
192 |
|
193 |
DefaultJFeaturesForm form = new DefaultJFeaturesForm();
|
194 |
form.bind(store, featureType2DynClass(store, featureType), null);
|
195 |
return form;
|
196 |
|
197 |
} catch (Exception ex) { |
198 |
throw new CreateJFeatureFormException(ex); |
199 |
} |
200 |
} |
201 |
|
202 |
@Override
|
203 |
public JFeaturesForm createJFeaturesForm(FeatureStore store, FeatureQuery query) throws CreateJFeatureFormException { |
204 |
try {
|
205 |
FeatureType featureType = store.getDefaultFeatureType(); |
206 |
|
207 |
DefaultJFeaturesForm form = new DefaultJFeaturesForm();
|
208 |
form.bind(store, featureType2DynClass(store, featureType), query); |
209 |
return form;
|
210 |
|
211 |
} catch (Exception ex) { |
212 |
throw new CreateJFeatureFormException(ex); |
213 |
} |
214 |
} |
215 |
|
216 |
public DynClass featureType2DynClass(FeatureStore store, FeatureType type) {
|
217 |
FeatureTypeDefinitionsManager featureTypeDefinitionsManager = DALLocator.getFeatureTypeDefinitionsManager(); |
218 |
if( featureTypeDefinitionsManager.contains(store,type) ) {
|
219 |
// Force reload next call to get.
|
220 |
featureTypeDefinitionsManager.remove(store,type); |
221 |
} |
222 |
DynClass dynClass = featureTypeDefinitionsManager.get(store,type); |
223 |
// Force reload next call to get.
|
224 |
DynFormLocator.getDynFormManager().removeDefinition(dynClass.getName()); |
225 |
return dynClass;
|
226 |
} |
227 |
|
228 |
@Override
|
229 |
public JDBCConnectionPanel createJDBCConnectionPanel() {
|
230 |
JDBCConnectionPanel x = new DefaultJDBCConnectionPanel();
|
231 |
return x;
|
232 |
} |
233 |
|
234 |
@Override
|
235 |
public JDBCConnectionDialog createJDBCConectionDialog() {
|
236 |
JDBCConnectionDialog x = new DefaultJDBCConnectionDialog();
|
237 |
return x;
|
238 |
} |
239 |
|
240 |
@Override
|
241 |
public void configureExpressionBuilder(ExpressionBuilderConfig builder, FeatureStore store) { |
242 |
DataManager dataManager = DALLocator.getDataManager(); |
243 |
FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
244 |
|
245 |
builder.removeAllElements(); |
246 |
FeatureStoreProviderFactory storeFactory = (FeatureStoreProviderFactory) store.getProviderFactory(); |
247 |
Feature sampleFeature = store.getSampleFeature(); |
248 |
builder.setAllowedFunctions(storeFactory.allowFunction()); |
249 |
if( sampleFeature!=null ) { |
250 |
featureSymbolTable.setFeature(sampleFeature); |
251 |
builder.setPreviewSymbolTable(featureSymbolTable.createParent()); |
252 |
} |
253 |
builder.addSymbolTable(featureSymbolTable); |
254 |
FeatureStoreElement storeElement = new DefaultFeatureStoreElement2(store);
|
255 |
builder.addElement(storeElement); |
256 |
if( store.getProviderFactory().hasSQLSupport()==DataStoreProviderFactory.YES ) {
|
257 |
builder.getPreferences().setSQLCompatible(true);
|
258 |
} |
259 |
builder.addSuggestionFactory(new StorePointFieldSuggestionProviderFactory(store));
|
260 |
builder.addSuggestionFactory(new QuotesForFieldNameSuggestionProviderFactory(store));
|
261 |
builder.addSuggestionFactory(new WrongNameFieldSuggestionProviderFactory(store));
|
262 |
builder.addSuggestionFactory(new CheckTableFieldsSuggestionProviderFactory(store));
|
263 |
builder.addSuggestionFactory(new DivSuggestionProviderFactory(store));
|
264 |
} |
265 |
|
266 |
@Override
|
267 |
public void resetExpressionBuilder(ExpressionBuilderConfig builder) { |
268 |
builder.removeAllElements(); |
269 |
builder.removeAddedElements(); |
270 |
builder.setPreviewSymbolTable(ExpressionUtils.createSymbolTable()); |
271 |
} |
272 |
|
273 |
@Override
|
274 |
public void addToExpressionBuilder(ExpressionBuilderConfig builder, FeatureStore store, String name) { |
275 |
this.addToExpressionBuilder(builder, store, name, false); |
276 |
} |
277 |
|
278 |
@Override
|
279 |
public void addToExpressionBuilder(ExpressionBuilderConfig builder, FeatureStore store, String name, boolean useHostVariable) { |
280 |
// Este metodo permite a?adir mas de un store al builder llamandolo
|
281 |
// con un name distinto para cada store. En el arbol se presentaran todos
|
282 |
// los stores que se configuren en el builder.
|
283 |
// Ojo, que las expresiones creadas por estos builder no son compatible
|
284 |
// con SQL.
|
285 |
DataManager dataManager = DALLocator.getDataManager(); |
286 |
|
287 |
// Creamos el store-element y lo a?adimos al builder
|
288 |
FeatureStoreElement n = new DefaultFeatureStoreElement2(store, name, useHostVariable);
|
289 |
builder.addElement(n); |
290 |
|
291 |
// Creamos una tabla de simbolos de ejemplo basada en el store, y la
|
292 |
// a?adimos a la tabla de simbolos de previsualizacion del builder.
|
293 |
FeatureSymbolTable featureSymbolTable = dataManager.createFeatureSymbolTable(); |
294 |
Feature sampleFeature = store.getSampleFeature(); |
295 |
if( sampleFeature!=null ) { |
296 |
featureSymbolTable.setFeature(sampleFeature); |
297 |
builder.getPreviewSymbolTable().addSymbolTable(featureSymbolTable); |
298 |
} |
299 |
|
300 |
// forzamos a que al insertar campos de un store se indique siempre
|
301 |
// en nombre del store. Necesario si hay mas de un store en el builder.
|
302 |
List<Element> elements = builder.getElements(); |
303 |
for (Element item : elements) { |
304 |
if( item instanceof FeatureStoreElement ) { |
305 |
((FeatureStoreElement)item).setUseFullyQualifiedNames(true);
|
306 |
} |
307 |
} |
308 |
// Marcamos como no compatible sql las expresiones que vamos a generar.
|
309 |
builder.getPreferences().setSQLCompatible(false);
|
310 |
|
311 |
// A?adimos los generadores de sugerencias.
|
312 |
builder.addSuggestionFactory(new StorePointFieldSuggestionProviderFactory(store));
|
313 |
builder.addSuggestionFactory(new QuotesForFieldNameSuggestionProviderFactory(store));
|
314 |
builder.addSuggestionFactory(new WrongNameFieldSuggestionProviderFactory(store));
|
315 |
builder.addSuggestionFactory(new CheckTableFieldsSuggestionProviderFactory(store));
|
316 |
builder.addSuggestionFactory(new DivSuggestionProviderFactory(store));
|
317 |
} |
318 |
|
319 |
@Override
|
320 |
public JExpressionBuilder createQueryFilterExpresion(FeatureStore store) {
|
321 |
return this.createJExpressionBuilder(store); |
322 |
} |
323 |
|
324 |
@Override
|
325 |
public JExpressionBuilder createJExpressionBuilder(final FeatureStore store) { |
326 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
327 |
final JExpressionBuilder builder = expressionSwingManager.createJExpressionBuilder();
|
328 |
this.configureExpressionBuilder(builder.getConfig(), store);
|
329 |
builder.expandElement( |
330 |
(Element t) -> t!=null && StringUtils.equals(t.getName(),store.getName()) |
331 |
); |
332 |
return builder;
|
333 |
} |
334 |
|
335 |
@Override
|
336 |
public ExpressionPickerController createExpressionPickerController(FeatureStore store, JTextComponent text, JButton button, JButton bookmarks, JButton history) { |
337 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
338 |
ExpressionPickerController builder = expressionSwingManager.createExpressionPickerController(text, button, bookmarks, history); |
339 |
if( store !=null ) { |
340 |
this.configureExpressionBuilder(builder.getConfig(), store);
|
341 |
} |
342 |
return builder;
|
343 |
} |
344 |
|
345 |
@Override
|
346 |
public AttributeDescriptorAndExpressionPickerController createExpressionPickerController(FeatureStore store, JComboBox combo, JButton button, JButton bookmarks, JButton history) { |
347 |
DefaultAttributeDescriptorAndExpressionPickerController controller = new DefaultAttributeDescriptorAndExpressionPickerController(combo, button, bookmarks, history, null); |
348 |
if( store !=null ) { |
349 |
this.configureExpressionBuilder(controller.getConfig(), store);
|
350 |
} |
351 |
return controller;
|
352 |
} |
353 |
|
354 |
@Override
|
355 |
public JFeatureForm createJFeatureForm(FeatureStore store) throws CreateJFeatureFormException { |
356 |
JFeatureForm form = new DefaultJFeatureForm();
|
357 |
form.setStore(store); |
358 |
return form;
|
359 |
} |
360 |
|
361 |
@Override
|
362 |
public JFeatureReferencesForm createJFeatureReferencesForm(FeatureStore store, List<FeatureReference> references) throws CreateJFeatureFormException { |
363 |
JFeatureReferencesForm form = new DefaultJFeatureReferencesForm();
|
364 |
form.bind(store, references); |
365 |
return form;
|
366 |
} |
367 |
|
368 |
@Override
|
369 |
public JFeatureForm createJFeatureForm(Feature feature) throws CreateJFeatureFormException { |
370 |
JFeatureForm form = new DefaultJFeatureForm();
|
371 |
form.setFeature(feature); |
372 |
return form;
|
373 |
} |
374 |
|
375 |
@Override
|
376 |
public JFeatureForm createJFeatureForm(DynFormDefinition definicion) throws CreateJFeatureFormException { |
377 |
JFeatureForm form = new DefaultJFeatureForm();
|
378 |
form.setDefinition(definicion); |
379 |
return form;
|
380 |
} |
381 |
|
382 |
@Override
|
383 |
public JFeatureTable createJFeatureTable(FeatureTableModel model) {
|
384 |
return this.createJFeatureTable(model, true); |
385 |
} |
386 |
|
387 |
@Override
|
388 |
public JFeatureTable createJFeatureTable(FeatureTableModel model, boolean isDoubleBuffered) { |
389 |
return new FeatureTablePanel(model, isDoubleBuffered); |
390 |
} |
391 |
|
392 |
@Override
|
393 |
public FeatureTableModel createEmptyFeatureTableModel(DynStruct struct) {
|
394 |
return new EmptyFeatureTableModel(struct); |
395 |
} |
396 |
|
397 |
@Override
|
398 |
public FeatureTableModel createFeatureTableModel(FeatureStore featureStore,
|
399 |
FeatureQuery featureQuery) { |
400 |
try {
|
401 |
FeaturePagingHelper pager = DALLocator.getDataManager().createFeaturePagingHelper( |
402 |
featureStore, featureQuery, |
403 |
FeaturePagingHelper.DEFAULT_PAGE_SIZE |
404 |
); |
405 |
return this.createFeatureTableModel(pager); |
406 |
} catch (BaseException ex) {
|
407 |
throw new RuntimeException("Can't create a FeatureTableModel.", ex); |
408 |
} |
409 |
} |
410 |
|
411 |
@Override
|
412 |
public FeatureTableModel createFeatureTableModel(FeaturePagingHelper featurePager) {
|
413 |
return new DefaultFeatureTableModel(featurePager); |
414 |
} |
415 |
|
416 |
@Override
|
417 |
public ProjectionPickerController createProjectionPickerController(
|
418 |
JTextField txtProjection,
|
419 |
JButton btnSelectProjection
|
420 |
) { |
421 |
ProjectionPickerControllerImpl picker = new ProjectionPickerControllerImpl(txtProjection, btnSelectProjection);
|
422 |
return picker;
|
423 |
} |
424 |
|
425 |
@Override
|
426 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo) { |
427 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, null); |
428 |
return controller;
|
429 |
} |
430 |
|
431 |
@Override
|
432 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list) { |
433 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, null); |
434 |
return controller;
|
435 |
} |
436 |
|
437 |
@Override
|
438 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JComboBox combo, Predicate<FeatureAttributeDescriptor> filter) { |
439 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(combo, filter);
|
440 |
return controller;
|
441 |
} |
442 |
|
443 |
@Override
|
444 |
public AttributeDescriptorPickerController createAttributeDescriptorPickerController(JList list, Predicate<FeatureAttributeDescriptor> filter) { |
445 |
AttributeDescriptorPickerController controller = new DefaultAttributeDescriptorPickerController(list, filter);
|
446 |
return controller;
|
447 |
} |
448 |
|
449 |
@Override
|
450 |
public FeatureTypePanel createFeatureTypePanel() {
|
451 |
FeatureTypePanel panel = new DefaultFeatureTypePanel();
|
452 |
return panel;
|
453 |
} |
454 |
|
455 |
@Override
|
456 |
public FeatureTypeAttributePanel createFeatureTypeAttributePanel() {
|
457 |
FeatureTypeAttributePanel panel = new DefaultFeatureAttributePanel();
|
458 |
return panel;
|
459 |
} |
460 |
|
461 |
@Override
|
462 |
public FeatureStoreElement createFeatureStoreElement() {
|
463 |
FeatureStoreElement e = new DefaultFeatureStoreElement2(null); |
464 |
return e;
|
465 |
} |
466 |
|
467 |
@Override
|
468 |
public FeatureStoreElement createFeatureStoreElement(FeatureStore store) {
|
469 |
FeatureStoreElement e = new DefaultFeatureStoreElement2(store);
|
470 |
return e;
|
471 |
} |
472 |
|
473 |
@Override
|
474 |
public ExpressionPickerController createExpressionPickerController(FeatureStore store, JTextComponent text, JButton button) { |
475 |
FeatureSymbolTable previewSymbolTable = DALLocator.getManager().createFeatureSymbolTable(); |
476 |
previewSymbolTable.setFeature(store.getSampleFeature()); |
477 |
|
478 |
ExpressionPickerController controller = ExpressionEvaluatorSwingLocator.getManager().createExpressionPickerController(text, button); |
479 |
controller.getConfig().addElement(this.createFeatureStoreElement(store));
|
480 |
controller.getConfig().setPreviewSymbolTable(previewSymbolTable); |
481 |
|
482 |
return controller;
|
483 |
} |
484 |
|
485 |
|
486 |
@Override
|
487 |
public FeatureStoreSearchPanel createFeatureStoreSearchPanel(FeatureStore store) {
|
488 |
DefaultSearchPanel e = new DefaultSearchPanel(store);
|
489 |
return e;
|
490 |
} |
491 |
|
492 |
@Override
|
493 |
public final void registerStoreAction(DALActionFactory action) { |
494 |
this.featureStoreSearchActions.put(action.getName().toLowerCase(), action);
|
495 |
} |
496 |
|
497 |
@Override
|
498 |
public Collection<DALActionFactory> getStoreActions() { |
499 |
return Collections.unmodifiableCollection(this.featureStoreSearchActions.values()); |
500 |
} |
501 |
|
502 |
@Override
|
503 |
public Collection<DALActionFactory> getApplicableStoreActions(DALActionContext context) { |
504 |
Collection<DALActionFactory> factories = new ArrayList<>(); |
505 |
try {
|
506 |
for (DALActionFactory factory : this.featureStoreSearchActions.values()) { |
507 |
if (factory == null ) { |
508 |
continue;
|
509 |
} |
510 |
try {
|
511 |
if (factory.isApplicable(context)) {
|
512 |
factories.add(factory); |
513 |
} |
514 |
} catch (Exception ex) { |
515 |
LOGGER.warn("Can't access to DAL action factory " + factory.getName(), ex);
|
516 |
} |
517 |
|
518 |
} |
519 |
} catch (Exception ex) { |
520 |
LOGGER.warn("Can't get DAL action factories", ex);
|
521 |
} |
522 |
return factories;
|
523 |
} |
524 |
|
525 |
@Override
|
526 |
public DALActionFactory getStoreAction(String name) { |
527 |
DALActionFactory action = this.featureStoreSearchActions.get(name.toLowerCase());
|
528 |
return action;
|
529 |
} |
530 |
|
531 |
@Override
|
532 |
public void setStoreAction(AbstractButton component, String name, boolean preserveLabel, DALActionContext context) { |
533 |
DALActionFactory factory = this.getStoreAction(name);
|
534 |
Action action = factory.createAction(context);
|
535 |
if( preserveLabel ) {
|
536 |
String s = component.getText();
|
537 |
component.setAction(action); |
538 |
component.setText(s); |
539 |
} else {
|
540 |
component.setAction(action); |
541 |
} |
542 |
} |
543 |
|
544 |
|
545 |
@Override
|
546 |
public PickerController<JDBCServerExplorerParameters> createJDBCConnectionPickerController(
|
547 |
JComboBox cboConnection, JButton btnConnection |
548 |
) { |
549 |
JDBCConnectionPickerController x = new JDBCConnectionPickerController(cboConnection, btnConnection);
|
550 |
return x;
|
551 |
} |
552 |
|
553 |
@Override
|
554 |
public SimpleFeaturesTableModel createSimpleFeaturesTableModel(FeatureStore store) {
|
555 |
try {
|
556 |
SimpleFeaturesTableModelImpl m = new SimpleFeaturesTableModelImpl(store);
|
557 |
return m;
|
558 |
} catch (DataException ex) {
|
559 |
throw new RuntimeException("Can't creatre SimpleFeaturesTableModel.", ex); |
560 |
} |
561 |
} |
562 |
|
563 |
@Override
|
564 |
public SimpleFeaturesTableModel createSimpleFeaturesTableModel(FeatureStore store, Expression filter) { |
565 |
try {
|
566 |
SimpleFeaturesTableModelImpl m = new SimpleFeaturesTableModelImpl(store, filter);
|
567 |
return m;
|
568 |
} catch (DataException ex) {
|
569 |
throw new RuntimeException("Can't creatre SimpleFeaturesTableModel.", ex); |
570 |
} |
571 |
} |
572 |
|
573 |
@Override
|
574 |
public SimpleFeaturesTableModel createSimpleEditedFeaturesTableModel(FeatureStore store, Expression filter) { |
575 |
SimpleFeaturesTableModelImpl m = new SimpleEditedFeaturesTableModelImpl(store, filter);
|
576 |
return m;
|
577 |
} |
578 |
|
579 |
@Override
|
580 |
public SimpleFeaturesTableModel createSimpleSelectedFeaturesTableModel(FeatureStore store, Expression filter) { |
581 |
SimpleFeaturesTableModelImpl m = new SimpleSelectedFeaturesTableModelImpl(store, filter);
|
582 |
return m;
|
583 |
} |
584 |
|
585 |
@Override
|
586 |
public SimpleFeaturesTableModel createSimpleFeaturesTableModel(FeatureType featureType, List<String> columnNames, List<Feature> features) { |
587 |
SimpleFeaturesTableModelImpl m = new SimpleFeaturesTableModelImpl(featureType, columnNames, features);
|
588 |
return m;
|
589 |
} |
590 |
|
591 |
@Override
|
592 |
public FeatureAttributeListCellRenderer createDefaultFeatureAttributeListCellRenderer() {
|
593 |
FeatureAttributeListCellRenderer r = new FeatureAttributeListCellRendererImpl();
|
594 |
return r;
|
595 |
} |
596 |
|
597 |
@Override
|
598 |
public FeatureAttributeTableCellRenderer createDefaultFeatureAttributeTableCellRenderer() {
|
599 |
FeatureAttributeTableCellRenderer r = new FeatureAttributeTableCellRendererImpl();
|
600 |
return r;
|
601 |
} |
602 |
|
603 |
@Override
|
604 |
public FeatureQueryOrderPanel createFeatureStoreOrderPanel() {
|
605 |
DefaultFeatureQueryOrderPanel p = new DefaultFeatureQueryOrderPanel();
|
606 |
return p;
|
607 |
} |
608 |
|
609 |
@Override
|
610 |
public Iterable<SearchConditionPanelFactory> getSearchConditionPanels() { |
611 |
if( this.searchConditionPanelFactories==null ) { |
612 |
return Collections.EMPTY_LIST; |
613 |
} |
614 |
return this.searchConditionPanelFactories.values(); |
615 |
} |
616 |
|
617 |
@Override
|
618 |
public void registerSearchConditionPanel(SearchConditionPanelFactory factory) { |
619 |
if( this.searchConditionPanelFactories==null ) { |
620 |
this.searchConditionPanelFactories = new HashMap<>(); |
621 |
} |
622 |
this.searchConditionPanelFactories.put(factory.getName(), factory);
|
623 |
} |
624 |
|
625 |
@Override
|
626 |
public FeatureAttributesSelectionPanel createFeatureAttributeSelectionPanel() {
|
627 |
FeatureAttributesSelectionPanel p = new DefaultFeatureAttributesSelectionPanel();
|
628 |
return p;
|
629 |
} |
630 |
|
631 |
@Override
|
632 |
public void registerSearchPostProcess(SearchPostProcessFactory process) { |
633 |
this.searchPostProcess.put(process.getName(), process);
|
634 |
} |
635 |
|
636 |
@Override
|
637 |
public Map<String,SearchPostProcessFactory> getSearchPostProcess() { |
638 |
return this.searchPostProcess; |
639 |
} |
640 |
|
641 |
@Override
|
642 |
public SearchPostProcessFactory getSearchPostProcess(String name) { |
643 |
SearchPostProcessFactory process = this.searchPostProcess.get(name);
|
644 |
return process;
|
645 |
} |
646 |
|
647 |
@Override
|
648 |
public FeaturesFormContext createFeaturesFormContext(FeatureStore store) {
|
649 |
DefaultFeaturesFormContext context = new DefaultFeaturesFormContext(store);
|
650 |
return context;
|
651 |
} |
652 |
|
653 |
@Override
|
654 |
public TreeModel createTreeModel(StoresRepository repository) { |
655 |
StoresRepositoryTreeModel model = new StoresRepositoryTreeModel(repository);
|
656 |
return model;
|
657 |
} |
658 |
|
659 |
@Override
|
660 |
public String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc) { |
661 |
return getAttributeDescriptorLabel(attrdesc, null); |
662 |
} |
663 |
|
664 |
@Override
|
665 |
public String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc, String tableName) { |
666 |
String theLabel;
|
667 |
int theUseLabels;
|
668 |
if (getUseLabels() == null) { |
669 |
Tags tags = attrdesc.getTags(); |
670 |
if (tags.has(DAL_USE_LABELS)) {
|
671 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
672 |
} else {
|
673 |
if (attrdesc.getFeatureType() != null) { |
674 |
tags = attrdesc.getFeatureType().getTags(); |
675 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
676 |
} else {
|
677 |
theUseLabels = USE_LABELS_NO; |
678 |
} |
679 |
} |
680 |
} else {
|
681 |
theUseLabels = getUseLabels(); |
682 |
} |
683 |
switch (theUseLabels) {
|
684 |
case USE_LABELS_BOTH:
|
685 |
if (!StringUtils.equals(attrdesc.getLocalizedLabel(), attrdesc.getName())){
|
686 |
if (StringUtils.isBlank(tableName)) {
|
687 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName()); |
688 |
} else {
|
689 |
theLabel = String.format("%s [%s/%s]", attrdesc.getLocalizedLabel(), attrdesc.getName(), tableName); |
690 |
} |
691 |
break;
|
692 |
} |
693 |
case USE_LABELS_YES:
|
694 |
if (StringUtils.isBlank(tableName)) {
|
695 |
theLabel = attrdesc.getLocalizedLabel(); |
696 |
} else {
|
697 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), tableName); |
698 |
} |
699 |
break;
|
700 |
default:
|
701 |
case USE_LABELS_NO:
|
702 |
if (StringUtils.isBlank(tableName)) {
|
703 |
theLabel = attrdesc.getName(); |
704 |
} else {
|
705 |
theLabel = String.format("%s [%s]", attrdesc.getName(), tableName); |
706 |
} |
707 |
break;
|
708 |
} |
709 |
return theLabel;
|
710 |
} |
711 |
|
712 |
/**
|
713 |
* @return the useLabels
|
714 |
*/
|
715 |
@Override
|
716 |
public Integer getUseLabels() { |
717 |
return useLabels;
|
718 |
} |
719 |
|
720 |
/**
|
721 |
* @param useLabels the useLabels to set
|
722 |
*/
|
723 |
@Override
|
724 |
public void setUseLabels(Integer useLabels) { |
725 |
this.useLabels = useLabels;
|
726 |
} |
727 |
|
728 |
@Override
|
729 |
public SearchParameters createFeatureStoreSearchPanelParameters() {
|
730 |
return new DefaultSearchParameters(); |
731 |
} |
732 |
|
733 |
public FeatureQueryPickerController createFeatureQueryPickerController(JTextComponent text, JButton button, JButton history, JButton bookmarks) { |
734 |
DefaultFeatureQueryPickerController controller = new DefaultFeatureQueryPickerController(text, button, history, bookmarks);
|
735 |
return controller;
|
736 |
} |
737 |
|
738 |
@Override
|
739 |
public StoresRepositoryController createStoresRepositoryController(JTree tree) { |
740 |
StoresRepositoryControllerImpl src = new StoresRepositoryControllerImpl(tree);
|
741 |
return src;
|
742 |
} |
743 |
|
744 |
@Override
|
745 |
public Icon getStoreGeometryIcon(FeatureStore store) { |
746 |
try {
|
747 |
if( store == null ) { |
748 |
return null; |
749 |
} |
750 |
FeatureType ft = store.getDefaultFeatureTypeQuietly(); |
751 |
if( ft == null ) { |
752 |
return null; |
753 |
} |
754 |
FeatureAttributeDescriptor geomattr = ft.getDefaultGeometryAttribute(); |
755 |
if( geomattr == null ) { |
756 |
return null; |
757 |
} |
758 |
int geometryType = geomattr.getGeomType().getType();
|
759 |
String name;
|
760 |
switch (geometryType) {
|
761 |
case Geometry.TYPES.LINE:
|
762 |
name = "store-geomtype-line";
|
763 |
break;
|
764 |
case Geometry.TYPES.POINT:
|
765 |
name = "store-geomtype-point";
|
766 |
break;
|
767 |
case Geometry.TYPES.POLYGON:
|
768 |
name = "store-geomtype-polygon";
|
769 |
break;
|
770 |
case Geometry.TYPES.MULTILINE:
|
771 |
name = "store-geomtype-multiline";
|
772 |
break;
|
773 |
case Geometry.TYPES.MULTIPOINT:
|
774 |
name = "store-geomtype-multipoint";
|
775 |
break;
|
776 |
case Geometry.TYPES.MULTIPOLYGON:
|
777 |
name = "store-geomtype-multipolygon";
|
778 |
break;
|
779 |
case Geometry.TYPES.GEOMETRY:
|
780 |
name = "store-geomtype-mix";
|
781 |
break;
|
782 |
default:
|
783 |
return null; |
784 |
} |
785 |
if (!store.isFeatureSelectionEmpty()) {
|
786 |
name = name + "-sel";
|
787 |
} |
788 |
name = name + ".png";
|
789 |
URL url = this.getClass().getResource("/storegeomtypes/" + name); |
790 |
if (url == null) { |
791 |
return null; |
792 |
} |
793 |
Icon icon = new ImageIcon(url); |
794 |
return icon;
|
795 |
} catch (Exception ex) { |
796 |
return null; |
797 |
} |
798 |
} |
799 |
|
800 |
@Override
|
801 |
public int askUserStopEditing(FeatureStore featureStore) { |
802 |
return this.askUserStopEditing(null, featureStore, true); |
803 |
} |
804 |
|
805 |
public int askUserStopEditing(FeatureStore featureStore, boolean allowContinue) { |
806 |
return this.askUserStopEditing(null, featureStore, allowContinue); |
807 |
} |
808 |
|
809 |
public int askUserStopEditing(Component parent, FeatureStore featureStore, boolean allowContinue) { |
810 |
boolean allowWrite = featureStore.allowWrite();
|
811 |
|
812 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
813 |
String message;
|
814 |
String[] options = new String[allowContinue?3:2]; |
815 |
int defaultoption;
|
816 |
|
817 |
message = "<html>"+
|
818 |
"<p>"+i18n.getTranslation("stop_edition")+"</p><br>"; |
819 |
if( allowWrite ) {
|
820 |
message = message + |
821 |
"<b>"+i18n.getTranslation("_Guardar")+": </b>"+i18n.getTranslation("_Save_changes")+"<br>"; |
822 |
options[0] = i18n.getTranslation("_Guardar"); |
823 |
defaultoption = 0;
|
824 |
} else {
|
825 |
message = message + |
826 |
"<b>"+i18n.getTranslation("_Export")+": </b>"+i18n.getTranslation("_Export_table")+"<br>"; |
827 |
options[0] = i18n.getTranslation("_Export"); |
828 |
defaultoption = allowContinue?2:0; |
829 |
} |
830 |
message = message + |
831 |
"<b>"+i18n.getTranslation("_Descartar")+": </b>"+i18n.getTranslation("_Discard_and_lose_changes")+"<br>"; |
832 |
options[1] = i18n.getTranslation("_Descartar"); |
833 |
if( allowContinue ) {
|
834 |
message = message + |
835 |
"<b>"+i18n.getTranslation("_Continuar")+": </b>"+i18n.getTranslation("_Continue_editing_without_saving")+"<br>"; |
836 |
options[2] = i18n.getTranslation("_Continuar"); |
837 |
} |
838 |
message = message + "</html>";
|
839 |
|
840 |
int resp = JOptionPane |
841 |
.showOptionDialog( |
842 |
parent, |
843 |
message, |
844 |
i18n.getTranslation("stop_edition"),
|
845 |
allowContinue?JOptionPane.YES_NO_CANCEL_OPTION:JOptionPane.YES_NO_OPTION, |
846 |
JOptionPane.QUESTION_MESSAGE, null, options, |
847 |
options[defaultoption]); |
848 |
|
849 |
switch( resp ) {
|
850 |
case 0: |
851 |
if( allowWrite )
|
852 |
return STOP_EDITING_SAVE;
|
853 |
return STOP_EDITING_EXPORT;
|
854 |
case 1: |
855 |
return STOP_EDITING_DISCARD;
|
856 |
default:
|
857 |
case 2: |
858 |
return STOP_EDITING_CONTINUE;
|
859 |
} |
860 |
} |
861 |
|
862 |
public boolean exportStore(FeatureStore store, WindowManager.MODE mode) { |
863 |
DALActionFactory exportActionFactory = null;
|
864 |
for (DALActionFactory action : this.getStoreActions()) { |
865 |
if( StringUtils.equalsIgnoreCase("Export", action.getName()) ) { |
866 |
exportActionFactory = action; |
867 |
break;
|
868 |
} |
869 |
} |
870 |
if( exportActionFactory == null ) { |
871 |
return false; |
872 |
} |
873 |
DALActionContext context = new AbstractDALActionFactory.AbstractDALActionContext("ExportActionContext") { |
874 |
@Override
|
875 |
public DataStore getStore() {
|
876 |
return store;
|
877 |
} |
878 |
}; |
879 |
context.set("WindowMode", mode);
|
880 |
Action action = exportActionFactory.createAction(context);
|
881 |
action.actionPerformed(new ActionEvent(store, 0, exportActionFactory.getName())); |
882 |
return true; |
883 |
} |
884 |
|
885 |
} |
886 |
|
887 |
|