KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > TemplateWizardPanel2


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.openide.loaders;
21
22 import javax.swing.event.ChangeListener JavaDoc;
23 import org.openide.WizardDescriptor;
24 import org.openide.util.HelpCtx;
25
26 /** Implementaion of WizardDescriptor.Panel that can be used in create from template.
27  *
28  * @author Jiri Rechtacek
29  */

30 final class TemplateWizardPanel2 implements WizardDescriptor.FinishablePanel<WizardDescriptor> {
31     private TemplateWizard2 templateWizard2UI;
32     /** listener to changes in the wizard */
33     private ChangeListener JavaDoc listener;
34
35     private WizardDescriptor settings;
36
37     private TemplateWizard2 getPanelUI () {
38         if (templateWizard2UI == null) {
39             templateWizard2UI = new TemplateWizard2 ();
40             templateWizard2UI.addChangeListener (listener);
41         }
42         return templateWizard2UI;
43     }
44     
45     /** Add a listener to changes of the panel's validity.
46     * @param l the listener to add
47     * @see #isValid
48     */

49     public void addChangeListener (ChangeListener JavaDoc l) {
50         if (listener != null) throw new IllegalStateException JavaDoc ();
51         if (templateWizard2UI != null)
52             templateWizard2UI.addChangeListener (l);
53         listener = l;
54     }
55
56     /** Remove a listener to changes of the panel's validity.
57     * @param l the listener to remove
58     */

59     public void removeChangeListener (ChangeListener JavaDoc l) {
60         listener = null;
61         if (templateWizard2UI != null)
62             templateWizard2UI.removeChangeListener (l);
63     }
64
65     /** Get the component displayed in this panel.
66      *
67      * Note; method can be called from any thread, but not concurrently
68      * with other methods of this interface.
69      *
70      * @return the UI component of this wizard panel
71      *
72      */

73     public java.awt.Component JavaDoc getComponent() {
74         return getPanelUI ();
75     }
76     
77     /** Help for this panel.
78      * When the panel is active, this is used as the help for the wizard dialog.
79      * @return the help or <code>null</code> if no help is supplied
80      *
81      */

82     public HelpCtx getHelp() {
83         return new HelpCtx (TemplateWizard2.class);
84     }
85     
86     /** Test whether the panel is finished and it is safe to proceed to the next one.
87     * If the panel is valid, the "Next" (or "Finish") button will be enabled.
88     * @return <code>true</code> if the user has entered satisfactory information
89     */

90     public boolean isValid() {
91         if (templateWizard2UI == null) {
92             return false;
93         }
94         
95         String JavaDoc err = getPanelUI().implIsValid();
96         // bugfix #34799, don't set errorMessage if the panel is not showed
97
if (getPanelUI ().isShowing ()) {
98             settings.putProperty("WizardPanel_errorMessage", err); //NOI18N
99
}
100         return err == null;
101     }
102     
103     /** Provides the wizard panel with the current data--either
104      * the default data or already-modified settings, if the user used the previous and/or next buttons.
105      * This method can be called multiple times on one instance of <code>WizardDescriptor.Panel</code>.
106      * <p>The settings object is originally supplied to {@link WizardDescriptor#WizardDescriptor(WizardDescriptor.Iterator,Object)}.
107      * In the case of a <code>TemplateWizard.Iterator</code> panel, the object is
108      * in fact the <code>TemplateWizard</code>.
109      * @param settings the object representing wizard panel state
110      * @exception IllegalStateException if the the data provided
111      * by the wizard are not valid.
112      *
113      */

114     public void readSettings(WizardDescriptor settings) {
115         this.settings = (WizardDescriptor)settings;
116         getPanelUI ().implReadSettings (settings);
117     }
118     
119     /** Provides the wizard panel with the opportunity to update the
120      * settings with its current customized state.
121      * Rather than updating its settings with every change in the GUI, it should collect them,
122      * and then only save them when requested to by this method.
123      * Also, the original settings passed to {@link #readSettings} should not be modified (mutated);
124      * rather, the object passed in here should be mutated according to the collected changes,
125      * in case it is a copy.
126      * This method can be called multiple times on one instance of <code>WizardDescriptor.Panel</code>.
127      * <p>The settings object is originally supplied to {@link WizardDescriptor#WizardDescriptor(WizardDescriptor.Iterator,Object)}.
128      * In the case of a <code>TemplateWizard.Iterator</code> panel, the object is
129      * in fact the <code>TemplateWizard</code>.
130      * @param settings the object representing wizard panel state
131      *
132      */

133     public void storeSettings(WizardDescriptor settings) {
134         getPanelUI ().implStoreSettings (settings);
135         this.settings = null;
136     }
137
138     public boolean isFinishPanel() {
139         return true;
140     }
141     
142 }
143
Popular Tags