KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ejb > wizard > entity > EntityEJBWizard


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.entity;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.modules.j2ee.ejbcore.api.codegeneration.EntityGenerator;
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.spi.java.project.support.ui.templates.JavaTemplates;
32 import org.netbeans.spi.project.ui.templates.support.Templates;
33 import org.openide.ErrorManager;
34 import org.openide.filesystems.FileObject;
35 import org.netbeans.modules.j2ee.common.Util;
36 import org.netbeans.modules.j2ee.ejbcore.Utils;
37 import org.openide.WizardDescriptor;
38 import org.openide.util.NbBundle;
39 /**
40  *
41  * @author Chris Webster
42  * @author Martin Adamek
43  */

44 public final class EntityEJBWizard implements WizardDescriptor.InstantiatingIterator {
45
46     private WizardDescriptor.Panel[] panels;
47     private int index = 0;
48     private EntityEJBWizardDescriptor ejbPanel;
49     private WizardDescriptor wiz;
50
51     public static EntityEJBWizard create () {
52         return new EntityEJBWizard ();
53     }
54
55     public String JavaDoc name () {
56         return NbBundle.getMessage (EntityEJBWizard.class, "LBL_EntityEJBWizardTitle");
57     }
58
59     public void uninitialize(WizardDescriptor wiz) {
60     }
61
62     public void initialize(WizardDescriptor wizardDescriptor) {
63         wiz = wizardDescriptor;
64         Project project = Templates.getProject(wiz);
65         SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project);
66         ejbPanel = new EntityEJBWizardDescriptor();
67         WizardDescriptor.Panel wizardPanel = JavaTemplates.createPackageChooser(project,sourceGroups, ejbPanel, true);
68
69         JComponent JavaDoc jComponent = (JComponent JavaDoc) wizardPanel.getComponent();
70         Util.changeLabelInComponent(jComponent, NbBundle.getMessage(EntityEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(EntityEJBWizard.class, "LBL_EJB_Name") );
71         Util.hideLabelAndLabelFor(jComponent, NbBundle.getMessage(EntityEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label"));
72         panels = new WizardDescriptor.Panel[] {wizardPanel};
73         Utils.mergeSteps(wiz, panels, null);
74
75     }
76
77     public Set JavaDoc instantiate () {
78         boolean isCMP = ejbPanel.isCMP();
79         EntityGenerator entityGenerator = EntityGenerator.create(
80                 Templates.getTargetName(wiz),
81                 Templates.getTargetFolder(wiz),
82                 ejbPanel.hasRemote(),
83                 ejbPanel.hasLocal(),
84                 isCMP,
85                 ejbPanel.getPrimaryKeyClassName()
86                 );
87         FileObject result = null;
88         try {
89             result = entityGenerator.generate();
90         } catch (IOException JavaDoc ex) {
91             ErrorManager.getDefault().notify(ex);
92         }
93         return result == null ? Collections.<FileObject>emptySet() : Collections.singleton(result);
94     }
95
96     public void addChangeListener(ChangeListener JavaDoc listener) {
97     }
98
99     public void removeChangeListener(ChangeListener JavaDoc listener) {
100     }
101
102     public boolean hasPrevious () {
103         return index > 0;
104     }
105
106     public boolean hasNext () {
107     return index < panels.length - 1;
108     }
109
110     public void nextPanel () {
111         if (! hasNext ()) {
112             throw new NoSuchElementException JavaDoc();
113         }
114         index++;
115     }
116
117     public void previousPanel () {
118         if (! hasPrevious ()) {
119             throw new NoSuchElementException JavaDoc();
120         }
121         index--;
122     }
123
124     public WizardDescriptor.Panel current() {
125         return panels[index];
126     }
127 }
128
129
Popular Tags