gvsig-tools / 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 / base / BaseJDynFormSet.java @ 2039
History | View | Annotate | Download (23.5 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
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 |
*
|
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 |
*
|
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.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.tools.dynform.services.dynformset.base; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Color; |
27 |
import java.awt.Component; |
28 |
import java.awt.event.MouseAdapter; |
29 |
import java.awt.event.MouseEvent; |
30 |
import java.util.ArrayList; |
31 |
import java.util.Iterator; |
32 |
import java.util.List; |
33 |
import javax.swing.Action; |
34 |
import javax.swing.BorderFactory; |
35 |
import javax.swing.BoxLayout; |
36 |
|
37 |
import javax.swing.JComponent; |
38 |
import javax.swing.JLabel; |
39 |
import javax.swing.JOptionPane; |
40 |
import javax.swing.JPanel; |
41 |
import org.gvsig.tools.ToolsLocator; |
42 |
|
43 |
import org.gvsig.tools.dynform.AbortActionException; |
44 |
import org.gvsig.tools.dynform.DynFormDefinition; |
45 |
import org.gvsig.tools.dynform.JDynForm; |
46 |
import org.gvsig.tools.dynform.JDynForm.JDynFormListener; |
47 |
import org.gvsig.tools.dynform.JDynFormField; |
48 |
import org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.FormSetListener; |
49 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_CANCEL_NEW; |
50 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_CLOSE; |
51 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_DELETE; |
52 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_FIRST; |
53 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_LAST; |
54 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_NEW; |
55 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_NEXT; |
56 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_PREVIOUS; |
57 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_SAVE; |
58 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_SEARCH; |
59 |
import org.gvsig.tools.dynform.spi.dynformset.AbstractJDynFormSet; |
60 |
import org.gvsig.tools.dynform.spi.dynformset.ActionStore; |
61 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
62 |
import org.gvsig.tools.dynform.spi.dynformset.JDynFormSetFactory; |
63 |
import org.gvsig.tools.dynobject.DynObject; |
64 |
import org.gvsig.tools.dynobject.DynObjectSet; |
65 |
import org.gvsig.tools.dynobject.Tags; |
66 |
import org.gvsig.tools.exception.BaseException; |
67 |
import org.gvsig.tools.visitor.VisitCanceledException; |
68 |
import org.gvsig.tools.visitor.Visitor; |
69 |
|
70 |
@SuppressWarnings("UseSpecificCatch") |
71 |
public class BaseJDynFormSet extends AbstractJDynFormSet implements FormSetListener, JDynFormListener { |
72 |
|
73 |
private JLabel jlabel_messages = null; |
74 |
private JDynForm form = null; |
75 |
private FormSetButtonBar buttonBar = null; |
76 |
private int current = 0; |
77 |
|
78 |
public BaseJDynFormSet(
|
79 |
DynFormSPIManager manager, |
80 |
JDynFormSetFactory factory, |
81 |
JDynForm.DynFormContext context, |
82 |
DynFormDefinition definition, |
83 |
Tags contextTags |
84 |
) { |
85 |
super(manager, factory,context, definition, contextTags);
|
86 |
} |
87 |
|
88 |
@Override
|
89 |
public JComponent asJComponent() { |
90 |
if (this.contents == null) { |
91 |
this.initComponents();
|
92 |
if (this.buttonBar != null) { |
93 |
this.buttonBar.setReadOnly(this.isReadOnly()); |
94 |
} |
95 |
if (this.form != null) { |
96 |
this.form.setReadOnly(this.isReadOnly()); |
97 |
} |
98 |
} |
99 |
this.fireFormMovedToEvent(current);
|
100 |
return this.contents; |
101 |
} |
102 |
|
103 |
public JDynForm getForm() {
|
104 |
return this.form; |
105 |
} |
106 |
|
107 |
public JLabel getMessagesJLabel() { |
108 |
if (this.jlabel_messages == null) { |
109 |
this.jlabel_messages = new JLabel(); |
110 |
// this.jlabel_messages.setBorder( BorderFactory.createLoweredBevelBorder());
|
111 |
this.jlabel_messages.setText(" "); |
112 |
this.jlabel_messages.addMouseListener(new MouseAdapter() { |
113 |
@Override
|
114 |
public void mouseClicked(MouseEvent evt) { |
115 |
int count = evt.getClickCount();
|
116 |
if (count == 2) { |
117 |
JOptionPane.showMessageDialog(contents, jlabel_messages.getText(), "Status", JOptionPane.INFORMATION_MESSAGE); |
118 |
} |
119 |
} |
120 |
}); |
121 |
} |
122 |
return this.jlabel_messages; |
123 |
} |
124 |
|
125 |
@Override
|
126 |
public void message() { |
127 |
this.getMessagesJLabel().setText(" "); |
128 |
} |
129 |
|
130 |
@Override
|
131 |
public void message(String msg) { |
132 |
this.getMessagesJLabel().setText(msg);
|
133 |
} |
134 |
|
135 |
private FormSetButtonBar getButtonBar() {
|
136 |
if (this.buttonBar == null) { |
137 |
initComponents(); |
138 |
} |
139 |
return this.buttonBar; |
140 |
} |
141 |
|
142 |
private void initComponents() { |
143 |
this.contents = new JPanel(); |
144 |
this.contents.setBorder(BorderFactory.createLineBorder(Color.GRAY)); |
145 |
this.contents.setLayout(new BorderLayout()); |
146 |
|
147 |
this.form = this.getManager().getDynFormManager().createJDynForm(this.getContext(), this.getDefinition()); |
148 |
this.form.setReadOnly(this.isReadOnly()); |
149 |
this.form.setLayoutMode(this.getLayoutMode()); |
150 |
this.form.setUseScrollBars(this.getUseScrollBars()); |
151 |
this.form.addListener(this); |
152 |
|
153 |
if (!actionsBuffer.isEmpty()) {
|
154 |
for (ActionStore actStore : actionsBuffer) {
|
155 |
if (actStore.isSeparator()) {
|
156 |
form.addSeparatorToPopupMenu( |
157 |
actStore.getDataType()); |
158 |
} else {
|
159 |
form.addActionToPopupMenu( |
160 |
actStore.getDataType(), |
161 |
actStore.getActionName(), |
162 |
actStore.getAction()); |
163 |
} |
164 |
} |
165 |
} |
166 |
if (this.getUseScrollBars()) { |
167 |
if (this.formHeight > -1 && this.formWidth > -1) { |
168 |
this.setFormSize(this.formWidth, this.formHeight); |
169 |
} |
170 |
} |
171 |
this.form.setShowMessageStatus(false); |
172 |
//this.form.setLayoutMode(this.layoutMode);
|
173 |
this.form.addListener(this); |
174 |
|
175 |
this.buttonBar = new FormSetButtonBar(); |
176 |
this.buttonBar.addListener(this); |
177 |
this.buttonBar.setActionActive(ID_ACTION_DELETE, this.allowDelete()); |
178 |
this.buttonBar.setActionActive(ID_ACTION_NEW, this.allowNew()); |
179 |
this.buttonBar.setActionActive(ID_ACTION_CANCEL_NEW, this.allowNew()); |
180 |
this.buttonBar.setActionActive(ID_ACTION_SAVE, this.allowUpdate()); |
181 |
this.buttonBar.setActionActive(ID_ACTION_SEARCH, this.allowSearch()); |
182 |
this.buttonBar.setActionActive(ID_ACTION_CLOSE, this.allowClose()); |
183 |
this.buttonBar.setVisible(ID_ACTION_CANCEL_NEW, false); |
184 |
this.buttonBar.setReadOnly(this.isReadOnly()); |
185 |
this.contents.add(this.form.asJComponent(), BorderLayout.CENTER); |
186 |
|
187 |
JPanel p = new JPanel(); |
188 |
p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); |
189 |
this.buttonBar.asJComponent().setAlignmentX(Component.LEFT_ALIGNMENT); |
190 |
this.getMessagesJLabel().setAlignmentX(Component.LEFT_ALIGNMENT); |
191 |
p.add(this.buttonBar.asJComponent());
|
192 |
p.add(this.getMessagesJLabel());
|
193 |
this.contents.add(p, BorderLayout.SOUTH); |
194 |
|
195 |
doChangeValues(); |
196 |
} |
197 |
|
198 |
@Override
|
199 |
public void setAllowDelete(boolean allowDelete) { |
200 |
super.setAllowDelete(allowDelete);
|
201 |
if( this.buttonBar!=null ) { |
202 |
this.buttonBar.setActionActive(ID_ACTION_DELETE, this.allowDelete()); |
203 |
} |
204 |
} |
205 |
|
206 |
@Override
|
207 |
public void setAllowNew(boolean allowNew) { |
208 |
super.setAllowNew(allowNew);
|
209 |
if( this.buttonBar!=null ) { |
210 |
this.buttonBar.setActionActive(ID_ACTION_NEW, this.allowNew()); |
211 |
} |
212 |
} |
213 |
|
214 |
private void doChangeValues() { |
215 |
this.current = 0; |
216 |
if (this.values == null || this.values.isEmpty()) { |
217 |
this.form.setReadOnly(true); |
218 |
this.getButtonBar().setEnabled(ID_ACTION_DELETE, false); |
219 |
this.getButtonBar().setEnabled(ID_ACTION_SAVE, false); |
220 |
this.getButtonBar().setEnabled(ID_ACTION_NEW,
|
221 |
this.allowNew() && !this.isReadOnly()); |
222 |
this.getButtonBar().setNumrecords(0); |
223 |
this.form.clear();
|
224 |
} else {
|
225 |
this.form.setValues((DynObject) this.values.get(this.current)); |
226 |
this.getButtonBar().setEnabled(ID_ACTION_DELETE,
|
227 |
this.allowDelete() && !this.isReadOnly()); |
228 |
this.getButtonBar().setEnabled(ID_ACTION_SAVE,
|
229 |
this.allowUpdate() && !this.isReadOnly()); |
230 |
this.getButtonBar().setNumrecords(this.values.size()); |
231 |
} |
232 |
this.getButtonBar().setCurrent(this.current); |
233 |
} |
234 |
|
235 |
@Override
|
236 |
public void setValues(List values) { |
237 |
super.setValues(values);
|
238 |
if (this.contents != null) { |
239 |
doChangeValues(); |
240 |
} |
241 |
} |
242 |
|
243 |
@Override
|
244 |
public void setValues(DynObjectSet values) { |
245 |
super.setValues(values);
|
246 |
if (this.contents != null) { |
247 |
doChangeValues(); |
248 |
} |
249 |
} |
250 |
|
251 |
@Override
|
252 |
public void setReadOnly(boolean readOnly) { |
253 |
// if( this.isReadOnly() == readOnly ) {
|
254 |
// return;
|
255 |
// }
|
256 |
super.setReadOnly(readOnly);
|
257 |
if (this.buttonBar != null) { |
258 |
this.buttonBar.setReadOnly(readOnly);
|
259 |
} |
260 |
if (this.form != null) { |
261 |
this.form.setReadOnly(readOnly);
|
262 |
} |
263 |
} |
264 |
|
265 |
@Override
|
266 |
public boolean doActionFirst() { |
267 |
if (this.values.isEmpty()) { |
268 |
return false; |
269 |
} |
270 |
|
271 |
if (autosave) {
|
272 |
if (this.form.isModified() || this.isInNewState() ) { |
273 |
if (!doActionSave()) {
|
274 |
return false; |
275 |
} |
276 |
} |
277 |
} |
278 |
this.current = 0; |
279 |
this.form.setValues((DynObject) this.values.get(this.current)); |
280 |
this.buttonBar.setCurrent(this.current); |
281 |
try {
|
282 |
this.getButtonBar().setEnabled(ID_ACTION_DELETE,
|
283 |
this.allowDelete() && !this.isReadOnly()); |
284 |
this.getButtonBar().setEnabled(ID_ACTION_SAVE,
|
285 |
this.allowUpdate() && !this.isReadOnly()); |
286 |
} catch (Exception ex) { |
287 |
LOGGER.warn("Can't enable/disable delete and save buttons",ex);
|
288 |
} |
289 |
this.fireFormMovedToEvent(this.current); |
290 |
return true; |
291 |
} |
292 |
|
293 |
@Override
|
294 |
public boolean doActionPrevious() { |
295 |
if (this.values.isEmpty()) { |
296 |
return false; |
297 |
} |
298 |
|
299 |
if (autosave) {
|
300 |
if (this.form.isModified() || this.isInNewState() ) { |
301 |
if (!doActionSave()) {
|
302 |
return false; |
303 |
} |
304 |
} |
305 |
} |
306 |
if (this.current > 0) { |
307 |
this.current--;
|
308 |
} |
309 |
this.form.setValues((DynObject) this.values.get(this.current)); |
310 |
this.buttonBar.setCurrent(this.current); |
311 |
this.fireFormMovedToEvent(this.current); |
312 |
return true; |
313 |
} |
314 |
|
315 |
@Override
|
316 |
public boolean doActionNext() { |
317 |
if (this.values.isEmpty()) { |
318 |
return false; |
319 |
} |
320 |
|
321 |
if (autosave) {
|
322 |
if (this.form.isModified() || this.isInNewState() ) { |
323 |
if (!doActionSave()) {
|
324 |
return false; |
325 |
} |
326 |
} |
327 |
} |
328 |
if (this.current < this.values.size() - 1) { |
329 |
this.current++;
|
330 |
} |
331 |
this.form.setValues((DynObject) this.values.get(this.current)); |
332 |
this.buttonBar.setCurrent(this.current); |
333 |
this.fireFormMovedToEvent(this.current); |
334 |
return true; |
335 |
} |
336 |
|
337 |
@Override
|
338 |
public boolean doActionLast() { |
339 |
if (this.values.isEmpty()) { |
340 |
return false; |
341 |
} |
342 |
|
343 |
if (autosave) {
|
344 |
if (this.form.isModified() || this.isInNewState() ) { |
345 |
if (!doActionSave()) {
|
346 |
return false; |
347 |
} |
348 |
} |
349 |
} |
350 |
this.current = this.values.size() - 1; |
351 |
this.form.setValues((DynObject) this.values.get(this.current)); |
352 |
this.buttonBar.setCurrent(this.current); |
353 |
this.fireFormMovedToEvent(this.current); |
354 |
return true; |
355 |
} |
356 |
|
357 |
@Override
|
358 |
public boolean doActionSave() { |
359 |
if ( !this.isInNewState() && this.values.isEmpty()) { |
360 |
return false; |
361 |
} |
362 |
try {
|
363 |
this.listeners.accept(new Visitor() { |
364 |
@Override
|
365 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
366 |
((JDynFormSetListener) listener).formBeforeSave(BaseJDynFormSet.this); |
367 |
} |
368 |
}); |
369 |
} catch (AbortActionException e) {
|
370 |
return false; |
371 |
} catch (BaseException e) {
|
372 |
LOGGER.warn("Can't notify to listeners before save.",e);
|
373 |
return false; |
374 |
} |
375 |
|
376 |
List<String> fieldsName = new ArrayList<>(); |
377 |
if (!this.form.hasValidValues(fieldsName)) { |
378 |
String errores = ""; |
379 |
Iterator<String> it = fieldsName.iterator(); |
380 |
while (it.hasNext()) {
|
381 |
String name = (String) it.next(); |
382 |
errores = errores + " - " + name + "\n"; |
383 |
} |
384 |
int r = confirmDialog(
|
385 |
"There are incorrect data in the following fields:\n" + errores + "\nContinuing the incorrect values โwill not be saved. Do you want to continue?", "warning", |
386 |
JOptionPane.WARNING_MESSAGE,
|
387 |
JOptionPane.YES_NO_OPTION);
|
388 |
if (r != JOptionPane.YES_OPTION) { |
389 |
return false; |
390 |
} |
391 |
} |
392 |
if( !this.isInNewState() ) { |
393 |
if (this.current >= 0 && this.current < this.values.size()) { |
394 |
this.form.getValues((DynObject) this.values.get(this.current)); |
395 |
} else {
|
396 |
LOGGER.warn("current out of range.");
|
397 |
} |
398 |
} |
399 |
try {
|
400 |
this.listeners.accept(new Visitor() { |
401 |
@Override
|
402 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
403 |
((JDynFormSetListener) listener).formAfterSave(BaseJDynFormSet.this); |
404 |
} |
405 |
}); |
406 |
} catch (AbortActionException e) {
|
407 |
return false; |
408 |
} catch (BaseException e) {
|
409 |
LOGGER.warn("Can't notify to listeners after save.",e);
|
410 |
return false; |
411 |
} |
412 |
this.leaveTheNewState();
|
413 |
return true; |
414 |
} |
415 |
|
416 |
@Override
|
417 |
public boolean doActionNew() { |
418 |
try {
|
419 |
this.listeners.accept(new Visitor() { |
420 |
@Override
|
421 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
422 |
((JDynFormSetListener) listener).formBeforeNew(BaseJDynFormSet.this); |
423 |
} |
424 |
}); |
425 |
} catch (BaseException e) {
|
426 |
return true; |
427 |
} |
428 |
this.enterStateNew();
|
429 |
try {
|
430 |
this.listeners.accept(new Visitor() { |
431 |
@Override
|
432 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
433 |
((JDynFormSetListener) listener).formAfterNew(BaseJDynFormSet.this); |
434 |
} |
435 |
}); |
436 |
} catch (BaseException e) {
|
437 |
return true; |
438 |
} |
439 |
return true; |
440 |
} |
441 |
|
442 |
@Override
|
443 |
public boolean doActionCancelNew() { |
444 |
try {
|
445 |
this.listeners.accept(new Visitor() { |
446 |
@Override
|
447 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
448 |
((JDynFormSetListener) listener).formBeforeCancelNew(BaseJDynFormSet.this); |
449 |
} |
450 |
}); |
451 |
} catch (BaseException e) {
|
452 |
return true; |
453 |
} |
454 |
this.leaveTheNewState();
|
455 |
try {
|
456 |
this.listeners.accept(new Visitor() { |
457 |
@Override
|
458 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
459 |
((JDynFormSetListener) listener).formAfterCancelNew(BaseJDynFormSet.this); |
460 |
} |
461 |
}); |
462 |
} catch (BaseException e) {
|
463 |
return true; |
464 |
} |
465 |
return true; |
466 |
} |
467 |
|
468 |
@Override
|
469 |
protected void enterStateNew() { |
470 |
if( this.isInNewState() ) { |
471 |
return;
|
472 |
} |
473 |
try {
|
474 |
FormSetButtonBar bar = this.getButtonBar();
|
475 |
super.enterStateNew();
|
476 |
bar.setCurrentLabel(ToolsLocator.getI18nManager().getTranslation("nuevo"));
|
477 |
bar.setNumrecords(this.countValues());
|
478 |
|
479 |
bar.setVisible(ID_ACTION_CANCEL_NEW, true);
|
480 |
bar.setVisible(ID_ACTION_NEW, false);
|
481 |
|
482 |
bar.setEnabled(ID_ACTION_SAVE,true);
|
483 |
bar.setEnabled(ID_ACTION_CANCEL_NEW,true);
|
484 |
bar.setEnabled(ID_ACTION_DELETE,false);
|
485 |
bar.setEnabled(ID_ACTION_FIRST,false);
|
486 |
bar.setEnabled(ID_ACTION_NEXT,false);
|
487 |
bar.setEnabled(ID_ACTION_PREVIOUS,false);
|
488 |
bar.setEnabled(ID_ACTION_LAST,false);
|
489 |
bar.setEnabled(ID_ACTION_SEARCH,false);
|
490 |
} catch (Exception ex) { |
491 |
LOGGER.warn("Can't enable/disable delete and save buttons",ex);
|
492 |
} |
493 |
} |
494 |
|
495 |
@Override
|
496 |
protected void leaveTheNewState() { |
497 |
if( !(this.isInNewState()) ) { |
498 |
return;
|
499 |
} |
500 |
super.leaveTheNewState();
|
501 |
try {
|
502 |
FormSetButtonBar bar = this.getButtonBar();
|
503 |
|
504 |
bar.setVisible(ID_ACTION_CANCEL_NEW, false);
|
505 |
bar.setVisible(ID_ACTION_NEW, true);
|
506 |
|
507 |
bar.setEnabled(ID_ACTION_SAVE,true);
|
508 |
bar.setEnabled(ID_ACTION_NEW,true);
|
509 |
bar.setEnabled(ID_ACTION_DELETE,true);
|
510 |
bar.setEnabled(ID_ACTION_SEARCH,true);
|
511 |
|
512 |
bar.setCurrentLabel(null);
|
513 |
bar.setNumrecords(this.countValues());
|
514 |
bar.setCurrent(this.current);
|
515 |
} catch (Exception ex) { |
516 |
LOGGER.warn("Can't enable/disable delete and save buttons",ex);
|
517 |
} |
518 |
} |
519 |
|
520 |
@Override
|
521 |
public boolean doActionDelete() { |
522 |
if (this.values.isEmpty()) { |
523 |
return false; |
524 |
} |
525 |
|
526 |
if (this.countValues() < 1) { |
527 |
return true; |
528 |
} |
529 |
try {
|
530 |
this.listeners.accept(new Visitor() { |
531 |
@Override
|
532 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
533 |
((JDynFormSetListener) listener).formBeforeDelete(BaseJDynFormSet.this); |
534 |
} |
535 |
}); |
536 |
} catch (BaseException e) {
|
537 |
return true; |
538 |
} |
539 |
|
540 |
if (this.current >= countValues()) { |
541 |
this.current = countValues() - 1; |
542 |
} |
543 |
if (this.current > -1) { |
544 |
this.form.setValues((DynObject) this.values.get(this.current)); |
545 |
} |
546 |
this.buttonBar.setNumrecords(this.countValues()); |
547 |
this.buttonBar.setCurrent(this.current); |
548 |
|
549 |
try {
|
550 |
this.listeners.accept(new Visitor() { |
551 |
@Override
|
552 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
553 |
((JDynFormSetListener) listener).formAfterDelete(BaseJDynFormSet.this); |
554 |
} |
555 |
}); |
556 |
} catch (BaseException e) {
|
557 |
return true; |
558 |
} |
559 |
return true; |
560 |
} |
561 |
|
562 |
@Override
|
563 |
public boolean doActionSearch() { |
564 |
if (this.values.isEmpty()) { |
565 |
return false; |
566 |
} |
567 |
|
568 |
try {
|
569 |
this.listeners.accept(new Visitor() { |
570 |
@Override
|
571 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
572 |
((JDynFormSetListener) listener).formBeforeSearch(BaseJDynFormSet.this); |
573 |
} |
574 |
}); |
575 |
} catch (BaseException e) {
|
576 |
return true; |
577 |
} |
578 |
// Do search
|
579 |
try {
|
580 |
this.listeners.accept(new Visitor() { |
581 |
@Override
|
582 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
583 |
((JDynFormSetListener) listener).formAfterSearch(BaseJDynFormSet.this); |
584 |
} |
585 |
}); |
586 |
} catch (BaseException e) {
|
587 |
return true; |
588 |
} |
589 |
return true; |
590 |
} |
591 |
|
592 |
@Override
|
593 |
public boolean doActionClose() { |
594 |
fireCloseEvent(); |
595 |
return true; |
596 |
} |
597 |
|
598 |
@Override
|
599 |
public void doSetCurrentRecord(int index) { |
600 |
this.setCurrentIndex(index);
|
601 |
} |
602 |
|
603 |
@Override
|
604 |
public void setFormSize(int width, int height) { |
605 |
super.setFormSize(width, height);
|
606 |
if (this.form != null) { |
607 |
this.form.setFormSize(width, height);
|
608 |
} |
609 |
} |
610 |
|
611 |
@Override
|
612 |
public int getCurrentIndex() { |
613 |
return this.current; |
614 |
} |
615 |
|
616 |
@Override
|
617 |
public void setCurrentIndex(int index) { |
618 |
if (index < 0 || index > countValues()) { |
619 |
throw new IllegalArgumentException("Index (" + index + ") out of range [0.." + countValues() + "]."); |
620 |
} |
621 |
this.current = index;
|
622 |
this.form.setValues((DynObject) this.values.get(this.current)); |
623 |
this.buttonBar.setCurrent(this.current); |
624 |
this.fireFormMovedToEvent(this.current); |
625 |
} |
626 |
|
627 |
@Override
|
628 |
public void fieldChanged(JDynFormField field) { |
629 |
LOGGER.debug("Ha cambiado el field: " + field.getName() + " con el valor => " + field.getValue()); |
630 |
} |
631 |
|
632 |
@Override
|
633 |
public DynObject get(int position) { |
634 |
LOGGER.debug("Recojo el field: " + position);
|
635 |
return (DynObject) this.values.get(position); |
636 |
} |
637 |
|
638 |
@Override
|
639 |
public List getValues() { |
640 |
if (this.current >= 0 && this.current < this.values.size()) { |
641 |
this.form.getValues((DynObject) this.values.get(this.current)); |
642 |
} |
643 |
return this.values; |
644 |
} |
645 |
|
646 |
@Override
|
647 |
public boolean hasValidValues() { |
648 |
return this.form.hasValidValues(); |
649 |
} |
650 |
|
651 |
@Override
|
652 |
public boolean hasValidValues(List<String> fieldsName) { |
653 |
return this.form.hasValidValues(fieldsName); |
654 |
} |
655 |
|
656 |
public void clear() { |
657 |
if (this.form != null) { |
658 |
this.form.clear();
|
659 |
} |
660 |
} |
661 |
|
662 |
@Override
|
663 |
public void getFormValues(DynObject values) { |
664 |
this.form.getValues(values);
|
665 |
} |
666 |
|
667 |
@Override
|
668 |
public void addAction(Action action) { |
669 |
this.getButtonBar().addAction(action);
|
670 |
} |
671 |
|
672 |
@Override
|
673 |
public void setActionVisible(String action, boolean visible) { |
674 |
this.getButtonBar().setVisible(action, visible);
|
675 |
} |
676 |
|
677 |
@Override
|
678 |
public void setActionEnabled(String action, boolean enabled) { |
679 |
this.getButtonBar().setEnabled(action, enabled);
|
680 |
} |
681 |
|
682 |
@Override
|
683 |
public boolean isActionEnabled(String action) { |
684 |
return this.getButtonBar().isEnabled(action); |
685 |
} |
686 |
|
687 |
@Override
|
688 |
public boolean isActionVisible(String action) { |
689 |
return this.getButtonBar().isVisible(action); |
690 |
} |
691 |
|
692 |
@Override
|
693 |
public JComponent getActionButton(String action) { |
694 |
return this.getButtonBar().getActionButton(action); |
695 |
} |
696 |
|
697 |
@Override
|
698 |
public void fireEvent(String action, Object value) { |
699 |
this.getButtonBar().fireEvent(action, value);
|
700 |
} |
701 |
|
702 |
} |