1 18 package org.netbeans.modules.changelog.wizard; 19 20 24 25 import org.openide.util.*; 26 import org.openide.*; 27 import org.openide.filesystems.*; 28 import org.openide.loaders.*; 29 import org.openide.modules.*; 30 31 import javax.swing.event.*; 32 import javax.swing.*; 33 import java.util.*; 34 import org.netbeans.modules.changelog.*; 35 import org.netbeans.modules.changelog.html.*; 36 37 38 public class HtmlPanel extends javax.swing.JPanel { 39 40 private HtmlPanelCustomizer customizer; 41 private ChangeLogHTMLService[] array; 42 private boolean loadingSemafore = false; 43 44 public HtmlPanel() { 45 initComponents(); 46 putClientProperty ("WizardPanel_contentSelectedIndex", new Integer (2)); customizer = new HtmlPanelCustomizer(); 48 customizer.disableEditing(true); 49 pnlCustom.add(customizer, java.awt.BorderLayout.CENTER); 50 51 array = null; 52 53 comServerDef.addActionListener(new java.awt.event.ActionListener () { 54 public void actionPerformed(java.awt.event.ActionEvent event) { 55 if (!loadingSemafore) { 56 changeItem(); 57 } 58 } 59 }); 60 btnEdit.addActionListener(new java.awt.event.ActionListener () { 61 public void actionPerformed(java.awt.event.ActionEvent event) { 62 doEdit(); 63 } 64 }); 65 btnSaveAs.addActionListener(new java.awt.event.ActionListener () { 66 public void actionPerformed(java.awt.event.ActionEvent event) { 67 doSaveAs(); 68 } 69 }); 70 } 71 72 77 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 79 80 lblServerDef = new javax.swing.JLabel (); 81 comServerDef = new javax.swing.JComboBox (); 82 btnEdit = new javax.swing.JButton (); 83 btnSaveAs = new javax.swing.JButton (); 84 pnlCustom = new javax.swing.JPanel (); 85 86 setLayout(new java.awt.GridBagLayout ()); 87 88 setMinimumSize(new java.awt.Dimension (400, 200)); 89 setPreferredSize(new java.awt.Dimension (600, 300)); 90 getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSN_HtmlPanel")); 91 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSD_HtmlPanel")); 92 lblServerDef.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACS_lblServerDef_mnc").charAt(0)); 93 lblServerDef.setLabelFor(comServerDef); 94 lblServerDef.setText(org.openide.util.NbBundle.getBundle(HtmlPanel.class).getString("HtmlPanel.lblServerDef.text")); 95 gridBagConstraints = new java.awt.GridBagConstraints (); 96 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 97 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 98 add(lblServerDef, gridBagConstraints); 99 100 gridBagConstraints = new java.awt.GridBagConstraints (); 101 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 102 gridBagConstraints.insets = new java.awt.Insets (12, 6, 0, 0); 103 add(comServerDef, gridBagConstraints); 104 comServerDef.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSD_comServerDef")); 105 106 btnEdit.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACS_btnEdit_mnc").charAt(0)); 107 btnEdit.setText(org.openide.util.NbBundle.getBundle(HtmlPanel.class).getString("HtmlPanel.btnEdit.text")); 108 gridBagConstraints = new java.awt.GridBagConstraints (); 109 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 110 gridBagConstraints.insets = new java.awt.Insets (12, 6, 0, 0); 111 add(btnEdit, gridBagConstraints); 112 btnEdit.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSD_btnEdit")); 113 114 btnSaveAs.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACS_btnSaveAs_mnc").charAt(0)); 115 btnSaveAs.setText(org.openide.util.NbBundle.getBundle(HtmlPanel.class).getString("HtmlPanel.btnSave.text")); 116 gridBagConstraints = new java.awt.GridBagConstraints (); 117 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 118 gridBagConstraints.insets = new java.awt.Insets (12, 6, 0, 12); 119 add(btnSaveAs, gridBagConstraints); 120 btnSaveAs.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSD_btnSaveAs")); 121 122 pnlCustom.setLayout(new java.awt.BorderLayout ()); 123 124 gridBagConstraints = new java.awt.GridBagConstraints (); 125 gridBagConstraints.gridx = 0; 126 gridBagConstraints.gridy = 1; 127 gridBagConstraints.gridwidth = 4; 128 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 129 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 130 gridBagConstraints.weighty = 0.5; 131 gridBagConstraints.insets = new java.awt.Insets (6, 12, 12, 12); 132 add(pnlCustom, gridBagConstraints); 133 134 } 136 private void changeItem() { 137 int index = comServerDef.getSelectedIndex(); 138 customizer.setObject(array[index]); 139 customizer.disableEditing(true); 140 } 141 142 private void doEdit() { 143 customizer.disableEditing(false); 144 } 145 146 private void doSaveAs() { 147 int index = comServerDef.getSelectedIndex(); 149 NotifyDescriptor.InputLine dial = new NotifyDescriptor.InputLine("Name:", "Save As", NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE); 150 Object ret = TopManager.getDefault().notify(dial); 151 if (ret.equals(NotifyDescriptor.OK_OPTION)) { 152 ChangeLogHTMLService service = array[index]; 153 service.setName(dial.getInputText()); 154 DataFolder f = DataFolder.findFolder( 155 Repository.getDefault().getDefaultFileSystem().findResource("Services/ChangeLogHtmlType")); ModuleInfo m = null; 157 Iterator it = Lookup.getDefault().lookup( 158 new Lookup.Template(ModuleInfo.class, 159 null, null)).allInstances().iterator(); 160 while (it.hasNext()) { 161 ModuleInfo _m = (ModuleInfo)it.next(); 162 if (_m.getCodeNameBase().equals("org.netbeans.modules.changelog")) { m = _m; 164 break; 165 } 166 } 167 if (m == null) throw new IllegalStateException (); 168 try { 169 InstanceDataObject ido = InstanceDataObject.create(f, null, service, m, true); 170 } catch (java.io.IOException exc) { 171 ErrorManager.getDefault().log(ErrorManager.USER, "Cannot save new Server Info"); 172 return; 173 } 174 } 175 loadCombo(); 176 comServerDef.setSelectedIndex(array.length - 1); 177 changeItem(); 178 } 179 180 private void loadCombo() { 181 loadingSemafore = true; 183 Lookup.Template template = new Lookup.Template(ChangeLogHTMLService.class); 184 Lookup.Result result = Lookup.getDefault().lookup(template); 185 Collection coll = result.allInstances(); 186 array = new ChangeLogHTMLService[coll.size() + 1]; 187 String [] names = new String [coll.size() + 1]; 188 Iterator it = coll.iterator(); 189 int count = 1; 190 while (it.hasNext()) { 191 ChangeLogHTMLService serv = (ChangeLogHTMLService)it.next(); 192 array[count] = (ChangeLogHTMLService)serv.createClone(); 193 names[count] = serv.getName(); 194 count = count + 1; 195 } 196 array[0] = new ChangeLogHTMLService(); 197 names[0] = org.openide.util.NbBundle.getBundle(HtmlPanel.class).getString("No_server_specific_processing"); 198 comServerDef.setModel(new DefaultComboBoxModel(names)); 199 loadingSemafore = false; 200 201 } 202 203 204 205 private javax.swing.JButton btnSaveAs; 207 private javax.swing.JComboBox comServerDef; 208 private javax.swing.JButton btnEdit; 209 private javax.swing.JPanel pnlCustom; 210 private javax.swing.JLabel lblServerDef; 211 213 214 public static class Panel implements org.openide.WizardDescriptor.Panel { 215 216 private HtmlPanel panel; 217 private String name; 218 219 220 public Panel (String name) { 221 this.name = name; 222 } 223 224 227 public synchronized java.awt.Component getComponent() { 228 if (this.panel == null) { 229 this.panel = new HtmlPanel(); 230 this.panel.setName (this.name); 231 } 232 return this.panel; 233 } 234 235 239 public HelpCtx getHelp() { 240 return new HelpCtx(this.getClass()); 241 } 242 243 247 public void addChangeListener(ChangeListener l) { 248 } 249 250 253 public void removeChangeListener(ChangeListener l) { 254 } 255 256 public boolean isValid() { 257 return true; 258 } 259 260 269 public void storeSettings(Object settings) { 270 if (settings instanceof ChangeLogProcessor) { 271 ChangeLogProcessor proces = (ChangeLogProcessor)settings; 272 HtmlPanel p = (HtmlPanel) this.getComponent(); 273 if (p.comServerDef.getSelectedIndex() != 0) { 274 int index = p.comServerDef.getSelectedIndex(); 275 proces.setHtmlSiteProcessor(p.array[index]); 276 } else { 277 proces.setHtmlSiteProcessor(null); 278 } 279 } 280 } 281 282 289 public void readSettings(Object settings) { 290 if (settings instanceof ChangeLogProcessor) { 291 HtmlPanel p = (HtmlPanel) this.getComponent(); 292 p.loadCombo(); 293 ChangeLogProcessor proces = (ChangeLogProcessor)settings; 294 if (proces.getHtmlSiteProcessor() == null) { 295 p.comServerDef.setSelectedIndex(0); 296 p.changeItem(); 297 } else { 298 ChangeLogHTMLService service = proces.getHtmlSiteProcessor(); 299 for (int i = 0; i < p.array.length; i++) { 300 if (p.array[i].getName().equals(service.getName())) { 301 p.comServerDef.setSelectedIndex(i); 302 p.changeItem(); 303 break; 304 } 305 } 306 } 307 } 308 } 309 310 } 311 312 } 313 | Popular Tags |