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.Component;
045: import java.beans.PropertyChangeEvent;
046: import java.beans.PropertyChangeListener;
047: import java.io.File;
048: import org.netbeans.modules.projectimport.eclipse.EclipseUtils;
049: import org.openide.WizardDescriptor;
050: import org.openide.WizardValidationException;
051:
052: /**
053: * Selection wizard panel for Eclipse Wizard importer.
054: *
055: * @author mkrauskopf
056: */
057: final class SelectionWizardPanel extends ImporterWizardPanel implements
058: PropertyChangeListener, WizardDescriptor.ValidatingPanel {
059:
060: private SelectionPanel panel;
061:
062: /** Creates a new instance of WorkspaceWizardPanel */
063: SelectionWizardPanel() {
064: panel = new SelectionPanel();
065: panel.addPropertyChangeListener(this );
066: initPanel(panel, 0);
067: }
068:
069: public Component getComponent() {
070: return panel;
071: }
072:
073: public void propertyChange(PropertyChangeEvent evt) {
074: String propName = evt.getPropertyName();
075: if ("errorMessage".equals(propName)) { //NOI18N
076: setErrorMessage((String) evt.getNewValue());
077: } else if ("workspaceChoosen".equals(propName)) { // NOI18N
078: String[] steps;
079: if (((Boolean) evt.getNewValue()).booleanValue()) {
080: steps = new String[] { WORKSPACE_LOCATION_STEP,
081: PROJECTS_SELECTION_STEP };
082: } else {
083: steps = new String[] { PROJECT_SELECTION_STEP };
084: }
085: panel.putClientProperty("WizardPanel_contentData", steps); // NOI18N
086: }
087: }
088:
089: // ==== delegate methods ==== //
090:
091: boolean isWorkspaceChosen() {
092: return panel.isWorkspaceChosen();
093: }
094:
095: /** Returns project directory of single-selected project. */
096: String getProjectDir() {
097: return panel.getProjectDir();
098: }
099:
100: /** Returns destination directory for single-selected project. */
101: public String getProjectDestinationDir() {
102: return panel.getProjectDestinationDir();
103: }
104:
105: /** Returns workspace directory choosed by user. */
106: public String getWorkspaceDir() {
107: return panel.getWorkspaceDir();
108: }
109:
110: public void validate() throws WizardValidationException {
111: if (!panel.isWorkspaceChosen()) {
112: String dest = getProjectDestinationDir();
113:
114: String message = null;
115: if ((!new File(dest).isAbsolute())
116: || !EclipseUtils.isWritable(dest)) {
117: message = ProjectImporterWizard.getMessage(
118: "MSG_CannotCreateProjectInFolder", dest); // NOI18N
119: } else if (!EclipseUtils
120: .isRegularJavaProject(getProjectDir())) {
121: message = ProjectImporterWizard
122: .getMessage("MSG_CannotImportNonJavaProject"); // NOI18N
123: }
124: if (message != null) {
125: setErrorMessage(message);
126: throw new WizardValidationException(panel, message,
127: null);
128: }
129: }
130: }
131: }
|