KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > SuiteCustomizerSources


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.apisupport.project.ui.customizer;
21
22 import java.util.Arrays JavaDoc;
23 import javax.swing.event.ListSelectionListener JavaDoc;
24 import org.netbeans.api.project.Project;
25 import org.netbeans.modules.apisupport.project.NbModuleProject;
26 import org.netbeans.modules.apisupport.project.ui.UIUtil;
27 import org.openide.util.NbBundle;
28
29 /**
30  * Represents <em>Sources</em> panel in Suite customizer.
31  *
32  * @author Martin Krauskopf
33  */

34 final class SuiteCustomizerSources extends NbPropertyPanel.Suite {
35
36     /**
37      * Creates new form SuiteCustomizerSources
38      */

39     SuiteCustomizerSources(final SuiteProperties suiteProps) {
40         super(suiteProps, SuiteCustomizerSources.class);
41         initComponents();
42         initAccesibility();
43         prjFolderValue.setText(suiteProps.getProjectDirectory());
44         refresh();
45         moduleList.setCellRenderer(CustomizerComponentFactory.getModuleCellRenderer());
46         moduleList.addListSelectionListener(new ListSelectionListener JavaDoc() {
47             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc e) {
48                 if (!e.getValueIsAdjusting()) {
49                     updateEnabled();
50                 }
51             }
52         });
53     }
54     
55     void refresh() {
56         moduleList.setModel(getProperties().getModulesListModel());
57     }
58     
59     private void updateEnabled() {
60         boolean enabled = moduleList.getSelectedIndex() != -1;
61         removeModuleButton.setEnabled(enabled);
62     }
63     
64     private CustomizerComponentFactory.SuiteSubModulesListModel getModuleListModel() {
65         return (CustomizerComponentFactory.SuiteSubModulesListModel) moduleList.getModel();
66     }
67     
68     /** This method is called from within the constructor to
69      * initialize the form.
70      * WARNING: Do NOT modify this code. The content of this method is
71      * always regenerated by the Form Editor.
72      */

73     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
74
private void initComponents() {
75         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
76
77         prjFolderPanel = new javax.swing.JPanel JavaDoc();
78         prjFolder = new javax.swing.JLabel JavaDoc();
79         prjFolderValue = new javax.swing.JTextField JavaDoc();
80         moduleLabel = new javax.swing.JLabel JavaDoc();
81         modulesSP = new javax.swing.JScrollPane JavaDoc();
82         moduleList = new javax.swing.JList JavaDoc();
83         buttonPanel = new javax.swing.JPanel JavaDoc();
84         addModuleButton = new javax.swing.JButton JavaDoc();
85         removeModuleButton = new javax.swing.JButton JavaDoc();
86
87         setLayout(new java.awt.GridBagLayout JavaDoc());
88
89         prjFolderPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
90
91         prjFolder.setLabelFor(prjFolderValue);
92         org.openide.awt.Mnemonics.setLocalizedText(prjFolder, org.openide.util.NbBundle.getMessage(SuiteCustomizerSources.class, "LBL_ProjectFolder"));
93         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
94         gridBagConstraints.gridx = 0;
95         gridBagConstraints.gridy = 0;
96         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
97         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
98         prjFolderPanel.add(prjFolder, gridBagConstraints);
99
100         prjFolderValue.setEditable(false);
101         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
102         gridBagConstraints.gridx = 1;
103         gridBagConstraints.gridy = 0;
104         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
105         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
106         gridBagConstraints.weightx = 1.0;
107         prjFolderPanel.add(prjFolderValue, gridBagConstraints);
108
109         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
110         gridBagConstraints.gridx = 0;
111         gridBagConstraints.gridy = 0;
112         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
113         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
114         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
115         add(prjFolderPanel, gridBagConstraints);
116
117         moduleLabel.setLabelFor(moduleList);
118         org.openide.awt.Mnemonics.setLocalizedText(moduleLabel, org.openide.util.NbBundle.getMessage(SuiteCustomizerSources.class, "LBL_SuiteModules"));
119         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints.gridx = 0;
121         gridBagConstraints.gridy = 1;
122         gridBagConstraints.gridwidth = 2;
123         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
124         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 2, 0);
125         add(moduleLabel, gridBagConstraints);
126
127         modulesSP.setViewportView(moduleList);
128
129         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
130         gridBagConstraints.gridx = 0;
131         gridBagConstraints.gridy = 2;
132         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
133         gridBagConstraints.weightx = 1.0;
134         gridBagConstraints.weighty = 1.0;
135         add(modulesSP, gridBagConstraints);
136
137         buttonPanel.setLayout(new java.awt.GridLayout JavaDoc(2, 1, 0, 6));
138
139         org.openide.awt.Mnemonics.setLocalizedText(addModuleButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerSources.class, "CTL_AddButton"));
140         addModuleButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
141             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
142                 addModule(evt);
143             }
144         });
145
146         buttonPanel.add(addModuleButton);
147
148         org.openide.awt.Mnemonics.setLocalizedText(removeModuleButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerSources.class, "CTL_RemoveButton"));
149         removeModuleButton.setEnabled(false);
150         removeModuleButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
151             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
152                 removeModule(evt);
153             }
154         });
155
156         buttonPanel.add(removeModuleButton);
157
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.gridx = 1;
160         gridBagConstraints.gridy = 2;
161         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
162         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
163         add(buttonPanel, gridBagConstraints);
164
165     }
166     // </editor-fold>//GEN-END:initComponents
167

168     private void removeModule(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeModule
169
getModuleListModel().removeModules(Arrays.asList(moduleList.getSelectedValues()));
170         if (moduleList.getModel().getSize() > 0) {
171             moduleList.setSelectedIndex(0);
172         }
173         moduleList.requestFocus();
174     }//GEN-LAST:event_removeModule
175

176     private void addModule(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addModule
177
NbModuleProject project = UIUtil.chooseSuiteComponent(this, getProperties().getProject());
178         if (project != null) {
179             if (getModuleListModel().contains(project)) {
180                 moduleList.setSelectedValue(project, true);
181             } else {
182                 getModuleListModel().addModule(project);
183             }
184         }
185     }//GEN-LAST:event_addModule
186

187     // Variables declaration - do not modify//GEN-BEGIN:variables
188
private javax.swing.JButton JavaDoc addModuleButton;
189     private javax.swing.JPanel JavaDoc buttonPanel;
190     private javax.swing.JLabel JavaDoc moduleLabel;
191     private javax.swing.JList JavaDoc moduleList;
192     private javax.swing.JScrollPane JavaDoc modulesSP;
193     private javax.swing.JLabel JavaDoc prjFolder;
194     private javax.swing.JPanel JavaDoc prjFolderPanel;
195     private javax.swing.JTextField JavaDoc prjFolderValue;
196     private javax.swing.JButton JavaDoc removeModuleButton;
197     // End of variables declaration//GEN-END:variables
198

199     private static String JavaDoc getMessage(String JavaDoc key) {
200         return NbBundle.getMessage(CustomizerDisplay.class, key);
201     }
202     
203     private void initAccesibility() {
204         addModuleButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_AddModuleButton"));
205         moduleList.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ModuleList"));
206         prjFolderValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_PrjFolderValue"));
207         removeModuleButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_RemoveModuleButton"));
208     }
209     
210 }
211
Popular Tags