KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > ui > actions > RemoveInstanceAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.deployment.impl.ui.actions;
21
22 import org.openide.util.actions.*;
23 import org.openide.actions.*;
24 import org.openide.nodes.*;
25 import org.openide.util.HelpCtx;
26 import org.netbeans.modules.j2ee.deployment.impl.*;
27 import org.netbeans.modules.j2ee.deployment.impl.ui.*;
28 import org.openide.NotifyDescriptor;
29 import org.openide.util.NbBundle;
30 import org.openide.DialogDisplayer;
31
32 /**
33  * Remove instance action displays a confirmation dialog whether the server should
34  * be removed. The server is stopped before removal if it was started from within
35  * the IDE before.
36  *
37  * @author nn136682
38  */

39 public class RemoveInstanceAction extends CookieAction {
40     
41     protected void performAction(org.openide.nodes.Node[] nodes) {
42         for (int i=0; i<nodes.length; i++) {
43             ServerInstance instance = (ServerInstance) nodes[i].getCookie(ServerInstance.class);
44             if (instance == null || instance.isRemoveForbidden()) {
45                 continue;
46             }
47             String JavaDoc title = NbBundle.getMessage(RemoveInstanceAction.class, "MSG_RemoveInstanceTitle", instance.getDisplayName());
48             String JavaDoc msg = NbBundle.getMessage(RemoveInstanceAction.class, "MSG_ReallyRemoveInstance", instance.getDisplayName());
49             NotifyDescriptor d = new NotifyDescriptor.Confirmation(msg, title, NotifyDescriptor.OK_CANCEL_OPTION);
50             if (DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.OK_OPTION) {
51                 instance.remove();
52             }
53         }
54     }
55     
56     protected boolean enable (Node[] nodes) {
57         for (int i = 0; i < nodes.length; i++) {
58             ServerInstance instance = (ServerInstance)nodes[i].getCookie(ServerInstance.class);
59             if (instance == null || instance.isRemoveForbidden()
60                 || instance.getServerState() == ServerInstance.STATE_WAITING) {
61                 return false;
62             }
63         }
64         return true;
65     }
66     
67     protected Class JavaDoc[] cookieClasses() {
68         return new Class JavaDoc[] {
69             ServerInstance.class
70         };
71     }
72     
73     protected int mode() {
74         return MODE_ALL;
75     }
76     
77     public String JavaDoc getName() {
78         return NbBundle.getMessage(RemoveInstanceAction.class, "LBL_Remove");
79     }
80     
81     public org.openide.util.HelpCtx getHelpCtx() {
82         return HelpCtx.DEFAULT_HELP;
83     }
84     
85     protected boolean asynchronous() {
86         return false;
87     }
88
89 }
90
Popular Tags