components/visual-panels/usermgr/src/java/vpanels/app/usermgr/com/oracle/solaris/vp/panels/usermgr/client/swing/DeleteUserAction.java
changeset 827 0944d8c0158b
child 843 190d2b5889a8
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) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panels.usermgr.client.swing;
       
    27 
       
    28 import java.awt.*;
       
    29 import java.awt.event.*;
       
    30 import javax.swing.*;
       
    31 import java.util.List;
       
    32 import javax.swing.JOptionPane;
       
    33 import com.oracle.solaris.vp.panel.common.action.*;
       
    34 import com.oracle.solaris.vp.panel.common.control.Control;
       
    35 import com.oracle.solaris.vp.panel.swing.action.DeleteManagedObjectAction;
       
    36 import com.oracle.solaris.vp.panel.swing.control.SwingControl;
       
    37 import com.oracle.solaris.vp.util.misc.*;
       
    38 import com.oracle.solaris.vp.util.misc.finder.Finder;
       
    39 import com.oracle.solaris.vp.util.swing.GUIUtil;
       
    40 
       
    41 /**
       
    42  * Delete a user or role
       
    43  */
       
    44 @SuppressWarnings({"serial"})
       
    45 public class DeleteUserAction extends DeleteManagedObjectAction
       
    46     <UserManagedObject, UserManagedObject, List<UserManagedObject>> {
       
    47 
       
    48     //
       
    49     // Static data
       
    50     //
       
    51 
       
    52     private static final String DELETE_TEXT = Finder.getString(
       
    53 	"usermgr.action.delete.button");
       
    54 
       
    55     //
       
    56     // Instance data
       
    57     //
       
    58 
       
    59     private SwingControl control;
       
    60 
       
    61     //
       
    62     // Constructors
       
    63     //
       
    64 
       
    65     public DeleteUserAction(SwingControl control) {
       
    66 	super(DELETE_TEXT, null, control);
       
    67         ActionString actStr = new ActionString(
       
    68 	    "usermgr.action.delete.button");
       
    69 	putValue(Action.NAME, actStr.getString());
       
    70 	putValue(Action.MNEMONIC_KEY, actStr.getMnemonic());
       
    71 	this.control = control;
       
    72     }
       
    73 
       
    74     //
       
    75     // StructuredAction methods
       
    76     //
       
    77 
       
    78     @Override
       
    79     public UserManagedObject getRuntimeInput(List<UserManagedObject> selection,
       
    80 	UserManagedObject input) throws ActionAbortedException {
       
    81 
       
    82 	if (selection.isEmpty()) {
       
    83 	    throw new ActionAbortedException();
       
    84 	}
       
    85 	UserMgrPanelDescriptor descriptor = (UserMgrPanelDescriptor)
       
    86 	    control.getPanelDescriptor();
       
    87 
       
    88 	String message = Finder.getString("usermgr.action.delete.confirm." +
       
    89 		descriptor.getTypeString(), selection.get(0).getName());
       
    90 
       
    91 	JOptionPane pane = new JOptionPane(message,
       
    92 	    JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
       
    93 	 UserMgrUtils.removeIcons(pane);
       
    94 	 JDialog dialog = pane.createDialog(getHasComponent().getComponent(),
       
    95 		Finder.getString("usermgr.action.delete.title." +
       
    96 		descriptor.getTypeString()));
       
    97 
       
    98 	dialog.setVisible(true);
       
    99 
       
   100 	if (!ObjectUtil.equals(pane.getValue(), JOptionPane.OK_OPTION)) {
       
   101 	    throw new ActionAbortedException();
       
   102         }
       
   103 
       
   104 	return null;
       
   105     }
       
   106 
       
   107     //
       
   108     // DefaultStructuredAction methods
       
   109     //
       
   110 
       
   111     @Override
       
   112     public List<UserManagedObject> workBusy(List<UserManagedObject> selection,
       
   113 	UserManagedObject input) throws ActionAbortedException,
       
   114 	ActionFailedException, ActionUnauthorizedException {
       
   115 
       
   116 	if (!selection.isEmpty()) {
       
   117 	    UserMgrPanelDescriptor descriptor = (UserMgrPanelDescriptor)
       
   118 		control.getPanelDescriptor();
       
   119 	    descriptor.addToDeleteList(selection.get(0));
       
   120 	    descriptor.saveDeletedUsers();
       
   121 	    // If the running Control is a UserMgrControl for a just-deleted
       
   122 	    // service, reset the Control and navigate back to its parent
       
   123 	    Control child = control.getRunningChild();
       
   124 	    if (child instanceof UserMgrBasicControl) {
       
   125 		UserManagedObject umo =
       
   126 		    ((UserMgrBasicControl)child).getUserManagedObject();
       
   127 
       
   128 		if (selection.contains(umo)) {
       
   129 		    child.doCancel();
       
   130 		}
       
   131 	    }
       
   132 	}
       
   133 
       
   134 	return selection;
       
   135     }
       
   136 }