KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > wizards > ServletPanel


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.web.wizards;
21
22 import java.awt.Component JavaDoc;
23
24 import javax.swing.event.ChangeListener JavaDoc;
25 import org.netbeans.api.java.project.JavaProjectConstants;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.api.project.ProjectUtils;
28
29 import org.openide.WizardDescriptor;
30 import org.openide.loaders.TemplateWizard;
31 import org.openide.util.HelpCtx;
32 import org.netbeans.spi.project.ui.templates.support.Templates;
33 import org.netbeans.modules.web.api.webmodule.WebModule;
34 import org.netbeans.api.project.SourceGroup;
35 import org.netbeans.api.project.Sources;
36 import org.openide.filesystems.FileObject;
37
38 /* Wizard panel that collects data for the Servlet and Filter
39  * wizards.
40  *
41  * @author Ana von Klopp, Milan Kuchtiak
42  */

43 public class ServletPanel implements WizardDescriptor.FinishPanel {
44     
45     /** The visual component that displays this panel.
46      * If you need to access the component from this class,
47      * just use getComponent().
48      */

49     private transient BaseWizardPanel wizardPanel;
50     private transient TemplateWizard wizard;
51     /** listener to changes in the wizard */
52     private ChangeListener JavaDoc listener;
53     private DeployData deployData;
54     private transient TargetEvaluator evaluator;
55
56     /** Create the wizard panel descriptor. */
57     private ServletPanel(TargetEvaluator evaluator, TemplateWizard wizard,
58              boolean first) {
59         this.evaluator=evaluator;
60     this.wizard = wizard;
61     this.deployData = evaluator.getDeployData();
62     if(first)
63         this.wizardPanel = new DeployDataPanel(evaluator);
64     else
65         this.wizardPanel = new DeployDataExtraPanel(evaluator);
66     }
67
68     /** Create the wizard panel descriptor. */
69     public static ServletPanel createServletPanel(TargetEvaluator evaluator,
70                           TemplateWizard wizard) {
71     return new ServletPanel(evaluator, wizard, true);
72     }
73
74     /** Create the wizard panel descriptor. */
75     public static ServletPanel createFilterPanel(TargetEvaluator evaluator,
76                           TemplateWizard wizard) {
77     return new ServletPanel(evaluator, wizard, false);
78     }
79     
80     public Component JavaDoc getComponent () {
81         return wizardPanel;
82     }
83
84     public boolean isValid() {
85     if(deployData.isValid()) {
86         wizard.putProperty("WizardPanel_errorMessage", ""); //NOI18N
87
return true;
88     }
89     wizard.putProperty("WizardPanel_errorMessage", //NOI18N
90
deployData.getErrorMessage());
91     return false;
92     }
93     
94     public HelpCtx getHelp() {
95         return null;
96         //return wizardPanel.getHelp();
97
}
98     
99     /** Add a listener to changes of the panel's validity.
100     * @param l the listener to add
101     * @see #isValid
102     */

103     public void addChangeListener (ChangeListener JavaDoc l) {
104         if (listener != null) throw new IllegalStateException JavaDoc ();
105         if (wizardPanel != null)
106         wizardPanel.addChangeListener (l);
107         listener = l;
108     }
109
110     /** Remove a listener to changes of the panel's validity.
111     * @param l the listener to remove
112     */

113     public void removeChangeListener (ChangeListener JavaDoc l) {
114         listener = null;
115         if (wizardPanel != null)
116         wizardPanel.removeChangeListener (l);
117     }
118     
119     public void readSettings (Object JavaDoc settings) {
120         if(settings instanceof TemplateWizard) {
121             TemplateWizard w = (TemplateWizard)settings;
122             //Project project = Templates.getProject(w);
123
String JavaDoc targetName = w.getTargetName();
124             org.openide.filesystems.FileObject targetFolder = Templates.getTargetFolder(w);
125             Project project = Templates.getProject( w );
126             Sources sources = ProjectUtils.getSources(project);
127             SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
128             String JavaDoc packageName = null;
129             for (int i = 0; i < groups.length && packageName == null; i++) {
130                 if (WebModule.getWebModule (groups [i].getRootFolder ()) != null) {
131                     packageName = org.openide.filesystems.FileUtil.getRelativePath (groups [i].getRootFolder (), targetFolder);
132                 }
133             }
134             if (packageName!=null)
135                 packageName = packageName.replace('/','.');
136             else packageName="";
137             if (targetName==null)
138                 evaluator.setClassName(w.getTemplate().getName(),packageName);
139             else
140                 evaluator.setClassName(targetName,packageName);
141         }
142     wizardPanel.setData();
143     }
144     
145     public void storeSettings (Object JavaDoc settings) {
146     // do nothing
147
}
148 }
Popular Tags