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