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.wizard.action;
043:
044: import java.util.ArrayList;
045: import java.util.Collection;
046: import java.util.Collections;
047: import java.util.HashMap;
048: import java.util.Map;
049: import java.util.StringTokenizer;
050: import javax.swing.ComboBoxModel;
051: import javax.swing.DefaultComboBoxModel;
052: import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
053: import org.openide.WizardDescriptor;
054: import org.openide.util.HelpCtx;
055: import org.openide.util.NbBundle;
056:
057: /**
058: * The first panel in the <em>New Action Wizard</em>.
059: *
060: * @author Martin Krauskopf
061: */
062: final class ActionTypePanel extends BasicWizardIterator.Panel {
063:
064: private static final Map<String, String> NAME_TO_FQCN;
065:
066: static {
067: Map<String, String> map = new HashMap<String, String>(
068: DataModel.PREDEFINED_COOKIE_CLASSES.length);
069: for (String fqcn : DataModel.PREDEFINED_COOKIE_CLASSES) {
070: String name = DataModel.parseClassName(fqcn);
071: map.put(name, fqcn);
072: }
073: NAME_TO_FQCN = Collections.unmodifiableMap(map);
074: }
075:
076: private DataModel data;
077:
078: public ActionTypePanel(final WizardDescriptor setting,
079: final DataModel data) {
080: super (setting);
081: this .data = data;
082: initComponents();
083: initAccesibility();
084: putClientProperty("NewFileWizard_Title",
085: getMessage("LBL_ActionWizardTitle"));
086: cookieClass.setModel(createCookieClassModel());
087: }
088:
089: protected String getPanelName() {
090: return getMessage("LBL_ActionType_Title");
091: }
092:
093: protected void storeToDataModel() {
094: data.setAlwaysEnabled(alwaysEnabled.isSelected());
095: data.setCookieClasses(getCookieClasses());
096: data.setMultiSelection(isMultiSelection());
097: }
098:
099: private String[] getCookieClasses() {
100: StringTokenizer classesST = new StringTokenizer(cookieClass
101: .getEditor().getItem().toString(), ", "); // NOI18N
102: Collection<String> classes = new ArrayList<String>();
103: while (classesST.hasMoreTokens()) {
104: String clazz = classesST.nextToken().trim();
105: String fqcn = NAME_TO_FQCN.get(clazz);
106: classes.add(fqcn == null ? clazz : fqcn);
107: }
108: String[] s = new String[classes.size()];
109: return classes.toArray(s);
110: }
111:
112: protected void readFromDataModel() {
113: condionallyEnabledActionPerformed(null);
114: markValid();
115: }
116:
117: protected HelpCtx getHelp() {
118: return new HelpCtx(ActionTypePanel.class);
119: }
120:
121: private boolean isMultiSelection() {
122: return modeMultiple.isSelected();
123: }
124:
125: private static String getMessage(String key) {
126: return NbBundle.getMessage(ActionTypePanel.class, key);
127: }
128:
129: private static ComboBoxModel createCookieClassModel() {
130: DefaultComboBoxModel cookieClassModel = new DefaultComboBoxModel();
131: for (String fqcn : DataModel.PREDEFINED_COOKIE_CLASSES) {
132: String name = DataModel.parseClassName(fqcn);
133: cookieClassModel.addElement(name);
134: }
135: return cookieClassModel;
136: }
137:
138: /** This method is called from within the constructor to
139: * initialize the form.
140: * WARNING: Do NOT modify this code. The content of this method is
141: * always regenerated by the Form Editor.
142: */
143: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
144: private void initComponents() {
145: java.awt.GridBagConstraints gridBagConstraints;
146:
147: whenEnabledGroup = new javax.swing.ButtonGroup();
148: modeGroup = new javax.swing.ButtonGroup();
149: alwaysEnabled = new javax.swing.JRadioButton();
150: condionallyEnabled = new javax.swing.JRadioButton();
151: cookieClassTxt = new javax.swing.JLabel();
152: cookieClass = new javax.swing.JComboBox();
153: filler = new javax.swing.JLabel();
154: modeOne = new javax.swing.JRadioButton();
155: modeMultiple = new javax.swing.JRadioButton();
156:
157: setLayout(new java.awt.GridBagLayout());
158:
159: whenEnabledGroup.add(alwaysEnabled);
160: alwaysEnabled.setSelected(true);
161: org.openide.awt.Mnemonics.setLocalizedText(alwaysEnabled,
162: org.openide.util.NbBundle.getMessage(
163: ActionTypePanel.class, "CTL_AlwaysEnabled"));
164: alwaysEnabled.setBorder(javax.swing.BorderFactory
165: .createEmptyBorder(0, 0, 0, 0));
166: alwaysEnabled.setMargin(new java.awt.Insets(0, 0, 0, 0));
167: alwaysEnabled
168: .addActionListener(new java.awt.event.ActionListener() {
169: public void actionPerformed(
170: java.awt.event.ActionEvent evt) {
171: condionallyEnabledActionPerformed(evt);
172: }
173: });
174:
175: gridBagConstraints = new java.awt.GridBagConstraints();
176: gridBagConstraints.gridx = 0;
177: gridBagConstraints.gridy = 0;
178: gridBagConstraints.gridwidth = 2;
179: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
180: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
181: add(alwaysEnabled, gridBagConstraints);
182:
183: whenEnabledGroup.add(condionallyEnabled);
184: org.openide.awt.Mnemonics.setLocalizedText(condionallyEnabled,
185: org.openide.util.NbBundle.getMessage(
186: ActionTypePanel.class,
187: "CTL_ConditionallyEnabled"));
188: condionallyEnabled.setBorder(javax.swing.BorderFactory
189: .createEmptyBorder(0, 0, 0, 0));
190: condionallyEnabled.setMargin(new java.awt.Insets(0, 0, 0, 0));
191: condionallyEnabled
192: .addActionListener(new java.awt.event.ActionListener() {
193: public void actionPerformed(
194: java.awt.event.ActionEvent evt) {
195: condionallyEnabledActionPerformed(evt);
196: }
197: });
198:
199: gridBagConstraints = new java.awt.GridBagConstraints();
200: gridBagConstraints.gridx = 0;
201: gridBagConstraints.gridy = 1;
202: gridBagConstraints.gridwidth = 2;
203: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
204: gridBagConstraints.insets = new java.awt.Insets(24, 0, 0, 0);
205: add(condionallyEnabled, gridBagConstraints);
206:
207: cookieClassTxt.setLabelFor(cookieClass);
208: org.openide.awt.Mnemonics.setLocalizedText(cookieClassTxt,
209: org.openide.util.NbBundle.getMessage(
210: ActionTypePanel.class, "LBL_CookieClass"));
211: gridBagConstraints = new java.awt.GridBagConstraints();
212: gridBagConstraints.gridx = 0;
213: gridBagConstraints.gridy = 2;
214: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
215: gridBagConstraints.insets = new java.awt.Insets(6, 18, 6, 0);
216: add(cookieClassTxt, gridBagConstraints);
217:
218: cookieClass.setEditable(true);
219: gridBagConstraints = new java.awt.GridBagConstraints();
220: gridBagConstraints.gridx = 1;
221: gridBagConstraints.gridy = 2;
222: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
223: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
224: gridBagConstraints.weightx = 1.0;
225: gridBagConstraints.insets = new java.awt.Insets(6, 12, 6, 0);
226: add(cookieClass, gridBagConstraints);
227:
228: gridBagConstraints = new java.awt.GridBagConstraints();
229: gridBagConstraints.gridx = 0;
230: gridBagConstraints.gridy = 5;
231: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
232: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
233: gridBagConstraints.weightx = 1.0;
234: gridBagConstraints.weighty = 1.0;
235: add(filler, gridBagConstraints);
236:
237: modeGroup.add(modeOne);
238: modeOne.setSelected(true);
239: org.openide.awt.Mnemonics.setLocalizedText(modeOne,
240: org.openide.util.NbBundle.getMessage(
241: ActionTypePanel.class, "CTL_ModeOneNode"));
242: modeOne.setBorder(javax.swing.BorderFactory.createEmptyBorder(
243: 0, 0, 0, 0));
244: modeOne.setMargin(new java.awt.Insets(0, 0, 0, 0));
245: gridBagConstraints = new java.awt.GridBagConstraints();
246: gridBagConstraints.gridx = 0;
247: gridBagConstraints.gridy = 3;
248: gridBagConstraints.gridwidth = 2;
249: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
250: gridBagConstraints.insets = new java.awt.Insets(0, 18, 6, 0);
251: add(modeOne, gridBagConstraints);
252:
253: modeGroup.add(modeMultiple);
254: org.openide.awt.Mnemonics.setLocalizedText(modeMultiple,
255: org.openide.util.NbBundle.getMessage(
256: ActionTypePanel.class, "CTL_ModeMultipleNode"));
257: modeMultiple.setBorder(javax.swing.BorderFactory
258: .createEmptyBorder(0, 0, 0, 0));
259: modeMultiple.setMargin(new java.awt.Insets(0, 0, 0, 0));
260: gridBagConstraints = new java.awt.GridBagConstraints();
261: gridBagConstraints.gridx = 0;
262: gridBagConstraints.gridy = 4;
263: gridBagConstraints.gridwidth = 2;
264: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
265: gridBagConstraints.insets = new java.awt.Insets(0, 18, 0, 0);
266: add(modeMultiple, gridBagConstraints);
267:
268: }// </editor-fold>//GEN-END:initComponents
269:
270: private void condionallyEnabledActionPerformed(
271: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_condionallyEnabledActionPerformed
272: boolean enabled = condionallyEnabled.isSelected();
273: cookieClass.setEnabled(enabled);
274: cookieClassTxt.setEnabled(enabled);
275: modeOne.setEnabled(enabled);
276: modeMultiple.setEnabled(enabled);
277: }//GEN-LAST:event_condionallyEnabledActionPerformed
278:
279: // Variables declaration - do not modify//GEN-BEGIN:variables
280: private javax.swing.JRadioButton alwaysEnabled;
281: private javax.swing.JRadioButton condionallyEnabled;
282: private javax.swing.JComboBox cookieClass;
283: private javax.swing.JLabel cookieClassTxt;
284: private javax.swing.JLabel filler;
285: private javax.swing.ButtonGroup modeGroup;
286: private javax.swing.JRadioButton modeMultiple;
287: private javax.swing.JRadioButton modeOne;
288: private javax.swing.ButtonGroup whenEnabledGroup;
289:
290: // End of variables declaration//GEN-END:variables
291:
292: private void initAccesibility() {
293: this .getAccessibleContext().setAccessibleDescription(
294: getMessage("ACS_ActionTypePanel"));
295: alwaysEnabled.getAccessibleContext().setAccessibleDescription(
296: getMessage("ACS_CTL_alwaysEnabled"));
297: condionallyEnabled.getAccessibleContext()
298: .setAccessibleDescription(
299: getMessage("ACS_CTL_condionallyEnabled"));
300: cookieClass.getAccessibleContext().setAccessibleDescription(
301: getMessage("ACS_CTL_cookieClass"));
302: modeMultiple.getAccessibleContext().setAccessibleDescription(
303: getMessage("ACS_CTL_modeMultiple"));
304: modeOne.getAccessibleContext().setAccessibleDescription(
305: getMessage("ACS_CTL_modeOne"));
306: }
307:
308: }
|