Revision 539 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/dynobject/DefaultJDynObjectComponent.java
DefaultJDynObjectComponent.java | ||
---|---|---|
37 | 37 |
import java.util.List; |
38 | 38 |
import java.util.Map; |
39 | 39 |
|
40 |
import javax.swing.BorderFactory; |
|
40 | 41 |
import javax.swing.JComponent; |
41 | 42 |
import javax.swing.JLabel; |
42 | 43 |
import javax.swing.JPanel; |
... | ... | |
50 | 51 |
import org.gvsig.tools.dataTypes.DataTypes; |
51 | 52 |
import org.gvsig.tools.dynobject.DynField; |
52 | 53 |
import org.gvsig.tools.dynobject.DynObject; |
54 |
import org.gvsig.tools.dynobject.DynStruct; |
|
53 | 55 |
import org.gvsig.tools.i18n.I18nManager; |
54 | 56 |
import org.gvsig.tools.service.ServiceException; |
55 | 57 |
import org.gvsig.tools.swing.api.dynobject.DynFieldModel; |
... | ... | |
86 | 88 |
|
87 | 89 |
private int tabPosition; |
88 | 90 |
|
89 |
public DefaultJDynObjectComponent(DynObject dynObject, |
|
91 |
private JPanel firstPanel; |
|
92 |
|
|
93 |
// private String firstGroup; |
|
94 |
|
|
95 |
public DefaultJDynObjectComponent(DynStruct definition, DynObject currentValue, |
|
90 | 96 |
DynObjectModel model, int tabPosition) throws ServiceException { |
91 | 97 |
super(); |
98 |
this.setDynField(definition); |
|
92 | 99 |
this.setModel(model); |
93 |
setDynObject(dynObject);
|
|
100 |
setDynObject(currentValue);
|
|
94 | 101 |
this.tabPosition = tabPosition; |
95 | 102 |
} |
96 | 103 |
|
97 | 104 |
private void initUI(int tabPosition) { |
98 | 105 |
this.labelList = new HashMap<DynField, StatusLabel>(); |
99 |
this.tabPanel = new JTabbedPane(); |
|
100 |
|
|
101 |
// Uncomment the following line to use scrolling tabs. |
|
102 |
this.tabPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); |
|
106 |
if (this.tabPanel == null){ |
|
107 |
this.tabPanel = new JTabbedPane(); |
|
108 |
// Uncomment the following line to use scrolling tabs. |
|
109 |
this.tabPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); |
|
110 |
} |
|
103 | 111 |
this.tabPanel.setTabPlacement(tabPosition); |
104 | 112 |
} |
105 | 113 |
|
... | ... | |
116 | 124 |
JLabel label = new JLabel(text); |
117 | 125 |
boolean isDynObject = |
118 | 126 |
field.getDynField().getType() == DataTypes.DYNOBJECT; |
127 |
boolean isList = |
|
128 |
field.getDynField().getType() == DataTypes.LIST; |
|
119 | 129 |
// Setting component's wrapper |
120 | 130 |
StatusLabel right = |
121 | 131 |
new StatusLabel(input, label, dynField); |
... | ... | |
135 | 145 |
} |
136 | 146 |
int column = -1; |
137 | 147 |
|
138 |
if (input.getDynField().getType() == DataTypes.DYNOBJECT) {
|
|
139 |
column += 1; |
|
140 |
constr.gridx = column; |
|
141 |
constr.ipady = 14; |
|
142 |
constr.fill = GridBagConstraints.NONE; |
|
143 |
constr.weightx = 0; |
|
144 |
constr.ipadx = 2; |
|
145 |
constr.ipady = 2; |
|
148 |
if (isDynObject||isList){
|
|
149 |
// column += 1;
|
|
150 |
// constr.gridx = column;
|
|
151 |
// constr.ipady = 14;
|
|
152 |
// constr.fill = GridBagConstraints.NONE;
|
|
153 |
// constr.weightx = 0;
|
|
154 |
// constr.ipadx = 2;
|
|
155 |
// constr.ipady = 2;
|
|
146 | 156 |
|
147 | 157 |
column += 1; |
148 | 158 |
constr.gridx = column; |
149 | 159 |
constr.gridy = row; |
150 | 160 |
constr.anchor = GridBagConstraints.NORTHWEST; |
161 |
constr.fill = GridBagConstraints.NONE; |
|
151 | 162 |
panel.add(right.getValidationLabel(), constr); |
152 | 163 |
|
153 | 164 |
column += 1; |
154 | 165 |
constr.gridx = column; |
155 | 166 |
constr.ipady = 2; |
156 |
constr.weightx = 1;
|
|
167 |
constr.weightx = 4;
|
|
157 | 168 |
constr.fill = GridBagConstraints.HORIZONTAL; |
158 |
panel.add(right.getValidationPanel(), constr); |
|
169 |
constr.anchor = GridBagConstraints.NORTHWEST; |
|
170 |
constr.gridwidth = 2; |
|
171 |
if (isDynObject){ |
|
172 |
constr.gridwidth = 4; |
|
173 |
} |
|
174 |
panel.add(right.getValidationPanel(isDynObject), constr); |
|
159 | 175 |
// panel.add(new JScrollPane(input.asJComponent()), constr); |
160 | 176 |
|
161 | 177 |
} else { |
... | ... | |
166 | 182 |
constr.gridy = row; |
167 | 183 |
|
168 | 184 |
if (!isDynObject) { |
169 |
column += 1; |
|
185 |
// column += 1;
|
|
170 | 186 |
constr.gridx = column; |
171 | 187 |
|
172 | 188 |
panel.add(label, constr); |
... | ... | |
189 | 205 |
|
190 | 206 |
constr.gridx = column; |
191 | 207 |
constr.ipady = 2; |
192 |
constr.weightx = 1;
|
|
208 |
constr.weightx = 2;
|
|
193 | 209 |
constr.fill = GridBagConstraints.HORIZONTAL; |
194 | 210 |
constr.anchor = GridBagConstraints.NORTHWEST; |
195 |
panel.add(right.getValidationPanel(), constr); |
|
211 |
panel.add(right.getValidationPanel(false), constr);
|
|
196 | 212 |
} |
197 | 213 |
|
198 | 214 |
Component component = right.getFieldComponent(); |
199 |
addComponentToList(component, input); |
|
215 |
this.getSelectedComponents().addComponentToList(component, input);
|
|
200 | 216 |
|
201 | 217 |
input.fireValueChangedEvent(); |
202 | 218 |
} |
... | ... | |
235 | 251 |
*/ |
236 | 252 |
public JComponent asJComponent() { |
237 | 253 |
try { |
238 |
|
|
239 |
initUI(tabPosition); |
|
240 | 254 |
this.load(getDynObject()); |
241 | 255 |
} catch (ServiceException e) { |
242 | 256 |
// TODO Auto-generated catch block |
243 | 257 |
e.printStackTrace(); |
244 | 258 |
} |
259 |
if (tabPanel.getTabCount()==1){ |
|
260 |
this.tabPanel.removeAll(); |
|
261 |
// tabPanel.remove(0); |
|
262 |
return firstPanel; |
|
263 |
} |
|
245 | 264 |
return this.tabPanel; |
246 | 265 |
} |
247 |
|
|
248 | 266 |
private StatusLabel getFieldLabel(DynField field) { |
249 | 267 |
return this.labelList.get(field); |
250 | 268 |
} |
... | ... | |
252 | 270 |
protected void addParametersFromModel() throws ServiceException { |
253 | 271 |
DynField field; |
254 | 272 |
JPanel pane; |
255 |
if (!this.hasDynObject()){ |
|
256 |
for (int index = 0;index<this.tabPanel.getTabCount();index++){ |
|
257 |
this.tabPanel.remove(index); |
|
258 |
} |
|
273 |
if (getDefinition()== null){ |
|
259 | 274 |
return; |
260 | 275 |
} |
261 | 276 |
|
277 |
if (this.tabPanel == null){ |
|
278 |
initUI(tabPosition); |
|
279 |
} |
|
280 |
if (this.tabPanel.getTabCount()>0){ |
|
281 |
return; |
|
282 |
} |
|
283 |
// for (int index = 0;index<this.tabPanel.getTabCount();index++){ |
|
284 |
// this.tabPanel.remove(index); |
|
285 |
// } |
|
286 |
// if (!this.hasDynObject()){ |
|
287 |
// return; |
|
288 |
// } |
|
289 |
|
|
290 |
|
|
262 | 291 |
String[] groups = this.getModel().getGroups(); |
263 | 292 |
|
264 | 293 |
|
... | ... | |
266 | 295 |
List<DynFieldModel> items = this.getModel().getGroupElements(group); |
267 | 296 |
|
268 | 297 |
pane = new JPanel(new GridBagLayout()); |
269 |
|
|
270 |
pane.setName(this.getDynObject().getDynClass().getName());
|
|
298 |
pane.setBorder(BorderFactory.createTitledBorder("rightPanel border: " + this.getDefinition().getName())); |
|
299 |
pane.setName(this.getDefinition().getName());
|
|
271 | 300 |
for (int i = 0; i < items.size(); i++) { |
272 | 301 |
field = items.get(i).getDynField(); |
273 | 302 |
addGridBagComponent( |
274 | 303 |
pane, |
275 |
new DynObjectValueField(this.getDynObject(), field |
|
304 |
new DynObjectValueField(this.getDefinition(), this.getDynObject(), field
|
|
276 | 305 |
.getName()), i, items.size()); |
277 | 306 |
} |
278 | 307 |
// this.tabPanel.addTab(group, pane); |
279 | 308 |
// JPanel borderPane = new JPanel(new BorderLayout()); |
280 | 309 |
// borderPane.add(pane, BorderLayout.WEST); |
310 |
if (firstPanel == null){ |
|
311 |
firstPanel = pane; |
|
312 |
} |
|
281 | 313 |
this.tabPanel.addTab(group, new JScrollPane(pane)); |
282 | 314 |
} |
283 | 315 |
} |
... | ... | |
328 | 360 |
* .lang.Object) |
329 | 361 |
*/ |
330 | 362 |
public void setValue(Object value) { |
331 |
if (value != null) { |
|
332 |
if (value instanceof DynObject) { |
|
333 |
fillValues((DynObject) value); |
|
334 |
} |
|
335 |
return; |
|
336 |
} |
|
337 |
this.emptyAll(); |
|
363 |
fillValues((DynObject) value); |
|
338 | 364 |
} |
339 | 365 |
|
340 | 366 |
public DynField getDynField() { |
... | ... | |
352 | 378 |
public void setFieldValue(Object value) { |
353 | 379 |
input.setFieldValue(value); |
354 | 380 |
} |
381 |
|
|
382 |
public DynField getParentDynField() { |
|
383 |
// TODO Auto-generated method stub |
|
384 |
return null; |
|
385 |
} |
|
355 | 386 |
|
356 | 387 |
} |
Also available in: Unified diff