1 2 24 package org.enhydra.tool.codegen.wizard; 25 26 import org.enhydra.tool.ToolBoxInfo; 28 import org.enhydra.tool.codegen.internal.AppOptionSet; 29 import org.enhydra.tool.codegen.GeneratorOption; 30 import org.enhydra.tool.codegen.GeneratorException; 31 import org.enhydra.tool.codegen.ValidationException; 32 import org.enhydra.tool.codegen.ValidationUtil; 33 import org.enhydra.tool.common.ToolException; 34 import org.enhydra.tool.common.PathHandle; 35 import org.enhydra.tool.common.SwingUtil; 36 37 import javax.swing.*; 39 import javax.swing.border.*; 40 import java.awt.*; 41 import java.awt.event.ActionEvent ; 42 import java.awt.event.ActionListener ; 43 import java.beans.*; 44 import java.io.File ; 45 import java.util.Properties ; 46 import java.util.ResourceBundle ; 47 48 52 public class AppOptionPanel1 extends CodeGenPanel implements RootEditor { 53 54 private final String DEF_PACKAGE = "untitled"; private final String DEF_PROJECT = "Untitled1"; 58 61 64 transient public JLabel labelProjectName; 65 66 69 transient public JTextField textProjectName; 70 71 74 transient public JLabel labelPackage; 75 76 79 transient public JTextField textPackage; 80 81 84 transient public JPanel panelDest; 85 86 89 transient public JButton buttonSet; 90 91 94 transient public JTextField textDest; 95 96 transient private JPanel panelFiller; 98 transient private GridBagLayout layoutMain; 99 transient private GridBagLayout layoutDest; 100 transient private LocalButtonListener buttonListener; 101 transient private TitledBorder borderDest; 102 transient private JLabel labelClient; 103 transient private JComboBox comboClient; 104 transient private JPanel panelEnhydraRoot; 105 transient private JTextField textEnhydraRoot; 106 transient private GridBagLayout layoutEnhydraRoot; 107 transient private Border borderEnhydraRoot; 108 transient private JButton buttonEnhydraRoot; 109 110 115 public AppOptionPanel1() { 116 try { 117 jbInit(); 118 pmInit(); 119 } catch (Exception ex) { 120 ex.printStackTrace(); 121 } 122 } 123 124 public boolean isAllowRootEdit() { 126 return textProjectName.isEnabled(); 127 } 128 129 public void setAllowRootEdit(boolean allow) { 131 textProjectName.setEnabled(allow); 132 textDest.setEnabled(allow); 133 } 134 135 142 public void readOptionSet() throws GeneratorException { 143 GeneratorOption option = null; 144 PathHandle handle = null; 145 146 option = getOptionSet().lookup(AppOptionSet.CLIENT); 148 comboClient.setSelectedItem(option.getValue()); 149 150 option = getOptionSet().lookup(AppOptionSet.PROJECT); 152 textProjectName.setText(option.getValue()); 153 154 option = getOptionSet().lookup(AppOptionSet.PACKAGE); 156 textPackage.setText(option.getValue()); 157 158 option = getOptionSet().lookup(AppOptionSet.ROOT); 160 handle = PathHandle.createPathHandle(option.getValue()); 161 textDest.setText(handle.getPath()); 162 } 163 164 171 public void writeOptionSet() throws GeneratorException { 172 String value = new String (); 173 174 value = comboClient.getSelectedItem().toString().trim(); 176 getOptionSet().lookup(AppOptionSet.CLIENT).setValue(value); 177 178 value = textProjectName.getText().trim(); 180 getOptionSet().lookup(AppOptionSet.PROJECT).setValue(value); 181 182 value = textPackage.getText().trim(); 184 getOptionSet().lookup(AppOptionSet.PACKAGE).setValue(value); 185 186 value = textDest.getText().trim(); 188 getOptionSet().lookup(AppOptionSet.ROOT).setValue(value); 189 } 190 191 199 public void validateOptionSet() throws ValidationException { 200 String value = new String (); 201 202 value = textProjectName.getText().trim(); 204 if (!ValidationUtil.isJavaIdentifier(value)) { 205 throw new ValidationException(res.getString("Project_directory")); 206 } 207 208 value = textPackage.getText().trim(); 210 if (!ValidationUtil.isJavaPackage(value)) { 211 throw new ValidationException(res.getString("Package_is_not_valid")); 212 } 213 214 value = textDest.getText().trim(); 216 if (!ValidationUtil.isParentDirectory(value)) { 217 throw new ValidationException("Invalid Project Root"); 218 } 219 if (ToolBoxInfo.isRootSettable()) { 220 if (!ToolBoxInfo.isEnhydraRoot(ToolBoxInfo.getEnhydraRoot())) { 221 throw new ValidationException("Invalid Application Server Root"); 222 } 223 } 224 } 225 226 232 public String getPageTitle() { 233 return res.getString("Client_type_and"); 234 } 235 236 243 public String getInstructions() { 244 StringBuffer buf = new StringBuffer (); 245 246 buf.append(res.getString("Instruct1")); 247 buf.append(res.getString("Instruct2")); 248 buf.append(res.getString("Instruct3")); 249 buf.append(res.getString("Instruct4")); 250 return buf.toString(); 251 } 252 253 private void chooseEnhydraRoot() { 257 File choice = null; 258 PathHandle path = null; 259 Properties props = null; 260 String message = null; 261 262 choice = SwingUtil.getDirectoryChoice(this, 263 ToolBoxInfo.getEnhydraRoot(), 264 "Select Application Server Root"); 265 path = PathHandle.createPathHandle(choice); 266 if (path.isDirectory() && ToolBoxInfo.isEnhydraRoot(path.getPath())) { 267 try { 268 props = ToolBoxInfo.loadProperties(); 269 props.setProperty(ToolBoxInfo.ENHYDRA_ROOT, path.getPath()); 270 ToolBoxInfo.storeProperties(props); 271 textEnhydraRoot.setText(ToolBoxInfo.getEnhydraRoot()); 272 textEnhydraRoot.setToolTipText(textEnhydraRoot.getText()); 273 } catch (ToolException e) { 274 message = e.getMessage(); 275 } 276 } else { 277 message = "Invalid Application Server Root"; 278 } 279 if (message != null) { 280 JOptionPane.showMessageDialog(this, message, "Kelp Error", 281 JOptionPane.ERROR_MESSAGE); 282 } 283 } 284 285 293 private void jbInit() throws Exception { 294 textProjectName = 295 (JTextField) Beans.instantiate(getClass().getClassLoader(), 296 JTextField.class.getName()); 297 labelPackage = (JLabel) Beans.instantiate(getClass().getClassLoader(), 298 JLabel.class.getName()); 299 textPackage = 300 (JTextField) Beans.instantiate(getClass().getClassLoader(), 301 JTextField.class.getName()); 302 panelDest = (JPanel) Beans.instantiate(getClass().getClassLoader(), 303 JPanel.class.getName()); 304 layoutDest = 305 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 306 GridBagLayout.class.getName()); 307 buttonSet = (JButton) Beans.instantiate(getClass().getClassLoader(), 308 JButton.class.getName()); 309 textDest = (JTextField) Beans.instantiate(getClass().getClassLoader(), 310 JTextField.class.getName()); 311 layoutMain = 312 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 313 GridBagLayout.class.getName()); 314 labelProjectName = 315 (JLabel) Beans.instantiate(getClass().getClassLoader(), 316 JLabel.class.getName()); 317 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 318 JPanel.class.getName()); 319 labelClient = (JLabel) Beans.instantiate(getClass().getClassLoader(), 320 JLabel.class.getName()); 321 comboClient = 322 (JComboBox) Beans.instantiate(getClass().getClassLoader(), 323 JComboBox.class.getName()); 324 panelEnhydraRoot = 325 (JPanel) Beans.instantiate(getClass().getClassLoader(), 326 JPanel.class.getName()); 327 textEnhydraRoot = 328 (JTextField) Beans.instantiate(getClass().getClassLoader(), 329 JTextField.class.getName()); 330 buttonEnhydraRoot = 331 (JButton) Beans.instantiate(getClass().getClassLoader(), 332 JButton.class.getName()); 333 layoutEnhydraRoot = 334 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 335 GridBagLayout.class.getName()); 336 borderEnhydraRoot = 337 BorderFactory.createTitledBorder("Application Server Root"); 338 labelProjectName.setMaximumSize(new Dimension(120, 17)); 339 labelProjectName.setMinimumSize(new Dimension(120, 17)); 340 labelProjectName.setPreferredSize(new Dimension(120, 17)); 341 labelProjectName.setText(res.getString("Project_directory1")); 342 labelPackage.setText(res.getString("Package_")); 343 buttonSet.setText(res.getString("Set_")); 344 panelDest.setBorder(BorderFactory.createTitledBorder("Project Root")); 345 panelDest.setLayout(layoutDest); 346 labelClient.setText(res.getString("Client_type_")); 347 panelDest.add(textDest, 348 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, 349 GridBagConstraints.WEST, 350 GridBagConstraints.HORIZONTAL, 351 new Insets(4, 5, 3, 5), 0, 0)); 352 panelDest.add(buttonSet, 353 new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, 354 GridBagConstraints.CENTER, 355 GridBagConstraints.NONE, 356 new Insets(4, 5, 3, 10), 0, 0)); 357 textEnhydraRoot.setEnabled(false); 358 buttonEnhydraRoot.setText(res.getString("Set_")); 359 panelEnhydraRoot.setLayout(layoutEnhydraRoot); 360 panelEnhydraRoot.setBorder(borderEnhydraRoot); 361 panelEnhydraRoot.add(textEnhydraRoot, 362 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0, 363 GridBagConstraints.WEST, 364 GridBagConstraints.HORIZONTAL, 365 new Insets(4, 5, 3, 5), 366 0, 0)); 367 panelEnhydraRoot.add(buttonEnhydraRoot, 368 new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 369 GridBagConstraints.CENTER, 370 GridBagConstraints.NONE, 371 new Insets(4, 5, 3, 10), 372 0, 0)); 373 this.setLayout(layoutMain); 374 this.add(labelProjectName, new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0 375 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 3, 5), 50, 0)); 376 this.add(labelPackage, new GridBagConstraints(0, 1, 1, 1, 0.1, 0.0 377 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 3, 5), 50, 0)); 378 this.add(textProjectName, new GridBagConstraints(1, 0, 1, 1, 0.1, 0.0 379 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 3, 5), 150, 0)); 380 this.add(panelDest, 381 new GridBagConstraints(0, 3, 2, 1, 0.1, 0.0, 382 GridBagConstraints.CENTER, 383 GridBagConstraints.BOTH, 384 new Insets(3, 5, 3, 5), 0, 0)); 385 this.add(textPackage, new GridBagConstraints(1, 1, 1, 1, 0.1, 0.0 386 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 3, 5), 150, 0)); 387 this.add(panelFiller, 388 new GridBagConstraints(0, 5, 2, 1, 0.4, 0.4, 389 GridBagConstraints.CENTER, 390 GridBagConstraints.BOTH, 391 new Insets(0, 0, 0, 0), 0, 0)); 392 this.add(labelClient, new GridBagConstraints(0, 2, 1, 1, 0.1, 0.0 393 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 3, 5), 50, 0)); 394 this.add(comboClient, new GridBagConstraints(1, 2, 1, 1, 0.1, 0.0 395 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 3, 5), 50, 0)); 396 this.add(panelEnhydraRoot, 397 new GridBagConstraints(0, 4, 4, 1, 0.1, 0.0, 398 GridBagConstraints.CENTER, 399 GridBagConstraints.BOTH, 400 new Insets(3, 5, 5, 5), 0, 0)); 401 } 402 403 409 private void pmInit() { 410 String [] docTypes = new String [0]; 411 412 buttonListener = new LocalButtonListener(); 413 buttonSet.addActionListener(buttonListener); 414 textDest.setText(new String ()); 415 textPackage.setText(DEF_PACKAGE); 416 textProjectName.setText(DEF_PROJECT); 417 comboClient.removeAllItems(); 418 docTypes = ToolBoxInfo.getSupportedDocTypes(); 419 for (int i = 0; i < docTypes.length; i++) { 420 comboClient.addItem(docTypes[i].toUpperCase()); 421 } 422 textEnhydraRoot.setText(ToolBoxInfo.getEnhydraRoot()); 423 textEnhydraRoot.setToolTipText(textEnhydraRoot.getText()); 424 textEnhydraRoot.setEnabled(false); 425 if (ToolBoxInfo.isRootSettable()) { 426 buttonListener = new LocalButtonListener(); 427 buttonEnhydraRoot.addActionListener(buttonListener); 428 buttonEnhydraRoot.setEnabled(true); 429 } else { 430 buttonEnhydraRoot.setVisible(false); 431 panelEnhydraRoot.remove(buttonEnhydraRoot); 432 } 433 } 434 435 private void browseForFile() { 436 File destDir = null; 437 438 destDir = 439 SwingUtil.getDirectoryChoice(this, textDest.getText(), 440 res.getString("Choose_the_root_path")); 441 if (destDir != null) { 442 textDest.setText(PathHandle.createPathString(destDir)); 443 } 444 } 445 446 private class LocalButtonListener implements ActionListener { 447 public void actionPerformed(ActionEvent event) { 448 Object source = event.getSource(); 449 450 if (source == buttonSet) { 451 browseForFile(); 452 } else if (source == buttonEnhydraRoot) { 453 chooseEnhydraRoot(); 454 } 455 } 456 457 } 458 } 459 | Popular Tags |