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