KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > eclipse > ImportProjectAction


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;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.swing.JDialog JavaDoc;
29 import javax.swing.Timer JavaDoc;
30 import javax.swing.WindowConstants JavaDoc;
31 import org.netbeans.api.project.ui.OpenProjects;
32 import org.netbeans.modules.projectimport.eclipse.wizard.ProgressPanel;
33 import org.netbeans.modules.projectimport.eclipse.wizard.ProjectImporterWizard;
34 import org.openide.DialogDescriptor;
35 import org.openide.DialogDisplayer;
36 import org.openide.NotifyDescriptor;
37 import org.openide.util.HelpCtx;
38 import org.openide.util.NbBundle;
39 import org.openide.util.actions.CallableSystemAction;
40
41 /**
42  * Runs EclipseProject Importer.
43  *
44  * @author mkrauskopf
45  */

46 public class ImportProjectAction extends CallableSystemAction {
47     
48     /** Creates a new instance of ImportProjectAction */
49     public ImportProjectAction() {
50         putValue("noIconInMenu", Boolean.TRUE); //NOI18N
51
}
52     
53     public void performAction() {
54         ProjectImporterWizard wizard = new ProjectImporterWizard();
55         wizard.start();
56         Set JavaDoc eclProjects = wizard.getProjects();
57         String JavaDoc destination = wizard.getDestination();
58         if (wizard.isCancelled() || eclProjects == null || destination == null) {
59             return;
60         }
61         
62         final Importer importer = new Importer(eclProjects, destination,
63                 wizard.getRecursively());
64         
65         // prepare progress dialog
66
final ProgressPanel progressPanel = new ProgressPanel();
67         DialogDescriptor desc = new DialogDescriptor(progressPanel,
68                 NbBundle.getMessage(ImportProjectAction.class, "CTL_ProgressDialogTitle"),
69                 true, new Object JavaDoc[]{}, null, 0, null, null);
70         desc.setClosingOptions(new Object JavaDoc[]{});
71         final Dialog JavaDoc progressDialog = DialogDisplayer.getDefault().createDialog(desc);
72         ((JDialog JavaDoc) progressDialog).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
73         progressPanel.start(wizard.getNumberOfImportedProject());
74         
75         // progress timer for periodically update progress
76
final Timer JavaDoc progressTimer = new Timer JavaDoc(50, null);
77         progressTimer.addActionListener(new ActionListener JavaDoc() {
78             public void actionPerformed(ActionEvent JavaDoc e) {
79                 progressPanel.setProgress(importer.getNOfProcessed(), importer.getProgressInfo());
80                 if (importer.isDone()) {
81                     progressTimer.stop();
82                     progressDialog.setVisible(false);
83                     progressDialog.dispose();
84                     Collection JavaDoc warnings = importer.getWarnings();
85                     if (warnings != null) {
86                         StringBuffer JavaDoc messages = new StringBuffer JavaDoc(
87                                 NbBundle.getMessage(ImportProjectAction.class,
88                                 "MSG_ProblemsOccured")); // NOI18N
89
messages.append("\n\n"); // NOI18N
90
for (Iterator JavaDoc it = warnings.iterator(); it.hasNext(); ) {
91                             String JavaDoc message = (String JavaDoc) it.next();
92                             messages.append(" - " + message + "\n"); // NOI18N
93
}
94                         NotifyDescriptor d = new DialogDescriptor.Message(
95                                 messages.toString(), NotifyDescriptor.WARNING_MESSAGE);
96                         DialogDisplayer.getDefault().notify(d);
97                     }
98                     // open created projects when importing finished
99
OpenProjects.getDefault().open(importer.getProjects(), true);
100                     if (importer.getProjects().length > 0) {
101                         OpenProjects.getDefault().setMainProject(importer.getProjects()[0]);
102                     }
103                 }
104             }
105         });
106         importer.startImporting(); // runs importing in separate thread
107
progressTimer.start();
108         progressDialog.setVisible(true);
109     }
110     
111     public String JavaDoc getName() {
112         return NbBundle.getMessage(ImportProjectAction.class, "CTL_MenuItem"); // NOI18N
113
}
114     
115     public HelpCtx getHelpCtx() {
116         return null;
117     }
118     
119     protected boolean asynchronous() {
120         return false;
121     }
122 }
123
Popular Tags