|
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.util.List; |
|
29 import com.oracle.solaris.vp.panel.common.action.*; |
|
30 import com.oracle.solaris.vp.panel.common.model.ManagedObject; |
|
31 import com.oracle.solaris.vp.panel.swing.action.EnableManagedObjectAction; |
|
32 import com.oracle.solaris.vp.panel.swing.control.SwingControl; |
|
33 |
|
34 @SuppressWarnings({"serial"}) |
|
35 public class EnableVirtualHostAction |
|
36 extends EnableManagedObjectAction<ManagedObject, Object, Object> { |
|
37 |
|
38 // |
|
39 // Instance data |
|
40 // |
|
41 |
|
42 private SwingControl control; |
|
43 |
|
44 // |
|
45 // Constructors |
|
46 // |
|
47 |
|
48 public EnableVirtualHostAction(SwingControl control, boolean enable) { |
|
49 super(enable ? TEXT_ENABLE : TEXT_DISABLE, null, control, enable); |
|
50 this.control = control; |
|
51 } |
|
52 |
|
53 // |
|
54 // StructuredAction methods |
|
55 // |
|
56 |
|
57 /** |
|
58 * Enables this {@code Action} iff the selection contains only {@link |
|
59 * VirtualHost}s, and the enabled state of at least one would be changed by |
|
60 * this action. |
|
61 */ |
|
62 @Override |
|
63 public void refresh() { |
|
64 boolean enabled = false; |
|
65 List<ManagedObject> selection = getPresetInput(); |
|
66 |
|
67 for (ManagedObject o : selection) { |
|
68 if (!(o instanceof VirtualHost)) { |
|
69 enabled = false; |
|
70 break; |
|
71 } |
|
72 |
|
73 if (!enabled) { |
|
74 VirtualHost vHost = (VirtualHost)o; |
|
75 if (vHost.isEnabled() != getEnable()) { |
|
76 enabled = true; |
|
77 } |
|
78 } |
|
79 } |
|
80 |
|
81 setEnabled(enabled); |
|
82 } |
|
83 |
|
84 // |
|
85 // DefaultStructuredAction methods |
|
86 // |
|
87 |
|
88 @Override |
|
89 public Object workBusy(List<ManagedObject> selection, Object input) |
|
90 throws ActionAbortedException, ActionFailedException, |
|
91 ActionUnauthorizedException { |
|
92 |
|
93 boolean enable = getEnable(); |
|
94 |
|
95 for (ManagedObject object : selection) { |
|
96 VirtualHost vHost = (VirtualHost)object; |
|
97 vHost.getEnabledProperty().setFirstValue(enable); |
|
98 } |
|
99 |
|
100 return null; |
|
101 } |
|
102 } |