1 package org.netbeans.modules.j2ee.persistence.wizard.dao; 2 3 import java.io.IOException ; 4 import javax.swing.ComboBoxModel ; 5 import javax.swing.JPanel ; 6 import javax.swing.event.ChangeListener ; 7 import javax.swing.event.DocumentEvent ; 8 import javax.swing.event.DocumentListener ; 9 import javax.swing.text.Document ; 10 import javax.swing.text.JTextComponent ; 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 implements DocumentListener { 25 26 private static final String CLASSNAME_LOCAL = NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_GeneratedFacadeLocal"); 27 private static final String CLASSNAME_REMOTE = NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_GeneratedFacadeRemote"); 28 29 private WizardDescriptor wizard; 30 private Project project; 31 private JTextComponent packageComboBoxEditor; 32 private ChangeSupport changeSupport = new ChangeSupport(this); 33 34 public EjbFacadeVisualPanel2(WizardDescriptor wizard) { 35 this.wizard = wizard; 36 initComponents(); 37 packageComboBoxEditor = ((JTextComponent )packageComboBox.getEditor().getEditorComponent()); 38 Document packageComboBoxDocument = packageComboBoxEditor.getDocument(); 39 packageComboBoxDocument.addDocumentListener(this); 41 handleCheckboxes(); 42 } 43 44 @Override 45 public String getName() { 46 return NbBundle.getMessage(EjbFacadeVisualPanel2.class, "LBL_GeneratedSessionBeans"); 47 } 48 49 public void addChangeListener(ChangeListener listener) { 50 changeSupport.addChangeListener(listener); 51 } 52 53 boolean valid(WizardDescriptor wizard) { 54 return true; 56 } 57 58 public SourceGroup getLocationValue() { 59 return (SourceGroup)locationComboBox.getSelectedItem(); 60 } 61 62 public String 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 SourceGroup targetSourceGroup = SourceGroupSupport.getFolderSourceGroup(sourceGroups, targetFolder); 86 if (targetSourceGroup != null) { 87 locationComboBox.setSelectedItem(targetSourceGroup); 88 String 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 ex) { 100 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 101 } 102 } 103 104 private void updateSourceGroupPackages() { 105 SourceGroup sourceGroup = (SourceGroup)locationComboBox.getSelectedItem(); 106 ComboBoxModel model = PackageView.createListView(sourceGroup); 107 if (model.getSelectedItem()!= null && model.getSelectedItem().toString().startsWith("META-INF") 108 && model.getSize() > 1) { model.setSelectedItem(model.getElementAt(1)); 110 } 111 packageComboBox.setModel(model); 112 } 113 114 public void insertUpdate(DocumentEvent e) { 115 } 116 117 public void removeUpdate(DocumentEvent e) { 118 } 119 120 public void changedUpdate(DocumentEvent 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 145 private void initComponents() { 147 jLabel1 = new javax.swing.JLabel (); 148 jLabel2 = new javax.swing.JLabel (); 149 jLabel3 = new javax.swing.JLabel (); 150 jLabel4 = new javax.swing.JLabel (); 151 locationComboBox = new javax.swing.JComboBox (); 152 packageComboBox = new javax.swing.JComboBox (); 153 projectTextField = new javax.swing.JTextField (); 154 jLabel6 = new javax.swing.JLabel (); 155 remoteCheckBox = new javax.swing.JCheckBox (); 156 localCheckBox = new javax.swing.JCheckBox (); 157 createdFilesText = new javax.swing.JTextField (); 158 jLabel5 = new javax.swing.JLabel (); 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 (0, 0, 0, 0)); 177 remoteCheckBox.addActionListener(new java.awt.event.ActionListener () { 178 public void actionPerformed(java.awt.event.ActionEvent 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 (0, 0, 0, 0)); 187 localCheckBox.addActionListener(new java.awt.event.ActionListener () { 188 public void actionPerformed(java.awt.event.ActionEvent 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 [] {"", ""})); 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 } 250 private void localCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { handleCheckboxes(); 252 changeSupport.fireChange(); 253 } 255 private void remoteCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { handleCheckboxes(); 257 changeSupport.fireChange(); 258 } 260 261 private javax.swing.JTextField createdFilesText; 263 private javax.swing.JLabel jLabel1; 264 private javax.swing.JLabel jLabel2; 265 private javax.swing.JLabel jLabel3; 266 private javax.swing.JLabel jLabel4; 267 private javax.swing.JLabel jLabel5; 268 private javax.swing.JLabel jLabel6; 269 private javax.swing.JCheckBox localCheckBox; 270 private javax.swing.JComboBox locationComboBox; 271 private javax.swing.JComboBox packageComboBox; 272 private javax.swing.JTextField projectTextField; 273 private javax.swing.JCheckBox remoteCheckBox; 274 276 } 277 278 | Popular Tags |