KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > toolbar > FormButtonModel


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.toolbar;
14
15 import com.tonbeller.wcf.component.Component;
16 import com.tonbeller.wcf.controller.RequestContext;
17
18 /**
19  * toolbar button that optionally validates or reverts the content of forms. Afterwards it optionally
20  * forwards to another page.
21  *
22  * @author av
23  */

24 public class FormButtonModel implements ToolButtonModel {
25   Component comp;
26   String JavaDoc action;
27   String JavaDoc forward;
28
29   public FormButtonModel(Component comp) {
30     this.comp = comp;
31   }
32
33   /**
34    * @see com.tonbeller.wcf.toolbar.ToolButtonModel#isPressed(RequestContext)
35    */

36   public boolean isPressed(RequestContext context) {
37     return false;
38   }
39
40   /**
41    * @see com.tonbeller.wcf.toolbar.ToolButtonModel#setPressed(RequestContext, boolean)
42    */

43   public void setPressed(RequestContext context, boolean pressed) {
44     boolean success = true;
45     if (action != null) {
46       if (action.equals("revert"))
47         comp.revert(context);
48       else if (action.equals("validate"))
49         success = comp.validate(context);
50       else
51         throw new IllegalArgumentException JavaDoc("invalid action: " + action);
52     }
53     if (success && forward != null && forward.length() > 0)
54       comp.setNextView(forward);
55   }
56
57   /**
58    * Sets the action.
59    * @param action The action to set
60    */

61   public void setAction(String JavaDoc action) {
62     this.action = action;
63   }
64
65   /**
66    * Sets the forward.
67    * @param forward The forward to set
68    */

69   public void setForward(String JavaDoc forward) {
70     this.forward = forward;
71   }
72
73 }
74
Popular Tags