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 @ 1118
History | View | Annotate | Download (6.77 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.DynField_v2; |
43 |
import org.gvsig.tools.dynobject.DynObject; |
44 |
import org.gvsig.tools.dynobject.DynStruct; |
45 |
import org.gvsig.tools.service.ServiceException; |
46 |
import org.gvsig.tools.service.spi.ServiceManager; |
47 |
|
48 |
public class JDynFormFieldDynObjectList extends AbstractJDynFormField implements JDynFormField, JDynFormListener, JDynFormSetListener, FocusListener { |
49 |
|
50 |
protected List assignedValue = null; |
51 |
protected List currentValue = null; |
52 |
protected JDynFormSet jdynFormSet = null; |
53 |
protected boolean readonly = false; |
54 |
|
55 |
public JDynFormFieldDynObjectList(DynObject parameters,
|
56 |
ServiceManager serviceManager) { |
57 |
super(parameters, serviceManager);
|
58 |
this.assignedValue = (List) this.getParameterValue(); |
59 |
} |
60 |
|
61 |
public void setReadOnly(boolean readonly) { |
62 |
this.readonly = readonly;
|
63 |
if( this.contents != null ) { |
64 |
this.jdynFormSet.setReadOnly(readonly);
|
65 |
} |
66 |
} |
67 |
|
68 |
public Object getAssignedValue() { |
69 |
return this.assignedValue; |
70 |
} |
71 |
|
72 |
public void initComponent() { |
73 |
this.contents = new JPanel(); |
74 |
this.contents.setLayout(new BorderLayout()); |
75 |
try {
|
76 |
DynFormFieldDefinition def = this.getDefinition();
|
77 |
DynField_v2 fielddef = (DynField_v2)def; |
78 |
DynStruct struct = fielddef.getDynClassOfItems(); |
79 |
if(fielddef.getTags().has("ViewMode")){ |
80 |
String name = (String) fielddef.getTags().get("ViewMode"); |
81 |
try{
|
82 |
this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(name,struct);
|
83 |
}catch(Exception e){ |
84 |
logger.warn("Error en la creaci?n del DynFormSet '"+ name +"'" , e); |
85 |
this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(struct);
|
86 |
} |
87 |
}else{
|
88 |
this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(struct);
|
89 |
} |
90 |
this.jdynFormSet.addListener(this); |
91 |
if( fielddef.getTags().has("layoutMode") ) { |
92 |
this.jdynFormSet.setLayoutMode(fielddef.getTags().getInt("layoutMode")); |
93 |
|
94 |
} |
95 |
|
96 |
if( fielddef.getTags().has("allowNew") ) { |
97 |
this.jdynFormSet.setAllowNew(fielddef.getTags().getBoolean("allowNew")); |
98 |
|
99 |
} |
100 |
if( fielddef.getTags().has("allowUpdate") ) { |
101 |
this.jdynFormSet.setAllowUpdate(fielddef.getTags().getBoolean("allowUpdate")); |
102 |
|
103 |
} |
104 |
if( fielddef.getTags().has("allowDelete") ) { |
105 |
this.jdynFormSet.setAllowDelete(fielddef.getTags().getBoolean("allowDelete")); |
106 |
|
107 |
} |
108 |
if( fielddef.getTags().has("allowSearch") ) { |
109 |
this.jdynFormSet.setAllowSearch(fielddef.getTags().getBoolean("allowSearch")); |
110 |
|
111 |
} |
112 |
|
113 |
this.jdynFormSet.setAllowClose(false); |
114 |
this.jdynFormSet.setUseScrollBars(false); |
115 |
// this.jdynFormSet.setShowMessageStatus(false);
|
116 |
// this.jdynFormSet.addListener(this);
|
117 |
this.contents.add(jdynFormSet.asJComponent(),BorderLayout.CENTER); |
118 |
this.contents.setVisible(true); |
119 |
this.jdynFormSet.setReadOnly(readonly);
|
120 |
this.setValue(this.assignedValue); |
121 |
} catch (Exception e) { |
122 |
logger.warn("",e);
|
123 |
} |
124 |
// this.jdynForm.addFocusListener(this);
|
125 |
|
126 |
} |
127 |
|
128 |
|
129 |
public void setValue(Object value) { |
130 |
if( value == null ) { |
131 |
// TODO
|
132 |
// this.jdynForm.clear();
|
133 |
} else {
|
134 |
if( !(value instanceof List) ) { |
135 |
logger.info("setValue invoked with non List value ("+value.toString()+")."); |
136 |
return;
|
137 |
} |
138 |
try {
|
139 |
this.jdynFormSet.setValues((List)value); |
140 |
} catch (ServiceException e) {
|
141 |
logger.warn("Error settings values to DynformSet",e);
|
142 |
} |
143 |
} |
144 |
this.assignedValue = (List) value; |
145 |
this.currentValue = this.assignedValue; |
146 |
} |
147 |
|
148 |
public Object getValue() { |
149 |
return this.currentValue; |
150 |
} |
151 |
|
152 |
public boolean hasValidValue() { |
153 |
return true; |
154 |
} |
155 |
|
156 |
public void focusGained(FocusEvent arg0) { |
157 |
fireFieldEnterEvent(); |
158 |
this.problemIndicator().restore();
|
159 |
} |
160 |
|
161 |
public void focusLost(FocusEvent arg0) { |
162 |
fireFieldExitEvent(); |
163 |
} |
164 |
|
165 |
public void message(String message) { |
166 |
fireMessageEvent(message); |
167 |
} |
168 |
|
169 |
public void fieldChanged(JDynFormField field) { |
170 |
// TODO Auto-generated method stub
|
171 |
|
172 |
} |
173 |
|
174 |
public void formMessage(String message) { |
175 |
// TODO Auto-generated method stub
|
176 |
|
177 |
} |
178 |
|
179 |
public void formClose() { |
180 |
// TODO Auto-generated method stub
|
181 |
|
182 |
} |
183 |
|
184 |
public void formMovedTo(int currentPosition) { |
185 |
// TODO Auto-generated method stub
|
186 |
|
187 |
} |
188 |
|
189 |
public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException { |
190 |
// TODO Auto-generated method stub
|
191 |
|
192 |
} |
193 |
|
194 |
public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException { |
195 |
DynFormFieldDefinition def = this.getDefinition();
|
196 |
DynField_v2 fielddef = (DynField_v2)def; |
197 |
DynStruct struct = fielddef.getDynClassOfItems(); |
198 |
DynObject value = ToolsLocator.getDynObjectManager().createDynObject(struct); |
199 |
this.currentValue.add(value);
|
200 |
|
201 |
|
202 |
} |
203 |
|
204 |
public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException { |
205 |
this.currentValue.remove(dynformSet.getCurrentIndex());
|
206 |
} |
207 |
|
208 |
public void formBeforeSearch(JDynFormSet dynformSet) throws AbortActionException { |
209 |
// TODO Auto-generated method stub
|
210 |
|
211 |
} |
212 |
|
213 |
public void formAfterSave(JDynFormSet dynformSet) { |
214 |
// TODO Auto-generated method stub
|
215 |
|
216 |
} |
217 |
|
218 |
public void formAfterNew(JDynFormSet dynformSet) { |
219 |
// TODO Auto-generated method stub
|
220 |
|
221 |
} |
222 |
|
223 |
public void formAfterDelete(JDynFormSet dynformSet) { |
224 |
// TODO Auto-generated method stub
|
225 |
|
226 |
} |
227 |
|
228 |
public void formAfterSearch(JDynFormSet dynformSet) { |
229 |
// TODO Auto-generated method stub
|
230 |
|
231 |
} |
232 |
|
233 |
} |