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.awt.EventQueue;
045: import java.beans.PropertyChangeEvent;
046: import java.util.Iterator;
047: import java.util.SortedSet;
048: import javax.swing.DefaultComboBoxModel;
049: import org.netbeans.modules.apisupport.project.ui.UIUtil;
050: import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo;
051: import org.netbeans.modules.apisupport.project.universe.NbPlatform;
052: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
053: import org.openide.util.NbBundle;
054:
055: /**
056: * Represents <em>Display</em> panel in Netbeans Module customizer.
057: *
058: * @author mkrauskopf
059: */
060: final class CustomizerDisplay extends NbPropertyPanel.Single {
061:
062: private boolean noBundle;
063: private boolean showInPluginManagerCheckboxChanged;
064:
065: CustomizerDisplay(final SingleModuleProperties props,
066: ProjectCustomizer.Category cat) {
067: super (props, CustomizerDisplay.class, cat);
068: initComponents();
069: initAccessibility();
070: refresh();
071: checkValidity();
072: }
073:
074: void refresh() {
075: this .noBundle = getBundle() == null;
076: if (noBundle) {
077: nameValue.setEnabled(false);
078: categoryValue.setEnabled(false);
079: shortDescValue.setEnabled(false);
080: longDescValue.setEnabled(false);
081: } else {
082: readFromProperties();
083: }
084: Boolean autoUpdateShowInClient = ((SingleModuleProperties) props)
085: .getAutoUpdateShowInClient();
086: if (autoUpdateShowInClient == null) {
087: autoUpdateShowInClient = !getBooleanProperty(SingleModuleProperties.IS_AUTOLOAD)
088: && !getBooleanProperty(SingleModuleProperties.IS_EAGER);
089: }
090: showInPluginManagerCheckbox.setSelected(autoUpdateShowInClient);
091: showInPluginManagerCheckboxChanged = false;
092: NbPlatform plaf = getProperties().getActivePlatform();
093: if (plaf != null) {
094: // #110661: only show for new target platforms.
095: // Checking harness version is not enough - a new harness with an old platform should *not* write this attr,
096: showInPluginManagerCheckbox
097: .setVisible(plaf
098: .getModule("org.netbeans.modules.autoupdate.services") != null); // NOI18N
099: } else {
100: // XXX netbeans.org module; harder to check; skip for now and always show checkbox
101: }
102: }
103:
104: private void checkValidity() {
105: if (this .noBundle) {
106: category
107: .setErrorMessage(getMessage("MSG_NoBundleForModule"));
108: } else {
109: category.setErrorMessage(null);
110: }
111: }
112:
113: @Override
114: public void store() {
115: if (!noBundle) {
116: getBundle().setDisplayName(nameValue.getText());
117: getBundle().setCategory(getSelectedCategory());
118: getBundle().setShortDescription(shortDescValue.getText());
119: getBundle().setLongDescription(longDescValue.getText());
120: }
121: if (showInPluginManagerCheckboxChanged) {
122: ((SingleModuleProperties) props)
123: .setAutoUpdateShowInClient(showInPluginManagerCheckbox
124: .isSelected());
125: }
126: }
127:
128: private LocalizedBundleInfo getBundle() {
129: return getProperties().getBundleInfo();
130: }
131:
132: private void readFromProperties() {
133: UIUtil.setText(nameValue, getBundle().getDisplayName());
134: UIUtil.setText(shortDescValue, getBundle()
135: .getShortDescription());
136: longDescValue.setText(getBundle().getLongDescription());
137: fillUpCategoryValue();
138: }
139:
140: private void fillUpCategoryValue() {
141: categoryValue.setEnabled(false);
142: categoryValue.setModel(CustomizerComponentFactory
143: .createComboWaitModel());
144: categoryValue
145: .setSelectedItem(CustomizerComponentFactory.WAIT_VALUE);
146: ModuleProperties.RP.post(new Runnable() {
147: public void run() {
148: final SortedSet moduleCategories = getProperties()
149: .getModuleCategories();
150: EventQueue.invokeLater(new Runnable() {
151: public void run() {
152: DefaultComboBoxModel model = new DefaultComboBoxModel();
153: categoryValue.removeAllItems();
154: for (Iterator it = moduleCategories.iterator(); it
155: .hasNext();) {
156: model.addElement(it.next());
157: }
158: if (!moduleCategories.contains(getCategory())) {
159: // put module's own category at the beginning
160: model.insertElementAt(getCategory(), 0);
161: }
162: categoryValue.setModel(model);
163: categoryValue.setSelectedItem(getCategory());
164: categoryValue.setEnabled(true);
165: }
166: });
167: }
168: });
169: }
170:
171: private String getCategory() {
172: LocalizedBundleInfo bundle = getBundle();
173: String cat = bundle != null ? bundle.getCategory() : null;
174: return cat != null ? cat : ""; // NOI18N
175: }
176:
177: @Override
178: public void propertyChange(PropertyChangeEvent evt) {
179: super .propertyChange(evt);
180: if (SingleModuleProperties.NB_PLATFORM_PROPERTY.equals(evt
181: .getPropertyName())) {
182: fillUpCategoryValue();
183: }
184: }
185:
186: private String getSelectedCategory() {
187: String cat = (String) categoryValue.getSelectedItem();
188: return CustomizerComponentFactory.WAIT_VALUE.equals(cat) ? getCategory()
189: : cat;
190: }
191:
192: /** This method is called from within the constructor to
193: * initialize the form.
194: * WARNING: Do NOT modify this code. The content of this method is
195: * always regenerated by the Form Editor.
196: */
197: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
198: private void initComponents() {
199: java.awt.GridBagConstraints gridBagConstraints;
200:
201: name = new javax.swing.JLabel();
202: nameValue = new javax.swing.JTextField();
203: categoryLabel = new javax.swing.JLabel();
204: categoryValue = new javax.swing.JComboBox();
205: shortDesc = new javax.swing.JLabel();
206: shortDescValue = new javax.swing.JTextField();
207: longDesc = new javax.swing.JLabel();
208: hackPanel = new javax.swing.JPanel();
209: longDescValueSP = new javax.swing.JScrollPane();
210: longDescValue = new javax.swing.JTextArea();
211: showInPluginManagerCheckbox = new javax.swing.JCheckBox();
212:
213: setLayout(new java.awt.GridBagLayout());
214:
215: name.setLabelFor(nameValue);
216: org.openide.awt.Mnemonics.setLocalizedText(name,
217: org.openide.util.NbBundle.getMessage(
218: CustomizerDisplay.class, "LBL_DisplayName")); // NOI18N
219: gridBagConstraints = new java.awt.GridBagConstraints();
220: gridBagConstraints.gridx = 0;
221: gridBagConstraints.gridy = 0;
222: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
223: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
224: add(name, gridBagConstraints);
225: gridBagConstraints = new java.awt.GridBagConstraints();
226: gridBagConstraints.gridx = 1;
227: gridBagConstraints.gridy = 0;
228: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
229: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
230: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
231: add(nameValue, gridBagConstraints);
232:
233: categoryLabel.setLabelFor(categoryValue);
234: org.openide.awt.Mnemonics
235: .setLocalizedText(categoryLabel,
236: org.openide.util.NbBundle.getMessage(
237: CustomizerDisplay.class,
238: "LBL_DisplayCategory")); // NOI18N
239: gridBagConstraints = new java.awt.GridBagConstraints();
240: gridBagConstraints.gridx = 0;
241: gridBagConstraints.gridy = 1;
242: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
243: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
244: add(categoryLabel, gridBagConstraints);
245:
246: categoryValue.setEditable(true);
247: gridBagConstraints = new java.awt.GridBagConstraints();
248: gridBagConstraints.gridx = 1;
249: gridBagConstraints.gridy = 1;
250: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
251: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
252: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
253: add(categoryValue, gridBagConstraints);
254:
255: shortDesc.setLabelFor(shortDescValue);
256: org.openide.awt.Mnemonics.setLocalizedText(shortDesc,
257: org.openide.util.NbBundle
258: .getMessage(CustomizerDisplay.class,
259: "LBL_ShortDescription")); // NOI18N
260: gridBagConstraints = new java.awt.GridBagConstraints();
261: gridBagConstraints.gridx = 0;
262: gridBagConstraints.gridy = 2;
263: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
264: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
265: add(shortDesc, gridBagConstraints);
266: gridBagConstraints = new java.awt.GridBagConstraints();
267: gridBagConstraints.gridx = 1;
268: gridBagConstraints.gridy = 2;
269: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
271: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
272: add(shortDescValue, gridBagConstraints);
273:
274: longDesc.setLabelFor(longDescValue);
275: org.openide.awt.Mnemonics
276: .setLocalizedText(longDesc, org.openide.util.NbBundle
277: .getMessage(CustomizerDisplay.class,
278: "LBL_LongDescription")); // NOI18N
279: gridBagConstraints = new java.awt.GridBagConstraints();
280: gridBagConstraints.gridx = 0;
281: gridBagConstraints.gridy = 3;
282: gridBagConstraints.gridwidth = 2;
283: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
284: gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 6);
285: add(longDesc, gridBagConstraints);
286:
287: hackPanel.setLayout(new java.awt.BorderLayout());
288:
289: longDescValue.setLineWrap(true);
290: longDescValue.setRows(10);
291: longDescValue.setWrapStyleWord(true);
292: longDescValueSP.setViewportView(longDescValue);
293:
294: hackPanel.add(longDescValueSP, java.awt.BorderLayout.CENTER);
295:
296: gridBagConstraints = new java.awt.GridBagConstraints();
297: gridBagConstraints.gridx = 0;
298: gridBagConstraints.gridy = 4;
299: gridBagConstraints.gridwidth = 2;
300: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
301: gridBagConstraints.weightx = 1.0;
302: gridBagConstraints.weighty = 1.0;
303: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
304: add(hackPanel, gridBagConstraints);
305:
306: org.openide.awt.Mnemonics
307: .setLocalizedText(
308: showInPluginManagerCheckbox,
309: org.openide.util.NbBundle
310: .getMessage(CustomizerDisplay.class,
311: "CustomizerDisplay.showInPluginManagerCheckbox.text")); // NOI18N
312: showInPluginManagerCheckbox.setMargin(new java.awt.Insets(0, 0,
313: 0, 0));
314: showInPluginManagerCheckbox
315: .addActionListener(new java.awt.event.ActionListener() {
316: public void actionPerformed(
317: java.awt.event.ActionEvent evt) {
318: showInPluginManagerCheckboxActionPerformed(evt);
319: }
320: });
321: gridBagConstraints = new java.awt.GridBagConstraints();
322: gridBagConstraints.gridx = 0;
323: gridBagConstraints.gridy = 5;
324: gridBagConstraints.gridwidth = 2;
325: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
326: add(showInPluginManagerCheckbox, gridBagConstraints);
327: }// </editor-fold>//GEN-END:initComponents
328:
329: private void showInPluginManagerCheckboxActionPerformed(
330: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showInPluginManagerCheckboxActionPerformed
331: showInPluginManagerCheckboxChanged = true;
332: }//GEN-LAST:event_showInPluginManagerCheckboxActionPerformed
333:
334: // Variables declaration - do not modify//GEN-BEGIN:variables
335: private javax.swing.JLabel categoryLabel;
336: private javax.swing.JComboBox categoryValue;
337: private javax.swing.JPanel hackPanel;
338: private javax.swing.JLabel longDesc;
339: private javax.swing.JTextArea longDescValue;
340: private javax.swing.JScrollPane longDescValueSP;
341: private javax.swing.JLabel name;
342: private javax.swing.JTextField nameValue;
343: private javax.swing.JLabel shortDesc;
344: private javax.swing.JTextField shortDescValue;
345: private javax.swing.JCheckBox showInPluginManagerCheckbox;
346:
347: // End of variables declaration//GEN-END:variables
348:
349: private static String getMessage(String key) {
350: return NbBundle.getMessage(CustomizerDisplay.class, key);
351: }
352:
353: private void initAccessibility() {
354: longDescValue.getAccessibleContext().setAccessibleDescription(
355: getMessage("ACSD_LongDescValue"));
356: nameValue.getAccessibleContext().setAccessibleDescription(
357: getMessage("ACSD_NameValue"));
358: shortDescValue.getAccessibleContext().setAccessibleDescription(
359: getMessage("ACSD_ShortDescValue"));
360: }
361:
362: }
|