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.util.ArrayList;
045: import java.util.Iterator;
046: import java.util.List;
047: import javax.swing.JComponent;
048: import javax.swing.event.ChangeEvent;
049: import javax.swing.event.ChangeListener;
050: import org.openide.WizardDescriptor;
051: import org.openide.util.HelpCtx;
052:
053: /**
054: * Basic wizard panel for Eclipse Wizard importer.
055: *
056: * @author mkrauskopf
057: */
058: abstract class ImporterWizardPanel implements WizardDescriptor.Panel {
059:
060: /** Registered ChangeListeners */
061: private List changeListeners;
062:
063: /** Panel validity flag */
064: private boolean valid;
065:
066: /** Error message displayed by wizard. */
067: private String errorMessage;
068:
069: static final String WORKSPACE_LOCATION_STEP = ProjectImporterWizard
070: .getMessage("CTL_WorkspaceLocationStep"); // NOI18N
071: static final String PROJECT_SELECTION_STEP = ProjectImporterWizard
072: .getMessage("CTL_ProjectSelectionStep"); // NOI18N
073: static final String PROJECTS_SELECTION_STEP = ProjectImporterWizard
074: .getMessage("CTL_ProjectsSelectionStep"); // NOI18N
075:
076: /* Init defaults for the given component. */
077: void initPanel(JComponent comp, int wizardNumber) {
078: comp.putClientProperty("WizardPanel_autoWizardStyle",
079: Boolean.TRUE); // NOI18N
080: comp.putClientProperty("WizardPanel_contentDisplayed",
081: Boolean.TRUE); // NOI18N
082: comp.putClientProperty("WizardPanel_contentNumbered",
083: Boolean.TRUE); // NOI18N
084: comp.putClientProperty("WizardPanel_contentSelectedIndex", // NOI18N
085: new Integer(wizardNumber));
086: comp.putClientProperty("WizardPanel_contentData", new String[] { // NOI18N
087: WORKSPACE_LOCATION_STEP, PROJECTS_SELECTION_STEP });
088: comp.setPreferredSize(new java.awt.Dimension(500, 380));
089: }
090:
091: /**
092: * Return message to be displayed as ErrorMessage by Eclipse importer
093: * wizard. Default implementation returns null (no error message will be
094: * displayed)
095: */
096: public void addChangeListener(ChangeListener l) {
097: if (changeListeners == null) {
098: changeListeners = new ArrayList(2);
099: }
100: changeListeners.add(l);
101: }
102:
103: public void removeChangeListener(ChangeListener l) {
104: if (changeListeners != null) {
105: if (changeListeners.remove(l) && changeListeners.isEmpty()) {
106: changeListeners = null;
107: }
108: }
109: }
110:
111: protected void fireChange() {
112: if (changeListeners != null) {
113: ChangeEvent e = new ChangeEvent(this );
114: for (Iterator i = changeListeners.iterator(); i.hasNext();) {
115: ((ChangeListener) i.next()).stateChanged(e);
116: }
117: }
118: }
119:
120: /**
121: * Sets error message used by importer wizard. Consequently sets validity of
122: * this panel. If the given <code>newError</code> is null panel is
123: * considered valid. Invalid otherwise.
124: */
125: protected void setErrorMessage(String newError) {
126: boolean changed = (errorMessage == null && newError != null)
127: || (errorMessage != null && !errorMessage
128: .equals(newError));
129: if (changed)
130: errorMessage = newError;
131: setValid(newError == null, changed);
132: }
133:
134: /** Sets if the current state of panel is valid or not. */
135: protected void setValid(boolean valid, boolean forceFiring) {
136: boolean changed = this .valid != valid;
137: if (changed)
138: this .valid = valid;
139: if (changed || forceFiring) {
140: fireChange();
141: }
142: }
143:
144: /** Returns error message used by importer wizard. */
145: String getErrorMessage() {
146: return errorMessage;
147: }
148:
149: public boolean isValid() {
150: return valid;
151: }
152:
153: public HelpCtx getHelp() {
154: return null;
155: }
156:
157: public void storeSettings(Object settings) {
158: ;
159: }
160:
161: public void readSettings(Object settings) {
162: ;
163: }
164: }
|