1 19 24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common; 25 26 import java.awt.Container ; 27 import java.awt.Font ; 28 import java.awt.GridBagConstraints ; 29 import java.awt.Insets ; 30 31 import java.awt.event.MouseAdapter ; 32 import java.awt.event.MouseEvent ; 33 34 import java.util.ResourceBundle ; 35 import javax.swing.JPanel ; 36 import javax.swing.ImageIcon ; 37 import javax.swing.SwingUtilities ; 38 import javax.swing.UIManager ; 39 import javax.swing.plaf.metal.MetalLookAndFeel ; 40 import org.netbeans.modules.j2ee.sun.share.config.ConfigDataObject; 41 import org.netbeans.modules.j2ee.sun.share.config.ConfigurationStorage; 42 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration; 43 import org.openide.cookies.EditCookie; 44 45 import org.openide.util.HelpCtx; 46 47 import org.netbeans.modules.j2ee.sun.share.Constants; 48 import org.netbeans.modules.j2ee.sun.share.configbean.Base; 49 import org.netbeans.modules.j2ee.sun.share.configbean.Utils; 50 51 55 public class CustomizerTitlePanel extends JPanel { 56 57 59 protected static final ResourceBundle commonBundle = ResourceBundle.getBundle( 60 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); 62 64 private static final String helpButtonImagePath = 65 "org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/resources/customizerHelp.gif"; 67 70 public static final ImageIcon helpIcon = 71 new ImageIcon (Utils.getResourceURL(helpButtonImagePath, CustomizerTitlePanel.class)); 72 73 74 public CustomizerTitlePanel() { 75 initComponents(); 76 initUserComponents(); 77 } 78 79 public void setCustomizerTitle(String title) { 80 jLblDDType.setText(title); 81 } 82 83 public GridBagConstraints getConstraints() { 84 GridBagConstraints constraints = new GridBagConstraints (); 85 constraints.gridwidth = GridBagConstraints.REMAINDER; 86 constraints.fill = GridBagConstraints.HORIZONTAL; 87 constraints.anchor = GridBagConstraints.NORTH; 88 constraints.weightx = 1.0; 89 90 return constraints; 91 } 92 93 98 private void initComponents() { 100 java.awt.GridBagConstraints gridBagConstraints; 101 102 jLblDDType = new javax.swing.JLabel (); 103 jBtnEditXml = new javax.swing.JButton (); 104 jBtnDocType = new javax.swing.JButton (); 105 jBtnHelp = new javax.swing.JButton (); 106 107 setLayout(new java.awt.GridBagLayout ()); 108 109 gridBagConstraints = new java.awt.GridBagConstraints (); 110 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 111 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 112 gridBagConstraints.weightx = 1.0; 113 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 5); 114 add(jLblDDType, gridBagConstraints); 115 116 jBtnEditXml.setText(commonBundle.getString("LBL_EditAsXml")); 117 jBtnEditXml.setMargin(new java.awt.Insets (0, 10, 0, 10)); 118 jBtnEditXml.addActionListener(new java.awt.event.ActionListener () { 119 public void actionPerformed(java.awt.event.ActionEvent evt) { 120 jBtnEditXmlActionPerformed(evt); 121 } 122 }); 123 124 gridBagConstraints = new java.awt.GridBagConstraints (); 125 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 126 add(jBtnEditXml, gridBagConstraints); 127 jBtnEditXml.getAccessibleContext().setAccessibleName(commonBundle.getString("ACSN_EditAsXml")); 128 jBtnEditXml.getAccessibleContext().setAccessibleDescription(commonBundle.getString("ACSD_EditAsXml")); 129 130 jBtnDocType.setText(commonBundle.getString("LBL_DocType")); 131 jBtnDocType.setMargin(new java.awt.Insets (0, 10, 0, 10)); 132 jBtnDocType.addActionListener(new java.awt.event.ActionListener () { 133 public void actionPerformed(java.awt.event.ActionEvent evt) { 134 jBtnDocTypeActionPerformed(evt); 135 } 136 }); 137 138 gridBagConstraints = new java.awt.GridBagConstraints (); 139 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 140 add(jBtnDocType, gridBagConstraints); 141 jBtnDocType.getAccessibleContext().setAccessibleName(commonBundle.getString("ACSN_Doctype")); 142 jBtnDocType.getAccessibleContext().setAccessibleDescription(commonBundle.getString("ACSD_Doctype")); 143 144 jBtnHelp.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 2, 1, 1)); 145 jBtnHelp.setContentAreaFilled(false); 146 jBtnHelp.setDefaultCapable(false); 147 jBtnHelp.setFocusPainted(false); 148 jBtnHelp.setName("CustomizerHelpButton"); 149 jBtnHelp.addActionListener(new java.awt.event.ActionListener () { 150 public void actionPerformed(java.awt.event.ActionEvent evt) { 151 jBtnHelpActionPerformed(evt); 152 } 153 }); 154 155 gridBagConstraints = new java.awt.GridBagConstraints (); 156 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 157 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 5); 158 add(jBtnHelp, gridBagConstraints); 159 jBtnHelp.getAccessibleContext().setAccessibleName(commonBundle.getString("ACSN_Help")); 160 jBtnHelp.getAccessibleContext().setAccessibleDescription(commonBundle.getString("ACSD_Help")); 161 162 } 164 private void jBtnEditXmlActionPerformed(java.awt.event.ActionEvent evt) { Base theBean = null; 167 Container parent = getParent(); 168 if(parent instanceof BaseCustomizer) { 169 BaseCustomizer masterPanel = (BaseCustomizer) parent; 170 theBean = masterPanel.getBean(); 171 } 172 else if(parent instanceof BeanCustomizer) { 174 BeanCustomizer masterPanel = (BeanCustomizer) parent; 175 theBean = masterPanel.getBean(); 176 } 177 178 if(theBean != null) { 179 switchToXml(theBean.getConfig()); 180 } 181 } 183 private void jBtnDocTypeActionPerformed(java.awt.event.ActionEvent evt) { Base theBean = null; 185 Container p = getParent(); 186 if(p instanceof JPanel ) { 187 JPanel parent = (JPanel ) p; 188 if(parent instanceof BaseCustomizer) { 189 BaseCustomizer masterPanel = (BaseCustomizer) parent; 190 theBean = masterPanel.getBean(); 191 } 192 else if(parent instanceof BeanCustomizer) { 194 BeanCustomizer masterPanel = (BeanCustomizer) parent; 195 theBean = masterPanel.getBean(); 196 } 197 198 if(theBean != null) { 199 ChangeDocTypePanel.editASVersion(parent, theBean); 200 } 201 } 202 } 204 private void jBtnHelpActionPerformed(java.awt.event.ActionEvent evt) { Container parent = getParent(); 206 if(parent instanceof HelpCtx.Provider) { 207 Utils.invokeHelp(((HelpCtx.Provider) parent).getHelpCtx()); 208 } else { 209 Constants.jsr88Logger.fine(commonBundle.getString("ERR_CustomizerHelpNotFound")); 210 } 211 } 213 214 private javax.swing.JButton jBtnDocType; 216 private javax.swing.JButton jBtnEditXml; 217 private javax.swing.JButton jBtnHelp; 218 private javax.swing.JLabel jLblDDType; 219 221 private void initUserComponents() { 222 Font labelFont = jLblDDType.getFont(); 224 jLblDDType.setFont(labelFont.deriveFont(Font.BOLD, labelFont.getSize()+4)); 225 226 jBtnHelp.setIcon(helpIcon); 227 228 if (UIManager.getLookAndFeel() instanceof MetalLookAndFeel ) { 233 jBtnHelp.setBorderPainted(false); 234 jBtnHelp.addMouseListener(new MouseAdapter () { 236 public void mouseEntered (MouseEvent me) { 237 jBtnHelp.setBorderPainted(true); 238 } 239 public void mouseExited (MouseEvent me) { 240 jBtnHelp.setBorderPainted(false); 241 } 242 }); 243 } 244 } 245 246 private boolean switchToXml(SunONEDeploymentConfiguration config) { 247 ConfigDataObject primaryDO = null; 249 ConfigurationStorage storage = config.getStorage(); 250 if(storage != null) { 251 primaryDO = storage.getPrimaryDataObject(); 252 } 253 254 if(primaryDO == null) { 255 return false; 257 } 258 259 if(!primaryDO.closeConfigEditors()) { 260 return false; 262 } 263 264 try { 266 Thread.currentThread().sleep(100); 268 } catch (InterruptedException ex) { 269 } 271 272 final ConfigDataObject theDataObject = primaryDO; 273 SwingUtilities.invokeLater(new Runnable () { 274 public void run() { 275 EditCookie editCookie = (EditCookie) theDataObject.getCookie(EditCookie.class); 277 if(editCookie != null) { 278 editCookie.edit(); 279 } 280 } 281 }); 282 283 return true; 284 } 285 } 286 | Popular Tags |