Revision 1405 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

View differences:

JDynFormFieldDynObjectList.java
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 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.
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10 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.
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15 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.
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
package org.gvsig.tools.dynform.services.dynformfield.DynObjectList;
25 24

  
......
38 37
import org.gvsig.tools.dynform.JDynFormField;
39 38
import org.gvsig.tools.dynform.JDynFormSet;
40 39
import org.gvsig.tools.dynform.JDynFormSet.JDynFormSetListener;
40
import org.gvsig.tools.dynform.spi.AbstractJDynForm;
41
import org.gvsig.tools.dynform.spi.AbstractJDynFormSet;
42
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
41 43
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
42
import org.gvsig.tools.dynobject.DynClass;
43 44
import org.gvsig.tools.dynobject.DynField;
44 45
import org.gvsig.tools.dynobject.DynField_v2;
45 46
import org.gvsig.tools.dynobject.DynObject;
......
48 49
import org.gvsig.tools.service.spi.ServiceManager;
49 50

  
50 51
public class JDynFormFieldDynObjectList extends AbstractJDynFormField implements JDynFormField, JDynFormListener, JDynFormSetListener, FocusListener {
51
	
52
	protected List assignedValue  = null;
53
	protected List currentValue = null;
54
	protected JDynFormSet jdynFormSet = null;
55
	protected boolean readonly = false;
56 52

  
57
	public JDynFormFieldDynObjectList(DynObject parameters,
58
			ServiceManager serviceManager) {
59
		super(parameters, serviceManager);
60
		this.assignedValue = (List) this.getParameterValue();
61
	}
53
    protected List assignedValue = null;
54
    protected List currentValue = null;
55
    protected AbstractJDynFormSet jdynFormSet = null;
56
    protected boolean readonly = false;
62 57

  
63
	public void setReadOnly(boolean readonly) {
64
		super.setReadOnly(readonly);
65
		if( this.contents != null ) {
66
			this.jdynFormSet.setReadOnly(readonly);
67
		}
68
	}
69
	
70
	public Object getAssignedValue() {
71
		return this.assignedValue;
72
	}
73
	
74
	public void initComponent() {
75
		this.contents = new JPanel();
76
		this.contents.setLayout(new BorderLayout());
77
		try {
78
			DynFormFieldDefinition def = this.getDefinition();
79
			DynField_v2 fielddef = (DynField_v2)def;
80
			DynStruct struct = fielddef.getDynClassOfItems();
81
                        String viewMode = getTagValueAsString("ViewMode", "dynform.viewmode", "Subform");
82
                        try{
83
                                this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(viewMode,struct);
84
                        } catch(Exception e){
85
                                logger.warn("Error en la creaci?n del DynFormSet '"+ viewMode +"'" , e);
86
                                this.jdynFormSet = DynFormLocator.getDynFormManager().createJDynFormSet(struct);
87
                        }
58
    public JDynFormFieldDynObjectList(DynObject parameters,
59
            ServiceManager serviceManager) {
60
        super(parameters, serviceManager);
61
        this.assignedValue = (List) this.getParameterValue();
62
    }
88 63

  
89
                        int height = getTagValueAsInt("dynform.height", -1);
90
                        if( height>0 ) {
91
                            this.jdynFormSet.setFormSize(50,height); 
92
                        }
64
    public void setReadOnly(boolean readonly) {
65
        super.setReadOnly(readonly);
66
        if (this.contents != null) {
67
            this.jdynFormSet.setReadOnly(readonly);
68
        }
69
    }
93 70

  
94
                        this.jdynFormSet.addListener(this);
95
                        this.jdynFormSet.setLayoutMode(getTagValueAsInt("layoutMode", "dynform.layoutmode",JDynFormSet.USE_PLAIN));
96
                        this.jdynFormSet.setAllowNew(getTagValueAsBoolean("allowNew", "dynform.action.new", false));
97
                        this.jdynFormSet.setAllowUpdate(getTagValueAsBoolean("allowUpdate", "dynform.action.update", false));
98
                        this.jdynFormSet.setAllowDelete(getTagValueAsBoolean("allowDelete", "dynform.action.delete", false));
99
                        this.jdynFormSet.setAllowSearch(getTagValueAsBoolean("allowSearch", "dynform.action.search", false));
100
			this.jdynFormSet.setAllowClose(false);
101
			this.jdynFormSet.setUseScrollBars(false);
102
//			this.jdynFormSet.setShowMessageStatus(false);
103
//			this.jdynFormSet.addListener(this);
104
			this.contents.add(jdynFormSet.asJComponent(),BorderLayout.CENTER);
105
			this.contents.setVisible(true);
106
			this.jdynFormSet.setReadOnly(readonly);
107
			this.setValue(this.assignedValue);
108
		} catch (Exception e) {
109
			logger.warn("",e);
110
		}
71
    public Object getAssignedValue() {
72
        return this.assignedValue;
73
    }
74

  
75
    public void initComponent() {
76
        this.contents = new JPanel();
77
        this.contents.setLayout(new BorderLayout());
78
        try {
79
            DynFormFieldDefinition def = this.getDefinition();
80
            DynField_v2 fielddef = (DynField_v2) def;
81
            DynStruct struct = fielddef.getDynClassOfItems();
82
            String viewMode = getTagValueAsString("ViewMode", DynFormSPIManager.TAG_DYNFORM_VIEWMODE, "Subform");
83
            try {
84
                this.jdynFormSet = (AbstractJDynFormSet) DynFormLocator.getDynFormManager().createJDynFormSet(viewMode, struct);
85
            } catch (Exception e) {
86
                logger.warn("Error en la creaci?n del DynFormSet '" + viewMode + "'", e);
87
                this.jdynFormSet = (AbstractJDynFormSet) DynFormLocator.getDynFormManager().createJDynFormSet(struct);
88
            }
89
            this.jdynFormSet.loadDefaultValueFromTags(this.getDefinition().getTags());
90

  
91
//            int height = getTagValueAsInt(DynFormSPIManager.TAG_DYNFORM_HEIGHT, -1);
92
//            if (height > 0) {
93
//                this.jdynFormSet.setFormSize(50, height);
94
//            }
95

  
96
            this.jdynFormSet.addListener(this);
97
            this.contents.add(jdynFormSet.asJComponent(), BorderLayout.CENTER);
98
            this.contents.setVisible(true);
99
            this.setValue(this.assignedValue);
100
        } catch (Exception e) {
101
            logger.warn("", e);
102
        }
111 103
//		this.jdynForm.addFocusListener(this);
112 104

  
113
	}
114
	
115
	
116
	public void setValue(Object value) {
117
		if( value == null ) {
105
    }
106

  
107
    public void setValue(Object value) {
108
        if (value == null) {
118 109
			// TODO
119
			// this.jdynForm.clear();
120
		} else {
121
			if( !(value instanceof List) ) {
122
				logger.info("setValue invoked with non List value ("+value.toString()+").");
123
				return;
124
			}
125
			try {
126
				this.jdynFormSet.setValues((List)value);
127
			} catch (ServiceException e) {
128
				logger.warn("Error settings values to DynformSet",e);
129
			}
130
		}
131
		this.assignedValue = (List) value;
132
		this.currentValue = this.assignedValue;
133
	}
134
	
135
	public Object getValue() {
136
		return this.jdynFormSet.getValues();
137
	}
138
	
139
	public boolean hasValidValue() {
140
		return this.jdynFormSet.hasValidValues();
141
	}
110
            // this.jdynForm.clear();
111
        } else {
112
            if (!(value instanceof List)) {
113
                logger.info("setValue invoked with non List value (" + value.toString() + ").");
114
                return;
115
            }
116
            try {
117
                this.jdynFormSet.setValues((List) value);
118
            } catch (ServiceException e) {
119
                logger.warn("Error settings values to DynformSet", e);
120
            }
121
        }
122
        this.assignedValue = (List) value;
123
        this.currentValue = this.assignedValue;
124
    }
142 125

  
143
	public void focusGained(FocusEvent arg0) {
144
		fireFieldEnterEvent();
145
		this.problemIndicator().restore();
146
	}
126
    public Object getValue() {
127
        return this.jdynFormSet.getValues();
128
    }
147 129

  
148
	public void focusLost(FocusEvent arg0) {
149
		fireFieldExitEvent();
150
	}
130
    public boolean hasValidValue() {
131
        return this.jdynFormSet.hasValidValues();
132
    }
151 133

  
152
	public void message(String message) {
153
		fireMessageEvent(message);
154
	}
134
    public void focusGained(FocusEvent arg0) {
135
        fireFieldEnterEvent();
136
        this.problemIndicator().restore();
137
    }
155 138

  
156
	public void fieldChanged(JDynFormField field) {
139
    public void focusLost(FocusEvent arg0) {
140
        fireFieldExitEvent();
141
    }
142

  
143
    public void message(String message) {
144
        fireMessageEvent(message);
145
    }
146

  
147
    public void fieldChanged(JDynFormField field) {
157 148
		// TODO Auto-generated method stub
158
		
159
	}
160 149

  
161
	public void formMessage(String message) {
150
    }
151

  
152
    public void formMessage(String message) {
162 153
		// TODO Auto-generated method stub
163
		
164
	}
165 154

  
166
	public void formClose() {
155
    }
156

  
157
    public void formClose() {
167 158
		// TODO Auto-generated method stub
168
		
169
	}
170 159

  
171
	public void formMovedTo(int currentPosition) {
160
    }
161

  
162
    public void formMovedTo(int currentPosition) {
172 163
		// TODO Auto-generated method stub
173
		
174
	}
175 164

  
176
	public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException {
165
    }
166

  
167
    public void formBeforeSave(JDynFormSet dynformSet) throws AbortActionException {
177 168
		// TODO Auto-generated method stub
178
		
179
	}
180 169

  
181
	public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException {
182
		DynFormFieldDefinition def = this.getDefinition();
183
		DynField_v2 fielddef = (DynField_v2)def;
184
		DynStruct struct = fielddef.getDynClassOfItems();
185
		DynObject value = createDynObject(struct);
186
		this.currentValue.add(value);
170
    }
187 171

  
188
		
189
	}
190
	
191
	private DynObject createDynObject(DynStruct dynStruct){
192
		DynObject value = ToolsLocator.getDynObjectManager().createDynObject(dynStruct);
193
		DynField[] fields = dynStruct.getDynFields();
194
		for(int i=0;i<fields.length; i++){
195
			DynField_v2 field = (DynField_v2) fields[i];
196
			if(field.getDataType().isDynObject()){
197
				value.setDynValue(field.getName(), createDynObject(field.getDynClassOfValue()));
198
			}
199
		}
200
		return value;
201
	}
172
    public void formBeforeNew(JDynFormSet dynformSet) throws AbortActionException {
173
        DynFormFieldDefinition def = this.getDefinition();
174
        DynField_v2 fielddef = (DynField_v2) def;
175
        DynStruct struct = fielddef.getDynClassOfItems();
176
        DynObject value = createDynObject(struct);
177
        this.currentValue.add(value);
178
    }
202 179

  
203
	public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException {
204
		this.currentValue.remove(dynformSet.getCurrentIndex());
205
	}
180
    public void formBeforeCancelNew(JDynFormSet dynformSet) throws AbortActionException {
181
		// TODO Auto-generated method stub
206 182

  
207
	public void formBeforeSearch(JDynFormSet dynformSet) throws AbortActionException {
183
    }
184

  
185
    private DynObject createDynObject(DynStruct dynStruct) {
186
        DynObject value = ToolsLocator.getDynObjectManager().createDynObject(dynStruct);
187
        DynField[] fields = dynStruct.getDynFields();
188
        for (int i = 0; i < fields.length; i++) {
189
            DynField_v2 field = (DynField_v2) fields[i];
190
            if (field.getDataType().isDynObject()) {
191
                value.setDynValue(field.getName(), createDynObject(field.getDynClassOfValue()));
192
            }
193
        }
194
        return value;
195
    }
196

  
197
    public void formBeforeDelete(JDynFormSet dynformSet) throws AbortActionException {
198
        this.currentValue.remove(dynformSet.getCurrentIndex());
199
    }
200

  
201
    public void formBeforeSearch(JDynFormSet dynformSet) throws AbortActionException {
208 202
		// TODO Auto-generated method stub
209
		
210
	}
211 203

  
212
	public void formAfterSave(JDynFormSet dynformSet) {
204
    }
205

  
206
    public void formAfterSave(JDynFormSet dynformSet) {
213 207
		// TODO Auto-generated method stub
214
		
215
	}
216 208

  
217
	public void formAfterNew(JDynFormSet dynformSet) {
209
    }
210

  
211
    public void formAfterNew(JDynFormSet dynformSet) {
218 212
		// TODO Auto-generated method stub
219
		
220
	}
221 213

  
222
	public void formAfterDelete(JDynFormSet dynformSet) {
214
    }
215

  
216
    public void formAfterCancelNew(JDynFormSet dynformSet) {
223 217
		// TODO Auto-generated method stub
224
		
225
	}
226 218

  
227
	public void formAfterSearch(JDynFormSet dynformSet) {
219
    }
220

  
221
    public void formAfterDelete(JDynFormSet dynformSet) {
228 222
		// TODO Auto-generated method stub
229
		
230
	}
231
	
223

  
224
    }
225

  
226
    public void formAfterSearch(JDynFormSet dynformSet) {
227
		// TODO Auto-generated method stub
228

  
229
    }
230

  
232 231
}

Also available in: Unified diff