KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > runtime > actions > UndeployAction


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

20 import java.util.Vector JavaDoc;
21 import org.openide.ErrorManager;
22 import org.openide.nodes.Node;
23 import org.openide.util.Lookup;
24 import org.openide.util.actions.NodeAction;
25 import org.openide.util.NbBundle;
26 import org.openide.util.HelpCtx;
27 import org.openide.util.RequestProcessor;
28 import org.netbeans.modules.j2ee.sun.bridge.apis.Undeployable;
29
30 import org.netbeans.modules.j2ee.sun.bridge.apis.RefreshCookie;
31
32 /**
33  *
34  *
35  */

36 public class UndeployAction extends NodeAction {
37     
38     /**
39      *
40      *
41      */

42     protected void performAction(final Node[] activatedNodes) {
43         if (activatedNodes==null){
44             return;
45         }
46         Vector JavaDoc parents = new java.util.Vector JavaDoc();
47         for (int i=0;i<activatedNodes.length;i++){
48             Node parentNode = activatedNodes[i].getParentNode();
49             parents.add(parentNode);
50         }
51         final Object JavaDoc[] parentNodes = parents.toArray();
52         
53         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
54             public void run() {
55                 for (int i=0;i<activatedNodes.length;i++){
56                     Node node = activatedNodes[i];
57                     Lookup lookup = node.getLookup();
58                     Object JavaDoc obj = lookup.lookup(Undeployable.class);
59                     
60                     try {
61                         if(obj instanceof Undeployable) {
62                             Undeployable undeployableObj = (Undeployable)obj;
63                             undeployableObj.undeploy();
64                         }
65                     } catch(java.lang.RuntimeException JavaDoc rex) {
66                         ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,rex);
67                     }
68                 }
69                 for(int i=0; i<parentNodes.length; i++){
70                     Node parentNode = (Node)parentNodes[i];
71                     RefreshCookie refreshAction =
72                             (RefreshCookie)parentNode.getCookie(RefreshCookie.class);
73                     if (refreshAction != null){
74                         refreshAction.refresh();
75                     }
76                 }
77             }
78         });
79     }
80     
81     
82     /**
83      *
84      *
85      */

86     protected boolean enable(Node[] nodes) {
87         return ((nodes != null) && (nodes.length >= 1)) ? true : false;
88     }
89     
90     
91     /**
92      *
93      *
94      */

95     protected boolean asynchronous() {
96         return false;
97     }
98     
99     
100     /**
101      *
102      *
103      */

104     public HelpCtx getHelpCtx() {
105         return HelpCtx.DEFAULT_HELP;
106     }
107     
108     
109     /**
110      *
111      */

112     public String JavaDoc getName() {
113         return NbBundle.getMessage(UndeployAction.class, "LBL_UndeployAction");
114     }
115     
116 }
117
Popular Tags