|
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.Control; |
|
33 import com.oracle.solaris.vp.panel.common.model.ManagedObject; |
|
34 import com.oracle.solaris.vp.panel.swing.action.DeleteManagedObjectAction; |
|
35 import com.oracle.solaris.vp.panel.swing.control.SwingControl; |
|
36 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
37 import com.oracle.solaris.vp.util.swing.GUIUtil; |
|
38 |
|
39 @SuppressWarnings({"serial"}) |
|
40 public class DeleteVirtualHostAction |
|
41 extends DeleteManagedObjectAction<ManagedObject, Object, VirtualHost[]> { |
|
42 |
|
43 // |
|
44 // Static data |
|
45 // |
|
46 |
|
47 private static final String TEXT = Finder.getString( |
|
48 "vhosts.action.delete.button"); |
|
49 |
|
50 // |
|
51 // Instance data |
|
52 // |
|
53 |
|
54 private SwingControl control; |
|
55 |
|
56 // |
|
57 // Constructors |
|
58 // |
|
59 |
|
60 public DeleteVirtualHostAction(SwingControl control) { |
|
61 super(TEXT, null, control); |
|
62 this.control = control; |
|
63 } |
|
64 |
|
65 // |
|
66 // StructuredAction methods |
|
67 // |
|
68 |
|
69 @Override |
|
70 public Object getRuntimeInput(List<ManagedObject> selection, Object input) |
|
71 throws ActionAbortedException { |
|
72 |
|
73 int count = selection.size(); |
|
74 if (count == 0) { |
|
75 throw new ActionAbortedException(); |
|
76 } |
|
77 |
|
78 String message = Finder.getString( |
|
79 "vhosts.action.delete.confirm." + count, |
|
80 selection.get(0).getName(), count); |
|
81 |
|
82 int response = GUIUtil.showConfirmation( |
|
83 getHasComponent().getComponent(), null, message, |
|
84 JOptionPane.YES_NO_OPTION); |
|
85 |
|
86 if (response != JOptionPane.YES_OPTION) { |
|
87 throw new ActionAbortedException(); |
|
88 } |
|
89 |
|
90 return null; |
|
91 } |
|
92 |
|
93 /** |
|
94 * Enables this {@code Action} iff the selection is not empty and is all |
|
95 * {@link VirtualHost}s. |
|
96 */ |
|
97 @Override |
|
98 public void refresh() { |
|
99 boolean enabled = getPresetInput().size() != 0; |
|
100 |
|
101 if (enabled) { |
|
102 List<ManagedObject> selection = getPresetInput(); |
|
103 for (ManagedObject o : selection) { |
|
104 if (!(o instanceof VirtualHost)) { |
|
105 enabled = false; |
|
106 break; |
|
107 } |
|
108 } |
|
109 } |
|
110 |
|
111 setEnabled(enabled); |
|
112 } |
|
113 |
|
114 // |
|
115 // DefaultStructuredAction methods |
|
116 // |
|
117 |
|
118 @Override |
|
119 public VirtualHost[] workBusy(List<ManagedObject> selection, |
|
120 Object input) throws ActionAbortedException, ActionFailedException, |
|
121 ActionUnauthorizedException { |
|
122 |
|
123 // Selection has been verified as VirtualHosts |
|
124 VirtualHost[] vHosts = selection.toArray( |
|
125 new VirtualHost[selection.size()]); |
|
126 |
|
127 if (!selection.isEmpty()) { |
|
128 ApachePanelDescriptor descriptor = vHosts[0].getPanelDescriptor(); |
|
129 descriptor.scheduleRemove(vHosts); |
|
130 |
|
131 // If the running Control is a VirtualHostControl for a just-deleted |
|
132 // VirtualHost, reset the Control and navigate back to its parent |
|
133 Control child = control.getRunningChild(); |
|
134 if (child instanceof VirtualHostControl) { |
|
135 VirtualHost vHost = |
|
136 ((VirtualHostControl)child).getVirtualHost(); |
|
137 |
|
138 if (selection.contains(vHost)) { |
|
139 child.doCancel(); |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 return vHosts; |
|
145 } |
|
146 } |