1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.updatecenter; 21 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import javax.swing.JTextField ; 25 import javax.swing.event.DocumentEvent ; 26 import javax.swing.event.DocumentListener ; 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 40 final class UpdateCenterRegistrationPanel extends BasicWizardIterator.Panel { 41 42 private DataModel data; 43 private DocumentListener updateListener; 44 45 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")); 55 updateListener = new UIUtil.DocumentAdapter() { 56 public void insertUpdate(DocumentEvent 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 getPanelName() { 73 return getMessage("LBL_UpdateCenterRegistrationPanel_Title"); } 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 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")); } else if (data.getUpdateCenterDisplayName ().length () == 0) { 106 setError(getMessage ("ERR_Empty_Display_Name")); } else { 108 result = true; 109 if (! data.getUpdateCenterURL ().endsWith (".xml")) { 110 setWarning(getMessage("WRN_Url_dont_xml_file")); } else { 112 113 try { 114 new URL (data.getUpdateCenterURL ()); 116 117 markValid(); 119 } catch (MalformedURLException 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 getMessage(String key) { 134 return NbBundle.getMessage(UpdateCenterRegistrationPanel.class, key); 135 } 136 137 142 private void initComponents() { 144 java.awt.GridBagConstraints gridBagConstraints; 145 146 ucUrlLabel = new javax.swing.JLabel (); 147 ucUrl = new javax.swing.JTextField (); 148 displayNameLabel = new javax.swing.JLabel (); 149 displayName = new javax.swing.JTextField (); 150 projectLabel = new javax.swing.JLabel (); 151 project = new JTextField (ProjectUtils.getInformation(data.getProject()).getDisplayName()); 152 createdFilesLabel = new javax.swing.JLabel (); 153 createdFiles = new javax.swing.JTextArea (); 154 modifiedFilesLabel = new javax.swing.JLabel (); 155 modifiedFiles = new javax.swing.JTextArea (); 156 157 setLayout(new java.awt.GridBagLayout ()); 158 159 getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACN_UpdateCenterRegistrationPanel", new Object [] {})); 160 getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel", new Object [] {})); 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 (); 164 gridBagConstraints.gridx = 0; 165 gridBagConstraints.gridy = 0; 166 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 167 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 12); 168 add(ucUrlLabel, gridBagConstraints); 169 ucUrlLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_ucUrlLabel", new Object [] {})); 170 171 ucUrl.setText(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "CTL_SampleURL")); 172 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 184 gridBagConstraints.gridx = 0; 185 gridBagConstraints.gridy = 1; 186 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 187 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 12); 188 add(displayNameLabel, gridBagConstraints); 189 displayNameLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_displayNameLabel", new Object [] {})); 190 191 displayName.setText(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "CTL_SampleName", new Object [] {project.getText ()})); 192 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 204 gridBagConstraints.gridx = 0; 205 gridBagConstraints.gridy = 3; 206 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 207 gridBagConstraints.insets = new java.awt.Insets (18, 0, 6, 12); 208 add(projectLabel, gridBagConstraints); 209 projectLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_projectLabel", new Object [] {})); 210 211 project.setEditable(false); 212 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 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 (36, 0, 6, 12); 230 add(createdFilesLabel, gridBagConstraints); 231 createdFilesLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_createdFilesLabel", new Object [] {})); 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 (); 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 (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 (); 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 (0, 0, 0, 12); 257 add(modifiedFilesLabel, gridBagConstraints); 258 modifiedFilesLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateCenterRegistrationPanel.class, "ACD_UpdateCenterRegistrationPanel_modifiedFilesLabel", new Object [] {})); 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 (); 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 } 277 278 private javax.swing.JTextArea createdFiles; 280 private javax.swing.JLabel createdFilesLabel; 281 private javax.swing.JTextField displayName; 282 private javax.swing.JLabel displayNameLabel; 283 private javax.swing.JTextArea modifiedFiles; 284 private javax.swing.JLabel modifiedFilesLabel; 285 private javax.swing.JTextField project; 286 private javax.swing.JLabel projectLabel; 287 private javax.swing.JTextField ucUrl; 288 private javax.swing.JLabel ucUrlLabel; 289 291 } | Popular Tags |