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 / DefaultJFeatureReferencesForm.java @ 46959

History | View | Annotate | Download (19.4 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 45532 jjdelcerro
import java.awt.event.ActionListener;
29 44291 jjdelcerro
import java.awt.event.ComponentAdapter;
30
import java.awt.event.ComponentEvent;
31 45788 jjdelcerro
import java.util.AbstractList;
32 42489 jjdelcerro
import java.util.List;
33
import javax.swing.AbstractAction;
34 44202 jjdelcerro
import static javax.swing.Action.ACTION_COMMAND_KEY;
35
import static javax.swing.Action.NAME;
36
import static javax.swing.Action.SHORT_DESCRIPTION;
37
import static javax.swing.Action.SMALL_ICON;
38 42112 jjdelcerro
import javax.swing.JComponent;
39
import javax.swing.JPanel;
40 45788 jjdelcerro
import org.gvsig.featureform.swing.JFeatureReferencesForm;
41 42112 jjdelcerro
import org.gvsig.fmap.dal.exception.DataException;
42 45781 fdiaz
import org.gvsig.fmap.dal.feature.FacadeOfAFeature;
43 42112 jjdelcerro
import org.gvsig.fmap.dal.feature.Feature;
44 45425 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
45 45788 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureReference;
46 42112 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureStore;
47 42489 jjdelcerro
import org.gvsig.fmap.dal.swing.DALSwingLocator;
48 44202 jjdelcerro
import org.gvsig.fmap.dal.swing.impl.DefaultDataSwingManager;
49 42112 jjdelcerro
import org.gvsig.tools.ToolsLocator;
50 45120 jjdelcerro
import org.gvsig.tools.dispose.Disposable;
51 42112 jjdelcerro
import org.gvsig.tools.dynform.AbortActionException;
52 44128 jjdelcerro
import org.gvsig.tools.dynform.DynFormDefinition;
53 42112 jjdelcerro
import org.gvsig.tools.dynform.DynFormLocator;
54
import org.gvsig.tools.dynform.DynFormManager;
55 44202 jjdelcerro
import org.gvsig.tools.dynform.JDynForm;
56 45425 jjdelcerro
import org.gvsig.tools.dynform.JDynFormField;
57 42112 jjdelcerro
import org.gvsig.tools.dynform.JDynFormSet;
58 45783 jjdelcerro
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_NAVIGATION;
59 44488 jjdelcerro
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_SAVE;
60 42112 jjdelcerro
import org.gvsig.tools.dynform.JDynFormSet.JDynFormSetListener;
61
import org.gvsig.tools.dynobject.DynClass;
62
import org.gvsig.tools.dynobject.DynObject;
63
import org.gvsig.tools.i18n.I18nManager;
64 45781 fdiaz
import org.gvsig.tools.swing.api.ActionListenerSupport;
65 42112 jjdelcerro
import org.gvsig.tools.swing.api.ToolsSwingLocator;
66 45781 fdiaz
import org.gvsig.tools.swing.api.ToolsSwingUtils;
67 42112 jjdelcerro
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
68 45781 fdiaz
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
69 42489 jjdelcerro
import org.gvsig.tools.swing.icontheme.IconTheme;
70 45781 fdiaz
import org.slf4j.Logger;
71
import org.slf4j.LoggerFactory;
72 42112 jjdelcerro
73
/**
74
 * @author fdiaz
75
 *
76
 */
77 44128 jjdelcerro
@SuppressWarnings("UseSpecificCatch")
78 45788 jjdelcerro
public class DefaultJFeatureReferencesForm implements Disposable, JFeatureReferencesForm {
79 42112 jjdelcerro
80 44531 omartinez
    private final String REFRESHFORM_ACTION = "refreshForm";
81 44488 jjdelcerro
82 45788 jjdelcerro
    public static class FeaturesList extends AbstractList<Feature> {
83
84
        private final List<FeatureReference> references;
85
86
        public FeaturesList(List<FeatureReference> references) {
87
            this.references = references;
88
        }
89
90
        @Override
91
        public Feature get(int index) {
92
            try {
93
                return this.references.get(index).getFeature();
94
            } catch (DataException ex) {
95
                throw new RuntimeException("Can't get feature "+index, ex);
96
            }
97
        }
98
99
        @Override
100
        public int size() {
101
            return this.references.size();
102
        }
103
104
    }
105
106
    public static class DynObjectsList extends AbstractList<DynObject> {
107
108
        private final List<FeatureReference> references;
109
110
        public DynObjectsList( List<FeatureReference> references) {
111
            this.references = references;
112
        }
113
114
        @Override
115
        public DynObject get(int index) {
116
            try {
117
                Feature feature = this.references.get(index).getFeature();
118
                return feature.getAsDynObject();
119
            } catch (DataException ex) {
120
                throw new RuntimeException("Can't get dynobject "+index, ex);
121
            }
122
        }
123
124
        @Override
125
        public int size() {
126
            return this.references.size();
127
        }
128
129
    }
130
131
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJFeatureReferencesForm.class);
132 44281 jjdelcerro
133 44291 jjdelcerro
    private JPanel panel;
134 42112 jjdelcerro
    private JDynFormSet formset;
135 44128 jjdelcerro
    private DynFormDefinition definition = null;
136 45788 jjdelcerro
    private final ActionListenerSupport actionListeners;
137
    private List<FeatureReference> references;
138
    private List<Feature> features;
139
    private List<DynObject> dynobjects;
140
    private FeatureStore store;
141
142 42714 dmartinezizquierdo
143 45788 jjdelcerro
    public DefaultJFeatureReferencesForm() {
144 42112 jjdelcerro
        this.panel = new JPanel(new BorderLayout());
145 44291 jjdelcerro
        this.panel.addComponentListener(new ComponentAdapter() {
146
            @Override
147
            public void componentHidden(ComponentEvent e) {
148 45120 jjdelcerro
                dispose();
149 44291 jjdelcerro
            }
150
        });
151 45532 jjdelcerro
        this.actionListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
152 42112 jjdelcerro
    }
153
154 42489 jjdelcerro
    @Override
155 42112 jjdelcerro
    public void setPreferredSize(Dimension dimension) {
156 45425 jjdelcerro
        panel.setPreferredSize(dimension);
157 42112 jjdelcerro
    }
158
159 42489 jjdelcerro
    private void updateForm() {
160 42473 fdiaz
        if (this.formset == null) {
161 45425 jjdelcerro
            this.getFormset();
162 42248 jjdelcerro
        }
163 42489 jjdelcerro
        try {
164 45788 jjdelcerro
            this.formset.setValues(this.dynobjects);
165 42489 jjdelcerro
        } catch (Exception ex) {
166
            throw new RuntimeException("Can't update form", ex);
167
        }
168 44488 jjdelcerro
        updateButtonEnabledStatus();
169 42248 jjdelcerro
    }
170 42473 fdiaz
171 42489 jjdelcerro
    @Override
172 42112 jjdelcerro
    public JComponent asJComponent() {
173 45788 jjdelcerro
//        if (this.features == null) {
174
//            try {
175 42248 jjdelcerro
                updateForm();
176 45788 jjdelcerro
//            } catch (Exception ex) {
177
//                throw new RuntimeException(ex);
178
//            }
179
//        }
180 42112 jjdelcerro
        return this.panel;
181
    }
182
183 42489 jjdelcerro
    @Override
184 45788 jjdelcerro
    public void bind(FeatureStore store, List<FeatureReference> references) {
185
        this.bind(store, null, references);
186 45532 jjdelcerro
    }
187 45788 jjdelcerro
188
    public void bind(FeatureStore store, DynClass definition, List<FeatureReference> references) {
189
        if (store == null || references == null) {
190 42489 jjdelcerro
            throw new IllegalArgumentException("bind need a store as parameter, not a null.");
191
        }
192
        try {
193 45788 jjdelcerro
            DynFormManager formManager = DynFormLocator.getDynFormManager();
194 45618 jolivas
            if (definition == null) {
195 45532 jjdelcerro
                DefaultDataSwingManager manager = (DefaultDataSwingManager) DALSwingLocator.getSwingManager();
196
                definition = manager.featureType2DynClass(store, store.getDefaultFeatureType());
197
            }
198
            this.store = store;
199 45788 jjdelcerro
            this.definition = formManager.getDefinition(definition);
200
            this.setFeatures(references);
201
202 42489 jjdelcerro
        } catch (Exception ex) {
203 45788 jjdelcerro
            throw new RuntimeException("Can't bind features of '" + store.getName() + "' to form", ex);
204 42489 jjdelcerro
        }
205 42112 jjdelcerro
    }
206 42473 fdiaz
207 45120 jjdelcerro
    @Override
208
    public void dispose() {
209 44291 jjdelcerro
        this.panel = null;
210
        this.formset = null;
211 44488 jjdelcerro
        this.features = null;
212 44291 jjdelcerro
        this.definition = null;
213 42112 jjdelcerro
    }
214 45618 jolivas
215 42489 jjdelcerro
    @Override
216
    public JDynFormSet getFormset() {
217 42473 fdiaz
        if (this.formset == null) {
218 42112 jjdelcerro
            DynFormManager formManager = DynFormLocator.getDynFormManager();
219 44253 jjdelcerro
            this.formset = formManager.createJDynFormSet(
220 46010 jjdelcerro
                    new DefaultFeaturesFormContext(this.store) {
221
                        @Override
222
                        public Feature getCurrentFeature() {
223
                            return DefaultJFeatureReferencesForm.this.getCurrentFeature();
224
                        }
225
                    },
226 44253 jjdelcerro
                    this.definition,
227
                    null
228
            );
229 45788 jjdelcerro
230 44202 jjdelcerro
            List<String> groups = this.definition.getGroups();
231 45618 jolivas
            if (groups.size() == 1 && groups.get(0) == null) {
232 44202 jjdelcerro
                this.formset.setLayoutMode(JDynForm.USE_PLAIN);
233
            } else {
234
                this.formset.setLayoutMode(JDynForm.USE_TABS);
235
            }
236 45788 jjdelcerro
            this.formset.setAllowNew(false);
237
            this.formset.setAllowDelete(false);
238 44202 jjdelcerro
            this.formset.setAllowUpdate(true);
239 42112 jjdelcerro
            this.formset.setAllowClose(true);
240 45788 jjdelcerro
            this.formset.setAllowSearch(false);
241 42112 jjdelcerro
            this.formset.setAutosave(true);
242 42714 dmartinezizquierdo
243 44531 omartinez
            this.formset.addAction(new RefreshAction());
244 45618 jolivas
245 42489 jjdelcerro
            this.formset.addListener(new FormSetListener());
246 45618 jolivas
            this.formset.getForm().addListener(new JDynForm.JDynFormListener() {
247
                @Override
248
                public void message(String string) {
249
                }
250
251
                @Override
252
                public void fieldChanged(JDynFormField jdff) {
253
                    updateButtonEnabledStatus();
254
                }
255
            });
256
257 45425 jjdelcerro
            ToolsSwingLocator.getToolsSwingManager().removeBorder(this.formset.asJComponent());
258
            this.panel.add(this.formset.asJComponent(), BorderLayout.CENTER);
259
            this.panel.revalidate();
260 45788 jjdelcerro
            ToolsSwingUtils.ensureRowsCols(this.panel, 8, 70, 25, 100);
261 45781 fdiaz
262 42112 jjdelcerro
        }
263 44488 jjdelcerro
        updateButtonEnabledStatus();
264 42112 jjdelcerro
        return this.formset;
265
    }
266
267 42489 jjdelcerro
    @Override
268
    public long getCurrentIndex() {
269 45618 jolivas
        if (this.formset == null) {
270 42489 jjdelcerro
            return -1;
271
        }
272
        return this.formset.getCurrentIndex();
273
    }
274
275
    @Override
276
    public Feature get(long index) {
277 45618 jolivas
        if (this.formset == null || this.features == null) {
278 42489 jjdelcerro
            return null;
279
        }
280 45788 jjdelcerro
        return this.features.get((int)index);
281 42489 jjdelcerro
    }
282 45618 jolivas
283 44531 omartinez
    private class RefreshAction extends AbstractAction {
284 42714 dmartinezizquierdo
285 44531 omartinez
        @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
286
        public RefreshAction() {
287
            I18nManager i18nManager = ToolsLocator.getI18nManager();
288
            IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault();
289
290
            this.putValue(NAME, null);
291 45591 fdiaz
            this.putValue(SHORT_DESCRIPTION, i18nManager.getTranslation("_Reload_data"));
292 44531 omartinez
            this.putValue(SMALL_ICON, iconTheme.get("form-refresh-data"));
293
            this.putValue(ACTION_COMMAND_KEY, REFRESHFORM_ACTION);
294
            this.setEnabled(!formset.isInNewState());
295
        }
296
297
        @Override
298
        public void actionPerformed(ActionEvent ae) {
299
            try {
300
                I18nManager i18n = ToolsLocator.getI18nManager();
301 45591 fdiaz
                formset.message(i18n.getTranslation("_Form_reloaded"));
302 45788 jjdelcerro
                int x = formset.getCurrentIndex();
303 44531 omartinez
                updateForm();
304 45788 jjdelcerro
                formset.setCurrentIndex(x);
305 44531 omartinez
            } catch (Exception ex) {
306 45591 fdiaz
                LOGGER.warn("Can't reload form", ex);
307 44531 omartinez
            }
308
        }
309
    }
310
311 42489 jjdelcerro
    @Override
312
    public void showForm(MODE mode) {
313 42248 jjdelcerro
        WindowManager winmgr = ToolsSwingLocator.getWindowManager();
314 44202 jjdelcerro
        String title = this.definition.getLabel();
315 42775 jjdelcerro
        winmgr.showWindow(this.asJComponent(), title, mode);
316 42112 jjdelcerro
    }
317
318 44488 jjdelcerro
    private void saveChanges(JDynFormSet theFormSet) {
319 44346 jjdelcerro
        I18nManager i18n = ToolsLocator.getI18nManager();
320 44488 jjdelcerro
        try {
321 45788 jjdelcerro
            int index = theFormSet.getCurrentIndex();
322
            DynObject currentElement = theFormSet.get(index);
323
            theFormSet.getFormValues(currentElement);
324
            store.update(((FacadeOfAFeature) currentElement).getEditableFeature());
325
            this.formset.message(i18n.getTranslation("_Record_saved"));
326
            try {
327
                this.formset.setCurrentIndex(index);
328
            } catch (Exception ex) {
329
                LOGGER.warn("Can't reload form data after insert.", ex);
330 42775 jjdelcerro
            }
331 45618 jolivas
        } catch (Exception ex) {
332 44488 jjdelcerro
            theFormSet.message(i18n.getTranslation("error_saving_data_will_not_save"));
333 45618 jolivas
            throw new RuntimeException("Can't save values", ex);
334
335 44488 jjdelcerro
        } finally {
336
            updateButtonEnabledStatus();
337 42489 jjdelcerro
        }
338 42112 jjdelcerro
339
    }
340 45618 jolivas
341 42489 jjdelcerro
    @Override
342
    public void saveChanges() {
343
        if (this.formset != null && this.formset.countValues() > 0) {
344
            this.saveChanges(this.formset);
345 42112 jjdelcerro
        }
346
    }
347
348 44488 jjdelcerro
    private void updateButtonEnabledStatus() {
349 45618 jolivas
        if (this.formset == null) {
350 44488 jjdelcerro
            return;
351
        }
352 45788 jjdelcerro
        if (this.store == null || store.isBroken() || this.references == null) {
353 44488 jjdelcerro
            this.formset.setReadOnly(true);
354 45618 jolivas
            formset.setActionEnabled(ACTION_SAVE, false);
355 45788 jjdelcerro
            formset.setActionEnabled(REFRESHFORM_ACTION, false);
356 45783 jjdelcerro
            formset.setActionEnabled(ACTION_NAVIGATION, false);
357 44488 jjdelcerro
            return;
358
        }
359 45788 jjdelcerro
        this.formset.setReadOnly(false);
360
        if (this.features != null && this.features.isEmpty()) {
361
            formset.getForm().setReadOnly(true);
362
            formset.setActionEnabled(ACTION_SAVE, false);
363
            formset.setActionEnabled(REFRESHFORM_ACTION, false);
364
            formset.setActionEnabled(ACTION_NAVIGATION, false);
365 45618 jolivas
366 45788 jjdelcerro
        } else if (formset.getForm().isModified()) {
367
            formset.setActionEnabled(ACTION_SAVE, true);
368
            formset.setActionEnabled(REFRESHFORM_ACTION, true);
369
            formset.setActionEnabled(ACTION_NAVIGATION, true);
370 44488 jjdelcerro
371 45788 jjdelcerro
        } else {
372
            formset.setActionEnabled(ACTION_SAVE, false);
373
            formset.setActionEnabled(REFRESHFORM_ACTION, true);
374
            formset.setActionEnabled(ACTION_NAVIGATION, true);
375 44488 jjdelcerro
        }
376
    }
377 45425 jjdelcerro
378
    private void clearUniqueFields() {
379 45618 jolivas
        for (FeatureAttributeDescriptor attr : this.store.getDefaultFeatureTypeQuietly()) {
380
            if ((attr.isPrimaryKey() && !attr.isAutomatic()) || (attr.isIndexed() && !attr.allowIndexDuplicateds())) {
381 45425 jjdelcerro
                JDynFormField field = formset.getForm().getField(attr.getName());
382 45618 jolivas
                if (field != null) {
383 45425 jjdelcerro
                    field.clear();
384
                }
385
            }
386
        }
387
    }
388 45618 jolivas
389
    private void setEnabledUniqueFields(boolean enabled) {
390
        for (FeatureAttributeDescriptor attr : this.store.getDefaultFeatureTypeQuietly()) {
391
            if ((attr.isPrimaryKey() && !attr.isAutomatic()) || (attr.isIndexed() && !attr.allowIndexDuplicateds())) {
392
                JDynFormField field = formset.getForm().getField(attr.getName());
393
                if (field != null) {
394
                    field.setReadOnly(!enabled);
395
                }
396
            }
397
        }
398
    }
399
400 42489 jjdelcerro
    @Override
401
    public long getDataSetSize() {
402 45788 jjdelcerro
        if (this.references != null) {
403
            return references.size();
404 42489 jjdelcerro
        }
405
        return 0;
406 42112 jjdelcerro
    }
407
408 42489 jjdelcerro
    @Override
409
    public FeatureStore getFeatureStore() {
410
        return this.store;
411 42112 jjdelcerro
    }
412
413 42489 jjdelcerro
    private class FormSetListener implements JDynFormSetListener {
414 42112 jjdelcerro
415 42489 jjdelcerro
        @Override
416
        public void formMessage(String message) {
417 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formMessage"));
418 42489 jjdelcerro
        }
419 42112 jjdelcerro
420 42489 jjdelcerro
        @Override
421
        public void formClose() {
422
            panel.setVisible(false);
423 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formClose"));
424 42112 jjdelcerro
        }
425
426 42489 jjdelcerro
        @Override
427
        public void formMovedTo(int currentPosition) throws AbortActionException {
428
            LOGGER.trace("formMovedTo " + currentPosition);
429 44488 jjdelcerro
            updateButtonEnabledStatus();
430 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formMovedTo"));
431 42489 jjdelcerro
        }
432 42112 jjdelcerro
433 42489 jjdelcerro
        @Override
434
        public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException {
435
            LOGGER.trace("formBeforeSave");
436 45618 jolivas
            saveChanges(dynformSet);
437 44488 jjdelcerro
            updateButtonEnabledStatus();
438 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formBeforeSave"));
439 42489 jjdelcerro
        }
440 42112 jjdelcerro
441 44259 jjdelcerro
        @Override
442 42489 jjdelcerro
        public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException {
443
            LOGGER.trace("formBeforeNew");
444 45425 jjdelcerro
            clearUniqueFields();
445 44488 jjdelcerro
            updateButtonEnabledStatus();
446 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formBeforeNew"));
447 42112 jjdelcerro
        }
448
449 44259 jjdelcerro
        @Override
450 42489 jjdelcerro
        public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException {
451
            LOGGER.trace("formBeforeDelete");
452 44488 jjdelcerro
            updateButtonEnabledStatus();
453 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formBeforeDelete"));
454 42489 jjdelcerro
        }
455 42112 jjdelcerro
456 42489 jjdelcerro
        @Override
457
        public void formAfterSave(JDynFormSet dynformSet) throws AbortActionException {
458
            LOGGER.trace("formAfterSave");
459 44488 jjdelcerro
            updateButtonEnabledStatus();
460 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formAfterSave"));
461 42489 jjdelcerro
        }
462 42112 jjdelcerro
463 42489 jjdelcerro
        @Override
464
        public void formAfterNew(JDynFormSet dynformSet) throws AbortActionException {
465
            LOGGER.trace("formAfterNew");
466 44488 jjdelcerro
            updateButtonEnabledStatus();
467 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formAfterNew"));
468 42112 jjdelcerro
        }
469
470 42489 jjdelcerro
        @Override
471
        public void formAfterDelete(JDynFormSet dynformSet) throws AbortActionException {
472
            LOGGER.trace("formAfterDelete");
473 42112 jjdelcerro
        }
474
475 42489 jjdelcerro
        @Override
476
        public void formBeforeSearch(JDynFormSet dynformSet) throws AbortActionException {
477
            LOGGER.trace("formBeforeSearch");
478 42112 jjdelcerro
        }
479
480 42489 jjdelcerro
        @Override
481
        public void formAfterSearch(JDynFormSet dynformSet) throws AbortActionException {
482
            LOGGER.trace("formAfterSearch");
483
        }
484 42775 jjdelcerro
485
        @Override
486
        public void formBeforeCancelNew(JDynFormSet dynformSet) throws AbortActionException {
487
            LOGGER.trace("formBeforeCancelNew");
488 44488 jjdelcerro
            updateButtonEnabledStatus();
489 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formBeforeCancelNew"));
490 42775 jjdelcerro
        }
491
492
        @Override
493
        public void formAfterCancelNew(JDynFormSet dynformSet) throws AbortActionException {
494
            LOGGER.trace("formAfterCancelNew");
495 44488 jjdelcerro
            updateButtonEnabledStatus();
496 45532 jjdelcerro
            actionListeners.fireActionEvent(new ActionEvent(this, 1, "formAfterCancelNew"));
497 42775 jjdelcerro
        }
498 42112 jjdelcerro
    }
499
500 45532 jjdelcerro
    @Override
501
    public void addActionListener(ActionListener listener) {
502
        this.actionListeners.addActionListener(listener);
503
    }
504
505
    @Override
506
    public ActionListener[] getActionListeners() {
507
        return this.actionListeners.getActionListeners();
508
    }
509
510
    @Override
511
    public void removeActionListener(ActionListener listener) {
512
        this.actionListeners.removeActionListener(listener);
513
    }
514
515
    @Override
516
    public void removeAllActionListener() {
517
        this.actionListeners.removeAllActionListener();
518
    }
519
520
    @Override
521
    public void fireActionEvent(ActionEvent event) {
522
        this.actionListeners.fireActionEvent(event);
523
    }
524
525
    @Override
526
    public boolean hasActionListeners() {
527
        return this.actionListeners.hasActionListeners();
528
    }
529
530 45788 jjdelcerro
    @Override
531
    public void setFeatures(List<FeatureReference> references) {
532
        this.references = references;
533
        this.features = new FeaturesList(references);
534
        this.dynobjects = new DynObjectsList(references);
535
        if (formset != null) {
536
            this.panel.remove(formset.asJComponent());
537
            this.panel.revalidate();
538
            this.formset = null;
539
        }
540
        this.updateForm();
541
    }
542
543 46010 jjdelcerro
    @Override
544
    public Feature getCurrentFeature() {
545
        long index = getCurrentIndex();
546
        if( index<0 ) {
547
            return null;
548
        }
549
        Feature f = get(index);
550
        try {
551
            DynObject adapter = f.getAsDynObject();
552
            this.getFormset().getForm().getValues(adapter);
553
            f = ((FacadeOfAFeature)adapter).getFeature();
554
            return f;
555
        } catch(Exception ex) {
556
            return f;
557
        }
558
    }
559
560 42112 jjdelcerro
}