Revision 846 org.gvsig.tools/library/trunk/org.gvsig.tools/dynform/src/org/gvsig/tools/dynform/impl/DefaultJDynFormSet.java
DefaultJDynFormSet.java | ||
---|---|---|
9 | 9 |
import java.util.List; |
10 | 10 |
import java.util.Set; |
11 | 11 |
|
12 |
import javax.swing.BoxLayout; |
|
13 | 12 |
import javax.swing.JComponent; |
14 | 13 |
import javax.swing.JLabel; |
15 | 14 |
import javax.swing.JOptionPane; |
... | ... | |
43 | 42 |
private List values=null; |
44 | 43 |
private int current=0; |
45 | 44 |
private Set listeners = null; |
45 |
private boolean autosave = true; |
|
46 | 46 |
|
47 | 47 |
public DefaultJDynFormSet(DefaultDynFormManager manager, DynFormDefinition definition) throws ServiceException { |
48 | 48 |
this.manager = manager; |
... | ... | |
102 | 102 |
public JLabel getMessagesJLabel() { |
103 | 103 |
if( this.jlabel_messages == null ) { |
104 | 104 |
this.jlabel_messages = new JLabel(); |
105 |
// this.jlabel_messages.setBorder( BorderFactory.createLoweredBevelBorder()); |
|
106 |
this.jlabel_messages.setText(" "); |
|
105 | 107 |
this.jlabel_messages.addMouseListener(new MouseAdapter() { |
106 | 108 |
public void mouseClicked(MouseEvent evt) { |
107 | 109 |
int count = evt.getClickCount(); |
... | ... | |
140 | 142 |
|
141 | 143 |
this.buttonBar = new FormSetButtonBar(); |
142 | 144 |
this.buttonBar.addListener(this); |
143 |
|
|
144 |
JPanel bottomPanel = new JPanel(); |
|
145 |
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS)); |
|
146 |
bottomPanel.add(this.buttonBar.asJComponent()); |
|
147 |
bottomPanel.add(this.getMessagesJLabel()); |
|
148 | 145 |
|
146 |
this.contents.add(this.buttonBar.asJComponent(), BorderLayout.NORTH); |
|
149 | 147 |
this.contents.add(this.form.asJComponent(), BorderLayout.CENTER); |
150 |
this.contents.add(bottomPanel, BorderLayout.SOUTH); |
|
148 |
this.contents.add(this.getMessagesJLabel(), BorderLayout.SOUTH); |
|
149 |
if( this.values != null ) { |
|
150 |
doChangeValue(); |
|
151 |
} |
|
151 | 152 |
} |
152 | 153 |
|
153 | 154 |
public int getLayoutMode() { |
... | ... | |
161 | 162 |
this.layoutMode = layoutMode; |
162 | 163 |
} |
163 | 164 |
|
165 |
private void doChangeValue() throws ServiceException { |
|
166 |
this.current = 0; |
|
167 |
this.form.setValues((DynObject) this.values.get(this.current)); |
|
168 |
|
|
169 |
this.getButtonBar().setNumrecords(this.values.size()); |
|
170 |
this.getButtonBar().setCurrent(this.current); |
|
171 |
} |
|
172 |
|
|
164 | 173 |
public void setValues(List values) throws ServiceException { |
165 | 174 |
List x = new ArrayList(); |
166 | 175 |
x.addAll(values); |
167 | 176 |
this.values = x; |
168 |
this.getButtonBar().setNumrecords(this.values.size()); |
|
169 |
doActionFirst(); |
|
170 |
|
|
171 |
// FIXME: Is the list readonly ??? |
|
172 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionDelete, true); |
|
173 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionSave, true); |
|
174 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionNew, true); |
|
177 |
if( this.contents != null ) { |
|
178 |
doChangeValue(); |
|
179 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionDelete, true); |
|
180 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionSave, true); |
|
181 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionNew, true); |
|
182 |
} |
|
175 | 183 |
} |
176 | 184 |
|
177 | 185 |
public void setValues(DynObjectSet values) throws ServiceException { |
... | ... | |
188 | 196 |
x.add(obj); |
189 | 197 |
} |
190 | 198 |
this.values = x; |
191 |
this.getButtonBar().setNumrecords(this.values.size()); |
|
192 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionDelete, values.isDeleteEnabled()); |
|
193 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionSave, values.isUpdateEnabled()); |
|
194 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionNew, values.isUpdateEnabled()); |
|
195 |
doActionFirst(); |
|
199 |
if( this.contents != null ) { |
|
200 |
doChangeValue(); |
|
201 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionDelete, values.isDeleteEnabled()); |
|
202 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionSave, values.isUpdateEnabled()); |
|
203 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionNew, values.isUpdateEnabled()); |
|
204 |
} |
|
196 | 205 |
} |
197 | 206 |
|
198 | 207 |
public boolean isReadOnly() { |
... | ... | |
204 | 213 |
this.form.setReadOnly(readOnly); |
205 | 214 |
} |
206 | 215 |
|
207 |
public void doActionFirst() { |
|
216 |
public boolean doActionFirst() { |
|
217 |
if( autosave ) { |
|
218 |
if( !doActionSave() ) { |
|
219 |
return false; |
|
220 |
} |
|
221 |
} |
|
208 | 222 |
this.current = 0; |
209 | 223 |
this.form.setValues((DynObject) this.values.get(this.current)); |
210 | 224 |
this.buttonBar.setCurrent(this.current); |
225 |
return true; |
|
211 | 226 |
} |
212 | 227 |
|
213 |
public void doActionPrevious() { |
|
228 |
public boolean doActionPrevious() { |
|
229 |
if( autosave ) { |
|
230 |
if( !doActionSave() ) { |
|
231 |
return false; |
|
232 |
} |
|
233 |
} |
|
214 | 234 |
if( this.current > 0 ) { |
215 | 235 |
this.current--; |
216 | 236 |
} |
217 | 237 |
this.form.setValues((DynObject) this.values.get(this.current)); |
218 | 238 |
this.buttonBar.setCurrent(this.current); |
239 |
return true; |
|
219 | 240 |
} |
220 | 241 |
|
221 |
public void doActionNext() { |
|
242 |
public boolean doActionNext() { |
|
243 |
if( autosave ) { |
|
244 |
if( !doActionSave() ) { |
|
245 |
return false; |
|
246 |
} |
|
247 |
} |
|
222 | 248 |
if( this.current < this.values.size() ) { |
223 | 249 |
this.current++; |
224 | 250 |
} |
225 | 251 |
this.form.setValues((DynObject) this.values.get(this.current)); |
226 | 252 |
this.buttonBar.setCurrent(this.current); |
253 |
return true; |
|
227 | 254 |
} |
228 | 255 |
|
229 |
public void doActionLast() { |
|
256 |
public boolean doActionLast() { |
|
257 |
if( autosave ) { |
|
258 |
if( !doActionSave() ) { |
|
259 |
return false; |
|
260 |
} |
|
261 |
} |
|
230 | 262 |
this.current = this.values.size()-1; |
231 | 263 |
this.form.setValues((DynObject) this.values.get(this.current)); |
232 | 264 |
this.buttonBar.setCurrent(this.current); |
265 |
return true; |
|
233 | 266 |
} |
234 | 267 |
|
235 |
public void doActionSave() { |
|
236 |
// TODO Auto-generated method stub |
|
268 |
public boolean doActionSave() { |
|
269 |
if( !this.form.isModified() ) { |
|
270 |
return true; |
|
271 |
} |
|
272 |
if( !this.form.haveValidValues() ) { |
|
273 |
int r = confirmDialog( |
|
274 |
"There are incorrect data. Continuing the incorrect values will not be saved. Do you want to continue?", "warning", |
|
275 |
JOptionPane.WARNING_MESSAGE, |
|
276 |
JOptionPane.YES_NO_OPTION); |
|
277 |
if( r != JOptionPane.YES_OPTION ) { |
|
278 |
return false; |
|
279 |
} |
|
280 |
} |
|
281 |
this.form.getValues((DynObject) this.values.get(this.current)); |
|
282 |
return true; |
|
237 | 283 |
} |
238 | 284 |
|
239 |
public void doActionNew() {
|
|
240 |
// TODO Auto-generated method stub
|
|
285 |
public boolean doActionNew() {
|
|
286 |
return true;
|
|
241 | 287 |
} |
242 | 288 |
|
243 |
public void doActionDelete() {
|
|
244 |
// TODO Auto-generated method stub
|
|
289 |
public boolean doActionDelete() {
|
|
290 |
return true;
|
|
245 | 291 |
} |
246 | 292 |
|
247 |
public void doActionSearch() {
|
|
248 |
// TODO Auto-generated method stub
|
|
293 |
public boolean doActionSearch() {
|
|
294 |
return true;
|
|
249 | 295 |
} |
250 | 296 |
|
251 |
public void doActionClose() {
|
|
297 |
public boolean doActionClose() {
|
|
252 | 298 |
fireCloseEvent(); |
299 |
return true; |
|
253 | 300 |
} |
254 | 301 |
|
255 | 302 |
public void closeForm() { |
256 | 303 |
// Do nothing |
257 | 304 |
} |
305 |
|
|
306 |
public boolean isAutosave() { |
|
307 |
return this.autosave; |
|
308 |
} |
|
309 |
|
|
310 |
public void setAutosave(boolean autosave) { |
|
311 |
this.autosave = autosave; |
|
312 |
} |
|
313 |
|
|
314 |
public int confirmDialog(final String message, final String title, final int optionType, |
|
315 |
final int messageType) { |
|
316 |
return JOptionPane.showConfirmDialog( |
|
317 |
this.contents, message,title, optionType, messageType); |
|
318 |
} |
|
258 | 319 |
} |
Also available in: Unified diff