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-2006 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.apisupport.project.ui.customizer;
043:
044: import java.util.Arrays;
045: import javax.swing.event.ListSelectionListener;
046: import org.netbeans.modules.apisupport.project.NbModuleProject;
047: import org.netbeans.modules.apisupport.project.ui.UIUtil;
048: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
049: import org.openide.util.NbBundle;
050:
051: /**
052: * Represents <em>Sources</em> panel in Suite customizer.
053: *
054: * @author Martin Krauskopf
055: */
056: final class SuiteCustomizerSources extends NbPropertyPanel.Suite {
057:
058: /**
059: * Creates new form SuiteCustomizerSources
060: */
061: SuiteCustomizerSources(final SuiteProperties suiteProps,
062: ProjectCustomizer.Category cat) {
063: super (suiteProps, SuiteCustomizerSources.class, cat);
064: initComponents();
065: initAccesibility();
066: prjFolderValue.setText(suiteProps.getProjectDirectory());
067: refresh();
068: moduleList.setCellRenderer(CustomizerComponentFactory
069: .getModuleCellRenderer());
070: moduleList
071: .addListSelectionListener(new ListSelectionListener() {
072: public void valueChanged(
073: javax.swing.event.ListSelectionEvent e) {
074: if (!e.getValueIsAdjusting()) {
075: updateEnabled();
076: }
077: }
078: });
079: }
080:
081: void refresh() {
082: moduleList.setModel(getProperties().getModulesListModel());
083: }
084:
085: private void updateEnabled() {
086: boolean enabled = moduleList.getSelectedIndex() != -1;
087: removeModuleButton.setEnabled(enabled);
088: }
089:
090: private CustomizerComponentFactory.SuiteSubModulesListModel getModuleListModel() {
091: return (CustomizerComponentFactory.SuiteSubModulesListModel) moduleList
092: .getModel();
093: }
094:
095: /** This method is called from within the constructor to
096: * initialize the form.
097: * WARNING: Do NOT modify this code. The content of this method is
098: * always regenerated by the Form Editor.
099: */
100: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
101: private void initComponents() {
102: java.awt.GridBagConstraints gridBagConstraints;
103:
104: prjFolderPanel = new javax.swing.JPanel();
105: prjFolder = new javax.swing.JLabel();
106: prjFolderValue = new javax.swing.JTextField();
107: moduleLabel = new javax.swing.JLabel();
108: modulesSP = new javax.swing.JScrollPane();
109: moduleList = new javax.swing.JList();
110: buttonPanel = new javax.swing.JPanel();
111: addModuleButton = new javax.swing.JButton();
112: removeModuleButton = new javax.swing.JButton();
113:
114: setLayout(new java.awt.GridBagLayout());
115:
116: prjFolderPanel.setLayout(new java.awt.GridBagLayout());
117:
118: prjFolder.setLabelFor(prjFolderValue);
119: org.openide.awt.Mnemonics.setLocalizedText(prjFolder,
120: org.openide.util.NbBundle.getMessage(
121: SuiteCustomizerSources.class,
122: "LBL_ProjectFolder"));
123: gridBagConstraints = new java.awt.GridBagConstraints();
124: gridBagConstraints.gridx = 0;
125: gridBagConstraints.gridy = 0;
126: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
127: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
128: prjFolderPanel.add(prjFolder, gridBagConstraints);
129:
130: prjFolderValue.setEditable(false);
131: gridBagConstraints = new java.awt.GridBagConstraints();
132: gridBagConstraints.gridx = 1;
133: gridBagConstraints.gridy = 0;
134: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
135: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
136: gridBagConstraints.weightx = 1.0;
137: prjFolderPanel.add(prjFolderValue, gridBagConstraints);
138:
139: gridBagConstraints = new java.awt.GridBagConstraints();
140: gridBagConstraints.gridx = 0;
141: gridBagConstraints.gridy = 0;
142: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
143: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
144: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
145: add(prjFolderPanel, gridBagConstraints);
146:
147: moduleLabel.setLabelFor(moduleList);
148: org.openide.awt.Mnemonics.setLocalizedText(moduleLabel,
149: org.openide.util.NbBundle.getMessage(
150: SuiteCustomizerSources.class,
151: "LBL_SuiteModules"));
152: gridBagConstraints = new java.awt.GridBagConstraints();
153: gridBagConstraints.gridx = 0;
154: gridBagConstraints.gridy = 1;
155: gridBagConstraints.gridwidth = 2;
156: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
157: gridBagConstraints.insets = new java.awt.Insets(18, 0, 2, 0);
158: add(moduleLabel, gridBagConstraints);
159:
160: modulesSP.setViewportView(moduleList);
161:
162: gridBagConstraints = new java.awt.GridBagConstraints();
163: gridBagConstraints.gridx = 0;
164: gridBagConstraints.gridy = 2;
165: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
166: gridBagConstraints.weightx = 1.0;
167: gridBagConstraints.weighty = 1.0;
168: add(modulesSP, gridBagConstraints);
169:
170: buttonPanel.setLayout(new java.awt.GridLayout(2, 1, 0, 6));
171:
172: org.openide.awt.Mnemonics.setLocalizedText(addModuleButton,
173: org.openide.util.NbBundle.getMessage(
174: SuiteCustomizerSources.class, "CTL_AddButton"));
175: addModuleButton
176: .addActionListener(new java.awt.event.ActionListener() {
177: public void actionPerformed(
178: java.awt.event.ActionEvent evt) {
179: addModule(evt);
180: }
181: });
182:
183: buttonPanel.add(addModuleButton);
184:
185: org.openide.awt.Mnemonics.setLocalizedText(removeModuleButton,
186: org.openide.util.NbBundle.getMessage(
187: SuiteCustomizerSources.class,
188: "CTL_RemoveButton"));
189: removeModuleButton.setEnabled(false);
190: removeModuleButton
191: .addActionListener(new java.awt.event.ActionListener() {
192: public void actionPerformed(
193: java.awt.event.ActionEvent evt) {
194: removeModule(evt);
195: }
196: });
197:
198: buttonPanel.add(removeModuleButton);
199:
200: gridBagConstraints = new java.awt.GridBagConstraints();
201: gridBagConstraints.gridx = 1;
202: gridBagConstraints.gridy = 2;
203: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
204: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
205: add(buttonPanel, gridBagConstraints);
206:
207: }
208:
209: // </editor-fold>//GEN-END:initComponents
210:
211: private void removeModule(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeModule
212: getModuleListModel().removeModules(
213: Arrays.asList(moduleList.getSelectedValues()));
214: if (moduleList.getModel().getSize() > 0) {
215: moduleList.setSelectedIndex(0);
216: } else {
217: moduleList.clearSelection();
218: }
219: moduleList.requestFocus();
220: }//GEN-LAST:event_removeModule
221:
222: private void addModule(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addModule
223: NbModuleProject project = UIUtil.chooseSuiteComponent(this ,
224: getProperties().getProject());
225: if (project != null) {
226: if (getModuleListModel().contains(project)) {
227: moduleList.setSelectedValue(project, true);
228: } else {
229: getModuleListModel().addModule(project);
230: }
231: }
232: }//GEN-LAST:event_addModule
233:
234: // Variables declaration - do not modify//GEN-BEGIN:variables
235: private javax.swing.JButton addModuleButton;
236: private javax.swing.JPanel buttonPanel;
237: private javax.swing.JLabel moduleLabel;
238: private javax.swing.JList moduleList;
239: private javax.swing.JScrollPane modulesSP;
240: private javax.swing.JLabel prjFolder;
241: private javax.swing.JPanel prjFolderPanel;
242: private javax.swing.JTextField prjFolderValue;
243: private javax.swing.JButton removeModuleButton;
244:
245: // End of variables declaration//GEN-END:variables
246:
247: private static String getMessage(String key) {
248: return NbBundle.getMessage(CustomizerDisplay.class, key);
249: }
250:
251: private void initAccesibility() {
252: addModuleButton.getAccessibleContext()
253: .setAccessibleDescription(
254: getMessage("ACSD_AddModuleButton"));
255: moduleList.getAccessibleContext().setAccessibleDescription(
256: getMessage("ACSD_ModuleList"));
257: prjFolderValue.getAccessibleContext().setAccessibleDescription(
258: getMessage("ACSD_PrjFolderValue"));
259: removeModuleButton.getAccessibleContext()
260: .setAccessibleDescription(
261: getMessage("ACSD_RemoveModuleButton"));
262: }
263:
264: }
|