KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ejb > wizard > session > SessionEJBWizard


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.ejb.wizard.session;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.modules.j2ee.ejbcore.api.codegeneration.SessionGenerator;
24 import java.util.Collections JavaDoc;
25 import java.util.NoSuchElementException JavaDoc;
26 import java.util.Set JavaDoc;
27 import javax.swing.JComponent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.api.project.SourceGroup;
31 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
32 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
33 import org.netbeans.spi.project.ui.templates.support.Templates;
34 import org.openide.filesystems.FileObject;
35 import org.netbeans.modules.j2ee.common.Util;
36 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
37 import org.netbeans.modules.j2ee.ejbcore.Utils;
38 import org.openide.ErrorManager;
39 import org.openide.WizardDescriptor;
40 import org.openide.util.NbBundle;
41
42 /**
43  *
44  * @author Chris Webster
45  * @author Martin Adamek
46  */

47 public final class SessionEJBWizard implements WizardDescriptor.InstantiatingIterator{
48
49     private WizardDescriptor.Panel[] panels;
50     private int index = 0;
51     private SessionEJBWizardDescriptor ejbPanel;
52     private WizardDescriptor wiz;
53
54     public static SessionEJBWizard create () {
55         return new SessionEJBWizard ();
56     }
57
58     public String JavaDoc name () {
59     return NbBundle.getMessage (SessionEJBWizard.class,
60                      "LBL_SessionEJBWizardTitle");
61     }
62
63     public void uninitialize(WizardDescriptor wiz) {
64     }
65
66     public void initialize(WizardDescriptor wizardDescriptor) {
67         wiz = wizardDescriptor;
68         Project project = Templates.getProject(wiz);
69         SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project);
70         ejbPanel = new SessionEJBWizardDescriptor();
71         WizardDescriptor.Panel wizardDescriptorPanel = JavaTemplates.createPackageChooser(project,sourceGroups, ejbPanel, true);
72
73     JComponent JavaDoc jComponent = (JComponent JavaDoc) wizardDescriptorPanel.getComponent();
74         Util.changeLabelInComponent(jComponent,
75                 NbBundle.getMessage(SessionEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"),
76                 NbBundle.getMessage(SessionEJBWizard.class, "LBL_EJB_Name"));
77         Util.hideLabelAndLabelFor(jComponent,
78                 NbBundle.getMessage(SessionEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label"));
79         panels = new WizardDescriptor.Panel[] {wizardDescriptorPanel};
80         Utils.mergeSteps(wiz, panels, null);
81     }
82
83     public Set JavaDoc instantiate () {
84         FileObject pkg = Templates.getTargetFolder(wiz);
85         EjbJar ejbModule = EjbJar.getEjbJar(pkg);
86         // TODO: UI - add checkbox for Java EE 5 to create also EJB 2.1 style EJBs
87
boolean isSimplified = ejbModule.getJ2eePlatformVersion().equals(J2eeModule.JAVA_EE_5);
88         SessionGenerator sessionGenerator = SessionGenerator.create(
89                 Templates.getTargetName(wiz),
90                 pkg,
91                 ejbPanel.hasRemote(),
92                 ejbPanel.hasLocal(),
93                 ejbPanel.isStateful(),
94                 isSimplified,
95                 true, // TODO: UI - add checkbox for creation of business interface
96
!isSimplified // TODO: UI - add checkbox for option XML (not annotation) usage
97
);
98         FileObject result = null;
99         try {
100             result = sessionGenerator.generate();
101         } catch (IOException JavaDoc ex) {
102             ErrorManager.getDefault().notify(ex);
103         }
104         return result == null ? Collections.<FileObject>emptySet() : Collections.singleton(result);
105     }
106
107     public void addChangeListener(ChangeListener JavaDoc listener) {
108     }
109
110     public void removeChangeListener(ChangeListener JavaDoc listener) {
111     }
112
113     public boolean hasPrevious () {
114         return index > 0;
115     }
116
117     public boolean hasNext () {
118     return index < panels.length - 1;
119     }
120
121     public void nextPanel () {
122         if (! hasNext ()) {
123             throw new NoSuchElementException JavaDoc ();
124         }
125         index++;
126     }
127     public void previousPanel () {
128         if (! hasPrevious ()) {
129             throw new NoSuchElementException JavaDoc ();
130         }
131         index--;
132     }
133     public WizardDescriptor.Panel current () {
134         return panels[index];
135     }
136
137 }
138
139
Popular Tags