KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > widget > WidgetState


1 /*
2  * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Sam
27  */

28
29
30 package com.caucho.widget;
31
32 import java.util.AbstractMap JavaDoc;
33 import java.util.Collections JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Map JavaDoc;
36 import java.util.Set JavaDoc;
37
38 /**
39  * The state for a widget is restored from and saved to a String[].
40  */

41 abstract public class WidgetState
42   extends AbstractMap JavaDoc<String JavaDoc, WidgetState>
43 {
44   private Widget _widget;
45   private WidgetState _parent;
46   WidgetMode _widgetMode; // package access for Widget;
47

48   protected WidgetState()
49   {
50   }
51
52   void setWidget( Widget widget )
53   {
54     _widget = widget;
55   }
56
57   public Widget getWidget()
58   {
59     return _widget;
60   }
61
62   void setParent( WidgetState parent )
63   {
64     _parent = parent;
65   }
66
67   public WidgetState getParent()
68   {
69     return _parent;
70   }
71
72   public Set JavaDoc<Map.Entry JavaDoc<String JavaDoc,WidgetState>> entrySet()
73   {
74     return (Set JavaDoc<Map.Entry JavaDoc<String JavaDoc,WidgetState>>) Collections.EMPTY_SET;
75   }
76
77   public WidgetState put( String JavaDoc id, WidgetState value )
78   {
79     throw new UnsupportedOperationException JavaDoc();
80   }
81
82   public Object JavaDoc getValue()
83   {
84     throw new UnsupportedOperationException JavaDoc();
85   }
86
87   /**
88    * Called once for each request to restore the state of the widget
89    * for the request.
90    */

91   abstract public void decode( String JavaDoc[] data )
92     throws WidgetException;
93
94   abstract public String JavaDoc[] encode()
95     throws WidgetException;
96
97   public List JavaDoc<WidgetWarning> getWarnings()
98   {
99     return null;
100   }
101
102   public List JavaDoc<WidgetError> getErrors()
103   {
104     return null;
105   }
106
107   /**
108    * Set the mode for this widget. The default is to use the mode set for the
109    * widget, or if that has not been set to inherit the mode from the parent
110    * state.
111    */

112   public void setWidgetMode( WidgetMode widgetMode )
113   {
114     if ( _widget.isWidgetModeAllowed( widgetMode ) )
115       _widgetMode = widgetMode;
116   }
117
118   /**
119    * If the widgetMode has not been set, then the parent's mode is returned, if
120    * there is no parent then WidgetMode.VIEW is returned.
121    */

122   final public WidgetMode getWidgetMode()
123   {
124     WidgetMode widgetMode = _widgetMode;
125
126     if ( widgetMode == null ) {
127       widgetMode = getWidget().getWidgetMode();
128
129       if ( widgetMode == null ) {
130         if ( _parent != null )
131           widgetMode = _parent.getWidgetMode();
132
133         if ( widgetMode == null )
134           widgetMode = WidgetMode.VIEW;
135       }
136     }
137
138     return widgetMode;
139   }
140
141   void resetAll()
142   {
143     reset();
144
145     _widget = null;
146     _parent = null;
147     _widgetMode = null;
148   }
149
150   /**
151    * Reset all member variables to the state immediately following
152    * construction.
153    */

154   abstract public void reset();
155 }
156
Popular Tags