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.apisupport.project.ui.wizard.options;
043:
044: import java.awt.Component;
045: import javax.swing.JTextField;
046: import javax.swing.event.DocumentEvent;
047: import javax.swing.event.DocumentListener;
048: import javax.swing.text.JTextComponent;
049: import org.netbeans.api.project.ProjectUtils;
050: import org.netbeans.modules.apisupport.project.ui.UIUtil;
051: import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
052: import org.netbeans.modules.apisupport.project.ui.wizard.options.NewOptionsIterator.DataModel;
053: import org.openide.WizardDescriptor;
054: import org.openide.util.HelpCtx;
055: import org.openide.util.NbBundle;
056:
057: /**
058: * @author Radek Matous
059: */
060: final class OptionsPanel extends BasicWizardIterator.Panel {
061:
062: private final DataModel data;
063: private DocumentListener updateListener;
064:
065: /** Creates new NameAndLocationPanel */
066: public OptionsPanel(final WizardDescriptor setting,
067: final DataModel data) {
068: super (setting);
069: this .data = data;
070: initComponents();
071: initAccessibility();
072: if (data.getPackageName() != null) {
073: packageName.setSelectedItem(data.getPackageName());
074: }
075: putClientProperty("NewFileWizard_Title",
076: getMessage("LBL_OptionsWizardTitle"));
077:
078: }
079:
080: private void addListeners() {
081: if (updateListener == null) {
082: updateListener = new UIUtil.DocumentAdapter() {
083: public void insertUpdate(DocumentEvent e) {
084: updateData();
085: }
086: };
087:
088: txtPrefix.getDocument().addDocumentListener(updateListener);
089: Component editorComp = packageName.getEditor()
090: .getEditorComponent();
091: if (editorComp instanceof JTextComponent) {
092: ((JTextComponent) editorComp).getDocument()
093: .addDocumentListener(updateListener);
094: }
095: }
096: }
097:
098: private void removeListeners() {
099: if (updateListener != null) {
100: txtPrefix.getDocument().removeDocumentListener(
101: updateListener);
102: Component editorComp = packageName.getEditor()
103: .getEditorComponent();
104: if (editorComp instanceof JTextComponent) {
105: ((JTextComponent) editorComp).getDocument()
106: .removeDocumentListener(updateListener);
107: }
108: updateListener = null;
109: }
110: }
111:
112: protected void storeToDataModel() {
113: removeListeners();
114: updateData();
115: }
116:
117: protected void readFromDataModel() {
118: addListeners();
119: txtPrefix.setText(data.getClassNamePrefix());
120: }
121:
122: public void removeNotify() {
123: super .removeNotify();
124: removeListeners();
125: }
126:
127: public void addNotify() {
128: super .addNotify();
129: addListeners();
130: updateData();
131: }
132:
133: private void updateData() {
134: int errCode = data.setPackageAndPrefix(packageName.getEditor()
135: .getItem().toString(), txtPrefix.getText());
136: data.getCreatedModifiedFiles();
137: createdFilesValue.setText(UIUtil.generateTextAreaContent(data
138: .getCreatedModifiedFiles().getCreatedPaths()));
139: modifiedFilesValue.setText(UIUtil.generateTextAreaContent(data
140: .getCreatedModifiedFiles().getModifiedPaths()));
141:
142: //#68294 check if the paths for newly created files are valid or not..
143: String[] invalid = data.getCreatedModifiedFiles()
144: .getInvalidPaths();
145: if (data.isErrorCode(errCode)) {
146: setError(data.getErrorMessage(errCode));//NOI18N
147: } else if (invalid.length > 0) {
148: setError(NbBundle.getMessage(OptionsPanel.class,
149: "ERR_ToBeCreateFileExists", invalid[0]));//NOI18N
150: } else if (data.isSuccessCode(errCode)) {
151: markValid();
152: }
153: }
154:
155: protected String getPanelName() {
156: return getMessage("LBL_OptionsPanel1_Title");
157: }
158:
159: protected HelpCtx getHelp() {
160: return new HelpCtx(OptionsPanel.class);
161: }
162:
163: private static String getMessage(String key) {
164: return NbBundle.getMessage(OptionsPanel.class, key);
165: }
166:
167: private void initAccessibility() {
168: this .getAccessibleContext().setAccessibleDescription(
169: getMessage("ACS_OptionsPanel"));
170: projectNameValue.getAccessibleContext()
171: .setAccessibleDescription(
172: getMessage("ACS_CTL_ProjectName"));
173: packageName.getAccessibleContext().setAccessibleDescription(
174: getMessage("ACS_CTL_PackageName"));
175: createdFilesValue.getAccessibleContext()
176: .setAccessibleDescription(
177: getMessage("ACS_CTL_CreatedFilesValue"));
178: modifiedFilesValue.getAccessibleContext()
179: .setAccessibleDescription(
180: getMessage("ACS_CTL_ModifiedFilesValue"));
181: txtPrefix.getAccessibleContext().setAccessibleDescription(
182: getMessage("ACS_CTL__ClassNamePrefix"));
183: }
184:
185: /** This method is called from within the constructor to
186: * initialize the form.
187: * WARNING: Do NOT modify this code. The content of this method is
188: * always regenerated by the Form Editor.
189: */
190: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
191: private void initComponents() {
192: java.awt.GridBagConstraints gridBagConstraints;
193:
194: projectName = new javax.swing.JLabel();
195: projectNameValue = new JTextField(ProjectUtils.getInformation(
196: this .data.getProject()).getDisplayName());
197: createdFiles = new javax.swing.JLabel();
198: modifiedFiles = new javax.swing.JLabel();
199: createdFilesValueS = new javax.swing.JScrollPane();
200: createdFilesValue = new javax.swing.JTextArea();
201: modifiedFilesValueS = new javax.swing.JScrollPane();
202: modifiedFilesValue = new javax.swing.JTextArea();
203: packageName = UIUtil.createPackageComboBox(data
204: .getSourceRootGroup());
205: packageNameTxt = new javax.swing.JLabel();
206: lblPrefix = new javax.swing.JLabel();
207: txtPrefix = new javax.swing.JTextField();
208:
209: setLayout(new java.awt.GridBagLayout());
210:
211: projectName.setLabelFor(projectNameValue);
212: org.openide.awt.Mnemonics
213: .setLocalizedText(
214: projectName,
215: java.util.ResourceBundle
216: .getBundle(
217: "org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle")
218: .getString("LBL_ProjectName"));
219: gridBagConstraints = new java.awt.GridBagConstraints();
220: gridBagConstraints.gridx = 0;
221: gridBagConstraints.gridy = 0;
222: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
223: gridBagConstraints.insets = new java.awt.Insets(1, 0, 6, 12);
224: add(projectName, gridBagConstraints);
225:
226: projectNameValue.setEditable(false);
227: gridBagConstraints = new java.awt.GridBagConstraints();
228: gridBagConstraints.gridx = 1;
229: gridBagConstraints.gridy = 0;
230: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
231: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
232: gridBagConstraints.weightx = 1.0;
233: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
234: add(projectNameValue, gridBagConstraints);
235:
236: createdFiles.setLabelFor(createdFilesValue);
237: org.openide.awt.Mnemonics
238: .setLocalizedText(
239: createdFiles,
240: java.util.ResourceBundle
241: .getBundle(
242: "org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle")
243: .getString("LBL_CreatedFiles"));
244: gridBagConstraints = new java.awt.GridBagConstraints();
245: gridBagConstraints.gridx = 0;
246: gridBagConstraints.gridy = 3;
247: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
248: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
249: gridBagConstraints.insets = new java.awt.Insets(18, 0, 6, 12);
250: add(createdFiles, gridBagConstraints);
251:
252: modifiedFiles.setLabelFor(modifiedFilesValue);
253: org.openide.awt.Mnemonics
254: .setLocalizedText(
255: modifiedFiles,
256: java.util.ResourceBundle
257: .getBundle(
258: "org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle")
259: .getString("LBL_ModifiedFiles"));
260: gridBagConstraints = new java.awt.GridBagConstraints();
261: gridBagConstraints.gridx = 0;
262: gridBagConstraints.gridy = 4;
263: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
264: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
265: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
266: add(modifiedFiles, gridBagConstraints);
267:
268: createdFilesValue.setBackground(javax.swing.UIManager
269: .getDefaults().getColor("Label.background"));
270: createdFilesValue.setColumns(20);
271: createdFilesValue.setEditable(false);
272: createdFilesValue.setRows(5);
273: createdFilesValue.setBorder(null);
274: createdFilesValueS.setViewportView(createdFilesValue);
275:
276: gridBagConstraints = new java.awt.GridBagConstraints();
277: gridBagConstraints.gridx = 1;
278: gridBagConstraints.gridy = 3;
279: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
280: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
281: gridBagConstraints.weightx = 1.0;
282: gridBagConstraints.weighty = 0.5;
283: gridBagConstraints.insets = new java.awt.Insets(18, 0, 6, 0);
284: add(createdFilesValueS, gridBagConstraints);
285:
286: modifiedFilesValue.setBackground(javax.swing.UIManager
287: .getDefaults().getColor("Label.background"));
288: modifiedFilesValue.setColumns(20);
289: modifiedFilesValue.setEditable(false);
290: modifiedFilesValue.setRows(5);
291: modifiedFilesValue.setToolTipText("modifiedFilesValue");
292: modifiedFilesValue.setBorder(null);
293: modifiedFilesValueS.setViewportView(modifiedFilesValue);
294:
295: gridBagConstraints = new java.awt.GridBagConstraints();
296: gridBagConstraints.gridx = 1;
297: gridBagConstraints.gridy = 4;
298: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
299: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
300: gridBagConstraints.weightx = 1.0;
301: gridBagConstraints.weighty = 0.5;
302: add(modifiedFilesValueS, gridBagConstraints);
303:
304: packageName.setEditable(true);
305: gridBagConstraints = new java.awt.GridBagConstraints();
306: gridBagConstraints.gridx = 1;
307: gridBagConstraints.gridy = 2;
308: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
309: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
310: gridBagConstraints.weightx = 1.0;
311: add(packageName, gridBagConstraints);
312:
313: packageNameTxt.setLabelFor(packageName);
314: org.openide.awt.Mnemonics.setLocalizedText(packageNameTxt,
315: org.openide.util.NbBundle.getMessage(
316: OptionsPanel.class, "LBL_PackageName"));
317: gridBagConstraints = new java.awt.GridBagConstraints();
318: gridBagConstraints.gridx = 0;
319: gridBagConstraints.gridy = 2;
320: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
321: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
322: add(packageNameTxt, gridBagConstraints);
323:
324: lblPrefix.setLabelFor(txtPrefix);
325: org.openide.awt.Mnemonics.setLocalizedText(lblPrefix,
326: org.openide.util.NbBundle.getMessage(
327: OptionsPanel.class, "LBL_Prefix"));
328: gridBagConstraints = new java.awt.GridBagConstraints();
329: gridBagConstraints.gridx = 0;
330: gridBagConstraints.gridy = 1;
331: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
332: gridBagConstraints.insets = new java.awt.Insets(12, 0, 6, 12);
333: add(lblPrefix, gridBagConstraints);
334:
335: gridBagConstraints = new java.awt.GridBagConstraints();
336: gridBagConstraints.gridx = 1;
337: gridBagConstraints.gridy = 1;
338: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
339: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
340: gridBagConstraints.weightx = 1.0;
341: gridBagConstraints.insets = new java.awt.Insets(12, 0, 6, 0);
342: add(txtPrefix, gridBagConstraints);
343:
344: }// </editor-fold>//GEN-END:initComponents
345:
346: // Variables declaration - do not modify//GEN-BEGIN:variables
347: private javax.swing.JLabel createdFiles;
348: private javax.swing.JTextArea createdFilesValue;
349: private javax.swing.JScrollPane createdFilesValueS;
350: private javax.swing.JLabel lblPrefix;
351: private javax.swing.JLabel modifiedFiles;
352: private javax.swing.JTextArea modifiedFilesValue;
353: private javax.swing.JScrollPane modifiedFilesValueS;
354: private javax.swing.JComboBox packageName;
355: private javax.swing.JLabel packageNameTxt;
356: private javax.swing.JLabel projectName;
357: private javax.swing.JTextField projectNameValue;
358: private javax.swing.JTextField txtPrefix;
359: // End of variables declaration//GEN-END:variables
360:
361: }
|