KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > patterns > ServiceLocatorWizard


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.j2ee.ejbcore.patterns;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.api.project.ProjectUtils;
24 import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer;
25 import java.util.Collections JavaDoc;
26 import java.util.NoSuchElementException JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.netbeans.api.java.project.JavaProjectConstants;
30 import org.netbeans.api.project.Project;
31 import org.netbeans.api.project.SourceGroup;
32 import org.netbeans.api.project.Sources;
33 import org.netbeans.modules.j2ee.ejbcore.EjbGenerationUtil;
34 import org.netbeans.modules.j2ee.ejbcore.Utils;
35 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
36 import org.netbeans.spi.project.ui.templates.support.Templates;
37 import org.openide.WizardDescriptor;
38 import org.openide.filesystems.FileObject;
39 import org.openide.loaders.DataFolder;
40 import org.openide.loaders.DataObject;
41 import org.openide.util.NbBundle;
42
43
44 /**
45  *
46  * @author Chris Webster
47  * @author Martin Adamek
48  */

49 public final class ServiceLocatorWizard implements WizardDescriptor.InstantiatingIterator {
50     private WizardDescriptor.Panel[] panels;
51     private int index = 0;
52     private WizardDescriptor wiz;
53     
54     private static final String JavaDoc [] STEPS =
55                                    new String JavaDoc [] {
56                                        NbBundle.getMessage (ServiceLocatorWizard.class,
57                          "LBL_SpecifyName")
58                                    };
59                                
60     public String JavaDoc name () {
61     return NbBundle.getMessage (ServiceLocatorWizard.class,
62                     "LBL_MessageServiceLocatorWizardTitle");
63     }
64
65     public void uninitialize(WizardDescriptor wiz) {
66     }
67     
68     public void initialize(WizardDescriptor wizardDescriptor) {
69         wiz = wizardDescriptor;
70         Project project = Templates.getProject(wiz);
71         Sources sources = ProjectUtils.getSources(project);
72         SourceGroup[] sourceGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
73         panels = new WizardDescriptor.Panel[] {JavaTemplates.createPackageChooser(project,sourceGroups)};
74         Utils.mergeSteps(wiz, panels, STEPS);
75     }
76     
77     public Set JavaDoc instantiate () throws IOException JavaDoc {
78         FileObject pkg = Templates.getTargetFolder(wiz);
79         String JavaDoc clsName = Templates.getTargetName(wiz);
80         Project project = Templates.getProject(wiz);
81         DataFolder dataFolder = DataFolder.findFolder(pkg);
82         FileObject template = Templates.getTemplate(wiz);
83         DataObject dTemplate = DataObject.find( template );
84         DataObject dobj = dTemplate.createFromTemplate( dataFolder, clsName);
85         String JavaDoc pkgName = EjbGenerationUtil.getSelectedPackageName(pkg);
86         String JavaDoc fullName = (pkgName.length()>0?pkgName+'.':"")+clsName;
87         EnterpriseReferenceContainer erc = (EnterpriseReferenceContainer)
88                 project.getLookup().lookup(EnterpriseReferenceContainer.class);
89         if (erc != null) {
90             erc.setServiceLocatorName(fullName);
91         }
92         FileObject createdFile = dobj.getPrimaryFile();
93         
94         return Collections.singleton(createdFile);
95     }
96     
97     public void addChangeListener(ChangeListener JavaDoc listener) {
98     }
99     
100     public void removeChangeListener(ChangeListener JavaDoc listener) {
101     }
102     
103     public boolean hasPrevious () {
104         return index > 0;
105     }
106     
107     public boolean hasNext () {
108     return index < panels.length - 1;
109     }
110     
111     public void nextPanel () {
112         if (! hasNext ()) {
113             throw new NoSuchElementException JavaDoc ();
114         }
115         index++;
116     }
117     
118     public void previousPanel () {
119         if (! hasPrevious ()) {
120             throw new NoSuchElementException JavaDoc ();
121         }
122         index--;
123     }
124     
125     public WizardDescriptor.Panel current () {
126         return panels[index];
127     }
128     
129 }
130
131
Popular Tags