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/dynformset/subform/SubformJDynFormSet.java
SubformJDynFormSet.java | ||
---|---|---|
36 | 36 |
import javax.swing.JLabel; |
37 | 37 |
import javax.swing.JOptionPane; |
38 | 38 |
import javax.swing.JPanel; |
39 |
import org.gvsig.tools.ToolsLocator; |
|
39 | 40 |
|
40 | 41 |
import org.gvsig.tools.dynform.AbortActionException; |
41 | 42 |
import org.gvsig.tools.dynform.DynFormDefinition; |
... | ... | |
68 | 69 |
super(manager, definition); |
69 | 70 |
} |
70 | 71 |
|
72 |
@Override |
|
71 | 73 |
public JComponent asJComponent() { |
72 | 74 |
if (this.contents == null) { |
73 | 75 |
try { |
... | ... | |
86 | 88 |
// this.jlabel_messages.setBorder( BorderFactory.createLoweredBevelBorder()); |
87 | 89 |
this.jlabel_messages.setText(" "); |
88 | 90 |
this.jlabel_messages.addMouseListener(new MouseAdapter() { |
91 |
@Override |
|
89 | 92 |
public void mouseClicked(MouseEvent evt) { |
90 | 93 |
int count = evt.getClickCount(); |
91 | 94 |
if (count == 2) { |
... | ... | |
97 | 100 |
return this.jlabel_messages; |
98 | 101 |
} |
99 | 102 |
|
103 |
@Override |
|
100 | 104 |
public void message() { |
101 | 105 |
this.getMessagesJLabel().setText(" "); |
102 | 106 |
} |
103 | 107 |
|
108 |
@Override |
|
104 | 109 |
public void message(String msg) { |
105 | 110 |
this.getMessagesJLabel().setText(msg); |
106 | 111 |
} |
... | ... | |
122 | 127 |
this.form.addListener(this); |
123 | 128 |
|
124 | 129 |
if (!actionsBuffer.isEmpty()) { |
125 |
Iterator it = actionsBuffer.iterator(); |
|
126 |
while (it.hasNext()) { |
|
127 |
ActionStore actStore = (ActionStore) it.next(); |
|
130 |
for (ActionStore actStore : actionsBuffer) { |
|
128 | 131 |
if (actStore.isSeparator()) { |
129 | 132 |
form.addSeparatorToPopupMenu( |
130 | 133 |
actStore.getDataType()); |
... | ... | |
142 | 145 |
} |
143 | 146 |
} |
144 | 147 |
this.form.setShowMessageStatus(false); |
145 |
this.form.setLayoutMode(this.layoutMode); |
|
148 |
//this.form.setLayoutMode(this.layoutMode);
|
|
146 | 149 |
this.form.addListener(this); |
147 | 150 |
|
148 | 151 |
this.buttonBar = new FormSetButtonBar(); |
149 | 152 |
this.buttonBar.addListener(this); |
150 | 153 |
this.buttonBar.setActionActive(FormSetButtonBar.ActionDelete, this.allowDelete()); |
151 | 154 |
this.buttonBar.setActionActive(FormSetButtonBar.ActionNew, this.allowNew()); |
155 |
this.buttonBar.setActionActive(FormSetButtonBar.ActionCancelNew, this.allowNew()); |
|
152 | 156 |
this.buttonBar.setActionActive(FormSetButtonBar.ActionSave, this.allowUpdate()); |
153 | 157 |
this.buttonBar.setActionActive(FormSetButtonBar.ActionSearch, this.allowSearch()); |
154 | 158 |
this.buttonBar.setActionActive(FormSetButtonBar.ActionClose, this.allowClose()); |
155 |
|
|
159 |
this.buttonBar.setVisible(FormSetButtonBar.ActionCancelNew, false); |
|
156 | 160 |
this.contents.add(this.buttonBar.asJComponent(), BorderLayout.NORTH); |
157 | 161 |
this.contents.add(this.form.asJComponent(), BorderLayout.CENTER); |
158 | 162 |
this.contents.add(this.getMessagesJLabel(), BorderLayout.SOUTH); |
159 | 163 |
doChangeValues(); |
160 | 164 |
} |
161 | 165 |
|
166 |
@Override |
|
167 |
public void setAllowDelete(boolean allowDelete) { |
|
168 |
super.setAllowDelete(allowDelete); |
|
169 |
if( this.buttonBar!=null ) { |
|
170 |
this.buttonBar.setActionActive(FormSetButtonBar.ActionDelete, this.allowDelete()); |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
@Override |
|
175 |
public void setAllowNew(boolean allowNew) { |
|
176 |
super.setAllowNew(allowNew); |
|
177 |
if( this.buttonBar!=null ) { |
|
178 |
this.buttonBar.setActionActive(FormSetButtonBar.ActionNew, this.allowNew()); |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
162 | 182 |
private void doChangeValues() throws ServiceException { |
163 | 183 |
this.current = 0; |
164 | 184 |
if (this.values == null || this.values.isEmpty()) { |
... | ... | |
207 | 227 |
} |
208 | 228 |
} |
209 | 229 |
|
230 |
@Override |
|
210 | 231 |
public boolean doActionFirst() { |
211 | 232 |
if (this.values.isEmpty()) { |
212 | 233 |
return false; |
213 | 234 |
} |
214 | 235 |
|
215 | 236 |
if (autosave) { |
216 |
if (this.form.isModified()) { |
|
237 |
if (this.form.isModified() || this.isInNewState() ) {
|
|
217 | 238 |
if (!doActionSave()) { |
218 | 239 |
return false; |
219 | 240 |
} |
... | ... | |
230 | 251 |
} catch (Exception ex) { |
231 | 252 |
logger.warn("Can't enable/disable delete and save buttons",ex); |
232 | 253 |
} |
233 |
|
|
234 | 254 |
this.fireFormMovedToEvent(this.current); |
235 | 255 |
return true; |
236 | 256 |
} |
237 | 257 |
|
258 |
@Override |
|
238 | 259 |
public boolean doActionPrevious() { |
239 | 260 |
if (this.values.isEmpty()) { |
240 | 261 |
return false; |
241 | 262 |
} |
242 | 263 |
|
243 | 264 |
if (autosave) { |
244 |
if (this.form.isModified()) { |
|
265 |
if (this.form.isModified() || this.isInNewState() ) {
|
|
245 | 266 |
if (!doActionSave()) { |
246 | 267 |
return false; |
247 | 268 |
} |
... | ... | |
256 | 277 |
return true; |
257 | 278 |
} |
258 | 279 |
|
280 |
@Override |
|
259 | 281 |
public boolean doActionNext() { |
260 | 282 |
if (this.values.isEmpty()) { |
261 | 283 |
return false; |
262 | 284 |
} |
263 | 285 |
|
264 | 286 |
if (autosave) { |
265 |
if (this.form.isModified()) { |
|
287 |
if (this.form.isModified() || this.isInNewState() ) {
|
|
266 | 288 |
if (!doActionSave()) { |
267 | 289 |
return false; |
268 | 290 |
} |
... | ... | |
277 | 299 |
return true; |
278 | 300 |
} |
279 | 301 |
|
302 |
@Override |
|
280 | 303 |
public boolean doActionLast() { |
281 | 304 |
if (this.values.isEmpty()) { |
282 | 305 |
return false; |
283 | 306 |
} |
284 | 307 |
|
285 | 308 |
if (autosave) { |
286 |
if (this.form.isModified()) { |
|
309 |
if (this.form.isModified() || this.isInNewState() ) {
|
|
287 | 310 |
if (!doActionSave()) { |
288 | 311 |
return false; |
289 | 312 |
} |
... | ... | |
296 | 319 |
return true; |
297 | 320 |
} |
298 | 321 |
|
322 |
@Override |
|
299 | 323 |
public boolean doActionSave() { |
300 |
if (this.values.isEmpty()) { |
|
324 |
if ( !this.isInNewState() && this.values.isEmpty()) {
|
|
301 | 325 |
return false; |
302 | 326 |
} |
303 | 327 |
try { |
304 | 328 |
this.listeners.accept(new Visitor() { |
329 |
@Override |
|
305 | 330 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
306 | 331 |
((JDynFormSetListener) listener).formBeforeSave(SubformJDynFormSet.this); |
307 | 332 |
} |
... | ... | |
313 | 338 |
return false; |
314 | 339 |
} |
315 | 340 |
|
316 |
List<String> fieldsName = new ArrayList<String>();
|
|
341 |
List<String> fieldsName = new ArrayList<>(); |
|
317 | 342 |
if (!this.form.hasValidValues(fieldsName)) { |
318 | 343 |
String errores = ""; |
319 | 344 |
Iterator<String> it = fieldsName.iterator(); |
... | ... | |
329 | 354 |
return false; |
330 | 355 |
} |
331 | 356 |
} |
332 |
if (this.current >= 0 && this.current < this.values.size()) { |
|
333 |
this.form.getValues((DynObject) this.values.get(this.current)); |
|
334 |
} else { |
|
335 |
logger.warn("current out of range."); |
|
357 |
if( !this.isInNewState() ) { |
|
358 |
if (this.current >= 0 && this.current < this.values.size()) { |
|
359 |
this.form.getValues((DynObject) this.values.get(this.current)); |
|
360 |
} else { |
|
361 |
logger.warn("current out of range."); |
|
362 |
} |
|
336 | 363 |
} |
337 |
|
|
338 | 364 |
try { |
339 | 365 |
this.listeners.accept(new Visitor() { |
366 |
@Override |
|
340 | 367 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
341 | 368 |
((JDynFormSetListener) listener).formAfterSave(SubformJDynFormSet.this); |
342 | 369 |
} |
... | ... | |
347 | 374 |
logger.warn("Can't notify to listeners after save.",e); |
348 | 375 |
return false; |
349 | 376 |
} |
377 |
this.leaveTheNewState(); |
|
350 | 378 |
return true; |
351 | 379 |
} |
352 | 380 |
|
381 |
@Override |
|
353 | 382 |
public boolean doActionNew() { |
354 | 383 |
try { |
355 | 384 |
this.listeners.accept(new Visitor() { |
385 |
@Override |
|
356 | 386 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
357 | 387 |
((JDynFormSetListener) listener).formBeforeNew(SubformJDynFormSet.this); |
358 | 388 |
} |
... | ... | |
360 | 390 |
} catch (BaseException e) { |
361 | 391 |
return true; |
362 | 392 |
} |
363 |
|
|
364 |
this.current = this.values.size() - 1; |
|
365 |
this.form.setValues((DynObject) this.values.get(this.current)); |
|
366 |
this.form.setReadOnly(this.isReadOnly()); |
|
367 |
this.buttonBar.setNumrecords(this.countValues()); |
|
368 |
this.buttonBar.setCurrent(this.current); |
|
393 |
this.enterStateNew(); |
|
369 | 394 |
try { |
370 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionDelete, |
|
371 |
this.allowDelete() && !this.isReadOnly()); |
|
372 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionSave, |
|
373 |
this.allowUpdate() && !this.isReadOnly()); |
|
374 |
} catch (Exception ex) { |
|
375 |
logger.warn("Can't enable/disable delete and save buttons",ex); |
|
395 |
this.listeners.accept(new Visitor() { |
|
396 |
@Override |
|
397 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
398 |
((JDynFormSetListener) listener).formAfterNew(SubformJDynFormSet.this); |
|
399 |
} |
|
400 |
}); |
|
401 |
} catch (BaseException e) { |
|
402 |
return true; |
|
376 | 403 |
} |
404 |
return true; |
|
405 |
} |
|
377 | 406 |
|
407 |
@Override |
|
408 |
public boolean doActionCancelNew() { |
|
378 | 409 |
try { |
379 | 410 |
this.listeners.accept(new Visitor() { |
411 |
@Override |
|
380 | 412 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
381 |
((JDynFormSetListener) listener).formAfterNew(SubformJDynFormSet.this);
|
|
413 |
((JDynFormSetListener) listener).formBeforeCancelNew(SubformJDynFormSet.this);
|
|
382 | 414 |
} |
383 | 415 |
}); |
384 | 416 |
} catch (BaseException e) { |
385 | 417 |
return true; |
386 | 418 |
} |
419 |
this.leaveTheNewState(); |
|
420 |
try { |
|
421 |
this.listeners.accept(new Visitor() { |
|
422 |
@Override |
|
423 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
424 |
((JDynFormSetListener) listener).formAfterCancelNew(SubformJDynFormSet.this); |
|
425 |
} |
|
426 |
}); |
|
427 |
} catch (BaseException e) { |
|
428 |
return true; |
|
429 |
} |
|
387 | 430 |
return true; |
388 | 431 |
} |
389 | 432 |
|
433 |
@Override |
|
434 |
protected void enterStateNew() { |
|
435 |
if( this.isInNewState() ) { |
|
436 |
return; |
|
437 |
} |
|
438 |
try { |
|
439 |
FormSetButtonBar bar = this.getButtonBar(); |
|
440 |
super.enterStateNew(); |
|
441 |
bar.setCurrentLabel(ToolsLocator.getI18nManager().getTranslation("nuevo")); |
|
442 |
bar.setNumrecords(this.countValues()); |
|
443 |
|
|
444 |
bar.setVisible(FormSetButtonBar.ActionCancelNew, true); |
|
445 |
bar.setVisible(FormSetButtonBar.ActionNew, false); |
|
446 |
|
|
447 |
bar.setEnabled(FormSetButtonBar.ActionSave,true); |
|
448 |
bar.setEnabled(FormSetButtonBar.ActionCancelNew,true); |
|
449 |
bar.setEnabled(FormSetButtonBar.ActionDelete,false); |
|
450 |
bar.setEnabled(FormSetButtonBar.ActionFirst,false); |
|
451 |
bar.setEnabled(FormSetButtonBar.ActionNext,false); |
|
452 |
bar.setEnabled(FormSetButtonBar.ActionPrevious,false); |
|
453 |
bar.setEnabled(FormSetButtonBar.ActionLast,false); |
|
454 |
bar.setEnabled(FormSetButtonBar.ActionSearch,false); |
|
455 |
} catch (Exception ex) { |
|
456 |
logger.warn("Can't enable/disable delete and save buttons",ex); |
|
457 |
} |
|
458 |
} |
|
459 |
|
|
460 |
@Override |
|
461 |
protected void leaveTheNewState() { |
|
462 |
if( !(this.isInNewState()) ) { |
|
463 |
return; |
|
464 |
} |
|
465 |
super.leaveTheNewState(); |
|
466 |
try { |
|
467 |
FormSetButtonBar bar = this.getButtonBar(); |
|
468 |
|
|
469 |
bar.setVisible(FormSetButtonBar.ActionCancelNew, false); |
|
470 |
bar.setVisible(FormSetButtonBar.ActionNew, true); |
|
471 |
|
|
472 |
bar.setEnabled(FormSetButtonBar.ActionSave,true); |
|
473 |
bar.setEnabled(FormSetButtonBar.ActionNew,true); |
|
474 |
bar.setEnabled(FormSetButtonBar.ActionDelete,true); |
|
475 |
bar.setEnabled(FormSetButtonBar.ActionSearch,true); |
|
476 |
|
|
477 |
bar.setCurrentLabel(null); |
|
478 |
bar.setNumrecords(this.countValues()); |
|
479 |
bar.setCurrent(this.current); |
|
480 |
} catch (Exception ex) { |
|
481 |
logger.warn("Can't enable/disable delete and save buttons",ex); |
|
482 |
} |
|
483 |
} |
|
484 |
|
|
485 |
@Override |
|
390 | 486 |
public boolean doActionDelete() { |
391 | 487 |
if (this.values.isEmpty()) { |
392 | 488 |
return false; |
... | ... | |
397 | 493 |
} |
398 | 494 |
try { |
399 | 495 |
this.listeners.accept(new Visitor() { |
496 |
@Override |
|
400 | 497 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
401 | 498 |
((JDynFormSetListener) listener).formBeforeDelete(SubformJDynFormSet.this); |
402 | 499 |
} |
... | ... | |
416 | 513 |
|
417 | 514 |
try { |
418 | 515 |
this.listeners.accept(new Visitor() { |
516 |
@Override |
|
419 | 517 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
420 | 518 |
((JDynFormSetListener) listener).formAfterDelete(SubformJDynFormSet.this); |
421 | 519 |
} |
... | ... | |
426 | 524 |
return true; |
427 | 525 |
} |
428 | 526 |
|
527 |
@Override |
|
429 | 528 |
public boolean doActionSearch() { |
430 | 529 |
if (this.values.isEmpty()) { |
431 | 530 |
return false; |
... | ... | |
433 | 532 |
|
434 | 533 |
try { |
435 | 534 |
this.listeners.accept(new Visitor() { |
535 |
@Override |
|
436 | 536 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
437 | 537 |
((JDynFormSetListener) listener).formBeforeSearch(SubformJDynFormSet.this); |
438 | 538 |
} |
... | ... | |
443 | 543 |
// Do search |
444 | 544 |
try { |
445 | 545 |
this.listeners.accept(new Visitor() { |
546 |
@Override |
|
446 | 547 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
447 | 548 |
((JDynFormSetListener) listener).formAfterSearch(SubformJDynFormSet.this); |
448 | 549 |
} |
... | ... | |
453 | 554 |
return true; |
454 | 555 |
} |
455 | 556 |
|
557 |
@Override |
|
456 | 558 |
public boolean doActionClose() { |
457 | 559 |
fireCloseEvent(); |
458 | 560 |
return true; |
459 | 561 |
} |
460 | 562 |
|
563 |
@Override |
|
461 | 564 |
public void doSetCurrentRecord(int index) { |
462 | 565 |
this.setCurrentIndex(index); |
463 | 566 |
} |
... | ... | |
470 | 573 |
} |
471 | 574 |
} |
472 | 575 |
|
576 |
@Override |
|
473 | 577 |
public int getCurrentIndex() { |
474 | 578 |
return this.current; |
475 | 579 |
} |
476 | 580 |
|
581 |
@Override |
|
477 | 582 |
public void setCurrentIndex(int index) { |
478 | 583 |
if (index < 0 || index > countValues()) { |
479 | 584 |
throw new IllegalArgumentException("Index (" + index + ") out of range [0.." + countValues() + "]."); |
... | ... | |
484 | 589 |
this.fireFormMovedToEvent(this.current); |
485 | 590 |
} |
486 | 591 |
|
592 |
@Override |
|
487 | 593 |
public void fieldChanged(JDynFormField field) { |
488 | 594 |
logger.debug("Ha cambiado el field: " + field.getName() + " con el valor => " + field.getValue()); |
489 | 595 |
} |
... | ... | |
494 | 600 |
return (DynObject) this.values.get(position); |
495 | 601 |
} |
496 | 602 |
|
603 |
@Override |
|
497 | 604 |
public List getValues() { |
498 | 605 |
if (this.current >= 0 && this.current < this.values.size()) { |
499 | 606 |
this.form.getValues((DynObject) this.values.get(this.current)); |
... | ... | |
501 | 608 |
return this.values; |
502 | 609 |
} |
503 | 610 |
|
611 |
@Override |
|
504 | 612 |
public boolean hasValidValues() { |
505 | 613 |
return this.form.hasValidValues(); |
506 | 614 |
} |
507 | 615 |
|
616 |
@Override |
|
508 | 617 |
public boolean hasValidValues(List<String> fieldsName) { |
509 | 618 |
return this.form.hasValidValues(fieldsName); |
510 | 619 |
} |
... | ... | |
515 | 624 |
} |
516 | 625 |
} |
517 | 626 |
|
627 |
@Override |
|
518 | 628 |
public void getFormValues(DynObject values) { |
519 | 629 |
this.form.getValues(values); |
520 | 630 |
} |
Also available in: Unified diff