Revision 270 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.spi/src/main/java/org/gvsig/tools/swing/spi/AbstractDynObjectComponent.java
AbstractDynObjectComponent.java | ||
---|---|---|
55 | 55 |
* |
56 | 56 |
*/ |
57 | 57 |
public abstract class AbstractDynObjectComponent implements |
58 |
JDynObjectComponent, ValueField {
|
|
58 |
JDynObjectComponent, ValueField {
|
|
59 | 59 |
|
60 | 60 |
private static final long serialVersionUID = 4088620749911859250L; |
61 | 61 |
|
... | ... | |
74 | 74 |
* the {@link DynObject} to render |
75 | 75 |
*/ |
76 | 76 |
public AbstractDynObjectComponent(DynObject dynObject, DynObjectModel model) { |
77 |
this.dynObject = dynObject; |
|
78 |
if (model == null) |
|
79 |
try { |
|
80 |
this.model = ToolsSwingLocator.getDynObjectSwingManager() |
|
81 |
.createDynObjectModel(this.dynObject.getDynClass()); |
|
82 |
} catch (ServiceException e) { |
|
83 |
// TODO Auto-generated catch block |
|
84 |
e.printStackTrace(); |
|
85 |
} |
|
86 |
else |
|
87 |
this.model = model; |
|
88 |
manager = ToolsSwingLocator.getDynObjectSwingManager(); |
|
77 |
this.dynObject = dynObject; |
|
78 |
if (model == null) |
|
79 |
try { |
|
80 |
this.model = |
|
81 |
ToolsSwingLocator.getDynObjectSwingManager() |
|
82 |
.createDynObjectModel(this.dynObject.getDynClass()); |
|
83 |
} catch (ServiceException e) { |
|
84 |
// TODO Auto-generated catch block |
|
85 |
e.printStackTrace(); |
|
86 |
} |
|
87 |
else |
|
88 |
this.model = model; |
|
89 |
manager = ToolsSwingLocator.getDynObjectSwingManager(); |
|
89 | 90 |
} |
90 | 91 |
|
91 | 92 |
protected void addComponentToList(Component component, |
92 |
JDynFieldComponent input) {
|
|
93 |
this.getComponents().put(component, input);
|
|
93 |
JDynFieldComponent input) {
|
|
94 |
this.getComponents().put(component, input);
|
|
94 | 95 |
} |
95 | 96 |
|
96 | 97 |
private Map<Component, JDynFieldComponent> getComponents() { |
97 |
if (componentField == null) {
|
|
98 |
componentField = new HashMap<Component, JDynFieldComponent>();
|
|
99 |
}
|
|
100 |
return componentField;
|
|
98 |
if (componentField == null) {
|
|
99 |
componentField = new HashMap<Component, JDynFieldComponent>();
|
|
100 |
}
|
|
101 |
return componentField;
|
|
101 | 102 |
|
102 | 103 |
} |
103 | 104 |
|
... | ... | |
108 | 109 |
* org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getDefaultValue() |
109 | 110 |
*/ |
110 | 111 |
public Object getDefaultValue() { |
111 |
return this.getDynObject();
|
|
112 |
return this.getDynObject();
|
|
112 | 113 |
} |
113 | 114 |
|
114 | 115 |
/* |
... | ... | |
118 | 119 |
* org.gvsig.tools.swing.impl.dynobject.JDynbjectComponent#getDynObject() |
119 | 120 |
*/ |
120 | 121 |
public DynObject getDynObject() { |
121 |
return dynObject;
|
|
122 |
return dynObject;
|
|
122 | 123 |
} |
123 | 124 |
|
124 | 125 |
protected JDynFieldComponent getJDynFieldComponent(DynField field) |
125 |
throws ServiceException {
|
|
126 |
return this.getJDynFieldComponent(field, null);
|
|
126 |
throws ServiceException {
|
|
127 |
return this.getJDynFieldComponent(field, null);
|
|
127 | 128 |
} |
128 | 129 |
|
129 | 130 |
/** |
... | ... | |
131 | 132 |
* @throws ServiceException |
132 | 133 |
*/ |
133 | 134 |
protected JDynFieldComponent getJDynFieldComponent(DynField field, |
134 |
ValueChangedListener listener) throws ServiceException { |
|
135 |
ValueField valueItem = new DynObjectValueField(this.getDynObject(), |
|
136 |
field.getName()); |
|
137 |
JDynFieldComponent jfield = ((DynObjectSwingManager) this.getManager()) |
|
138 |
.createJDynFieldComponent(valueItem, field); |
|
139 |
if (listener != null) { |
|
140 |
jfield.addValueChangedListener(this); |
|
141 |
jfield.fireValueChangedEvent(); |
|
142 |
} |
|
143 |
return jfield; |
|
135 |
ValueChangedListener listener) throws ServiceException { |
|
136 |
ValueField valueItem = |
|
137 |
new DynObjectValueField(this.getDynObject(), field.getName()); |
|
138 |
JDynFieldComponent jfield = |
|
139 |
((DynObjectSwingManager) this.getManager()) |
|
140 |
.createJDynFieldComponent(valueItem, field); |
|
141 |
if (listener != null) { |
|
142 |
jfield.addValueChangedListener(this); |
|
143 |
jfield.fireValueChangedEvent(); |
|
144 |
} |
|
145 |
return jfield; |
|
144 | 146 |
} |
145 | 147 |
|
146 | 148 |
/* |
... | ... | |
149 | 151 |
* @see org.gvsig.tools.service.Service#getManager() |
150 | 152 |
*/ |
151 | 153 |
public Manager getManager() { |
152 |
return manager;
|
|
154 |
return manager;
|
|
153 | 155 |
} |
154 | 156 |
|
155 | 157 |
/* |
... | ... | |
158 | 160 |
* @see org.gvsig.tools.swing.impl.dynobject.JDynbjectComponent#getModel() |
159 | 161 |
*/ |
160 | 162 |
public DynObjectModel getModel() { |
161 |
return model;
|
|
163 |
return model;
|
|
162 | 164 |
} |
163 | 165 |
|
164 | 166 |
public Object getValue() { |
165 |
return this.getDynObject();
|
|
167 |
return this.getDynObject();
|
|
166 | 168 |
} |
167 | 169 |
|
168 | 170 |
public boolean isValid() { |
169 |
Map<Component, JDynFieldComponent> items = this.getComponents();
|
|
170 |
for (JDynFieldComponent item : items.values()) {
|
|
171 |
if (!this.isValid(item))
|
|
172 |
return false;
|
|
173 |
}
|
|
174 |
return true;
|
|
171 |
Map<Component, JDynFieldComponent> items = this.getComponents();
|
|
172 |
for (JDynFieldComponent item : items.values()) {
|
|
173 |
if (!this.isValid(item))
|
|
174 |
return false;
|
|
175 |
}
|
|
176 |
return true;
|
|
175 | 177 |
} |
176 |
|
|
178 |
|
|
177 | 179 |
/** |
178 | 180 |
* |
179 | 181 |
*/ |
180 | 182 |
protected void emptyAll() { |
181 |
Map<Component, JDynFieldComponent> items = this.getComponents();
|
|
182 |
for (JDynFieldComponent item : items.values())
|
|
183 |
item.setValue(null);
|
|
183 |
Map<Component, JDynFieldComponent> items = this.getComponents();
|
|
184 |
for (JDynFieldComponent item : items.values())
|
|
185 |
item.setValue(null);
|
|
184 | 186 |
} |
185 | 187 |
|
186 | 188 |
/** |
187 | 189 |
* @param value |
188 | 190 |
*/ |
189 | 191 |
protected void fillValues(DynObject dynObject) { |
190 |
Map<Component, JDynFieldComponent> items = this.getComponents();
|
|
191 |
for (JDynFieldComponent item : items.values())
|
|
192 |
item.setValue(dynObject.getDynValue(item.getDynField().getName()));
|
|
192 |
Map<Component, JDynFieldComponent> items = this.getComponents();
|
|
193 |
for (JDynFieldComponent item : items.values())
|
|
194 |
item.setValue(dynObject.getDynValue(item.getDynField().getName()));
|
|
193 | 195 |
} |
194 | 196 |
|
195 | 197 |
/** |
... | ... | |
199 | 201 |
protected abstract boolean isValid(JDynFieldComponent component); |
200 | 202 |
|
201 | 203 |
public void saveStatus() { |
202 |
Iterator<JDynFieldComponent> componentFields = this.getComponents()
|
|
203 |
.values().iterator();
|
|
204 |
JDynFieldComponent comp;
|
|
205 |
while (componentFields.hasNext()) {
|
|
206 |
comp = componentFields.next();
|
|
207 |
comp.saveStatus();
|
|
208 |
}
|
|
204 |
Iterator<JDynFieldComponent> componentFields =
|
|
205 |
this.getComponents().values().iterator();
|
|
206 |
JDynFieldComponent comp;
|
|
207 |
while (componentFields.hasNext()) {
|
|
208 |
comp = componentFields.next();
|
|
209 |
comp.saveStatus();
|
|
210 |
}
|
|
209 | 211 |
} |
210 |
|
|
211 | 212 |
|
212 |
|
|
213 |
/* (non-Javadoc) |
|
214 |
* @see org.gvsig.tools.swing.api.dynobject.JDynObjectComponent#addValueChangedListener(org.gvsig.tools.swing.api.dynobject.ValueChangedListener) |
|
213 |
/* |
|
214 |
* (non-Javadoc) |
|
215 |
* |
|
216 |
* @seeorg.gvsig.tools.swing.api.dynobject.JDynObjectComponent# |
|
217 |
* addValueChangedListener |
|
218 |
* (org.gvsig.tools.swing.api.dynobject.ValueChangedListener) |
|
215 | 219 |
*/ |
216 | 220 |
public void addValueChangedListener(ValueChangedListener listener) { |
217 |
Iterator<JDynFieldComponent> componentFields = this.getComponents()
|
|
218 |
.values().iterator();
|
|
219 |
JDynFieldComponent comp;
|
|
220 |
while (componentFields.hasNext()) {
|
|
221 |
comp = componentFields.next();
|
|
222 |
comp.addValueChangedListener(listener);
|
|
223 |
} |
|
221 |
Iterator<JDynFieldComponent> componentFields =
|
|
222 |
this.getComponents().values().iterator();
|
|
223 |
JDynFieldComponent comp;
|
|
224 |
while (componentFields.hasNext()) {
|
|
225 |
comp = componentFields.next();
|
|
226 |
comp.addValueChangedListener(listener);
|
|
227 |
}
|
|
224 | 228 |
} |
225 | 229 |
|
226 | 230 |
} |
Also available in: Unified diff