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 / featureform / swing / impl / DefaultJFeaturesForm.java @ 44259
History | View | Annotate | Download (22.9 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.featureform.swing.impl; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dimension; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.util.ArrayList; |
29 |
import java.util.List; |
30 |
import javax.swing.AbstractAction; |
31 |
import javax.swing.Action; |
32 |
import static javax.swing.Action.ACTION_COMMAND_KEY; |
33 |
import static javax.swing.Action.NAME; |
34 |
import static javax.swing.Action.SHORT_DESCRIPTION; |
35 |
import static javax.swing.Action.SMALL_ICON; |
36 |
|
37 |
import javax.swing.JComponent; |
38 |
import javax.swing.JOptionPane; |
39 |
import javax.swing.JPanel; |
40 |
import org.gvsig.expressionevaluator.Expression; |
41 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
42 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
43 |
|
44 |
import org.slf4j.Logger; |
45 |
import org.slf4j.LoggerFactory; |
46 |
|
47 |
import org.gvsig.featureform.swing.JFeaturesForm; |
48 |
import org.gvsig.fmap.dal.DALLocator; |
49 |
import org.gvsig.fmap.dal.DataManager; |
50 |
import org.gvsig.fmap.dal.DataStore; |
51 |
import org.gvsig.fmap.dal.StoresRepository; |
52 |
import org.gvsig.fmap.dal.exception.DataException; |
53 |
import org.gvsig.fmap.dal.expressionevaluator.ExpressionEvaluator; |
54 |
import org.gvsig.fmap.dal.feature.Feature; |
55 |
import org.gvsig.fmap.dal.feature.FacadeOfAFeature; |
56 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
57 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
58 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
59 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
60 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
61 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
62 |
import org.gvsig.fmap.dal.swing.impl.DefaultDataSwingManager; |
63 |
import org.gvsig.tools.ToolsLocator; |
64 |
import org.gvsig.tools.dynform.AbortActionException; |
65 |
import org.gvsig.tools.dynform.DynFormDefinition; |
66 |
import org.gvsig.tools.dynform.DynFormLocator; |
67 |
import org.gvsig.tools.dynform.DynFormManager; |
68 |
import org.gvsig.tools.dynform.JDynForm; |
69 |
import org.gvsig.tools.dynform.JDynFormSet; |
70 |
import org.gvsig.tools.dynform.JDynFormSet.JDynFormSetListener; |
71 |
import org.gvsig.tools.dynobject.DynClass; |
72 |
import org.gvsig.tools.dynobject.DynObject; |
73 |
import org.gvsig.tools.evaluator.Evaluator; |
74 |
import org.gvsig.tools.exception.BaseException; |
75 |
import org.gvsig.tools.i18n.I18nManager; |
76 |
import org.gvsig.tools.observer.Observable; |
77 |
import org.gvsig.tools.observer.Observer; |
78 |
import org.gvsig.tools.service.ServiceException; |
79 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
80 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
81 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
82 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
83 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
84 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE; |
85 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
86 |
import org.gvsig.tools.util.ResourcesStorage; |
87 |
|
88 |
/**
|
89 |
* @author fdiaz
|
90 |
*
|
91 |
*/
|
92 |
@SuppressWarnings("UseSpecificCatch") |
93 |
public class DefaultJFeaturesForm implements JFeaturesForm { |
94 |
|
95 |
public class DefaultFeaturesFormContext implements FeaturesFormContext { |
96 |
|
97 |
private DefaultFeaturesFormContext() {
|
98 |
|
99 |
} |
100 |
|
101 |
@Override
|
102 |
public ResourcesStorage getResourcesStorage() {
|
103 |
return store.getResourcesStorage();
|
104 |
} |
105 |
|
106 |
@Override
|
107 |
public FeatureStore getFeatureStore(String storeName) { |
108 |
return (FeatureStore) this.getDataStore(storeName); |
109 |
} |
110 |
|
111 |
@Override
|
112 |
public DataStore getDataStore(String storeName) { |
113 |
FeatureStore theStore = (FeatureStore) store.getChildren().get(storeName); |
114 |
if (theStore == null) { |
115 |
DataManager dataManager = DALLocator.getDataManager(); |
116 |
StoresRepository repository = dataManager.getStoresRepository(); |
117 |
if (repository.containsKey(storeName)) {
|
118 |
theStore = (FeatureStore) repository.get(storeName); |
119 |
} |
120 |
} |
121 |
return theStore;
|
122 |
} |
123 |
|
124 |
} |
125 |
|
126 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJFeaturesForm.class); |
127 |
|
128 |
private static final int PAGE_SIZE = 500; |
129 |
private final JPanel panel; |
130 |
private JDynFormSet formset;
|
131 |
private FeatureStore store;
|
132 |
private FeaturePagingHelper ph;
|
133 |
private DynFormDefinition definition = null; |
134 |
private FeatureQuery currentQuery;
|
135 |
private final List<Action> otherActions; |
136 |
|
137 |
public DefaultJFeaturesForm() {
|
138 |
this.panel = new JPanel(new BorderLayout()); |
139 |
this.otherActions = new ArrayList<>(); |
140 |
} |
141 |
|
142 |
@Override
|
143 |
public void setPreferredSize(Dimension dimension) { |
144 |
// panel.setPreferredSize(dimension);
|
145 |
} |
146 |
|
147 |
private void updateForm() { |
148 |
if (this.formset == null) { |
149 |
this.panel.add(this.getFormset().asJComponent(), BorderLayout.CENTER); |
150 |
} |
151 |
try {
|
152 |
this.ph = DALLocator.getDataManager().createFeaturePagingHelper(store, this.currentQuery, PAGE_SIZE); |
153 |
this.formset.setValues(ph.asListOfDynObjects());
|
154 |
} catch (Exception ex) { |
155 |
throw new RuntimeException("Can't update form", ex); |
156 |
} |
157 |
} |
158 |
|
159 |
@Override
|
160 |
public JComponent asJComponent() { |
161 |
if (this.ph == null) { |
162 |
try {
|
163 |
updateForm(); |
164 |
} catch (Exception ex) { |
165 |
throw new RuntimeException(ex); |
166 |
} |
167 |
} |
168 |
return this.panel; |
169 |
} |
170 |
|
171 |
@Override
|
172 |
public void bind(FeatureStore store) { |
173 |
if (store == null) { |
174 |
throw new IllegalArgumentException("bind need a store as parameter, not a null."); |
175 |
} |
176 |
try {
|
177 |
DefaultDataSwingManager manager = (DefaultDataSwingManager) DALSwingLocator.getSwingManager(); |
178 |
DynClass theDefinition = manager.featureType2DynClass(store, store.getDefaultFeatureType()); |
179 |
this.bind(store, theDefinition);
|
180 |
} catch (Exception ex) { |
181 |
throw new RuntimeException("Can't bind store '" + store.getName() + "' to form", ex); |
182 |
} |
183 |
} |
184 |
|
185 |
public void bind(FeatureStore store, DynClass definition) throws ServiceException, DataException { |
186 |
if (this.store == store) { |
187 |
return;
|
188 |
} |
189 |
DynFormManager formManager = DynFormLocator.getDynFormManager(); |
190 |
this.definition = formManager.getDefinition(definition);
|
191 |
if (formset != null) { |
192 |
this.panel.remove(formset.asJComponent());
|
193 |
this.formset = null; |
194 |
} |
195 |
this.store = store;
|
196 |
this.ph = null; |
197 |
|
198 |
} |
199 |
|
200 |
@Override
|
201 |
public JDynFormSet getFormset() {
|
202 |
if (this.formset == null) { |
203 |
DynFormManager formManager = DynFormLocator.getDynFormManager(); |
204 |
this.formset = formManager.createJDynFormSet(
|
205 |
new DefaultFeaturesFormContext(),
|
206 |
this.definition,
|
207 |
null
|
208 |
); |
209 |
List<String> groups = this.definition.getGroups(); |
210 |
if( groups.size()==1 && groups.get(0)==null ) { |
211 |
this.formset.setLayoutMode(JDynForm.USE_PLAIN);
|
212 |
} else {
|
213 |
this.formset.setLayoutMode(JDynForm.USE_TABS);
|
214 |
} |
215 |
this.formset.setAllowNew(true); |
216 |
this.formset.setAllowDelete(true); |
217 |
this.formset.setAllowUpdate(true); |
218 |
this.formset.setAllowClose(true); |
219 |
this.formset.setAllowSearch(true); |
220 |
this.formset.setAutosave(true); |
221 |
|
222 |
this.formset.addAction(new StartEditingAction()); |
223 |
this.formset.addAction(new FinishEditingAction()); |
224 |
for( Action action : this.otherActions ) { |
225 |
this.formset.addAction(action);
|
226 |
} |
227 |
|
228 |
this.formset.addListener(new FormSetListener()); |
229 |
} |
230 |
if( this.store.isEditing() ) { |
231 |
this.formset.setReadOnly(false); |
232 |
formset.setActionVisible("startEditing", false); |
233 |
formset.setActionEnabled("startEditing", false); |
234 |
formset.setActionVisible("finishEditing", true); |
235 |
formset.setActionEnabled("finishEditing", true); |
236 |
} else {
|
237 |
this.formset.setReadOnly(true); |
238 |
formset.setActionVisible("startEditing", true); |
239 |
formset.setActionEnabled("startEditing", true); |
240 |
formset.setActionVisible("finishEditing", false); |
241 |
formset.setActionEnabled("finishEditing", false); |
242 |
} |
243 |
return this.formset; |
244 |
} |
245 |
|
246 |
@Override
|
247 |
public void addAction(Action action) { |
248 |
this.otherActions.add(action);
|
249 |
if( this.formset!=null ) { |
250 |
this.formset.addAction(action);
|
251 |
} |
252 |
} |
253 |
|
254 |
@Override
|
255 |
public long getCurrentIndex() { |
256 |
if( this.formset==null ) { |
257 |
return -1; |
258 |
} |
259 |
return this.formset.getCurrentIndex(); |
260 |
} |
261 |
|
262 |
@Override
|
263 |
public Feature get(long index) { |
264 |
if( this.formset==null || this.ph==null ) { |
265 |
return null; |
266 |
} |
267 |
try {
|
268 |
return this.ph.getFeatureAt(index); |
269 |
} catch (BaseException ex) {
|
270 |
return null; |
271 |
} |
272 |
} |
273 |
|
274 |
private class FinishEditingAction extends AbstractAction implements Observer { |
275 |
|
276 |
@SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) |
277 |
public FinishEditingAction() {
|
278 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
279 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
280 |
|
281 |
this.putValue(NAME,null); |
282 |
this.putValue(SHORT_DESCRIPTION,i18nManager.getTranslation("_Stop_editing")); |
283 |
this.putValue(SMALL_ICON, iconTheme.get("table-stop-editing")); |
284 |
this.putValue(ACTION_COMMAND_KEY, "finishEditing"); |
285 |
|
286 |
this.setEnabled(store.isEditing());
|
287 |
store.addObserver(this);
|
288 |
} |
289 |
|
290 |
@Override
|
291 |
public void actionPerformed(ActionEvent ae) { |
292 |
if( store.isEditing() ) {
|
293 |
try {
|
294 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
295 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
296 |
int x = dialogManager.confirmDialog(
|
297 |
"? Desea terminar edicion y guardar los cambios ?\n\nPulse cancelar para cancelar la edicion y los cambios.",
|
298 |
i18nManager.getTranslation("_Stop_editing"),
|
299 |
JOptionPane.YES_NO_CANCEL_OPTION,
|
300 |
JOptionPane.QUESTION_MESSAGE
|
301 |
); |
302 |
switch(x) {
|
303 |
case JOptionPane.YES_OPTION: |
304 |
store.finishEditing(); |
305 |
break;
|
306 |
case JOptionPane.NO_OPTION: |
307 |
break;
|
308 |
case JOptionPane.CANCEL_OPTION: |
309 |
store.cancelEditing(); |
310 |
break;
|
311 |
} |
312 |
} catch (DataException ex) {
|
313 |
LOGGER.warn("Can't finish editing in FeatureForm ("+store.getName()+").",ex); |
314 |
} |
315 |
} |
316 |
} |
317 |
|
318 |
@Override
|
319 |
public void update(Observable observable, Object notification) { |
320 |
if( notification instanceof FeatureStoreNotification ) { |
321 |
FeatureStoreNotification n = (FeatureStoreNotification) notification; |
322 |
switch( n.getType() ) {
|
323 |
case FeatureStoreNotification.AFTER_STARTEDITING:
|
324 |
case FeatureStoreNotification.AFTER_FINISHEDITING:
|
325 |
case FeatureStoreNotification.AFTER_CANCELEDITING:
|
326 |
if( store.isEditing() ) {
|
327 |
formset.setReadOnly(false);
|
328 |
formset.setActionVisible("finishEditing", true); |
329 |
formset.setActionEnabled("finishEditing", true); |
330 |
} else {
|
331 |
formset.setReadOnly(true);
|
332 |
formset.setActionVisible("finishEditing", false); |
333 |
formset.setActionEnabled("finishEditing", false); |
334 |
} |
335 |
break;
|
336 |
} |
337 |
} |
338 |
} |
339 |
|
340 |
} |
341 |
|
342 |
private class StartEditingAction extends AbstractAction implements Observer { |
343 |
|
344 |
@SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) |
345 |
public StartEditingAction() {
|
346 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
347 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
348 |
|
349 |
this.putValue(NAME,null); |
350 |
this.putValue(SHORT_DESCRIPTION,i18nManager.getTranslation("_Start_editing")); |
351 |
this.putValue(SMALL_ICON, iconTheme.get("table-start-editing")); |
352 |
this.putValue(ACTION_COMMAND_KEY, "startEditing"); |
353 |
|
354 |
this.setEnabled(!store.isEditing());
|
355 |
store.addObserver(this);
|
356 |
} |
357 |
|
358 |
@Override
|
359 |
public void actionPerformed(ActionEvent ae) { |
360 |
if( !store.isEditing() ) {
|
361 |
try {
|
362 |
store.edit(); |
363 |
} catch (DataException ex) {
|
364 |
LOGGER.warn("Can't finish editing in FeatureForm ("+store.getName()+").",ex); |
365 |
} |
366 |
} |
367 |
} |
368 |
|
369 |
@Override
|
370 |
public void update(Observable observable, Object notification) { |
371 |
if( notification instanceof FeatureStoreNotification ) { |
372 |
FeatureStoreNotification n = (FeatureStoreNotification) notification; |
373 |
switch( n.getType() ) {
|
374 |
case FeatureStoreNotification.AFTER_STARTEDITING:
|
375 |
case FeatureStoreNotification.AFTER_FINISHEDITING:
|
376 |
case FeatureStoreNotification.AFTER_CANCELEDITING:
|
377 |
if( store.isEditing() ) {
|
378 |
formset.setReadOnly(false);
|
379 |
formset.setActionVisible("startEditing", false); |
380 |
formset.setActionEnabled("startEditing", false); |
381 |
} else {
|
382 |
formset.setReadOnly(true);
|
383 |
formset.setActionVisible("startEditing", true); |
384 |
formset.setActionEnabled("startEditing", true); |
385 |
} |
386 |
break;
|
387 |
} |
388 |
} |
389 |
} |
390 |
|
391 |
} |
392 |
|
393 |
@Override
|
394 |
public void setQuery(FeatureQuery query) { |
395 |
if (this.ph != null) { |
396 |
if (this.formset != null && !formset.isReadOnly() && this.formset.isAutosave() && this.formset.countValues() > 0) { |
397 |
if (!store.isEditing()) {
|
398 |
try {
|
399 |
store.edit(); |
400 |
} catch (DataException e1) {
|
401 |
throw new RuntimeException("Can't set query", e1); |
402 |
} |
403 |
} |
404 |
saveChanges(this.formset);
|
405 |
} |
406 |
} |
407 |
this.currentQuery = query;
|
408 |
updateForm(); |
409 |
} |
410 |
|
411 |
private FeatureQuery getCurrentQuery() {
|
412 |
return this.currentQuery; |
413 |
} |
414 |
|
415 |
@Override
|
416 |
public void showForm(MODE mode) { |
417 |
this.panel.add(this.getFormset().asJComponent(), BorderLayout.CENTER); |
418 |
WindowManager winmgr = ToolsSwingLocator.getWindowManager(); |
419 |
String title = this.definition.getLabel(); |
420 |
winmgr.showWindow(this.asJComponent(), title, mode);
|
421 |
} |
422 |
|
423 |
private void saveChanges(JDynFormSet dynformSet) { |
424 |
if( dynformSet.isInNewState() ) {
|
425 |
Feature feat = null;
|
426 |
try {
|
427 |
feat = store.createNewFeature(false);
|
428 |
} catch (DataException ex) {
|
429 |
LOGGER.warn("Can't create new feature.",ex);
|
430 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
431 |
dynformSet.message(i18nManager.getTranslation("error_saving_data_will_not_save"));
|
432 |
throw new RuntimeException("Can't new save values"); |
433 |
} |
434 |
DynObject dynObject = feat.getAsDynObject(); |
435 |
dynformSet.getFormValues(dynObject); |
436 |
try {
|
437 |
ph.insert(((FacadeOfAFeature)dynObject).getEditableFeature()); |
438 |
} catch (BaseException e) {
|
439 |
throw new RuntimeException("Can't save values", e); |
440 |
} |
441 |
try {
|
442 |
this.formset.setValues(ph.asListOfDynObjects());
|
443 |
this.formset.setCurrentIndex((int)(ph.getTotalSize())-1); |
444 |
} catch(Exception ex) { |
445 |
LOGGER.warn("Can't reload form data after insert.",ex);
|
446 |
} |
447 |
} else {
|
448 |
int index = dynformSet.getCurrentIndex();
|
449 |
DynObject dynObject = dynformSet.get(index); |
450 |
|
451 |
if ( !(dynObject instanceof FacadeOfAFeature) ) { |
452 |
LOGGER.warn("Can't get the associated feature index " + index);
|
453 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
454 |
dynformSet.message(i18nManager.getTranslation("error_saving_data_will_not_save"));
|
455 |
throw new RuntimeException("Can't save values"); |
456 |
} |
457 |
dynformSet.getFormValues(dynObject); |
458 |
try {
|
459 |
ph.update(((FacadeOfAFeature)dynObject).getEditableFeature()); |
460 |
} catch (BaseException e) {
|
461 |
throw new RuntimeException("Can't save values", e); |
462 |
} |
463 |
} |
464 |
|
465 |
} |
466 |
|
467 |
@Override
|
468 |
public void saveChanges() { |
469 |
if (this.formset != null && this.formset.countValues() > 0) { |
470 |
if (store != null && !store.isEditing()) { |
471 |
try {
|
472 |
store.edit(); |
473 |
} catch (DataException e1) {
|
474 |
LOGGER.warn("Can't edit the store " + store.getName());
|
475 |
throw new RuntimeException("Can't save changes.", e1); |
476 |
} |
477 |
} |
478 |
this.saveChanges(this.formset); |
479 |
} |
480 |
} |
481 |
|
482 |
@Override
|
483 |
public long getDataSetSize() { |
484 |
if (this.ph != null) { |
485 |
return ph.getTotalSize();
|
486 |
} |
487 |
return 0; |
488 |
} |
489 |
|
490 |
@Override
|
491 |
public FeatureStore getFeatureStore() {
|
492 |
return this.store; |
493 |
} |
494 |
|
495 |
private class FormSetListener implements JDynFormSetListener { |
496 |
|
497 |
@Override
|
498 |
public void formMessage(String message) { |
499 |
} |
500 |
|
501 |
@Override
|
502 |
public void formClose() { |
503 |
panel.setVisible(false);
|
504 |
} |
505 |
|
506 |
@Override
|
507 |
public void formMovedTo(int currentPosition) throws AbortActionException { |
508 |
LOGGER.trace("formMovedTo " + currentPosition);
|
509 |
} |
510 |
|
511 |
@Override
|
512 |
public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException { |
513 |
LOGGER.trace("formBeforeSave");
|
514 |
if (!store.isEditing()) {
|
515 |
try {
|
516 |
store.edit(); |
517 |
} catch (DataException e1) {
|
518 |
throw new StoreEditException(e1, store.getName()); |
519 |
} |
520 |
} |
521 |
} |
522 |
|
523 |
@Override
|
524 |
public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException { |
525 |
LOGGER.trace("formBeforeNew");
|
526 |
} |
527 |
|
528 |
@Override
|
529 |
public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException { |
530 |
LOGGER.trace("formBeforeDelete");
|
531 |
} |
532 |
|
533 |
@Override
|
534 |
public void formAfterSave(JDynFormSet dynformSet) throws AbortActionException { |
535 |
LOGGER.trace("formAfterSave");
|
536 |
saveChanges(dynformSet); |
537 |
} |
538 |
|
539 |
@Override
|
540 |
public void formAfterNew(JDynFormSet dynformSet) throws AbortActionException { |
541 |
LOGGER.trace("formAfterNew");
|
542 |
} |
543 |
|
544 |
@Override
|
545 |
public void formAfterDelete(JDynFormSet dynformSet) throws AbortActionException { |
546 |
LOGGER.trace("formAfterDelete");
|
547 |
} |
548 |
|
549 |
@Override
|
550 |
public void formBeforeSearch(JDynFormSet dynformSet) throws AbortActionException { |
551 |
LOGGER.trace("formBeforeSearch");
|
552 |
DataSwingManager dataSwingmanager = DALSwingLocator.getSwingManager(); |
553 |
WindowManager_v2 winmgr = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
554 |
|
555 |
JExpressionBuilder builder = dataSwingmanager.createQueryFilterExpresion(store); |
556 |
FeatureQuery currentQuery = getCurrentQuery(); |
557 |
if( currentQuery!=null ) { |
558 |
Evaluator filter = currentQuery.getFilter(); |
559 |
if( filter instanceof ExpressionEvaluator ) { |
560 |
Expression expression = ((ExpressionEvaluator)filter).getExpression();
|
561 |
builder.setExpression(expression); |
562 |
} |
563 |
} |
564 |
Dialog dialog = winmgr.createDialog(
|
565 |
builder.asJComponent(), |
566 |
"Filtro",
|
567 |
"Creacion de filtro sobre '"+store.getName()+"'", |
568 |
WindowManager_v2.BUTTONS_OK_CANCEL |
569 |
); |
570 |
dialog.show(WindowManager.MODE.DIALOG); |
571 |
if( dialog.getAction() == WindowManager_v2.BUTTON_OK ) {
|
572 |
Expression expresion = builder.getExpression();
|
573 |
try {
|
574 |
FeatureQuery query = store.createFeatureQuery(); |
575 |
if( ExpressionUtils.isPhraseEmpty(expresion) ) {
|
576 |
query.clearFilter(); |
577 |
} else {
|
578 |
query.setFilter(expresion); |
579 |
} |
580 |
setQuery(query); |
581 |
} catch (Exception ex) { |
582 |
LOGGER.warn("Can't apply filter '" + expresion + "'.", ex); |
583 |
} |
584 |
} |
585 |
} |
586 |
|
587 |
@Override
|
588 |
public void formAfterSearch(JDynFormSet dynformSet) throws AbortActionException { |
589 |
LOGGER.trace("formAfterSearch");
|
590 |
} |
591 |
|
592 |
@Override
|
593 |
public void formBeforeCancelNew(JDynFormSet dynformSet) throws AbortActionException { |
594 |
LOGGER.trace("formBeforeCancelNew");
|
595 |
} |
596 |
|
597 |
@Override
|
598 |
public void formAfterCancelNew(JDynFormSet dynformSet) throws AbortActionException { |
599 |
LOGGER.trace("formAfterCancelNew");
|
600 |
} |
601 |
} |
602 |
|
603 |
private static class StoreEditException extends AbortActionException { |
604 |
|
605 |
/**
|
606 |
*
|
607 |
*/
|
608 |
private static final long serialVersionUID = -7682017811778577130L; |
609 |
|
610 |
public StoreEditException(Throwable cause, String storename) { |
611 |
super("Can't edit the store '%(storename)'", cause, "cant_edit_the store_XstorenameX", serialVersionUID); |
612 |
setValue("storename", storename);
|
613 |
} |
614 |
} |
615 |
} |