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