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

History | View | Annotate | Download (4.61 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.dynform.DynFormFieldDefinition;
34
import org.gvsig.tools.dynform.DynFormLocator;
35
import org.gvsig.tools.dynform.JDynForm.JDynFormListener;
36
import org.gvsig.tools.dynform.JDynFormField;
37
import org.gvsig.tools.dynform.JDynFormSet;
38
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
39
import org.gvsig.tools.dynobject.DynField_v2;
40
import org.gvsig.tools.dynobject.DynObject;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.service.ServiceException;
43
import org.gvsig.tools.service.spi.ServiceManager;
44

    
45
public class JDynFormFieldDynObjectList extends AbstractJDynFormField implements JDynFormField, JDynFormListener, FocusListener {
46
        
47
        protected List assignedValue  = null;
48
        protected List currentValue = null;
49
        protected JDynFormSet jdynFormSet = null;
50
        protected boolean readonly = false;
51

    
52
        public JDynFormFieldDynObjectList(DynObject parameters,
53
                        ServiceManager serviceManager) {
54
                super(parameters, serviceManager);
55
                this.assignedValue = (List) this.getParameterValue();
56
        }
57

    
58
        public void setReadOnly(boolean readonly) {
59
                this.readonly = readonly;
60
                if( this.contents != null ) {
61
                        this.jdynFormSet.setReadOnly(readonly);
62
                }
63
        }
64
        
65
        public Object getAssignedValue() {
66
                return this.assignedValue;
67
        }
68
        
69
        public void initComponent() {
70
                this.contents = new JPanel();
71
                this.contents.setLayout(new BorderLayout());
72
                try {
73
                        DynFormFieldDefinition def = this.getDefinition();
74
                        DynField_v2 fielddef = (DynField_v2)def;
75
                        DynStruct struct = fielddef.getStructWhenTypeIsDynObject();
76
                        if(fielddef.getTags().has("ViewMode")){
77
                                String name = (String) fielddef.getTags().get("ViewMode");
78
                                try{
79
                                        this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(name,struct);
80
                                }catch(Exception e){
81
                                        logger.warn("Error en la creaci?n del DynFormSet '"+ name +"'" , e);
82
                                        this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(struct);
83
                                }
84
                        }else{
85
                                this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(struct);
86
                        }
87
                        if( fielddef.getTags().has("layoutMode") ) {
88
                                this.jdynFormSet.setLayoutMode(fielddef.getTags().getInt("layoutMode"));
89
                        }
90
                        this.jdynFormSet.setUseScrollBars(false);
91
//                        this.jdynFormSet.setShowMessageStatus(false);
92
//                        this.jdynFormSet.addListener(this);
93
                        this.contents.add(jdynFormSet.asJComponent(),BorderLayout.CENTER);
94
                        this.contents.setVisible(true);
95
                        this.jdynFormSet.setReadOnly(readonly);
96
                        this.setValue(this.assignedValue);
97
                } catch (Exception e) {
98
                        logger.warn("",e);
99
                }
100
//                this.jdynForm.addFocusListener(this);
101

    
102
        }
103
        
104
        
105
        public void setValue(Object value) {
106
                if( value == null ) {
107
                        // TODO
108
                        // this.jdynForm.clear();
109
                } else {
110
                        if( !(value instanceof List) ) {
111
                                logger.info("setValue invoked with non List value ("+value.toString()+").");
112
                                return;
113
                        }
114
                        try {
115
                                this.jdynFormSet.setValues((List)value);
116
                        } catch (ServiceException e) {
117
                                logger.warn("Error settings values to DynformSet",e);
118
                        }
119
                }
120
                this.assignedValue = (List) value;
121
                this.currentValue = this.assignedValue;
122
        }
123
        
124
        public Object getValue() {
125
                return this.currentValue;
126
        }
127
        
128
        public boolean hasValidValue() {
129
                return true;
130
        }
131

    
132
        public void focusGained(FocusEvent arg0) {
133
                fireFieldEnterEvent();
134
                this.problemIndicator().restore();
135
        }
136

    
137
        public void focusLost(FocusEvent arg0) {
138
                fireFieldExitEvent();
139
        }
140

    
141
        public void message(String message) {
142
                fireMessageEvent(message);
143
        }
144

    
145
        public void fieldChanged(JDynFormField field) {
146
                // TODO Auto-generated method stub
147
                
148
        }
149
        
150
}