Revision 539

View differences:

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
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
}
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/StatusLabel.java
33 33
 */
34 34
package org.gvsig.tools.swing.impl.dynobject;
35 35

  
36
import java.awt.BorderLayout;
36 37
import java.awt.Color;
37 38
import java.awt.Component;
38 39
import java.awt.Font;
......
47 48
import javax.swing.JLabel;
48 49
import javax.swing.JPanel;
49 50
import javax.swing.JScrollPane;
51
import javax.swing.JTabbedPane;
50 52
import javax.swing.SwingConstants;
51 53

  
52 54
import org.gvsig.tools.ToolsLocator;
......
61 63
 * whenever the listener is triggered.
62 64
 * 
63 65
 * @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
64
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n  Reinhold</a> -
66
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n Reinhold</a>
67
 *         -
65 68
 *         gvSIG Team
66 69
 * @version $Id$
67 70
 * 
......
88 91

  
89 92
    private DynField dynField;
90 93

  
91
    public StatusLabel(JDynFieldComponent input, JLabel fieldLabel, DynField dynField) {
94
    public StatusLabel(JDynFieldComponent input, JLabel fieldLabel,
95
        DynField dynField) {
92 96
        this.fieldComponent = input;
93 97
        this.fieldLabel = fieldLabel;
94 98
        this.dynField = dynField;
95
        
96
       initUI();
99
        if (dynField == null){
100
            this.dynField = input.getDynField();
101
        }
102

  
103
        initUI();
97 104
    }
98 105

  
99 106
    private void initUI() {
......
103 110
        validationLabel.setIconTextGap(1);
104 111
        validationLabel.setText(" ");
105 112
        validationLabel.setVerticalAlignment(SwingConstants.TOP);
106
        
107
        
113

  
108 114
        validationMessage = new JLabel();
109 115
        validationLabel.setOpaque(true);
110 116
        validationLabel.setText("");
111 117
        validationLabel.setVerticalAlignment(SwingConstants.CENTER);
112
        
118

  
113 119
        fieldLabel.setOpaque(true);
114 120
        fieldLabel.setHorizontalTextPosition(SwingConstants.LEFT);
115 121
        fieldLabel.setHorizontalAlignment(SwingConstants.LEFT);
......
125 131
     * @return
126 132
     */
127 133
    private Icon getIcon(String iconName, String description) {
128
        URL res = this.getClass().getResource(iconName);
129
        if (res == null){
134
        URL res = org.gvsig.tools.swing.impl.dynobject.StatusLabel.class.getResource(iconName);
135
        if (res == null) {
130 136
            return null;
131 137
        }
132 138
        String path = res.getPath();
......
152 158
    public Component getValidationLabel() {
153 159
        return this.fieldLabel;
154 160
    }
155
   
156
    public Component getFieldComponent(){
161

  
162
    public Component getFieldComponent() {
157 163
        JComponent component = this.fieldComponent.asJComponent();
158 164
        component.setName(dynField.getName());
159 165
        return component;
160 166
    }
161
    
162
    public Component getValidationPanel() {
167

  
168
    public Component getValidationPanel(boolean addScrollPane) {
163 169
        if (validationPanel == null) {
164 170
            validationPanel = new JPanel(new GridBagLayout());
171
            validationPanel.setOpaque(true);
165 172

  
166
                GridBagConstraints constr = getValidationPanelConstraints();
167
                validationPanel.setOpaque(true);
173
            GridBagConstraints constr = getValidationPanelConstraints();
174
            constr.weightx = 0.0;
175
            constr.weighty = 0.0;
168 176

  
169
                constr.weightx = 0.0; 
170
                constr.weighty = 0.0; 
171
                constr.gridx = 0; 
172
                constr.gridy = 1; 
173
                constr.fill = GridBagConstraints.NONE;
174
                validationPanel.add(validationLabel, constr);
177
            constr.gridx = 0;
178
            constr.gridy = 1;
179
            constr.fill = GridBagConstraints.NONE;
180
            
181
            validationPanel.add(validationLabel, constr);
175 182

  
183
            constr.weightx = 1.0;
184
            constr.weighty = 0.0;
185
            constr.gridx = 0;
186
            constr.gridy = 0;
187
            if (this.dynField.getType() == DataTypes.LIST) {
188
                constr.gridwidth = 3;
176 189

  
177
                constr.weightx = 1.0; 
178
                constr.weighty = 0.0; 
179
                constr.gridx = 0; 
180
                constr.gridy = 0; 
181
                if(this.dynField.getType()== DataTypes.LIST){
182
                    constr.gridwidth=3;
183
                    
184
                }else{
185
                    constr.gridwidth=2;                    
186
                }
187
//                constr.fill = GridBagConstraints.RELATIVE;
188
                constr.fill = GridBagConstraints.BOTH; 
189
                constr.anchor = GridBagConstraints.NORTHWEST;
190
                validationPanel.add(getFieldComponent(),  constr);
190
            } else {
191
                constr.gridwidth = 2;
192
            }
191 193

  
192
                constr = new GridBagConstraints();
193
                constr.insets = new Insets(1, 2, 2, 2);
194
                constr.gridx = 1; 
195
                constr.gridy = 1; 
196
                constr.ipadx = 5;
197
                constr.ipady = 1;
198
                constr.fill = GridBagConstraints.HORIZONTAL;
199
                constr.anchor = GridBagConstraints.NORTHWEST;
194
            constr.gridwidth = 2;
195
            // constr.fill = GridBagConstraints.RELATIVE;
196
            constr.fill = GridBagConstraints.BOTH;
197
            constr.anchor = GridBagConstraints.NORTHWEST;
198
            
199
            validationPanel.add(getFieldComponent(), constr);
200 200

  
201
                validationPanel.add(validationMessage, constr);
201
            constr = new GridBagConstraints();
202
            constr.insets = new Insets(1, 2, 2, 2);
203
            constr.gridx = 1;
204
            constr.gridy = 1;
205
            constr.ipadx = 5;
206
            constr.ipady = 1;
207
            constr.fill = GridBagConstraints.BOTH;
208
            constr.anchor = GridBagConstraints.NORTHWEST;
209

  
210
            validationPanel.add(validationMessage, constr);
202 211
        }
203
     
204
        JScrollPane jScrollPane = new javax.swing.JScrollPane(); 
205
        JPanel newPanel = new JPanel(new GridBagLayout());
212
        
213
        if (!addScrollPane){
214
            return validationPanel; 
215
        }
216
        
217
        JScrollPane jScrollPane = new javax.swing.JScrollPane();
218
        JPanel newPanel = new JPanel(new BorderLayout());
206 219
        jScrollPane.setViewportView(validationPanel);
207
           
208
        newPanel.add(jScrollPane, getValidationPanelConstraints()); 
220

  
221
        newPanel.add(jScrollPane, BorderLayout.WEST);
209 222
        return newPanel;
210 223
    }
211 224

  
212 225
    private GridBagConstraints getValidationPanelConstraints() {
213 226
        GridBagConstraints constr = new GridBagConstraints();
214 227
        constr.insets = new Insets(2, 2, 2, 2);
215
        constr.weightx = 1.0; 
216
        constr.weighty = 1.0; 
217 228
        constr.ipadx = 2;
218 229
        constr.ipady = 2;
219
        constr.fill = GridBagConstraints.BOTH; 
230
        constr.fill = GridBagConstraints.BOTH;
220 231
        constr.anchor = GridBagConstraints.NORTHWEST;
221
        return constr;    }
232
        return constr;
233
    }
222 234

  
223 235
    /*
224 236
     * (non-Javadoc)
......
243 255

  
244 256
    private String getErrorMessage(JDynFieldComponent field) {
245 257
        String msg = field.getValidationMessage();
246
        if ((field.isMandatory())&&(field.getValue()==null)){
258
        if ((field.isMandatory()) && (field.getValue() == null)) {
247 259
            return translate("Mandatory field. Please insert value.");
248 260
        }
249
        if ((msg == null) ||(msg.equals(""))){
261
        if ((msg == null) || (msg.equals(""))) {
250 262
            return translate("Incompatible type. Not Validated");
251 263
        }
252
        return msg;        
264
        return msg;
253 265
    }
254 266

  
255 267
    private String translate(String message) {
......
257 269
    }
258 270

  
259 271
    private void updateValidationMessageStatus() {
260
        if (validationMessage.getText().equals("")){
272
        if (validationMessage.getText().equals("")) {
261 273
            validationMessage.setVisible(false);
262
        }else{
263
            validationMessage.setVisible(true);            
264
            
274
        } else {
275
            validationMessage.setVisible(true);
276

  
265 277
        }
266 278
    }
267 279
}

Also available in: Unified diff