KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ui > TemplateChooserPanel


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.project.ui;
21
22 import java.awt.Component JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.event.ChangeEvent JavaDoc;
26 import javax.swing.event.ChangeListener JavaDoc;
27 import org.netbeans.api.project.Project;
28 import org.netbeans.modules.project.uiapi.ProjectChooserFactory;
29 import org.openide.NotifyDescriptor;
30 import org.openide.WizardDescriptor;
31 import org.openide.ErrorManager;
32 import org.openide.loaders.DataObject;
33 import org.openide.loaders.DataObjectNotFoundException;
34 import org.openide.loaders.TemplateWizard;
35 import org.openide.util.HelpCtx;
36 import org.openide.util.NbBundle;
37
38 /**
39  *
40  * @author Petr Hrebejk
41  */

42
43 final class TemplateChooserPanel implements WizardDescriptor.Panel, ChangeListener JavaDoc {
44
45     private static String JavaDoc lastCategory = null;
46     private static String JavaDoc lastTemplate = null;
47
48     private final List JavaDoc<ChangeListener JavaDoc> listeners = new ArrayList JavaDoc<ChangeListener JavaDoc>();
49     private TemplateChooserPanelGUI gui;
50
51     private Project project;
52     // private String[] recommendedTypes;
53

54     TemplateChooserPanel( Project p /*, String recommendedTypes[] */ ) {
55         this.project = p;
56         /* this.recommendedTypes = recommendedTypes; */
57     }
58
59     public Component JavaDoc getComponent() {
60         if (gui == null) {
61             gui = new TemplateChooserPanelGUI();
62             gui.addChangeListener(this);
63         }
64         return gui;
65     }
66
67     public HelpCtx getHelp() {
68         // XXX
69
return null;
70     }
71
72     public boolean isValid() {
73         return gui != null && gui.getTemplate() != null;
74     }
75
76     public synchronized void addChangeListener(ChangeListener JavaDoc l) {
77         listeners.add(l);
78     }
79
80     public synchronized void removeChangeListener(ChangeListener JavaDoc l) {
81         listeners.remove(l);
82     }
83
84     private void fireChange() {
85         ChangeEvent JavaDoc e = new ChangeEvent JavaDoc(this);
86         List JavaDoc<ChangeListener JavaDoc> templist;
87         synchronized (this) {
88             templist = new ArrayList JavaDoc<ChangeListener JavaDoc> (listeners);
89         }
90     for (ChangeListener JavaDoc l: templist) {
91             l.stateChanged(e);
92         }
93     }
94
95     public void readSettings(Object JavaDoc settings) {
96         TemplateChooserPanelGUI panel = (TemplateChooserPanelGUI) this.getComponent();
97         panel.readValues( project, lastCategory, lastTemplate );
98         ((WizardDescriptor)settings).putProperty ("WizardPanel_contentSelectedIndex", new Integer JavaDoc (0)); // NOI18N
99
((WizardDescriptor)settings).putProperty ("WizardPanel_contentData", new String JavaDoc[] { // NOI18N
100
NbBundle.getBundle (TemplateChooserPanel.class).getString ("LBL_TemplatesPanel_Name"), // NOI18N
101
NbBundle.getBundle (TemplateChooserPanel.class).getString ("LBL_TemplatesPanel_Dots")}); // NOI18N
102
// bugfix #44400: wizard title always changes
103
((WizardDescriptor)settings).putProperty ("NewFileWizard_Title", null); // NOI18N
104
}
105
106     public void storeSettings(Object JavaDoc settings) {
107             
108         WizardDescriptor wd = (WizardDescriptor)settings;
109         
110         Object JavaDoc value = wd.getValue();
111         
112         if ( NotifyDescriptor.CANCEL_OPTION != value &&
113              NotifyDescriptor.CLOSED_OPTION != value ) {
114             try {
115
116                 Project newProject = gui.getProject ();
117                 if (!project.equals (newProject)) {
118                     project = newProject;
119                     wd.putProperty( ProjectChooserFactory.WIZARD_KEY_PROJECT, newProject );
120                 }
121                 
122                 if (gui.getTemplate () == null) {
123                     return ;
124                 }
125                 
126                 if (wd instanceof TemplateWizard) {
127                     ((TemplateWizard)wd).setTemplate( DataObject.find( gui.getTemplate() ) );
128                 } else {
129                     wd.putProperty( ProjectChooserFactory.WIZARD_KEY_TEMPLATE, gui.getTemplate () );
130                 }
131
132                 lastCategory = gui.getCategoryName();
133                 lastTemplate = gui.getTemplateName();
134             }
135             catch( DataObjectNotFoundException e ) {
136                 ErrorManager.getDefault().notify (e);
137             }
138         }
139     }
140
141     public void stateChanged(ChangeEvent JavaDoc e) {
142         /*
143         FileObject template = gui.getTemplate();
144         p = gui.getProject();
145         if (template != null) {
146             setDelegate(findTemplateWizardIterator(template, p));
147         } else {
148             setDelegate(null);
149         }
150          */

151         fireChange();
152         
153     }
154
155 }
156     
Popular Tags