Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.dynform / org.gvsig.tools.dynform.services / src / main / java / org / gvsig / tools / dynform / services / dynformfield / DynObject / JDynFormFieldDynObject.java @ 1405

History | View | Annotate | Download (4.38 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.tools.dynform.services.dynformfield.DynObject;
24

    
25
import java.awt.BorderLayout;
26
import java.awt.event.FocusEvent;
27
import java.awt.event.FocusListener;
28

    
29
import javax.swing.JPanel;
30

    
31
import org.gvsig.tools.dynform.DynFormLocator;
32
import org.gvsig.tools.dynform.JDynForm.JDynFormListener;
33
import org.gvsig.tools.dynform.JDynFormField;
34
import org.gvsig.tools.dynform.spi.AbstractJDynForm;
35
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
36
import org.gvsig.tools.dynobject.DynObject;
37
import org.gvsig.tools.dynobject.DynStruct;
38
import org.gvsig.tools.service.spi.ServiceManager;
39

    
40
public class JDynFormFieldDynObject extends AbstractJDynFormField implements JDynFormField, JDynFormListener, FocusListener {
41

    
42
    protected DynObject assignedValue = null;
43
    protected DynObject currentValue = null;
44
    protected AbstractJDynForm jdynForm = null;
45
    protected boolean readonly = false;
46

    
47
    public JDynFormFieldDynObject(DynObject parameters,
48
            ServiceManager serviceManager) {
49
        super(parameters, serviceManager);
50
        this.assignedValue = (DynObject) this.getParameterValue();
51
    }
52

    
53
    @Override
54
    public void setReadOnly(boolean readonly) {
55
        super.setReadOnly(readonly);
56
        if (this.jdynForm != null) {
57
            this.jdynForm.setReadOnly(readonly);
58
        }
59
    }
60

    
61
    @Override
62
    public Object getAssignedValue() {
63
        return this.assignedValue;
64
    }
65

    
66
    @Override
67
    public void initComponent() {
68
        this.contents = new JPanel();
69
        this.contents.setLayout(new BorderLayout());
70
        try {
71
            DynStruct struct = this.getDefinition().getDynClassOfValue();
72
            this.jdynForm = (AbstractJDynForm) DynFormLocator.getDynFormManager().createJDynForm(struct);
73
            this.jdynForm.setUseScrollBars(false);
74
            this.jdynForm.setReadOnly(readonly);
75
            this.jdynForm.loadDefaultValuesFromTags(this.getDefinition().getTags());
76

    
77
            this.jdynForm.addListener(this);
78
            this.contents.add(jdynForm.asJComponent(), BorderLayout.CENTER);
79
            this.jdynForm.setShowMessageStatus(false);
80
            this.contents.setVisible(true);
81
            this.setValue(this.assignedValue);
82
        } catch (Exception e) {
83
            logger.warn("Can't initialize JDynFormFiledDynObject.", e);
84
        }
85

    
86
    }
87

    
88
    public void setValue(Object value) {
89
        if (value == null) {
90
                        // TODO
91
            // this.jdynForm.clear();
92
        } else {
93
            if (!(value instanceof DynObject)) {
94
                logger.info("setValue invoked with non DynObject value (" + value.toString() + ").");
95
                return;
96
            }
97
            this.jdynForm.setValues((DynObject) value);
98
        }
99
        this.assignedValue = (DynObject) value;
100
        this.currentValue = this.assignedValue;
101
    }
102

    
103
    public Object getValue() {
104
        this.jdynForm.getValues(this.currentValue);
105
        return this.currentValue;
106
    }
107

    
108
    public boolean hasValidValue() {
109
        return true;
110
    }
111

    
112
    public void focusGained(FocusEvent arg0) {
113
        fireFieldEnterEvent();
114
        this.problemIndicator().restore();
115
    }
116

    
117
    public void focusLost(FocusEvent arg0) {
118
        fireFieldExitEvent();
119
    }
120

    
121
    public void message(String message) {
122
        fireMessageEvent(message);
123
    }
124

    
125
    public void fieldChanged(JDynFormField field) {
126
                // TODO Auto-generated method stub
127

    
128
    }
129

    
130
    public void clear() {
131
        if (this.jdynForm != null) {
132
            this.jdynForm.clear();
133
        }
134
    }
135
}