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