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 org.netbeans.modules.visualweb.ejb.datamodel.EjbInfo;
052: import org.netbeans.modules.visualweb.ejb.datamodel.MethodInfo;
053: import org.netbeans.modules.visualweb.ejb.datamodel.MethodParam;
054: import org.netbeans.modules.visualweb.ejb.load.EjbLoadException;
055: import org.netbeans.modules.visualweb.ejb.load.EjbLoader;
056: import java.awt.Dialog;
057: import java.awt.event.ActionListener;
058: import java.util.*;
059: import javax.swing.JButton;
060: import org.openide.DialogDescriptor;
061: import org.openide.DialogDisplayer;
062: import org.openide.NotifyDescriptor;
063: import org.openide.util.NbBundle;
064:
065: /**
066: * This class is to handle the modification of an existing EJB group
067: *
068: * @author cao
069: */
070: public class ConfigureMethodsDialog implements ActionListener {
071: private boolean cancelled = false;
072: private boolean refresh = false;
073:
074: private DialogDescriptor dialogDescriptor;
075: private Dialog dialog;
076:
077: private ConfigureMethodsPanel configurePanel;
078:
079: private JButton okButton;
080: private JButton cancelButton;
081:
082: private EjbGroup ejbGroup;
083: private EjbGroup origCopy;
084:
085: public ConfigureMethodsDialog(EjbGroup group, boolean refresh) {
086: this (group);
087: this .refresh = refresh;
088: }
089:
090: public ConfigureMethodsDialog(EjbGroup group) {
091: origCopy = group;
092: ejbGroup = (EjbGroup) group.clone();
093:
094: configurePanel = new ConfigureMethodsPanel(ejbGroup);
095:
096: dialogDescriptor = new DialogDescriptor(configurePanel,
097: NbBundle.getMessage(ConfigureMethodsDialog.class,
098: "CONFIGURE_METHODS"), true,
099: (ActionListener) this );
100:
101: okButton = new JButton(NbBundle.getMessage(
102: ConfigureMethodsDialog.class, "OK"));
103: okButton.getAccessibleContext().setAccessibleDescription(
104: java.util.ResourceBundle.getBundle(
105: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
106: .getString("OK"));
107: cancelButton = new JButton(NbBundle.getMessage(
108: ConfigureMethodsDialog.class, "CANCEL_BUTTON_LABEL"));
109: cancelButton.getAccessibleContext().setAccessibleDescription(
110: java.util.ResourceBundle.getBundle(
111: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
112: .getString("CANCEL_BUTTON_DESC"));
113: dialogDescriptor.setOptions(new Object[] { okButton,
114: cancelButton });
115: dialogDescriptor
116: .setClosingOptions(new Object[] { cancelButton });
117:
118: // TODO: no help for preview feature
119: //dialogDescriptor.setHelpCtx(new HelpCtx("projrave_ui_elements_server_nav_add_datasourcedb"));
120:
121: dialog = DialogDisplayer.getDefault().createDialog(
122: dialogDescriptor);
123: dialog.setResizable(true);
124: dialog.pack();
125: }
126:
127: public void showDialog() {
128: dialog.setVisible(true);
129: }
130:
131: public boolean isCancelled() {
132: return cancelled;
133: }
134:
135: public EjbGroup getEjbGroup() {
136: return this .ejbGroup;
137: }
138:
139: public void enableAddButton(boolean enable) {
140: this .okButton.setEnabled(enable);
141: }
142:
143: public void actionPerformed(java.awt.event.ActionEvent e) {
144:
145: if (e.getSource() == okButton) {
146:
147: // Programmatically stop the CellEditor so that we do not lose the very last editting value
148: configurePanel.getMethodDetailPanel().stopLastCellEditing();
149:
150: // Get the last class name input from the user in the method detail panel
151: configurePanel.getMethodDetailPanel()
152: .updateColElemClassName();
153:
154: // If anything has changed, the all the classes will be regenerated
155: if (refresh || isModified(origCopy, ejbGroup)) {
156:
157: // Regenerate the classes
158:
159: EjbLoader ejbLoader = new EjbLoader(ejbGroup);
160:
161: try {
162: ejbLoader.createWrapperClientBeans();
163:
164: // (IZ 199266) Propagate modification here so compilation
165: // errors do not corrupt the data model
166: doModification(origCopy, ejbGroup);
167:
168: EjbDataModel.getInstance().touchModifiedFlag();
169: } catch (EjbLoadException ex) {
170: // Popup error message here to ask the them give correct information
171:
172: String msg = ex.getMessage();
173: if (ex.getExceptionType() == EjbLoadException.SYSTEM_EXCEPTION)
174: msg = NbBundle.getMessage(
175: ConfigureMethodsDialog.class,
176: "FAILED_TO_MODIFY_METHODS_CONFIG",
177: ejbGroup.getName());
178:
179: NotifyDescriptor d = new NotifyDescriptor.Message(
180: msg, NotifyDescriptor.ERROR_MESSAGE);
181: DialogDisplayer.getDefault().notify(d);
182: return;
183: }
184: }
185:
186: dialog.dispose();
187: } else if (e.getSource() == cancelButton) {
188: cancelled = true;
189: }
190: }
191:
192: private boolean isModified(EjbGroup origGroup, EjbGroup modGroup) {
193: return findModifications(origGroup, modGroup, false);
194: }
195:
196: private void doModification(EjbGroup origGroup, EjbGroup modGroup) {
197: findModifications(origGroup, modGroup, true);
198: }
199:
200: private boolean findModifications(EjbGroup origGroup,
201: EjbGroup modGroup, boolean modifyOriginal) {
202: boolean foundModification = false;
203:
204: for (Iterator iter = origGroup.getSessionBeans().iterator(); iter
205: .hasNext();) {
206: EjbInfo origEjbInfo = (EjbInfo) iter.next();
207: EjbInfo modEjbInfo = modGroup.getEjbInfo(origEjbInfo
208: .getCompInterfaceName());
209:
210: // Compare mehtod by method
211: ArrayList origMethods = origEjbInfo.getMethods();
212: ArrayList modMethods = modEjbInfo.getMethods();
213: for (int i = 0; i < origMethods.size(); i++) {
214: MethodInfo origMethod = (MethodInfo) origMethods.get(i);
215:
216: if (origMethod.isMethodConfigurable()) {
217: // Anything changed
218: MethodInfo modMethod = (MethodInfo) modMethods
219: .get(i);
220:
221: if (origMethod.getReturnType().isCollection()) {
222: // Check whehter the collection element class type change
223: if (!origMethod.getReturnType()
224: .getElemClassName().equals(
225: modMethod.getReturnType()
226: .getElemClassName())) {
227: origMethod
228: .getReturnType()
229: .setElemClassName(
230: modMethod.getReturnType()
231: .getElemClassName());
232: foundModification = true;
233: }
234: }
235:
236: // Check parameter names
237: ArrayList origParamNames = origMethod
238: .getParameters();
239: if (origParamNames != null
240: && !origParamNames.isEmpty()) {
241: ArrayList modParamNames = modMethod
242: .getParameters();
243:
244: for (int pi = 0; pi < origParamNames.size(); pi++) {
245: MethodParam origParam = (MethodParam) origParamNames
246: .get(pi);
247: MethodParam modParam = (MethodParam) modParamNames
248: .get(pi);
249:
250: if (!origParam.getName().equals(
251: modParam.getName())) {
252: if (modifyOriginal) {
253: origParam.setName(modParam
254: .getName());
255: }
256:
257: foundModification = true;
258: }
259: }
260: }
261: }
262: }
263:
264: }
265:
266: return foundModification;
267: }
268: }
|