KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > wizards > PersistenceClientIterator


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.jsf.wizards;
21
22 import java.awt.Component JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.List 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.ProjectUtils;
32 import org.netbeans.api.project.SourceGroup;
33 import org.netbeans.modules.j2ee.common.DelegatingWizardDescriptorPanel;
34 //TODO: RETOUCHE
35
//import org.netbeans.modules.j2ee.persistence.dd.orm.model_1_0.Entity;
36
//import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.PersistenceUnit;
37
//import org.netbeans.modules.j2ee.persistence.provider.ProviderUtil;
38
//import org.netbeans.modules.j2ee.persistence.unit.PUDataObject;
39
//import org.netbeans.modules.j2ee.persistence.wizard.PersistenceClientEntitySelection;
40
//import org.netbeans.modules.j2ee.persistence.wizard.Util;
41
import org.netbeans.modules.web.api.webmodule.WebModule;
42 import org.netbeans.modules.web.jsf.JSFConfigUtilities;
43 import org.netbeans.spi.project.ui.templates.support.Templates;
44 import org.openide.WizardDescriptor;
45 import org.openide.filesystems.FileObject;
46 import org.openide.loaders.DataFolder;
47 import org.openide.loaders.TemplateWizard;
48 import org.openide.util.HelpCtx;
49 import org.openide.util.NbBundle;
50
51 /**
52  *
53  * @author Pavel Buzek
54  */

55 public class PersistenceClientIterator implements TemplateWizard.Iterator {
56     
57     private int index;
58     private transient WizardDescriptor.Panel[] panels;
59     
60     public Set JavaDoc instantiate(TemplateWizard wizard) throws IOException JavaDoc {
61 // List<Entity> entities = (List<Entity>) wizard.getProperty(WizardProperties.ENTITY_CLASS);
62
// String jsfFolder = (String) wizard.getProperty(WizardProperties.JSF_FOLDER);
63
// Project project = Templates.getProject(wizard);
64
// FileObject targetFolder = Templates.getTargetFolder(wizard);
65
// String controllerPkg = (String) wizard.getProperty(WizardProperties.JSF_CLASSES_PACKAGE);
66
//
67
// PersistenceUnit persistenceUnit =
68
// (PersistenceUnit) wizard.getProperty(org.netbeans.modules.j2ee.persistence.wizard.WizardProperties.PERSISTENCE_UNIT);
69
//
70
// if (persistenceUnit != null){
71
// ProviderUtil.addPersistenceUnit(persistenceUnit, Templates.getProject(wizard));
72
// }
73
//
74
// for (Entity entity : entities) {
75
// String entityClass = entity.getClass2();
76
// String simpleClassName = JSFClientGenerator.simpleClassName(entityClass);
77
// String firstLower = simpleClassName.substring(0, 1).toLowerCase() + simpleClassName.substring(1);
78
// String folder = jsfFolder.endsWith("/") ? jsfFolder : jsfFolder + "/";
79
// folder = folder + firstLower;
80
// String controller = controllerPkg + "." + simpleClassName + "Controller";
81
// JSFClientGenerator.generateJSFPages(project, entityClass, folder, controller, targetFolder);
82
// }
83
//
84
// return Collections.singleton(DataFolder.findFolder(targetFolder));
85
return null;
86     }
87
88     public void initialize(TemplateWizard wizard) {
89 // index = 0;
90
// // obtaining target folder
91
// Project project = Templates.getProject( wizard );
92
// DataFolder targetFolder=null;
93
// try {
94
// targetFolder = wizard.getTargetFolder();
95
// } catch (IOException ex) {
96
// targetFolder = DataFolder.findFolder(project.getProjectDirectory());
97
// }
98
//
99
// SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
100
//
101
// WizardDescriptor.Panel secondPanel = new ValidationPanel(
102
// new PersistenceClientEntitySelection(NbBundle.getMessage(PersistenceClientIterator.class, "LBL_EntityClasses"),
103
// new HelpCtx(PersistenceClientIterator.class.getName() + "$PersistenceClientEntitySelection"), wizard)); // NOI18N
104
// WizardDescriptor.Panel thirdPanel = new PersistenceClientSetupPanel(project, wizard);
105
//// WizardDescriptor.Panel javaPanel = JavaTemplates.createPackageChooser(project, sourceGroups, secondPanel);
106
//// panels = new WizardDescriptor.Panel[] { javaPanel };
107
// panels = new WizardDescriptor.Panel[] { secondPanel, thirdPanel };
108
// String names[] = new String[] {
109
// NbBundle.getMessage(PersistenceClientIterator.class, "LBL_EntityClasses"),
110
// NbBundle.getMessage(PersistenceClientIterator.class, "LBL_JSFPagesAndClasses")
111
// };
112
// wizard.putProperty("NewFileWizard_Title",
113
// NbBundle.getMessage(PersistenceClientIterator.class, "Templates/Persistence/JsfFromDB"));
114
// Util.mergeSteps(wizard, panels, names);
115
}
116
117     private String JavaDoc[] createSteps(String JavaDoc[] before, WizardDescriptor.Panel[] panels) {
118         int diff = 0;
119         if (before == null) {
120             before = new String JavaDoc[0];
121         } else if (before.length > 0) {
122             diff = ("...".equals (before[before.length - 1])) ? 1 : 0; // NOI18N
123
}
124         String JavaDoc[] res = new String JavaDoc[ (before.length - diff) + panels.length];
125         for (int i = 0; i < res.length; i++) {
126             if (i < (before.length - diff)) {
127                 res[i] = before[i];
128             } else {
129                 res[i] = panels[i - before.length + diff].getComponent ().getName ();
130             }
131         }
132         return res;
133     }
134     
135     public void uninitialize(TemplateWizard wiz) {
136         panels = null;
137     }
138
139     public WizardDescriptor.Panel current() {
140         return panels[index];
141     }
142
143     public String JavaDoc name() {
144         return NbBundle.getMessage (PersistenceClientIterator.class, "LBL_WizardTitle_FromEntity");
145     }
146
147     public boolean hasNext() {
148         return index < panels.length - 1;
149     }
150
151     public boolean hasPrevious() {
152         return index > 0;
153     }
154
155     public void nextPanel() {
156         if (! hasNext ()) throw new NoSuchElementException JavaDoc ();
157         index++;
158     }
159
160     public void previousPanel() {
161         if (! hasPrevious ()) throw new NoSuchElementException JavaDoc ();
162         index--;
163     }
164
165     public void addChangeListener(ChangeListener JavaDoc l) {
166     }
167
168     public void removeChangeListener(ChangeListener JavaDoc l) {
169     }
170     
171     /**
172      * A panel which checks that the target project has a valid server set
173      * otherwise it delegates to the real panel.
174      */

175     private class ValidationPanel extends DelegatingWizardDescriptorPanel {
176
177         private ValidationPanel(WizardDescriptor.Panel delegate) {
178             super(delegate);
179         }
180         
181         public boolean isValid() {
182             Project project = getProject();
183             WizardDescriptor wizardDescriptor = getWizardDescriptor();
184             
185             // check that this project has a valid target server
186
if (!org.netbeans.modules.j2ee.common.Util.isValidServerInstance(project)) {
187                 wizardDescriptor.putProperty("WizardPanel_errorMessage",
188                         NbBundle.getMessage(PersistenceClientIterator.class, "ERR_MissingServer")); // NOI18N
189
return false;
190             }
191
192             return super.isValid();
193         }
194     }
195 }
196
Popular Tags