KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ejb > wizard > mdb > MessageEJBWizard


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.mdb;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.modules.j2ee.ejbcore.api.codegeneration.MessageGenerator;
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.modules.j2ee.common.DelegatingWizardDescriptorPanel;
33 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
34 import org.netbeans.spi.project.ui.templates.support.Templates;
35 import org.openide.filesystems.FileObject;
36 import org.netbeans.modules.j2ee.common.Util;
37 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
38 import org.netbeans.modules.j2ee.ejbcore.Utils;
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 MessageEJBWizard implements WizardDescriptor.InstantiatingIterator{
48
49     private WizardDescriptor.Panel[] panels;
50     private int index = 0;
51     private MessageEJBWizardPanel ejbPanel;
52     private WizardDescriptor wiz;
53
54     private static final String JavaDoc [] SESSION_STEPS = new String JavaDoc [] {
55         NbBundle.getMessage(MessageEJBWizard.class, "LBL_SpecifyEJBInfo")
56     };
57
58     public String JavaDoc name () {
59         return NbBundle.getMessage (MessageEJBWizard.class, "LBL_MessageEJBWizardTitle");
60     }
61
62     public void uninitialize(WizardDescriptor wiz) {
63     }
64
65     public void initialize(WizardDescriptor wizardDescriptor) {
66         wiz = wizardDescriptor;
67         Project project = Templates.getProject(wiz);
68         SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project);
69         ejbPanel = new MessageEJBWizardPanel(wiz);
70         WizardDescriptor.Panel wizardPanel = new ValidatingPanel(JavaTemplates.createPackageChooser(project,sourceGroups, ejbPanel, true));
71         JComponent JavaDoc jComponent = (JComponent JavaDoc) wizardPanel.getComponent ();
72         Util.changeLabelInComponent(jComponent, NbBundle.getMessage(MessageEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(MessageEJBWizard.class, "LBL_EJB_Name") );
73         Util.hideLabelAndLabelFor(jComponent, NbBundle.getMessage(MessageEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label"));
74         panels = new WizardDescriptor.Panel[] {wizardPanel};
75         Utils.mergeSteps(wiz, panels, SESSION_STEPS);
76     }
77
78     public Set JavaDoc instantiate() throws IOException JavaDoc {
79         FileObject pkg = Templates.getTargetFolder(wiz);
80         EjbJar ejbModule = EjbJar.getEjbJar(pkg);
81         
82         // TODO: UI - add checkbox for Java EE 5 to create also EJB 2.1 style EJBs
83
boolean isSimplified = ejbModule.getJ2eePlatformVersion().equals(J2eeModule.JAVA_EE_5);
84         MessageGenerator generator = MessageGenerator.create(
85                 Templates.getTargetName(wiz),
86                 pkg,
87                 ejbPanel.isQueue(),
88                 isSimplified,
89                 !isSimplified // TODO: UI - add checkbox for option XML (not annotation) usage
90
);
91         FileObject result = generator.generate();
92         return result == null ? Collections.EMPTY_SET : Collections.singleton(result);
93     }
94
95     public void addChangeListener(ChangeListener JavaDoc listener) {
96     }
97
98     public void removeChangeListener(ChangeListener JavaDoc listener) {
99     }
100
101     public boolean hasPrevious () {
102         return index > 0;
103     }
104
105     public boolean hasNext () {
106     return index < panels.length - 1;
107     }
108
109     public void nextPanel () {
110         if (! hasNext ()) {
111             throw new NoSuchElementException JavaDoc ();
112         }
113         index++;
114     }
115     public void previousPanel () {
116         if (! hasPrevious ()) {
117             throw new NoSuchElementException JavaDoc ();
118         }
119         index--;
120     }
121     public WizardDescriptor.Panel current () {
122         return panels[index];
123     }
124
125     /**
126      * A panel which checks whether the target project has a valid server set,
127      * otherwise it delegates to another panel.
128      */

129     private static final class ValidatingPanel extends DelegatingWizardDescriptorPanel {
130
131         public ValidatingPanel(WizardDescriptor.Panel delegate) {
132             super(delegate);
133         }
134
135         public boolean isValid() {
136             if (!org.netbeans.modules.j2ee.common.Util.isValidServerInstance(getProject())) {
137                 getWizardDescriptor().putProperty("WizardPanel_errorMessage",
138                         NbBundle.getMessage(MessageEJBWizard.class, "ERR_MissingServer")); // NOI18N
139
return false;
140             }
141             return super.isValid();
142         }
143     }
144 }
145
Popular Tags