usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/control/Navigator.java
author Stephen Talley <stephen.talley@sun.com>
Thu, 30 Oct 2008 13:52:45 -0400
changeset 133 e1112f707f32
parent 68 712f02aa3c15
child 139 2fbe46054558
permissions -rw-r--r--
4258 navigator shouldn't navigate to root control in constructor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     1
/*
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     2
 * CDDL HEADER START
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     3
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     7
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    11
 * and limitations under the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    12
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    18
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    19
 * CDDL HEADER END
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    20
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    21
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    22
/*
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    24
 * Use is subject to license terms.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    25
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    28
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    29
import java.util.*;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    30
import java.util.concurrent.*;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    31
import java.util.regex.Pattern;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    32
import org.opensolaris.os.vp.util.*;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    33
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    34
public class Navigator {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    35
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    36
    // Static data
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    37
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    38
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    39
    public static final String PATH_SEPARATOR = "/";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    40
    public static final String PARENT_ID = "..";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    48
    // Use a thread pool with a single core thread to autmatically handle
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    49
    // uncaught exceptions and queued requests
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    50
    private ThreadPoolExecutor threadPool;
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    51
    {
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    52
	ThreadFactory factory =
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    53
	    new NamedThreadFactory("Navigator-") {
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    54
		@Override
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    55
		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
    56
		    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
    57
		    return dispatchThread;
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    58
		}
25cc24ff4f57 3329 navigation thread pool should be non-static, per-Navigator
Stephen Talley <stephen.talley@sun.com>
parents: 54
diff changeset
    59
	    };
30
0ad10e34fb31 3025 Thread pools should be named for better diagnostics
Stephen Talley <stephen.talley@sun.com>
parents: 21
diff changeset
    60
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    61
	// Unbounded
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    62
	BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    63
30
0ad10e34fb31 3025 Thread pools should be named for better diagnostics
Stephen Talley <stephen.talley@sun.com>
parents: 21
diff changeset
    64
	threadPool = new ThreadPoolExecutor(
0ad10e34fb31 3025 Thread pools should be named for better diagnostics
Stephen Talley <stephen.talley@sun.com>
parents: 21
diff changeset
    65
	    1, 1, 10, TimeUnit.MINUTES, queue, factory);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    66
30
0ad10e34fb31 3025 Thread pools should be named for better diagnostics
Stephen Talley <stephen.talley@sun.com>
parents: 21
diff changeset
    67
	threadPool.allowCoreThreadTimeOut(true);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    68
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    69
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    70
    private StackList<Control> stack = new StackList<Control>();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    71
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    72
    private List<NavigationListener> listeners =
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    73
	new ArrayList<NavigationListener>();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    74
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    75
    private List<NavigationListener> roListeners =
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    76
	Collections.unmodifiableList(listeners);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    77
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    78
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    79
    // Navigator methods
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    80
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    81
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    82
    /**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    83
     * Adds a {@link NavigationListener} to be notified when navigation is
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    84
     * stopped and started.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    85
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    86
    public void addNavigationListener(NavigationListener l) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    87
	listeners.add(l);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    88
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    89
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    90
    /**
60
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
    91
     * 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
    92
     * 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
    93
     * 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
    94
     * 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
    95
     * handling any thrown exceptions.
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
    96
     * <p/>
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
    97
     * 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
    98
     * 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
    99
     * available.
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   100
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   101
     * @param	    r
60
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   102
     *		    the {@code Runnable} to run and handle any resulting
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   103
     *		    exceptions
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   104
     */
19
9c1f74f86687 2837 Minor spelling errors and inconsistencies
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   105
    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
   106
	threadPool.execute(r);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   107
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   108
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   109
    /**
68
712f02aa3c15 3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents: 60
diff changeset
   110
     * 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
   111
     * 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
   112
     * are thrown here.
60
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   113
     * <p/>
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   114
     * See {@link #asyncExec}.
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   115
     *
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   116
     * @param	    r
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   117
     *		    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
   118
     */
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   119
    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
   120
	throws NavigationAbortedException, InvalidAddressException,
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   121
	MissingParameterException, InvalidParameterException {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   122
68
712f02aa3c15 3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents: 60
diff changeset
   123
	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
   124
	    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
   125
	    return;
712f02aa3c15 3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents: 60
diff changeset
   126
	}
712f02aa3c15 3348 After selecting existing login from new window, unable to close window
Stephen Talley <stephen.talley@sun.com>
parents: 60
diff changeset
   127
60
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   128
	final boolean[] done = {false};
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   129
	final Throwable[] throwable = {null};
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   130
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   131
	asyncExec(
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   132
	    new Runnable() {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   133
		@Override
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   134
		public void run() {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   135
		    try {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   136
			r.run();
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   137
		    } catch (Throwable t) {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   138
			throwable[0] = t;
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   139
		    }
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   140
		    synchronized (done) {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   141
			done[0] = true;
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   142
			done.notify();
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
		}
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   145
	    });
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   146
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   147
	// 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
   148
	synchronized (done) {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   149
	    while (!done[0]) {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   150
		try {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   151
		    done.wait();
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   152
		} catch (InterruptedException ignore) {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   153
		}
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   154
	    }
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   155
	}
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   156
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   157
	Throwable t = throwable[0];
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   158
	if (t != null) {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   159
	    if (t instanceof NavigationAbortedException)
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   160
		throw (NavigationAbortedException)t;
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   161
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   162
	    if (t instanceof InvalidAddressException)
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   163
		throw (InvalidAddressException)t;
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   164
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   165
	    if (t instanceof MissingParameterException)
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   166
		throw (MissingParameterException)t;
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   167
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   168
	    if (t instanceof InvalidParameterException)
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   169
		throw (InvalidParameterException)t;
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   170
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   171
	    if (t instanceof RuntimeException)
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   172
		throw (RuntimeException)t;
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   173
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   174
	    if (t instanceof Error)
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   175
		throw (Error)t;
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   176
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   177
	    // 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
   178
	    assert false;
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   179
	}
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
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   182
    /**
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   183
     * Notifies all registered {@link NavigationListener}s that a navigation has
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   184
     * begun.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   185
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   186
    protected void fireNavigationStarted(NavigationEvent e) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   187
	// Iterate backwards to allow listener removal during iteration
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   188
	for (int i = listeners.size() - 1; i >= 0; i--) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   189
	    listeners.get(i).navigationStarted(e);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   190
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   191
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   192
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   193
    /**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   194
     * Notifies all registered {@link NavigationListener}s that a navigation has
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   195
     * stopped.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   196
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   197
    protected void fireNavigationStopped(NavigationEvent e) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   198
	// Iterate backwards to allow listener removal during iteration
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   199
	for (int i = listeners.size() - 1; i >= 0; i--) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   200
	    listeners.get(i).navigationStopped(e);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   201
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   202
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   203
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   204
    /**
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   205
     * 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
   206
     * 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
   207
     */
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   208
    public Control getCurrentControl() {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   209
	synchronized (stack) {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   210
	    return StackUtil.getTop(stack);
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   211
	}
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   212
    }
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   213
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   214
    public List<NavigationListener> getNavigationListeners() {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   215
	return roListeners;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   216
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   217
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   218
    /**
54
ffbdd1a03fca 3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents: 40
diff changeset
   219
     * Gets the current path.  This method is not thread-safe; it is up to
ffbdd1a03fca 3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents: 40
diff changeset
   220
     * 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
   221
     * path.
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   222
     */
54
ffbdd1a03fca 3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents: 40
diff changeset
   223
    @SuppressWarnings({"unchecked"})
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   224
    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
   225
	return (List<Control>)stack.clone();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   226
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   227
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   228
    /**
54
ffbdd1a03fca 3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents: 40
diff changeset
   229
     * 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
   230
     * 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
   231
     * currently modifying this path.
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   232
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   233
    public String getPathString() {
54
ffbdd1a03fca 3305 consumers of Navigator's getPath subject to ConcurrentModificationExceptions
Stephen Talley <stephen.talley@sun.com>
parents: 40
diff changeset
   234
	return getPathString(stack);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   235
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   236
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   237
    /**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   238
     * Navigates to the {@link Control} identified by the given path.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   239
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   240
     * @param	    relativeTo
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   241
     *		    a {@link Control} within the navigation stack to which
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   242
     *		    {@code path} is relative, or {@code null} if {@code path} is
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   243
     *		    absolute
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   244
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   245
     * @param	    path
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   246
     *		    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
   247
     *		    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
   248
     *		    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
   249
     *		    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
   250
     *		    Control}
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   251
     *
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   252
     * @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
   253
     *		    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
   254
     *		    been set
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   255
     *
40
d1412af1ae5b 3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents: 30
diff changeset
   256
     * @exception   NavigationAbortedException
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   257
     *		    if the navigation is vetoed
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   258
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   259
     * @exception   InvalidAddressException
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   260
     *		    if {@code path} does not refer to a valid address
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   261
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   262
     * @exception   MissingParameterException
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   263
     *		    if some {@link Control} in the process of navigation could
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   264
     *		    not be {@link Control#start started} due to a missing
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   265
     *		    intialization parameter
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   266
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   267
     * @exception   InvalidParameterException
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   268
     *		    if some {@link Control} in the process of navigation could
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   269
     *		    not be {@link Control#start started} due to an invalid
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   270
     *		    intialization parameter
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   271
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   272
     * @exception   IllegalArgumentException
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   273
     *		    if {@code relativeTo} is not in the navigation stack
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   274
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   275
    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
   276
	throws NavigationAbortedException, InvalidAddressException,
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   277
	MissingParameterException, InvalidParameterException {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   278
60
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   279
	assert isDispatchThread();
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   280
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   281
	synchronized (stack) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   282
	    // Last absolute path
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   283
	    StackList<Navigable> laPath = new StackList<Navigable>();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   284
	    laPath.addAll(stack);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   285
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   286
	    while (true) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   287
		// Current absolute path
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   288
		StackList<Navigable> caPath = new StackList<Navigable>();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   289
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   290
		if (relativeTo != null) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   291
		    caPath.addAll(laPath);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   292
		    try {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   293
			// Remove path elements until relativeTo is at the top
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   294
			while (!((HasControl)caPath.peek()).getControl().
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   295
			    equals(relativeTo)) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   296
			    caPath.pop();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   297
			}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   298
		    } catch (EmptyStackException e) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   299
			throw new IllegalArgumentException(String.format(
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   300
			    "Control not in navigation path: %s (%s)",
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   301
			    relativeTo.getClass().getName(),
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   302
			    relativeTo.getId()));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   303
		    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   304
		}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   305
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   306
		if (path.length != 0) {
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   307
		    CollectionUtil.addAll(caPath, path);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   308
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   309
		    // Remove unnecessary ".." segments
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   310
		    normalize(caPath);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   311
		}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   312
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   313
		List<Navigable> rPath = getRelativePath(laPath, caPath);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   314
		if (rPath.isEmpty()) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   315
		    break;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   316
		}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   317
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   318
		// 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
   319
		// laPath as appropriate
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   320
		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
   321
		    if (nav.getId().equals(PARENT_ID)) {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   322
			if (laPath.isEmpty()) {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   323
			    throw new IllegalArgumentException(
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   324
				"navigation stack has no root");
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   325
			}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   326
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   327
			laPath.pop();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   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();
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   342
			    Object last = laPath.peek();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   354
			}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   355
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   358
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   359
			laPath.push(pair);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   360
		    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   361
		}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   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 {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   364
		    Control control = ((HasControl)laPath.peek()).getControl();
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   365
		    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
   366
		    if (forward == null) {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   367
			break;
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   368
		    }
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   369
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   370
		    path = toArray(forward);
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   371
		    relativeTo = isAbsolute(forward) ? null : control;
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   372
		} catch (EmptyStackException ignore) {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   373
		    // No root Control
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   374
		}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   375
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   376
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   377
	    // 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
   378
	    Control orig = getCurrentControl();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   379
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   380
	    @SuppressWarnings({"unchecked"})
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   381
	    List<PendingControl> rPath =
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   382
		(List<PendingControl>)(List)getRelativePath(stack, laPath);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   383
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   384
	    if (!rPath.isEmpty()) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   385
		NavigationEvent event = new NavigationEvent(this,
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   386
		    Collections.unmodifiableList(rPath));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   387
		fireNavigationStarted(event);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   388
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   389
		try {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   390
		    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
   391
			Control curControl = getCurrentControl();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   392
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   393
			if (pend.getId().equals(PARENT_ID)) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   394
			    curControl.stop();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   395
			    stack.pop();
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   396
			    Control newCurControl = getCurrentControl();
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   397
			    if (newCurControl != null) {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   398
				newCurControl.childStopped(curControl);
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   399
			    }
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   400
			} else {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   401
			    Control newControl = pend.getControl();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   402
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   403
			    newControl.start(this, pend.getParameters());
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   404
			    stack.push(newControl);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   405
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   406
			    if (curControl != null) {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   407
				curControl.childStarted(newControl);
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   408
			    }
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   409
			}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   410
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   411
			if (System.getProperty("vpanels.debug.navigator") !=
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   412
			    null) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   413
			    System.out.printf("%s\n", getPathString());
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   414
			}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   415
		    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   416
		} finally {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   417
		    fireNavigationStopped(event);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   418
		}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   419
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   420
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   421
	    return orig;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   422
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   423
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   424
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   425
    /**
20
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   426
     * 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
   427
     * 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
   428
     * 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
   429
     */
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   430
    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
   431
	asyncExec(
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   432
	    new Runnable() {
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   433
		@Override
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   434
		public void run() {
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   435
		    try {
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   436
			goTo(relativeTo, path);
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   437
		    } catch (NavigationException ignore) {
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   438
		    }
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   439
		}
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
    /**
60
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   444
     * 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
   445
     * 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
   446
     * {@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
   447
     * {@link #asyncExecAndWait}.
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   448
     */
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   449
    public void goToAsyncAndWait(
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   450
	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
   451
	throws NavigationAbortedException, InvalidAddressException,
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   452
	MissingParameterException, InvalidParameterException {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   453
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   454
	asyncExecAndWait(
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   455
	    new NavRunnable() {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   456
		@Override
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   457
		public void run()
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   458
		    throws NavigationAbortedException, InvalidAddressException,
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   459
		    MissingParameterException, InvalidParameterException {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   460
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   461
		    goTo(relativeTo, path);
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
	    });
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
    /**
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   467
     * Shortcut for:
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   468
     * <p>
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   469
     *	 <code>
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   470
     *	   {@link #goTo(Control,Navigable...) goTo}(relativeTo,
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   471
     *	   new {@link SimpleNavigable#SimpleNavigable(String,Map)
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   472
     *	   SimpleNavigable}(id, {@link Navigable.Util#toMap
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   473
     *	   Navigable.Util.toMap}(parameters)));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   474
     *	 </code>
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   475
     * </p>
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   476
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   477
    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
   478
	String... parameters) throws NavigationAbortedException,
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   479
	InvalidAddressException, MissingParameterException,
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   480
	InvalidParameterException {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   481
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   482
	return goTo(relativeTo,
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   483
	    new SimpleNavigable(id, Navigable.Util.toMap(parameters)));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   484
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   485
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   486
    /**
60
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   487
     * 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
   488
     * 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
   489
     */
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   490
    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
   491
	final String... parameters) {
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   492
	    asyncExec(
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   493
		new Runnable() {
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   494
		    @Override
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   495
		    public void run() {
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   496
			try {
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   497
			    goTo(relativeTo, id, parameters);
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   498
			} catch (NavigationException ignore) {
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   499
			}
5423319ed064 2853 Async navigation in serious need of factoring
David Powell <David.Powell@sun.com>
parents: 19
diff changeset
   500
		    }
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
    /**
60
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   505
     * 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
   506
     * 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
   507
     */
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   508
    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
   509
	final String... parameters)
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   510
	throws NavigationAbortedException, InvalidAddressException,
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   511
	MissingParameterException, InvalidParameterException {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   512
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   513
	asyncExecAndWait(
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   514
	    new NavRunnable() {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   515
		@Override
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   516
		public void run()
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   517
		    throws NavigationAbortedException, InvalidAddressException,
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   518
		    MissingParameterException, InvalidParameterException {
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   519
9a179bed654e 3334 navigation should be run solely on navigation thread
Stephen Talley <stephen.talley@sun.com>
parents: 59
diff changeset
   520
		    goTo(relativeTo, id, parameters);
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
	    });
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
    /**
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   526
     * Navigate to the parent of the current {@link Control}.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   527
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   528
     * @return	    the previously current {@link Control}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   529
     *
40
d1412af1ae5b 3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents: 30
diff changeset
   530
     * @exception   NavigationAbortedException
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   531
     *		    if the navigation is vetoed
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   532
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   533
     * @exception   IllegalArgumentException
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   534
     *		    if the navigation stack consists only of the root element
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   535
     */
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   536
    public Control goToParent() throws NavigationAbortedException {
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   537
	try {
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   538
	    return goTo(getCurrentControl(), PendingControl.PARENT);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   539
	} catch (InvalidAddressException ignore) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   540
	    // Should not be possible
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   541
	} catch (InvalidParameterException ignore) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   542
	    // Should not be possible
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   543
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   544
	return null;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   545
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   546
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   547
    /**
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   548
     * 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
   549
     * 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
   550
     * 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
   551
     */
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   552
    public boolean isDispatchThread() {
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   553
	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
   554
    }
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   555
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   556
    /**
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   557
     * Removes a {@link NavigationListener} from notification of when navigation
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   558
     * is stopped and started.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   559
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   560
    public boolean removeNavigationListener(NavigationListener l) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   561
	return listeners.remove(l);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   562
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   563
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   564
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   565
    // Private methods
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   566
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   567
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   568
    /**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   569
     * Gets the relative path between the given absolute paths.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   570
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   571
     * @param	    fromPath
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   572
     *		    an absolute source path
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   573
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   574
     * @param	    toPath
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   575
     *		    an absolute destination path
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   576
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   577
     * @return	    a relative path from the current path to the given path
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   578
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   579
    private List<Navigable> getRelativePath(
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   580
	List<? extends Navigable> fromPath,
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   581
	List<? extends Navigable> toPath) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   582
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   583
	List<Navigable> rPath = new ArrayList<Navigable>();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   584
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   585
	// Determine branching index
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   586
	int branch = 0;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   587
	while (branch < fromPath.size() && branch < toPath.size() &&
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   588
	    Navigable.Util.equals(fromPath.get(branch), toPath.get(branch))) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   589
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   590
	    branch++;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   591
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   592
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   593
	for (int i = fromPath.size() - 1; i >= branch; i--) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   594
	    rPath.add(PendingControl.PARENT);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   595
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   596
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   597
	for (int i = branch; i < toPath.size(); i++) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   598
	    rPath.add(toPath.get(i));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   599
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   600
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   601
	return rPath;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   602
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   603
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   604
    /**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   605
     * Removes each ".." segment and preceding non-".." segment the given path.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   606
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   607
    private void normalize(List<? extends HasId> path) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   608
	for (int i = 1; i < path.size(); i++) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   609
	    if (path.get(i).getId().equals(PARENT_ID) &&
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   610
		!path.get(i - 1).getId().equals(PARENT_ID)) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   611
		path.remove(i--);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   612
		path.remove(i--);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   613
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   614
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   615
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   616
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   617
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   618
    // Static methods
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   619
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   620
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   621
    /**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   622
     * Gets the given path as a {@code String}.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   623
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   624
    public static String getPathString(Collection<? extends Navigable> path) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   625
	StringBuffer buffer = new StringBuffer();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   626
133
e1112f707f32 4258 navigator shouldn't navigate to root control in constructor
Stephen Talley <stephen.talley@sun.com>
parents: 68
diff changeset
   627
	for (Navigable nav : path) {
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   628
	    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
   629
		nav.getId(), nav.getParameters()));
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   630
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   631
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   632
	return buffer.toString();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   633
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   634
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   635
    /**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   636
     * Determines whether the given path is absolute.  If the given path starts
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   637
     * with PATH_SEPARATOR, it is considered absolute.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   638
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   639
    public static boolean isAbsolute(String path) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   640
	return path.startsWith(PATH_SEPARATOR);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   641
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   642
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   643
    public static SimpleNavigable[] toArray(String path) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   644
	path = path.replaceFirst(
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   645
	    "^(" + Pattern.quote(PATH_SEPARATOR) + ")+", "");
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   646
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   647
	String[] parts = path.split(PATH_SEPARATOR, 0);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   648
	SimpleNavigable[] elements = new SimpleNavigable[parts.length];
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   649
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   650
	for (int i = 0; i < parts.length; i++) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   651
	    elements[i] = Control.decode(parts[i]);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   652
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   653
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   654
	return elements;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   655
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   656
}