KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > archive > customizer > ArchiveProjectCustomizer


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.archive.customizer;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.GridBagConstraints JavaDoc;
26 import java.beans.PropertyChangeEvent JavaDoc;
27 import java.beans.PropertyChangeListener JavaDoc;
28 import java.beans.PropertyVetoException JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.Collections JavaDoc;
32 import java.util.ResourceBundle JavaDoc;
33 import javax.swing.JLabel JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35 import javax.swing.tree.TreeSelectionModel JavaDoc;
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 JavaDoc {
48     
49     private Component JavaDoc currentCustomizer;
50     private GridBagConstraints JavaDoc fillConstraints;
51     private transient DialogDescriptor dialogDescriptor;
52     
53     public ArchiveProjectCustomizer(ArchiveProjectProperties apProperties) { // , ProjectEar wm) {
54
initComponents();
55         HelpCtx.setHelpIDString(customizerPanel, "org.netbeans.modules.j2ee.archive.customizer.ArchiveProjectCustomizer" ); //NOI18N
56
this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ArchiveProjectCustomizer.class, "ACS_Customize_A11YDesc")); //NOI18N
57

58         fillConstraints = new GridBagConstraints JavaDoc();
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)/*, wm)*/ ), fillConstraints );
67     }
68     
69     /** This method is called from within the constructor to
70      * initialize the form.
71      * WARNING: Do NOT modify this code. The content of this method is
72      * always regenerated by the Form Editor.
73      */

74     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
75
private void initComponents() {
76         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
77
78         categoryPanel = new javax.swing.JPanel JavaDoc();
79         customizerPanel = new javax.swing.JPanel JavaDoc();
80         jLabel1 = new javax.swing.JLabel JavaDoc();
81
82         setLayout(new java.awt.GridBagLayout JavaDoc());
83
84         setPreferredSize(new java.awt.Dimension JavaDoc(750, 450));
85         categoryPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
86
87         categoryPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
88         categoryPanel.setMinimumSize(new java.awt.Dimension JavaDoc(220, 4));
89         categoryPanel.setPreferredSize(new java.awt.Dimension JavaDoc(220, 4));
90         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 8, 8, 4);
97         add(categoryPanel, gridBagConstraints);
98
99         customizerPanel.setLayout(new javax.swing.BoxLayout JavaDoc(customizerPanel, javax.swing.BoxLayout.Y_AXIS));
100
101         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc();
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 JavaDoc(8, 8, 0, 4);
121         add(jLabel1, gridBagConstraints);
122
123     }// </editor-fold>//GEN-END:initComponents
124

125     
126     // Variables declaration - do not modify//GEN-BEGIN:variables
127
private javax.swing.JPanel JavaDoc categoryPanel;
128     private javax.swing.JPanel JavaDoc customizerPanel;
129     private javax.swing.JLabel JavaDoc jLabel1;
130     // End of variables declaration//GEN-END:variables
131

132     // Private innerclasses ----------------------------------------------------
133

134     private class CategoryView extends JPanel JavaDoc implements ExplorerManager.Provider {
135         
136         private final ExplorerManager manager;
137         private final BeanTreeView btv;
138         
139         CategoryView( Node rootNode ) {
140             
141             // See #36315
142
manager = new ExplorerManager();
143             
144             setLayout( new BorderLayout JavaDoc() );
145             
146             Dimension JavaDoc size = new Dimension JavaDoc( 220, 4 );
147             btv = new BeanTreeView(); // Add the BeanTreeView
148
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")); //NOI18N
162
btv.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ArchiveProjectCustomizer.class, "ACS_CustomizeTree_A11YDesc")); //NOI18N
163
}
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 JavaDoc e ) {
184                         // No node will be selected
185
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
186                                 e);
187                     }
188                 }
189             }
190             
191         }
192         
193         
194         /** Listens to selection change and shows the customizers as
195          * panels
196          */

197         
198         private class ManagerChangeListener implements PropertyChangeListener JavaDoc {
199             
200             public void propertyChange(PropertyChangeEvent JavaDoc 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     // Private methods ---------------------------------------------------------
238

239     private static Node createRootNode(ArchiveProjectProperties apProperties) {
240         String JavaDoc ICON = "org/netbeans/modules/j2ee/earproject/ui/resources/propertyNode.gif"; // NOI18N
241
ResourceBundle JavaDoc bundle = NbBundle.getBundle( ArchiveProjectCustomizer.class );
242         
243         ConfigurationDescription descriptions[] = new ConfigurationDescription[] {
244             new ConfigurationDescription(
245                 "Run", // NOI18N
246
bundle.getString( "LBL_Category_Run" ), // NOI18N
247
ICON,
248                 new CustomizerRun(apProperties),
249                 null),
250             
251         };
252         
253         ConfigurationDescription rootDescription = new ConfigurationDescription(
254                 "InvisibleRoot", "InvisibleRoot", null, null, descriptions ); // NOI18N
255

256         return new ConfigurationNode( rootDescription );
257     }
258     
259     // Private meyhods ---------------------------------------------------------
260

261 // // XXX Remove when all panels have some options
262
//
263
// private static javax.swing.JLabel createEmptyLabel( String text ) {
264
//
265
// JLabel label;
266
// if ( text == null ) {
267
// label = new JLabel();
268
// } else {
269
// label = new JLabel( text );
270
// label.setHorizontalAlignment( JLabel.CENTER );
271
// }
272
//
273
// return label;
274
// }
275

276     // Private innerclasses ----------------------------------------------------
277

278     /** Class describing the configuration node. Prototype of the
279      * configuration node.
280      */

281     private static class ConfigurationDescription {
282         
283         private String JavaDoc name;
284         private String JavaDoc displayName;
285         private String JavaDoc iconBase;
286         private Component JavaDoc customizer;
287         private ConfigurationDescription[] children;
288         // XXX Add Node.Properties
289

290         ConfigurationDescription( String JavaDoc name,
291                 String JavaDoc displayName,
292                 String JavaDoc iconBase,
293                 Component JavaDoc 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     /** Node to be used for configuration
307      */

308     private static class ConfigurationNode extends AbstractNode {
309         
310         private final Component JavaDoc 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; // true;
324
}
325         
326         public Component JavaDoc getCustomizer() {
327             return customizer;
328         }
329                 
330     }
331     
332     /** Children used for configuration
333      */

334     private static class ConfigurationChildren extends Children.Keys {
335         
336         private final Collection JavaDoc descriptions;
337         
338         public ConfigurationChildren( ConfigurationDescription[] descriptions ) {
339             this.descriptions = Arrays.asList( descriptions );
340         }
341         
342         // Children.Keys impl --------------------------------------------------
343

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 JavaDoc key ) {
353             return new Node[] { new ConfigurationNode( (ConfigurationDescription)key ) };
354         }
355     }
356     
357     public HelpCtx getHelpCtx() {
358         return currentCustomizer instanceof JLabel JavaDoc
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