001: package org.netbeans.modules.j2ee.sun.ide.runtime.actions;
002:
003: /*
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
005: *
006: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common
010: * Development and Distribution License("CDDL") (collectively, the
011: * "License"). You may not use this file except in compliance with the
012: * License. You can obtain a copy of the License at
013: * http://www.netbeans.org/cddl-gplv2.html
014: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
015: * specific language governing permissions and limitations under the
016: * License. When distributing the software, include this License Header
017: * Notice in each file and include the License file at
018: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
019: * particular file as subject to the "Classpath" exception as provided
020: * by Sun in the GPL Version 2 section of the License file that
021: * accompanied this code. If applicable, add the following below the
022: * License Header, with the fields enclosed by brackets [] replaced by
023: * your own identifying information:
024: * "Portions Copyrighted [year] [name of copyright owner]"
025: *
026: * Contributor(s):
027: *
028: * The Original Software is NetBeans. The Initial Developer of the Original
029: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
030: * Microsystems, Inc. All Rights Reserved.
031: *
032: * If you wish your version of this file to be governed by only the CDDL
033: * or only the GPL Version 2, indicate your decision by adding
034: * "[Contributor] elects to include this software in this distribution
035: * under the [CDDL or GPL Version 2] license." If you do not indicate a
036: * single choice of license, a recipient has the option to distribute
037: * your version of this file under either the CDDL, the GPL Version 2 or
038: * to extend the choice of license to its licensees as provided above.
039: * However, if you add GPL Version 2 code and therefore, elected the GPL
040: * Version 2 license, then the option applies only if the new code is
041: * made subject to such option by the copyright holder.
042: */
043: import java.util.Vector;
044: import org.openide.ErrorManager;
045: import org.openide.nodes.Node;
046: import org.openide.util.Lookup;
047: import org.openide.util.actions.NodeAction;
048: import org.openide.util.NbBundle;
049: import org.openide.util.HelpCtx;
050: import org.openide.util.RequestProcessor;
051: import org.netbeans.modules.j2ee.sun.bridge.apis.Undeployable;
052:
053: import org.netbeans.modules.j2ee.sun.bridge.apis.RefreshCookie;
054:
055: /**
056: *
057: *
058: */
059: public class UndeployAction extends NodeAction {
060:
061: /**
062: *
063: *
064: */
065: protected void performAction(final Node[] activatedNodes) {
066: if (activatedNodes == null) {
067: return;
068: }
069: Vector parents = new java.util.Vector();
070: for (int i = 0; i < activatedNodes.length; i++) {
071: Node parentNode = activatedNodes[i].getParentNode();
072: parents.add(parentNode);
073: }
074: final Object[] parentNodes = parents.toArray();
075:
076: RequestProcessor.getDefault().post(new Runnable() {
077: public void run() {
078: for (int i = 0; i < activatedNodes.length; i++) {
079: Node node = activatedNodes[i];
080: Lookup lookup = node.getLookup();
081: Object obj = lookup.lookup(Undeployable.class);
082:
083: try {
084: if (obj instanceof Undeployable) {
085: Undeployable undeployableObj = (Undeployable) obj;
086: undeployableObj.undeploy();
087: }
088: } catch (java.lang.RuntimeException rex) {
089: ErrorManager.getDefault().notify(
090: ErrorManager.INFORMATIONAL, rex);
091: }
092: }
093: for (int i = 0; i < parentNodes.length; i++) {
094: Node parentNode = (Node) parentNodes[i];
095: RefreshCookie refreshAction = (RefreshCookie) parentNode
096: .getCookie(RefreshCookie.class);
097: if (refreshAction != null) {
098: refreshAction.refresh();
099: }
100: }
101: }
102: });
103: }
104:
105: /**
106: *
107: *
108: */
109: protected boolean enable(Node[] nodes) {
110: return ((nodes != null) && (nodes.length >= 1)) ? true : false;
111: }
112:
113: /**
114: *
115: *
116: */
117: protected boolean asynchronous() {
118: return false;
119: }
120:
121: /**
122: *
123: *
124: */
125: public HelpCtx getHelpCtx() {
126: return HelpCtx.DEFAULT_HELP;
127: }
128:
129: /**
130: *
131: */
132: public String getName() {
133: return NbBundle.getMessage(UndeployAction.class,
134: "LBL_UndeployAction");
135: }
136:
137: }
|