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-2007 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.winsys;
043:
044: import java.io.IOException;
045: import java.util.ArrayList;
046: import java.util.Collection;
047: import javax.swing.DefaultComboBoxModel;
048: import org.netbeans.modules.apisupport.project.layers.LayerUtils;
049: import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
050: import org.openide.WizardDescriptor;
051: import org.openide.filesystems.FileObject;
052: import org.openide.filesystems.FileSystem;
053: import org.openide.util.HelpCtx;
054: import org.openide.util.NbBundle;
055:
056: /**
057: * the first panel in TopComponent wizard
058: *
059: * @author Milos Kleint
060: */
061: final class BasicSettingsPanel extends BasicWizardIterator.Panel {
062:
063: private NewTCIterator.DataModel data;
064: private static final String[] DEFAULT_MODES = new String[] { "editor" //NOI18N
065: };
066:
067: /**
068: * Creates new form BasicSettingsPanel
069: */
070: public BasicSettingsPanel(WizardDescriptor setting,
071: NewTCIterator.DataModel data) {
072: super (setting);
073: this .data = data;
074: initComponents();
075: initAccessibility();
076: setupCombo();
077: putClientProperty("NewFileWizard_Title",
078: getMessage("LBL_TCWizardTitle"));
079: }
080:
081: private void checkValidity() {
082: //TODO: probably nothing...
083: markValid();
084: }
085:
086: // public void addNotify() {
087: // super.addNotify();
088: // attachDocumentListeners();
089: // checkValidity();
090: // }
091: //
092: // public void removeNotify() {
093: // // prevent checking when the panel is not "active"
094: // removeDocumentListeners();
095: // super.removeNotify();
096: // }
097: //
098: // private void attachDocumentListeners() {
099: // if (!listenersAttached) {
100: // listenersAttached = true;
101: // }
102: // }
103: //
104: // private void removeDocumentListeners() {
105: // if (listenersAttached) {
106: // listenersAttached = false;
107: // }
108: // }
109:
110: private void setupCombo() {
111: //TODO get dynamically from layers??
112: String[] modes = null;
113: try {
114: FileSystem fs = LayerUtils
115: .getEffectiveSystemFilesystem(data.getProject());
116: FileObject foRoot = fs.getRoot().getFileObject(
117: "Windows2/Modes"); //NOI18N
118: if (foRoot != null) {
119: FileObject[] fos = foRoot.getChildren();
120: Collection<String> col = new ArrayList<String>();
121: for (FileObject fo : fos) {
122: if (fo.isData() && "wsmode".equals(fo.getExt())) { //NOI18N
123: col.add(fo.getName());
124: }
125: }
126: modes = col.toArray(new String[col.size()]);
127: } else {
128: modes = DEFAULT_MODES;
129: }
130: } catch (IOException exc) {
131: modes = DEFAULT_MODES;
132:
133: }
134:
135: comMode.setModel(new DefaultComboBoxModel(modes));
136: }
137:
138: protected void storeToDataModel() {
139: data.setOpened(cbOpenedOnStart.isSelected());
140: data.setMode((String) comMode.getSelectedItem());
141: }
142:
143: protected void readFromDataModel() {
144: cbOpenedOnStart.setSelected(data.isOpened());
145: if (data.getMode() != null) {
146: comMode.setSelectedItem(data.getMode());
147: } else {
148: comMode.setSelectedItem("output");//NOI18N
149: }
150: checkValidity();
151: }
152:
153: protected String getPanelName() {
154: return getMessage("LBL_BasicSettings_Title");
155: }
156:
157: protected HelpCtx getHelp() {
158: return new HelpCtx(BasicSettingsPanel.class);
159: }
160:
161: private static String getMessage(String key) {
162: return NbBundle.getMessage(BasicSettingsPanel.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: lblMode = new javax.swing.JLabel();
175: comMode = new javax.swing.JComboBox();
176: cbOpenedOnStart = new javax.swing.JCheckBox();
177:
178: setLayout(new java.awt.GridBagLayout());
179:
180: lblMode.setLabelFor(comMode);
181: org.openide.awt.Mnemonics.setLocalizedText(lblMode,
182: org.openide.util.NbBundle.getMessage(
183: BasicSettingsPanel.class, "LBL_Mode"));
184: gridBagConstraints = new java.awt.GridBagConstraints();
185: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
186: gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0);
187: add(lblMode, gridBagConstraints);
188:
189: gridBagConstraints = new java.awt.GridBagConstraints();
190: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
191: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
192: gridBagConstraints.weightx = 0.1;
193: gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 6);
194: add(comMode, gridBagConstraints);
195:
196: org.openide.awt.Mnemonics.setLocalizedText(cbOpenedOnStart,
197: org.openide.util.NbBundle.getMessage(
198: BasicSettingsPanel.class, "LBL_OpenOnStart"));
199: cbOpenedOnStart.setBorder(new javax.swing.border.EmptyBorder(
200: new java.awt.Insets(0, 0, 0, 0)));
201: cbOpenedOnStart.setMargin(new java.awt.Insets(0, 0, 0, 0));
202: gridBagConstraints = new java.awt.GridBagConstraints();
203: gridBagConstraints.gridx = 0;
204: gridBagConstraints.gridy = 1;
205: gridBagConstraints.gridwidth = 2;
206: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
207: gridBagConstraints.weighty = 0.1;
208: gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0);
209: add(cbOpenedOnStart, gridBagConstraints);
210:
211: }
212:
213: // </editor-fold>//GEN-END:initComponents
214:
215: // Variables declaration - do not modify//GEN-BEGIN:variables
216: private javax.swing.JCheckBox cbOpenedOnStart;
217: private javax.swing.JComboBox comMode;
218: private javax.swing.JLabel lblMode;
219:
220: // End of variables declaration//GEN-END:variables
221:
222: private void initAccessibility() {
223: this .getAccessibleContext().setAccessibleDescription(
224: getMessage("ACS_BasicSettingsPanel"));
225: cbOpenedOnStart.getAccessibleContext()
226: .setAccessibleDescription(
227: getMessage("ACS_CTL_OpenOnStart"));
228: comMode.getAccessibleContext().setAccessibleDescription(
229: getMessage("ACS_CTL_Mode"));
230: }
231:
232: }
|