components/visual-panels/apache/src/java/vpanels/app/apache/com/oracle/solaris/vp/panels/apache/client/swing/CloneVirtualHostAction.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.panels.apache.client.swing;
       
    27 
       
    28 import java.awt.Component;
       
    29 import java.util.List;
       
    30 import javax.swing.JOptionPane;
       
    31 import com.oracle.solaris.vp.panel.common.action.*;
       
    32 import com.oracle.solaris.vp.panel.common.control.*;
       
    33 import com.oracle.solaris.vp.panel.common.model.ManagedObject;
       
    34 import com.oracle.solaris.vp.panel.swing.action.CloneManagedObjectAction;
       
    35 import com.oracle.solaris.vp.panel.swing.control.SwingControl;
       
    36 import com.oracle.solaris.vp.util.misc.finder.Finder;
       
    37 
       
    38 @SuppressWarnings({"serial"})
       
    39 public class CloneVirtualHostAction
       
    40     extends CloneManagedObjectAction<ManagedObject, String, VirtualHost> {
       
    41 
       
    42     //
       
    43     // Instance data
       
    44     //
       
    45 
       
    46     private SwingControl<ApachePanelDescriptor, ?> control;
       
    47 
       
    48     //
       
    49     // Constructors
       
    50     //
       
    51 
       
    52     public CloneVirtualHostAction(
       
    53 	SwingControl<ApachePanelDescriptor, ?> control) {
       
    54 
       
    55 	super(TEXT, ICONS, control);
       
    56 	this.control = control;
       
    57 	setLoops(true);
       
    58     }
       
    59 
       
    60     //
       
    61     // StructuredAction methods
       
    62     //
       
    63 
       
    64     @Override
       
    65     public String getRuntimeInput(List<ManagedObject> selection, String domain)
       
    66 	throws ActionAbortedException {
       
    67 
       
    68 	Object response = JOptionPane.showInputDialog(
       
    69 	    getHasComponent().getComponent(),
       
    70 	    Finder.getString("vhosts.action.clone.message"),
       
    71 	    Finder.getString("vhosts.action.clone.title"),
       
    72 	    JOptionPane.PLAIN_MESSAGE, null, null, domain);
       
    73 
       
    74 	if (response == null) {
       
    75 	    throw new ActionAbortedException();
       
    76 	}
       
    77 
       
    78 	return response.toString();
       
    79     }
       
    80 
       
    81     /**
       
    82      * Enables this {@code Action} iff a single {@link VirtualHost} is selected.
       
    83      */
       
    84     @Override
       
    85     public void refresh() {
       
    86 	List<ManagedObject> selection = getPresetInput();
       
    87 	boolean enabled = selection.size() == 1 &&
       
    88 	    selection.get(0) instanceof VirtualHost;
       
    89 
       
    90 	setEnabled(enabled);
       
    91     }
       
    92 
       
    93     //
       
    94     // DefaultStructuredAction methods
       
    95     //
       
    96 
       
    97     @Override
       
    98     public VirtualHost workBusy(List<ManagedObject> selection,
       
    99 	String domain) throws ActionAbortedException, ActionFailedException,
       
   100 	ActionUnauthorizedException {
       
   101 
       
   102 	VirtualHost.validateDomainName(domain, null);
       
   103 
       
   104 	// Assume valid selection
       
   105 	VirtualHost orig = (VirtualHost)selection.get(0);
       
   106 
       
   107 	VirtualHost clone = orig.clone();
       
   108 	clone.getEnabledProperty().setFirstValue(false);
       
   109 	clone.getDomainProperty().setFirstValue(domain);
       
   110 
       
   111 	control.getPanelDescriptor().addChildren(clone);
       
   112 
       
   113 	// Navigate to the new virtual host
       
   114 	Navigable navigable = new SimpleNavigable(
       
   115 	    VirtualHostControl.ID, null,
       
   116 	    VirtualHostControl.PARAM_ID, clone.getId());
       
   117 
       
   118 	control.getNavigator().goToAsync(false, control, navigable);
       
   119 
       
   120 	return clone;
       
   121     }
       
   122 }