Revision 298 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/AbstractJDynField.java

View differences:

AbstractJDynField.java
72 72
        listeners = new ArrayList<ValueChangedListener>();
73 73
    }
74 74

  
75
    /*
76
     * (non-Javadoc)
77
     * 
78
     * @seeorg.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#
79
     * addValueChangedListener
80
     * (org.gvsig.tools.swing.api.dynobject.ValueChangedListener)
81
     */
82
    public void addValueChangedListener(ValueChangedListener listener) {
83
        // If it was the first item, we need to
84
        // initialize Component listeners
85
        // add listener to the dynfield set of listeners
86
        listeners.add(listener);
87
        // set supplementary listeners.
88
        this.setJDynFieldComponentListeners();
89
    }
90

  
75 91
    /**
76
     * Inits the JDynFieldComponent logic to create its components and check its
77
     * values.
92
     * The {@link JDynFieldComponent} can use this function to add any code
93
     * necessary
94
     * once all swing components have been initialized.
78 95
     */
79
    protected void init() {
80
        this.initData();
81
        this.initUI();
82
        if (this.getDynField().isReadOnly())
83
            this.setReadOnly();
84
        this.setValue(getInitialValue());
85
        this.afterUI();
96
    protected abstract void afterUI();
97

  
98
    /**
99
     * Then all {@link ValueChangedListener}s are fired to alert them
100
     * to check if the value has changed via the {@link getValue()} function of
101
     * the {@link JDynFieldComponent}.
102
     */
103
    public abstract void fireValueChangedEvent();
104

  
105
    /**
106
     * Gets the default value of the {@link ValueField} object.
107
     * 
108
     * @return
109
     *         the default value of the {@link ValueField} object.
110
     */
111
    public Object getDefaultFieldValue() {
112
        return this.getValueField().getDefaultFieldValue();
86 113
    }
87 114

  
88 115
    /**
89
     * JDynFieldComponents can use this function to initialize any
90
     * data containers before the swing components are created.
116
     * Returns the {@link DynField} being rendered.
117
     * 
118
     * @return the {@link DynField}
91 119
     */
92
    protected abstract void initData();
120
    public DynField getDynField() {
121
        return getValueField().getDynField();
122
    }
93 123

  
94 124
    /**
95
     * {@link JDynFieldComponent}s can use this function to initialized any
96
     * swing components to be used afterwards, and specify their
97
     * default settings.
125
     * Gets the current value of the {@link ValueField} object.
126
     * 
127
     * @return
128
     *         the current value of the {@link ValueField} object.
98 129
     */
99
    protected abstract void initUI();
130
    public Object getFieldValue() {
131
        return this.getValueField().getFieldValue();
132
    }
100 133

  
101 134
    /**
102 135
     * Checks if the {@link ValueField} has an inputed value; if not, then it
......
116 149
    }
117 150

  
118 151
    /**
119
     * The {@link JDynFieldComponent} can implement this function to set the
120
     * swing
121
     * components that represent this {@link DynField} to readOnly mode.
152
     * Gets the {@link ValueField} object.
153
     * 
154
     * @return
155
     *         the {@link ValueField} object.
122 156
     */
123
    protected abstract void setReadOnly();
157
    private ValueField getValueField() {
158
        return this.parent;
159
    }
124 160

  
125 161
    /**
126
     * Sets the value to the {@link JDynFieldComponent}. With this logic, it
127
     * checks first
128
     * if it is a null value or not. Then all {@link ValueChangedListener}s are
129
     * fired
130
     * to alert them to check if the value has changed via the {@link
131
     * getValue()} function.
132
     * 
133
     * @param value
134
     *            the value to be set into the swing component.
162
     * Inits the JDynFieldComponent logic to create its components and check its
163
     * values.
135 164
     */
136
    public void setValue(Object value) {
137
        if (value == null)
138
            setNullValue();
139
        else
140
            setNonNullValue(value);
141
        this.fireValueChangedEvent();
165
    protected void init() {
166
        this.initData();
167
        this.initUI();
168
        if (this.getDynField().isReadOnly()) {
169
            this.setReadOnly();
170
        }
171
        this.setValue(getInitialValue());
172
        this.afterUI();
142 173
    }
143 174

  
144 175
    /**
145
     * The {@link JDynFieldComponent} can use this function to add any code
146
     * necessary
147
     * once all swing components have been initialized.
176
     * JDynFieldComponents can use this function to initialize any
177
     * data containers before the swing components are created.
148 178
     */
149
    protected abstract void afterUI();
179
    protected abstract void initData();
150 180

  
151 181
    /**
182
     * {@link JDynFieldComponent}s can use this function to initialized any
183
     * swing components to be used afterwards, and specify their
184
     * default settings.
185
     */
186
    protected abstract void initUI();
187

  
188
    /**
189
     * Sets the current value of the {@link JDynFieldComponent} to the
190
     * {@link DynObject} value via the {@link ValueField} object.
191
     * 
192
     */
193
    public void setFieldValue(Object value) {
194
        this.getValueField().setFieldValue(value);
195
    }
196

  
197
    protected abstract void setJDynFieldComponentListeners();
198

  
199
    /**
152 200
     * The {@link JDynFieldComponent} can use this function to set a <b>non
153 201
     * null</b> value
154 202
     * into the correspondent swing component.
......
169 217
    protected abstract void setNullValue();
170 218

  
171 219
    /**
172
     * Then all {@link ValueChangedListener}s are fired to alert them
173
     * to check if the value has changed via the {@link getValue()} function of
174
     * the {@link JDynFieldComponent}.
220
     * The {@link JDynFieldComponent} can implement this function to set the
221
     * swing
222
     * components that represent this {@link DynField} to readOnly mode.
175 223
     */
176
    public abstract void fireValueChangedEvent();
224
    protected abstract void setReadOnly();
177 225

  
178 226
    /**
179
     * Returns the {@link DynField} being rendered.
227
     * Sets the value to the {@link JDynFieldComponent}. With this logic, it
228
     * checks first
229
     * if it is a null value or not. Then all {@link ValueChangedListener}s are
230
     * fired
231
     * to alert them to check if the value has changed via the {@link
232
     * getValue()} function.
180 233
     * 
181
     * @return the {@link DynField}
234
     * @param value
235
     *            the value to be set into the swing component.
182 236
     */
183
    public DynField getDynField() {
184
        return getValueField().getDynField();
237
    public void setValue(Object value) {
238
        if (value == null) {
239
            setNullValue();
240
        } else {
241
            setNonNullValue(value);
242
        }
243
        this.fireValueChangedEvent();
185 244
    }
186 245

  
187
    /**
188
     * Gets the {@link ValueField} object.
189
     * 
190
     * @return
191
     *         the {@link ValueField} object.
192
     */
193
    private ValueField getValueField() {
194
        return this.parent;
195
    }
196

  
197
    /**
198
     * Gets the default value of the {@link ValueField} object.
199
     * 
200
     * @return
201
     *         the default value of the {@link ValueField} object.
202
     */
203
    public Object getDefaultFieldValue() {
204
        return this.getValueField().getDefaultFieldValue();
205
    }
206

  
207
    /**
208
     * Gets the current value of the {@link ValueField} object.
209
     * 
210
     * @return
211
     *         the current value of the {@link ValueField} object.
212
     */
213
    public Object getFieldValue() {
214
        return this.getValueField().getFieldValue();
215
    }
216

  
217
    /**
218
     * Sets the current value of the {@link JDynFieldComponent} to the
219
     * {@link DynObject} value via the {@link ValueField} object.
220
     * 
221
     */
222
    public void setFieldValue(Object value) {
223
        this.getValueField().setFieldValue(value);
224
    }
225
    
226
    /*
227
     * (non-Javadoc)
228
     * 
229
     * @seeorg.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#
230
     * addValueChangedListener
231
     * (org.gvsig.tools.swing.api.dynobject.ValueChangedListener)
232
     */
233
    public void addValueChangedListener(ValueChangedListener listener) {
234
        // If it was the first item, we need to
235
        // initialize Component listeners
236
        // add listener to the dynfield set of listeners
237
        listeners.add(listener);
238
        // set supplementary listeners.
239
        this.setJDynFieldComponentListeners();
240
    }
241

  
242
    protected abstract void setJDynFieldComponentListeners();
243

  
244 246
}

Also available in: Unified diff