KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > blueprints > ui > ExampleTab


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.j2ee.blueprints.ui;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import org.openide.ErrorManager;
25 import org.openide.cookies.InstanceCookie;
26 import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.Repository;
28 import org.openide.loaders.DataObject;
29
30 import org.netbeans.modules.j2ee.blueprints.catalog.bpcatalogxmlparser.Nbcategory;
31
32 /**
33  * Tab Panel containing information about sample code for a solutions
34  * catalog entry.
35  *
36  * @author Mark Roth
37  */

38 public class ExampleTab
39     extends BluePrintsTabPanel
40 {
41     /** Creates new form ExampleTabPanel */
42     public ExampleTab(BluePrintsPanel bluePrintsPanel) {
43         super(bluePrintsPanel);
44         initComponents();
45     }
46
47     /** This method is called from within the constructor to
48      * initialize the form.
49      * WARNING: Do NOT modify this code. The content of this method is
50      * always regenerated by the Form Editor.
51      */

52     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
53
private void initComponents() {
54         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
55
56         launchExampleText = new javax.swing.JTextPane JavaDoc();
57         installBtn = new javax.swing.JButton JavaDoc();
58
59         setLayout(new java.awt.GridBagLayout JavaDoc());
60
61         setBackground(java.awt.Color.white);
62         launchExampleText.setEditable(false);
63         launchExampleText.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("launchExampleText"));
64         launchExampleText.setMargin(new java.awt.Insets JavaDoc(12, 12, 12, 12));
65         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
66         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
67         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
68         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
69         gridBagConstraints.weightx = 1.0;
70         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 7, 0);
71         add(launchExampleText, gridBagConstraints);
72
73         installBtn.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/blueprints/ui/Bundle").getString("launchBtn"));
74         installBtn.addActionListener(new java.awt.event.ActionListener JavaDoc() {
75             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
76                 installBtnActionPerformed(evt);
77             }
78         });
79
80         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
81         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
82         gridBagConstraints.weighty = 1.0;
83         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
84         add(installBtn, gridBagConstraints);
85
86     }
87     // </editor-fold>//GEN-END:initComponents
88

89     private void installBtnActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_installBtnActionPerformed
90
installExample();
91     }//GEN-LAST:event_installBtnActionPerformed
92

93     
94     // Variables declaration - do not modify//GEN-BEGIN:variables
95
private javax.swing.JButton JavaDoc installBtn;
96     private javax.swing.JTextPane JavaDoc launchExampleText;
97     // End of variables declaration//GEN-END:variables
98

99     // Special constants that allow us to preselect a template in the new
100
// project wizard
101
private static final String JavaDoc OPEN_SAMPLE_ACTION =
102         "org-netbeans-modules-project-ui-WelcomeScreenHack/" + // NOI18N
103
"org-netbeans-modules-project-ui-NewSample.instance"; // NOI18N
104
private static final String JavaDoc BUNDLE_PROPERTY_PREFIX =
105         "Samples/Blueprints"; // NOI18N
106
private static final String JavaDoc PRESELECT_CATEGORY =
107         "PRESELECT_CATEGORY"; // NOI18N
108
private static final String JavaDoc PRESELECT_TEMPLATE =
109         "PRESELECT_TEMPLATE"; // NOI18N
110

111     
112     public void setScrollPosition(int scrollPosition) {
113         // Ignore - no scroll position for this tab.
114
}
115
116     public int getScrollPosition() {
117         // No scroll position for this tab.
118
return 0;
119     }
120     
121     public void updateTab() {
122         // Nothing to update.
123
// The contents of this panel remain the same regardless of what
124
// article is slected.
125
}
126     
127     private void installExample() {
128         performAction(OPEN_SAMPLE_ACTION, "");
129     }
130
131     private Action JavaDoc findAction (String JavaDoc key) {
132         FileObject fo =
133             Repository.getDefault().getDefaultFileSystem().findResource(key);
134         
135         if (fo != null && fo.isValid()) {
136             try {
137                 DataObject dob = DataObject.find (fo);
138                 InstanceCookie ic =
139                     (InstanceCookie) dob.getCookie(InstanceCookie.class);
140                 
141                 if (ic != null) {
142                     Object JavaDoc instance = ic.instanceCreate();
143                     if (instance instanceof Action JavaDoc) {
144                         return (Action JavaDoc) instance;
145                     }
146                 }
147             } catch (Exception JavaDoc e) {
148                 ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
149                 return null;
150             }
151         }
152         return null;
153     }
154     
155     private boolean performAction(String JavaDoc key, String JavaDoc command) {
156         Action JavaDoc a = findAction (key);
157         if (a == null) {
158             return false;
159         }
160         Nbcategory category = bluePrintsPanel.getSelectedCategory();
161         String JavaDoc categoryId = category.getId();
162         if(category.getShowSpec().equals("true")){ //NOI18N
163
categoryId = category.getSpec() + "/" + categoryId; // NOI18N
164
}
165         a.putValue(PRESELECT_CATEGORY, BUNDLE_PROPERTY_PREFIX + "/" // NOI18N
166
+ categoryId);
167         a.putValue(PRESELECT_TEMPLATE, bluePrintsPanel.getExampleId());
168         
169         ActionEvent JavaDoc ae = new ActionEvent JavaDoc(this, ActionEvent.ACTION_PERFORMED,
170             command);
171         try {
172             a.actionPerformed(ae);
173             return true;
174         } catch (Exception JavaDoc e) {
175             ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
176             return false;
177         }
178     }
179 }
180
Popular Tags