1 19 20 package org.netbeans.modules.j2ee.blueprints.ui; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.Action ; 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 38 public class ExampleTab 39 extends BluePrintsTabPanel 40 { 41 42 public ExampleTab(BluePrintsPanel bluePrintsPanel) { 43 super(bluePrintsPanel); 44 initComponents(); 45 } 46 47 52 private void initComponents() { 54 java.awt.GridBagConstraints gridBagConstraints; 55 56 launchExampleText = new javax.swing.JTextPane (); 57 installBtn = new javax.swing.JButton (); 58 59 setLayout(new java.awt.GridBagLayout ()); 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 (12, 12, 12, 12)); 65 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 () { 75 public void actionPerformed(java.awt.event.ActionEvent evt) { 76 installBtnActionPerformed(evt); 77 } 78 }); 79 80 gridBagConstraints = new java.awt.GridBagConstraints (); 81 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 82 gridBagConstraints.weighty = 1.0; 83 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 84 add(installBtn, gridBagConstraints); 85 86 } 87 89 private void installBtnActionPerformed(java.awt.event.ActionEvent evt) { installExample(); 91 } 93 94 private javax.swing.JButton installBtn; 96 private javax.swing.JTextPane launchExampleText; 97 99 private static final String OPEN_SAMPLE_ACTION = 102 "org-netbeans-modules-project-ui-WelcomeScreenHack/" + "org-netbeans-modules-project-ui-NewSample.instance"; private static final String BUNDLE_PROPERTY_PREFIX = 105 "Samples/Blueprints"; private static final String PRESELECT_CATEGORY = 107 "PRESELECT_CATEGORY"; private static final String PRESELECT_TEMPLATE = 109 "PRESELECT_TEMPLATE"; 111 112 public void setScrollPosition(int scrollPosition) { 113 } 115 116 public int getScrollPosition() { 117 return 0; 119 } 120 121 public void updateTab() { 122 } 126 127 private void installExample() { 128 performAction(OPEN_SAMPLE_ACTION, ""); 129 } 130 131 private Action findAction (String 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 instance = ic.instanceCreate(); 143 if (instance instanceof Action ) { 144 return (Action ) instance; 145 } 146 } 147 } catch (Exception e) { 148 ErrorManager.getDefault().notify(ErrorManager.WARNING, e); 149 return null; 150 } 151 } 152 return null; 153 } 154 155 private boolean performAction(String key, String command) { 156 Action a = findAction (key); 157 if (a == null) { 158 return false; 159 } 160 Nbcategory category = bluePrintsPanel.getSelectedCategory(); 161 String categoryId = category.getId(); 162 if(category.getShowSpec().equals("true")){ categoryId = category.getSpec() + "/" + categoryId; } 165 a.putValue(PRESELECT_CATEGORY, BUNDLE_PROPERTY_PREFIX + "/" + categoryId); 167 a.putValue(PRESELECT_TEMPLATE, bluePrintsPanel.getExampleId()); 168 169 ActionEvent ae = new ActionEvent (this, ActionEvent.ACTION_PERFORMED, 170 command); 171 try { 172 a.actionPerformed(ae); 173 return true; 174 } catch (Exception e) { 175 ErrorManager.getDefault().notify(ErrorManager.WARNING, e); 176 return false; 177 } 178 } 179 } 180 | Popular Tags |