This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 49647
Collapse All | Expand All

(-)projectuiapi/src/org/netbeans/modules/project/uiapi/CategoryModel.java (+112 lines)
Line 0 Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.project.uiapi;
15
16
import java.beans.PropertyChangeListener;
17
import java.beans.PropertyChangeSupport;
18
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
19
20
21
/** Maintains current category in the customizer.
22
 *
23
 * @author Petr Hrebejk
24
 */
25
public class CategoryModel {
26
    
27
    public static final String PROP_CURRENT_CATEGORY = "propCurrentCategory";
28
    
29
    private ProjectCustomizer.Category[] categories;
30
    
31
    private ProjectCustomizer.Category currentCategory;
32
    
33
    // Might be vetoable later
34
    private PropertyChangeSupport pcs;
35
    
36
    public CategoryModel( ProjectCustomizer.Category[] categories ) {
37
        
38
        if ( categories == null || categories.length == 0 ) {
39
            throw new IllegalArgumentException( "Must provide at least one category" ); // NOI18N
40
        }
41
        
42
        this.categories = categories;
43
        this.currentCategory = categories[0];
44
        this.pcs = new PropertyChangeSupport( this );
45
    }
46
    
47
    
48
    public ProjectCustomizer.Category getCurrentCategory() {
49
        return this.currentCategory;
50
    }
51
    
52
    public ProjectCustomizer.Category getCategory( String name ) {
53
        return findCategoryByName( name, categories );
54
    }
55
    
56
    public void setCurrentCategory( ProjectCustomizer.Category category ) {
57
        
58
        if ( currentCategory != category ) {
59
            ProjectCustomizer.Category oldValue = currentCategory;
60
            this.currentCategory = category;
61
            firePropertyChange( PROP_CURRENT_CATEGORY, oldValue, category );
62
        }
63
        
64
    }
65
    
66
    public ProjectCustomizer.Category[] getCategories() {
67
        return this.categories;
68
    }
69
    
70
    public void addPropertyChangeListener( String propertyName, PropertyChangeListener l ) {
71
        pcs.addPropertyChangeListener( propertyName, l );
72
    }
73
    
74
    public void addPropertyChangeListener( PropertyChangeListener l ) {
75
        pcs.addPropertyChangeListener( l );
76
    }
77
    
78
    public void removePropertyChangeListener( String propertyName, PropertyChangeListener l ) {
79
        pcs.removePropertyChangeListener( propertyName, l );
80
    }
81
    
82
    public void removePropertyChangeListener( PropertyChangeListener l ) {
83
        pcs.removePropertyChangeListener( l );
84
    }
85
    
86
    public void firePropertyChange( String propertyName, Object oldValue, Object newValue ) {
87
        pcs.firePropertyChange( propertyName, oldValue, newValue );
88
    }
89
    
90
    // Private methods ---------------------------------------------------------
91
    
92
    private static ProjectCustomizer.Category findCategoryByName( String name, ProjectCustomizer.Category[] categories ) {
93
        
94
        for( int i = 0; i < categories.length; i++ ) {
95
            if ( name.equals( categories[i].getName() ) ) {
96
                return categories[i];
97
            }
98
            
99
            ProjectCustomizer.Category[] subcategories = categories[i].getSubcategories();
100
            if ( subcategories != null ) {
101
                ProjectCustomizer.Category category = findCategoryByName( name, subcategories );
102
                if ( category != null ) {
103
                    return category;
104
                }
105
            }
106
            
107
        }
108
        
109
        return null;
110
    }
111
    
112
}
(-)projectuiapi/src/org/netbeans/modules/project/uiapi/CategoryView.java~ (+224 lines)
Line 0 Link Here
1
/*4
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.project.uiapi;
15
16
import java.awt.BorderLayout;
17
import java.awt.Dimension;
18
import java.awt.Image;
19
import java.beans.PropertyChangeEvent;
20
import java.beans.PropertyChangeListener;
21
import java.beans.PropertyVetoException;
22
import java.util.Arrays;
23
import java.util.Collection;
24
import java.util.Collections;
25
import javax.swing.JPanel;
26
import javax.swing.tree.TreeSelectionModel;
27
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
28
import org.openide.explorer.ExplorerManager;
29
import org.openide.explorer.view.BeanTreeView;
30
import org.openide.nodes.AbstractNode;
31
import org.openide.nodes.Children;
32
import org.openide.nodes.Node;
33
import org.openide.util.NbBundle;
34
import org.openide.util.Utilities;
35
import org.openide.util.lookup.Lookups;
36
37
/**
38
 *
39
 * @author Petr Hrebejk
40
 */
41
public class CategoryView extends JPanel implements ExplorerManager.Provider, PropertyChangeListener {
42
                
43
    private ExplorerManager manager;
44
    private BeanTreeView btv;
45
    private CategoryModel categoryModel;
46
47
    private ProjectCustomizer.Category currentCategory;
48
49
    public CategoryView( CategoryModel categoryModel ) {
50
51
        this.categoryModel = categoryModel;
52
53
        // See #36315
54
        manager = new ExplorerManager();
55
56
        setLayout( new BorderLayout() );
57
58
        Dimension size = new Dimension( 220, 4 );
59
        btv = new BeanTreeView();    // Add the BeanTreeView
60
        btv.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
61
        btv.setPopupAllowed( false );
62
        btv.setRootVisible( false );
63
        btv.setDefaultActionAllowed( false );            
64
        btv.setMinimumSize( size );
65
        btv.setPreferredSize( size );
66
        btv.setMaximumSize( size );
67
        btv.setDragSource (false);
68
        this.add( btv, BorderLayout.CENTER );                        
69
        manager.setRootContext( createRootNode( categoryModel ) );
70
        manager.addPropertyChangeListener( this );
71
        categoryModel.addPropertyChangeListener( this );
72
        btv.expandAll();
73
74
        getAccessibleContext().setAccessibleName(NbBundle.getMessage(CategoryView.class,"AN_CatgoryView"));
75
        getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CategoryView.class,"AD_CategoryView"));
76
77
    }
78
79
    public ExplorerManager getExplorerManager() {
80
        return manager;
81
    }
82
83
84
    public void addNotify() {
85
        super.addNotify();
86
        btv.expandAll();
87
    }
88
89
90
    // Private methods -----------------------------------------------------
91
92
    private void selectNode( ProjectCustomizer.Category category ) {
93
94
        Node node = findNode( category, manager.getRootContext() );
95
96
        if ( node != null ) {                
97
            try {
98
                manager.setSelectedNodes( new Node[] { node } );
99
            }
100
            catch ( PropertyVetoException e ) {
101
                // No node will be selected
102
            }                
103
        }
104
105
    }   
106
107
    private Node findNode( ProjectCustomizer.Category category, Node node ) {
108
109
        Children ch = node.getChildren();;
110
111
        if ( ch != null && ch != Children.LEAF ) {
112
            Node nodes[] = ch.getNodes( true );
113
114
            if ( nodes != null ) {                    
115
                for( int i = 0; i < nodes.length; i++ ) {
116
                    ProjectCustomizer.Category cc = (ProjectCustomizer.Category)nodes[i].getLookup().lookup( ProjectCustomizer.Category.class );
117
118
                    if ( cc == category ) {
119
                        return nodes[i];
120
                    }
121
                    else {
122
                        Node n = findNode( category, nodes[i] );
123
                        if ( n != null ) {
124
                            return n;
125
                        }
126
                    }                                                
127
                }
128
            }
129
        }
130
131
        return null;
132
    }
133
134
135
    private Node createRootNode( CategoryModel categoryModel ) {            
136
        ProjectCustomizer.Category rootCategory = ProjectCustomizer.Category.create( "root", "root", null, categoryModel.getCategories() ); // NOI18N           
137
        return new CategoryNode( rootCategory );
138
    }
139
140
    // Implementation of property change listener --------------------------
141
142
    public void propertyChange(PropertyChangeEvent evt) {
143
144
        Object source = evt.getSource();
145
        String propertyName = evt.getPropertyName();
146
147
        if ( source== manager && ExplorerManager.PROP_SELECTED_NODES.equals( propertyName ) ) {
148
            Node nodes[] = manager.getSelectedNodes(); 
149
            if ( nodes == null || nodes.length <= 0 ) {
150
                return;
151
            }
152
            Node node = nodes[0];
153
154
            ProjectCustomizer.Category category = (ProjectCustomizer.Category) node.getLookup().lookup( ProjectCustomizer.Category.class );
155
            if ( category != categoryModel.getCurrentCategory() ) {
156
                categoryModel.setCurrentCategory( category );
157
            }
158
        }
159
160
        if ( source == categoryModel && CategoryModel.PROP_CURRENT_CATEGORY.equals( propertyName ) ) {
161
            selectNode( (ProjectCustomizer.Category)evt.getNewValue() );
162
        }
163
164
    }
165
166
167
    // Private Inner classes -----------------------------------------------
168
169
    /** Node to be used for configuration
170
     */
171
    private static class CategoryNode extends AbstractNode {
172
173
        private Image icon = Utilities.loadImage( "org/netbeans/modules/project/uiapi/defaultCategory.gif" ); // NOI18N    
174
175
        public CategoryNode( ProjectCustomizer.Category category ) {
176
            super( ( category.getSubcategories() == null || category.getSubcategories().length == 0 ) ? 
177
                        Children.LEAF : new CategoryChildren( category.getSubcategories() ), 
178
                   Lookups.fixed( new Object[] { category } ) );
179
            setName( category.getName() );
180
            setDisplayName( category.getDisplayName() );
181
182
            if ( category.getIcon() != null ) {
183
                this.icon = category.getIcon(); 
184
            }
185
186
        }
187
188
        public Image getIcon( int type ) {
189
            return this.icon;
190
        }
191
192
        public Image getOpenedIcon( int type ) {
193
            return getIcon( type );
194
        }
195
    }
196
197
    /** Children used for configuration
198
     */
199
    private static class CategoryChildren extends Children.Keys {
200
201
        private Collection descriptions;
202
203
        public CategoryChildren( ProjectCustomizer.Category[] descriptions ) {
204
            this.descriptions = Arrays.asList( descriptions );
205
        }
206
207
        // Children.Keys impl --------------------------------------------------
208
209
        public void addNotify() {
210
            setKeys( descriptions );
211
        }
212
213
        public void removeNotify() {
214
            setKeys( Collections.EMPTY_LIST );
215
        }
216
217
        protected Node[] createNodes( Object key ) {
218
            return new Node[] { new CategoryNode( (ProjectCustomizer.Category)key ) };
219
        }
220
    }        
221
222
}
223
            
224
 
(-)projectuiapi/src/org/netbeans/modules/project/uiapi/CustomizerDialog.java (+109 lines)
Line 0 Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.project.uiapi;
15
16
import java.awt.Dialog;
17
import java.awt.event.ActionEvent;
18
import java.awt.event.ActionListener;
19
import javax.swing.JButton;
20
import javax.swing.JPanel;
21
import org.openide.DialogDescriptor;
22
import org.openide.DialogDisplayer;
23
import org.openide.util.NbBundle;
24
25
26
/** Implementation of standard customizer dialog.
27
 *
28
 * @author Petr Hrebejk
29
 */
30
public class CustomizerDialog {
31
    
32
    /** Factory class only 
33
     */
34
    private CustomizerDialog() {}
35
    
36
    // Option indexes
37
    private static final int OPTION_OK = 0;
38
    private static final int OPTION_CANCEL = OPTION_OK + 1;
39
    
40
    // Option command names
41
    private static final String COMMAND_OK = "OK";          // NOI18N
42
    private static final String COMMAND_CANCEL = "CANCEL";  // NOI18N
43
                
44
    public static Dialog createDialog( ActionListener okOptionListener, JPanel innerPane ) {
45
        
46
        // Create options
47
        JButton options[] = new JButton[] { 
48
            new JButton( NbBundle.getMessage( CustomizerDialog.class, "LBL_Customizer_Ok_Option") ), // NOI18N
49
            new JButton( NbBundle.getMessage( CustomizerDialog.class, "LBL_Customizer_Cancel_Option" ) ) , // NOI18N
50
        };
51
52
        // Set commands
53
        options[ OPTION_OK ].setActionCommand( COMMAND_OK );
54
        options[ OPTION_CANCEL ].setActionCommand( COMMAND_CANCEL );
55
        
56
        //A11Y
57
        options[ OPTION_OK ].getAccessibleContext().setAccessibleDescription ( NbBundle.getMessage( CustomizerDialog.class, "AD_Customizer_Ok_Option") ); // NOI18N
58
        options[ OPTION_CANCEL ].getAccessibleContext().setAccessibleDescription ( NbBundle.getMessage( CustomizerDialog.class, "AD_Customizer_Cancel_Option") ); // NOI18N
59
        
60
61
        // RegisterListener
62
        ActionListener optionsListener = new OptionListener( okOptionListener );        
63
        options[ OPTION_OK ].addActionListener( optionsListener );
64
        options[ OPTION_CANCEL ].addActionListener( optionsListener );
65
        
66
        innerPane.getAccessibleContext().setAccessibleName( NbBundle.getMessage( CustomizerDialog.class, "AN_ProjectCustomizer") ); //NOI18N
67
        innerPane.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage( CustomizerDialog.class, "AD_ProjectCustomizer") ); //NOI18N      
68
                        
69
        DialogDescriptor dialogDescriptor = new DialogDescriptor( 
70
            innerPane,                             // innerPane
71
            NbBundle.getMessage( CustomizerDialog.class, "LBL_Customizer_Title" ), // NOI18N // displayName
72
            false,                                  // modal
73
            options,                                // options
74
            options[OPTION_OK],                     // initial value
75
            DialogDescriptor.BOTTOM_ALIGN,          // options align
76
            null,                                   // helpCtx
77
            null );                                 // listener 
78
79
        // XXX HelpCtx problem innerPane.setDialogDescriptor( dialogDescriptor );        
80
        dialogDescriptor.setClosingOptions( new Object[] { options[ OPTION_OK ], options[ OPTION_CANCEL ] } );
81
82
        Dialog dialog = DialogDisplayer.getDefault().createDialog( dialogDescriptor );
83
        return dialog;
84
        
85
    }    
86
    
87
    /** Listens to the actions on the Customizer's option buttons */
88
    private static class OptionListener implements ActionListener {
89
    
90
        private ActionListener okOptionListener;
91
        
92
        OptionListener( ActionListener okOptionListener ) {
93
            this.okOptionListener = okOptionListener;
94
        }
95
        
96
        public void actionPerformed( ActionEvent e ) {
97
            String command = e.getActionCommand();
98
            
99
            if ( COMMAND_OK.equals( command ) ) {
100
                // Call the OK option listener
101
                okOptionListener.actionPerformed( e ); // XXX maybe create new event
102
            }
103
            
104
        }        
105
        
106
    }
107
    
108
                            
109
}
(-)projectuiapi/src/org/netbeans/modules/project/uiapi/CustomizerPane.form (+52 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <Properties>
5
    <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
6
      <Dimension value="[750, 450]"/>
7
    </Property>
8
  </Properties>
9
10
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
11
  <SubComponents>
12
    <Container class="javax.swing.JPanel" name="categoryPanel">
13
      <Properties>
14
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
15
          <Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
16
            <EtchetBorder/>
17
          </Border>
18
        </Property>
19
        <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
20
          <Dimension value="[220, 4]"/>
21
        </Property>
22
        <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
23
          <Dimension value="[220, 4]"/>
24
        </Property>
25
      </Properties>
26
      <AccessibilityProperties>
27
        <Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
28
          <ResourceString bundle="org/netbeans/modules/java/j2seproject/support/Bundle.properties" key="AN_Customizer_categoryPanel" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
29
        </Property>
30
        <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
31
          <ResourceString bundle="org/netbeans/modules/java/j2seproject/support/Bundle.properties" key="AD_Customizer_categoryPanel" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
32
        </Property>
33
      </AccessibilityProperties>
34
      <Constraints>
35
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
36
          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="0" fill="1" ipadX="0" ipadY="0" insetsTop="8" insetsLeft="11" insetsBottom="8" insetsRight="11" anchor="10" weightX="0.0" weightY="1.0"/>
37
        </Constraint>
38
      </Constraints>
39
40
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
41
    </Container>
42
    <Container class="javax.swing.JPanel" name="customizerPanel">
43
      <Constraints>
44
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
45
          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="0" gridHeight="0" fill="1" ipadX="0" ipadY="0" insetsTop="8" insetsLeft="0" insetsBottom="8" insetsRight="11" anchor="10" weightX="1.0" weightY="1.0"/>
46
        </Constraint>
47
      </Constraints>
48
49
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
50
    </Container>
51
  </SubComponents>
52
</Form>
(-)projectuiapi/src/org/netbeans/modules/project/uiapi/CustomizerPane.java (+181 lines)
Line 0 Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.project.uiapi;
15
16
import java.awt.Component;
17
import java.awt.GridBagConstraints;
18
import java.beans.PropertyChangeEvent;
19
import java.beans.PropertyChangeListener;
20
import javax.swing.JComponent;
21
import javax.swing.JPanel;
22
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
23
import org.openide.util.HelpCtx;
24
import org.openide.util.NbBundle;
25
26
/**
27
 *
28
 * @author  phrebejk
29
 */
30
public class CustomizerPane extends javax.swing.JPanel implements HelpCtx.Provider {
31
    
32
    
33
    private Component currentCustomizer;
34
35
    private GridBagConstraints fillConstraints;
36
    
37
    //private DialogDescriptor dialogDescriptor;
38
    
39
    /** Creates new form J2SECustomizer */
40
    public CustomizerPane( JPanel categoryView, CategoryModel categoryModel, ProjectCustomizer.CategoryComponentProvider componentProvider ) {
41
        initComponents();
42
        // HelpCtx.setHelpIDString( customizerPanel, "org.netbeans.modules.java.j2seproject.ui.customizer.J2SECustomizer" ); // NOI18N
43
        this.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(CustomizerPane.class,"AD_CustomizerPane")); // NOI18N
44
        fillConstraints = new GridBagConstraints();
45
        fillConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
46
        fillConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
47
        fillConstraints.fill = java.awt.GridBagConstraints.BOTH;
48
        fillConstraints.weightx = 1.0;
49
        fillConstraints.weighty = 1.0;
50
        categoryModel.addPropertyChangeListener( new CategoryChangeListener( componentProvider ) );
51
        categoryPanel.add( categoryView, fillConstraints );                
52
    }
53
    
54
    /** This method is called from within the constructor to
55
     * initialize the form.
56
     * WARNING: Do NOT modify this code. The content of this method is
57
     * always regenerated by the Form Editor.
58
     */
59
    private void initComponents() {//GEN-BEGIN:initComponents
60
        java.awt.GridBagConstraints gridBagConstraints;
61
62
        categoryPanel = new javax.swing.JPanel();
63
        customizerPanel = new javax.swing.JPanel();
64
65
        setLayout(new java.awt.GridBagLayout());
66
67
        setPreferredSize(new java.awt.Dimension(750, 450));
68
        categoryPanel.setLayout(new java.awt.GridBagLayout());
69
70
        categoryPanel.setBorder(new javax.swing.border.EtchedBorder());
71
        categoryPanel.setMinimumSize(new java.awt.Dimension(220, 4));
72
        categoryPanel.setPreferredSize(new java.awt.Dimension(220, 4));
73
        gridBagConstraints = new java.awt.GridBagConstraints();
74
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
75
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
76
        gridBagConstraints.weighty = 1.0;
77
        gridBagConstraints.insets = new java.awt.Insets(8, 11, 8, 11);
78
        add(categoryPanel, gridBagConstraints);
79
        categoryPanel.getAccessibleContext().setAccessibleName(null);
80
        categoryPanel.getAccessibleContext().setAccessibleDescription(null);
81
82
        customizerPanel.setLayout(new java.awt.GridBagLayout());
83
84
        gridBagConstraints = new java.awt.GridBagConstraints();
85
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
86
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
87
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
88
        gridBagConstraints.weightx = 1.0;
89
        gridBagConstraints.weighty = 1.0;
90
        gridBagConstraints.insets = new java.awt.Insets(8, 0, 8, 11);
91
        add(customizerPanel, gridBagConstraints);
92
93
    }//GEN-END:initComponents
94
    
95
    
96
    // Variables declaration - do not modify//GEN-BEGIN:variables
97
    private javax.swing.JPanel categoryPanel;
98
    private javax.swing.JPanel customizerPanel;
99
    // End of variables declaration//GEN-END:variables
100
    
101
    
102
    /* XXX HELP IS NOT WORKING
103
    public void setDialogDescriptor( DialogDescriptor dialogDescriptor ) {
104
        this.dialogDescriptor = dialogDescriptor;
105
    }
106
    */
107
    
108
    // HelpCtx.Provider implementation -----------------------------------------
109
    
110
    public HelpCtx getHelpCtx() {
111
        /*
112
        if ( currentCustomizer != null ) {
113
            return HelpCtx.findHelp( currentCustomizer );
114
        }
115
        else {
116
            return HelpCtx.findHelp( customizerPanel );
117
        }
118
         */
119
        
120
        // XXX
121
        return null;
122
    }
123
    
124
    // Private innerclasses ----------------------------------------------------
125
                
126
    /** Listens to selection change and shows the customizers as
127
     *  panels
128
     */        
129
    private class CategoryChangeListener implements PropertyChangeListener {
130
131
        private ProjectCustomizer.CategoryComponentProvider componentProvider;
132
133
        
134
        public CategoryChangeListener( ProjectCustomizer.CategoryComponentProvider componentProvider  ) {
135
            this.componentProvider = componentProvider;
136
        }
137
        
138
        public void propertyChange(PropertyChangeEvent evt) {
139
            
140
            if ( CategoryModel.PROP_CURRENT_CATEGORY.equals( evt.getPropertyName() ) ) {
141
                
142
                ProjectCustomizer.Category newCategory = (ProjectCustomizer.Category)evt.getNewValue();
143
                
144
                if ( newCategory == null ) {
145
                    return;
146
                }
147
                                
148
                if ( currentCustomizer != null ) {
149
                    customizerPanel.remove( currentCustomizer );
150
                }
151
                
152
                JComponent newCustomizer = componentProvider.create( newCategory );
153
                
154
                if ( newCustomizer != null ) {
155
                    currentCustomizer = newCustomizer;
156
157
                    /*
158
                    if ( currentCustomizer instanceof javax.swing.JComponent ) {
159
                        ((javax.swing.JComponent)currentCustomizer).setPreferredSize( new java.awt.Dimension( 600, 0 ) );
160
                    }
161
                    */
162
                    customizerPanel.add( currentCustomizer, fillConstraints );
163
                    customizerPanel.validate();
164
                    customizerPanel.repaint();
165
                    
166
                    /* XXX HELP DOES NOT WORK IN DIALOGS
167
                    if ( ImplCustomizerPane.this.dialogDescriptor != null ) {
168
                        ImplCustomizerPane.this.dialogDescriptor.setHelpCtx( ImplCustomizerPane.this.getHelpCtx() );
169
                    }
170
                    */
171
                }
172
                else {
173
                    currentCustomizer = null;
174
                }
175
176
                return;
177
            }
178
        }
179
    }
180
    
181
}
(-)projectuiapi/src/org/netbeans/spi/project/ui/support/ProjectCustomizer.java (+151 lines)
Line 0 Link Here
1
/*
2
 * Support.java
3
 *
4
 * Created on December 9, 2004, 1:09 PM
5
 */
6
7
package org.netbeans.spi.project.ui.support;
8
9
import java.awt.Dialog;
10
import java.awt.Image;
11
import java.awt.event.ActionListener;
12
import javax.swing.JComponent;
13
import javax.swing.JPanel;
14
15
import org.netbeans.modules.project.uiapi.CategoryModel;
16
import org.netbeans.modules.project.uiapi.CategoryView;
17
import org.netbeans.modules.project.uiapi.CustomizerDialog;
18
import org.netbeans.modules.project.uiapi.CustomizerPane;
19
20
/** Support for creating standard ProjectCustomizer dialog.
21
 *
22
 * @author Petr Hrebejk
23
 */
24
public final class ProjectCustomizer {
25
    
26
    /** Factory/Namespace class only. */
27
    private ProjectCustomizer() {
28
    }
29
    
30
    /** Creates standard ProjectCutomizer dialog. Can be used for implementation
31
     * of CustomizerProvider.
32
     * @param categories Array of Categories to be shown in the dialog.
33
     * @param componentProvider Implementation of CategoryProvider which creates 
34
     *        components for each category.
35
     * @param preselectedCategory name of the category which should be selected.
36
     * @param okOptionListener ActionListener which will be notified when the user presses 
37
     *        the OK button.
38
     * @return Standard customizer dialog.
39
     */    
40
    public static Dialog createCustomizerDialog( Category[] categories,
41
                                                 CategoryComponentProvider componentProvider,
42
                                                 String preselectedCategory,
43
                                                 ActionListener okOptionListener ) {
44
        JPanel innerPane = createCustomizerPane( categories, componentProvider, preselectedCategory );
45
        Dialog dialog = CustomizerDialog.createDialog( okOptionListener, innerPane );
46
        return dialog;
47
    }
48
        
49
    /** Creates standard innerPane for customizer dialog.
50
     */
51
    private static JPanel createCustomizerPane( Category[] categories,
52
                                                CategoryComponentProvider componentProvider,
53
                                                String preselectedCategory ) {
54
        
55
        CategoryModel categoryModel = new CategoryModel( categories );
56
        JPanel categoryView = new CategoryView( categoryModel );
57
        JPanel customizerPane = new CustomizerPane( categoryView, categoryModel, componentProvider );
58
        
59
        if ( preselectedCategory == null ) {
60
            preselectedCategory = categories[0].getName();
61
        }
62
        
63
        Category c = categoryModel.getCategory( preselectedCategory );
64
        if ( c != null ) {
65
            categoryModel.setCurrentCategory( c );
66
        }
67
        
68
        return customizerPane;
69
    }
70
    
71
    /** Provides components for categories.
72
     */
73
    public static interface CategoryComponentProvider {
74
        
75
        /** Creates component which has to be shown for given category
76
         * @param category The Category
77
         * @return UI component for category customization 
78
         */ 
79
        public JComponent create( Category category );
80
        
81
    }
82
    
83
    /** Describes category of properties to be customized by given component
84
     */
85
    public static final class Category {
86
87
        private String name;
88
        private String displayName;
89
        private Image icon;
90
        private Category[] subcategories;
91
92
        /** Private constructor. See the factory method.
93
         */
94
        private Category( String name,
95
                         String displayName,
96
                         Image icon,
97
                         Category[] subcategories ) {
98
99
            this.name = name;
100
            this.displayName = displayName;
101
            this.icon = icon;            
102
            this.subcategories = subcategories;
103
        }
104
        
105
        /** Factory method which creates new category description.
106
         * @param name Prograatic name of the category
107
         * @param displayName Name to be shown to the user
108
         * @param icon Icon for given category. Will use default icon if null.
109
         * @param subcategories Subcategories to be shown under given category.
110
         *        Category won't be expandable if null or empty array.
111
         */
112
        public static Category create( String name,
113
                                       String displayName,
114
                                       Image icon,                                       
115
                                       Category[] subcategories ) {
116
            return new Category( name, displayName, icon, subcategories );
117
        }
118
        
119
        
120
        // Public methods ------------------------------------------------------
121
        
122
        /** Gets programmatic name of given category.
123
         * @return Programmatic name of the category
124
         */
125
        public String getName() {
126
            return this.name;
127
        }
128
                
129
        /** Gets display name of given category.
130
         * @return Display name of the category
131
         */
132
        public String getDisplayName() {
133
            return this.displayName;
134
        }
135
        
136
        /** Gets icon of given category.
137
         * @return Icon name of the category or null
138
         */
139
        public Image getIcon() {
140
            return this.icon;
141
        }
142
        
143
        /** Gets subcategories of given category.
144
         * @return Subcategories of the category or null
145
         */
146
        public Category[] getSubcategories() {
147
            return this.subcategories;
148
        }
149
    }
150
151
}

Return to bug 49647