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-2006 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: package org.netbeans.modules.websvc.core.jaxws.nodes;
043:
044: import java.awt.event.ItemEvent;
045: import java.awt.event.ItemListener;
046: import org.openide.DialogDisplayer;
047: import org.openide.NotifyDescriptor;
048: import org.openide.util.NbBundle;
049:
050: /**
051: *
052: * @author Martin Adamek
053: */
054: public class RefreshWsDialog extends javax.swing.JPanel {
055:
056: static final String CLOSE = "0";
057: static final String DO_NOTHING = "1";
058: static final String DOWNLOAD_WSDL = "2";
059: static final String REGENERATE_IMPL_CLASS = "3";
060: static final String DO_ALL = "4";
061:
062: private String implClass, url;
063: private boolean downloadWsdl;
064:
065: private RefreshWsDialog(boolean downloadWsdl, String implClass,
066: String url) {
067: this .downloadWsdl = downloadWsdl;
068: this .implClass = implClass;
069: this .url = url;
070: initComponents();
071: // display the delete_wsdl checkbox only if wsdl exists
072: if (!downloadWsdl) {
073: downloadWsdlCheckBox.setVisible(false);
074: jLabel1.setVisible(false);
075: jTextField1.setVisible(false);
076: } else {
077: jTextField1.setText(url);
078: downloadWsdlCheckBox.addItemListener(new ItemListener() {
079:
080: public void itemStateChanged(ItemEvent e) {
081: if (((javax.swing.JCheckBox) e.getSource())
082: .isSelected())
083: jTextField1.setEditable(true);
084: else
085: jTextField1.setEditable(false);
086: }
087:
088: });
089: }
090: }
091:
092: public static String open(boolean downloadWsdl, String implClass,
093: String url) {
094: String title = NbBundle.getMessage(RefreshWsDialog.class,
095: "MSG_ConfirmServiceRefresh");
096: RefreshWsDialog refreshDialog = new RefreshWsDialog(
097: downloadWsdl, implClass, url);
098: NotifyDescriptor desc = new NotifyDescriptor.Confirmation(
099: refreshDialog, title, NotifyDescriptor.YES_NO_OPTION);
100: Object result = DialogDisplayer.getDefault().notify(desc);
101: if (result.equals(NotifyDescriptor.CLOSED_OPTION)) {
102: return CLOSE;
103: } else if (result.equals(NotifyDescriptor.NO_OPTION)) {
104: return CLOSE;
105: } else if (refreshDialog.downloadWsdl()
106: && refreshDialog.regenerate()) {
107: return DO_ALL + refreshDialog.getWsdlUrl();
108: } else if (refreshDialog.downloadWsdl()) {
109: return DOWNLOAD_WSDL + refreshDialog.getWsdlUrl();
110: } else if (refreshDialog.regenerate()) {
111: return REGENERATE_IMPL_CLASS;
112: } else
113: return DO_NOTHING;
114:
115: }
116:
117: /**
118: * This prompts the user if he/she wants to regenerate the impl bean
119: * but does not give a choice as to refreshing the nodes (i.e. the nodes are
120: * always refreshed.
121: */
122: public static String openWithOKButtonOnly(boolean downloadWsdl,
123: String implClass, String url) {
124: RefreshWsDialog delDialog = new RefreshWsDialog(downloadWsdl,
125: implClass, url);
126: NotifyDescriptor desc = new NotifyDescriptor.Message(delDialog,
127: NotifyDescriptor.INFORMATION_MESSAGE);
128: DialogDisplayer.getDefault().notify(desc);
129: if (delDialog.regenerate()) {
130: return REGENERATE_IMPL_CLASS;
131: }
132: return DO_NOTHING;
133: }
134:
135: private boolean downloadWsdl() {
136: if (!downloadWsdl)
137: return false;
138: return downloadWsdlCheckBox.isSelected();
139: }
140:
141: private boolean regenerate() {
142: return regenerateCheckBox.isSelected();
143: }
144:
145: /** This method is called from within the constructor to
146: * initialize the form.
147: * WARNING: Do NOT modify this code. The content of this method is
148: * always regenerated by the Form Editor.
149: */
150: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
151: private void initComponents() {
152: java.awt.GridBagConstraints gridBagConstraints;
153:
154: downloadWsdlCheckBox = new javax.swing.JCheckBox();
155: regenerateCheckBox = new javax.swing.JCheckBox();
156: jLabel1 = new javax.swing.JLabel();
157: jLabel2 = new javax.swing.JLabel();
158: jLabel3 = new javax.swing.JLabel();
159: jTextField1 = new javax.swing.JTextField();
160:
161: setLayout(new java.awt.GridBagLayout());
162:
163: org.openide.awt.Mnemonics.setLocalizedText(
164: downloadWsdlCheckBox, org.openide.util.NbBundle
165: .getMessage(RefreshWsDialog.class,
166: "MSG_DownloadWsdl",
167: new Object[] { url })); // NOI18N
168: gridBagConstraints = new java.awt.GridBagConstraints();
169: gridBagConstraints.gridx = 0;
170: gridBagConstraints.gridy = 1;
171: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
172: gridBagConstraints.weightx = 1.0;
173: add(downloadWsdlCheckBox, gridBagConstraints);
174:
175: regenerateCheckBox.setSelected(true);
176: org.openide.awt.Mnemonics.setLocalizedText(regenerateCheckBox,
177: org.openide.util.NbBundle.getMessage(
178: RefreshWsDialog.class,
179: "MSG_RegenerateImplClass")); // NOI18N
180: gridBagConstraints = new java.awt.GridBagConstraints();
181: gridBagConstraints.gridx = 0;
182: gridBagConstraints.gridy = 4;
183: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
184: gridBagConstraints.weightx = 1.0;
185: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
186: add(regenerateCheckBox, gridBagConstraints);
187:
188: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
189: org.openide.util.NbBundle.getMessage(
190: RefreshWsDialog.class, "HINT_DownloadWsdl")); // NOI18N
191: gridBagConstraints = new java.awt.GridBagConstraints();
192: gridBagConstraints.gridx = 0;
193: gridBagConstraints.gridy = 3;
194: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
195: gridBagConstraints.insets = new java.awt.Insets(0, 22, 0, 0);
196: add(jLabel1, gridBagConstraints);
197:
198: org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
199: org.openide.util.NbBundle.getMessage(
200: RefreshWsDialog.class,
201: "HINT_RegenerateImplClass",
202: new Object[] { implClass + ".java.old" })); // NOI18N
203: gridBagConstraints = new java.awt.GridBagConstraints();
204: gridBagConstraints.gridx = 0;
205: gridBagConstraints.gridy = 5;
206: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
207: gridBagConstraints.insets = new java.awt.Insets(0, 22, 0, 0);
208: add(jLabel2, gridBagConstraints);
209:
210: org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
211: org.openide.util.NbBundle.getMessage(
212: RefreshWsDialog.class, "HINT_RefreshService")); // NOI18N
213: gridBagConstraints = new java.awt.GridBagConstraints();
214: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
215: gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
216: add(jLabel3, gridBagConstraints);
217:
218: jTextField1.setEditable(false);
219: gridBagConstraints = new java.awt.GridBagConstraints();
220: gridBagConstraints.gridx = 0;
221: gridBagConstraints.gridy = 2;
222: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
223: gridBagConstraints.insets = new java.awt.Insets(0, 22, 0, 22);
224: add(jTextField1, gridBagConstraints);
225: }// </editor-fold>//GEN-END:initComponents
226:
227: // Variables declaration - do not modify//GEN-BEGIN:variables
228: private javax.swing.JCheckBox downloadWsdlCheckBox;
229: private javax.swing.JLabel jLabel1;
230: private javax.swing.JLabel jLabel2;
231: private javax.swing.JLabel jLabel3;
232: private javax.swing.JTextField jTextField1;
233: private javax.swing.JCheckBox regenerateCheckBox;
234:
235: // End of variables declaration//GEN-END:variables
236:
237: private String getWsdlUrl() {
238: return jTextField1.getText().trim();
239: }
240: }
|