KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > eclipse > wizard > SelectionPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.projectimport.eclipse.wizard;
21
22 import java.awt.Color JavaDoc;
23 import java.io.File JavaDoc;
24 import javax.swing.JFileChooser JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26 import javax.swing.UIManager JavaDoc;
27 import javax.swing.event.DocumentEvent JavaDoc;
28 import javax.swing.event.DocumentListener JavaDoc;
29 import org.netbeans.modules.projectimport.eclipse.EclipseUtils;
30
31 /**
32  * Represent "Selection" step(panel) in the Eclipse importer wizard.
33  *
34  * @author mkrauskopf
35  */

36 final class SelectionPanel extends JPanel JavaDoc {
37
38     private String JavaDoc errorMessage;
39
40     /** Creates new form ProjectSelectionPanel */
41     public SelectionPanel() {
42         super();
43         initComponents();
44         Color JavaDoc lblBgr = UIManager.getColor("Label.background"); // NOI18N
45
wsDescription.setBackground(lblBgr);
46         note.setBackground(lblBgr);
47         workspaceDir.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
48             public void insertUpdate(DocumentEvent JavaDoc e) { workspaceChanged(); }
49             public void removeUpdate(DocumentEvent JavaDoc e) { workspaceChanged(); }
50             public void changedUpdate(DocumentEvent JavaDoc e) {}
51         });
52         projectDir.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
53             public void insertUpdate(DocumentEvent JavaDoc e) { projectChanged(); }
54             public void removeUpdate(DocumentEvent JavaDoc e) { projectChanged(); }
55             public void changedUpdate(DocumentEvent JavaDoc e) {}
56         });
57         projectDestDir.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
58             public void insertUpdate(DocumentEvent JavaDoc e) { projectChanged(); }
59             public void removeUpdate(DocumentEvent JavaDoc e) { projectChanged(); }
60             public void changedUpdate(DocumentEvent JavaDoc e) {}
61         });
62         setWorkspaceEnabled(workspaceButton.isSelected());
63     }
64     
65     /** Returns workspace directory choosed by user. */
66     String JavaDoc getWorkspaceDir() {
67         return workspaceDir.getText().trim();
68     }
69     
70     private void workspaceChanged() {
71         String JavaDoc workspace = getWorkspaceDir().trim();
72         if ("".equals(workspace)) {
73             setErrorMessage(ProjectImporterWizard.getMessage(
74                     "MSG_ChooseWorkspace")); // NOI18N
75
return;
76         }
77         boolean wsValid = EclipseUtils.isRegularWorkSpace(getWorkspaceDir());
78         setErrorMessage(wsValid ? null : ProjectImporterWizard.getMessage(
79                 "MSG_NotRegularWorkspace", getWorkspaceDir())); // NOI18N
80
}
81     
82     private void projectChanged() {
83         // check Eclipse project directory
84
String JavaDoc project = getProjectDir();
85         if ("".equals(project)) {
86             setErrorMessage(ProjectImporterWizard.getMessage(
87                     "MSG_ChooseProject")); // NOI18N
88
return;
89         }
90         File JavaDoc projectDirFile = new File JavaDoc(project);
91         if (!EclipseUtils.isRegularProject(projectDirFile)) {
92             setErrorMessage(ProjectImporterWizard.getMessage(
93                     "MSG_NotRegularProject", project)); // NOI18N
94
return;
95         }
96         
97         // check destination directory
98
String JavaDoc projectDest = getProjectDestinationDir();
99         if ("".equals(projectDest)) {
100             setErrorMessage(ProjectImporterWizard.getMessage(
101                     "MSG_ChooseProjectDestination")); // NOI18N
102
return;
103         }
104         File JavaDoc projectDestFile = new File JavaDoc(projectDest, projectDirFile.getName());
105         if (projectDestFile.exists()) {
106             setErrorMessage(ProjectImporterWizard.getMessage(
107                     "MSG_ProjectExist", projectDestFile.getName())); // NOI18N
108
return;
109         }
110         
111         // valid
112
setErrorMessage(null);
113     }
114     
115     void setErrorMessage(String JavaDoc newMessage) {
116         String JavaDoc oldMessage = this.errorMessage;
117         this.errorMessage = newMessage;
118         firePropertyChange("errorMessage", oldMessage, newMessage);
119     }
120     
121     boolean isWorkspaceChosen() {
122         return workspaceButton.isSelected();
123     }
124     
125     /** Returns project directory of single-selected project. */
126     public String JavaDoc getProjectDir() {
127         return projectDir.getText().trim();
128     }
129     
130     /** Returns destination directory for single-selected project. */
131     public String JavaDoc getProjectDestinationDir() {
132         return projectDestDir.getText().trim();
133     }
134     
135     /** This method is called from within the constructor to
136      * initialize the form.
137      * WARNING: Do NOT modify this code. The content of this method is
138      * always regenerated by the Form Editor.
139      */

140     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
141
private void initComponents() {
142         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
143
144         buttonGroup = new javax.swing.ButtonGroup JavaDoc();
145         workspaceDir = new javax.swing.JTextField JavaDoc();
146         worskpaceBrowse = new javax.swing.JButton JavaDoc();
147         workSpaceLBL = new javax.swing.JLabel JavaDoc();
148         projectDir = new javax.swing.JTextField JavaDoc();
149         projectBrowse = new javax.swing.JButton JavaDoc();
150         projectLBL = new javax.swing.JLabel JavaDoc();
151         projectButton = new javax.swing.JRadioButton JavaDoc();
152         workspaceButton = new javax.swing.JRadioButton JavaDoc();
153         projectDestLBL = new javax.swing.JLabel JavaDoc();
154         projectDestDir = new javax.swing.JTextField JavaDoc();
155         projectDestBrowse = new javax.swing.JButton JavaDoc();
156         wsDescription = new javax.swing.JTextArea JavaDoc();
157         note = new javax.swing.JTextArea JavaDoc();
158
159         setLayout(new java.awt.GridBagLayout JavaDoc());
160
161         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
162         gridBagConstraints.gridx = 1;
163         gridBagConstraints.gridy = 2;
164         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
165         gridBagConstraints.weightx = 1.0;
166         add(workspaceDir, gridBagConstraints);
167
168         org.openide.awt.Mnemonics.setLocalizedText(worskpaceBrowse, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_BrowseButton_B"));
169         worskpaceBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
170             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
171                 worskpaceBrowseActionPerformed(evt);
172             }
173         });
174
175         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
176         gridBagConstraints.gridx = 2;
177         gridBagConstraints.gridy = 2;
178         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
179         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 11, 0, 0);
180         add(worskpaceBrowse, gridBagConstraints);
181
182         workSpaceLBL.setLabelFor(workspaceDir);
183         org.openide.awt.Mnemonics.setLocalizedText(workSpaceLBL, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "LBL_Workspace"));
184         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
185         gridBagConstraints.gridx = 0;
186         gridBagConstraints.gridy = 2;
187         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
188         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
189         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 14, 0, 12);
190         add(workSpaceLBL, gridBagConstraints);
191
192         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.gridx = 1;
194         gridBagConstraints.gridy = 4;
195         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
196         gridBagConstraints.weightx = 1.0;
197         add(projectDir, gridBagConstraints);
198
199         org.openide.awt.Mnemonics.setLocalizedText(projectBrowse, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_BrowseButton_R"));
200         projectBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
201             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
202                 projectBrowseActionPerformed(evt);
203             }
204         });
205
206         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
207         gridBagConstraints.gridx = 2;
208         gridBagConstraints.gridy = 4;
209         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
210         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 11, 0, 0);
211         add(projectBrowse, gridBagConstraints);
212
213         projectLBL.setLabelFor(projectDir);
214         org.openide.awt.Mnemonics.setLocalizedText(projectLBL, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "LBL_Project"));
215         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
216         gridBagConstraints.gridx = 0;
217         gridBagConstraints.gridy = 4;
218         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
219         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
220         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 14, 0, 12);
221         add(projectLBL, gridBagConstraints);
222
223         buttonGroup.add(projectButton);
224         org.openide.awt.Mnemonics.setLocalizedText(projectButton, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_ProjectButton"));
225         projectButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
226         projectButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
227         projectButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
228             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
229                 projectButtonActionPerformed(evt);
230             }
231         });
232
233         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
234         gridBagConstraints.gridx = 0;
235         gridBagConstraints.gridy = 3;
236         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
237         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
238         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 0, 6, 0);
239         add(projectButton, gridBagConstraints);
240
241         buttonGroup.add(workspaceButton);
242         workspaceButton.setSelected(true);
243         org.openide.awt.Mnemonics.setLocalizedText(workspaceButton, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_WorkspaceButton"));
244         workspaceButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
245         workspaceButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
246         workspaceButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
247             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
248                 workspaceButtonActionPerformed(evt);
249             }
250         });
251
252         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
253         gridBagConstraints.gridx = 0;
254         gridBagConstraints.gridy = 1;
255         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
256         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
257         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
258         add(workspaceButton, gridBagConstraints);
259
260         projectDestLBL.setLabelFor(projectDestDir);
261         org.openide.awt.Mnemonics.setLocalizedText(projectDestLBL, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "LBL_ProjectDestination"));
262         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
263         gridBagConstraints.gridx = 0;
264         gridBagConstraints.gridy = 5;
265         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
266         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
267         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 14, 0, 12);
268         add(projectDestLBL, gridBagConstraints);
269
270         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
271         gridBagConstraints.gridx = 1;
272         gridBagConstraints.gridy = 5;
273         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
274         gridBagConstraints.weightx = 1.0;
275         add(projectDestDir, gridBagConstraints);
276
277         org.openide.awt.Mnemonics.setLocalizedText(projectDestBrowse, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_BrowseButton_S"));
278         projectDestBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
279             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
280                 projectDestBrowseActionPerformed(evt);
281             }
282         });
283
284         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
285         gridBagConstraints.gridx = 2;
286         gridBagConstraints.gridy = 5;
287         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
288         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 11, 0, 0);
289         add(projectDestBrowse, gridBagConstraints);
290
291         wsDescription.setEditable(false);
292         wsDescription.setLineWrap(true);
293         wsDescription.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/projectimport/eclipse/wizard/Bundle").getString("LBL_SpecifyWorkspaceDescription"));
294         wsDescription.setWrapStyleWord(true);
295         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
296         gridBagConstraints.gridx = 0;
297         gridBagConstraints.gridy = 0;
298         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
299         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
300         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 24, 0);
301         add(wsDescription, gridBagConstraints);
302
303         note.setEditable(false);
304         note.setLineWrap(true);
305         note.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/projectimport/eclipse/wizard/Bundle").getString("LBL_NoteAboutWorkspaceAdvantage"));
306         note.setWrapStyleWord(true);
307         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
308         gridBagConstraints.gridx = 0;
309         gridBagConstraints.gridy = 6;
310         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
311         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
312         gridBagConstraints.weighty = 1.0;
313         gridBagConstraints.insets = new java.awt.Insets JavaDoc(24, 0, 0, 0);
314         add(note, gridBagConstraints);
315
316     }// </editor-fold>//GEN-END:initComponents
317
private void projectDestBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_projectDestBrowseActionPerformed
318
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(projectDestDir.getText());
319         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
320         int ret = chooser.showOpenDialog(this);
321         if (ret == JFileChooser.APPROVE_OPTION) {
322             projectDestDir.setText(chooser.getSelectedFile().getAbsolutePath());
323         }
324     }//GEN-LAST:event_projectDestBrowseActionPerformed
325

326     private void projectButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_projectButtonActionPerformed
327
setWorkspaceEnabled(false);
328         projectChanged();
329         projectDir.requestFocusInWindow();
330         firePropertyChange("workspaceChoosen", true, false); // NOI18N
331
}//GEN-LAST:event_projectButtonActionPerformed
332

333     private void workspaceButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_workspaceButtonActionPerformed
334
setWorkspaceEnabled(true);
335         workspaceChanged();
336         firePropertyChange("workspaceChoosen", false, true); // NOI18N
337
}//GEN-LAST:event_workspaceButtonActionPerformed
338

339     private void setWorkspaceEnabled(boolean enabled) {
340         workSpaceLBL.setEnabled(enabled);
341         worskpaceBrowse.setEnabled(enabled);
342         workspaceDir.setEnabled(enabled);
343         projectLBL.setEnabled(!enabled);
344         projectBrowse.setEnabled(!enabled);
345         projectDir.setEnabled(!enabled);
346         projectDestBrowse.setEnabled(!enabled);
347         projectDestDir.setEnabled(!enabled);
348         projectDestLBL.setEnabled(!enabled);
349     }
350     
351     private void projectBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_projectBrowseActionPerformed
352
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(projectDir.getText());
353         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
354         int ret = chooser.showOpenDialog(this);
355         if (ret == JFileChooser.APPROVE_OPTION) {
356             projectDir.setText(chooser.getSelectedFile().getAbsolutePath());
357         }
358     }//GEN-LAST:event_projectBrowseActionPerformed
359

360     private void worskpaceBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_worskpaceBrowseActionPerformed
361
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(getWorkspaceDir());
362         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
363         int ret = chooser.showOpenDialog(this);
364         if (ret == JFileChooser.APPROVE_OPTION) {
365             workspaceDir.setText(chooser.getSelectedFile().getAbsolutePath());
366         }
367     }//GEN-LAST:event_worskpaceBrowseActionPerformed
368

369     
370     // Variables declaration - do not modify//GEN-BEGIN:variables
371
private javax.swing.ButtonGroup JavaDoc buttonGroup;
372     private javax.swing.JTextArea JavaDoc note;
373     private javax.swing.JButton JavaDoc projectBrowse;
374     private javax.swing.JRadioButton JavaDoc projectButton;
375     private javax.swing.JButton JavaDoc projectDestBrowse;
376     private javax.swing.JTextField JavaDoc projectDestDir;
377     private javax.swing.JLabel JavaDoc projectDestLBL;
378     private javax.swing.JTextField JavaDoc projectDir;
379     private javax.swing.JLabel JavaDoc projectLBL;
380     private javax.swing.JLabel JavaDoc workSpaceLBL;
381     private javax.swing.JRadioButton JavaDoc workspaceButton;
382     private javax.swing.JTextField JavaDoc workspaceDir;
383     private javax.swing.JButton JavaDoc worskpaceBrowse;
384     private javax.swing.JTextArea JavaDoc wsDescription;
385     // End of variables declaration//GEN-END:variables
386
}
387
Popular Tags