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

History | View | Annotate | Download (25.4 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.awt.event.ComponentAdapter;
29
import java.awt.event.ComponentEvent;
30
import java.util.ArrayList;
31
import java.util.Collection;
32
import java.util.List;
33
import javax.swing.AbstractAction;
34
import javax.swing.Action;
35
import static javax.swing.Action.ACTION_COMMAND_KEY;
36
import static javax.swing.Action.NAME;
37
import static javax.swing.Action.SHORT_DESCRIPTION;
38
import static javax.swing.Action.SMALL_ICON;
39

    
40
import javax.swing.JComponent;
41
import javax.swing.JOptionPane;
42
import javax.swing.JPanel;
43
import org.apache.commons.lang3.StringUtils;
44
import org.gvsig.expressionevaluator.Expression;
45
import org.gvsig.expressionevaluator.ExpressionUtils;
46
import org.gvsig.expressionevaluator.swing.JExpressionBuilder;
47

    
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

    
51
import org.gvsig.featureform.swing.JFeaturesForm;
52
import org.gvsig.fmap.dal.DALLocator;
53
import org.gvsig.fmap.dal.DataStore;
54
import org.gvsig.fmap.dal.StoresRepository;
55
import org.gvsig.fmap.dal.exception.DataException;
56
import org.gvsig.fmap.dal.expressionevaluator.ExpressionEvaluator;
57
import org.gvsig.fmap.dal.feature.Feature;
58
import org.gvsig.fmap.dal.feature.FacadeOfAFeature;
59
import org.gvsig.fmap.dal.feature.FeatureQuery;
60
import org.gvsig.fmap.dal.feature.FeatureStore;
61
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
62
import org.gvsig.fmap.dal.feature.FeatureType;
63
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper;
64
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory.AbstractDALActionContext;
65
import org.gvsig.fmap.dal.swing.DALActionFactory;
66
import org.gvsig.fmap.dal.swing.DALSwingLocator;
67
import org.gvsig.fmap.dal.swing.DataSwingManager;
68
import org.gvsig.fmap.dal.swing.impl.DefaultDataSwingManager;
69
import org.gvsig.fmap.dal.swing.impl.actions.ShowFormAction.ShowFormActionFactory;
70
import org.gvsig.tools.ToolsLocator;
71
import org.gvsig.tools.dispose.DisposeUtils;
72
import org.gvsig.tools.dynform.AbortActionException;
73
import org.gvsig.tools.dynform.DynFormDefinition;
74
import org.gvsig.tools.dynform.DynFormLocator;
75
import org.gvsig.tools.dynform.DynFormManager;
76
import org.gvsig.tools.dynform.JDynForm;
77
import org.gvsig.tools.dynform.JDynFormSet;
78
import org.gvsig.tools.dynform.JDynFormSet.JDynFormSetListener;
79
import org.gvsig.tools.dynobject.DynClass;
80
import org.gvsig.tools.dynobject.DynObject;
81
import org.gvsig.tools.evaluator.Evaluator;
82
import org.gvsig.tools.exception.BaseException;
83
import org.gvsig.tools.i18n.I18nManager;
84
import org.gvsig.tools.observer.Observable;
85
import org.gvsig.tools.observer.Observer;
86
import org.gvsig.tools.service.ServiceException;
87
import org.gvsig.tools.swing.api.ToolsSwingLocator;
88
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
89
import org.gvsig.tools.swing.api.windowmanager.Dialog;
90
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
91
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
92
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
93
import org.gvsig.tools.swing.icontheme.IconTheme;
94
import org.gvsig.tools.util.ResourcesStorage;
95

    
96
/**
97
 * @author fdiaz
98
 *
99
 */
100
@SuppressWarnings("UseSpecificCatch")
101
public class DefaultJFeaturesForm implements JFeaturesForm {
102

    
103
    public class DefaultFeaturesFormContext implements FeaturesFormContext {
104

    
105
        private DefaultFeaturesFormContext() {
106
            
107
        }
108

    
109
        public FeatureStore getFeatureStore() {
110
            return store;
111
        }
112
        
113
        @Override
114
        public FeatureType getFeatureType() {
115
            try {
116
                return store.getDefaultFeatureType();
117
            } catch (DataException ex) {
118
                return null;
119
            }
120
        }
121
        
122
        @Override
123
        public ResourcesStorage getResourcesStorage() {
124
            return store.getResourcesStorage();
125
        }
126

    
127
        @Override
128
        public StoresRepository getStoresRepository() {
129
            return store.getStoresRepository();
130
        }
131
        
132
    }
133
    
134
    private class FormActionContext extends AbstractDALActionContext {
135

    
136
        public FormActionContext() {
137
            super(ACTION_CONTEXT_NAME);
138
        }
139
        
140
        @Override
141
        public DataStore getStore() {
142
            return store;
143
        }
144

    
145
        @Override
146
        public Expression getFilter() {
147
            FeatureQuery theCurrentQuery = currentQuery;
148
            if( theCurrentQuery!=null ) {
149
                Evaluator filter = theCurrentQuery.getFilter();
150
                if( filter instanceof ExpressionEvaluator ) {
151
                    Expression expression = ((ExpressionEvaluator)filter).getExpression();
152
                    return expression;
153
                }
154
            }
155
            return null;
156
        }
157

    
158
        @Override
159
        public int getSelectedsCount() {
160
            return 0;
161
        }
162

    
163
        @Override
164
        public Expression getFilterForSelecteds() {
165
            return null;
166
        }
167

    
168
        @Override
169
        public JComponent getActionButton(String actionName) {
170
            if( formset == null ) {
171
                return null;
172
            }
173
            return formset.getActionButton(actionName);
174
        }
175
        
176
    }
177
    
178
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJFeaturesForm.class);
179

    
180
    private static final int PAGE_SIZE = 500;
181
    private JPanel panel;
182
    private JDynFormSet formset;
183
    private FeatureStore store;
184
    private FeaturePagingHelper ph;
185
    private DynFormDefinition definition = null;
186
    private FeatureQuery currentQuery;
187
    private List<Action> otherActions;
188

    
189
    public DefaultJFeaturesForm() {
190
        this.otherActions = new ArrayList<>();
191
        this.panel = new JPanel(new BorderLayout());
192
        this.panel.addComponentListener(new ComponentAdapter() {
193
            @Override
194
            public void componentHidden(ComponentEvent e) {
195
                doDispose();
196
            }
197
        });
198
    }
199

    
200
    @Override
201
    public void setPreferredSize(Dimension dimension) {
202
//        panel.setPreferredSize(dimension);
203
    }
204

    
205
    private void updateForm() {
206
        if (this.formset == null) {
207
            this.panel.add(this.getFormset().asJComponent(), BorderLayout.CENTER);
208
        }
209
        try {
210
            if( this.currentQuery!=null ) {
211
                this.currentQuery.retrievesAllAttributes();
212
            }
213
            this.ph = DALLocator.getDataManager().createFeaturePagingHelper(store, this.currentQuery, PAGE_SIZE);
214
            this.formset.setValues(ph.asListOfDynObjects());
215
        } catch (Exception ex) {
216
            throw new RuntimeException("Can't update form", ex);
217
        }
218
    }
219

    
220
    @Override
221
    public JComponent asJComponent() {
222
        if (this.ph == null) {
223
            try {
224
                updateForm();
225
            } catch (Exception ex) {
226
                throw new RuntimeException(ex);
227
            }
228
        }
229
        return this.panel;
230
    }
231

    
232
    @Override
233
    public void bind(FeatureStore store) {
234
        if (store == null) {
235
            throw new IllegalArgumentException("bind need a store as parameter, not a null.");
236
        }
237
        try {
238
            DefaultDataSwingManager manager = (DefaultDataSwingManager) DALSwingLocator.getSwingManager();
239
            DynClass theDefinition = manager.featureType2DynClass(store, store.getDefaultFeatureType());
240
            this.bind(store, theDefinition);
241
        } catch (Exception ex) {
242
            throw new RuntimeException("Can't bind store '" + store.getName() + "' to form", ex);
243
        }
244
    }
245

    
246
    public void bind(FeatureStore store, DynClass definition) throws ServiceException, DataException {
247
        if (this.store == store) {
248
            return;
249
        }
250
        DynFormManager formManager = DynFormLocator.getDynFormManager();
251
        this.definition = formManager.getDefinition(definition);
252
        if (formset != null) {
253
            this.panel.remove(formset.asJComponent());
254
            this.formset = null;
255
        }
256
        this.store = store;
257
        DisposeUtils.bind(store);
258
        this.ph = null;
259
    }
260

    
261
    private void doDispose() {
262
        DisposeUtils.disposeQuietly(store);
263
        this.store = null;
264
        this.panel = null;
265
        this.formset = null;
266
        this.ph = null;
267
        this.definition = null;
268
        this.currentQuery = null;
269
        this.otherActions = null;
270
    }
271
    
272
    @Override
273
    public JDynFormSet getFormset() {
274
        if (this.formset == null) {
275
            DynFormManager formManager = DynFormLocator.getDynFormManager();
276
            this.formset = formManager.createJDynFormSet(
277
                    new DefaultFeaturesFormContext(),
278
                    this.definition,
279
                    null
280
            );
281
            List<String> groups = this.definition.getGroups();
282
            if( groups.size()==1 && groups.get(0)==null ) {
283
                this.formset.setLayoutMode(JDynForm.USE_PLAIN);
284
            } else {
285
                this.formset.setLayoutMode(JDynForm.USE_TABS);
286
            }
287
            this.formset.setAllowNew(true);
288
            this.formset.setAllowDelete(true);
289
            this.formset.setAllowUpdate(true);
290
            this.formset.setAllowClose(true);
291
            this.formset.setAllowSearch(true);
292
            this.formset.setAutosave(true);
293

    
294
            this.formset.addAction(new StartEditingAction());
295
            this.formset.addAction(new FinishEditingAction());
296
            
297
            FormActionContext actionContext = new FormActionContext();
298
            Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions();
299
            for (DALActionFactory factory : factories) {
300
                if( StringUtils.equalsIgnoreCase(factory.getName(), ShowFormActionFactory.ACTION_NAME) ) {
301
                    continue;
302
                }
303
                Action action = factory.createAction(actionContext);
304
                this.formset.addAction(action);
305
            }            
306
            for( Action action : this.otherActions ) {
307
                this.formset.addAction(action);
308
            }
309

    
310
            this.formset.addListener(new FormSetListener());
311
        }
312
        if( this.store.isEditing() ) {
313
//            this.formset.setReadOnly(false);
314
            formset.setActionVisible("startEditing", false);
315
            formset.setActionEnabled("startEditing", false);
316
            formset.setActionVisible("finishEditing", true);
317
            formset.setActionEnabled("finishEditing", true);
318
        } else {
319
//            this.formset.setReadOnly(true);
320
            formset.setActionVisible("startEditing", true);
321
            formset.setActionEnabled("startEditing", true);
322
            formset.setActionVisible("finishEditing", false);
323
            formset.setActionEnabled("finishEditing", false);
324
        }
325
        return this.formset;
326
    }
327

    
328
    @Override
329
    public void addAction(Action action) {
330
        this.otherActions.add(action);
331
        if( this.formset!=null ) {
332
            this.formset.addAction(action);
333
        }
334
    }
335

    
336
    @Override
337
    public long getCurrentIndex() {
338
        if( this.formset==null ) {
339
            return -1;
340
        }
341
        return this.formset.getCurrentIndex();
342
    }
343

    
344
    @Override
345
    public Feature get(long index) {
346
        if( this.formset==null || this.ph==null ) {
347
            return null;
348
        }
349
        try {
350
            return this.ph.getFeatureAt(index);
351
        } catch (BaseException ex) {
352
            return null;
353
        }
354
    }
355

    
356
    private class FinishEditingAction extends AbstractAction implements Observer {
357

    
358
        @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
359
        public FinishEditingAction() {
360
            I18nManager i18nManager = ToolsLocator.getI18nManager();
361
            IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault();
362

    
363
            this.putValue(NAME,null);
364
            this.putValue(SHORT_DESCRIPTION,i18nManager.getTranslation("_Stop_editing"));
365
            this.putValue(SMALL_ICON, iconTheme.get("table-stop-editing"));
366
            this.putValue(ACTION_COMMAND_KEY, "finishEditing");
367

    
368
            this.setEnabled(store.isEditing());
369
            store.addObserver(this);
370
        }
371

    
372
        @Override
373
        public void actionPerformed(ActionEvent ae) {
374
            if( store.isEditing() ) {
375
                try {
376
                    I18nManager i18nManager = ToolsLocator.getI18nManager();
377
                    ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager();
378
                    int x = dialogManager.confirmDialog(
379
                            "? Desea terminar edicion y guardar los cambios ?\n\nPulse cancelar para cancelar la edicion y los cambios.",
380
                            i18nManager.getTranslation("_Stop_editing"),
381
                            JOptionPane.YES_NO_CANCEL_OPTION,
382
                            JOptionPane.QUESTION_MESSAGE
383
                    );
384
                    switch(x) {
385
                        case JOptionPane.YES_OPTION:
386
                            store.finishEditing();
387
                            break;
388
                        case JOptionPane.NO_OPTION:
389
                            break;
390
                        case JOptionPane.CANCEL_OPTION:
391
                            store.cancelEditing();
392
                            break;
393
                    }
394
                } catch (DataException ex) {
395
                    LOGGER.warn("Can't finish editing in FeatureForm ("+store.getName()+").",ex);
396
                }
397
            }
398
        }
399

    
400
        @Override
401
        public void update(Observable observable, Object notification) {
402
            if( notification instanceof FeatureStoreNotification ) {
403
                FeatureStoreNotification n =  (FeatureStoreNotification) notification;
404
                switch( n.getType() )  {
405
                    case FeatureStoreNotification.AFTER_STARTEDITING:
406
                    case FeatureStoreNotification.AFTER_FINISHEDITING:
407
                    case FeatureStoreNotification.AFTER_CANCELEDITING:
408
                        if( store.isEditing() ) {
409
                            formset.setReadOnly(false);
410
                            formset.setActionVisible("finishEditing", true);
411
                            formset.setActionEnabled("finishEditing", true);
412
                        } else {
413
                            formset.setReadOnly(true);
414
                            formset.setActionVisible("finishEditing", false);
415
                            formset.setActionEnabled("finishEditing", false);
416
                        }
417
                        break;
418
                }
419
            }
420
        }
421

    
422
    }
423

    
424
    private class StartEditingAction extends AbstractAction implements Observer {
425

    
426
        @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
427
        public StartEditingAction() {
428
            I18nManager i18nManager = ToolsLocator.getI18nManager();
429
            IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault();
430

    
431
            this.putValue(NAME,null);
432
            this.putValue(SHORT_DESCRIPTION,i18nManager.getTranslation("_Start_editing"));
433
            this.putValue(SMALL_ICON, iconTheme.get("table-start-editing"));
434
            this.putValue(ACTION_COMMAND_KEY, "startEditing");
435

    
436
            this.setEnabled(!store.isEditing());
437
            store.addObserver(this);
438
        }
439

    
440
        @Override
441
        public void actionPerformed(ActionEvent ae) {
442
            if( !store.isEditing() ) {
443
                try {
444
                    store.edit();
445
                } catch (DataException ex) {
446
                    LOGGER.warn("Can't finish editing in FeatureForm ("+store.getName()+").",ex);
447
                }
448
            }
449
        }
450

    
451
        @Override
452
        public void update(Observable observable, Object notification) {
453
            if( notification instanceof FeatureStoreNotification ) {
454
                FeatureStoreNotification n =  (FeatureStoreNotification) notification;
455
                switch( n.getType() )  {
456
                    case FeatureStoreNotification.AFTER_STARTEDITING:
457
                    case FeatureStoreNotification.AFTER_FINISHEDITING:
458
                    case FeatureStoreNotification.AFTER_CANCELEDITING:
459
                        if( store.isEditing() ) {
460
                            formset.setReadOnly(false);
461
                            formset.setActionVisible("startEditing", false);
462
                            formset.setActionEnabled("startEditing", false);
463
                        } else {
464
                            formset.setReadOnly(true);
465
                            formset.setActionVisible("startEditing", true);
466
                            formset.setActionEnabled("startEditing", true);
467
                        }
468
                        break;
469
                }
470
            }
471
        }
472

    
473
    }
474

    
475
    @Override
476
    public void setQuery(FeatureQuery query) {
477
        if (this.ph != null) {
478
            if (this.formset != null && !formset.isReadOnly() && this.formset.isAutosave() && this.formset.countValues() > 0) {
479
                if (!store.isEditing()) {
480
                    try {
481
                        store.edit();
482
                    } catch (DataException e1) {
483
                        throw new RuntimeException("Can't set query", e1);
484
                    }
485
                }
486
                saveChanges(this.formset);
487
            }
488
        }
489
        this.currentQuery = query;
490
        updateForm();
491
    }
492

    
493
    private FeatureQuery getCurrentQuery() {
494
        return this.currentQuery;
495
    }
496
    
497
    @Override
498
    public void showForm(MODE mode) {
499
        this.panel.add(this.getFormset().asJComponent(), BorderLayout.CENTER);
500
        WindowManager winmgr = ToolsSwingLocator.getWindowManager();
501
        String title = this.definition.getLabel();
502
        winmgr.showWindow(this.asJComponent(), title, mode);
503
    }
504

    
505
    private void saveChanges(JDynFormSet dynformSet) {
506
        if( dynformSet.isInNewState() ) {
507
            Feature feat = null;
508
            try {
509
                feat = store.createNewFeature(false);
510
            } catch (DataException ex) {
511
                LOGGER.warn("Can't create new feature.",ex);
512
                I18nManager i18nManager = ToolsLocator.getI18nManager();
513
                dynformSet.message(i18nManager.getTranslation("error_saving_data_will_not_save"));
514
                throw new RuntimeException("Can't new save values");
515
            }
516
            DynObject dynObject = feat.getAsDynObject();
517
            dynformSet.getFormValues(dynObject);
518
            try {
519
                ph.insert(((FacadeOfAFeature)dynObject).getEditableFeature());
520
            } catch (BaseException e) {
521
                throw new RuntimeException("Can't save values", e);
522
            }
523
            try {
524
                this.formset.setValues(ph.asListOfDynObjects());
525
                this.formset.setCurrentIndex((int)(ph.getTotalSize())-1);
526
            } catch(Exception ex) {
527
                LOGGER.warn("Can't reload form data after insert.",ex);
528
            }
529
        } else {
530
            int index = dynformSet.getCurrentIndex();
531
            DynObject dynObject = dynformSet.get(index);
532

    
533
            if ( !(dynObject instanceof FacadeOfAFeature) ) {
534
                LOGGER.warn("Can't get the associated feature index " + index);
535
                I18nManager i18nManager = ToolsLocator.getI18nManager();
536
                dynformSet.message(i18nManager.getTranslation("error_saving_data_will_not_save"));
537
                throw new RuntimeException("Can't save values");
538
            }
539
            dynformSet.getFormValues(dynObject);
540
            try {
541
                ph.update(((FacadeOfAFeature)dynObject).getEditableFeature());
542
            } catch (BaseException e) {
543
                throw new RuntimeException("Can't save values", e);
544
            }
545
        }
546

    
547
    }
548

    
549
    @Override
550
    public void saveChanges() {
551
        if (this.formset != null && this.formset.countValues() > 0) {
552
            if (store != null && !store.isEditing()) {
553
                try {
554
                    store.edit();
555
                } catch (DataException e1) {
556
                    LOGGER.warn("Can't edit the store " + store.getName());
557
                    throw new RuntimeException("Can't save changes.", e1);
558
                }
559
            }
560
            this.saveChanges(this.formset);
561
        }
562
    }
563

    
564
    @Override
565
    public long getDataSetSize() {
566
        if (this.ph != null) {
567
            return ph.getTotalSize();
568
        }
569
        return 0;
570
    }
571

    
572
    @Override
573
    public FeatureStore getFeatureStore() {
574
        return this.store;
575
    }
576

    
577
    private class FormSetListener implements JDynFormSetListener {
578

    
579
        @Override
580
        public void formMessage(String message) {
581
        }
582

    
583
        @Override
584
        public void formClose() {
585
            panel.setVisible(false);
586
        }
587

    
588
        @Override
589
        public void formMovedTo(int currentPosition) throws AbortActionException {
590
            LOGGER.trace("formMovedTo " + currentPosition);
591
        }
592

    
593
        @Override
594
        public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException {
595
            LOGGER.trace("formBeforeSave");
596
            if (!store.isEditing()) {
597
                try {
598
                    store.edit();
599
                } catch (DataException e1) {
600
                    throw new StoreEditException(e1, store.getName());
601
                }
602
            }
603
        }
604

    
605
        @Override
606
        public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException {
607
            LOGGER.trace("formBeforeNew");
608
        }
609

    
610
        @Override
611
        public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException {
612
            LOGGER.trace("formBeforeDelete");
613
        }
614

    
615
        @Override
616
        public void formAfterSave(JDynFormSet dynformSet) throws AbortActionException {
617
            LOGGER.trace("formAfterSave");
618
            saveChanges(dynformSet);
619
        }
620

    
621
        @Override
622
        public void formAfterNew(JDynFormSet dynformSet) throws AbortActionException {
623
            LOGGER.trace("formAfterNew");
624
        }
625

    
626
        @Override
627
        public void formAfterDelete(JDynFormSet dynformSet) throws AbortActionException {
628
            LOGGER.trace("formAfterDelete");
629
        }
630

    
631
        @Override
632
        public void formBeforeSearch(JDynFormSet dynformSet) throws AbortActionException {
633
            LOGGER.trace("formBeforeSearch");
634
            DataSwingManager dataSwingmanager = DALSwingLocator.getSwingManager();
635
            WindowManager_v2 winmgr = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
636

    
637
            JExpressionBuilder builder = dataSwingmanager.createQueryFilterExpresion(store);
638
            FeatureQuery currentQuery = getCurrentQuery();
639
            if( currentQuery!=null ) {
640
                Evaluator filter = currentQuery.getFilter();
641
                if( filter instanceof ExpressionEvaluator ) {
642
                    Expression expression = ((ExpressionEvaluator)filter).getExpression();
643
                    builder.setExpression(expression);
644
                }
645
            }
646
            Dialog dialog = winmgr.createDialog(
647
                    builder.asJComponent(),
648
                    "Filtro",
649
                    "Creacion de filtro sobre '"+store.getName()+"'",
650
                    WindowManager_v2.BUTTONS_OK_CANCEL
651
            );
652
            dialog.show(WindowManager.MODE.DIALOG);
653
            if( dialog.getAction() == WindowManager_v2.BUTTON_OK ) {
654
                Expression expresion = builder.getExpression();
655
                try {
656
                    FeatureQuery query = store.createFeatureQuery();
657
                    if( ExpressionUtils.isPhraseEmpty(expresion) ) {
658
                        query.clearFilter();
659
                    } else {
660
                        query.setFilter(expresion);
661
                    }
662
                    setQuery(query);
663
                } catch (Exception ex) {
664
                    LOGGER.warn("Can't apply filter '" + expresion + "'.", ex);
665
                }
666
            }
667
        }
668

    
669
        @Override
670
        public void formAfterSearch(JDynFormSet dynformSet) throws AbortActionException {
671
            LOGGER.trace("formAfterSearch");
672
        }
673

    
674
        @Override
675
        public void formBeforeCancelNew(JDynFormSet dynformSet) throws AbortActionException {
676
            LOGGER.trace("formBeforeCancelNew");
677
        }
678

    
679
        @Override
680
        public void formAfterCancelNew(JDynFormSet dynformSet) throws AbortActionException {
681
            LOGGER.trace("formAfterCancelNew");
682
        }
683
    }
684

    
685
    private static class StoreEditException extends AbortActionException {
686

    
687
        /**
688
         *
689
         */
690
        private static final long serialVersionUID = -7682017811778577130L;
691

    
692
        public StoreEditException(Throwable cause, String storename) {
693
            super("Can't edit the store '%(storename)'", cause, "cant_edit_the store_XstorenameX", serialVersionUID);
694
            setValue("storename", storename);
695
        }
696
    }
697
}