KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > customizer > EarCustomizer


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.earproject.ui.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.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 JavaDoc {
47     
48     private Component JavaDoc currentCustomizer;
49     private GridBagConstraints JavaDoc fillConstraints;
50     private DialogDescriptor dialogDescriptor;
51     
52     /** Creates new form WebCustomizer */
53     public EarCustomizer(EarProjectProperties earProperties, ProjectEar wm) {
54         initComponents();
55         //HelpCtx.setHelpIDString(customizerPanel, "org.netbeans.modules.j2ee.earproject.ui.customizer.EarCustomizer" ); //NOI18N
56
this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EarCustomizer.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(earProperties, 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(EarCustomizer.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(EarCustomizer.class, "ACS_CustomizeTree_A11YName")); //NOI18N
162
btv.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EarCustomizer.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
}
186                 }
187             }
188             
189         }
190         
191         
192         /** Listens to selection change and shows the customizers as
193          * panels
194          */

195         
196         private class ManagerChangeListener implements PropertyChangeListener JavaDoc {
197             
198             public void propertyChange(PropertyChangeEvent JavaDoc 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                         /*
221                         if ( currentCustomizer instanceof javax.swing.JComponent ) {
222                             ((javax.swing.JComponent)currentCustomizer).setPreferredSize( new java.awt.Dimension( 600, 0 ) );
223                         }
224                          */

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                             //EarCustomizer.this.dialogDescriptor.setHelpCtx(null);
231
}
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     // Private methods ---------------------------------------------------------
246

247     private static Node createRootNode(EarProjectProperties earProperties, ProjectEar wm) {
248         String JavaDoc ICON = "org/netbeans/modules/j2ee/earproject/ui/resources/propertyNode.gif"; // NOI18N
249
ResourceBundle JavaDoc bundle = NbBundle.getBundle( EarCustomizer.class );
250         
251         ConfigurationDescription buildDescriptions[] = new ConfigurationDescription[] {
252             new ConfigurationDescription(
253                 "Package", // NOI18N
254
bundle.getString( "LBL_Config_Packaging" ), // NOI18N
255
ICON,
256                 new CustomizerJarContent(earProperties),
257                 null ),
258         };
259         
260         ConfigurationDescription descriptions[] = new ConfigurationDescription[] {
261             new ConfigurationDescription(
262                 "General", // NOI18N
263
bundle.getString( "LBL_Config_Sources" ), // NOI18N
264
ICON,
265                 new CustomizerGeneral(earProperties),
266                 null ),
267             new ConfigurationDescription(
268                 "Libraries", // NOI18N
269
bundle.getString( "LBL_Config_Libraries" ), // NOI18N
270
ICON,
271                 new CustomizerLibraries(earProperties),
272                 null ),
273             new ConfigurationDescription(
274                 "BuildCategory", // NOI18N
275
bundle.getString( "LBL_Category_Build" ), // NOI18N
276
ICON,
277                 createEmptyLabel( null ),
278                 buildDescriptions ),
279             new ConfigurationDescription(
280                 "Run", // NOI18N
281
bundle.getString( "LBL_Category_Run" ), // NOI18N
282
ICON,
283                 new CustomizerRun(earProperties, wm),
284                 null),
285             
286         };
287         
288         ConfigurationDescription rootDescription = new ConfigurationDescription(
289                 "InvisibleRoot", "InvisibleRoot", null, null, descriptions ); // NOI18N
290

291         return new ConfigurationNode( rootDescription );
292     }
293     
294     // Private meyhods ---------------------------------------------------------
295

296     // XXX Remove when all panels have some options
297

298     private static javax.swing.JLabel JavaDoc createEmptyLabel( String JavaDoc text ) {
299         
300         JLabel JavaDoc label;
301         if ( text == null ) {
302             label = new JLabel JavaDoc();
303         } else {
304             label = new JLabel JavaDoc( text );
305             label.setHorizontalAlignment( JLabel.CENTER );
306         }
307         
308         return label;
309     }
310     
311     // Private innerclasses ----------------------------------------------------
312

313     /** Class describing the configuration node. Prototype of the
314      * configuration node.
315      */

316     private static class ConfigurationDescription {
317         
318         private String JavaDoc name;
319         private String JavaDoc displayName;
320         private String JavaDoc iconBase;
321         private Component JavaDoc customizer;
322         private ConfigurationDescription[] children;
323         // XXX Add Node.Properties
324

325         ConfigurationDescription( String JavaDoc name,
326                 String JavaDoc displayName,
327                 String JavaDoc iconBase,
328                 Component JavaDoc 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     /** Node to be used for configuration
342      */

343     private static class ConfigurationNode extends AbstractNode {
344         
345         private final Component JavaDoc 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; // true;
359
}
360         
361         public Component JavaDoc getCustomizer() {
362             return customizer;
363         }
364         
365     }
366     
367     /** Children used for configuration
368      */

369     private static class ConfigurationChildren extends Children.Keys {
370         
371         private final Collection JavaDoc descriptions;
372         
373         public ConfigurationChildren( ConfigurationDescription[] descriptions ) {
374             this.descriptions = Arrays.asList( descriptions );
375         }
376         
377         // Children.Keys impl --------------------------------------------------
378

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 JavaDoc key ) {
388             return new Node[] { new ConfigurationNode( (ConfigurationDescription)key ) };
389         }
390     }
391     
392     public HelpCtx getHelpCtx() {
393         return currentCustomizer instanceof JLabel JavaDoc
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