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 / DynObjectList / JDynFormFieldDynObjectList.java @ 1225

History | View | Annotate | Download (7.49 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.DynObjectList;
25

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

    
31
import javax.swing.JPanel;
32

    
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynform.AbortActionException;
35
import org.gvsig.tools.dynform.DynFormFieldDefinition;
36
import org.gvsig.tools.dynform.DynFormLocator;
37
import org.gvsig.tools.dynform.JDynForm.JDynFormListener;
38
import org.gvsig.tools.dynform.JDynFormField;
39
import org.gvsig.tools.dynform.JDynFormSet;
40
import org.gvsig.tools.dynform.JDynFormSet.JDynFormSetListener;
41
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
42
import org.gvsig.tools.dynobject.DynClass;
43
import org.gvsig.tools.dynobject.DynField;
44
import org.gvsig.tools.dynobject.DynField_v2;
45
import org.gvsig.tools.dynobject.DynObject;
46
import org.gvsig.tools.dynobject.DynStruct;
47
import org.gvsig.tools.service.ServiceException;
48
import org.gvsig.tools.service.spi.ServiceManager;
49

    
50
public class JDynFormFieldDynObjectList extends AbstractJDynFormField implements JDynFormField, JDynFormListener, JDynFormSetListener, FocusListener {
51
        
52
        protected List assignedValue  = null;
53
        protected List currentValue = null;
54
        protected JDynFormSet jdynFormSet = null;
55
        protected boolean readonly = false;
56

    
57
        public JDynFormFieldDynObjectList(DynObject parameters,
58
                        ServiceManager serviceManager) {
59
                super(parameters, serviceManager);
60
                this.assignedValue = (List) this.getParameterValue();
61
        }
62

    
63
        public void setReadOnly(boolean readonly) {
64
                super.setReadOnly(readonly);
65
                if( this.contents != null ) {
66
                        this.jdynFormSet.setReadOnly(readonly);
67
                }
68
        }
69
        
70
        public Object getAssignedValue() {
71
                return this.assignedValue;
72
        }
73
        
74
        public void initComponent() {
75
                this.contents = new JPanel();
76
                this.contents.setLayout(new BorderLayout());
77
                try {
78
                        DynFormFieldDefinition def = this.getDefinition();
79
                        DynField_v2 fielddef = (DynField_v2)def;
80
                        DynStruct struct = fielddef.getDynClassOfItems();
81
                        String viewMode = getTagValueAsString("ViewMode", "dynform.viewmode", "Subform");
82
                        try{
83
                                this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(viewMode,struct);
84
                        } catch(Exception e){
85
                                logger.warn("Error en la creaci?n del DynFormSet '"+ viewMode +"'" , e);
86
                                this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(struct);
87
                        }
88

    
89
                        int height = getTagValueAsInt("dynform.height", -1);
90
                        if( height>0 ) {
91
                            this.jdynFormSet.setFormSize(50,height); 
92
                        }
93

    
94
                        this.jdynFormSet.addListener(this);
95
                        this.jdynFormSet.setLayoutMode(getTagValueAsInt("layoutMode", "dynform.layoutmode",JDynFormSet.USE_PLAIN));
96
                        this.jdynFormSet.setAllowNew(getTagValueAsBoolean("allowNew", "dynform.action.new", false));
97
                        this.jdynFormSet.setAllowUpdate(getTagValueAsBoolean("allowUpdate", "dynform.action.update", false));
98
                        this.jdynFormSet.setAllowDelete(getTagValueAsBoolean("allowDelete", "dynform.action.delete", false));
99
                        this.jdynFormSet.setAllowSearch(getTagValueAsBoolean("allowSearch", "dynform.action.search", false));
100
                        this.jdynFormSet.setAllowClose(false);
101
                        this.jdynFormSet.setUseScrollBars(false);
102
//                        this.jdynFormSet.setShowMessageStatus(false);
103
//                        this.jdynFormSet.addListener(this);
104
                        this.contents.add(jdynFormSet.asJComponent(),BorderLayout.CENTER);
105
                        this.contents.setVisible(true);
106
                        this.jdynFormSet.setReadOnly(readonly);
107
                        this.setValue(this.assignedValue);
108
                } catch (Exception e) {
109
                        logger.warn("",e);
110
                }
111
//                this.jdynForm.addFocusListener(this);
112

    
113
        }
114
        
115
        
116
        public void setValue(Object value) {
117
                if( value == null ) {
118
                        // TODO
119
                        // this.jdynForm.clear();
120
                } else {
121
                        if( !(value instanceof List) ) {
122
                                logger.info("setValue invoked with non List value ("+value.toString()+").");
123
                                return;
124
                        }
125
                        try {
126
                                this.jdynFormSet.setValues((List)value);
127
                        } catch (ServiceException e) {
128
                                logger.warn("Error settings values to DynformSet",e);
129
                        }
130
                }
131
                this.assignedValue = (List) value;
132
                this.currentValue = this.assignedValue;
133
        }
134
        
135
        public Object getValue() {
136
                return this.jdynFormSet.getValues();
137
        }
138
        
139
        public boolean hasValidValue() {
140
                return this.jdynFormSet.hasValidValues();
141
        }
142

    
143
        public void focusGained(FocusEvent arg0) {
144
                fireFieldEnterEvent();
145
                this.problemIndicator().restore();
146
        }
147

    
148
        public void focusLost(FocusEvent arg0) {
149
                fireFieldExitEvent();
150
        }
151

    
152
        public void message(String message) {
153
                fireMessageEvent(message);
154
        }
155

    
156
        public void fieldChanged(JDynFormField field) {
157
                // TODO Auto-generated method stub
158
                
159
        }
160

    
161
        public void formMessage(String message) {
162
                // TODO Auto-generated method stub
163
                
164
        }
165

    
166
        public void formClose() {
167
                // TODO Auto-generated method stub
168
                
169
        }
170

    
171
        public void formMovedTo(int currentPosition) {
172
                // TODO Auto-generated method stub
173
                
174
        }
175

    
176
        public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException {
177
                // TODO Auto-generated method stub
178
                
179
        }
180

    
181
        public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException {
182
                DynFormFieldDefinition def = this.getDefinition();
183
                DynField_v2 fielddef = (DynField_v2)def;
184
                DynStruct struct = fielddef.getDynClassOfItems();
185
                DynObject value = createDynObject(struct);
186
                this.currentValue.add(value);
187

    
188
                
189
        }
190
        
191
        private DynObject createDynObject(DynStruct dynStruct){
192
                DynObject value = ToolsLocator.getDynObjectManager().createDynObject(dynStruct);
193
                DynField[] fields = dynStruct.getDynFields();
194
                for(int i=0;i<fields.length; i++){
195
                        DynField_v2 field = (DynField_v2) fields[i];
196
                        if(field.getDataType().isDynObject()){
197
                                value.setDynValue(field.getName(), createDynObject(field.getDynClassOfValue()));
198
                        }
199
                }
200
                return value;
201
        }
202

    
203
        public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException {
204
                this.currentValue.remove(dynformSet.getCurrentIndex());
205
        }
206

    
207
        public void formBeforeSearch(JDynFormSet dynformSet) throws AbortActionException {
208
                // TODO Auto-generated method stub
209
                
210
        }
211

    
212
        public void formAfterSave(JDynFormSet dynformSet) {
213
                // TODO Auto-generated method stub
214
                
215
        }
216

    
217
        public void formAfterNew(JDynFormSet dynformSet) {
218
                // TODO Auto-generated method stub
219
                
220
        }
221

    
222
        public void formAfterDelete(JDynFormSet dynformSet) {
223
                // TODO Auto-generated method stub
224
                
225
        }
226

    
227
        public void formAfterSearch(JDynFormSet dynformSet) {
228
                // TODO Auto-generated method stub
229
                
230
        }
231
        
232
}