author | Stephen Talley <stephen.talley@sun.com> |
Wed, 18 Mar 2009 13:57:09 -0400 | |
changeset 235 | 38f73435a683 |
parent 214 | aed2b42f7344 |
child 247 | 8ed978c14164 |
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 |
/* |
|
196
4aefd5567f1e
4364 sysid: resolve SysIdUtil.createNPException
Stephen Talley <stephen.talley@sun.com>
parents:
138
diff
changeset
|
23 |
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
0 | 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(); |
214
aed2b42f7344
6426 UnauthorizedActionException's name should follow convention
Stephen Talley <stephen.talley@sun.com>
parents:
196
diff
changeset
|
73 |
} catch (ActionUnauthorizedException e) { |
138
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 |
||
235
38f73435a683
7483 save/prompt functionality in SwingControl can be generalized and moved into Control and DefaultControl
Stephen Talley <stephen.talley@sun.com>
parents:
214
diff
changeset
|
240 |
/** |
38f73435a683
7483 save/prompt functionality in SwingControl can be generalized and moved into Control and DefaultControl
Stephen Talley <stephen.talley@sun.com>
parents:
214
diff
changeset
|
241 |
* Indicates whether there are any unsaved changes; specifically, whether |
38f73435a683
7483 save/prompt functionality in SwingControl can be generalized and moved into Control and DefaultControl
Stephen Talley <stephen.talley@sun.com>
parents:
214
diff
changeset
|
242 |
* {@link #save} should be called before stopping this {@code Control}. |
38f73435a683
7483 save/prompt functionality in SwingControl can be generalized and moved into Control and DefaultControl
Stephen Talley <stephen.talley@sun.com>
parents:
214
diff
changeset
|
243 |
*/ |
38f73435a683
7483 save/prompt functionality in SwingControl can be generalized and moved into Control and DefaultControl
Stephen Talley <stephen.talley@sun.com>
parents:
214
diff
changeset
|
244 |
protected abstract boolean isSaveNeeded(); |
38f73435a683
7483 save/prompt functionality in SwingControl can be generalized and moved into Control and DefaultControl
Stephen Talley <stephen.talley@sun.com>
parents:
214
diff
changeset
|
245 |
|
17
b82508ab9887
2522 hard to differentiate group and share edit views
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
246 |
protected boolean isStarted() { |
b82508ab9887
2522 hard to differentiate group and share edit views
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
247 |
return navigator != null; |
b82508ab9887
2522 hard to differentiate group and share edit views
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
248 |
} |
b82508ab9887
2522 hard to differentiate group and share edit views
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
249 |
|
0 | 250 |
/** |
138
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
251 |
* 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
|
252 |
* changes. |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
253 |
* <p/> |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
254 |
* 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
|
255 |
* |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
256 |
* @exception ActionAbortedException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
257 |
* 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
|
258 |
* |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
259 |
* @exception ActionFailedException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
260 |
* 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
|
261 |
*/ |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
262 |
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
|
263 |
{ |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
264 |
} |
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 |
/** |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
267 |
* 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
|
268 |
* running. |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
269 |
* <p/> |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
270 |
* 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
|
271 |
* |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
272 |
* @exception ActionAbortedException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
273 |
* 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
|
274 |
* |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
275 |
* @exception ActionFailedException |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
276 |
* 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
|
277 |
* |
214
aed2b42f7344
6426 UnauthorizedActionException's name should follow convention
Stephen Talley <stephen.talley@sun.com>
parents:
196
diff
changeset
|
278 |
* @exception ActionUnauthorizedException |
138
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
279 |
* 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
|
280 |
* operation |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
281 |
*/ |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
282 |
protected void save() throws ActionAbortedException, ActionFailedException, |
214
aed2b42f7344
6426 UnauthorizedActionException's name should follow convention
Stephen Talley <stephen.talley@sun.com>
parents:
196
diff
changeset
|
283 |
ActionUnauthorizedException { |
138
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
284 |
} |
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
285 |
|
48a05b6471de
4366 wizard: wizard steps should not be limited to SwingControls
Stephen Talley <stephen.talley@sun.com>
parents:
79
diff
changeset
|
286 |
/** |
0 | 287 |
* Sets the identifier for this {@code Control}. |
288 |
*/ |
|
289 |
protected void setId(String id) { |
|
290 |
this.id = id; |
|
291 |
} |
|
292 |
||
293 |
/** |
|
294 |
* Sets the name for this {@code Control}. |
|
295 |
*/ |
|
296 |
protected void setName(String name) { |
|
297 |
this.name = name; |
|
298 |
} |
|
299 |
||
300 |
protected void setNavigator(Navigator navigator) { |
|
301 |
this.navigator = navigator; |
|
302 |
} |
|
303 |
||
304 |
private void setParameters(Map<String, String> parameters) { |
|
305 |
this.parameters = parameters; |
|
306 |
} |
|
307 |
||
308 |
/** |
|
309 |
* Called by the {@link Navigator} when this {@code Control} is pushed onto |
|
310 |
* the {@code Control} stack. |
|
311 |
* <p> |
|
312 |
* This default implementation saves references to the given {@link |
|
313 |
* #getNavigator Navigator} and {@link #getParameters initialization |
|
314 |
* parameters}. |
|
315 |
* |
|
316 |
* @param navigator |
|
317 |
* the {@link Navigator} that handles navigation to/from this |
|
318 |
* {@code Controls} |
|
319 |
* |
|
320 |
* @param parameters |
|
321 |
* non-{@code null}, but optional (may be empty) initialization |
|
322 |
* parameters |
|
323 |
* |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
26
diff
changeset
|
324 |
* @exception NavigationAbortedException |
0 | 325 |
* if this {@code Control} could not be started due to the |
326 |
* action being cancelled or vetoed |
|
327 |
* |
|
328 |
* @exception InvalidParameterException |
|
329 |
* if this {@code Control} could not be started due to invalid |
|
330 |
* intialization parameters |
|
331 |
*/ |
|
332 |
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
|
333 |
throws NavigationAbortedException, InvalidParameterException { |
0 | 334 |
setNavigator(navigator); |
335 |
setParameters(parameters); |
|
336 |
} |
|
337 |
||
338 |
/** |
|
339 |
* Called by the {@link Navigator} prior to this {@code Control} being |
|
340 |
* removed as the current {@code Control}. |
|
341 |
* <p> |
|
342 |
* This default implementation resets the reference to the {@code |
|
343 |
* Navigator} and removes any set parameters. |
|
344 |
* |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
26
diff
changeset
|
345 |
* @exception NavigationAbortedException |
0 | 346 |
* if this {@code Control} should remain the current {@code |
347 |
* Control} |
|
348 |
*/ |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
26
diff
changeset
|
349 |
public void stop() throws NavigationAbortedException { |
0 | 350 |
setNavigator(null); |
351 |
setParameters(null); |
|
352 |
} |
|
353 |
||
354 |
// |
|
355 |
// Static methods |
|
356 |
// |
|
357 |
||
358 |
/** |
|
359 |
* Encodes the given identifier and parameters. |
|
360 |
* |
|
361 |
* @param id |
|
362 |
* a {@link Control#getId Control identifier} |
|
363 |
* |
|
364 |
* @param parameters |
|
365 |
* initialization parameters, or {@code null} if no parameters |
|
366 |
* apply |
|
367 |
* |
|
368 |
* @return an encoded String |
|
369 |
*/ |
|
370 |
public static String encode(String id, Map<String, String> parameters) { |
|
371 |
StringBuffer buffer = new StringBuffer(); |
|
372 |
||
373 |
try { |
|
374 |
buffer.append(URLEncoder.encode(id, ENCODING)); |
|
375 |
||
376 |
if (parameters != null && !parameters.isEmpty()) { |
|
377 |
buffer.append("?"); |
|
378 |
boolean first = true; |
|
379 |
||
380 |
for (String key : parameters.keySet()) { |
|
381 |
if (first) { |
|
382 |
first = false; |
|
383 |
} else { |
|
384 |
buffer.append("&"); |
|
385 |
} |
|
386 |
||
387 |
String value = parameters.get(key); |
|
388 |
if (value == null) { |
|
389 |
value = ""; |
|
390 |
} else { |
|
391 |
value = URLEncoder.encode(value, ENCODING); |
|
392 |
} |
|
393 |
||
394 |
key = URLEncoder.encode(key, ENCODING); |
|
395 |
||
396 |
buffer.append(key).append("=").append(value); |
|
397 |
} |
|
398 |
} |
|
399 |
} catch (UnsupportedEncodingException ignore) { |
|
400 |
} |
|
401 |
||
402 |
return buffer.toString(); |
|
403 |
} |
|
404 |
||
405 |
public static SimpleNavigable decode(String encoded) { |
|
406 |
String[] elements = encoded.split("\\?", 2); |
|
407 |
String id = elements[0]; |
|
408 |
Map<String, String> parameters = new HashMap<String, String>(); |
|
409 |
||
410 |
try { |
|
411 |
id = URLDecoder.decode(elements[0], ENCODING); |
|
412 |
} catch (UnsupportedEncodingException ignore) { |
|
413 |
} |
|
414 |
||
79
d22c901edeff
3496 code cleanup/best practices/nits
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
415 |
if (elements.length >= 2 && !elements[1].isEmpty()) { |
0 | 416 |
String[] keyEqVals = elements[1].split("&"); |
417 |
||
418 |
for (String keyEqVal : keyEqVals) { |
|
419 |
String[] nvPair = keyEqVal.split("=", 2); |
|
420 |
String key = nvPair[0]; |
|
421 |
String value = nvPair.length < 2 ? "" : nvPair[1]; |
|
422 |
||
423 |
try { |
|
424 |
key = URLDecoder.decode(key, ENCODING); |
|
425 |
value = URLDecoder.decode(value, ENCODING); |
|
426 |
} catch (UnsupportedEncodingException ignore) { |
|
427 |
} |
|
428 |
||
429 |
parameters.put(key, value); |
|
430 |
} |
|
431 |
} |
|
432 |
||
433 |
return new SimpleNavigable(id, parameters); |
|
434 |
} |
|
435 |
} |