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.swing.action.DeleteManagedObjectAction; |
|
34 import com.oracle.solaris.vp.panel.swing.control.SwingControl; |
|
35 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
36 import com.oracle.solaris.vp.util.swing.GUIUtil; |
|
37 |
|
38 @SuppressWarnings({"serial"}) |
|
39 public class DeleteMimeTypeAction |
|
40 extends DeleteManagedObjectAction<MimeType, Object, List<MimeType>> { |
|
41 |
|
42 // |
|
43 // Static data |
|
44 // |
|
45 |
|
46 private static final String TEXT = Finder.getString( |
|
47 "mimetypes.action.delete.button"); |
|
48 |
|
49 // |
|
50 // Instance data |
|
51 // |
|
52 |
|
53 private SwingControl control; |
|
54 |
|
55 // |
|
56 // Constructors |
|
57 // |
|
58 |
|
59 public DeleteMimeTypeAction(SwingControl control) { |
|
60 super(TEXT, null, control); |
|
61 this.control = control; |
|
62 } |
|
63 |
|
64 // |
|
65 // StructuredAction methods |
|
66 // |
|
67 |
|
68 @Override |
|
69 public Object getRuntimeInput(List<MimeType> selection, Object input) |
|
70 throws ActionAbortedException { |
|
71 |
|
72 int count = selection.size(); |
|
73 if (count == 0) { |
|
74 throw new ActionAbortedException(); |
|
75 } |
|
76 |
|
77 String message = Finder.getString( |
|
78 "mimetypes.action.delete.confirm." + count, |
|
79 selection.get(0).getName(), count); |
|
80 |
|
81 int response = GUIUtil.showConfirmation( |
|
82 getHasComponent().getComponent(), null, message, |
|
83 JOptionPane.YES_NO_OPTION); |
|
84 |
|
85 if (response != JOptionPane.YES_OPTION) { |
|
86 throw new ActionAbortedException(); |
|
87 } |
|
88 |
|
89 return null; |
|
90 } |
|
91 |
|
92 /** |
|
93 * Enables this {@code Action} iff the selection is not empty. |
|
94 */ |
|
95 @Override |
|
96 public void refresh() { |
|
97 setEnabled(getPresetInput().size() != 0); |
|
98 } |
|
99 |
|
100 // |
|
101 // DefaultStructuredAction methods |
|
102 // |
|
103 |
|
104 @Override |
|
105 public List<MimeType> workBusy(List<MimeType> selection, Object input) |
|
106 throws ActionAbortedException, ActionFailedException, |
|
107 ActionUnauthorizedException { |
|
108 |
|
109 if (!selection.isEmpty()) { |
|
110 MimeTypes mimeTypes = selection.get(0).getParent(); |
|
111 |
|
112 for (MimeType mimeType : selection) { |
|
113 mimeTypes.scheduleRemove(mimeType); |
|
114 } |
|
115 |
|
116 // If the running Control is a MimeTypeControl for a just-deleted |
|
117 // MimeType, reset the Control and navigate back to its parent |
|
118 Control child = control.getRunningChild(); |
|
119 if (child instanceof MimeTypeControl) { |
|
120 MimeType mimeType = ((MimeTypeControl)child).getMimeType(); |
|
121 if (selection.contains(mimeType)) { |
|
122 child.doCancel(); |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 return selection; |
|
128 } |
|
129 } |
|