author | Stephen Talley <stephen.talley@sun.com> |
Fri, 20 Feb 2009 13:56:20 -0500 | |
changeset 219 | 57841c113efe |
parent 190 | 555203a2de79 |
child 243 | 979bb698977b |
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 |
/* |
|
219
57841c113efe
6788 package names should share o.o.o.vp prefix
Stephen Talley <stephen.talley@sun.com>
parents:
190
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:
30
diff
changeset
|
27 |
package org.opensolaris.os.vp.panel.common.control; |
0 | 28 |
|
29 |
import java.util.*; |
|
30 |
import java.util.concurrent.*; |
|
31 |
import java.util.regex.Pattern; |
|
219
57841c113efe
6788 package names should share o.o.o.vp prefix
Stephen Talley <stephen.talley@sun.com>
parents:
190
diff
changeset
|
32 |
import org.opensolaris.os.vp.util.misc.*; |
0 | 33 |
|
34 |
public class Navigator { |
|
35 |
// |
|
36 |
// Static data |
|
37 |
// |
|
38 |
||
39 |
public static final String PATH_SEPARATOR = "/"; |
|
40 |
public static final String PARENT_ID = ".."; |
|
41 |
||
59
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
42 |
// |
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
43 |
// Instance data |
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
44 |
// |
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
45 |
|
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
46 |
private Thread dispatchThread; |
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
47 |
private ThreadPoolExecutor threadPool; |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
48 |
private LinkedList<Control> stack = new LinkedList<Control>(); |
157
f4316b998c95
4857 all classes that handle event management should use EventListeners class
Stephen Talley <stephen.talley@sun.com>
parents:
156
diff
changeset
|
49 |
private NavigationListeners listeners = new NavigationListeners(false); |
156
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
50 |
private String name; |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
51 |
|
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
52 |
// |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
53 |
// Constructors |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
54 |
// |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
55 |
|
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
56 |
public Navigator(String name) { |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
57 |
this.name = name; |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
58 |
|
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
59 |
String tName = String.format("%s-%s-", |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
60 |
TextUtil.getClassBaseName(getClass()), name); |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
61 |
|
59
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
62 |
ThreadFactory factory = |
156
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
63 |
new NamedThreadFactory(tName) { |
59
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
64 |
@Override |
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
65 |
public Thread newThread(Runnable r) { |
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
66 |
dispatchThread = super.newThread(r); |
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
67 |
return dispatchThread; |
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
68 |
} |
25cc24ff4f57
3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents:
54
diff
changeset
|
69 |
}; |
30
0ad10e34fb31
3025 Thread pools should be named for better diagnostics
Stephen Talley <stephen.talley@sun.com>
parents:
21
diff
changeset
|
70 |
|
0 | 71 |
// Unbounded |
72 |
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(); |
|
73 |
||
157
f4316b998c95
4857 all classes that handle event management should use EventListeners class
Stephen Talley <stephen.talley@sun.com>
parents:
156
diff
changeset
|
74 |
// Use a thread pool with a single core thread to autmatically handle |
f4316b998c95
4857 all classes that handle event management should use EventListeners class
Stephen Talley <stephen.talley@sun.com>
parents:
156
diff
changeset
|
75 |
// uncaught exceptions and queued requests |
30
0ad10e34fb31
3025 Thread pools should be named for better diagnostics
Stephen Talley <stephen.talley@sun.com>
parents:
21
diff
changeset
|
76 |
threadPool = new ThreadPoolExecutor( |
0ad10e34fb31
3025 Thread pools should be named for better diagnostics
Stephen Talley <stephen.talley@sun.com>
parents:
21
diff
changeset
|
77 |
1, 1, 10, TimeUnit.MINUTES, queue, factory); |
0 | 78 |
|
30
0ad10e34fb31
3025 Thread pools should be named for better diagnostics
Stephen Talley <stephen.talley@sun.com>
parents:
21
diff
changeset
|
79 |
threadPool.allowCoreThreadTimeOut(true); |
0 | 80 |
} |
81 |
||
82 |
// |
|
83 |
// Navigator methods |
|
84 |
// |
|
85 |
||
86 |
/** |
|
87 |
* Adds a {@link NavigationListener} to be notified when navigation is |
|
88 |
* stopped and started. |
|
89 |
*/ |
|
90 |
public void addNavigationListener(NavigationListener l) { |
|
91 |
listeners.add(l); |
|
92 |
} |
|
93 |
||
94 |
/** |
|
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
95 |
* Runs the given {@code Runnable} asynchronously on this {@code |
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
96 |
* Navigator}'s navigation thread. This thread is intended to be used |
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
97 |
* specifically for navigation; the given {@code Runnable} should thus be |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
98 |
* limited to calling {@link #goTo(Control,Navigable...)} and (briefly) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
99 |
* handling any thrown exceptions. |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
100 |
* <p/> |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
101 |
* Note: If this method is called when the navigation thread is busy, the |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
102 |
* given {@code Runnable} will be queued and run when the thread is |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
103 |
* available. |
0 | 104 |
* |
105 |
* @param r |
|
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
106 |
* the {@code Runnable} to run and handle any resulting |
0 | 107 |
* exceptions |
108 |
*/ |
|
19
9c1f74f86687
2837 Minor spelling errors and inconsistencies
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
109 |
public void asyncExec(Runnable r) { |
30
0ad10e34fb31
3025 Thread pools should be named for better diagnostics
Stephen Talley <stephen.talley@sun.com>
parents:
21
diff
changeset
|
110 |
threadPool.execute(r); |
0 | 111 |
} |
112 |
||
113 |
/** |
|
68
712f02aa3c15
3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents:
60
diff
changeset
|
114 |
* Runs the given {@link NavRunnable} on this {@code Navigator}'s navigation |
712f02aa3c15
3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents:
60
diff
changeset
|
115 |
* thread and waits for it to complete. Any exceptions thrown by {@code r} |
712f02aa3c15
3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents:
60
diff
changeset
|
116 |
* are thrown here. |
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
117 |
* <p/> |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
118 |
* See {@link #asyncExec}. |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
119 |
* |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
120 |
* @param r |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
121 |
* the {@link NavRunnable} to run |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
122 |
*/ |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
123 |
public void asyncExecAndWait(final NavRunnable r) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
124 |
throws NavigationAbortedException, InvalidAddressException, |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
125 |
MissingParameterException, InvalidParameterException { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
126 |
|
68
712f02aa3c15
3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents:
60
diff
changeset
|
127 |
if (isDispatchThread()) { |
712f02aa3c15
3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents:
60
diff
changeset
|
128 |
r.run(); |
712f02aa3c15
3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents:
60
diff
changeset
|
129 |
return; |
712f02aa3c15
3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents:
60
diff
changeset
|
130 |
} |
712f02aa3c15
3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents:
60
diff
changeset
|
131 |
|
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
132 |
final boolean[] done = {false}; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
133 |
final Throwable[] throwable = {null}; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
134 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
135 |
asyncExec( |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
136 |
new Runnable() { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
137 |
@Override |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
138 |
public void run() { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
139 |
try { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
140 |
r.run(); |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
141 |
} catch (Throwable t) { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
142 |
throwable[0] = t; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
143 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
144 |
synchronized (done) { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
145 |
done[0] = true; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
146 |
done.notify(); |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
147 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
148 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
149 |
}); |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
150 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
151 |
// Sleep until nav thread is done |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
152 |
synchronized (done) { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
153 |
while (!done[0]) { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
154 |
try { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
155 |
done.wait(); |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
156 |
} catch (InterruptedException ignore) { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
157 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
158 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
159 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
160 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
161 |
Throwable t = throwable[0]; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
162 |
if (t != null) { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
163 |
if (t instanceof NavigationAbortedException) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
164 |
throw (NavigationAbortedException)t; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
165 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
166 |
if (t instanceof InvalidAddressException) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
167 |
throw (InvalidAddressException)t; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
168 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
169 |
if (t instanceof MissingParameterException) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
170 |
throw (MissingParameterException)t; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
171 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
172 |
if (t instanceof InvalidParameterException) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
173 |
throw (InvalidParameterException)t; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
174 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
175 |
if (t instanceof RuntimeException) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
176 |
throw (RuntimeException)t; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
177 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
178 |
if (t instanceof Error) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
179 |
throw (Error)t; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
180 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
181 |
// All Throwables should be accounted for |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
182 |
assert false; |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
183 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
184 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
185 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
186 |
/** |
0 | 187 |
* Notifies all registered {@link NavigationListener}s that a navigation has |
188 |
* begun. |
|
189 |
*/ |
|
190 |
protected void fireNavigationStarted(NavigationEvent e) { |
|
157
f4316b998c95
4857 all classes that handle event management should use EventListeners class
Stephen Talley <stephen.talley@sun.com>
parents:
156
diff
changeset
|
191 |
listeners.navigationStarted(e); |
0 | 192 |
} |
193 |
||
194 |
/** |
|
195 |
* Notifies all registered {@link NavigationListener}s that a navigation has |
|
196 |
* stopped. |
|
197 |
*/ |
|
198 |
protected void fireNavigationStopped(NavigationEvent e) { |
|
157
f4316b998c95
4857 all classes that handle event management should use EventListeners class
Stephen Talley <stephen.talley@sun.com>
parents:
156
diff
changeset
|
199 |
listeners.navigationStopped(e); |
0 | 200 |
} |
201 |
||
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
202 |
/** |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
203 |
* Returns the current {@link Control}, or {@code null} if the root element |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
204 |
* of the navigation stack has not yet been set. |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
205 |
*/ |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
206 |
public Control getCurrentControl() { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
207 |
synchronized (stack) { |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
208 |
return stack.peekLast(); |
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
209 |
} |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
210 |
} |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
211 |
|
156
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
212 |
public String getName() { |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
213 |
return name; |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
214 |
} |
ad266190d7e6
4537 sysid: closing window during login + confirmation = hang
Stephen Talley <stephen.talley@sun.com>
parents:
139
diff
changeset
|
215 |
|
0 | 216 |
/** |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
217 |
* Gets a list of the elements of the current path, with the root element at |
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
218 |
* the beginning of the list. This method is not thread-safe; it is up to |
54
ffbdd1a03fca
3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
219 |
* callers to ensure the that navigation is not currently modifying this |
ffbdd1a03fca
3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
220 |
* path. |
0 | 221 |
*/ |
54
ffbdd1a03fca
3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
222 |
@SuppressWarnings({"unchecked"}) |
0 | 223 |
public List<Control> getPath() { |
54
ffbdd1a03fca
3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
224 |
return (List<Control>)stack.clone(); |
0 | 225 |
} |
226 |
||
227 |
/** |
|
54
ffbdd1a03fca
3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
228 |
* Gets the current path as a {@code String}. This method is not |
ffbdd1a03fca
3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
229 |
* thread-safe; it is up to callers to ensure the that navigation is not |
ffbdd1a03fca
3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
230 |
* currently modifying this path. |
0 | 231 |
*/ |
232 |
public String getPathString() { |
|
54
ffbdd1a03fca
3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
233 |
return getPathString(stack); |
0 | 234 |
} |
235 |
||
236 |
/** |
|
237 |
* Navigates to the {@link Control} identified by the given path. |
|
238 |
* |
|
239 |
* @param relativeTo |
|
240 |
* a {@link Control} within the navigation stack to which |
|
241 |
* {@code path} is relative, or {@code null} if {@code path} is |
|
242 |
* absolute |
|
243 |
* |
|
244 |
* @param path |
|
245 |
* the path (relative to {@code relativeTo}), or unspecified to |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
246 |
* navigate up the stack to {@code relativeTo}; if the root of |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
247 |
* this {@code Navigator} has not yet been set, the first |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
248 |
* element of this path <strong>must</strong> be a {@link |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
249 |
* Control} |
0 | 250 |
* |
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
251 |
* @return the previously current {@link Control}, or {@code null} if |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
252 |
* the root {@link Control} of the navigation stack has not yet |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
253 |
* been set |
0 | 254 |
* |
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
30
diff
changeset
|
255 |
* @exception NavigationAbortedException |
0 | 256 |
* if the navigation is vetoed |
257 |
* |
|
258 |
* @exception InvalidAddressException |
|
259 |
* if {@code path} does not refer to a valid address |
|
260 |
* |
|
261 |
* @exception MissingParameterException |
|
262 |
* if some {@link Control} in the process of navigation could |
|
263 |
* not be {@link Control#start started} due to a missing |
|
264 |
* intialization parameter |
|
265 |
* |
|
266 |
* @exception InvalidParameterException |
|
267 |
* if some {@link Control} in the process of navigation could |
|
268 |
* not be {@link Control#start started} due to an invalid |
|
269 |
* intialization parameter |
|
270 |
* |
|
271 |
* @exception IllegalArgumentException |
|
272 |
* if {@code relativeTo} is not in the navigation stack |
|
273 |
*/ |
|
274 |
public Control goTo(Control relativeTo, Navigable... path) |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
30
diff
changeset
|
275 |
throws NavigationAbortedException, InvalidAddressException, |
0 | 276 |
MissingParameterException, InvalidParameterException { |
277 |
||
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
278 |
assert isDispatchThread(); |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
279 |
|
0 | 280 |
synchronized (stack) { |
281 |
// Last absolute path |
|
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
282 |
LinkedList<Navigable> laPath = new LinkedList<Navigable>(); |
0 | 283 |
laPath.addAll(stack); |
284 |
||
285 |
while (true) { |
|
286 |
// Current absolute path |
|
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
287 |
LinkedList<Navigable> caPath = new LinkedList<Navigable>(); |
0 | 288 |
|
289 |
if (relativeTo != null) { |
|
290 |
caPath.addAll(laPath); |
|
291 |
try { |
|
292 |
// Remove path elements until relativeTo is at the top |
|
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
293 |
while (!((HasControl)caPath.getLast()).getControl(). |
0 | 294 |
equals(relativeTo)) { |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
295 |
caPath.removeLast(); |
0 | 296 |
} |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
297 |
} catch (NoSuchElementException e) { |
0 | 298 |
throw new IllegalArgumentException(String.format( |
299 |
"Control not in navigation path: %s (%s)", |
|
300 |
relativeTo.getClass().getName(), |
|
301 |
relativeTo.getId())); |
|
302 |
} |
|
303 |
} |
|
304 |
||
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
305 |
if (path.length != 0) { |
0 | 306 |
CollectionUtil.addAll(caPath, path); |
307 |
||
308 |
// Remove unnecessary ".." segments |
|
309 |
normalize(caPath); |
|
310 |
} |
|
311 |
||
312 |
List<Navigable> rPath = getRelativePath(laPath, caPath); |
|
313 |
if (rPath.isEmpty()) { |
|
314 |
break; |
|
315 |
} |
|
316 |
||
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
317 |
// Iterate through rPath, adding/removing elements to/from |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
318 |
// laPath as appropriate |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
319 |
for (Navigable nav : rPath) { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
320 |
if (nav.getId().equals(PARENT_ID)) { |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
321 |
try { |
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
322 |
laPath.removeLast(); |
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
323 |
} catch (NoSuchElementException e) { |
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
324 |
throw new IllegalArgumentException( |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
325 |
"\"..\" encountered with empty navigation " + |
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
326 |
"stack"); |
0 | 327 |
} |
328 |
} else { |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
329 |
Control newControl; |
0 | 330 |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
331 |
// If the Navigation stack has no root... |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
332 |
if (laPath.isEmpty()) { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
333 |
try { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
334 |
newControl = (Control)nav; |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
335 |
} catch (ClassCastException e) { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
336 |
throw new IllegalArgumentException( |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
337 |
"root-level Navigable \"" + nav.getName() + |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
338 |
"\" must be a Control"); |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
339 |
} |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
340 |
} else { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
341 |
String id = nav.getId(); |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
342 |
Object last = laPath.getLast(); |
0 | 343 |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
344 |
// laPath elements are Controls or PendingControls |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
345 |
Control curControl = |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
346 |
((HasControl)last).getControl(); |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
347 |
newControl = curControl.getChildControl(id); |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
348 |
|
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
349 |
if (newControl == null) { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
350 |
throw new InvalidAddressException(String.format( |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
351 |
"%s%s%s", getPathString(laPath), |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
352 |
PATH_SEPARATOR, id)); |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
353 |
} |
0 | 354 |
} |
355 |
||
356 |
PendingControl pair = |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
357 |
new PendingControl(newControl, nav.getParameters()); |
0 | 358 |
|
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
359 |
laPath.add(pair); |
0 | 360 |
} |
361 |
} |
|
362 |
||
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
363 |
try { |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
364 |
Control control = |
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
365 |
((HasControl)laPath.getLast()).getControl(); |
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
366 |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
367 |
String forward = control.getForwardingPath(); |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
368 |
if (forward == null) { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
369 |
break; |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
370 |
} |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
371 |
|
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
372 |
path = toArray(forward); |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
373 |
relativeTo = isAbsolute(forward) ? null : control; |
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
374 |
} catch (NoSuchElementException ignore) { |
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
375 |
// No root Control |
0 | 376 |
} |
377 |
} |
|
378 |
||
379 |
// The original Control, before navigation |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
380 |
Control orig = getCurrentControl(); |
0 | 381 |
|
382 |
@SuppressWarnings({"unchecked"}) |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
383 |
List<PendingControl> rPath = |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
384 |
(List<PendingControl>)(List)getRelativePath(stack, laPath); |
0 | 385 |
|
386 |
if (!rPath.isEmpty()) { |
|
387 |
NavigationEvent event = new NavigationEvent(this, |
|
388 |
Collections.unmodifiableList(rPath)); |
|
389 |
fireNavigationStarted(event); |
|
390 |
||
391 |
try { |
|
392 |
for (PendingControl pend : rPath) { |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
393 |
Control curControl = getCurrentControl(); |
0 | 394 |
|
395 |
if (pend.getId().equals(PARENT_ID)) { |
|
396 |
curControl.stop(); |
|
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
397 |
stack.removeLast(); |
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
398 |
Control newCurControl = getCurrentControl(); |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
399 |
if (newCurControl != null) { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
400 |
newCurControl.childStopped(curControl); |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
401 |
} |
0 | 402 |
} else { |
403 |
Control newControl = pend.getControl(); |
|
404 |
||
405 |
newControl.start(this, pend.getParameters()); |
|
190
555203a2de79
5952 Stack API should conform to java.util.Dequeue specification
Stephen Talley <stephen.talley@sun.com>
parents:
157
diff
changeset
|
406 |
stack.add(newControl); |
0 | 407 |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
408 |
if (curControl != null) { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
409 |
curControl.childStarted(newControl); |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
410 |
} |
0 | 411 |
} |
412 |
||
413 |
if (System.getProperty("vpanels.debug.navigator") != |
|
414 |
null) { |
|
415 |
System.out.printf("%s\n", getPathString()); |
|
416 |
} |
|
417 |
} |
|
418 |
} finally { |
|
419 |
fireNavigationStopped(event); |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
return orig; |
|
424 |
} |
|
425 |
} |
|
426 |
||
427 |
/** |
|
20
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
428 |
* Asynchronously navigates to the {@link Control} identified by the |
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
429 |
* given path. A wrapper around {@link #goTo(Control,Navigable...)} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
430 |
* that is run asynchronously using {@link #asyncExec}. |
20
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
431 |
*/ |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
432 |
public void goToAsync(final Control relativeTo, final Navigable... path) { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
433 |
asyncExec( |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
434 |
new Runnable() { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
435 |
@Override |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
436 |
public void run() { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
437 |
try { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
438 |
goTo(relativeTo, path); |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
439 |
} catch (NavigationException ignore) { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
440 |
} |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
441 |
} |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
442 |
}); |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
443 |
} |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
444 |
|
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
445 |
/** |
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
446 |
* Asynchronously navigates to the {@link Control} identified by the given |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
447 |
* path, returning only when navigation is complete. A wrapper around |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
448 |
* {@link #goTo(Control,Navigable...)} that is run asynchronously using |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
449 |
* {@link #asyncExecAndWait}. |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
450 |
*/ |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
451 |
public void goToAsyncAndWait( |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
452 |
final Control relativeTo, final Navigable... path) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
453 |
throws NavigationAbortedException, InvalidAddressException, |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
454 |
MissingParameterException, InvalidParameterException { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
455 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
456 |
asyncExecAndWait( |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
457 |
new NavRunnable() { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
458 |
@Override |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
459 |
public void run() |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
460 |
throws NavigationAbortedException, InvalidAddressException, |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
461 |
MissingParameterException, InvalidParameterException { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
462 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
463 |
goTo(relativeTo, path); |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
464 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
465 |
}); |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
466 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
467 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
468 |
/** |
0 | 469 |
* Shortcut for: |
470 |
* <p> |
|
471 |
* <code> |
|
472 |
* {@link #goTo(Control,Navigable...) goTo}(relativeTo, |
|
473 |
* new {@link SimpleNavigable#SimpleNavigable(String,Map) |
|
474 |
* SimpleNavigable}(id, {@link Navigable.Util#toMap |
|
475 |
* Navigable.Util.toMap}(parameters))); |
|
476 |
* </code> |
|
477 |
* </p> |
|
478 |
*/ |
|
479 |
public Control goTo(Control relativeTo, String id, |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
30
diff
changeset
|
480 |
String... parameters) throws NavigationAbortedException, |
0 | 481 |
InvalidAddressException, MissingParameterException, |
482 |
InvalidParameterException { |
|
483 |
||
484 |
return goTo(relativeTo, |
|
485 |
new SimpleNavigable(id, Navigable.Util.toMap(parameters))); |
|
486 |
} |
|
487 |
||
488 |
/** |
|
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
489 |
* A wrapper around {@link #goTo(Control,String,String...)} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
490 |
* that is run asynchronously using {@link #asyncExec}. |
20
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
491 |
*/ |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
492 |
public void goToAsync(final Control relativeTo, final String id, |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
493 |
final String... parameters) { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
494 |
asyncExec( |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
495 |
new Runnable() { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
496 |
@Override |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
497 |
public void run() { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
498 |
try { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
499 |
goTo(relativeTo, id, parameters); |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
500 |
} catch (NavigationException ignore) { |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
501 |
} |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
502 |
} |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
503 |
}); |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
504 |
} |
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
505 |
|
5423319ed064
2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents:
19
diff
changeset
|
506 |
/** |
60
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
507 |
* A wrapper around {@link #goTo(Control,String,String...)} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
508 |
* that is run asynchronously using {@link #asyncExecAndWait}. |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
509 |
*/ |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
510 |
public void goToAsyncAndWait(final Control relativeTo, final String id, |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
511 |
final String... parameters) |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
512 |
throws NavigationAbortedException, InvalidAddressException, |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
513 |
MissingParameterException, InvalidParameterException { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
514 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
515 |
asyncExecAndWait( |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
516 |
new NavRunnable() { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
517 |
@Override |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
518 |
public void run() |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
519 |
throws NavigationAbortedException, InvalidAddressException, |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
520 |
MissingParameterException, InvalidParameterException { |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
521 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
522 |
goTo(relativeTo, id, parameters); |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
523 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
524 |
}); |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
525 |
} |
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
526 |
|
9a179bed654e
3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents:
59
diff
changeset
|
527 |
/** |
0 | 528 |
* Navigate to the parent of the current {@link Control}. |
529 |
* |
|
530 |
* @return the previously current {@link Control} |
|
531 |
* |
|
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
30
diff
changeset
|
532 |
* @exception NavigationAbortedException |
0 | 533 |
* if the navigation is vetoed |
534 |
* |
|
535 |
* @exception IllegalArgumentException |
|
536 |
* if the navigation stack consists only of the root element |
|
537 |
*/ |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
538 |
public Control goToParent() throws NavigationAbortedException { |
0 | 539 |
try { |
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
540 |
return goTo(getCurrentControl(), PendingControl.PARENT); |
0 | 541 |
} catch (InvalidAddressException ignore) { |
542 |
// Should not be possible |
|
543 |
} catch (InvalidParameterException ignore) { |
|
544 |
// Should not be possible |
|
545 |
} |
|
546 |
return null; |
|
547 |
} |
|
548 |
||
549 |
/** |
|
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
550 |
* Determines whether the current thread is the navigation dispatch thread. |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
551 |
* The navigation dispatch thread may change over time, but only one is |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
552 |
* alive at a time. |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
553 |
*/ |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
554 |
public boolean isDispatchThread() { |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
555 |
return Thread.currentThread() == dispatchThread; |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
556 |
} |
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
557 |
|
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
558 |
/** |
0 | 559 |
* Removes a {@link NavigationListener} from notification of when navigation |
560 |
* is stopped and started. |
|
561 |
*/ |
|
562 |
public boolean removeNavigationListener(NavigationListener l) { |
|
563 |
return listeners.remove(l); |
|
564 |
} |
|
565 |
||
566 |
// |
|
567 |
// Private methods |
|
568 |
// |
|
569 |
||
570 |
/** |
|
571 |
* Gets the relative path between the given absolute paths. |
|
572 |
* |
|
573 |
* @param fromPath |
|
574 |
* an absolute source path |
|
575 |
* |
|
576 |
* @param toPath |
|
577 |
* an absolute destination path |
|
578 |
* |
|
579 |
* @return a relative path from the current path to the given path |
|
580 |
*/ |
|
581 |
private List<Navigable> getRelativePath( |
|
582 |
List<? extends Navigable> fromPath, |
|
583 |
List<? extends Navigable> toPath) { |
|
584 |
||
585 |
List<Navigable> rPath = new ArrayList<Navigable>(); |
|
586 |
||
587 |
// Determine branching index |
|
588 |
int branch = 0; |
|
589 |
while (branch < fromPath.size() && branch < toPath.size() && |
|
590 |
Navigable.Util.equals(fromPath.get(branch), toPath.get(branch))) { |
|
591 |
||
592 |
branch++; |
|
593 |
} |
|
594 |
||
595 |
for (int i = fromPath.size() - 1; i >= branch; i--) { |
|
596 |
rPath.add(PendingControl.PARENT); |
|
597 |
} |
|
598 |
||
599 |
for (int i = branch; i < toPath.size(); i++) { |
|
600 |
rPath.add(toPath.get(i)); |
|
601 |
} |
|
602 |
||
603 |
return rPath; |
|
604 |
} |
|
605 |
||
606 |
/** |
|
607 |
* Removes each ".." segment and preceding non-".." segment the given path. |
|
608 |
*/ |
|
609 |
private void normalize(List<? extends HasId> path) { |
|
610 |
for (int i = 1; i < path.size(); i++) { |
|
611 |
if (path.get(i).getId().equals(PARENT_ID) && |
|
612 |
!path.get(i - 1).getId().equals(PARENT_ID)) { |
|
613 |
path.remove(i--); |
|
614 |
path.remove(i--); |
|
615 |
} |
|
616 |
} |
|
617 |
} |
|
618 |
||
619 |
// |
|
620 |
// Static methods |
|
621 |
// |
|
622 |
||
623 |
/** |
|
624 |
* Gets the given path as a {@code String}. |
|
625 |
*/ |
|
626 |
public static String getPathString(Collection<? extends Navigable> path) { |
|
627 |
StringBuffer buffer = new StringBuffer(); |
|
628 |
||
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
629 |
for (Navigable nav : path) { |
0 | 630 |
buffer.append(PATH_SEPARATOR).append(Control.encode( |
133
e1112f707f32
4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents:
68
diff
changeset
|
631 |
nav.getId(), nav.getParameters())); |
0 | 632 |
} |
633 |
||
634 |
return buffer.toString(); |
|
635 |
} |
|
636 |
||
637 |
/** |
|
638 |
* Determines whether the given path is absolute. If the given path starts |
|
639 |
* with PATH_SEPARATOR, it is considered absolute. |
|
640 |
*/ |
|
641 |
public static boolean isAbsolute(String path) { |
|
642 |
return path.startsWith(PATH_SEPARATOR); |
|
643 |
} |
|
644 |
||
645 |
public static SimpleNavigable[] toArray(String path) { |
|
646 |
path = path.replaceFirst( |
|
647 |
"^(" + Pattern.quote(PATH_SEPARATOR) + ")+", ""); |
|
648 |
||
649 |
String[] parts = path.split(PATH_SEPARATOR, 0); |
|
650 |
SimpleNavigable[] elements = new SimpleNavigable[parts.length]; |
|
651 |
||
652 |
for (int i = 0; i < parts.length; i++) { |
|
653 |
elements[i] = Control.decode(parts[i]); |
|
654 |
} |
|
655 |
||
656 |
return elements; |
|
657 |
} |
|
658 |
} |