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: * ModifyEjbGroupDialog.java
043: *
044: * Created on June 10, 2004, 2:51 PM
045: */
046:
047: package org.netbeans.modules.visualweb.ejb.ui;
048:
049: import org.netbeans.modules.visualweb.ejb.datamodel.EjbDataModel;
050: import org.netbeans.modules.visualweb.ejb.datamodel.EjbGroup;
051: import java.awt.Dialog;
052: import java.awt.event.ActionListener;
053: import java.util.*;
054: import javax.swing.JButton;
055: import org.openide.DialogDescriptor;
056: import org.openide.DialogDisplayer;
057: import org.openide.NotifyDescriptor;
058: import org.openide.util.NbBundle;
059:
060: /**
061: * This class is to handle the modification of an existing EJB group
062: *
063: * @author cao
064: */
065: public class ModifyEjbGroupDialog implements ActionListener {
066: private DialogDescriptor dialogDescriptor;
067: private Dialog dialog;
068:
069: private ModifyEjbGroupPanel grpPanel;
070:
071: private JButton okButton;
072: private JButton cancelButton;
073:
074: private EjbGroup ejbGroup;
075: private EjbGroup origCopy;
076:
077: public ModifyEjbGroupDialog(EjbGroup group) {
078: origCopy = group;
079: ejbGroup = (EjbGroup) group.clone();
080:
081: grpPanel = new ModifyEjbGroupPanel(group);
082:
083: dialogDescriptor = new DialogDescriptor(grpPanel,
084: NbBundle.getMessage(AddEjbGroupDialog.class,
085: "MODIFY_EJB_GROUP"), true,
086: (ActionListener) this );
087:
088: okButton = new JButton(NbBundle.getMessage(
089: ModifyEjbGroupDialog.class, "OK"));
090: okButton.getAccessibleContext().setAccessibleDescription(
091: java.util.ResourceBundle.getBundle(
092: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
093: .getString("OK"));
094: cancelButton = new JButton(NbBundle.getMessage(
095: ModifyEjbGroupDialog.class, "CANCEL_BUTTON_LABEL"));
096: cancelButton.getAccessibleContext().setAccessibleDescription(
097: java.util.ResourceBundle.getBundle(
098: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
099: .getString("CANCEL_BUTTON_DESC"));
100: dialogDescriptor.setOptions(new Object[] { okButton,
101: cancelButton });
102: dialogDescriptor
103: .setClosingOptions(new Object[] { cancelButton });
104:
105: // TODO: no help for preview feature
106: //dialogDescriptor.setHelpCtx(new HelpCtx("projrave_ui_elements_server_nav_add_datasourcedb"));
107:
108: dialog = DialogDisplayer.getDefault().createDialog(
109: dialogDescriptor);
110: dialog.setResizable(true);
111: dialog.pack();
112: }
113:
114: public void showDialog() {
115: dialog.setVisible(true);
116: }
117:
118: public void enableAddButton(boolean enable) {
119: this .okButton.setEnabled(enable);
120: }
121:
122: public void actionPerformed(java.awt.event.ActionEvent e) {
123: if (e.getSource() == okButton) {
124: // Make sure the user has entered all the required data
125: StringBuffer errorMessage = new StringBuffer();
126: if (!grpPanel.validateData(errorMessage)) {
127: NotifyDescriptor d = new NotifyDescriptor.Message(
128: errorMessage.toString(),
129: NotifyDescriptor.ERROR_MESSAGE);
130: DialogDisplayer.getDefault().notify(d);
131: return;
132: }
133:
134: // Get all the user input from the inner panel
135: ejbGroup.setName(grpPanel.getGroupName());
136: ejbGroup.setServerHost(grpPanel.getServerHost());
137: ejbGroup.setIIOPPort(Integer.parseInt(grpPanel
138: .getIIOPPort()));
139:
140: // In case of the same client jar file is added in more than
141: // one ejb group, warn the user to modify the other groups too
142: if (checkClientJarInfo(ejbGroup)) {
143: // Take care the modification on the rest of the fields
144: EjbDataModel.getInstance().modifyEjbGroup(origCopy,
145: ejbGroup);
146:
147: dialog.dispose();
148: }
149: }
150: }
151:
152: private boolean checkClientJarInfo(EjbGroup grp) {
153: ArrayList grpNames = new ArrayList();
154:
155: for (Iterator iter = grp.getClientJarFileNames().iterator(); iter
156: .hasNext();) {
157: String jar = (String) iter.next();
158:
159: Collection grps = EjbDataModel.getInstance()
160: .findEjbGroupsForJar(jar);
161:
162: for (Iterator grpIter = grps.iterator(); grpIter.hasNext();) {
163: EjbGroup existingGrpWithJar = (EjbGroup) grpIter.next();
164:
165: if (existingGrpWithJar != null
166: && (!existingGrpWithJar.getServerHost().equals(
167: grp.getServerHost()) || existingGrpWithJar
168: .getIIOPPort() != grp.getIIOPPort())) {
169: if (!grpNames
170: .contains(existingGrpWithJar.getName())
171: && !existingGrpWithJar.getName().equals(
172: grp.getName())) //Not itself
173: grpNames.add(existingGrpWithJar.getName());
174: }
175: }
176: }
177:
178: if (grpNames.size() != 0) {
179: // The server host and/or RMI-IIOP port modification will cause EJB Set {0} to
180: // contain incorrect information. Would like to preceed?
181: StringBuffer nameStr = new StringBuffer();
182: boolean first = true;
183: for (Iterator iter = grpNames.iterator(); iter.hasNext();) {
184: if (first)
185: first = false;
186: else
187: nameStr.append(", ");
188:
189: nameStr.append((String) iter.next());
190:
191: }
192: String msg = NbBundle.getMessage(
193: ModifyEjbGroupDialog.class, "MISMATCH_INFO_JAR_Q",
194: nameStr.toString());
195: NotifyDescriptor confDialog = new NotifyDescriptor.Confirmation(
196: msg, NotifyDescriptor.OK_CANCEL_OPTION);
197: if (!(DialogDisplayer.getDefault().notify(confDialog) == NotifyDescriptor.OK_OPTION))
198: return false;
199: else
200: return true;
201: } else
202: return true;
203: }
204: }
|