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.updatecenter;
043:
044: import java.net.MalformedURLException;
045: import java.net.URL;
046: import javax.swing.JTextField;
047: import javax.swing.event.DocumentEvent;
048: import javax.swing.event.DocumentListener;
049: import org.netbeans.api.project.ProjectUtils;
050: import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
051: import org.netbeans.modules.apisupport.project.ui.UIUtil;
052: import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
053: import org.openide.WizardDescriptor;
054: import org.openide.util.HelpCtx;
055: import org.openide.util.NbBundle;
056:
057: /**
058: * The panel in the <em>New Update Center Wizard</em>.
059: *
060: * @author Jiri Rechtacek
061: */
062: final class UpdateCenterRegistrationPanel extends
063: BasicWizardIterator.Panel {
064:
065: private DataModel data;
066: private DocumentListener updateListener;
067:
068: /**
069: * Creates new UpdateCenterRegistrationPanel
070: */
071: public UpdateCenterRegistrationPanel(
072: final WizardDescriptor setting, final DataModel data) {
073: super (setting);
074: this .data = data;
075: initComponents();
076:
077: putClientProperty("NewFileWizard_Title",
078: getMessage("LBL_NewUpdateCenterWizardTitle")); //NOI18N
079:
080: updateListener = new UIUtil.DocumentAdapter() {
081: public void insertUpdate(DocumentEvent e) {
082: updateData();
083: }
084: };
085: }
086:
087: private void addListeners() {
088: ucUrl.getDocument().addDocumentListener(updateListener);
089: displayName.getDocument().addDocumentListener(updateListener);
090: }
091:
092: private void removeListeners() {
093: ucUrl.getDocument().removeDocumentListener(updateListener);
094: displayName.getDocument()
095: .removeDocumentListener(updateListener);
096: }
097:
098: protected String getPanelName() {
099: return getMessage("LBL_UpdateCenterRegistrationPanel_Title"); //NOI18N
100: }
101:
102: protected void storeToDataModel() {
103: removeListeners();
104: storeBaseData();
105: }
106:
107: protected void readFromDataModel() {
108: updateData();
109: addListeners();
110: }
111:
112: void updateData() {
113: storeBaseData();
114: if (checkValidity()) {
115: CreatedModifiedFiles files = data
116: .refreshCreatedModifiedFiles();
117: createdFiles.setText(UIUtil.generateTextAreaContent(files
118: .getCreatedPaths()));
119: modifiedFiles.setText(UIUtil.generateTextAreaContent(files
120: .getModifiedPaths()));
121: }
122: }
123:
124: /** Data needed to compute CMF */
125: private void storeBaseData() {
126: data.setUpdateCenterURL(ucUrl.getText().trim());
127: data.setUpdateCenterDisplayName(displayName.getText().trim());
128: }
129:
130: private boolean checkValidity() {
131: boolean result = false;
132: if (data.getUpdateCenterURL().length() == 0) {
133: setError(getMessage("ERR_Url_Is_Empty")); //NOI18N
134: } else if (data.getUpdateCenterDisplayName().length() == 0) {
135: setError(getMessage("ERR_Empty_Display_Name")); //NOI18N
136: } else {
137: result = true;
138: if (!data.getUpdateCenterURL().endsWith(".xml")) {
139: setWarning(getMessage("WRN_Url_dont_xml_file")); // NOI18N
140: } else {
141:
142: try {
143: // try transform to URL
144: new URL(data.getUpdateCenterURL());
145:
146: // all is ok
147: markValid();
148: } catch (MalformedURLException ex) {
149: setWarning(NbBundle.getMessage(
150: UpdateCenterRegistrationPanel.class,
151: "WRN_Url_cannot_be_created", ex
152: .getLocalizedMessage()));
153: }
154:
155: }
156: }
157:
158: return result;
159: }
160:
161: protected HelpCtx getHelp() {
162: return new HelpCtx(UpdateCenterRegistrationPanel.class);
163: }
164:
165: private static String getMessage(String key) {
166: return NbBundle.getMessage(UpdateCenterRegistrationPanel.class,
167: key);
168: }
169:
170: /** This method is called from within the constructor to
171: * initialize the form.
172: * WARNING: Do NOT modify this code. The content of this method is
173: * always regenerated by the Form Editor.
174: */
175: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
176: private void initComponents() {
177: java.awt.GridBagConstraints gridBagConstraints;
178:
179: ucUrlLabel = new javax.swing.JLabel();
180: ucUrl = new javax.swing.JTextField();
181: displayNameLabel = new javax.swing.JLabel();
182: displayName = new javax.swing.JTextField();
183: projectLabel = new javax.swing.JLabel();
184: project = new JTextField(ProjectUtils.getInformation(
185: data.getProject()).getDisplayName());
186: createdFilesLabel = new javax.swing.JLabel();
187: createdFiles = new javax.swing.JTextArea();
188: modifiedFilesLabel = new javax.swing.JLabel();
189: modifiedFiles = new javax.swing.JTextArea();
190:
191: setLayout(new java.awt.GridBagLayout());
192:
193: getAccessibleContext().setAccessibleName(
194: org.openide.util.NbBundle.getMessage(
195: UpdateCenterRegistrationPanel.class,
196: "ACN_UpdateCenterRegistrationPanel",
197: new Object[] {}));
198: getAccessibleContext().setAccessibleDescription(
199: org.openide.util.NbBundle.getMessage(
200: UpdateCenterRegistrationPanel.class,
201: "ACD_UpdateCenterRegistrationPanel",
202: new Object[] {}));
203: ucUrlLabel.setLabelFor(ucUrl);
204: org.openide.awt.Mnemonics.setLocalizedText(ucUrlLabel,
205: org.openide.util.NbBundle.getMessage(
206: UpdateCenterRegistrationPanel.class,
207: "LBL_UpdateCenterURL"));
208: gridBagConstraints = new java.awt.GridBagConstraints();
209: gridBagConstraints.gridx = 0;
210: gridBagConstraints.gridy = 0;
211: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
212: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 12);
213: add(ucUrlLabel, gridBagConstraints);
214: ucUrlLabel.getAccessibleContext().setAccessibleDescription(
215: org.openide.util.NbBundle.getMessage(
216: UpdateCenterRegistrationPanel.class,
217: "ACD_UpdateCenterRegistrationPanel_ucUrlLabel",
218: new Object[] {}));
219:
220: ucUrl.setText(org.openide.util.NbBundle.getMessage(
221: UpdateCenterRegistrationPanel.class, "CTL_SampleURL"));
222: gridBagConstraints = new java.awt.GridBagConstraints();
223: gridBagConstraints.gridx = 1;
224: gridBagConstraints.gridy = 0;
225: gridBagConstraints.gridwidth = 2;
226: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
227: gridBagConstraints.weightx = 1.0;
228: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
229: add(ucUrl, gridBagConstraints);
230:
231: displayNameLabel.setLabelFor(displayName);
232: org.openide.awt.Mnemonics.setLocalizedText(displayNameLabel,
233: org.openide.util.NbBundle.getMessage(
234: UpdateCenterRegistrationPanel.class,
235: "LBL_DisplayName"));
236: gridBagConstraints = new java.awt.GridBagConstraints();
237: gridBagConstraints.gridx = 0;
238: gridBagConstraints.gridy = 1;
239: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
240: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 12);
241: add(displayNameLabel, gridBagConstraints);
242: displayNameLabel
243: .getAccessibleContext()
244: .setAccessibleDescription(
245: org.openide.util.NbBundle
246: .getMessage(
247: UpdateCenterRegistrationPanel.class,
248: "ACD_UpdateCenterRegistrationPanel_displayNameLabel",
249: new Object[] {}));
250:
251: displayName.setText(org.openide.util.NbBundle.getMessage(
252: UpdateCenterRegistrationPanel.class, "CTL_SampleName",
253: new Object[] { project.getText() }));
254: gridBagConstraints = new java.awt.GridBagConstraints();
255: gridBagConstraints.gridx = 1;
256: gridBagConstraints.gridy = 1;
257: gridBagConstraints.gridwidth = 2;
258: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
259: gridBagConstraints.weightx = 1.0;
260: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
261: add(displayName, gridBagConstraints);
262:
263: projectLabel.setLabelFor(project);
264: org.openide.awt.Mnemonics.setLocalizedText(projectLabel,
265: org.openide.util.NbBundle.getMessage(
266: UpdateCenterRegistrationPanel.class,
267: "LBL_ProjectName"));
268: gridBagConstraints = new java.awt.GridBagConstraints();
269: gridBagConstraints.gridx = 0;
270: gridBagConstraints.gridy = 3;
271: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
272: gridBagConstraints.insets = new java.awt.Insets(18, 0, 6, 12);
273: add(projectLabel, gridBagConstraints);
274: projectLabel
275: .getAccessibleContext()
276: .setAccessibleDescription(
277: org.openide.util.NbBundle
278: .getMessage(
279: UpdateCenterRegistrationPanel.class,
280: "ACD_UpdateCenterRegistrationPanel_projectLabel",
281: new Object[] {}));
282:
283: project.setEditable(false);
284: gridBagConstraints = new java.awt.GridBagConstraints();
285: gridBagConstraints.gridx = 1;
286: gridBagConstraints.gridy = 3;
287: gridBagConstraints.gridwidth = 2;
288: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
289: gridBagConstraints.weightx = 1.0;
290: gridBagConstraints.insets = new java.awt.Insets(18, 0, 6, 0);
291: add(project, gridBagConstraints);
292:
293: createdFilesLabel.setLabelFor(createdFiles);
294: org.openide.awt.Mnemonics.setLocalizedText(createdFilesLabel,
295: org.openide.util.NbBundle.getMessage(
296: UpdateCenterRegistrationPanel.class,
297: "LBL_CreatedFiles"));
298: gridBagConstraints = new java.awt.GridBagConstraints();
299: gridBagConstraints.gridx = 0;
300: gridBagConstraints.gridy = 5;
301: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
302: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
303: gridBagConstraints.weighty = 0.5;
304: gridBagConstraints.insets = new java.awt.Insets(36, 0, 6, 12);
305: add(createdFilesLabel, gridBagConstraints);
306: createdFilesLabel
307: .getAccessibleContext()
308: .setAccessibleDescription(
309: org.openide.util.NbBundle
310: .getMessage(
311: UpdateCenterRegistrationPanel.class,
312: "ACD_UpdateCenterRegistrationPanel_createdFilesLabel",
313: new Object[] {}));
314:
315: createdFiles.setBackground(javax.swing.UIManager.getDefaults()
316: .getColor("Label.background"));
317: createdFiles.setColumns(20);
318: createdFiles.setEditable(false);
319: createdFiles.setRows(5);
320: createdFiles.setBorder(null);
321: gridBagConstraints = new java.awt.GridBagConstraints();
322: gridBagConstraints.gridx = 1;
323: gridBagConstraints.gridy = 5;
324: gridBagConstraints.gridwidth = 2;
325: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
326: gridBagConstraints.weightx = 1.0;
327: gridBagConstraints.weighty = 0.5;
328: gridBagConstraints.insets = new java.awt.Insets(36, 0, 6, 0);
329: add(createdFiles, gridBagConstraints);
330:
331: modifiedFilesLabel.setLabelFor(modifiedFiles);
332: org.openide.awt.Mnemonics.setLocalizedText(modifiedFilesLabel,
333: org.openide.util.NbBundle.getMessage(
334: UpdateCenterRegistrationPanel.class,
335: "LBL_ModifiedFiles"));
336: gridBagConstraints = new java.awt.GridBagConstraints();
337: gridBagConstraints.gridx = 0;
338: gridBagConstraints.gridy = 6;
339: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
340: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
341: gridBagConstraints.weighty = 0.5;
342: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
343: add(modifiedFilesLabel, gridBagConstraints);
344: modifiedFilesLabel
345: .getAccessibleContext()
346: .setAccessibleDescription(
347: org.openide.util.NbBundle
348: .getMessage(
349: UpdateCenterRegistrationPanel.class,
350: "ACD_UpdateCenterRegistrationPanel_modifiedFilesLabel",
351: new Object[] {}));
352:
353: modifiedFiles.setBackground(javax.swing.UIManager.getDefaults()
354: .getColor("Label.background"));
355: modifiedFiles.setColumns(20);
356: modifiedFiles.setEditable(false);
357: modifiedFiles.setRows(5);
358: modifiedFiles.setToolTipText("modifiedFilesValue");
359: modifiedFiles.setBorder(null);
360: gridBagConstraints = new java.awt.GridBagConstraints();
361: gridBagConstraints.gridx = 1;
362: gridBagConstraints.gridy = 6;
363: gridBagConstraints.gridwidth = 2;
364: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
365: gridBagConstraints.weightx = 1.0;
366: gridBagConstraints.weighty = 0.5;
367: add(modifiedFiles, gridBagConstraints);
368:
369: }// </editor-fold>//GEN-END:initComponents
370:
371: // Variables declaration - do not modify//GEN-BEGIN:variables
372: private javax.swing.JTextArea createdFiles;
373: private javax.swing.JLabel createdFilesLabel;
374: private javax.swing.JTextField displayName;
375: private javax.swing.JLabel displayNameLabel;
376: private javax.swing.JTextArea modifiedFiles;
377: private javax.swing.JLabel modifiedFilesLabel;
378: private javax.swing.JTextField project;
379: private javax.swing.JLabel projectLabel;
380: private javax.swing.JTextField ucUrl;
381: private javax.swing.JLabel ucUrlLabel;
382: // End of variables declaration//GEN-END:variables
383:
384: }
|