author | Stephen Talley <stephen.talley@sun.com> |
Fri, 31 Oct 2008 17:38:21 -0400 | |
changeset 138 | 48a05b6471de |
parent 79 | d22c901edeff |
child 196 | 4aefd5567f1e |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
5 |
* Common Development and Distribution License (the "License"). |
|
6 |
* You may not use this file except in compliance with the License. |
|
7 |
* |
|
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
||
22 |
/* |
|
23 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
|
24 |
* Use is subject to license terms. |
|
25 |
*/ |
|
26 |
||
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
26
diff
changeset
|
27 |
package org.opensolaris.os.vp.panel.common.control; |
0 | 28 |
|
29 |
import java.io.UnsupportedEncodingException; |
|
30 |
import java.net.*; |
|
31 |
import java.util.*; |
|
138
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
32 |
import org.opensolaris.os.vp.panel.common.action.*; |
0 | 33 |
|
34 |
/** |
|
35 |
* The {@code Control} class encapsulates the control over all aspects of a |
|
36 |
* single point in a navigation hierarchy. |
|
37 |
*/ |
|
38 |
public abstract class Control implements Navigable, HasControl { |
|
39 |
// |
|
40 |
// Static data |
|
41 |
// |
|
42 |
||
43 |
private static final String ENCODING = "UTF-8"; |
|
44 |
||
45 |
// |
|
46 |
// Instance data |
|
47 |
// |
|
48 |
||
49 |
private Navigator navigator; |
|
50 |
private String id; |
|
51 |
private String name; |
|
52 |
private Map<String, String> parameters; |
|
53 |
||
138
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
54 |
private StructuredAction<?, ?, ?> resetAction = |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
55 |
new StructuredAction<Object, Object, Object>(null) { |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
56 |
@Override |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
57 |
public Object work(Object pInput, Object rtInput) |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
58 |
throws ActionAbortedException, ActionFailedException { |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
59 |
|
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
60 |
reset(); |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
61 |
return null; |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
62 |
} |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
63 |
}; |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
64 |
|
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
65 |
private StructuredAction<?, ?, ?> saveAction = |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
66 |
new StructuredAction<Object, Object, Object>(null) { |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
67 |
@Override |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
68 |
public Object work(Object pInput, Object rtInput) |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
69 |
throws ActionAbortedException, ActionFailedException { |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
70 |
|
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
71 |
try { |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
72 |
save(); |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
73 |
} catch (NoPermissionException e) { |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
74 |
throw new ActionFailedException(e); |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
75 |
} |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
76 |
return null; |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
77 |
} |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
78 |
}; |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
79 |
|
0 | 80 |
// |
81 |
// Constructors |
|
82 |
// |
|
83 |
||
84 |
/** |
|
85 |
* Constructs a {@code Control} with the given identifier and name. |
|
86 |
*/ |
|
87 |
public Control(String id, String name) { |
|
88 |
setId(id); |
|
89 |
setName(name); |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* Constructs a {@code Control} with a {@code null} identifier and name. |
|
94 |
*/ |
|
95 |
public Control() { |
|
96 |
this(null, null); |
|
97 |
} |
|
98 |
||
99 |
// |
|
100 |
// HasId methods |
|
101 |
// |
|
102 |
||
103 |
/** |
|
104 |
* Gets an identifier for this {@code Control}, sufficiently unique as to |
|
105 |
* distinguish itself from its siblings. |
|
106 |
*/ |
|
107 |
@Override |
|
108 |
public String getId() { |
|
109 |
return id; |
|
110 |
} |
|
111 |
||
112 |
// |
|
113 |
// Navigable methods |
|
114 |
// |
|
115 |
||
116 |
/** |
|
117 |
* Gets the localized name of this {@code Control}. |
|
118 |
*/ |
|
119 |
@Override |
|
120 |
public String getName() { |
|
121 |
return name; |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Gets the initialization parameters passed to the {@link #start} method, |
|
126 |
* if this {@code Control} is started, or {@code null} if this {@code |
|
127 |
* Control} is stopped. |
|
128 |
*/ |
|
129 |
@Override |
|
130 |
public Map<String, String> getParameters() { |
|
131 |
return parameters; |
|
132 |
} |
|
133 |
||
134 |
// |
|
135 |
// HasControl methods |
|
136 |
// |
|
137 |
||
138 |
@Override |
|
139 |
public Control getControl() { |
|
140 |
return this; |
|
141 |
} |
|
142 |
||
143 |
// |
|
144 |
// Control methods |
|
145 |
// |
|
146 |
||
147 |
/** |
|
148 |
* Called by the {@link Navigator} just after a child {@code Control} of |
|
149 |
* this {@code Control} has been started and pushed onto the {@link |
|
150 |
* Navigator}'s {@code Control} stack. |
|
151 |
* <p> |
|
152 |
* This default implementation does nothing. |
|
153 |
* |
|
154 |
* @param control |
|
155 |
* the child {@code Control} |
|
156 |
*/ |
|
157 |
public void childStarted(Control control) { |
|
158 |
} |
|
159 |
||
160 |
/** |
|
161 |
* Called by the {@link Navigator} just after a child {@code Control} of |
|
162 |
* this {@code Control} has been stopped and popped off the {@link |
|
163 |
* Navigator}'s {@code Control} stack. |
|
164 |
* <p> |
|
165 |
* This default implementation does nothing. |
|
166 |
* |
|
167 |
* @param control |
|
168 |
* the child {@code Control} |
|
169 |
*/ |
|
170 |
public void childStopped(Control control) { |
|
171 |
} |
|
172 |
||
173 |
/** |
|
174 |
* Gets a list of {@code Navigable}s that resolve to a child {@code Control} |
|
175 |
* of this {@code Control}. |
|
176 |
* |
|
177 |
* @return a non-{@code null} (but possibly empty) {@code Collection} |
|
178 |
*/ |
|
179 |
public abstract List<Navigable> getBrowsable(); |
|
180 |
||
181 |
/** |
|
138
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
182 |
* Gets a {@link StructuredAction} that invokes {@link #reset}. |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
183 |
*/ |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
184 |
public StructuredAction<?, ?, ?> getResetAction() { |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
185 |
return resetAction; |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
186 |
} |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
187 |
|
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
188 |
/** |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
189 |
* Gets a {@link StructuredAction} that invokes {@link #save}. |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
190 |
*/ |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
191 |
public StructuredAction<?, ?, ?> getSaveAction() { |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
192 |
return saveAction; |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
193 |
} |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
194 |
|
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
195 |
/** |
26
8a459d117e4a
2991 Stricter enforcement of UI operations on event thread would help avoid deadlocks
Stephen Talley <stephen.talley@sun.com>
parents:
17
diff
changeset
|
196 |
* Gets a hint as to whether this {@code Control} should be returned by a |
8a459d117e4a
2991 Stricter enforcement of UI operations on event thread would help avoid deadlocks
Stephen Talley <stephen.talley@sun.com>
parents:
17
diff
changeset
|
197 |
* parent {@code Control}'s {@link #getBrowsable} method. The parent may |
8a459d117e4a
2991 Stricter enforcement of UI operations on event thread would help avoid deadlocks
Stephen Talley <stephen.talley@sun.com>
parents:
17
diff
changeset
|
198 |
* choose to ignore this hint. |
8a459d117e4a
2991 Stricter enforcement of UI operations on event thread would help avoid deadlocks
Stephen Talley <stephen.talley@sun.com>
parents:
17
diff
changeset
|
199 |
*/ |
8a459d117e4a
2991 Stricter enforcement of UI operations on event thread would help avoid deadlocks
Stephen Talley <stephen.talley@sun.com>
parents:
17
diff
changeset
|
200 |
public abstract boolean isBrowsable(); |
8a459d117e4a
2991 Stricter enforcement of UI operations on event thread would help avoid deadlocks
Stephen Talley <stephen.talley@sun.com>
parents:
17
diff
changeset
|
201 |
|
8a459d117e4a
2991 Stricter enforcement of UI operations on event thread would help avoid deadlocks
Stephen Talley <stephen.talley@sun.com>
parents:
17
diff
changeset
|
202 |
/** |
0 | 203 |
* Gets the child {@code Control} with the given identifier, creating it if |
204 |
* necessary. |
|
205 |
* |
|
206 |
* @param id |
|
207 |
* a unique identifier, as reported by the child {@code |
|
208 |
* Control}'s {@link #getId} method. |
|
209 |
* |
|
210 |
* @return a {@code Control} object, or {@code null} if no such child |
|
211 |
* is known |
|
212 |
*/ |
|
213 |
public abstract Control getChildControl(String id); |
|
214 |
||
215 |
/** |
|
216 |
* Gets a path to forward to automatically when this {@code Control} is the |
|
217 |
* final destination of the {@link Navigator}. When this {@code Control} is |
|
218 |
* at the top of the {@code Control} stack (not in transit to another |
|
219 |
* {@code Control}), the {@link Navigator} will automatically navigate to |
|
220 |
* the returned path. |
|
221 |
* <p> |
|
222 |
* This default implementation returns {@code null}. |
|
223 |
* |
|
224 |
* @return an absolute or relative path, or {@code null} if no |
|
225 |
* automatic forwarding should occur |
|
226 |
*/ |
|
227 |
public String getForwardingPath() { |
|
228 |
return null; |
|
229 |
} |
|
230 |
||
231 |
/** |
|
232 |
* Gets the {@link Navigator} passed to the {@link #start} method, if |
|
233 |
* this {@code Control} is started, or {@code null} if this {@code Control} |
|
234 |
* is stopped. |
|
235 |
*/ |
|
236 |
public Navigator getNavigator() { |
|
237 |
return navigator; |
|
238 |
} |
|
239 |
||
17
b82508ab9887
2522 hard to differentiate group and share edit views
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
240 |
protected boolean isStarted() { |
b82508ab9887
2522 hard to differentiate group and share edit views
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
241 |
return navigator != null; |
b82508ab9887
2522 hard to differentiate group and share edit views
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
242 |
} |
b82508ab9887
2522 hard to differentiate group and share edit views
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
243 |
|
0 | 244 |
/** |
138
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
245 |
* If appropriate, resets this {@code Control}, discarding any pending |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
246 |
* changes. |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
247 |
* <p/> |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
248 |
* This default implementation does nothing. |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
249 |
* |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
250 |
* @exception ActionAbortedException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
251 |
* if this operation is cancelled |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
252 |
* |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
253 |
* @exception ActionFailedException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
254 |
* if this operation fails |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
255 |
*/ |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
256 |
protected void reset() throws ActionAbortedException, ActionFailedException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
257 |
{ |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
258 |
} |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
259 |
|
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
260 |
/** |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
261 |
* If appropriate, saves any changes made while this {@code Control} is |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
262 |
* running. |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
263 |
* <p/> |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
264 |
* This default implementation does nothing. |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
265 |
* |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
266 |
* @exception ActionAbortedException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
267 |
* if this operation is cancelled |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
268 |
* |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
269 |
* @exception ActionFailedException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
270 |
* if this operation fails |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
271 |
* |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
272 |
* @exception NoPermissionException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
273 |
* if the current user has insufficient privileges for this |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
274 |
* operation |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
275 |
*/ |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
276 |
protected void save() throws ActionAbortedException, ActionFailedException, |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
277 |
NoPermissionException { |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
278 |
} |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
279 |
|
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
280 |
/** |
0 | 281 |
* Sets the identifier for this {@code Control}. |
282 |
*/ |
|
283 |
protected void setId(String id) { |
|
284 |
this.id = id; |
|
285 |
} |
|
286 |
||
287 |
/** |
|
288 |
* Sets the name for this {@code Control}. |
|
289 |
*/ |
|
290 |
protected void setName(String name) { |
|
291 |
this.name = name; |
|
292 |
} |
|
293 |
||
294 |
protected void setNavigator(Navigator navigator) { |
|
295 |
this.navigator = navigator; |
|
296 |
} |
|
297 |
||
298 |
private void setParameters(Map<String, String> parameters) { |
|
299 |
this.parameters = parameters; |
|
300 |
} |
|
301 |
||
302 |
/** |
|
303 |
* Called by the {@link Navigator} when this {@code Control} is pushed onto |
|
304 |
* the {@code Control} stack. |
|
305 |
* <p> |
|
306 |
* This default implementation saves references to the given {@link |
|
307 |
* #getNavigator Navigator} and {@link #getParameters initialization |
|
308 |
* parameters}. |
|
309 |
* |
|
310 |
* @param navigator |
|
311 |
* the {@link Navigator} that handles navigation to/from this |
|
312 |
* {@code Controls} |
|
313 |
* |
|
314 |
* @param parameters |
|
315 |
* non-{@code null}, but optional (may be empty) initialization |
|
316 |
* parameters |
|
317 |
* |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
26
diff
changeset
|
318 |
* @exception NavigationAbortedException |
0 | 319 |
* if this {@code Control} could not be started due to the |
320 |
* action being cancelled or vetoed |
|
321 |
* |
|
322 |
* @exception InvalidParameterException |
|
323 |
* if this {@code Control} could not be started due to invalid |
|
324 |
* intialization parameters |
|
325 |
*/ |
|
326 |
public void start(Navigator navigator, Map<String, String> parameters) |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
26
diff
changeset
|
327 |
throws NavigationAbortedException, InvalidParameterException { |
0 | 328 |
setNavigator(navigator); |
329 |
setParameters(parameters); |
|
330 |
} |
|
331 |
||
332 |
/** |
|
333 |
* Called by the {@link Navigator} prior to this {@code Control} being |
|
334 |
* removed as the current {@code Control}. |
|
335 |
* <p> |
|
336 |
* This default implementation resets the reference to the {@code |
|
337 |
* Navigator} and removes any set parameters. |
|
338 |
* |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
26
diff
changeset
|
339 |
* @exception NavigationAbortedException |
0 | 340 |
* if this {@code Control} should remain the current {@code |
341 |
* Control} |
|
342 |
*/ |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
26
diff
changeset
|
343 |
public void stop() throws NavigationAbortedException { |
0 | 344 |
setNavigator(null); |
345 |
setParameters(null); |
|
346 |
} |
|
347 |
||
348 |
// |
|
349 |
// Static methods |
|
350 |
// |
|
351 |
||
352 |
/** |
|
353 |
* Encodes the given identifier and parameters. |
|
354 |
* |
|
355 |
* @param id |
|
356 |
* a {@link Control#getId Control identifier} |
|
357 |
* |
|
358 |
* @param parameters |
|
359 |
* initialization parameters, or {@code null} if no parameters |
|
360 |
* apply |
|
361 |
* |
|
362 |
* @return an encoded String |
|
363 |
*/ |
|
364 |
public static String encode(String id, Map<String, String> parameters) { |
|
365 |
StringBuffer buffer = new StringBuffer(); |
|
366 |
||
367 |
try { |
|
368 |
buffer.append(URLEncoder.encode(id, ENCODING)); |
|
369 |
||
370 |
if (parameters != null && !parameters.isEmpty()) { |
|
371 |
buffer.append("?"); |
|
372 |
boolean first = true; |
|
373 |
||
374 |
for (String key : parameters.keySet()) { |
|
375 |
if (first) { |
|
376 |
first = false; |
|
377 |
} else { |
|
378 |
buffer.append("&"); |
|
379 |
} |
|
380 |
||
381 |
String value = parameters.get(key); |
|
382 |
if (value == null) { |
|
383 |
value = ""; |
|
384 |
} else { |
|
385 |
value = URLEncoder.encode(value, ENCODING); |
|
386 |
} |
|
387 |
||
388 |
key = URLEncoder.encode(key, ENCODING); |
|
389 |
||
390 |
buffer.append(key).append("=").append(value); |
|
391 |
} |
|
392 |
} |
|
393 |
} catch (UnsupportedEncodingException ignore) { |
|
394 |
} |
|
395 |
||
396 |
return buffer.toString(); |
|
397 |
} |
|
398 |
||
399 |
public static SimpleNavigable decode(String encoded) { |
|
400 |
String[] elements = encoded.split("\\?", 2); |
|
401 |
String id = elements[0]; |
|
402 |
Map<String, String> parameters = new HashMap<String, String>(); |
|
403 |
||
404 |
try { |
|
405 |
id = URLDecoder.decode(elements[0], ENCODING); |
|
406 |
} catch (UnsupportedEncodingException ignore) { |
|
407 |
} |
|
408 |
||
79
d22c901edeff
3496 code cleanup/best practices/nits
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
409 |
if (elements.length >= 2 && !elements[1].isEmpty()) { |
0 | 410 |
String[] keyEqVals = elements[1].split("&"); |
411 |
||
412 |
for (String keyEqVal : keyEqVals) { |
|
413 |
String[] nvPair = keyEqVal.split("=", 2); |
|
414 |
String key = nvPair[0]; |
|
415 |
String value = nvPair.length < 2 ? "" : nvPair[1]; |
|
416 |
||
417 |
try { |
|
418 |
key = URLDecoder.decode(key, ENCODING); |
|
419 |
value = URLDecoder.decode(value, ENCODING); |
|
420 |
} catch (UnsupportedEncodingException ignore) { |
|
421 |
} |
|
422 |
||
423 |
parameters.put(key, value); |
|
424 |
} |
|
425 |
} |
|
426 |
||
427 |
return new SimpleNavigable(id, parameters); |
|
428 |
} |
|
429 |
} |