1 19 20 package org.netbeans.modules.j2ee.archive.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.archive.project.ArchiveProjectProperties; 37 import org.openide.DialogDescriptor; 38 import org.openide.ErrorManager; 39 import org.openide.explorer.ExplorerManager; 40 import org.openide.explorer.view.BeanTreeView; 41 import org.openide.nodes.AbstractNode; 42 import org.openide.nodes.Children; 43 import org.openide.nodes.Node; 44 import org.openide.util.HelpCtx; 45 import org.openide.util.NbBundle; 46 47 public class ArchiveProjectCustomizer extends javax.swing.JPanel { 48 49 private Component currentCustomizer; 50 private GridBagConstraints fillConstraints; 51 private transient DialogDescriptor dialogDescriptor; 52 53 public ArchiveProjectCustomizer(ArchiveProjectProperties apProperties) { initComponents(); 55 HelpCtx.setHelpIDString(customizerPanel, "org.netbeans.modules.j2ee.archive.customizer.ArchiveProjectCustomizer" ); this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ArchiveProjectCustomizer.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(apProperties) ), 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(ArchiveProjectCustomizer.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(ArchiveProjectCustomizer.class, "ACS_CustomizeTree_A11YName")); btv.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ArchiveProjectCustomizer.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 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 186 e); 187 } 188 } 189 } 190 191 } 192 193 194 197 198 private class ManagerChangeListener implements PropertyChangeListener { 199 200 public void propertyChange(PropertyChangeEvent evt) { 201 if(evt.getSource() == manager) { 202 203 if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { 204 Node nodes[] = manager.getSelectedNodes(); 205 if ( nodes != null && nodes.length > 0 ) { 206 Node node = nodes[0]; 207 208 if ( currentCustomizer != null ) { 209 customizerPanel.remove( currentCustomizer ); 210 } 211 if ( node.hasCustomizer() ) { 212 currentCustomizer = node.getCustomizer(); 213 214 if ( currentCustomizer instanceof ArchiveCustomizerPanel ) { 215 ((ArchiveCustomizerPanel)currentCustomizer).initValues(); 216 } 217 218 customizerPanel.add( currentCustomizer, fillConstraints ); 219 customizerPanel.validate(); 220 customizerPanel.repaint(); 221 if (ArchiveProjectCustomizer.this.dialogDescriptor != null ) { 222 ArchiveProjectCustomizer.this.dialogDescriptor.setHelpCtx(ArchiveProjectCustomizer.this.getHelpCtx()); 223 } 224 } else { 225 currentCustomizer = null; 226 if (ArchiveProjectCustomizer.this.dialogDescriptor != null ) { 227 ArchiveProjectCustomizer.this.dialogDescriptor.setHelpCtx(null); 228 } 229 } 230 } 231 } 232 } 233 } 234 } 235 } 236 237 239 private static Node createRootNode(ArchiveProjectProperties apProperties) { 240 String ICON = "org/netbeans/modules/j2ee/earproject/ui/resources/propertyNode.gif"; ResourceBundle bundle = NbBundle.getBundle( ArchiveProjectCustomizer.class ); 242 243 ConfigurationDescription descriptions[] = new ConfigurationDescription[] { 244 new ConfigurationDescription( 245 "Run", bundle.getString( "LBL_Category_Run" ), ICON, 248 new CustomizerRun(apProperties), 249 null), 250 251 }; 252 253 ConfigurationDescription rootDescription = new ConfigurationDescription( 254 "InvisibleRoot", "InvisibleRoot", null, null, descriptions ); 256 return new ConfigurationNode( rootDescription ); 257 } 258 259 261 276 278 281 private static class ConfigurationDescription { 282 283 private String name; 284 private String displayName; 285 private String iconBase; 286 private Component customizer; 287 private ConfigurationDescription[] children; 288 290 ConfigurationDescription( String name, 291 String displayName, 292 String iconBase, 293 Component customizer, 294 ConfigurationDescription[] children ) { 295 296 this.name = name; 297 this.displayName = displayName; 298 this.iconBase = iconBase; 299 this.customizer = customizer; 300 this.children = children; 301 } 302 303 } 304 305 306 308 private static class ConfigurationNode extends AbstractNode { 309 310 private final Component customizer; 311 312 public ConfigurationNode( ConfigurationDescription description ) { 313 super( description.children == null ? Children.LEAF : new ConfigurationChildren( description.children ) ); 314 setName( description.name ); 315 setDisplayName( description.displayName ); 316 if ( description.iconBase != null ) { 317 setIconBaseWithExtension( description.iconBase ); 318 } 319 this.customizer = description.customizer; 320 } 321 322 public boolean hasCustomizer() { 323 return this.customizer != null; } 325 326 public Component getCustomizer() { 327 return customizer; 328 } 329 330 } 331 332 334 private static class ConfigurationChildren extends Children.Keys { 335 336 private final Collection descriptions; 337 338 public ConfigurationChildren( ConfigurationDescription[] descriptions ) { 339 this.descriptions = Arrays.asList( descriptions ); 340 } 341 342 344 public void addNotify() { 345 setKeys( descriptions ); 346 } 347 348 public void removeNotify() { 349 setKeys( Collections.EMPTY_LIST ); 350 } 351 352 protected Node[] createNodes( Object key ) { 353 return new Node[] { new ConfigurationNode( (ConfigurationDescription)key ) }; 354 } 355 } 356 357 public HelpCtx getHelpCtx() { 358 return currentCustomizer instanceof JLabel 359 ? null : HelpCtx.findHelp(currentCustomizer); 360 } 361 362 public void setDialogDescriptor( DialogDescriptor dialogDescriptor ) { 363 this.dialogDescriptor = dialogDescriptor; 364 if (null != dialogDescriptor) { 365 dialogDescriptor.setHelpCtx(getHelpCtx()); 366 } 367 } 368 369 } 370 | Popular Tags |