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.wizard;
043:
044: import java.awt.Dialog;
045: import java.util.Iterator;
046: import java.util.Set;
047: import javax.swing.event.ChangeEvent;
048: import javax.swing.event.ChangeListener;
049: import org.netbeans.modules.projectimport.eclipse.EclipseProject;
050: import org.openide.DialogDescriptor;
051: import org.openide.DialogDisplayer;
052: import org.openide.NotifyDescriptor;
053: import org.openide.WizardDescriptor;
054: import org.openide.util.NbBundle;
055:
056: /**
057: * Wizard for importing Eclipse project.
058: *
059: * @author mkrauskopf
060: */
061: public final class ProjectImporterWizard {
062:
063: private Set projects;
064: private String destination;
065: private boolean recursively;
066: private boolean cancelled;
067: private int numberOfImportedProjects;
068:
069: /** Starts Eclipse importer wizard. */
070: public void start() {
071: final EclipseWizardIterator iterator = new EclipseWizardIterator();
072: final WizardDescriptor wizardDescriptor = new WizardDescriptor(
073: iterator);
074: iterator.addChangeListener(new ChangeListener() {
075: public void stateChanged(ChangeEvent e) {
076: wizardDescriptor.putProperty(
077: "WizardPanel_errorMessage", // NOI18N
078: iterator.getErrorMessage());
079: }
080: });
081: wizardDescriptor.setTitleFormat(new java.text.MessageFormat(
082: "{1}")); // NOI18N
083: wizardDescriptor.setTitle(ProjectImporterWizard
084: .getMessage("CTL_WizardTitle")); // NOI18N
085: Dialog dialog = DialogDisplayer.getDefault().createDialog(
086: wizardDescriptor);
087: dialog.setVisible(true);
088: dialog.toFront();
089: cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
090: if (!cancelled) {
091: projects = iterator.getProjects();
092: showAdditionalInfo(projects);
093: destination = iterator.getDestination();
094: recursively = iterator.getRecursively();
095: numberOfImportedProjects = iterator
096: .getNumberOfImportedProject();
097: }
098: }
099:
100: private void showAdditionalInfo(Set projects) {
101: StringBuffer messages = null;
102: for (Iterator it = projects.iterator(); it.hasNext();) {
103: EclipseProject prj = (EclipseProject) it.next();
104: Set natures = prj.getOtherNatures();
105: if (natures != null && !natures.isEmpty()) {
106: if (messages == null) {
107: messages = new StringBuffer(
108: getMessage("MSG_CreatedByPlugin") + "\n\n"); // NOI18N
109: }
110: messages.append(" - " + prj.getName()); // NOI18N
111: }
112: }
113: if (messages != null) {
114: NotifyDescriptor d = new DialogDescriptor.Message(messages
115: .toString(), NotifyDescriptor.INFORMATION_MESSAGE);
116: DialogDisplayer.getDefault().notify(d);
117: }
118: }
119:
120: /** Returns project selected by user with the help of the wizard. */
121: public Set getProjects() {
122: return projects;
123: }
124:
125: /**
126: * Returns number of projects which will be imported (including both
127: * required and selected projects)
128: */
129: public int getNumberOfImportedProject() {
130: return numberOfImportedProjects;
131: }
132:
133: /**
134: * Returns destination directory where new NetBeans projects will be stored.
135: */
136: public String getDestination() {
137: return destination;
138: }
139:
140: public boolean getRecursively() {
141: return recursively;
142: }
143:
144: /**
145: * Returns whether user canceled the wizard.
146: */
147: public boolean isCancelled() {
148: return cancelled;
149: }
150:
151: /** Gets message from properties bundle for this package. */
152: static String getMessage(String key) {
153: return NbBundle.getMessage(ProjectImporterWizard.class, key);
154: }
155:
156: /** Gets message from properties bundle for this package. */
157: static String getMessage(String key, Object param1) {
158: return NbBundle.getMessage(ProjectImporterWizard.class, key,
159: param1);
160: }
161: }
|