001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.compapp.projects.jbi.ui.customizer;
043:
044: import java.awt.BorderLayout;
045: import java.awt.Component;
046: import java.awt.Dimension;
047: import java.awt.GridBagConstraints;
048: import java.beans.PropertyChangeEvent;
049: import java.beans.PropertyChangeListener;
050: import java.beans.PropertyVetoException;
051: import java.util.Arrays;
052: import java.util.Collection;
053: import java.util.Collections;
054: import java.util.ResourceBundle;
055:
056: import javax.swing.JLabel;
057: import javax.swing.JPanel;
058: import javax.swing.tree.TreeSelectionModel;
059:
060: import org.openide.explorer.ExplorerManager;
061: import org.openide.explorer.view.BeanTreeView;
062: import org.openide.DialogDescriptor;
063: import org.openide.nodes.AbstractNode;
064: import org.openide.nodes.Children;
065: import org.openide.nodes.Node;
066: import org.openide.util.HelpCtx;
067: import org.openide.util.NbBundle;
068:
069: public class JbiJarCustomizer extends javax.swing.JPanel {
070:
071: private Component currentCustomizer;
072:
073: private GridBagConstraints fillConstraints;
074:
075: private JbiProjectProperties webProperties;
076:
077: private DialogDescriptor dialogDescriptor;
078:
079: /** Creates new form WebCustomizer */
080: public JbiJarCustomizer(JbiProjectProperties webProperties) {
081: initComponents();
082: this .getAccessibleContext().setAccessibleDescription(
083: NbBundle.getMessage(JbiJarCustomizer.class,
084: "ACS_Customize_A11YDesc")); // NOI18N
085:
086: this .webProperties = webProperties;
087: //this.wm = wm;
088:
089: fillConstraints = new GridBagConstraints();
090: fillConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
091: fillConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
092: fillConstraints.fill = java.awt.GridBagConstraints.BOTH;
093: fillConstraints.weightx = 1.0;
094: fillConstraints.weighty = 1.0;
095:
096: categoryPanel.add(new CategoryView(
097: createRootNode(webProperties)), fillConstraints);
098: }
099:
100: /** This method is called from within the constructor to
101: * initialize the form.
102: * WARNING: Do NOT modify this code. The content of this method is
103: * always regenerated by the Form Editor.
104: */
105: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
106: private void initComponents() {
107: java.awt.GridBagConstraints gridBagConstraints;
108:
109: categoryPanel = new javax.swing.JPanel();
110: customizerPanel = new javax.swing.JPanel();
111:
112: setLayout(new java.awt.GridBagLayout());
113:
114: setPreferredSize(new java.awt.Dimension(750, 450));
115: categoryPanel.setLayout(new java.awt.GridBagLayout());
116:
117: categoryPanel.setBorder(javax.swing.BorderFactory
118: .createEtchedBorder());
119: categoryPanel.setMinimumSize(new java.awt.Dimension(220, 4));
120: categoryPanel.setPreferredSize(new java.awt.Dimension(220, 4));
121: gridBagConstraints = new java.awt.GridBagConstraints();
122: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
123: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
124: gridBagConstraints.weighty = 1.0;
125: gridBagConstraints.insets = new java.awt.Insets(8, 8, 8, 8);
126: add(categoryPanel, gridBagConstraints);
127:
128: customizerPanel.setLayout(new java.awt.GridBagLayout());
129:
130: gridBagConstraints = new java.awt.GridBagConstraints();
131: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
132: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
133: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
134: gridBagConstraints.weightx = 1.0;
135: gridBagConstraints.weighty = 1.0;
136: gridBagConstraints.insets = new java.awt.Insets(8, 4, 8, 8);
137: add(customizerPanel, gridBagConstraints);
138:
139: }// </editor-fold>//GEN-END:initComponents
140:
141: // Variables declaration - do not modify//GEN-BEGIN:variables
142: private javax.swing.JPanel categoryPanel;
143: private javax.swing.JPanel customizerPanel;
144:
145: // End of variables declaration//GEN-END:variables
146:
147: // Private innerclasses ----------------------------------------------------
148:
149: private class CategoryView extends JPanel implements
150: ExplorerManager.Provider {
151:
152: private ExplorerManager manager;
153: private BeanTreeView btv;
154:
155: CategoryView(Node rootNode) {
156:
157: // See #36315
158: manager = new ExplorerManager();
159:
160: setLayout(new BorderLayout());
161:
162: Dimension size = new Dimension(220, 4);
163: btv = new BeanTreeView(); // Add the BeanTreeView
164: btv
165: .setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
166: btv.setPopupAllowed(false);
167: btv.setRootVisible(false);
168: btv.setDefaultActionAllowed(false);
169: btv.setMinimumSize(size);
170: btv.setPreferredSize(size);
171: btv.setMaximumSize(size);
172: this .add(btv, BorderLayout.CENTER);
173: manager.setRootContext(rootNode);
174: manager
175: .addPropertyChangeListener(new ManagerChangeListener());
176: selectFirstNode();
177: btv.expandAll();
178:
179: btv.getAccessibleContext().setAccessibleName(
180: NbBundle.getMessage(JbiJarCustomizer.class,
181: "ACS_CustomizeTree_A11YName")); // NOI18N
182: btv.getAccessibleContext().setAccessibleDescription(
183: NbBundle.getMessage(JbiJarCustomizer.class,
184: "ACS_CustomizeTree_A11YDesc")); // NOI18N
185: }
186:
187: public ExplorerManager getExplorerManager() {
188: return manager;
189: }
190:
191: public void addNotify() {
192: super .addNotify();
193: btv.expandAll();
194: }
195:
196: private void selectFirstNode() {
197:
198: Children ch = manager.getRootContext().getChildren();
199: if (ch != null) {
200: Node nodes[] = ch.getNodes();
201:
202: if (nodes != null && nodes.length > 0) {
203: try {
204: manager
205: .setSelectedNodes(new Node[] { nodes[0] });
206: } catch (PropertyVetoException e) {
207: // No node will be selected
208: }
209: }
210: }
211:
212: }
213:
214: /** Listens to selection change and shows the customizers as
215: * panels
216: */
217:
218: private class ManagerChangeListener implements
219: PropertyChangeListener {
220:
221: public void propertyChange(PropertyChangeEvent evt) {
222: if (evt.getSource() != manager) {
223: return;
224: }
225:
226: if (ExplorerManager.PROP_SELECTED_NODES.equals(evt
227: .getPropertyName())) {
228: Node nodes[] = manager.getSelectedNodes();
229: if (nodes == null || nodes.length <= 0) {
230: return;
231: }
232: Node node = nodes[0];
233:
234: if (currentCustomizer != null) {
235: customizerPanel.remove(currentCustomizer);
236: }
237: if (node.hasCustomizer()) {
238: currentCustomizer = node.getCustomizer();
239:
240: if (currentCustomizer instanceof Panel) {
241: ((Panel) currentCustomizer).initValues();
242: }
243:
244: /*
245: if ( currentCustomizer instanceof javax.swing.JComponent ) {
246: ((javax.swing.JComponent)currentCustomizer).setPreferredSize( new java.awt.Dimension( 600, 0 ) );
247: }
248: */
249: customizerPanel.add(currentCustomizer,
250: fillConstraints);
251: customizerPanel.validate();
252: customizerPanel.repaint();
253: if (JbiJarCustomizer.this .dialogDescriptor != null) {
254: JbiJarCustomizer.this .dialogDescriptor
255: .setHelpCtx(JbiJarCustomizer.this
256: .getHelpCtx());
257: }
258: } else {
259: currentCustomizer = null;
260: if (JbiJarCustomizer.this .dialogDescriptor != null) {
261: JbiJarCustomizer.this .dialogDescriptor
262: .setHelpCtx(null);
263: }
264: }
265:
266: return;
267: }
268: }
269: }
270: }
271:
272: // Private methods ---------------------------------------------------------
273:
274: private static Node createRootNode(
275: JbiProjectProperties webProperties) {
276: String ICON_FOLDER = "org/netbeans/modules/compapp/projects/jbi/ui/resources/";
277: ResourceBundle bundle = NbBundle
278: .getBundle(JbiJarCustomizer.class);
279:
280: ConfigurationDescription buildDescriptions[] = new ConfigurationDescription[] { new ConfigurationDescription(
281: "Build",
282: bundle.getString("LBL_Config_Package_Project"), // NOI18N
283: ICON_FOLDER + "defaultCategory", // "build", // NOI18N
284: new CustomizerJarContent(webProperties), null), };
285: //=======Start of JBI ==============================================//
286: ConfigurationDescription runDescriptions[] = new ConfigurationDescription[] { new ConfigurationDescription(
287: "Run", bundle.getString("LBL_Config_Run_Project"), // NOI18N
288: ICON_FOLDER + "defaultCategory", // "run", // NOI18N
289: new CustomizerRun(webProperties), null), };
290: //=======End of JBI ================================================//
291:
292: ConfigurationDescription descriptions[] = new ConfigurationDescription[] {
293: new ConfigurationDescription("General", bundle
294: .getString("LBL_Config_General"), // NOI18N
295: ICON_FOLDER + "defaultCategory", // "jbiProjectIcon", // NOI18N
296: new CustomizerGeneral(webProperties), null),
297: new ConfigurationDescription("BuildCategoty", bundle
298: .getString("LBL_Config_Build"), // NOI18N
299: ICON_FOLDER + "defaultCategory", // "general", // NOI18N
300: createEmptyLabel(null), buildDescriptions),
301: //=======Start of JBI ==========================================//
302: new ConfigurationDescription("RunCategoty", bundle
303: .getString("LBL_Config_Run"), // NOI18N
304: ICON_FOLDER + "defaultCategory", // "run", // NOI18N
305: createEmptyLabel(null), runDescriptions)
306: //=======End of JBI ============================================//
307: };
308:
309: ConfigurationDescription rootDescription = new ConfigurationDescription(
310: "InvisibleRoot", "InvisibleRoot", null, null,
311: descriptions); // NOI18N
312:
313: return new ConfigurationNode(rootDescription);
314:
315: }
316:
317: // Private meyhods ---------------------------------------------------------
318:
319: // XXX Remove when all panels have some options
320:
321: private static javax.swing.JLabel createEmptyLabel(String text) {
322:
323: JLabel label;
324: if (text == null) {
325: label = new JLabel();
326: } else {
327: label = new JLabel(text);
328: label.setHorizontalAlignment(JLabel.CENTER);
329: }
330:
331: return label;
332: }
333:
334: // Private innerclasses ----------------------------------------------------
335:
336: /** Class describing the configuration node. Prototype of the
337: * configuration node.
338: */
339: private static class ConfigurationDescription {
340:
341: private String name;
342: private String displayName;
343: private String iconBase;
344: private Component customizer;
345: private ConfigurationDescription[] children;
346:
347: // XXX Add Node.Properties
348:
349: ConfigurationDescription(String name, String displayName,
350: String iconBase, Component customizer,
351: ConfigurationDescription[] children) {
352:
353: this .name = name;
354: this .displayName = displayName;
355: this .iconBase = iconBase;
356: this .customizer = customizer;
357: this .children = children;
358: }
359:
360: }
361:
362: /** Node to be used for configuration
363: */
364: private static class ConfigurationNode extends AbstractNode {
365:
366: private Component customizer;
367:
368: public ConfigurationNode(ConfigurationDescription description) {
369: super (description.children == null ? Children.LEAF
370: : new ConfigurationChildren(description.children));
371: setName(description.name);
372: setDisplayName(description.displayName);
373: if (description.iconBase != null) {
374: setIconBase(description.iconBase);
375: }
376: this .customizer = description.customizer;
377: }
378:
379: public boolean hasCustomizer() {
380: return true;
381: }
382:
383: public Component getCustomizer() {
384: return customizer;
385: }
386:
387: }
388:
389: /** Children used for configuration
390: */
391: private static class ConfigurationChildren extends Children.Keys {
392:
393: private Collection descriptions;
394:
395: public ConfigurationChildren(
396: ConfigurationDescription[] descriptions) {
397: this .descriptions = Arrays.asList(descriptions);
398: }
399:
400: // Children.Keys impl --------------------------------------------------
401:
402: public void addNotify() {
403: setKeys(descriptions);
404: }
405:
406: public void removeNotify() {
407: setKeys(Collections.EMPTY_LIST);
408: }
409:
410: protected Node[] createNodes(Object key) {
411: return new Node[] { new ConfigurationNode(
412: (ConfigurationDescription) key) };
413: }
414: }
415:
416: static interface Panel {
417:
418: public void initValues();
419:
420: }
421:
422: public HelpCtx getHelpCtx() {
423: return currentCustomizer instanceof JLabel ? null : HelpCtx
424: .findHelp(currentCustomizer);
425: }
426:
427: public void setDialogDescriptor(DialogDescriptor dialogDescriptor) {
428: this.dialogDescriptor = dialogDescriptor;
429: if (null != dialogDescriptor) {
430: dialogDescriptor.setHelpCtx(getHelpCtx());
431: }
432: }
433: }
|