KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > BasicWizardPanel


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.apisupport.project.ui.wizard;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import javax.swing.event.ChangeEvent JavaDoc;
25 import javax.swing.event.ChangeListener JavaDoc;
26 import javax.swing.event.EventListenerList JavaDoc;
27 import org.openide.WizardDescriptor;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30
31 /**
32  * Basic wizard panel for APISupport projects.
33  *
34  * @author Martin Krauskopf
35  */

36 public abstract class BasicWizardPanel implements WizardDescriptor.Panel, PropertyChangeListener JavaDoc {
37     
38     private boolean valid = true;
39     private WizardDescriptor settings;
40     
41     private EventListenerList JavaDoc listeners = new EventListenerList JavaDoc();
42     
43     protected BasicWizardPanel(WizardDescriptor settings) {
44         this.settings = settings;
45     }
46     
47     public void setSettings(WizardDescriptor settings) {
48         this.settings = settings;
49     }
50     
51     protected WizardDescriptor getSettings() {
52         return settings;
53     }
54     
55     public void addChangeListener(ChangeListener JavaDoc l) {
56         listeners.add(ChangeListener JavaDoc.class, l);
57     }
58     
59     public void removeChangeListener(ChangeListener JavaDoc l) {
60         listeners.remove(ChangeListener JavaDoc.class, l);
61     }
62     
63     protected void fireChange() {
64         ChangeListener JavaDoc[] chListeners = (ChangeListener JavaDoc[]) listeners.
65                 getListeners(ChangeListener JavaDoc.class);
66         ChangeEvent JavaDoc e = new ChangeEvent JavaDoc(this);
67         for (int i = 0; i < chListeners.length; i++) {
68             chListeners[i].stateChanged(e);
69         }
70     }
71     
72     /**
73      * Convenience method for accessing Bundle resources from this package.
74      */

75     protected final String JavaDoc getMessage(String JavaDoc key) {
76         return NbBundle.getMessage(getClass(), key);
77     }
78     
79     public HelpCtx getHelp() {
80         return null;
81     }
82     
83     public void storeSettings(Object JavaDoc settings) {}
84     
85     public void readSettings(Object JavaDoc settings) {}
86     
87     public boolean isValid() {
88         return valid;
89     }
90     
91     /**
92      * Mainly for receiving events from wrapped component about its validity.
93      * Firing events further to Wizard descriptor so it will reread this panel's
94      * state and reenable/redisable its next/prev/finish/... buttons.
95      */

96     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
97         if ("valid".equals(evt.getPropertyName())) { // NOI18N
98
boolean nueValid = ((Boolean JavaDoc) evt.getNewValue()).booleanValue();
99             if (nueValid != valid) {
100                 valid = nueValid;
101                 fireChange();
102             }
103         }
104     }
105     
106     abstract static class NewTemplatePanel extends BasicWizardPanel {
107         
108         private final NewModuleProjectData data;
109         
110         NewTemplatePanel(final NewModuleProjectData data) {
111             super(data.getSettings());
112             this.data = data;
113         }
114         
115         abstract void reloadData();
116         abstract void storeData();
117         
118         public NewModuleProjectData getData() {
119             return data;
120         }
121         
122         public void readSettings(Object JavaDoc settings) {
123             reloadData();
124         }
125         
126         public void storeSettings(Object JavaDoc settings) {
127             storeData();
128         }
129         
130         protected String JavaDoc getWizardTypeString() {
131             String JavaDoc helpId = null;
132             switch (data.getWizardType()) {
133                 case NewNbModuleWizardIterator.TYPE_SUITE:
134                     helpId = "suite"; // NOI18N
135
break;
136                 case NewNbModuleWizardIterator.TYPE_MODULE:
137                 case NewNbModuleWizardIterator.TYPE_SUITE_COMPONENT:
138                     helpId = "module"; // NOI18N
139
break;
140                 case NewNbModuleWizardIterator.TYPE_LIBRARY_MODULE:
141                     helpId = "library"; // NOI18N
142
break;
143                 default:
144                     assert false : "Unknown wizard type = " + data.getWizardType();
145             }
146             return helpId;
147         }
148         
149     }
150     
151 }
Popular Tags