KickJava   Java API By Example, From Geeks To Geeks.

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


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.Component JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.io.File JavaDoc;
26 import org.netbeans.modules.projectimport.eclipse.EclipseUtils;
27 import org.openide.WizardDescriptor;
28 import org.openide.WizardValidationException;
29
30 /**
31  * Selection wizard panel for Eclipse Wizard importer.
32  *
33  * @author mkrauskopf
34  */

35 final class SelectionWizardPanel extends ImporterWizardPanel implements
36         PropertyChangeListener JavaDoc, WizardDescriptor.ValidatingPanel {
37     
38     private SelectionPanel panel;
39     
40     /** Creates a new instance of WorkspaceWizardPanel */
41     SelectionWizardPanel() {
42         panel = new SelectionPanel();
43         panel.addPropertyChangeListener(this);
44         initPanel(panel, 0);
45     }
46     
47     public Component JavaDoc getComponent() {
48         return panel;
49     }
50     
51     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
52         String JavaDoc propName = evt.getPropertyName();
53         if ("errorMessage".equals(propName)) { //NOI18N
54
setErrorMessage((String JavaDoc) evt.getNewValue());
55         } else if ("workspaceChoosen".equals(propName)) { // NOI18N
56
String JavaDoc[] steps;
57             if (((Boolean JavaDoc) evt.getNewValue()).booleanValue()) {
58                 steps = new String JavaDoc[] { WORKSPACE_LOCATION_STEP, PROJECTS_SELECTION_STEP };
59             } else {
60                 steps = new String JavaDoc[] { PROJECT_SELECTION_STEP };
61             }
62             panel.putClientProperty("WizardPanel_contentData", steps); // NOI18N
63
}
64     }
65     
66     // ==== delegate methods ==== //
67

68     boolean isWorkspaceChosen() {
69         return panel.isWorkspaceChosen();
70     }
71     
72     /** Returns project directory of single-selected project. */
73     String JavaDoc getProjectDir() {
74         return panel.getProjectDir();
75     }
76     
77     /** Returns destination directory for single-selected project. */
78     public String JavaDoc getProjectDestinationDir() {
79         return panel.getProjectDestinationDir();
80     }
81     
82     /** Returns workspace directory choosed by user. */
83     public String JavaDoc getWorkspaceDir() {
84         return panel.getWorkspaceDir();
85     }
86     
87     public void validate() throws WizardValidationException {
88         if (!panel.isWorkspaceChosen()) {
89             String JavaDoc dest = getProjectDestinationDir();
90
91             String JavaDoc message = null;
92             if ((!new File JavaDoc(dest).isAbsolute()) || !EclipseUtils.isWritable(dest)) {
93                 message = ProjectImporterWizard.getMessage(
94                         "MSG_CannotCreateProjectInFolder", dest); // NOI18N
95
} else if (!EclipseUtils.isRegularJavaProject(getProjectDir())) {
96                 message = ProjectImporterWizard.getMessage(
97                         "MSG_CannotImportNonJavaProject"); // NOI18N
98
}
99             if (message != null) {
100                 setErrorMessage(message);
101                 throw new WizardValidationException(panel, message, null);
102             }
103         }
104     }
105 }
106
Popular Tags