001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.projectimport.eclipse;
043:
044: import java.awt.Dialog;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import java.util.Collection;
048: import java.util.Iterator;
049: import java.util.Set;
050: import javax.swing.JDialog;
051: import javax.swing.Timer;
052: import javax.swing.WindowConstants;
053: import org.netbeans.api.project.ui.OpenProjects;
054: import org.netbeans.modules.projectimport.eclipse.wizard.ProgressPanel;
055: import org.netbeans.modules.projectimport.eclipse.wizard.ProjectImporterWizard;
056: import org.openide.DialogDescriptor;
057: import org.openide.DialogDisplayer;
058: import org.openide.NotifyDescriptor;
059: import org.openide.util.HelpCtx;
060: import org.openide.util.NbBundle;
061: import org.openide.util.actions.CallableSystemAction;
062:
063: /**
064: * Runs EclipseProject Importer.
065: *
066: * @author mkrauskopf
067: */
068: public class ImportProjectAction extends CallableSystemAction {
069:
070: /** Creates a new instance of ImportProjectAction */
071: public ImportProjectAction() {
072: putValue("noIconInMenu", Boolean.TRUE); //NOI18N
073: }
074:
075: public void performAction() {
076: ProjectImporterWizard wizard = new ProjectImporterWizard();
077: wizard.start();
078: Set eclProjects = wizard.getProjects();
079: String destination = wizard.getDestination();
080: if (wizard.isCancelled() || eclProjects == null
081: || destination == null) {
082: return;
083: }
084:
085: final Importer importer = new Importer(eclProjects,
086: destination, wizard.getRecursively());
087:
088: // prepare progress dialog
089: final ProgressPanel progressPanel = new ProgressPanel();
090: DialogDescriptor desc = new DialogDescriptor(progressPanel,
091: NbBundle.getMessage(ImportProjectAction.class,
092: "CTL_ProgressDialogTitle"), true,
093: new Object[] {}, null, 0, null, null);
094: desc.setClosingOptions(new Object[] {});
095: final Dialog progressDialog = DialogDisplayer.getDefault()
096: .createDialog(desc);
097: ((JDialog) progressDialog)
098: .setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
099: progressPanel.start(wizard.getNumberOfImportedProject());
100:
101: // progress timer for periodically update progress
102: final Timer progressTimer = new Timer(50, null);
103: progressTimer.addActionListener(new ActionListener() {
104: public void actionPerformed(ActionEvent e) {
105: progressPanel.setProgress(importer.getNOfProcessed(),
106: importer.getProgressInfo());
107: if (importer.isDone()) {
108: progressTimer.stop();
109: progressDialog.setVisible(false);
110: progressDialog.dispose();
111: Collection warnings = importer.getWarnings();
112: if (warnings != null) {
113: StringBuffer messages = new StringBuffer(
114: NbBundle.getMessage(
115: ImportProjectAction.class,
116: "MSG_ProblemsOccured")); // NOI18N
117: messages.append("\n\n"); // NOI18N
118: for (Iterator it = warnings.iterator(); it
119: .hasNext();) {
120: String message = (String) it.next();
121: messages.append(" - " + message + "\n"); // NOI18N
122: }
123: NotifyDescriptor d = new DialogDescriptor.Message(
124: messages.toString(),
125: NotifyDescriptor.WARNING_MESSAGE);
126: DialogDisplayer.getDefault().notify(d);
127: }
128: // open created projects when importing finished
129: if (importer.getProjects().length > 0) {
130: OpenProjects.getDefault().open(
131: importer.getProjects(), true);
132: OpenProjects.getDefault().setMainProject(
133: importer.getProjects()[0]);
134: }
135: }
136: }
137: });
138: importer.startImporting(); // runs importing in separate thread
139: progressTimer.start();
140: progressDialog.setVisible(true);
141: }
142:
143: public String getName() {
144: return NbBundle.getMessage(ImportProjectAction.class,
145: "CTL_MenuItem"); // NOI18N
146: }
147:
148: public HelpCtx getHelpCtx() {
149: return null;
150: }
151:
152: protected boolean asynchronous() {
153: return false;
154: }
155: }
|