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, 2013, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panel.swing.smf; |
|
27 |
|
28 import java.util.List; |
|
29 import com.oracle.solaris.rad.client.RadPrivilegeException; |
|
30 import com.oracle.solaris.scf.common.ScfException; |
|
31 import com.oracle.solaris.vp.panel.common.action.*; |
|
32 import com.oracle.solaris.vp.panel.common.smf.*; |
|
33 import com.oracle.solaris.vp.panel.swing.action.UpdateManagedObjectAction; |
|
34 import com.oracle.solaris.vp.panel.swing.control.SwingControl; |
|
35 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
36 |
|
37 @SuppressWarnings("serial") |
|
38 public class ClearServiceAction |
|
39 extends UpdateManagedObjectAction<SmfManagedObject, Object, Object> { |
|
40 |
|
41 protected static final String TEXT_CLEAR = |
|
42 Finder.getString("service.action.clear"); |
|
43 |
|
44 // |
|
45 // Constructors |
|
46 // |
|
47 |
|
48 public ClearServiceAction(SwingControl control) { |
|
49 super(TEXT_CLEAR, ICONS, control); |
|
50 } |
|
51 |
|
52 // |
|
53 // StructuredAction methods |
|
54 // |
|
55 |
|
56 @Override |
|
57 public void refresh() { |
|
58 super.refresh(); |
|
59 |
|
60 if (isEnabled()) { |
|
61 // Verify each selected item is an InstanceManagedObject |
|
62 for (SmfManagedObject o : getPresetInput()) { |
|
63 if (!(o instanceof InstanceManagedObject)) { |
|
64 setEnabled(false); |
|
65 break; |
|
66 } |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 // |
|
72 // DefaultStructuredAction methods |
|
73 // |
|
74 |
|
75 @Override |
|
76 public Object workBusy(List<SmfManagedObject> selection, Object input) |
|
77 throws ActionFailedException, ActionUnauthorizedException { |
|
78 |
|
79 for (SmfManagedObject object : selection) { |
|
80 // Selection has been verified as InstanceManagedObjects |
|
81 InstanceManagedObject inst = (InstanceManagedObject)object; |
|
82 try { |
|
83 inst.getService().clear(); |
|
84 } catch (ScfException e) { |
|
85 SmfUtil.throwActionException(e); |
|
86 } catch (RadPrivilegeException e) { |
|
87 throw new ActionUnauthorizedException(e); |
|
88 } |
|
89 } |
|
90 |
|
91 return null; |
|
92 } |
|
93 } |
|