KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > wizard > dao > EjbFacadeVisualPanel2


1 package org.netbeans.modules.j2ee.persistence.wizard.dao;
2
3 import java.io.IOException JavaDoc;
4 import javax.swing.ComboBoxModel JavaDoc;
5 import javax.swing.JPanel JavaDoc;
6 import javax.swing.event.ChangeListener JavaDoc;
7 import javax.swing.event.DocumentEvent JavaDoc;
8 import javax.swing.event.DocumentListener JavaDoc;
9 import javax.swing.text.Document JavaDoc;
10 import javax.swing.text.JTextComponent JavaDoc;
11 import org.netbeans.api.project.Project;
12 import org.netbeans.api.project.ProjectUtils;
13 import org.netbeans.api.project.SourceGroup;
14 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.ChangeSupport;
15 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.SourceGroupSupport;
16 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.SourceGroupUISupport;
17 import org.netbeans.spi.java.project.support.ui.PackageView;
18 import org.netbeans.spi.project.ui.templates.support.Templates;
19 import org.openide.ErrorManager;
20 import org.openide.WizardDescriptor;
21 import org.openide.filesystems.FileObject;
22 import org.openide.util.NbBundle;
23
24 public final class EjbFacadeVisualPanel2 extends JPanel JavaDoc implements DocumentListener JavaDoc {
25     
26     private static final String JavaDoc CLASSNAME_LOCAL = NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_GeneratedFacadeLocal");
27     private static final String JavaDoc CLASSNAME_REMOTE = NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_GeneratedFacadeRemote");
28     
29     private WizardDescriptor wizard;
30     private Project project;
31     private JTextComponent JavaDoc packageComboBoxEditor;
32     private ChangeSupport changeSupport = new ChangeSupport(this);
33
34     public EjbFacadeVisualPanel2(WizardDescriptor wizard) {
35         this.wizard = wizard;
36         initComponents();
37         packageComboBoxEditor = ((JTextComponent JavaDoc)packageComboBox.getEditor().getEditorComponent());
38         Document JavaDoc packageComboBoxDocument = packageComboBoxEditor.getDocument();
39         // TODO: add package listener
40
packageComboBoxDocument.addDocumentListener(this);
41         handleCheckboxes();
42     }
43
44     @Override JavaDoc
45     public String JavaDoc getName() {
46         return NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_GeneratedSessionBeans");
47     }
48     
49     public void addChangeListener(ChangeListener JavaDoc listener) {
50         changeSupport.addChangeListener(listener);
51     }
52     
53     boolean valid(WizardDescriptor wizard) {
54         // TODO: add package listener
55
return true;
56     }
57     
58     public SourceGroup getLocationValue() {
59         return (SourceGroup)locationComboBox.getSelectedItem();
60     }
61
62     public String JavaDoc getPackage() {
63         return packageComboBoxEditor.getText();
64     }
65
66     private void locationChanged() {
67         updateSourceGroupPackages();
68         changeSupport.fireChange();
69     }
70     
71     void read(WizardDescriptor settings) {
72         project = Templates.getProject(settings);
73         FileObject targetFolder = Templates.getTargetFolder(settings);
74         
75         projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName());
76
77         SourceGroup[] sourceGroups = SourceGroupSupport.getJavaSourceGroups(project);
78         SourceGroupUISupport.connect(locationComboBox, sourceGroups);
79
80         packageComboBox.setRenderer(PackageView.listRenderer());
81
82         updateSourceGroupPackages();
83
84         // set default source group and package cf. targetFolder
85
SourceGroup targetSourceGroup = SourceGroupSupport.getFolderSourceGroup(sourceGroups, targetFolder);
86         if (targetSourceGroup != null) {
87             locationComboBox.setSelectedItem(targetSourceGroup);
88             String JavaDoc targetPackage = SourceGroupSupport.getPackageForFolder(targetSourceGroup, targetFolder);
89             if (targetPackage != null) {
90                 packageComboBoxEditor.setText(targetPackage);
91             }
92         }
93
94     }
95     
96     void store(WizardDescriptor settings) {
97         try {
98             Templates.setTargetFolder(settings, SourceGroupSupport.getFolderForPackage(getLocationValue(), getPackage()));
99         } catch (IOException JavaDoc ex) {
100             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
101         }
102     }
103
104     private void updateSourceGroupPackages() {
105         SourceGroup sourceGroup = (SourceGroup)locationComboBox.getSelectedItem();
106         ComboBoxModel JavaDoc model = PackageView.createListView(sourceGroup);
107         if (model.getSelectedItem()!= null && model.getSelectedItem().toString().startsWith("META-INF")
108                 && model.getSize() > 1) { // NOI18N
109
model.setSelectedItem(model.getElementAt(1));
110         }
111         packageComboBox.setModel(model);
112     }
113     
114     public void insertUpdate(DocumentEvent JavaDoc e) {
115     }
116
117     public void removeUpdate(DocumentEvent JavaDoc e) {
118     }
119
120     public void changedUpdate(DocumentEvent JavaDoc e) {
121     }
122
123     boolean isRemote() {
124         return remoteCheckBox.isSelected();
125     }
126     
127     boolean isLocal() {
128         return localCheckBox.isSelected();
129     }
130     
131     private void handleCheckboxes() {
132         createdFilesText.setText(NbBundle.getMessage(
133             EjbFacadeVisualPanel2.class,
134             "LBL_CreatedFIles",
135             isLocal() ? CLASSNAME_LOCAL : "",
136             isRemote() ? CLASSNAME_REMOTE : ""
137         ));
138     }
139     
140     /** This method is called from within the constructor to
141      * initialize the form.
142      * WARNING: Do NOT modify this code. The content of this method is
143      * always regenerated by the Form Editor.
144      */

145     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
146
private void initComponents() {
147         jLabel1 = new javax.swing.JLabel JavaDoc();
148         jLabel2 = new javax.swing.JLabel JavaDoc();
149         jLabel3 = new javax.swing.JLabel JavaDoc();
150         jLabel4 = new javax.swing.JLabel JavaDoc();
151         locationComboBox = new javax.swing.JComboBox JavaDoc();
152         packageComboBox = new javax.swing.JComboBox JavaDoc();
153         projectTextField = new javax.swing.JTextField JavaDoc();
154         jLabel6 = new javax.swing.JLabel JavaDoc();
155         remoteCheckBox = new javax.swing.JCheckBox JavaDoc();
156         localCheckBox = new javax.swing.JCheckBox JavaDoc();
157         createdFilesText = new javax.swing.JTextField JavaDoc();
158         jLabel5 = new javax.swing.JLabel JavaDoc();
159
160         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_SpecifyLocation"));
161
162         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_Project"));
163
164         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_Location"));
165
166         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_Package"));
167
168         packageComboBox.setEditable(true);
169
170         projectTextField.setEditable(false);
171
172         org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_CreateInterface"));
173
174         org.openide.awt.Mnemonics.setLocalizedText(remoteCheckBox, org.openide.util.NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_Remote"));
175         remoteCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
176         remoteCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
177         remoteCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
178             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
179                 remoteCheckBoxActionPerformed(evt);
180             }
181         });
182
183         localCheckBox.setSelected(true);
184         org.openide.awt.Mnemonics.setLocalizedText(localCheckBox, org.openide.util.NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_Local"));
185         localCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
186         localCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
187         localCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
188             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
189                 localCheckBoxActionPerformed(evt);
190             }
191         });
192
193         createdFilesText.setEditable(false);
194         createdFilesText.setHorizontalAlignment(javax.swing.JTextField.LEFT);
195         createdFilesText.setText(org.openide.util.NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_CreatedFIles", new Object JavaDoc[] {"", ""}));
196         createdFilesText.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
197
198         org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_CreatedFilesLabel"));
199
200         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
201         this.setLayout(layout);
202         layout.setHorizontalGroup(
203             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
204             .add(layout.createSequentialGroup()
205                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
206                     .add(jLabel2)
207                     .add(jLabel3)
208                     .add(jLabel4)
209                     .add(jLabel5))
210                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
211                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
212                     .add(projectTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 568, Short.MAX_VALUE)
213                     .add(locationComboBox, 0, 568, Short.MAX_VALUE)
214                     .add(packageComboBox, 0, 568, Short.MAX_VALUE)
215                     .add(createdFilesText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 568, Short.MAX_VALUE)))
216             .add(jLabel1)
217             .add(jLabel6)
218             .add(remoteCheckBox)
219             .add(localCheckBox)
220         );
221         layout.setVerticalGroup(
222             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
223             .add(layout.createSequentialGroup()
224                 .add(jLabel1)
225                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
226                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
227                     .add(jLabel2)
228                     .add(projectTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
229                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
230                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
231                     .add(jLabel3)
232                     .add(locationComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
233                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
234                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
235                     .add(jLabel4)
236                     .add(packageComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
237                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
238                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
239                     .add(jLabel5)
240                     .add(createdFilesText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
241                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
242                 .add(jLabel6)
243                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
244                 .add(remoteCheckBox)
245                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
246                 .add(localCheckBox))
247         );
248     }// </editor-fold>//GEN-END:initComponents
249

250     private void localCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_localCheckBoxActionPerformed
251
handleCheckboxes();
252         changeSupport.fireChange();
253     }//GEN-LAST:event_localCheckBoxActionPerformed
254

255     private void remoteCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_remoteCheckBoxActionPerformed
256
handleCheckboxes();
257         changeSupport.fireChange();
258     }//GEN-LAST:event_remoteCheckBoxActionPerformed
259

260     
261     // Variables declaration - do not modify//GEN-BEGIN:variables
262
private javax.swing.JTextField JavaDoc createdFilesText;
263     private javax.swing.JLabel JavaDoc jLabel1;
264     private javax.swing.JLabel JavaDoc jLabel2;
265     private javax.swing.JLabel JavaDoc jLabel3;
266     private javax.swing.JLabel JavaDoc jLabel4;
267     private javax.swing.JLabel JavaDoc jLabel5;
268     private javax.swing.JLabel JavaDoc jLabel6;
269     private javax.swing.JCheckBox JavaDoc localCheckBox;
270     private javax.swing.JComboBox JavaDoc locationComboBox;
271     private javax.swing.JComboBox JavaDoc packageComboBox;
272     private javax.swing.JTextField JavaDoc projectTextField;
273     private javax.swing.JCheckBox JavaDoc remoteCheckBox;
274     // End of variables declaration//GEN-END:variables
275

276 }
277
278
Popular Tags