KickJava   Java API By Example, From Geeks To Geeks.

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


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.Dialog JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
25 import javax.swing.event.ChangeEvent JavaDoc;
26 import javax.swing.event.ChangeListener JavaDoc;
27 import org.netbeans.modules.projectimport.eclipse.EclipseProject;
28 import org.openide.DialogDescriptor;
29 import org.openide.DialogDisplayer;
30 import org.openide.NotifyDescriptor;
31 import org.openide.WizardDescriptor;
32 import org.openide.util.NbBundle;
33
34 /**
35  * Wizard for importing Eclipse project.
36  *
37  * @author mkrauskopf
38  */

39 public final class ProjectImporterWizard {
40     
41     private Set JavaDoc projects;
42     private String JavaDoc destination;
43     private boolean recursively;
44     private boolean cancelled;
45     private int numberOfImportedProjects;
46     
47     /** Starts Eclipse importer wizard. */
48     public void start() {
49         final EclipseWizardIterator iterator = new EclipseWizardIterator();
50         final WizardDescriptor wizardDescriptor = new WizardDescriptor(iterator);
51         iterator.addChangeListener(new ChangeListener JavaDoc() {
52             public void stateChanged(ChangeEvent JavaDoc e) {
53                 wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
54
iterator.getErrorMessage());
55             }
56         });
57         wizardDescriptor.setTitleFormat(new java.text.MessageFormat JavaDoc("{1}")); // NOI18N
58
wizardDescriptor.setTitle(
59                 ProjectImporterWizard.getMessage("CTL_WizardTitle")); // NOI18N
60
Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
61         dialog.setVisible(true);
62         dialog.toFront();
63         cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
64         if (!cancelled) {
65             projects = iterator.getProjects();
66             showAdditionalInfo(projects);
67             destination = iterator.getDestination();
68             recursively = iterator.getRecursively();
69             numberOfImportedProjects = iterator.getNumberOfImportedProject();
70         }
71     }
72     
73     private void showAdditionalInfo(Set JavaDoc projects) {
74         StringBuffer JavaDoc messages = null;
75         for (Iterator JavaDoc it = projects.iterator(); it.hasNext(); ) {
76             EclipseProject prj = (EclipseProject) it.next();
77             Set JavaDoc natures = prj.getOtherNatures();
78             if (natures != null && !natures.isEmpty()) {
79                 if (messages == null) {
80                     messages = new StringBuffer JavaDoc(
81                             getMessage("MSG_CreatedByPlugin") + "\n\n"); // NOI18N
82
}
83                 messages.append(" - " + prj.getName()); // NOI18N
84
}
85         }
86         if (messages != null) {
87             NotifyDescriptor d = new DialogDescriptor.Message(
88                     messages.toString(), NotifyDescriptor.INFORMATION_MESSAGE);
89             DialogDisplayer.getDefault().notify(d);
90         }
91     }
92     
93     /** Returns project selected by user with the help of the wizard. */
94     public Set JavaDoc getProjects() {
95         return projects;
96     }
97     
98     /**
99      * Returns number of projects which will be imported (including both
100      * required and selected projects)
101      */

102     public int getNumberOfImportedProject() {
103         return numberOfImportedProjects;
104     }
105     
106     /**
107      * Returns destination directory where new NetBeans projects will be stored.
108      */

109     public String JavaDoc getDestination() {
110         return destination;
111     }
112     
113     public boolean getRecursively() {
114         return recursively;
115     }
116     
117     /**
118      * Returns whether user canceled the wizard.
119      */

120     public boolean isCancelled() {
121         return cancelled;
122     }
123     
124     /** Gets message from properties bundle for this package. */
125     static String JavaDoc getMessage(String JavaDoc key) {
126         return NbBundle.getMessage(ProjectImporterWizard.class, key);
127     }
128     
129     /** Gets message from properties bundle for this package. */
130     static String JavaDoc getMessage(String JavaDoc key, Object JavaDoc param1) {
131         return NbBundle.getMessage(ProjectImporterWizard.class, key, param1);
132     }
133 }
134
Popular Tags