Statistics
| Revision:

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 @ 44253

History | View | Annotate | Download (22.9 KB)

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