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

View differences:

AbstractDynObjectComponent.java
38 38
import java.util.Iterator;
39 39
import java.util.Map;
40 40

  
41
import org.gvsig.tools.dynobject.DynField;
42 41
import org.gvsig.tools.dynobject.DynObject;
43 42
import org.gvsig.tools.service.Manager;
44 43
import org.gvsig.tools.service.ServiceException;
......
51 50
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
52 51

  
53 52
/**
54
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
55 53
 * 
54
 * @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
55
 * @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n&nbsp;</a> -
56
 *         gvSIG Team
57
 * @version $Id$
58
 * 
56 59
 */
57 60
public abstract class AbstractDynObjectComponent implements
58 61
    JDynObjectComponent, ValueField {
......
89 92
        manager = ToolsSwingLocator.getDynObjectSwingManager();
90 93
    }
91 94

  
95
    /**
96
     * Adds a new JDynFieldComponent to the list.
97
     * 
98
     * @param component
99
     *            the java awt Component
100
     * @param input
101
     *            the correspondent JDynFieldComponent object
102
     */
92 103
    protected void addComponentToList(Component component,
93 104
        JDynFieldComponent input) {
94 105
        this.getComponents().put(component, input);
95 106
    }
96 107

  
108
    /**
109
     * Gets the map of all graphic JDynFieldComponents of this
110
     * JDynObjectComponent.
111
     * 
112
     * @return
113
     *         the map containing the graphic Components.
114
     */
97 115
    private Map<Component, JDynFieldComponent> getComponents() {
98 116
        if (componentField == null) {
99 117
            componentField = new HashMap<Component, JDynFieldComponent>();
......
122 140
        return dynObject;
123 141
    }
124 142

  
125
    protected JDynFieldComponent getJDynFieldComponent(DynField field)
126
        throws ServiceException {
127
        return this.getJDynFieldComponent(field, null);
128
    }
129

  
130 143
    /**
144
     * 
145
     * Returns a {@link JDynFieldComponent} that best matches with the given
146
     * {@link ValueField} and adds, if any, the given listener to the
147
     * JDynFieldComponent listeneres.
148
     * 
149
     * @param valueItem
150
     *            the {@link ValueField} element.
151
     * @param listener
152
     *            the current {@link ValueChangedListener} to be added to the
153
     *            JDynFieldComponent listeners.
131 154
     * @return
155
     *         the {@link JDynFieldComponent}.
156
     * 
132 157
     * @throws ServiceException
133 158
     */
134
    protected JDynFieldComponent getJDynFieldComponent(DynField field,
159
    protected JDynFieldComponent getJDynFieldComponent(ValueField valueItem,
135 160
        ValueChangedListener listener) throws ServiceException {
136
        ValueField valueItem =
137
            new DynObjectValueField(this.getDynObject(), field.getName());
138 161
        JDynFieldComponent jfield =
139 162
            ((DynObjectSwingManager) this.getManager())
140
                .createJDynFieldComponent(valueItem, field);
163
                .createJDynFieldComponent(valueItem);
141 164
        if (listener != null) {
142
            jfield.addValueChangedListener(this);
165
            jfield.addValueChangedListener(listener);
143 166
            jfield.fireValueChangedEvent();
144 167
        }
145 168
        return jfield;
......
163 186
        return model;
164 187
    }
165 188

  
166
    public Object getValue() {
167
        return this.getDynObject();
168
    }
189
    //
190
    // public Object getValue() {
191
    // return this.getDynObject();
192
    // }
169 193

  
170 194
    public boolean isValid() {
171 195
        Map<Component, JDynFieldComponent> items = this.getComponents();
172 196
        for (JDynFieldComponent item : items.values()) {
173
            if (!this.isValid(item))
197
            if (!item.isValid())
174 198
                return false;
175 199
        }
176 200
        return true;
......
178 202

  
179 203
    /**
180 204
     * 
205
     * Sets all FieldValues of this {@link JDynObjectComponent} to null.
206
     * 
181 207
     */
182 208
    protected void emptyAll() {
183 209
        Map<Component, JDynFieldComponent> items = this.getComponents();
......
186 212
    }
187 213

  
188 214
    /**
215
     * Sets all FieldValues of this {@link JDynObjectComponent} to its the
216
     * current values
217
     * of the same FieldValues at the {@link DynObject} given as input.
218
     * 
189 219
     * @param value
190 220
     */
191 221
    protected void fillValues(DynObject dynObject) {
......
195 225
    }
196 226

  
197 227
    /**
198
     * @param component
199
     * @return
228
     * Walks through all JDynFieldComponents to save its current values into
229
     * their DynObject.
200 230
     */
201
    protected abstract boolean isValid(JDynFieldComponent component);
202

  
203 231
    public void saveStatus() {
204 232
        Iterator<JDynFieldComponent> componentFields =
205 233
            this.getComponents().values().iterator();

Also available in: Unified diff