1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 /*
23  * SelectPathVisualPanel.java
24  *
25  * Created on February 12, 2003
26  */
27 
28 package org.openoffice.netbeans.modules.office.wizard;
29 
30 import java.util.Hashtable;
31 import java.util.Enumeration;
32 import java.io.File;
33 import java.io.IOException;
34 import javax.swing.JFileChooser;
35 
36 import org.openide.util.NbBundle;
37 import org.openoffice.idesupport.SVersionRCFile;
38 import org.openoffice.idesupport.OfficeInstallation;
39 import org.openoffice.netbeans.modules.office.options.OfficeSettings;
40 
41 /** A single panel for a wizard - the GUI portion.
42  *
43  * @author tomaso
44  */
45 public class SelectPathVisualPanel extends javax.swing.JPanel {
46 
47     /** The wizard panel descriptor associated with this GUI panel.
48      * If you need to fire state changes or something similar, you can
49      * use this handle to do so.
50      */
51     private final SelectPathPanel panel;
52 
53     /** Create the wizard panel and set up some basic properties. */
SelectPathVisualPanel(SelectPathPanel panel)54     public SelectPathVisualPanel(SelectPathPanel panel) {
55         this.panel = panel;
56         initComponents();
57         OfficeInstallation orig = panel.getSelectedPath();
58 
59         try {
60             Enumeration enumer = SVersionRCFile.createInstance().getVersions();
61 
62             while (enumer.hasMoreElements()) {
63                 OfficeInstallation oi = (OfficeInstallation)enumer.nextElement();
64                 installationsComboBox.addItem(oi);
65             }
66         }
67         catch (IOException ioe) {
68             installationsComboBox.addItem("<empty>");
69         }
70 
71         if (orig != null) {
72             installationsComboBox.setSelectedItem(orig);
73             installPath.setText(orig.getPath());
74         }
75 
76         installationsComboBox.addActionListener(
77             new java.awt.event.ActionListener() {
78                 public void actionPerformed(java.awt.event.ActionEvent evt) {
79                     installationsComboBoxActionPerformed(evt);
80                 }
81             }
82         );
83 
84         // Provide a name in the title bar.
85         setName(NbBundle.getMessage(SelectPathVisualPanel.class, "TITLE_SelectPathVisualPanel"));
86         /*
87         // Optional: provide a special description for this pane.
88         // You must have turned on WizardDescriptor.WizardPanel_helpDisplayed
89         // (see descriptor in standard iterator template for an example of this).
90         try {
91             putClientProperty("WizardPanel_helpURL", // NOI18N
92                 new URL("nbresloc:/org/openoffice/netbeans/modules/office/wizard/SelectPathVisualHelp.html")); // NOI18N
93         } catch (MalformedURLException mfue) {
94             throw new IllegalStateException(mfue.toString());
95         }
96          */
97     }
98 
installationsComboBoxActionPerformed( java.awt.event.ActionEvent evt)99     private void installationsComboBoxActionPerformed(
100         java.awt.event.ActionEvent evt) {
101 
102         OfficeInstallation oi =
103             (OfficeInstallation)installationsComboBox.getSelectedItem();
104 
105         installPath.setText(oi.getPath());
106         panel.setSelectedPath(oi);
107     }
108 
109     /** This method is called from within the constructor to
110      * initialize the form.
111      * WARNING: Do NOT modify this code. The content of this method is
112      * always regenerated by the Form Editor.
113      */
initComponents()114     private void initComponents() {//GEN-BEGIN:initComponents
115         java.awt.GridBagConstraints gridBagConstraints;
116 
117         jLabel1 = new javax.swing.JLabel();
118         installPath = new javax.swing.JTextField();
119         jLabel2 = new javax.swing.JLabel();
120         installationsComboBox = new javax.swing.JComboBox();
121         jPanel1 = new javax.swing.JPanel();
122         browseButton = new javax.swing.JButton();
123 
124         setLayout(new java.awt.GridBagLayout());
125 
126         setPreferredSize(new java.awt.Dimension(600, 300));
127         jLabel1.setText("Installations Detected");
128         gridBagConstraints = new java.awt.GridBagConstraints();
129         gridBagConstraints.gridx = 0;
130         gridBagConstraints.gridy = 0;
131         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
132         gridBagConstraints.insets = new java.awt.Insets(12, 12, 11, 2);
133         add(jLabel1, gridBagConstraints);
134 
135         installPath.setEditable(false);
136         gridBagConstraints = new java.awt.GridBagConstraints();
137         gridBagConstraints.gridx = 1;
138         gridBagConstraints.gridy = 1;
139         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
140         gridBagConstraints.weightx = 1.0;
141         gridBagConstraints.insets = new java.awt.Insets(12, 0, 11, 11);
142         add(installPath, gridBagConstraints);
143 
144         jLabel2.setText("Installation Directory");
145         gridBagConstraints = new java.awt.GridBagConstraints();
146         gridBagConstraints.gridx = 0;
147         gridBagConstraints.gridy = 1;
148         gridBagConstraints.insets = new java.awt.Insets(12, 12, 11, 12);
149         add(jLabel2, gridBagConstraints);
150 
151         gridBagConstraints = new java.awt.GridBagConstraints();
152         gridBagConstraints.gridx = 1;
153         gridBagConstraints.gridy = 0;
154         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
156         gridBagConstraints.insets = new java.awt.Insets(11, 0, 11, 11);
157         add(installationsComboBox, gridBagConstraints);
158 
159         gridBagConstraints = new java.awt.GridBagConstraints();
160         gridBagConstraints.gridy = 2;
161         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
162         gridBagConstraints.weighty = 1.0;
163         add(jPanel1, gridBagConstraints);
164 
165         browseButton.setText("Browse...");
166         browseButton.addActionListener(new java.awt.event.ActionListener() {
167             public void actionPerformed(java.awt.event.ActionEvent evt) {
168                 browseButtonActionPerformed(evt);
169             }
170         });
171 
172         gridBagConstraints = new java.awt.GridBagConstraints();
173         gridBagConstraints.gridx = 2;
174         gridBagConstraints.gridy = 1;
175         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
176         add(browseButton, gridBagConstraints);
177 
178     }//GEN-END:initComponents
179 
browseButtonActionPerformed(java.awt.event.ActionEvent evt)180     private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
181         // Add your handling code here:
182         File target = null;
183 
184         JFileChooser chooser = new JFileChooser();
185         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
186         int result = chooser.showDialog(null, null);
187 
188         if (result == JFileChooser.APPROVE_OPTION) {
189             target = chooser.getSelectedFile();
190 
191             String path;
192             try {
193                 path = target.getCanonicalPath();
194             }
195             catch (IOException ioe) {
196                 path = target.getAbsolutePath();
197             }
198 
199             OfficeInstallation oi = new OfficeInstallation(path, path);
200 
201             if (oi.supportsFramework()) {
202                 installPath.setText(path);
203                 panel.setSelectedPath(oi);
204             }
205         }
206 
207     }//GEN-LAST:event_browseButtonActionPerformed
208 
209     // Variables declaration - do not modify//GEN-BEGIN:variables
210     private javax.swing.JTextField installPath;
211     private javax.swing.JButton browseButton;
212     private javax.swing.JComboBox installationsComboBox;
213     private javax.swing.JLabel jLabel2;
214     private javax.swing.JLabel jLabel1;
215     private javax.swing.JPanel jPanel1;
216     // End of variables declaration//GEN-END:variables
217 }
218