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.platform;
043:
044: import java.awt.Container;
045: import java.awt.Dialog;
046: import java.awt.Window;
047: import java.text.MessageFormat;
048: import javax.swing.JButton;
049: import javax.swing.JComponent;
050: import javax.swing.JPanel;
051: import javax.swing.event.ListSelectionEvent;
052: import javax.swing.event.ListSelectionListener;
053: import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardPanel;
054: import org.netbeans.modules.apisupport.project.universe.NbPlatform;
055: import org.openide.DialogDescriptor;
056: import org.openide.DialogDisplayer;
057: import org.openide.WizardDescriptor;
058: import org.openide.awt.Mnemonics;
059: import org.openide.util.HelpCtx;
060: import org.openide.util.NbBundle;
061:
062: /**
063: * Represents customizer for managing NetBeans platforms.
064: *
065: * @author Martin Krauskopf
066: */
067: public final class NbPlatformCustomizer extends JPanel {
068:
069: static final String CHOOSER_STEP = getMessage("MSG_ChoosePlatfrom"); // NOI18N
070: static final String INFO_STEP = getMessage("MSG_PlatformName"); // NOI18N
071:
072: static final String PLAF_DIR_PROPERTY = "selectedPlafDir"; // NOI18N
073: static final String PLAF_LABEL_PROPERTY = "selectedPlafLabel"; // NOI18N
074:
075: private NbPlatformCustomizerSources sourcesTab;
076: private NbPlatformCustomizerModules modulesTab;
077: private NbPlatformCustomizerJavadoc javadocTab;
078: private NbPlatformCustomizerHarness harnessTab;
079:
080: public static void showCustomizer() {
081: HarnessUpgrader.checkForUpgrade();
082: NbPlatformCustomizer customizer = new NbPlatformCustomizer();
083: JButton closeButton = new JButton();
084: Mnemonics.setLocalizedText(closeButton, NbBundle.getMessage(
085: NbPlatformCustomizer.class, "CTL_Close"));
086: DialogDescriptor descriptor = new DialogDescriptor(
087: customizer,
088: getMessage("CTL_NbPlatformManager_Title"), // NOI18N
089: true, new Object[] { closeButton }, closeButton,
090: DialogDescriptor.DEFAULT_ALIGN, new HelpCtx(
091: NbPlatformCustomizer.class), null);
092: Dialog dlg = DialogDisplayer.getDefault().createDialog(
093: descriptor);
094: dlg.setVisible(true);
095: dlg.dispose();
096: }
097:
098: /**
099: * Creates new form NbPlatformCustomizer
100: */
101: private NbPlatformCustomizer() {
102: initComponents();
103: initAccessibility();
104: initTabs();
105: platformsList
106: .addListSelectionListener(new ListSelectionListener() {
107: public void valueChanged(ListSelectionEvent e) {
108: refreshPlatform();
109: }
110: });
111: refreshPlatform();
112: }
113:
114: private void initTabs() {
115: if (platformsList.getModel().getSize() > 0) {
116: platformsList.setSelectedIndex(0);
117: sourcesTab = new NbPlatformCustomizerSources();
118: modulesTab = new NbPlatformCustomizerModules();
119: javadocTab = new NbPlatformCustomizerJavadoc();
120: harnessTab = new NbPlatformCustomizerHarness();
121: detailPane.addTab(getMessage("CTL_ModulesTab"), modulesTab); // NOI18N
122: detailPane.addTab(getMessage("CTL_SourcesTab"), sourcesTab); // NOI18N
123: detailPane.addTab(getMessage("CTL_JavadocTab"), javadocTab); // NOI18N
124: detailPane.addTab(getMessage("CTL_HarnessTab"), harnessTab); // NOI18N
125: Container window = this .getTopLevelAncestor();
126: if (window != null && window instanceof Window) {
127: ((Window) window).pack();
128: }
129: }
130: }
131:
132: private void refreshPlatform() {
133: NbPlatform plaf = (NbPlatform) platformsList.getSelectedValue();
134: if (plaf == null) {
135: removeButton.setEnabled(false);
136: return;
137: }
138: plfNameValue.setText(plaf.getLabel());
139: plfFolderValue.setText(plaf.getDestDir().getAbsolutePath());
140: boolean isValid = plaf.isValid();
141: if (isValid) {
142: if (sourcesTab == null) {
143: initTabs();
144: }
145: if (sourcesTab != null) {
146: modulesTab.setPlatform(plaf);
147: sourcesTab.setPlatform(plaf);
148: javadocTab.setPlatform(plaf);
149: harnessTab.setPlatform(plaf);
150: }
151: } else {
152: modulesTab.reset();
153: detailPane.setSelectedIndex(0);
154: }
155: detailPane.setEnabledAt(0, isValid);
156: detailPane.setEnabledAt(1, isValid);
157: detailPane.setEnabledAt(2, isValid);
158: removeButton.setEnabled(!plaf.isDefault());
159: }
160:
161: private static String getMessage(String key) {
162: return NbBundle.getMessage(NbPlatformCustomizer.class, key);
163: }
164:
165: /** This method is called from within the constructor to
166: * initialize the form.
167: * WARNING: Do NOT modify this code. The content of this method is
168: * always regenerated by the Form Editor.
169: */
170: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
171: private void initComponents() {
172: java.awt.GridBagConstraints gridBagConstraints;
173:
174: platformLbl = new javax.swing.JLabel();
175: platformsListSP = new javax.swing.JScrollPane();
176: platformsList = PlatformComponentFactory.getNbPlatformsList();
177: addButton = new javax.swing.JButton();
178: removeButton = new javax.swing.JButton();
179: infoPane = new javax.swing.JPanel();
180: plfName = new javax.swing.JLabel();
181: pflFolder = new javax.swing.JLabel();
182: plfNameValue = new javax.swing.JTextField();
183: plfFolderValue = new javax.swing.JTextField();
184: detailPane = new javax.swing.JTabbedPane();
185:
186: setLayout(new java.awt.GridBagLayout());
187:
188: setBorder(new javax.swing.border.EmptyBorder(
189: new java.awt.Insets(12, 12, 12, 12)));
190: platformLbl.setLabelFor(platformsList);
191: org.openide.awt.Mnemonics.setLocalizedText(platformLbl,
192: org.openide.util.NbBundle.getMessage(
193: NbPlatformCustomizer.class, "LBL_Platforms"));
194: gridBagConstraints = new java.awt.GridBagConstraints();
195: gridBagConstraints.gridx = 0;
196: gridBagConstraints.gridy = 0;
197: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
198: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
199: add(platformLbl, gridBagConstraints);
200:
201: platformsList
202: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
203: platformsListSP.setViewportView(platformsList);
204:
205: gridBagConstraints = new java.awt.GridBagConstraints();
206: gridBagConstraints.gridx = 0;
207: gridBagConstraints.gridy = 1;
208: gridBagConstraints.gridwidth = 2;
209: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
210: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
211: gridBagConstraints.weighty = 1.0;
212: gridBagConstraints.insets = new java.awt.Insets(2, 0, 12, 6);
213: add(platformsListSP, gridBagConstraints);
214:
215: org.openide.awt.Mnemonics.setLocalizedText(addButton,
216: org.openide.util.NbBundle.getMessage(
217: NbPlatformCustomizer.class, "CTL_AddPlatform"));
218: addButton
219: .addActionListener(new java.awt.event.ActionListener() {
220: public void actionPerformed(
221: java.awt.event.ActionEvent evt) {
222: addPlatform(evt);
223: }
224: });
225:
226: gridBagConstraints = new java.awt.GridBagConstraints();
227: gridBagConstraints.gridx = 0;
228: gridBagConstraints.gridy = 2;
229: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
230: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
231: add(addButton, gridBagConstraints);
232:
233: org.openide.awt.Mnemonics.setLocalizedText(removeButton,
234: org.openide.util.NbBundle.getMessage(
235: NbPlatformCustomizer.class,
236: "CTL_RemovePlatfrom"));
237: removeButton
238: .addActionListener(new java.awt.event.ActionListener() {
239: public void actionPerformed(
240: java.awt.event.ActionEvent evt) {
241: removePlatform(evt);
242: }
243: });
244:
245: gridBagConstraints = new java.awt.GridBagConstraints();
246: gridBagConstraints.gridx = 1;
247: gridBagConstraints.gridy = 2;
248: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
249: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 6);
250: add(removeButton, gridBagConstraints);
251:
252: infoPane.setLayout(new java.awt.GridBagLayout());
253:
254: plfName.setLabelFor(plfNameValue);
255: org.openide.awt.Mnemonics.setLocalizedText(plfName,
256: org.openide.util.NbBundle.getMessage(
257: NbPlatformCustomizer.class,
258: "LBL_PlatformName_N"));
259: gridBagConstraints = new java.awt.GridBagConstraints();
260: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
261: infoPane.add(plfName, gridBagConstraints);
262:
263: pflFolder.setLabelFor(plfFolderValue);
264: org.openide.awt.Mnemonics.setLocalizedText(pflFolder,
265: org.openide.util.NbBundle.getMessage(
266: NbPlatformCustomizer.class,
267: "LBL_PlatformFolder"));
268: gridBagConstraints = new java.awt.GridBagConstraints();
269: gridBagConstraints.gridx = 0;
270: gridBagConstraints.gridy = 1;
271: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
272: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
273: infoPane.add(pflFolder, gridBagConstraints);
274:
275: plfNameValue.setEditable(false);
276: gridBagConstraints = new java.awt.GridBagConstraints();
277: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
278: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
279: gridBagConstraints.weightx = 1.0;
280: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
281: infoPane.add(plfNameValue, gridBagConstraints);
282:
283: plfFolderValue.setEditable(false);
284: gridBagConstraints = new java.awt.GridBagConstraints();
285: gridBagConstraints.gridx = 1;
286: gridBagConstraints.gridy = 1;
287: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
288: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
289: gridBagConstraints.weightx = 1.0;
290: gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
291: infoPane.add(plfFolderValue, gridBagConstraints);
292:
293: gridBagConstraints = new java.awt.GridBagConstraints();
294: gridBagConstraints.gridx = 0;
295: gridBagConstraints.gridy = 2;
296: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
297: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
298: gridBagConstraints.weightx = 1.0;
299: gridBagConstraints.weighty = 1.0;
300: infoPane.add(detailPane, gridBagConstraints);
301:
302: gridBagConstraints = new java.awt.GridBagConstraints();
303: gridBagConstraints.gridx = 2;
304: gridBagConstraints.gridy = 1;
305: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
306: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
307: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
308: gridBagConstraints.weightx = 1.0;
309: gridBagConstraints.insets = new java.awt.Insets(2, 6, 12, 0);
310: add(infoPane, gridBagConstraints);
311:
312: }
313:
314: // </editor-fold>//GEN-END:initComponents
315:
316: private PlatformComponentFactory.NbPlatformListModel getPlafListModel() {
317: return (PlatformComponentFactory.NbPlatformListModel) platformsList
318: .getModel();
319: }
320:
321: private void removePlatform(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePlatform
322: NbPlatform plaf = (NbPlatform) platformsList.getSelectedValue();
323: if (plaf != null) {
324: getPlafListModel().removePlatform(plaf);
325: platformsList.setSelectedValue(NbPlatform
326: .getDefaultPlatform(), true);
327: refreshPlatform();
328: }
329: }//GEN-LAST:event_removePlatform
330:
331: private void addPlatform(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPlatform
332: PlatformChooserWizardPanel chooser = new PlatformChooserWizardPanel(
333: null);
334: PlatformInfoWizardPanel info = new PlatformInfoWizardPanel(null);
335: WizardDescriptor wd = new WizardDescriptor(
336: new BasicWizardPanel[] { chooser, info });
337: initPanel(chooser, wd, 0);
338: initPanel(info, wd, 1);
339: wd.setTitleFormat(new MessageFormat("{0}")); // NOI18N
340: Dialog dialog = DialogDisplayer.getDefault().createDialog(wd);
341: dialog.setTitle(getMessage("CTL_AddNetbeansPlatformTitle")); // NOI18N
342: dialog.setVisible(true);
343: dialog.toFront();
344: if (wd.getValue() == WizardDescriptor.FINISH_OPTION) {
345: String plafDir = (String) wd.getProperty(PLAF_DIR_PROPERTY);
346: String plafLabel = (String) wd
347: .getProperty(PLAF_LABEL_PROPERTY);
348: String id = plafLabel.replace(' ', '_');
349: NbPlatform plaf = getPlafListModel().addPlatform(id,
350: plafDir, plafLabel);
351: if (plaf != null) {
352: platformsList.setSelectedValue(plaf, true);
353: refreshPlatform();
354: }
355: }
356: }//GEN-LAST:event_addPlatform
357:
358: private void initPanel(BasicWizardPanel panel, WizardDescriptor wd,
359: int i) {
360: panel.setSettings(wd);
361: JComponent jc = (JComponent) panel.getComponent();
362: jc.putClientProperty("WizardPanel_autoWizardStyle",
363: Boolean.TRUE); // NOI18N
364: jc.putClientProperty("WizardPanel_contentDisplayed",
365: Boolean.TRUE); // NOI18N
366: jc.putClientProperty("WizardPanel_contentNumbered",
367: Boolean.TRUE); // NOI18N
368: jc.putClientProperty("WizardPanel_contentSelectedIndex",
369: new Integer(i)); // NOI18N
370: jc.putClientProperty("WizardPanel_contentData", new String[] { // NOI18N
371: CHOOSER_STEP, INFO_STEP });
372: }
373:
374: // Variables declaration - do not modify//GEN-BEGIN:variables
375: private javax.swing.JButton addButton;
376: private javax.swing.JTabbedPane detailPane;
377: private javax.swing.JPanel infoPane;
378: private javax.swing.JLabel pflFolder;
379: private javax.swing.JLabel platformLbl;
380: private javax.swing.JList platformsList;
381: private javax.swing.JScrollPane platformsListSP;
382: private javax.swing.JTextField plfFolderValue;
383: private javax.swing.JLabel plfName;
384: private javax.swing.JTextField plfNameValue;
385: private javax.swing.JButton removeButton;
386:
387: // End of variables declaration//GEN-END:variables
388:
389: private void initAccessibility() {
390: this .getAccessibleContext().setAccessibleDescription(
391: getMessage("ACS_NbPlatformCustomizer"));
392: platformsList.getAccessibleContext().setAccessibleDescription(
393: getMessage("ACS_CTL_platformsList"));
394: plfFolderValue.getAccessibleContext().setAccessibleDescription(
395: getMessage("ACS_CTL_plfFolderValue"));
396: plfNameValue.getAccessibleContext().setAccessibleDescription(
397: getMessage("ACS_CTL_plfNameValue"));
398: removeButton.getAccessibleContext().setAccessibleDescription(
399: getMessage("ACS_CTL_removeButton"));
400: addButton.getAccessibleContext().setAccessibleDescription(
401: getMessage("ACS_CTL_addButton"));
402: }
403: }
|