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

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 44259 jjdelcerro
        @Override
107 44253 jjdelcerro
        public FeatureStore getFeatureStore(String storeName) {
108
            return (FeatureStore) this.getDataStore(storeName);
109
        }
110
111 44259 jjdelcerro
        @Override
112 44253 jjdelcerro
        public DataStore getDataStore(String storeName) {
113 44259 jjdelcerro
            FeatureStore theStore = (FeatureStore) store.getChildren().get(storeName);
114 44253 jjdelcerro
            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 42775 jjdelcerro
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJFeaturesForm.class);
127 42112 jjdelcerro
128
    private static final int PAGE_SIZE = 500;
129 42489 jjdelcerro
    private final JPanel panel;
130 42112 jjdelcerro
    private JDynFormSet formset;
131
    private FeatureStore store;
132
    private FeaturePagingHelper ph;
133 44128 jjdelcerro
    private DynFormDefinition definition = null;
134 42248 jjdelcerro
    private FeatureQuery currentQuery;
135 44128 jjdelcerro
    private final List<Action> otherActions;
136 42714 dmartinezizquierdo
137 42775 jjdelcerro
    public DefaultJFeaturesForm() {
138 42112 jjdelcerro
        this.panel = new JPanel(new BorderLayout());
139 42489 jjdelcerro
        this.otherActions = new ArrayList<>();
140 42112 jjdelcerro
    }
141
142 42489 jjdelcerro
    @Override
143 42112 jjdelcerro
    public void setPreferredSize(Dimension dimension) {
144 44253 jjdelcerro
//        panel.setPreferredSize(dimension);
145 42112 jjdelcerro
    }
146
147 42489 jjdelcerro
    private void updateForm() {
148 42473 fdiaz
        if (this.formset == null) {
149
            this.panel.add(this.getFormset().asJComponent(), BorderLayout.CENTER);
150 42248 jjdelcerro
        }
151 42489 jjdelcerro
        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 42248 jjdelcerro
    }
158 42473 fdiaz
159 42489 jjdelcerro
    @Override
160 42112 jjdelcerro
    public JComponent asJComponent() {
161 42248 jjdelcerro
        if (this.ph == null) {
162
            try {
163
                updateForm();
164
            } catch (Exception ex) {
165
                throw new RuntimeException(ex);
166
            }
167 42473 fdiaz
        }
168 42112 jjdelcerro
        return this.panel;
169
    }
170
171 42489 jjdelcerro
    @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 44202 jjdelcerro
            DefaultDataSwingManager manager = (DefaultDataSwingManager) DALSwingLocator.getSwingManager();
178
            DynClass theDefinition = manager.featureType2DynClass(store, store.getDefaultFeatureType());
179
            this.bind(store, theDefinition);
180 42489 jjdelcerro
        } catch (Exception ex) {
181
            throw new RuntimeException("Can't bind store '" + store.getName() + "' to form", ex);
182
        }
183 42112 jjdelcerro
    }
184 42473 fdiaz
185 42112 jjdelcerro
    public void bind(FeatureStore store, DynClass definition) throws ServiceException, DataException {
186
        if (this.store == store) {
187
            return;
188
        }
189 44128 jjdelcerro
        DynFormManager formManager = DynFormLocator.getDynFormManager();
190 44202 jjdelcerro
        this.definition = formManager.getDefinition(definition);
191 42112 jjdelcerro
        if (formset != null) {
192
            this.panel.remove(formset.asJComponent());
193
            this.formset = null;
194
        }
195
        this.store = store;
196
        this.ph = null;
197 44128 jjdelcerro
198 42112 jjdelcerro
    }
199
200 42489 jjdelcerro
    @Override
201
    public JDynFormSet getFormset() {
202 42473 fdiaz
        if (this.formset == null) {
203 42112 jjdelcerro
            DynFormManager formManager = DynFormLocator.getDynFormManager();
204 44253 jjdelcerro
            this.formset = formManager.createJDynFormSet(
205
                    new DefaultFeaturesFormContext(),
206
                    this.definition,
207
                    null
208
            );
209 44202 jjdelcerro
            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 42112 jjdelcerro
            this.formset.setAllowClose(true);
219 42489 jjdelcerro
            this.formset.setAllowSearch(true);
220 42112 jjdelcerro
            this.formset.setAutosave(true);
221 42714 dmartinezizquierdo
222 44202 jjdelcerro
            this.formset.addAction(new StartEditingAction());
223 42489 jjdelcerro
            this.formset.addAction(new FinishEditingAction());
224
            for( Action action : this.otherActions ) {
225
                this.formset.addAction(action);
226
            }
227 42714 dmartinezizquierdo
228 42489 jjdelcerro
            this.formset.addListener(new FormSetListener());
229 42112 jjdelcerro
        }
230 44202 jjdelcerro
        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 42112 jjdelcerro
        return this.formset;
244
    }
245
246 42489 jjdelcerro
    @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 42714 dmartinezizquierdo
274 42489 jjdelcerro
    private class FinishEditingAction extends AbstractAction implements Observer {
275
276 44128 jjdelcerro
        @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
277 42489 jjdelcerro
        public FinishEditingAction() {
278 42714 dmartinezizquierdo
            I18nManager i18nManager = ToolsLocator.getI18nManager();
279 42489 jjdelcerro
            IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault();
280 42714 dmartinezizquierdo
281 42489 jjdelcerro
            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 42714 dmartinezizquierdo
290 42489 jjdelcerro
        @Override
291
        public void actionPerformed(ActionEvent ae) {
292
            if( store.isEditing() ) {
293
                try {
294 42714 dmartinezizquierdo
                    I18nManager i18nManager = ToolsLocator.getI18nManager();
295 42489 jjdelcerro
                    ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager();
296
                    int x = dialogManager.confirmDialog(
297 42714 dmartinezizquierdo
                            "? Desea terminar edicion y guardar los cambios ?\n\nPulse cancelar para cancelar la edicion y los cambios.",
298 42489 jjdelcerro
                            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 44202 jjdelcerro
                    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 42489 jjdelcerro
                        break;
336 44202 jjdelcerro
                }
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 42489 jjdelcerro
                    case FeatureStoreNotification.AFTER_FINISHEDITING:
376
                    case FeatureStoreNotification.AFTER_CANCELEDITING:
377 44202 jjdelcerro
                        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 42489 jjdelcerro
                        break;
387
                }
388
            }
389
        }
390 42714 dmartinezizquierdo
391 42489 jjdelcerro
    }
392
393
    @Override
394
    public void setQuery(FeatureQuery query) {
395 42112 jjdelcerro
        if (this.ph != null) {
396 44239 jjdelcerro
            if (this.formset != null && !formset.isReadOnly() && this.formset.isAutosave() && this.formset.countValues() > 0) {
397 42112 jjdelcerro
                if (!store.isEditing()) {
398
                    try {
399
                        store.edit();
400
                    } catch (DataException e1) {
401 42489 jjdelcerro
                        throw new RuntimeException("Can't set query", e1);
402 42112 jjdelcerro
                    }
403
                }
404
                saveChanges(this.formset);
405
            }
406
        }
407 42248 jjdelcerro
        this.currentQuery = query;
408
        updateForm();
409 42112 jjdelcerro
    }
410
411 44239 jjdelcerro
    private FeatureQuery getCurrentQuery() {
412
        return this.currentQuery;
413
    }
414
415 42489 jjdelcerro
    @Override
416
    public void showForm(MODE mode) {
417 42248 jjdelcerro
        this.panel.add(this.getFormset().asJComponent(), BorderLayout.CENTER);
418
        WindowManager winmgr = ToolsSwingLocator.getWindowManager();
419 44202 jjdelcerro
        String title = this.definition.getLabel();
420 42775 jjdelcerro
        winmgr.showWindow(this.asJComponent(), title, mode);
421 42112 jjdelcerro
    }
422
423 42489 jjdelcerro
    private void saveChanges(JDynFormSet dynformSet) {
424 42775 jjdelcerro
        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 42489 jjdelcerro
        }
464 42112 jjdelcerro
465
    }
466
467 42489 jjdelcerro
    @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 42112 jjdelcerro
            }
478 42489 jjdelcerro
            this.saveChanges(this.formset);
479 42112 jjdelcerro
        }
480
    }
481
482 42489 jjdelcerro
    @Override
483
    public long getDataSetSize() {
484
        if (this.ph != null) {
485
            return ph.getTotalSize();
486
        }
487
        return 0;
488 42112 jjdelcerro
    }
489
490 42489 jjdelcerro
    @Override
491
    public FeatureStore getFeatureStore() {
492
        return this.store;
493 42112 jjdelcerro
    }
494
495 42489 jjdelcerro
    private class FormSetListener implements JDynFormSetListener {
496 42112 jjdelcerro
497 42489 jjdelcerro
        @Override
498
        public void formMessage(String message) {
499
        }
500 42112 jjdelcerro
501 42489 jjdelcerro
        @Override
502
        public void formClose() {
503
            panel.setVisible(false);
504 42112 jjdelcerro
        }
505
506 42489 jjdelcerro
        @Override
507
        public void formMovedTo(int currentPosition) throws AbortActionException {
508
            LOGGER.trace("formMovedTo " + currentPosition);
509
        }
510 42112 jjdelcerro
511 42489 jjdelcerro
        @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 42112 jjdelcerro
523 44259 jjdelcerro
        @Override
524 42489 jjdelcerro
        public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException {
525
            LOGGER.trace("formBeforeNew");
526 42112 jjdelcerro
        }
527
528 44259 jjdelcerro
        @Override
529 42489 jjdelcerro
        public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException {
530
            LOGGER.trace("formBeforeDelete");
531
        }
532 42112 jjdelcerro
533 42489 jjdelcerro
        @Override
534
        public void formAfterSave(JDynFormSet dynformSet) throws AbortActionException {
535
            LOGGER.trace("formAfterSave");
536
            saveChanges(dynformSet);
537
        }
538 42112 jjdelcerro
539 42489 jjdelcerro
        @Override
540
        public void formAfterNew(JDynFormSet dynformSet) throws AbortActionException {
541
            LOGGER.trace("formAfterNew");
542 42112 jjdelcerro
        }
543
544 42489 jjdelcerro
        @Override
545
        public void formAfterDelete(JDynFormSet dynformSet) throws AbortActionException {
546
            LOGGER.trace("formAfterDelete");
547 42112 jjdelcerro
        }
548
549 42489 jjdelcerro
        @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 42714 dmartinezizquierdo
555 44128 jjdelcerro
            JExpressionBuilder builder = dataSwingmanager.createQueryFilterExpresion(store);
556 44239 jjdelcerro
            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 42489 jjdelcerro
            Dialog dialog = winmgr.createDialog(
565 44128 jjdelcerro
                    builder.asJComponent(),
566 42714 dmartinezizquierdo
                    "Filtro",
567
                    "Creacion de filtro sobre '"+store.getName()+"'",
568 42489 jjdelcerro
                    WindowManager_v2.BUTTONS_OK_CANCEL
569
            );
570
            dialog.show(WindowManager.MODE.DIALOG);
571
            if( dialog.getAction() == WindowManager_v2.BUTTON_OK ) {
572 44128 jjdelcerro
                Expression expresion = builder.getExpression();
573 42112 jjdelcerro
                try {
574 42489 jjdelcerro
                    FeatureQuery query = store.createFeatureQuery();
575 44239 jjdelcerro
                    if( ExpressionUtils.isPhraseEmpty(expresion) ) {
576
                        query.clearFilter();
577
                    } else {
578 44128 jjdelcerro
                        query.setFilter(expresion);
579 42489 jjdelcerro
                    }
580
                    setQuery(query);
581
                } catch (Exception ex) {
582
                    LOGGER.warn("Can't apply filter '" + expresion + "'.", ex);
583 42112 jjdelcerro
                }
584
            }
585
        }
586
587 42489 jjdelcerro
        @Override
588
        public void formAfterSearch(JDynFormSet dynformSet) throws AbortActionException {
589
            LOGGER.trace("formAfterSearch");
590
        }
591 42775 jjdelcerro
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 42112 jjdelcerro
    }
602
603 42489 jjdelcerro
    private static class StoreEditException extends AbortActionException {
604 42112 jjdelcerro
605 42489 jjdelcerro
        /**
606
         *
607
         */
608
        private static final long serialVersionUID = -7682017811778577130L;
609 42112 jjdelcerro
610 42489 jjdelcerro
        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 42112 jjdelcerro
        }
614
    }
615
}