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

History | View | Annotate | Download (4.16 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
                        this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(struct);
77
                        if( fielddef.hasTag("layoutMode") ) {
78
                                this.jdynFormSet.setLayoutMode(fielddef.getTagInt("layoutMode"));
79
                        }
80
                        this.jdynFormSet.setUseScrollBars(false);
81
//                        this.jdynFormSet.setShowMessageStatus(false);
82
//                        this.jdynFormSet.addListener(this);
83
                        this.contents.add(jdynFormSet.asJComponent(),BorderLayout.CENTER);
84
                        this.contents.setVisible(true);
85
                        this.jdynFormSet.setReadOnly(readonly);
86
                        this.setValue(this.assignedValue);
87
                } catch (Exception e) {
88
                        // TODO Auto-generated catch block
89
                        e.printStackTrace();
90
                }
91
//                this.jdynForm.addFocusListener(this);
92

    
93
        }
94
        
95
        
96
        public void setValue(Object value) {
97
                if( value == null ) {
98
                        // TODO
99
                        // this.jdynForm.clear();
100
                } else {
101
                        if( !(value instanceof DynObject) ) {
102
                                logger.info("setValue invoked with non DynObject value ("+value.toString()+").");
103
                                return;
104
                        }
105
                        try {
106
                                this.jdynFormSet.setValues((List)value);
107
                        } catch (ServiceException e) {
108
                                // TODO Auto-generated catch block
109
                                e.printStackTrace();
110
                        }
111
                }
112
                this.assignedValue = (List) value;
113
                this.currentValue = this.assignedValue;
114
        }
115
        
116
        public Object getValue() {
117
                return this.currentValue;
118
        }
119
        
120
        public boolean hasValidValue() {
121
                return true;
122
        }
123

    
124
        public void focusGained(FocusEvent arg0) {
125
                fireFieldEnterEvent();
126
                this.problemIndicator().restore();
127
        }
128

    
129
        public void focusLost(FocusEvent arg0) {
130
                fireFieldExitEvent();
131
        }
132

    
133
        public void message(String message) {
134
                fireMessageEvent(message);
135
        }
136
        
137
}