1 19 20 package org.netbeans.modules.j2ee.earproject.ui.customizer; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Component ; 24 import java.awt.Dimension ; 25 import java.awt.GridBagConstraints ; 26 import java.beans.PropertyChangeEvent ; 27 import java.beans.PropertyChangeListener ; 28 import java.beans.PropertyVetoException ; 29 import java.util.Arrays ; 30 import java.util.Collection ; 31 import java.util.Collections ; 32 import java.util.ResourceBundle ; 33 import javax.swing.JLabel ; 34 import javax.swing.JPanel ; 35 import javax.swing.tree.TreeSelectionModel ; 36 import org.netbeans.modules.j2ee.earproject.ProjectEar; 37 import org.openide.DialogDescriptor; 38 import org.openide.explorer.ExplorerManager; 39 import org.openide.explorer.view.BeanTreeView; 40 import org.openide.nodes.AbstractNode; 41 import org.openide.nodes.Children; 42 import org.openide.nodes.Node; 43 import org.openide.util.HelpCtx; 44 import org.openide.util.NbBundle; 45 46 public class EarCustomizer extends javax.swing.JPanel { 47 48 private Component currentCustomizer; 49 private GridBagConstraints fillConstraints; 50 private DialogDescriptor dialogDescriptor; 51 52 53 public EarCustomizer(EarProjectProperties earProperties, ProjectEar wm) { 54 initComponents(); 55 this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EarCustomizer.class, "ACS_Customize_A11YDesc")); 58 fillConstraints = new GridBagConstraints (); 59 fillConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 60 fillConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 61 fillConstraints.fill = java.awt.GridBagConstraints.BOTH; 62 fillConstraints.weightx = 1.0; 63 fillConstraints.weighty = 1.0; 64 fillConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; 65 66 categoryPanel.add( new CategoryView( createRootNode(earProperties, wm) ), fillConstraints ); 67 } 68 69 74 private void initComponents() { 76 java.awt.GridBagConstraints gridBagConstraints; 77 78 categoryPanel = new javax.swing.JPanel (); 79 customizerPanel = new javax.swing.JPanel (); 80 jLabel1 = new javax.swing.JLabel (); 81 82 setLayout(new java.awt.GridBagLayout ()); 83 84 setPreferredSize(new java.awt.Dimension (750, 450)); 85 categoryPanel.setLayout(new java.awt.GridBagLayout ()); 86 87 categoryPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 88 categoryPanel.setMinimumSize(new java.awt.Dimension (220, 4)); 89 categoryPanel.setPreferredSize(new java.awt.Dimension (220, 4)); 90 gridBagConstraints = new java.awt.GridBagConstraints (); 91 gridBagConstraints.gridx = 0; 92 gridBagConstraints.gridy = 1; 93 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 94 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 95 gridBagConstraints.weighty = 1.0; 96 gridBagConstraints.insets = new java.awt.Insets (0, 8, 8, 4); 97 add(categoryPanel, gridBagConstraints); 98 99 customizerPanel.setLayout(new javax.swing.BoxLayout (customizerPanel, javax.swing.BoxLayout.Y_AXIS)); 100 101 gridBagConstraints = new java.awt.GridBagConstraints (); 102 gridBagConstraints.gridx = 1; 103 gridBagConstraints.gridy = 1; 104 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 105 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 106 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 107 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 108 gridBagConstraints.weightx = 1.0; 109 gridBagConstraints.weighty = 1.0; 110 gridBagConstraints.insets = new java.awt.Insets (0, 4, 8, 8); 111 add(customizerPanel, gridBagConstraints); 112 113 jLabel1.setLabelFor(categoryPanel); 114 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getBundle(EarCustomizer.class).getString("LBL_Categories")); 115 gridBagConstraints = new java.awt.GridBagConstraints (); 116 gridBagConstraints.gridx = 0; 117 gridBagConstraints.gridy = 0; 118 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 119 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 120 gridBagConstraints.insets = new java.awt.Insets (8, 8, 0, 4); 121 add(jLabel1, gridBagConstraints); 122 123 } 125 126 private javax.swing.JPanel categoryPanel; 128 private javax.swing.JPanel customizerPanel; 129 private javax.swing.JLabel jLabel1; 130 132 134 private class CategoryView extends JPanel implements ExplorerManager.Provider { 135 136 private final ExplorerManager manager; 137 private final BeanTreeView btv; 138 139 CategoryView( Node rootNode ) { 140 141 manager = new ExplorerManager(); 143 144 setLayout( new BorderLayout () ); 145 146 Dimension size = new Dimension ( 220, 4 ); 147 btv = new BeanTreeView(); btv.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); 149 btv.setPopupAllowed( false ); 150 btv.setRootVisible( false ); 151 btv.setDefaultActionAllowed( false ); 152 btv.setMinimumSize( size ); 153 btv.setPreferredSize( size ); 154 btv.setMaximumSize( size ); 155 this.add( btv, BorderLayout.CENTER ); 156 manager.setRootContext( rootNode ); 157 manager.addPropertyChangeListener( new ManagerChangeListener() ); 158 selectFirstNode(); 159 btv.expandAll(); 160 161 btv.getAccessibleContext().setAccessibleName(NbBundle.getMessage(EarCustomizer.class, "ACS_CustomizeTree_A11YName")); btv.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EarCustomizer.class, "ACS_CustomizeTree_A11YDesc")); } 164 165 public ExplorerManager getExplorerManager() { 166 return manager; 167 } 168 169 public void addNotify() { 170 super.addNotify(); 171 btv.expandAll(); 172 } 173 174 private void selectFirstNode() { 175 176 Children ch = manager.getRootContext().getChildren(); 177 if ( ch != null ) { 178 Node nodes[] = ch.getNodes(); 179 180 if ( nodes != null && nodes.length > 0 ) { 181 try { 182 manager.setSelectedNodes( new Node[] { nodes[0] } ); 183 } catch ( PropertyVetoException e ) { 184 } 186 } 187 } 188 189 } 190 191 192 195 196 private class ManagerChangeListener implements PropertyChangeListener { 197 198 public void propertyChange(PropertyChangeEvent evt) { 199 if(evt.getSource() != manager) { 200 return; 201 } 202 203 if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { 204 Node nodes[] = manager.getSelectedNodes(); 205 if ( nodes == null || nodes.length <= 0 ) { 206 return; 207 } 208 Node node = nodes[0]; 209 210 if ( currentCustomizer != null ) { 211 customizerPanel.remove( currentCustomizer ); 212 } 213 if ( node.hasCustomizer() ) { 214 currentCustomizer = node.getCustomizer(); 215 216 if ( currentCustomizer instanceof ArchiveCustomizerPanel ) { 217 ((ArchiveCustomizerPanel)currentCustomizer).initValues(); 218 } 219 220 225 customizerPanel.add( currentCustomizer, fillConstraints ); 226 customizerPanel.validate(); 227 customizerPanel.repaint(); 228 if (EarCustomizer.this.dialogDescriptor != null ) { 229 EarCustomizer.this.dialogDescriptor.setHelpCtx(EarCustomizer.this.getHelpCtx()); 230 } 232 } else { 233 currentCustomizer = null; 234 if (EarCustomizer.this.dialogDescriptor != null ) { 235 EarCustomizer.this.dialogDescriptor.setHelpCtx(null); 236 } 237 } 238 239 return; 240 } 241 } 242 } 243 } 244 245 247 private static Node createRootNode(EarProjectProperties earProperties, ProjectEar wm) { 248 String ICON = "org/netbeans/modules/j2ee/earproject/ui/resources/propertyNode.gif"; ResourceBundle bundle = NbBundle.getBundle( EarCustomizer.class ); 250 251 ConfigurationDescription buildDescriptions[] = new ConfigurationDescription[] { 252 new ConfigurationDescription( 253 "Package", bundle.getString( "LBL_Config_Packaging" ), ICON, 256 new CustomizerJarContent(earProperties), 257 null ), 258 }; 259 260 ConfigurationDescription descriptions[] = new ConfigurationDescription[] { 261 new ConfigurationDescription( 262 "General", bundle.getString( "LBL_Config_Sources" ), ICON, 265 new CustomizerGeneral(earProperties), 266 null ), 267 new ConfigurationDescription( 268 "Libraries", bundle.getString( "LBL_Config_Libraries" ), ICON, 271 new CustomizerLibraries(earProperties), 272 null ), 273 new ConfigurationDescription( 274 "BuildCategory", bundle.getString( "LBL_Category_Build" ), ICON, 277 createEmptyLabel( null ), 278 buildDescriptions ), 279 new ConfigurationDescription( 280 "Run", bundle.getString( "LBL_Category_Run" ), ICON, 283 new CustomizerRun(earProperties, wm), 284 null), 285 286 }; 287 288 ConfigurationDescription rootDescription = new ConfigurationDescription( 289 "InvisibleRoot", "InvisibleRoot", null, null, descriptions ); 291 return new ConfigurationNode( rootDescription ); 292 } 293 294 296 298 private static javax.swing.JLabel createEmptyLabel( String text ) { 299 300 JLabel label; 301 if ( text == null ) { 302 label = new JLabel (); 303 } else { 304 label = new JLabel ( text ); 305 label.setHorizontalAlignment( JLabel.CENTER ); 306 } 307 308 return label; 309 } 310 311 313 316 private static class ConfigurationDescription { 317 318 private String name; 319 private String displayName; 320 private String iconBase; 321 private Component customizer; 322 private ConfigurationDescription[] children; 323 325 ConfigurationDescription( String name, 326 String displayName, 327 String iconBase, 328 Component customizer, 329 ConfigurationDescription[] children ) { 330 331 this.name = name; 332 this.displayName = displayName; 333 this.iconBase = iconBase; 334 this.customizer = customizer; 335 this.children = children; 336 } 337 338 } 339 340 341 343 private static class ConfigurationNode extends AbstractNode { 344 345 private final Component customizer; 346 347 public ConfigurationNode( ConfigurationDescription description ) { 348 super( description.children == null ? Children.LEAF : new ConfigurationChildren( description.children ) ); 349 setName( description.name ); 350 setDisplayName( description.displayName ); 351 if ( description.iconBase != null ) { 352 setIconBaseWithExtension( description.iconBase ); 353 } 354 this.customizer = description.customizer; 355 } 356 357 public boolean hasCustomizer() { 358 return this.customizer != null; } 360 361 public Component getCustomizer() { 362 return customizer; 363 } 364 365 } 366 367 369 private static class ConfigurationChildren extends Children.Keys { 370 371 private final Collection descriptions; 372 373 public ConfigurationChildren( ConfigurationDescription[] descriptions ) { 374 this.descriptions = Arrays.asList( descriptions ); 375 } 376 377 379 public void addNotify() { 380 setKeys( descriptions ); 381 } 382 383 public void removeNotify() { 384 setKeys( Collections.EMPTY_LIST ); 385 } 386 387 protected Node[] createNodes( Object key ) { 388 return new Node[] { new ConfigurationNode( (ConfigurationDescription)key ) }; 389 } 390 } 391 392 public HelpCtx getHelpCtx() { 393 return currentCustomizer instanceof JLabel 394 ? null : HelpCtx.findHelp(currentCustomizer); 395 } 396 397 public void setDialogDescriptor( DialogDescriptor dialogDescriptor ) { 398 this.dialogDescriptor = dialogDescriptor; 399 if (null != dialogDescriptor) { 400 dialogDescriptor.setHelpCtx(getHelpCtx()); 401 } 402 } 403 404 } 405 | Popular Tags |