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