1 19 20 package org.netbeans.modules.projectimport.eclipse; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 import java.util.Set ; 28 import javax.swing.JDialog ; 29 import javax.swing.Timer ; 30 import javax.swing.WindowConstants ; 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 46 public class ImportProjectAction extends CallableSystemAction { 47 48 49 public ImportProjectAction() { 50 putValue("noIconInMenu", Boolean.TRUE); } 52 53 public void performAction() { 54 ProjectImporterWizard wizard = new ProjectImporterWizard(); 55 wizard.start(); 56 Set eclProjects = wizard.getProjects(); 57 String 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 final ProgressPanel progressPanel = new ProgressPanel(); 67 DialogDescriptor desc = new DialogDescriptor(progressPanel, 68 NbBundle.getMessage(ImportProjectAction.class, "CTL_ProgressDialogTitle"), 69 true, new Object []{}, null, 0, null, null); 70 desc.setClosingOptions(new Object []{}); 71 final Dialog progressDialog = DialogDisplayer.getDefault().createDialog(desc); 72 ((JDialog ) progressDialog).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 73 progressPanel.start(wizard.getNumberOfImportedProject()); 74 75 final Timer progressTimer = new Timer (50, null); 77 progressTimer.addActionListener(new ActionListener () { 78 public void actionPerformed(ActionEvent e) { 79 progressPanel.setProgress(importer.getNOfProcessed(), importer.getProgressInfo()); 80 if (importer.isDone()) { 81 progressTimer.stop(); 82 progressDialog.setVisible(false); 83 progressDialog.dispose(); 84 Collection warnings = importer.getWarnings(); 85 if (warnings != null) { 86 StringBuffer messages = new StringBuffer ( 87 NbBundle.getMessage(ImportProjectAction.class, 88 "MSG_ProblemsOccured")); messages.append("\n\n"); for (Iterator it = warnings.iterator(); it.hasNext(); ) { 91 String message = (String ) it.next(); 92 messages.append(" - " + message + "\n"); } 94 NotifyDescriptor d = new DialogDescriptor.Message( 95 messages.toString(), NotifyDescriptor.WARNING_MESSAGE); 96 DialogDisplayer.getDefault().notify(d); 97 } 98 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(); progressTimer.start(); 108 progressDialog.setVisible(true); 109 } 110 111 public String getName() { 112 return NbBundle.getMessage(ImportProjectAction.class, "CTL_MenuItem"); } 114 115 public HelpCtx getHelpCtx() { 116 return null; 117 } 118 119 protected boolean asynchronous() { 120 return false; 121 } 122 } 123 | Popular Tags |