001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: * PanelOptionsVisual1.java
022: *
023: * Created on January 26, 2006, 5:24 PM
024: */
025:
026: package org.netbeans.modules.bpel.core.wizard;
027:
028: import java.text.MessageFormat;
029: import javax.swing.JTextField;
030:
031: import org.openide.WizardDescriptor;
032: import org.openide.awt.Mnemonics;
033: import org.openide.util.NbBundle;
034: import org.netbeans.api.project.Project;
035: import org.netbeans.api.project.ProjectInformation;
036: import org.netbeans.api.project.ProjectUtils;
037:
038: /**
039: *
040: * @author Praveen
041: */
042: public class BpelOptionsPanel extends javax.swing.JPanel {
043:
044: private static final long serialVersionUID = 1L;
045:
046: private static final String DEFAULT_SERVICE_NAME = NbBundle
047: .getMessage(BpelOptionsPanel.class,
048: "TXT_defaultServiceName"); //NOI18N
049: private static final String DEFAULT_PROJECT_NAME = NbBundle
050: .getMessage(BpelOptionsPanel.class,
051: "TXT_defaultProjectName"); //NOI18N
052: private static final String TARGET_URL_PREFIX = NbBundle
053: .getMessage(BpelOptionsPanel.class, "TXT_defaultTNS"); //NOI18N
054:
055: /** Creates new form PanelOptionsVisual1 */
056: public BpelOptionsPanel(NewBpelFilePanel newBpelFilePanel) {
057: initComponents();
058:
059: this .newBpelFilePanel = newBpelFilePanel;
060: NameSpaceListener namespaceListener = new NameSpaceListener();
061: namespaceTextField.getDocument().addDocumentListener(
062: namespaceListener);
063: }
064:
065: /** This method is called from within the constructor to
066: * initialize the form.
067: * WARNING: Do NOT modify this code. The content of this method is
068: * always regenerated by the Form Editor.
069: */
070: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
071: private void initComponents() {
072:
073: buttonGroup1 = new javax.swing.ButtonGroup();
074: jLabel1 = new javax.swing.JLabel();
075: Mnemonics.setLocalizedText(jLabel1, NbBundle.getMessage(
076: BpelOptionsPanel.class, "LBL_Namespace"));
077: namespaceTextField = new javax.swing.JTextField();
078:
079: jLabel1.setLabelFor(namespaceTextField);
080:
081: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
082: this );
083: this .setLayout(layout);
084: layout
085: .setHorizontalGroup(layout
086: .createParallelGroup(
087: org.jdesktop.layout.GroupLayout.LEADING)
088: .add(
089: org.jdesktop.layout.GroupLayout.TRAILING,
090: layout
091: .createSequentialGroup()
092: .add(
093: jLabel1,
094: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
095: 144, Short.MAX_VALUE)
096: .addPreferredGap(
097: org.jdesktop.layout.LayoutStyle.RELATED)
098: .add(
099: namespaceTextField,
100: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
101: 460,
102: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)));
103: layout
104: .setVerticalGroup(layout
105: .createParallelGroup(
106: org.jdesktop.layout.GroupLayout.LEADING)
107: .add(
108: layout
109: .createSequentialGroup()
110: .add(4, 4, 4)
111: .add(
112: layout
113: .createParallelGroup(
114: org.jdesktop.layout.GroupLayout.BASELINE)
115: .add(
116: namespaceTextField,
117: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
118: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
119: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
120: .add(
121: jLabel1,
122: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
123: 22,
124: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
125: .add(198, 198, 198)));
126:
127: java.util.ResourceBundle bundle = java.util.ResourceBundle
128: .getBundle("org/netbeans/modules/bpel/core/wizard/Bundle"); // NOI18N
129: jLabel1.getAccessibleContext().setAccessibleName(
130: bundle.getString("ACS_NamespaceLabel")); // NOI18N
131: namespaceTextField.getAccessibleContext().setAccessibleName(
132: bundle.getString("ACS_NamespaceTextField")); // NOI18N
133: namespaceTextField
134: .getAccessibleContext()
135: .setAccessibleDescription(
136: bundle
137: .getString("ACS_NamespaceTextFieldDescription")); // NOI18N
138: }// </editor-fold>//GEN-END:initComponents
139:
140: boolean valid(WizardDescriptor wizardDescriptor) {
141: return true;
142: }
143:
144: void store(WizardDescriptor d) {
145: // Set value for namespace
146: d.putProperty(WizardProperties.NAMESPACE, namespaceTextField
147: .getText());
148: }
149:
150: void read(WizardDescriptor d) {
151: }
152:
153: protected void setNamespaceTextField(String namespace) {
154: namespaceTextField.setText(namespace);
155: }
156:
157: protected String getNamespaceTextField() {
158: return namespaceTextField.getText();
159: }
160:
161: String getWsName() {
162: if (fileNameTF != null)
163: return fileNameTF.getText();
164: else
165: return DEFAULT_SERVICE_NAME;
166: }
167:
168: void attachFileNameListener(JTextField fileNameTF) {
169:
170: this .fileNameTF = fileNameTF;
171: if (fileNameTF != null) {
172: DocListener listener = new DocListener();
173: javax.swing.text.Document doc = fileNameTF.getDocument();
174: doc.addDocumentListener(listener);
175: }
176:
177: String newNamespace = generateNamespace();
178: namespaceTextField.setText(newNamespace);
179:
180: // initialise.
181: prevNamespace = newNamespace;
182:
183: }
184:
185: /**
186: * Generates a namespace by the template.
187: * Names of the project and the process are used here.
188: */
189: private String generateNamespace() {
190: String projectName = null;
191: Project proj = newBpelFilePanel.getProject();
192: if (proj != null) {
193: ProjectInformation projInfo = ProjectUtils
194: .getInformation(proj);
195: if (projInfo != null) {
196: projectName = projInfo.getName();
197: }
198: }
199: if (projectName == null || projectName.length() == 0) {
200: projectName = DEFAULT_PROJECT_NAME;
201: }
202: //
203: String serviceName = null;
204: if (fileNameTF != null) {
205: serviceName = fileNameTF.getText();
206: }
207: if (serviceName == null || serviceName.length() == 0) {
208: serviceName = DEFAULT_SERVICE_NAME;
209: }
210: //
211: String result = MessageFormat.format(TARGET_URL_PREFIX,
212: projectName, serviceName);
213: return result;
214:
215: }
216:
217: // Variables declaration - do not modify//GEN-BEGIN:variables
218: private javax.swing.ButtonGroup buttonGroup1;
219: private javax.swing.JLabel jLabel1;
220: private javax.swing.JTextField namespaceTextField;
221: // End of variables declaration//GEN-END:variables
222:
223: NewBpelFilePanel newBpelFilePanel;
224: private JTextField fileNameTF;
225: private String prevNamespace;
226: private boolean nameSpaceModifiedFlag = false;
227:
228: private void doUpdate() {
229: if (namespaceTextField.getText() != null
230: && prevNamespace != null)
231: if (!namespaceTextField.getText().equals(prevNamespace))
232: nameSpaceModifiedFlag = true;
233:
234: if (!nameSpaceModifiedFlag) {
235: String newNamespace = generateNamespace();
236: namespaceTextField.setText(newNamespace);
237: prevNamespace = newNamespace;
238: }
239: }
240:
241: private class DocListener implements
242: javax.swing.event.DocumentListener {
243: public void changedUpdate(javax.swing.event.DocumentEvent e) {
244: doUpdate();
245: }
246:
247: public void insertUpdate(javax.swing.event.DocumentEvent e) {
248: doUpdate();
249: }
250:
251: public void removeUpdate(javax.swing.event.DocumentEvent e) {
252: doUpdate();
253: }
254: };
255:
256: private class NameSpaceListener implements
257: javax.swing.event.DocumentListener {
258: public void changedUpdate(javax.swing.event.DocumentEvent e) {
259: checkValidNamespace();
260: newBpelFilePanel.fireChange();
261: }
262:
263: public void insertUpdate(javax.swing.event.DocumentEvent e) {
264: checkValidNamespace();
265: newBpelFilePanel.fireChange();
266: }
267:
268: public void removeUpdate(javax.swing.event.DocumentEvent e) {
269: checkValidNamespace();
270: newBpelFilePanel.fireChange();
271: }
272: };
273:
274: private void checkValidNamespace() {
275: if (newBpelFilePanel.getTemplateWizard() == null)
276: return;
277:
278: if (namespaceTextField.getText().contains(" ")) {
279: newBpelFilePanel.getTemplateWizard().putProperty(
280: "WizardPanel_errorMessage", // NOI18N
281: NbBundle.getMessage(BpelOptionsPanel.class,
282: "MSG_Namespace_Contains_Space")); // NOI18N
283: } else {
284: newBpelFilePanel.getTemplateWizard().putProperty(
285: "WizardPanel_errorMessage", null); //NOI18N
286: }
287: }
288:
289: }
|