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

History | View | Annotate | Download (4.09 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
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.dynform.services.dynformfield.DynObject;
25

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

    
30
import javax.swing.JPanel;
31

    
32
import org.gvsig.tools.dynform.DynFormFieldDefinition;
33
import org.gvsig.tools.dynform.DynFormLocator;
34
import org.gvsig.tools.dynform.JDynForm;
35
import org.gvsig.tools.dynform.JDynForm.JDynFormListener;
36
import org.gvsig.tools.dynform.JDynFormField;
37
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
38
import org.gvsig.tools.dynobject.DynField_v2;
39
import org.gvsig.tools.dynobject.DynObject;
40
import org.gvsig.tools.dynobject.DynStruct;
41
import org.gvsig.tools.service.spi.ServiceManager;
42

    
43
public class JDynFormFieldDynObject extends AbstractJDynFormField implements JDynFormField, JDynFormListener, FocusListener {
44
        
45
        protected DynObject assignedValue  = null;
46
        protected DynObject currentValue = null;
47
        protected JDynForm jdynForm = null;
48
        protected boolean readonly = false;
49

    
50
        public JDynFormFieldDynObject(DynObject parameters,
51
                        ServiceManager serviceManager) {
52
                super(parameters, serviceManager);
53
                this.assignedValue = (DynObject) this.getParameterValue();
54
        }
55

    
56
        public void setReadOnly(boolean readonly) {
57
                this.readonly = readonly;
58
                if( this.jdynForm != null ) {
59
                        this.jdynForm.setReadOnly(readonly);
60
                }
61
        }
62
        
63
        public Object getAssignedValue() {
64
                return this.assignedValue;
65
        }
66
        
67
        public void initComponent() {
68
                this.contents = new JPanel();
69
                this.contents.setLayout(new BorderLayout());
70
                try {
71
                        DynFormFieldDefinition def = this.getDefinition();
72
                        DynField_v2 fielddef = (DynField_v2)def;
73
                        DynStruct struct = fielddef.getDynClassOfValue();
74
                        this.jdynForm = DynFormLocator.getDynFormManager().createJDynForm(struct);
75
                        if( fielddef.getTags().has("layoutMode") ) {
76
                                this.jdynForm.setLayoutMode(fielddef.getTags().getInt("layoutMode"));
77
                        }
78
                        this.jdynForm.setUseScrollBars(false);
79
                        this.jdynForm.setShowMessageStatus(false);
80
                        this.jdynForm.addListener(this);
81
                        this.contents.add(jdynForm.asJComponent(),BorderLayout.CENTER);
82
                        this.contents.setVisible(true);
83
                        this.jdynForm.setReadOnly(readonly);
84
                        this.setValue(this.assignedValue);
85
                } catch (Exception e) {
86
                        // TODO Auto-generated catch block
87
                        e.printStackTrace();
88
                }
89
//                this.jdynForm.addFocusListener(this);
90

    
91
        }
92
        
93
        
94
        public void setValue(Object value) {
95
                if( value == null ) {
96
                        // TODO
97
                        // this.jdynForm.clear();
98
                } else {
99
                        if( !(value instanceof DynObject) ) {
100
                                logger.info("setValue invoked with non DynObject value ("+value.toString()+").");
101
                                return;
102
                        }
103
                        this.jdynForm.setValues((DynObject)value);
104
                }
105
                this.assignedValue = (DynObject) value;
106
                this.currentValue = this.assignedValue;
107
        }
108
        
109
        public Object getValue() {
110
                this.jdynForm.getValues(this.currentValue);
111
                return this.currentValue;
112
        }
113
        
114
        public boolean hasValidValue() {
115
                return true;
116
        }
117

    
118
        public void focusGained(FocusEvent arg0) {
119
                fireFieldEnterEvent();
120
                this.problemIndicator().restore();
121
        }
122

    
123
        public void focusLost(FocusEvent arg0) {
124
                fireFieldExitEvent();
125
        }
126

    
127
        public void message(String message) {
128
                fireMessageEvent(message);
129
        }
130

    
131
        public void fieldChanged(JDynFormField field) {
132
                // TODO Auto-generated method stub
133
                
134
        }
135
        
136
}