KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > updatecenter > UpdateCenterRegistrationPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.wizard.updatecenter;
21
22 import java.net.MalformedURLException JavaDoc;
23 import java.net.URL JavaDoc;
24 import javax.swing.JTextField JavaDoc;
25 import javax.swing.event.DocumentEvent JavaDoc;
26 import javax.swing.event.DocumentListener JavaDoc;
27 import org.netbeans.api.project.ProjectUtils;
28 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
29 import org.netbeans.modules.apisupport.project.ui.UIUtil;
30 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
31 import org.openide.WizardDescriptor;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34
35 /**
36  * The panel in the <em>New Update Center Wizard</em>.
37  *
38  * @author Jiri Rechtacek
39  */

40 final class UpdateCenterRegistrationPanel extends BasicWizardIterator.Panel {
41     
42     private DataModel data;
43     private DocumentListener JavaDoc updateListener;
44     
45     /**
46      * Creates new UpdateCenterRegistrationPanel
47      */

48     public UpdateCenterRegistrationPanel(final WizardDescriptor setting, final DataModel data) {
49         super(setting);
50         this.data = data;
51         initComponents();
52
53         putClientProperty("NewFileWizard_Title", getMessage("LBL_NewUpdateCenterWizardTitle")); //NOI18N
54

55         updateListener = new UIUtil.DocumentAdapter() {
56             public void insertUpdate(DocumentEvent JavaDoc e) {
57                 updateData();
58             }
59         };
60     }
61     
62     private void addListeners() {
63         ucUrl.getDocument ().addDocumentListener (updateListener);
64         displayName.getDocument ().addDocumentListener (updateListener);
65     }
66     
67     private void removeListeners() {
68         ucUrl.getDocument ().removeDocumentListener (updateListener);
69         displayName.getDocument ().removeDocumentListener (updateListener);
70     }
71     
72     protected String JavaDoc getPanelName() {
73         return getMessage("LBL_UpdateCenterRegistrationPanel_Title"); //NOI18N
74
}
75     
76     protected void storeToDataModel() {
77         removeListeners();
78         storeBaseData();
79     }
80     
81     protected void readFromDataModel() {
82         updateData();
83         addListeners();
84     }
85     
86     void updateData() {
87         storeBaseData ();
88         if (checkValidity ()) {
89             CreatedModifiedFiles files = data.refreshCreatedModifiedFiles();
90             createdFiles.setText(UIUtil.generateTextAreaContent(files.getCreatedPaths()));
91             modifiedFiles.setText(UIUtil.generateTextAreaContent(files.getModifiedPaths()));
92         }
93     }
94     
95     /** Data needed to compute CMF */
96     private void storeBaseData() {
97         data.setUpdateCenterURL (ucUrl.getText ().trim ());
98         data.setUpdateCenterDisplayName (displayName.getText ().trim ());
99     }
100     
101     private boolean checkValidity() {
102         boolean result = false;
103         if (data.getUpdateCenterURL ().length () == 0) {
104             setError(getMessage ("ERR_Url_Is_Empty")); //NOI18N
105
} else if (data.getUpdateCenterDisplayName ().length () == 0) {
106             setError(getMessage ("ERR_Empty_Display_Name")); //NOI18N
107
} else {
108             result = true;
109             if (! data.getUpdateCenterURL ().endsWith (".xml")) {
110                 setWarning(getMessage("WRN_Url_dont_xml_file")); // NOI18N
111
} else {
112                 
113                 try {
114                     // try transform to URL
115
new URL JavaDoc (data.getUpdateCenterURL ());
116
117                     // all is ok
118
markValid();
119                 } catch (MalformedURLException JavaDoc ex) {
120                     setWarning(NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "WRN_Url_cannot_be_created", ex.getLocalizedMessage()));
121                 }
122                 
123             }
124         }
125
126         return result;
127     }
128     
129     protected HelpCtx getHelp() {
130         return new HelpCtx(UpdateCenterRegistrationPanel.class);
131     }
132     
133     private static String JavaDoc getMessage(String JavaDoc key) {
134         return NbBundle.getMessage(UpdateCenterRegistrationPanel.class, key);
135     }
136     
137     /** This method is called from within the constructor to
138      * initialize the form.
139      * WARNING: Do NOT modify this code. The content of this method is
140      * always regenerated by the Form Editor.
141      */

142     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
143
private void initComponents() {
144         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
145
146         ucUrlLabel = new javax.swing.JLabel JavaDoc();
147         ucUrl = new javax.swing.JTextField JavaDoc();
148         displayNameLabel = new javax.swing.JLabel JavaDoc();
149         displayName = new javax.swing.JTextField JavaDoc();
150         projectLabel = new javax.swing.JLabel JavaDoc();
151         project = new JTextField JavaDoc(ProjectUtils.getInformation(data.getProject()).getDisplayName());
152         createdFilesLabel = new javax.swing.JLabel JavaDoc();
153         createdFiles = new javax.swing.JTextArea JavaDoc();
154         modifiedFilesLabel = new javax.swing.JLabel JavaDoc();
155         modifiedFiles = new javax.swing.JTextArea JavaDoc();
156
157         setLayout(new java.awt.GridBagLayout JavaDoc());
158
159         getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACN_UpdateCenterRegistrationPanel", new Object JavaDoc[] {}));
160         getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel", new Object JavaDoc[] {}));
161         ucUrlLabel.setLabelFor(ucUrl);
162         org.openide.awt.Mnemonics.setLocalizedText(ucUrlLabel, org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "LBL_UpdateCenterURL"));
163         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints.gridx = 0;
165         gridBagConstraints.gridy = 0;
166         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
167         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 12);
168         add(ucUrlLabel, gridBagConstraints);
169         ucUrlLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_ucUrlLabel", new Object JavaDoc[] {}));
170
171         ucUrl.setText(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "CTL_SampleURL"));
172         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridx = 1;
174         gridBagConstraints.gridy = 0;
175         gridBagConstraints.gridwidth = 2;
176         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
177         gridBagConstraints.weightx = 1.0;
178         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
179         add(ucUrl, gridBagConstraints);
180
181         displayNameLabel.setLabelFor(displayName);
182         org.openide.awt.Mnemonics.setLocalizedText(displayNameLabel, org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "LBL_DisplayName"));
183         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
184         gridBagConstraints.gridx = 0;
185         gridBagConstraints.gridy = 1;
186         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
187         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 12);
188         add(displayNameLabel, gridBagConstraints);
189         displayNameLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_displayNameLabel", new Object JavaDoc[] {}));
190
191         displayName.setText(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "CTL_SampleName", new Object JavaDoc[] {project.getText ()}));
192         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.gridx = 1;
194         gridBagConstraints.gridy = 1;
195         gridBagConstraints.gridwidth = 2;
196         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
197         gridBagConstraints.weightx = 1.0;
198         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
199         add(displayName, gridBagConstraints);
200
201         projectLabel.setLabelFor(project);
202         org.openide.awt.Mnemonics.setLocalizedText(projectLabel, org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "LBL_ProjectName"));
203         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
204         gridBagConstraints.gridx = 0;
205         gridBagConstraints.gridy = 3;
206         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
207         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 6, 12);
208         add(projectLabel, gridBagConstraints);
209         projectLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_projectLabel", new Object JavaDoc[] {}));
210
211         project.setEditable(false);
212         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
213         gridBagConstraints.gridx = 1;
214         gridBagConstraints.gridy = 3;
215         gridBagConstraints.gridwidth = 2;
216         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
217         gridBagConstraints.weightx = 1.0;
218         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 6, 0);
219         add(project, gridBagConstraints);
220
221         createdFilesLabel.setLabelFor(createdFiles);
222         org.openide.awt.Mnemonics.setLocalizedText(createdFilesLabel, org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "LBL_CreatedFiles"));
223         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
224         gridBagConstraints.gridx = 0;
225         gridBagConstraints.gridy = 5;
226         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
227         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
228         gridBagConstraints.weighty = 0.5;
229         gridBagConstraints.insets = new java.awt.Insets JavaDoc(36, 0, 6, 12);
230         add(createdFilesLabel, gridBagConstraints);
231         createdFilesLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_createdFilesLabel", new Object JavaDoc[] {}));
232
233         createdFiles.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background"));
234         createdFiles.setColumns(20);
235         createdFiles.setEditable(false);
236         createdFiles.setRows(5);
237         createdFiles.setBorder(null);
238         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
239         gridBagConstraints.gridx = 1;
240         gridBagConstraints.gridy = 5;
241         gridBagConstraints.gridwidth = 2;
242         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
243         gridBagConstraints.weightx = 1.0;
244         gridBagConstraints.weighty = 0.5;
245         gridBagConstraints.insets = new java.awt.Insets JavaDoc(36, 0, 6, 0);
246         add(createdFiles, gridBagConstraints);
247
248         modifiedFilesLabel.setLabelFor(modifiedFiles);
249         org.openide.awt.Mnemonics.setLocalizedText(modifiedFilesLabel, org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "LBL_ModifiedFiles"));
250         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
251         gridBagConstraints.gridx = 0;
252         gridBagConstraints.gridy = 6;
253         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
254         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
255         gridBagConstraints.weighty = 0.5;
256         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
257         add(modifiedFilesLabel, gridBagConstraints);
258         modifiedFilesLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_modifiedFilesLabel", new Object JavaDoc[] {}));
259
260         modifiedFiles.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background"));
261         modifiedFiles.setColumns(20);
262         modifiedFiles.setEditable(false);
263         modifiedFiles.setRows(5);
264         modifiedFiles.setToolTipText("modifiedFilesValue");
265         modifiedFiles.setBorder(null);
266         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
267         gridBagConstraints.gridx = 1;
268         gridBagConstraints.gridy = 6;
269         gridBagConstraints.gridwidth = 2;
270         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
271         gridBagConstraints.weightx = 1.0;
272         gridBagConstraints.weighty = 0.5;
273         add(modifiedFiles, gridBagConstraints);
274
275     }// </editor-fold>//GEN-END:initComponents
276

277     
278     // Variables declaration - do not modify//GEN-BEGIN:variables
279
private javax.swing.JTextArea JavaDoc createdFiles;
280     private javax.swing.JLabel JavaDoc createdFilesLabel;
281     private javax.swing.JTextField JavaDoc displayName;
282     private javax.swing.JLabel JavaDoc displayNameLabel;
283     private javax.swing.JTextArea JavaDoc modifiedFiles;
284     private javax.swing.JLabel JavaDoc modifiedFilesLabel;
285     private javax.swing.JTextField JavaDoc project;
286     private javax.swing.JLabel JavaDoc projectLabel;
287     private javax.swing.JTextField JavaDoc ucUrl;
288     private javax.swing.JLabel JavaDoc ucUrlLabel;
289     // End of variables declaration//GEN-END:variables
290

291 }
Popular Tags