15664 connection recovery should be re-enabled and expanded to include all connections
authorStephen Talley <stephen.talley@oracle.com>
Mon, 19 Apr 2010 17:51:52 -0400
changeset 483 5772d1eebdf4
parent 482 cc4780b46eb0
child 484 f518e3af782d
15664 connection recovery should be re-enabled and expanded to include all connections
usr/src/java/util/org/opensolaris/os/vp/util/swing/glass/BusyGlassPane.java
usr/src/java/vpanels/client/org/opensolaris/os/vp/client/swing/AppInstance.java
usr/src/java/vpanels/client/org/opensolaris/os/vp/client/swing/resources/Resources.properties
usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/ClientContext.java
usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/view/BusyIndicator.java
usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/view/SimpleBusyIndicator.java
usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/control/WindowControl.java
usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/control/resources/Resources.properties
usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/view/SettingsButtonBar.java
usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/view/SettingsToolBar.java
--- a/usr/src/java/util/org/opensolaris/os/vp/util/swing/glass/BusyGlassPane.java	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/util/org/opensolaris/os/vp/util/swing/glass/BusyGlassPane.java	Mon Apr 19 17:51:52 2010 -0400
@@ -30,65 +30,12 @@
 import javax.swing.*;
 import javax.swing.border.*;
 import org.jdesktop.animation.timing.Animator;
+import org.opensolaris.os.vp.panel.swing.view.*;
 import org.opensolaris.os.vp.util.misc.Finder;
 import org.opensolaris.os.vp.util.swing.*;
-import org.opensolaris.os.vp.util.swing.layout.*;
 
 @SuppressWarnings({"serial"})
-public class BusyGlassPane extends SimpleGlassPane {
-    //
-    // Inner classes
-    //
-
-    public static class BusyDialog extends JPanel {
-	//
-	// Constructors
-	//
-
-	public BusyDialog() {
-	    setOpaque(false);
-	}
-
-	//
-	// Component methods
-	//
-
-	@Override
-	public void setBackground(Color c) {
-	    super.setBackground(c);
-	    setBorder();
-	}
-
-	//
-	// JComponent methods
-	//
-
-	@Override
-	public void paintComponent(Graphics g) {
-	    int w = getWidth();
-	    int h = getHeight();
-
-	    g.setColor(getBackground());
-	    g.fillRect(0, 0, w, h);
-	}
-
-	//
-	// BusyDialog methods
-	//
-
-	public void setBorder() {
-	    Border empty = GUIUtil.getEmptyBorder();
-	    Color color = ColorUtil.darker(getBackground(), .5f);
-	    Border compound = BorderFactory.createCompoundBorder(
-		new LineBorder(color), empty);
-	    compound = BorderFactory.createCompoundBorder(
-		compound, new EtchedBorder());
-	    compound = BorderFactory.createCompoundBorder(
-		compound, empty);
-	    setBorder(compound);
-	}
-    }
-
+public class BusyGlassPane extends BlockingGlassPane {
     //
     // Static data
     //
@@ -104,6 +51,9 @@
     private JProgressBar progressBar;
     private WrappingText messageLabel;
     private FadablePanel fadePanel;
+    private SettingsPanel mainPanel;
+    private JButton[] buttons;
+    private Action[] actions;
 
     //
     // Constructors
@@ -121,21 +71,13 @@
 	// at the correct size).
 	messageLabel = new WrappingText();
 
-	int gap = GUIUtil.getGap();
-	ColumnLayout layout = new ColumnLayout();
-	ColumnLayoutConstraint c = new ColumnLayoutConstraint(
-	    HorizontalAnchor.FILL, gap);
-
-	BusyDialog dialog = new BusyDialog();
-	dialog.setLayout(layout);
-	dialog.add(progressBar, c);
-        dialog.add(messageLabel,
-	    c.setHorizontalAnchor(HorizontalAnchor.CENTER));
+	createMainPanel();
 
 	JPanel shadowPanel = new ShadowPanel();
 	shadowPanel.setOpaque(false);
 	shadowPanel.setLayout(new BorderLayout());
-	shadowPanel.add(dialog, BorderLayout.CENTER);
+	shadowPanel.add(mainPanel, BorderLayout.CENTER);
+	int gap = GUIUtil.getGap();
 	Border border = BorderFactory.createEmptyBorder(gap, gap, gap, gap);
 	shadowPanel.setBorder(border);
 
@@ -161,6 +103,10 @@
     // BusyGlassPane methods
     //
 
+    public Action[] getActions() {
+	return actions;
+    }
+
     public int getDelay() {
 	return fadePanel.getAnimator().getStartDelay();
     }
@@ -169,6 +115,23 @@
 	return message;
     }
 
+    public void setActions(Action... actions) {
+	SettingsButtonBar buttonBar = mainPanel.getButtonBar();
+	if (buttons != null) {
+	    for (JButton button : buttons) {
+		buttonBar.remove(button);
+	    }
+	}
+
+	buttons = new JButton[actions.length];
+	for (int i = 0; i < actions.length; i++) {
+	    buttons[i] = new JButton(actions[i]);
+	    buttonBar.add(buttons[i]);
+	}
+
+	this.actions = actions;
+    }
+
     public void setDelay(int delay) {
 	Animator animator = fadePanel.getAnimator();
 	animator.stop();
@@ -193,9 +156,49 @@
     //
 
     protected void reset() {
+	setActions();
 	setDelay(_DELAY);
 	setMessage(null);
 	progressBar.setIndeterminate(true);
 	fadePanel.setFaded(true, false);
     }
+
+    //
+    // Private methods
+    //
+
+    private void createMainPanel() {
+	// Override paintComponent and set non-opaque to avoid bug wherein the
+	// progress bar appears well before the rest of the panel has faded in
+	mainPanel = new SettingsPanel() {
+	    @Override
+	    public void paintComponent(Graphics g) {
+		int w = getWidth();
+		int h = getHeight();
+
+		g.setColor(getBackground());
+		g.fillRect(0, 0, w, h);
+	    }
+	};
+	mainPanel.setOpaque(false);
+
+	mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+
+	Border empty = GUIUtil.getEmptyBorder();
+	Color color = ColorUtil.darker(getBackground(), .5f);
+	Border compound = BorderFactory.createCompoundBorder(
+	    new LineBorder(color), empty);
+	compound = BorderFactory.createCompoundBorder(
+	    compound, new EtchedBorder());
+	compound = BorderFactory.createCompoundBorder(
+	    compound, empty);
+	mainPanel.setBorder(compound);
+
+	JPanel helpPane = mainPanel.getHelpPane();
+	helpPane.removeAll();
+	helpPane.add(progressBar, BorderLayout.CENTER);
+	helpPane.setVisible(true);
+
+        mainPanel.getContentPane().add(messageLabel, BorderLayout.CENTER);
+    }
 }
--- a/usr/src/java/vpanels/client/org/opensolaris/os/vp/client/swing/AppInstance.java	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/vpanels/client/org/opensolaris/os/vp/client/swing/AppInstance.java	Mon Apr 19 17:51:52 2010 -0400
@@ -147,7 +147,6 @@
 
     @Override
     public void connectionFailed(ConnectionEvent event) {
-	// XXX Need to stop any pending actions and close login first
 	cListeners.connectionFailed(
 	    new ConnectionEvent(this, event.getConnectionInfo()));
     }
@@ -243,8 +242,10 @@
 	throws ActionAbortedException {
 
 	if (request == null) {
-	    ConnectionInfo info = getConnectionInfo();
-	    return new AppInstance(app, hints, info);
+	    LoginProperty host = new LoginProperty(info.getHost(), false);
+	    LoginProperty user = new LoginProperty(info.getUser(), false);
+	    LoginProperty role = new LoginProperty(info.getRole(), false);
+	    request = new LoginRequest(host, user, role);
 	}
 
 	ConnectionInfo[] infos = loginManager.getConnectionInfo(request);
--- a/usr/src/java/vpanels/client/org/opensolaris/os/vp/client/swing/resources/Resources.properties	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/vpanels/client/org/opensolaris/os/vp/client/swing/resources/Resources.properties	Mon Apr 19 17:51:52 2010 -0400
@@ -84,8 +84,3 @@
         <tr><td><b>Version:</b></td><td>{8}</td></tr>\
     </table>
 certificate.view.unknown = Unknown certificate type ({0})<br><br>{1}
-
-connection.failed.title = Connection Failed
-connection.failed.message = The connection to {0} has been lost.  Verify that {0} is reachable and its system/rad:default SMF service is enabled.
-connection.failed.option.reconnect = Reconnect
-connection.failed.option.quit = Quit
--- a/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/ClientContext.java	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/ClientContext.java	Mon Apr 19 17:51:52 2010 -0400
@@ -91,16 +91,16 @@
      * confirm the connection, even if there is an open connection matching the
      * given criteria.
      * <p/>
-     * If a connection is made to a different host, {@code request} is {@code
-     * null}, or {@code forceNewContext} is {@code true}, a new {@code
-     * ClientContext} will be created, leaving the connection to this {@code
-     * ClientContext} unchanged.  The resulting new {@code ClientContext} will
-     * NOT have any specific navigation path pre-loaded.
+     * If a connection is made to a different host or {@code forceNewContext} is
+     * {@code true}, a new {@code ClientContext} will be created, leaving the
+     * connection to this {@code ClientContext} unchanged.  The resulting new
+     * {@code ClientContext} will NOT have any specific navigation path
+     * pre-loaded.
      *
      * @param	    request
      *		    the {@link LoginRequest} encapsulating the preset values and
      *		    editability of each core {@link LoginProperty}, or {@code
-     *		    null} to create a new {@code ClientContext} using this
+     *		    null} to use a read-only {@code LoginRequest} based this
      *		    {@code ClientContext}'s {@link #getConnectionInfo current
      *		    connection}
      *
--- a/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/view/BusyIndicator.java	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/view/BusyIndicator.java	Mon Apr 19 17:51:52 2010 -0400
@@ -26,6 +26,8 @@
 
 package org.opensolaris.os.vp.panel.common.view;
 
+import javax.swing.Action;
+
 /**
  * The {@code BusyIndicator} displays a visual indication of work in progress
  * and blocks the user from interacting with the client.
@@ -61,6 +63,11 @@
     //
 
     /**
+     * Gets any {@code Action}s to be presented to the user.
+     */
+    Action[] getActions();
+
+    /**
      * Gets the delay (in milliseconds) to wait in the initial stage before
      * transitioning to the secondary stage.
      */
@@ -81,6 +88,11 @@
     boolean isBusyIndicatorDisplayed();
 
     /**
+     * Sets any {@code Action}s to be presented to the user.
+     */
+    void setActions(Action... actions);
+
+    /**
      * Sets the delay (in milliseconds) to wait in the initial stage before
      * transitioning to the secondary stage.
      */
@@ -89,7 +101,7 @@
     /**
      * Displays or hides this busy indicator.  If {@code displayed} is {@code
      * false}, all settings ({@link #setMessage message}, {@link #setDelay
-     * delay}, etc.) are reset to their defaults.
+     * delay}, {@link #getActions actions}, etc.) are reset to their defaults.
      *
      * @param	    displayed
      *		    whether to display/hide this {@code BusyIndicator}
--- a/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/view/SimpleBusyIndicator.java	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/view/SimpleBusyIndicator.java	Mon Apr 19 17:51:52 2010 -0400
@@ -26,6 +26,8 @@
 
 package org.opensolaris.os.vp.panel.common.view;
 
+import javax.swing.Action;
+
 public class SimpleBusyIndicator implements BusyIndicator {
     //
     // Instance data
@@ -34,12 +36,18 @@
     private int delay;
     private String message;
     private boolean displayed;
+    private Action[] actions;
 
     //
     // BusyIndicator methods
     //
 
     @Override
+    public Action[] getActions() {
+	return actions;
+    }
+
+    @Override
     public int getDelay() {
 	return delay;
     }
@@ -55,6 +63,11 @@
     }
 
     @Override
+    public void setActions(Action... actions) {
+	this.actions = actions;
+    }
+
+    @Override
     public void setDelay(int delay) {
 	this.delay = delay;
     }
--- a/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/control/WindowControl.java	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/control/WindowControl.java	Mon Apr 19 17:51:52 2010 -0400
@@ -30,8 +30,9 @@
 import java.awt.event.*;
 import java.util.*;
 import java.util.List;
-import javax.swing.RootPaneContainer;
+import javax.swing.*;
 import org.opensolaris.os.vp.panel.common.*;
+import org.opensolaris.os.vp.panel.common.action.ActionException;
 import org.opensolaris.os.vp.panel.common.control.*;
 import org.opensolaris.os.vp.panel.common.model.PanelDescriptor;
 import org.opensolaris.os.vp.panel.common.view.*;
@@ -128,6 +129,48 @@
 		// Prevent interaction with GUI until connection is repaired
 		busy.setMessage(Finder.getString("connection.failed.message",
 		    event.getConnectionInfo().getHost()));
+
+		Action quit =
+		    new AbstractAction(Finder.getString(
+			"connection.failed.button.quit")) {
+
+			@Override
+			public void actionPerformed(ActionEvent event) {
+			    getNavigator().asyncExec(
+				new Runnable() {
+				    @Override
+				    public void run() {
+					try {
+					    getClientContext().closeInstance(
+						true);
+					} catch (ActionException ignore) {
+					}
+				    }
+				});
+			}
+		    };
+
+		Action reconnect =
+		    new AbstractAction(Finder.getString(
+			"connection.failed.button.reconnect")) {
+
+			@Override
+			public void actionPerformed(ActionEvent event) {
+			    getNavigator().asyncExec(
+				new Runnable() {
+				    @Override
+				    public void run() {
+					try {
+                                            getClientContext().login(null,
+						false);
+					} catch (ActionException ignore) {
+					}
+				    }
+				});
+			}
+		    };
+
+		busy.setActions(quit, reconnect);
 		busy.setDelay(0);
 		busy.setBusyIndicatorDisplayed(true);
 	    }
@@ -267,9 +310,6 @@
 	if (window instanceof RootPaneContainer) {
 	    LayeredGlassPane layered = new LayeredGlassPane();
 
-	    BlockingGlassPane blocking = new BlockingGlassPane();
-	    layered.add(blocking);
-
 	    busy = new BusyGlassPaneIndicator();
 	    layered.add(busy);
 
--- a/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/control/resources/Resources.properties	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/control/resources/Resources.properties	Mon Apr 19 17:51:52 2010 -0400
@@ -53,4 +53,6 @@
 tray.popup.help = Help...
 tray.popup.exit = Exit
 
-connection.failed.message = The connection to {0} has been lost.  Waiting for connection to be reestablished...
+connection.failed.message = The connection to {0} has been lost.  Verify that {0} is reachable and its system/rad:default SMF service is enabled.
+connection.failed.button.quit = Quit
+connection.failed.button.reconnect = Reconnect...
--- a/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/view/SettingsButtonBar.java	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/view/SettingsButtonBar.java	Mon Apr 19 17:51:52 2010 -0400
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -33,7 +33,6 @@
 import javax.swing.*;
 import org.opensolaris.os.vp.util.misc.*;
 import org.opensolaris.os.vp.util.swing.GUIUtil;
-import org.opensolaris.os.vp.util.swing.layout.RowLayoutConstraint;
 
 @SuppressWarnings({"serial"})
 public class SettingsButtonBar extends SettingsToolBar {
@@ -162,8 +161,6 @@
 	    "buttons.close.label", "dialog-ok", false);
 	buttons.add(closeButton);
 
-	RowLayoutConstraint r = getDefaultConstraint();
-
 	int gap = GUIUtil.getButtonGap();
 
 	add(quitButton, 0);
--- a/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/view/SettingsToolBar.java	Fri Apr 16 10:10:41 2010 -0400
+++ b/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/swing/view/SettingsToolBar.java	Mon Apr 19 17:51:52 2010 -0400
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -56,6 +56,7 @@
 
 	    @Override
 	    public void componentRemoved(ContainerEvent e)  {
+		setVisible();
 	    }
 	};