KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > eclipse > wizard > ImporterWizardPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.projectimport.eclipse.wizard;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import org.openide.WizardDescriptor;
29 import org.openide.util.HelpCtx;
30
31 /**
32  * Basic wizard panel for Eclipse Wizard importer.
33  *
34  * @author mkrauskopf
35  */

36 abstract class ImporterWizardPanel implements WizardDescriptor.Panel {
37
38     /** Registered ChangeListeners */
39     private List JavaDoc changeListeners;
40     
41     /** Panel validity flag */
42     private boolean valid;
43     
44     /** Error message displayed by wizard. */
45     private String JavaDoc errorMessage;
46     
47     static final String JavaDoc WORKSPACE_LOCATION_STEP =
48             ProjectImporterWizard.getMessage("CTL_WorkspaceLocationStep"); // NOI18N
49
static final String JavaDoc PROJECT_SELECTION_STEP =
50             ProjectImporterWizard.getMessage("CTL_ProjectSelectionStep"); // NOI18N
51
static final String JavaDoc PROJECTS_SELECTION_STEP =
52             ProjectImporterWizard.getMessage("CTL_ProjectsSelectionStep"); // NOI18N
53

54     /* Init defaults for the given component. */
55     void initPanel(JComponent JavaDoc comp, int wizardNumber) {
56         comp.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
57
comp.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
58
comp.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
59
comp.putClientProperty("WizardPanel_contentSelectedIndex", // NOI18N
60
new Integer JavaDoc(wizardNumber));
61         comp.putClientProperty("WizardPanel_contentData", new String JavaDoc[] { // NOI18N
62
WORKSPACE_LOCATION_STEP, PROJECTS_SELECTION_STEP
63         });
64         comp.setPreferredSize(new java.awt.Dimension JavaDoc(500, 380));
65     }
66     
67     /**
68      * Return message to be displayed as ErrorMessage by Eclipse importer
69      * wizard. Default implementation returns null (no error message will be
70      * displayed)
71      */

72     public void addChangeListener(ChangeListener JavaDoc l) {
73         if (changeListeners == null) {
74             changeListeners = new ArrayList JavaDoc(2);
75         }
76         changeListeners.add(l);
77     }
78     
79     public void removeChangeListener(ChangeListener JavaDoc l) {
80         if (changeListeners != null) {
81             if (changeListeners.remove(l) && changeListeners.isEmpty()) {
82                 changeListeners = null;
83             }
84         }
85     }
86     
87     protected void fireChange() {
88         if (changeListeners != null) {
89             ChangeEvent JavaDoc e = new ChangeEvent JavaDoc(this);
90             for (Iterator JavaDoc i = changeListeners.iterator(); i.hasNext(); ) {
91                 ((ChangeListener JavaDoc) i.next()).stateChanged(e);
92             }
93         }
94     }
95     
96     /**
97      * Sets error message used by importer wizard. Consequently sets validity of
98      * this panel. If the given <code>newError</code> is null panel is
99      * considered valid. Invalid otherwise.
100      */

101     protected void setErrorMessage(String JavaDoc newError) {
102         boolean changed =
103                 (errorMessage == null && newError != null) ||
104                 (errorMessage != null && !errorMessage.equals(newError));
105         if (changed) errorMessage = newError;
106         setValid(newError == null, changed);
107     }
108     
109     
110     /** Sets if the current state of panel is valid or not. */
111     protected void setValid(boolean valid, boolean forceFiring) {
112         boolean changed = this.valid != valid;
113         if (changed) this.valid = valid;
114         if (changed || forceFiring) {
115             fireChange();
116         }
117     }
118     
119     /** Returns error message used by importer wizard. */
120     String JavaDoc getErrorMessage() {
121         return errorMessage;
122     }
123     
124     
125     public boolean isValid() {
126         return valid;
127     }
128     
129     public HelpCtx getHelp() {
130         return null;
131     }
132     
133     public void storeSettings(Object JavaDoc settings) {;}
134     
135     public void readSettings(Object JavaDoc settings) {;}
136 }
137
Popular Tags