components/visual-panels/core/src/java/vpanels/panel/com/oracle/solaris/vp/panel/common/control/NavigationErrorHandler.java
changeset 827 0944d8c0158b
equal deleted inserted replaced
826:c6aad84d2493 827:0944d8c0158b
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panel.common.control;
       
    27 
       
    28 import java.util.List;
       
    29 
       
    30 /**
       
    31  * The {@code NavigationErrorHandler} class chooses the best path to re-navigate
       
    32  * to on navigation error.  If no {@link Control}s were started as a result of
       
    33  * the failed navigation, then the navigation is considered a complete failure
       
    34  * and a navigation back to the previous path is scheduled asynchronously.
       
    35  * Otherwise, a navigation to the current path is scheduled, which will cause
       
    36  * any path returned by {@link Navigator#getCurrentControl the current
       
    37  * Control}'s {@link Control#getForwardingPath} method to be followed.
       
    38  */
       
    39 public class NavigationErrorHandler implements NavigationListener {
       
    40     //
       
    41     // NavigationListener methods
       
    42     //
       
    43 
       
    44     @Override
       
    45     public void navigationStarted(NavigationStartEvent e) {
       
    46     }
       
    47 
       
    48     @Override
       
    49     public void navigationStopped(NavigationStopEvent event) {
       
    50 	if (!event.getNavigationSuccessful()) {
       
    51 	    Navigator navigator = event.getSource();
       
    52 
       
    53 	    boolean equal = false;
       
    54 	    Navigable[] last = event.getPreviousPath();
       
    55 	    List<Control> current = navigator.getPath();
       
    56 	    if (last.length == current.size()) {
       
    57 		equal = true;
       
    58 		for (int i = 0; i < last.length; i++) {
       
    59 		    if (!Navigable.Util.equals(last[i], current.get(i))) {
       
    60 			equal = false;
       
    61 			break;
       
    62 		    }
       
    63 		}
       
    64 	    }
       
    65 
       
    66 	    // Only re-navigate if the last path differs from the current path
       
    67 	    if (!equal) {
       
    68                 // If any Controls were started as a result of this navigation,
       
    69                 // assume it was successful enough to stay where we are.
       
    70                 // Otherwise, go back.
       
    71 		if (event.getStarted().isEmpty()) {
       
    72 		    // Go back
       
    73 		    navigator.goToAsync(true, null, last);
       
    74 		} else {
       
    75 		    // Navigate to the current path, which will forward to the
       
    76 		    // current Control's getForwardingPath, if any
       
    77 		    navigator.goToAsync(true, navigator.getCurrentControl());
       
    78 		}
       
    79 	    }
       
    80 	}
       
    81     }
       
    82 }