KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > common > CustomizerTitlePanel


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  * CustomizerTitlePanel.java
21  *
22  * Created on February 19, 2004, 4:57 PM
23  */

24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common;
25
26 import java.awt.Container JavaDoc;
27 import java.awt.Font JavaDoc;
28 import java.awt.GridBagConstraints JavaDoc;
29 import java.awt.Insets JavaDoc;
30
31 import java.awt.event.MouseAdapter JavaDoc;
32 import java.awt.event.MouseEvent JavaDoc;
33
34 import java.util.ResourceBundle JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.ImageIcon JavaDoc;
37 import javax.swing.SwingUtilities JavaDoc;
38 import javax.swing.UIManager JavaDoc;
39 import javax.swing.plaf.metal.MetalLookAndFeel JavaDoc;
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 /**
52  *
53  * @author Peter Williams
54  */

55 public class CustomizerTitlePanel extends JPanel JavaDoc {
56     
57     /** Reference to the resource bundle in customizers/common
58      */

59     protected static final ResourceBundle JavaDoc commonBundle = ResourceBundle.getBundle(
60         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); // NOI18N
61

62     /** Path for help button image resource
63      */

64     private static final String JavaDoc helpButtonImagePath =
65         "org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/resources/customizerHelp.gif"; // NOI18N
66

67     /** We only want to load this one. It's only used here, but in case someone
68      * decides to use it elsewhere, we'll make it public.
69      */

70     public static final ImageIcon JavaDoc helpIcon =
71          new ImageIcon JavaDoc(Utils.getResourceURL(helpButtonImagePath, CustomizerTitlePanel.class));
72     
73     /** Creates new form CustomizerTitlePanel */
74     public CustomizerTitlePanel() {
75         initComponents();
76         initUserComponents();
77     }
78     
79     public void setCustomizerTitle(String JavaDoc title) {
80         jLblDDType.setText(title);
81     }
82     
83     public GridBagConstraints JavaDoc getConstraints() {
84         GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
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     /** This method is called from within the constructor to
94      * initialize the form.
95      * WARNING: Do NOT modify this code. The content of this method is
96      * always regenerated by the Form Editor.
97      */

98     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
99
private void initComponents() {
100         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
101
102         jLblDDType = new javax.swing.JLabel JavaDoc();
103         jBtnEditXml = new javax.swing.JButton JavaDoc();
104         jBtnDocType = new javax.swing.JButton JavaDoc();
105         jBtnHelp = new javax.swing.JButton JavaDoc();
106
107         setLayout(new java.awt.GridBagLayout JavaDoc());
108
109         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(6, 6, 5, 5);
114         add(jLblDDType, gridBagConstraints);
115
116         jBtnEditXml.setText(commonBundle.getString("LBL_EditAsXml"));
117         jBtnEditXml.setMargin(new java.awt.Insets JavaDoc(0, 10, 0, 10));
118         jBtnEditXml.addActionListener(new java.awt.event.ActionListener JavaDoc() {
119             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
120                 jBtnEditXmlActionPerformed(evt);
121             }
122         });
123
124         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc(0, 10, 0, 10));
132         jBtnDocType.addActionListener(new java.awt.event.ActionListener JavaDoc() {
133             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
134                 jBtnDocTypeActionPerformed(evt);
135             }
136         });
137
138         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
139         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc() {
150             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
151                 jBtnHelpActionPerformed(evt);
152             }
153         });
154
155         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
156         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
157         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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     }// </editor-fold>//GEN-END:initComponents
163

164     private void jBtnEditXmlActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnEditXmlActionPerformed
165
// TODO add your handling code here:
166
Base theBean = null;
167         Container JavaDoc parent = getParent();
168         if(parent instanceof BaseCustomizer) {
169             BaseCustomizer masterPanel = (BaseCustomizer) parent;
170             theBean = masterPanel.getBean();
171         }
172         // FIXME we can remove this part when EjbJar customizers are migrated to BaseCustomizer.
173
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     }//GEN-LAST:event_jBtnEditXmlActionPerformed
182

183     private void jBtnDocTypeActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnDocTypeActionPerformed
184
Base theBean = null;
185         Container JavaDoc p = getParent();
186         if(p instanceof JPanel JavaDoc) {
187             JPanel JavaDoc parent = (JPanel JavaDoc) p;
188             if(parent instanceof BaseCustomizer) {
189                 BaseCustomizer masterPanel = (BaseCustomizer) parent;
190                 theBean = masterPanel.getBean();
191             }
192             // FIXME we can remove this part when EjbJar customizers are migrated to BaseCustomizer.
193
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     }//GEN-LAST:event_jBtnDocTypeActionPerformed
203

204     private void jBtnHelpActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnHelpActionPerformed
205
Container JavaDoc 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     }//GEN-LAST:event_jBtnHelpActionPerformed
212

213     
214     // Variables declaration - do not modify//GEN-BEGIN:variables
215
private javax.swing.JButton JavaDoc jBtnDocType;
216     private javax.swing.JButton JavaDoc jBtnEditXml;
217     private javax.swing.JButton JavaDoc jBtnHelp;
218     private javax.swing.JLabel JavaDoc jLblDDType;
219     // End of variables declaration//GEN-END:variables
220

221     private void initUserComponents() {
222         // Set the title font to be bold and +4 size to regular font, whatever that is.
223
Font JavaDoc labelFont = jLblDDType.getFont();
224         jLblDDType.setFont(labelFont.deriveFont(Font.BOLD, labelFont.getSize()+4));
225         
226         jBtnHelp.setIcon(helpIcon);
227         
228         // !PW Taken verbatim from org\openide\explorer\propertysheet\DescriptionPanel.java
229
// Just a little something to make the button a little bit more polished under
230
// metal L&F I think (though personally, I was unable to see any effect myself.)
231
//
232
if (UIManager.getLookAndFeel() instanceof MetalLookAndFeel JavaDoc) {
233             jBtnHelp.setBorderPainted(false);
234             //issue 34159 Metal rollover buttons do not use rollover border
235
jBtnHelp.addMouseListener(new MouseAdapter JavaDoc() {
236                 public void mouseEntered (MouseEvent JavaDoc me) {
237                     jBtnHelp.setBorderPainted(true);
238                 }
239                 public void mouseExited (MouseEvent JavaDoc me) {
240                     jBtnHelp.setBorderPainted(false);
241                 }
242             });
243         }
244     }
245     
246     private boolean switchToXml(SunONEDeploymentConfiguration config) {
247         // first get primary dataobject
248
ConfigDataObject primaryDO = null;
249         ConfigurationStorage storage = config.getStorage();
250         if(storage != null) {
251             primaryDO = storage.getPrimaryDataObject();
252         }
253         
254         if(primaryDO == null) {
255 // System.out.println("Can't find primary dataobject for this configuration.");
256
return false;
257         }
258         
259         if(!primaryDO.closeConfigEditors()) {
260 // System.out.println("Failed to close editor(s).");
261
return false;
262         }
263         
264         // process closing & possible autosave.
265
try {
266             // hack - wait for autosave() to post it's event.
267
Thread.currentThread().sleep(100);
268         } catch (InterruptedException JavaDoc ex) {
269             // shouldn't happen, but just ignore it if it does.
270
}
271         
272         final ConfigDataObject theDataObject = primaryDO;
273         SwingUtilities.invokeLater(new Runnable JavaDoc() {
274             public void run() {
275                 // reopen editor
276
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