001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /*
042: * DeleteEjbGroupAction.java
043: *
044: * Created on May 7, 2004, 12:23 AM
045: */
046:
047: package org.netbeans.modules.visualweb.ejb.actions;
048:
049: import org.netbeans.modules.visualweb.ejb.datamodel.EjbDataModel;
050: import org.netbeans.modules.visualweb.ejb.nodes.EjbGroupNode;
051: import java.util.*;
052: import org.openide.DialogDisplayer;
053: import org.openide.NotifyDescriptor;
054: import org.openide.nodes.FilterNode;
055: import org.openide.nodes.Node;
056: import org.openide.util.HelpCtx;
057: import org.openide.util.NbBundle;
058: import org.openide.util.actions.NodeAction;
059:
060: /**
061: * The action invoked when the user clicks on the "Delete"
062: * menu item on an EJB group node
063: *
064: * @author cao
065: */
066: public class DeleteEjbGroupAction extends NodeAction {
067: public DeleteEjbGroupAction() {
068: }
069:
070: protected boolean enable(org.openide.nodes.Node[] activatedNodes) {
071: return true;
072: }
073:
074: public org.openide.util.HelpCtx getHelpCtx() {
075: return HelpCtx.DEFAULT_HELP;
076: }
077:
078: public String getName() {
079: return NbBundle
080: .getMessage(DeleteEjbGroupAction.class, "DELETE");
081: }
082:
083: protected void performAction(org.openide.nodes.Node[] activatedNodes) {
084: // If the user only selected one EJB group to delete, the message will be like
085: // Are you sure you want to delete <EJB group name>?
086: // If the user selected multiple EJB groups to delete, the message will be like
087: // Are you sure you want to delete these <number> items?
088: // This makes the dialog consitent with the one popped up from netbeans when the user hit delete key
089:
090: String grpNameMsg = null;
091: String msg = null;
092: if (activatedNodes.length == 1) {
093: grpNameMsg = activatedNodes[0].getDisplayName();
094: msg = NbBundle.getMessage(DeleteEjbGroupAction.class,
095: "DELETE_CONFIRMATION", grpNameMsg);
096: } else
097: msg = NbBundle.getMessage(DeleteEjbGroupAction.class,
098: "DELTE_MULTIPLE_EJB_SETS", Integer
099: .toString(activatedNodes.length));
100:
101: // Confirm Object Deletion for deleting one EJB group and
102: // Confirm Mulitple Object Deletion for deleting mulitple EJB groups
103:
104: String title = null;
105: if (activatedNodes.length == 1)
106: title = NbBundle.getMessage(DeleteEjbGroupAction.class,
107: "DELETE_DIALOG_TITLE");
108: else
109: title = NbBundle.getMessage(DeleteEjbGroupAction.class,
110: "DELETE_DIALOG_TITLE_MUL");
111:
112: NotifyDescriptor d = new NotifyDescriptor.Confirmation(msg,
113: title, NotifyDescriptor.YES_NO_OPTION);
114: Object response = DialogDisplayer.getDefault().notify(d);
115:
116: if (response != null
117: && response.equals(NotifyDescriptor.YES_OPTION)) {
118: Collection removeGroups = new ArrayList();
119: for (int i = 0; i < activatedNodes.length; i++) {
120: Node node = null;
121: if (activatedNodes[i] instanceof FilterNode) {
122: node = (Node) activatedNodes[i]
123: .getCookie(EjbGroupNode.class);
124: } else {
125: node = activatedNodes[i];
126: }
127: removeGroups.add(((EjbGroupNode) node).getEjbGroup());
128: }
129:
130: EjbDataModel.getInstance().removeEjbGroups(removeGroups);
131: }
132: }
133:
134: /** @return <code>false</code> to be performed in event dispatch thread */
135: protected boolean asynchronous() {
136: return false;
137: }
138:
139: }
|