001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2008 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-2008 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.ruby.rubyproject.ui.wizards;
043:
044: import java.awt.event.ActionEvent;
045: import java.awt.event.ActionListener;
046: import java.beans.PropertyChangeEvent;
047: import java.beans.PropertyChangeListener;
048: import java.text.MessageFormat;
049: import java.util.StringTokenizer;
050: import javax.swing.event.DocumentListener;
051: import javax.swing.event.DocumentEvent;
052: import org.netbeans.modules.ruby.platform.PlatformComponentFactory;
053: import org.netbeans.modules.ruby.platform.RubyPlatformCustomizer;
054: import org.netbeans.modules.ruby.rubyproject.Util;
055: import org.openide.WizardDescriptor;
056: import org.openide.WizardValidationException;
057: import org.openide.util.NbBundle;
058: import org.openide.util.Utilities;
059:
060: public final class PanelOptionsVisual extends SettingsPanel implements
061: ActionListener, PropertyChangeListener {
062:
063: private static boolean lastMainClassCheck = true; // XXX Store somewhere
064:
065: private PanelConfigureProject panel;
066: private boolean valid;
067:
068: public PanelOptionsVisual(PanelConfigureProject panel, int type) {
069: initComponents();
070: Util.preselectWizardPlatform(platforms);
071: this .panel = panel;
072: fireChangeEvent();
073:
074: PlatformComponentFactory.addPlatformChangeListener(platforms,
075: new PlatformComponentFactory.PlatformChangeListener() {
076: public void platformChanged() {
077: fireChangeEvent();
078: }
079: });
080:
081: switch (type) {
082: // case NewRubyProjectWizardIterator.TYPE_LIB:
083: // setAsMainCheckBox.setVisible( false );
084: // createMainCheckBox.setVisible( false );
085: // mainClassTextField.setVisible( false );
086: // break;
087: case NewRubyProjectWizardIterator.TYPE_APP:
088: createMainCheckBox.addActionListener(this );
089: createMainCheckBox.setSelected(lastMainClassCheck);
090: mainClassTextField.setEnabled(lastMainClassCheck);
091: break;
092: case NewRubyProjectWizardIterator.TYPE_EXT:
093: setAsMainCheckBox.setVisible(true);
094: createMainCheckBox.setVisible(false);
095: mainClassTextField.setVisible(false);
096: break;
097: }
098:
099: this .mainClassTextField.getDocument().addDocumentListener(
100: new DocumentListener() {
101:
102: public void insertUpdate(DocumentEvent e) {
103: mainClassChanged();
104: }
105:
106: public void removeUpdate(DocumentEvent e) {
107: mainClassChanged();
108: }
109:
110: public void changedUpdate(DocumentEvent e) {
111: mainClassChanged();
112: }
113:
114: });
115: }
116:
117: public @Override
118: void removeNotify() {
119: Util.storeWizardPlatform(platforms);
120: super .removeNotify();
121: }
122:
123: public void actionPerformed(ActionEvent e) {
124: if (e.getSource() == createMainCheckBox) {
125: lastMainClassCheck = createMainCheckBox.isSelected();
126: mainClassTextField.setEnabled(lastMainClassCheck);
127: fireChangeEvent();
128: }
129: }
130:
131: public void propertyChange(PropertyChangeEvent event) {
132: if ("roots".equals(event.getPropertyName())) {
133: fireChangeEvent();
134: }
135: if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event
136: .getPropertyName())) {
137: String newProjectName = NewRubyProjectWizardIterator
138: .getPackageName((String) event.getNewValue());
139: if (!Utilities.isJavaIdentifier(newProjectName)) {
140: newProjectName = NbBundle.getMessage(
141: PanelOptionsVisual.class,
142: "TXT_PackageNameSuffix", newProjectName);
143: }
144: this .mainClassTextField.setText(MessageFormat.format(
145: NbBundle.getMessage(PanelOptionsVisual.class,
146: "TXT_ClassName"),
147: new Object[] { newProjectName }));
148: }
149: }
150:
151: private void fireChangeEvent() {
152: this .panel.fireChangeEvent();
153: }
154:
155: /** This method is called from within the constructor to
156: * initialize the form.
157: * WARNING: Do NOT modify this code. The content of this method is
158: * always regenerated by the Form Editor.
159: */
160: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
161: private void initComponents() {
162:
163: setAsMainCheckBox = new javax.swing.JCheckBox();
164: createMainCheckBox = new javax.swing.JCheckBox();
165: mainClassTextField = new javax.swing.JTextField();
166: rubyPlatformLabel = new javax.swing.JLabel();
167: platforms = org.netbeans.modules.ruby.platform.PlatformComponentFactory
168: .getRubyPlatformsComboxBox();
169: manageButton = new javax.swing.JButton();
170:
171: setAsMainCheckBox.setSelected(true);
172: org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox,
173: org.openide.util.NbBundle.getBundle(
174: PanelOptionsVisual.class).getString(
175: "LBL_setAsMainCheckBox")); // NOI18N
176: setAsMainCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
177:
178: createMainCheckBox.setSelected(true);
179: org.openide.awt.Mnemonics.setLocalizedText(createMainCheckBox,
180: org.openide.util.NbBundle.getBundle(
181: PanelOptionsVisual.class).getString(
182: "LBL_createMainCheckBox")); // NOI18N
183: createMainCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
184:
185: rubyPlatformLabel.setLabelFor(platforms);
186: org.openide.awt.Mnemonics.setLocalizedText(rubyPlatformLabel,
187: org.openide.util.NbBundle.getMessage(
188: PanelOptionsVisual.class, "RubyPlatformLabel")); // NOI18N
189:
190: org.openide.awt.Mnemonics.setLocalizedText(manageButton,
191: org.openide.util.NbBundle.getMessage(
192: PanelOptionsVisual.class, "RubyHomeBrowse")); // NOI18N
193: manageButton
194: .addActionListener(new java.awt.event.ActionListener() {
195: public void actionPerformed(
196: java.awt.event.ActionEvent evt) {
197: manageButtonActionPerformed(evt);
198: }
199: });
200:
201: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
202: this );
203: this .setLayout(layout);
204: layout
205: .setHorizontalGroup(layout
206: .createParallelGroup(
207: org.jdesktop.layout.GroupLayout.LEADING)
208: .add(
209: layout
210: .createSequentialGroup()
211: .add(
212: layout
213: .createParallelGroup(
214: org.jdesktop.layout.GroupLayout.LEADING)
215: .add(
216: layout
217: .createSequentialGroup()
218: .add(
219: layout
220: .createParallelGroup(
221: org.jdesktop.layout.GroupLayout.LEADING)
222: .add(
223: setAsMainCheckBox)
224: .add(
225: layout
226: .createSequentialGroup()
227: .add(
228: rubyPlatformLabel)
229: .addPreferredGap(
230: org.jdesktop.layout.LayoutStyle.RELATED)
231: .add(
232: platforms,
233: 0,
234: 344,
235: Short.MAX_VALUE)))
236: .addPreferredGap(
237: org.jdesktop.layout.LayoutStyle.RELATED)
238: .add(
239: manageButton))
240: .add(
241: layout
242: .createSequentialGroup()
243: .add(
244: createMainCheckBox)
245: .addPreferredGap(
246: org.jdesktop.layout.LayoutStyle.RELATED)
247: .add(
248: mainClassTextField,
249: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
250: 419,
251: Short.MAX_VALUE)))
252: .addContainerGap()));
253: layout
254: .setVerticalGroup(layout
255: .createParallelGroup(
256: org.jdesktop.layout.GroupLayout.LEADING)
257: .add(
258: layout
259: .createSequentialGroup()
260: .add(setAsMainCheckBox)
261: .addPreferredGap(
262: org.jdesktop.layout.LayoutStyle.RELATED)
263: .add(
264: layout
265: .createParallelGroup(
266: org.jdesktop.layout.GroupLayout.BASELINE)
267: .add(
268: createMainCheckBox)
269: .add(
270: mainClassTextField,
271: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
272: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
273: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
274: .add(18, 18, 18)
275: .add(
276: layout
277: .createParallelGroup(
278: org.jdesktop.layout.GroupLayout.BASELINE)
279: .add(
280: rubyPlatformLabel)
281: .add(
282: platforms,
283: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
284: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
285: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
286: .add(
287: manageButton))
288: .addContainerGap(
289: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
290: Short.MAX_VALUE)));
291:
292: setAsMainCheckBox.getAccessibleContext().setAccessibleName(
293: org.openide.util.NbBundle.getBundle(
294: PanelOptionsVisual.class).getString(
295: "ACSN_setAsMainCheckBox")); // NOI18N
296: setAsMainCheckBox.getAccessibleContext()
297: .setAccessibleDescription(
298: org.openide.util.NbBundle.getBundle(
299: PanelOptionsVisual.class).getString(
300: "ACSD_setAsMainCheckBox")); // NOI18N
301: createMainCheckBox.getAccessibleContext().setAccessibleName(
302: org.openide.util.NbBundle.getBundle(
303: PanelOptionsVisual.class).getString(
304: "ACSN_createMainCheckBox")); // NOI18N
305: createMainCheckBox.getAccessibleContext()
306: .setAccessibleDescription(
307: org.openide.util.NbBundle.getBundle(
308: PanelOptionsVisual.class).getString(
309: "ACSD_createMainCheckBox")); // NOI18N
310: mainClassTextField.getAccessibleContext().setAccessibleName(
311: org.openide.util.NbBundle.getBundle(
312: PanelOptionsVisual.class).getString(
313: "ASCN_mainClassTextFiled")); // NOI18N
314: mainClassTextField.getAccessibleContext()
315: .setAccessibleDescription(
316: org.openide.util.NbBundle.getBundle(
317: PanelOptionsVisual.class).getString(
318: "ASCD_mainClassTextFiled")); // NOI18N
319: rubyPlatformLabel
320: .getAccessibleContext()
321: .setAccessibleDescription(
322: org.openide.util.NbBundle
323: .getMessage(PanelOptionsVisual.class,
324: "PanelOptionsVisual.rubyPlatformLabel.AccessibleContext.accessibleDescription")); // NOI18N
325: manageButton
326: .getAccessibleContext()
327: .setAccessibleDescription(
328: org.openide.util.NbBundle
329: .getMessage(PanelOptionsVisual.class,
330: "PanelOptionsVisual.manageButton.AccessibleContext.accessibleDescription")); // NOI18N
331:
332: getAccessibleContext().setAccessibleName(
333: org.openide.util.NbBundle.getMessage(
334: PanelOptionsVisual.class,
335: "ACSN_PanelOptionsVisual")); // NOI18N
336: getAccessibleContext().setAccessibleDescription(
337: org.openide.util.NbBundle.getMessage(
338: PanelOptionsVisual.class,
339: "ACSD_PanelOptionsVisual")); // NOI18N
340: }// </editor-fold>//GEN-END:initComponents
341:
342: private void manageButtonActionPerformed(
343: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageButtonActionPerformed
344: RubyPlatformCustomizer.manage(platforms);
345: }//GEN-LAST:event_manageButtonActionPerformed
346:
347: boolean valid(WizardDescriptor settings) {
348: if (PlatformComponentFactory.getPlatform(platforms) == null) {
349: return false;
350: }
351: if (mainClassTextField.isVisible()
352: && mainClassTextField.isEnabled()) {
353: if (!valid) {
354: settings.putProperty("WizardPanel_errorMessage", // NOI18N
355: NbBundle.getMessage(PanelOptionsVisual.class,
356: "ERROR_IllegalMainClassName")); //NOI18N
357: }
358: return this .valid;
359: } else {
360: return true;
361: }
362: }
363:
364: void read(WizardDescriptor d) {
365: }
366:
367: void validate(WizardDescriptor d) throws WizardValidationException {
368: // nothing to validate
369: }
370:
371: void store(WizardDescriptor d) {
372: d.putProperty( /*XXX Define somewhere */"setAsMain",
373: setAsMainCheckBox.isSelected()
374: && setAsMainCheckBox.isVisible() ? Boolean.TRUE
375: : Boolean.FALSE); // NOI18N
376: d
377: .putProperty(
378: /*XXX Define somewhere */"mainClass",
379: createMainCheckBox.isSelected()
380: && createMainCheckBox.isVisible() ? mainClassTextField
381: .getText()
382: : null); // NOI18N
383: d.putProperty("platform", PlatformComponentFactory
384: .getPlatform(platforms));
385: // XXX
386: // RubyInstallation.getInstance().removePropertyChangeListener(this);
387: }
388:
389: // Variables declaration - do not modify//GEN-BEGIN:variables
390: private javax.swing.JCheckBox createMainCheckBox;
391: private javax.swing.JTextField mainClassTextField;
392: private javax.swing.JButton manageButton;
393: private javax.swing.JComboBox platforms;
394: private javax.swing.JLabel rubyPlatformLabel;
395: private javax.swing.JCheckBox setAsMainCheckBox;
396:
397: // End of variables declaration//GEN-END:variables
398:
399: private void mainClassChanged() {
400: String mainClassName = this .mainClassTextField.getText();
401: StringTokenizer tk = new StringTokenizer(mainClassName, "."); //NOI18N
402: valid = true;
403: while (tk.hasMoreTokens()) {
404: String token = tk.nextToken();
405: if (token.length() == 0
406: || /* !Utilities.isJavaIdentifier(token)*/token
407: .equals(" ")) {
408: valid = false;
409: break;
410: }
411: }
412: fireChangeEvent();
413: }
414:
415: }
|