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.uml.reporting.wizard;
043:
044: import java.io.File;
045: import javax.swing.DefaultComboBoxModel;
046: import javax.swing.JFileChooser;
047: import javax.swing.event.DocumentEvent;
048: import javax.swing.event.DocumentListener;
049: import org.netbeans.api.project.Project;
050: import org.netbeans.modules.uml.project.ProjectCellRenderer;
051: import org.netbeans.modules.uml.project.ProjectUtil;
052: import org.netbeans.modules.uml.project.UMLProject;
053: import org.openide.WizardDescriptor;
054: import org.openide.filesystems.FileObject;
055: import org.openide.filesystems.FileUtil;
056: import org.openide.util.NbBundle;
057:
058: /**
059: *
060: * @author Sheryl
061: */
062: public class ReportLocationPanel extends WizardPanelBase implements
063: WizardDescriptor.FinishablePanel {
064:
065: private Project selected;
066: private File folder;
067: private WizardDescriptor wizardDescriptor;
068:
069: /**
070: * Creates new form ReportLocationPanel
071: */
072: public ReportLocationPanel() {
073: initComponents();
074: DocumentListener docListener = new DocumentListener() {
075: public void changedUpdate(DocumentEvent e) {
076: }
077:
078: public void insertUpdate(DocumentEvent e) {
079: checkValidity();
080: }
081:
082: public void removeUpdate(DocumentEvent e) {
083: checkValidity();
084: }
085: };
086:
087: locationTextField.getDocument()
088: .addDocumentListener(docListener);
089: initValue();
090: }
091:
092: public boolean isFinishPanel() {
093: return true;
094: }
095:
096: public String getName() {
097: return NbBundle.getMessage(ReportLocationPanel.class,
098: "TITLE_ReportLocationPanel_WizardTitle");
099: }
100:
101: public void initValue() {
102: Project[] umlProjects = ProjectUtil.getOpenUMLProjects();
103: Project[] selectedProjects = ProjectUtil
104: .getSelectedProjects(UMLProject.class);
105: if (selectedProjects.length > 0)
106: selected = selectedProjects[0];
107: else if (umlProjects.length > 0)
108: selected = umlProjects[0];
109: DefaultComboBoxModel projectsModel = new DefaultComboBoxModel(
110: umlProjects);
111: projectComboBox.setModel(projectsModel);
112: projectComboBox.setRenderer(new ProjectCellRenderer());
113: projectComboBox.setSelectedItem(selected);
114: }
115:
116: public Project getSelectedProject() {
117: return (Project) projectComboBox.getSelectedItem();
118: }
119:
120: private void setReportFolder(File f) {
121: this .folder = f;
122: locationTextField.setText(f.getAbsolutePath());
123: setValid(true);
124: }
125:
126: public File getReportFolder() {
127: return new File(locationTextField.getText());
128: }
129:
130: private void checkValidity() {
131: String location = locationTextField.getText().trim();
132: File dir = new File(location);
133:
134: wizardDescriptor.putProperty("WizardPanel_errorMessage", null);
135: if (dir.exists() && !dir.isDirectory()) {
136: setValid(false);
137: wizardDescriptor.putProperty("WizardPanel_errorMessage",
138: NbBundle.getMessage(ReportLocationPanel.class,
139: "MSG_ReportLocationPanel_InvalidFolder"));
140: } else if (dir.exists() && dir.listFiles() != null
141: && dir.listFiles().length > 0) {
142: setValid(true);
143: wizardDescriptor.putProperty("WizardPanel_errorMessage",
144: NbBundle.getMessage(ReportLocationPanel.class,
145: "MSG_ReportLocationPanel_FolderExists"));
146: }
147: }
148:
149: public void readSettings(Object object) {
150: ReportWizardSettings settings = (ReportWizardSettings) object;
151: wizardDescriptor = settings.getWizardDescriptor();
152: Project p = settings.getProject();
153: folder = settings.getReportFolder();
154: if (p != null)
155: projectComboBox.setSelectedItem(p);
156: if (folder != null)
157: locationTextField.setText(folder.getAbsolutePath());
158: else {
159: FileObject fo = ((Project) projectComboBox
160: .getSelectedItem()).getProjectDirectory();
161: String path = FileUtil.toFile(fo.getParent())
162: .getAbsolutePath();
163:
164: locationTextField.setText(path);
165: }
166: }
167:
168: public void storeSettings(Object object) {
169: ReportWizardSettings settings = (ReportWizardSettings) object;
170:
171: settings.setProject(getSelectedProject());
172: settings.setReportFolder(getReportFolder());
173: }
174:
175: /** This method is called from within the constructor to
176: * initialize the form.
177: * WARNING: Do NOT modify this code. The content of this method is
178: * always regenerated by the Form Editor.
179: */
180: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
181: private void initComponents() {
182: java.awt.GridBagConstraints gridBagConstraints;
183:
184: jPanel1 = new javax.swing.JPanel();
185: ProjectLbl = new javax.swing.JLabel();
186: projectComboBox = new javax.swing.JComboBox();
187: locationLbl = new javax.swing.JLabel();
188: locationTextField = new javax.swing.JTextField();
189: browseBtn = new javax.swing.JButton();
190: jSeparator1 = new javax.swing.JSeparator();
191: msgPanel = new javax.swing.JPanel();
192:
193: setLayout(new java.awt.GridBagLayout());
194:
195: setMinimumSize(new java.awt.Dimension(180, 175));
196: setPreferredSize(new java.awt.Dimension(180, 175));
197: org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
198: jPanel1);
199: jPanel1.setLayout(jPanel1Layout);
200: jPanel1Layout.setHorizontalGroup(jPanel1Layout
201: .createParallelGroup(
202: org.jdesktop.layout.GroupLayout.LEADING).add(0,
203: 0, Short.MAX_VALUE));
204: jPanel1Layout.setVerticalGroup(jPanel1Layout
205: .createParallelGroup(
206: org.jdesktop.layout.GroupLayout.LEADING).add(0,
207: 0, Short.MAX_VALUE));
208: gridBagConstraints = new java.awt.GridBagConstraints();
209: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
210: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
211: gridBagConstraints.weightx = 1.0;
212: gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
213: add(jPanel1, gridBagConstraints);
214:
215: ProjectLbl.setText(java.util.ResourceBundle.getBundle(
216: "org/netbeans/modules/uml/reporting/wizard/Bundle")
217: .getString("LBL_ReportLocationPanel_Project"));
218: gridBagConstraints = new java.awt.GridBagConstraints();
219: gridBagConstraints.gridx = 0;
220: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
221: gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
222: add(ProjectLbl, gridBagConstraints);
223:
224: projectComboBox
225: .setModel(new javax.swing.DefaultComboBoxModel(
226: new String[] { "Item 1", "Item 2", "Item 3",
227: "Item 4" }));
228: gridBagConstraints = new java.awt.GridBagConstraints();
229: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
230: gridBagConstraints.weightx = 1.0;
231: gridBagConstraints.insets = new java.awt.Insets(0, 10, 10, 10);
232: add(projectComboBox, gridBagConstraints);
233:
234: locationLbl.setText(java.util.ResourceBundle.getBundle(
235: "org/netbeans/modules/uml/reporting/wizard/Bundle")
236: .getString("LBL_ReportLocationPanel_ReportLocation"));
237: gridBagConstraints = new java.awt.GridBagConstraints();
238: gridBagConstraints.gridx = 0;
239: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
240: gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
241: add(locationLbl, gridBagConstraints);
242:
243: locationTextField.setText("jTextField1");
244: gridBagConstraints = new java.awt.GridBagConstraints();
245: gridBagConstraints.gridy = 2;
246: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
247: gridBagConstraints.weightx = 1.0;
248: gridBagConstraints.insets = new java.awt.Insets(0, 10, 10, 10);
249: add(locationTextField, gridBagConstraints);
250:
251: browseBtn.setText(java.util.ResourceBundle.getBundle(
252: "org/netbeans/modules/uml/reporting/wizard/Bundle")
253: .getString("CTL_ReportLocationPanel"));
254: browseBtn
255: .addActionListener(new java.awt.event.ActionListener() {
256: public void actionPerformed(
257: java.awt.event.ActionEvent evt) {
258: browseBtnActionPerformed(evt);
259: }
260: });
261:
262: gridBagConstraints = new java.awt.GridBagConstraints();
263: gridBagConstraints.gridx = 2;
264: gridBagConstraints.gridy = 2;
265: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
266: gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
267: add(browseBtn, gridBagConstraints);
268:
269: gridBagConstraints = new java.awt.GridBagConstraints();
270: gridBagConstraints.gridx = 0;
271: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
272: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
273: add(jSeparator1, gridBagConstraints);
274:
275: msgPanel.setLayout(new java.awt.BorderLayout());
276:
277: gridBagConstraints = new java.awt.GridBagConstraints();
278: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
279: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
280: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
281: gridBagConstraints.weighty = 1.0;
282: add(msgPanel, gridBagConstraints);
283:
284: }// </editor-fold>//GEN-END:initComponents
285:
286: private void browseBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseBtnActionPerformed
287: JFileChooser fc = new JFileChooser();
288: fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
289: fc.setMultiSelectionEnabled(false);
290:
291: if (fc.showOpenDialog(fc) == JFileChooser.APPROVE_OPTION) {
292:
293: setReportFolder(fc.getSelectedFile());
294: }
295: }//GEN-LAST:event_browseBtnActionPerformed
296:
297: // Variables declaration - do not modify//GEN-BEGIN:variables
298: private javax.swing.JLabel ProjectLbl;
299: private javax.swing.JButton browseBtn;
300: private javax.swing.JPanel jPanel1;
301: private javax.swing.JSeparator jSeparator1;
302: private javax.swing.JLabel locationLbl;
303: private javax.swing.JTextField locationTextField;
304: private javax.swing.JPanel msgPanel;
305: private javax.swing.JComboBox projectComboBox;
306: // End of variables declaration//GEN-END:variables
307:
308: }
|