1 23 package org.enhydra.kelp.forte.actions; 24 25 import org.openide.util.HelpCtx; 27 import org.openide.util.NbBundle; 28 import org.openide.util.actions.CallableSystemAction; 29 import org.openide.DialogDescriptor; 30 import org.openide.TopManager; 31 import org.openide.loaders.DataObject; 32 import org.openide.loaders.DataObjectNotFoundException; 33 import org.openide.filesystems.FileSystem; 34 import org.openide.filesystems.FileObject; 35 import org.openide.cookies.ViewCookie; 36 import org.openide.filesystems.Repository; 37 import org.openide.filesystems.JarFileSystem; 38 import org.openide.util.actions.SystemAction; 39 import org.openide.util.actions.CallableSystemAction; 40 41 import org.enhydra.tool.codegen.Generator; 43 import org.enhydra.tool.codegen.GeneratorException; 44 import org.enhydra.tool.codegen.internal.Enhydra3AppGenerator; 45 import org.enhydra.tool.codegen.internal.WebAppGenerator; 46 import org.enhydra.tool.codegen.internal.ServiceGenerator; 47 import org.enhydra.tool.codegen.wizard.CodeGenWizard; 48 import org.enhydra.tool.codegen.wizard.GenSelectionEvent; 49 import org.enhydra.tool.codegen.wizard.GenSelectionListener; 50 import org.enhydra.tool.common.wizard.TBWizardButtonPanel; 51 import org.enhydra.tool.common.event.HelpListener; 52 import org.enhydra.tool.common.event.HelpEvent; 53 import org.enhydra.tool.ToolBoxInfo; 54 55 import org.enhydra.kelp.KelpInfo; 57 import org.enhydra.kelp.common.codegen.CodeGenException; 58 import org.enhydra.kelp.common.codegen.ProjectGenUtil; 59 import org.enhydra.kelp.common.codegen.Enhydra3AppUtil; 60 import org.enhydra.kelp.common.codegen.ServiceUtil; 61 import org.enhydra.kelp.common.codegen.WebAppUtil; 62 63 import org.enhydra.kelp.forte.node.ForteProject; 65 import org.enhydra.kelp.forte.node.XMLCDataObject; 66 import org.enhydra.kelp.forte.XMLCSettings; 67 68 import java.awt.Dialog ; 70 import java.awt.event.ActionListener ; 71 import java.awt.event.ActionEvent ; 72 import java.net.URL ; 73 import java.net.MalformedURLException ; 74 import java.io.File ; 75 import java.util.ArrayList ; 76 import java.io.IOException ; 77 import java.beans.PropertyVetoException ; 78 import javax.swing.JOptionPane ; 79 import java.util.ResourceBundle ; 80 81 import java.io.FileOutputStream ; 82 import java.io.FileNotFoundException ; 83 84 89 public class AppWizardAction extends CallableSystemAction 90 implements HelpListener, GenSelectionListener { 91 92 private static String anchor = "Idunno"; 93 private ProjectGenUtil util = null; 94 95 public static final int NOAPP = -1; 96 public static final int WEBAPP = 0; 97 public static final int SERVICE = 1; 98 public static final int ENHYDRA = 2; 99 100 protected static int apptype = NOAPP; 101 102 public static int getAppType() 103 { 104 return apptype; 105 } 106 107 public void performAction() { 108 String [] options = TBWizardButtonPanel.getOptions(); 109 110 try { 111 CodeGenWizard wizard = new CodeGenWizard(); 112 wizard.getInnerPanel().initPreferredSize(); 113 DialogDescriptor dscr = 114 new DialogDescriptor(wizard.getInnerPanel(), 115 wizard.getTitle(), true, options, 116 options[1], 117 DialogDescriptor.BOTTOM_ALIGN, 118 HelpCtx.DEFAULT_HELP, 119 wizard.createButtonListener()); 120 Dialog dlg = TopManager.getDefault().createDialog(dscr); 121 122 wizard.addSelectionListener(this); 123 wizard.addHelpListener(this); 124 wizard.getInnerPanel().preShow(); 125 wizard.setAllowRootEdit(false); 126 dlg.show(); 127 if (util == null) { 128 } else if (wizard.getOption() != JOptionPane.CANCEL_OPTION) 130 131 { 132 ForteProject project = new ForteProject(); 133 FileObject readme = null; 135 FileObject rootFile = project.getRootFolder(); 136 String src = XMLCSettings.getDefault().getRoot(); 137 rootFile.refresh(); 139 try { 140 rootFile.getFileObject(src); 141 } catch (IllegalArgumentException e) { 142 System.err.println(e); 143 return; 144 } 145 if (rootFile.getChildren().length <= 0) 146 return; 147 148 XMLCSettings.getDefault().setSource(org.enhydra.kelp.common.Constants.DIR_SRC); 149 150 util.importFiles(wizard.getGeneratedFiles()); 151 Repository rep = TopManager.getDefault().getRepository(); 153 String classpath = project.getClassPath(); 154 if (apptype == WEBAPP || apptype == ENHYDRA) 155 { 156 157 String target = null; 158 StringBuffer buf = new StringBuffer (); 159 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 160 append(File.separatorChar); 161 String base = buf.toString(); 162 buf.delete(0, buf.length()); 163 buf.append(base).append("enhydra.jar"); 164 target = buf.toString(); 165 buf.delete(0, buf.length()); 166 { 168 JarFileSystem jar = new JarFileSystem(); 169 jar.setJarFile(new File (target)); 170 rep.addFileSystem(jar); 171 } 172 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 173 append(File.separatorChar).append("build").append(File.separatorChar); 174 base = buf.toString(); 175 buf.delete(0, buf.length()); 176 buf.append(base).append("toolbox.jar"); 177 target = buf.toString(); 178 buf.delete(0, buf.length()); 179 { 181 JarFileSystem jar = new JarFileSystem(); 182 jar.setJarFile(new File (target)); 183 rep.addFileSystem(jar); 184 } 185 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 186 append(File.separatorChar); 187 base = buf.toString(); 188 buf.delete(0, buf.length()); 189 buf.append(base).append("xmlc.jar"); 190 target = buf.toString(); 191 buf.delete(0, buf.length()); 192 { 194 JarFileSystem jar = new JarFileSystem(); 195 jar.setJarFile(new File (target)); 196 rep.addFileSystem(jar); 197 } 198 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 200 append(File.separatorChar); 201 base = buf.toString(); 202 buf.delete(0, buf.length()); 203 buf.append(base).append("servlet.jar"); 204 target = buf.toString(); 205 buf.delete(0, buf.length()); 206 { 208 JarFileSystem jar = new JarFileSystem(); 209 jar.setJarFile(new File (target)); 210 rep.addFileSystem(jar); 211 } 212 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 214 append(File.separatorChar); 215 base = buf.toString(); 216 buf.delete(0, buf.length()); 217 buf.append(base).append("xercesImpl.jar"); 220 target = buf.toString(); 221 buf.delete(0, buf.length()); 222 { 224 JarFileSystem jar = new JarFileSystem(); 225 jar.setJarFile(new File (target)); 226 rep.addFileSystem(jar); 227 } 228 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 229 append(File.separatorChar); 230 base = buf.toString(); 231 buf.delete(0, buf.length()); 232 buf.append(base).append("xml-apis.jar"); 234 target = buf.toString(); 235 buf.delete(0, buf.length()); 236 { 237 JarFileSystem jar = new JarFileSystem(); 238 jar.setJarFile(new File (target)); 239 rep.addFileSystem(jar); 240 } 241 242 buf.append(base).append("dom3-xml-apis.jar"); 243 target = buf.toString(); 244 buf.delete(0, buf.length()); 245 { 246 JarFileSystem jar = new JarFileSystem(); 247 jar.setJarFile(new File (target)); 248 rep.addFileSystem(jar); 249 } 250 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 252 append(File.separatorChar); 253 base = buf.toString(); 254 buf.delete(0, buf.length()); 255 buf.append(base).append("tomcat.jar"); 256 target = buf.toString(); 257 buf.delete(0, buf.length()); 258 { 260 JarFileSystem jar = new JarFileSystem(); 261 jar.setJarFile(new File (target)); 262 rep.addFileSystem(jar); 263 } 264 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 265 append(File.separatorChar); 266 base = buf.toString(); 267 buf.delete(0, buf.length()); 268 buf.append(base).append("core.jar"); 269 target = buf.toString(); 270 buf.delete(0, buf.length()); 271 { 273 JarFileSystem jar = new JarFileSystem(); 274 jar.setJarFile(new File (target)); 275 rep.addFileSystem(jar); 276 } 277 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 278 append(File.separatorChar); 279 base = buf.toString(); 280 buf.delete(0, buf.length()); 281 buf.append(base).append("util.jar"); 282 target = buf.toString(); 283 buf.delete(0, buf.length()); 284 { 286 JarFileSystem jar = new JarFileSystem(); 287 jar.setJarFile(new File (target)); 288 rep.addFileSystem(jar); 289 } 290 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 291 append(File.separatorChar); 292 base = buf.toString(); 293 buf.delete(0, buf.length()); 294 buf.append(base).append("gnu-regexp.jar"); 295 target = buf.toString(); 296 buf.delete(0, buf.length()); 297 { 299 JarFileSystem jar = new JarFileSystem(); 300 jar.setJarFile(new File (target)); 301 rep.addFileSystem(jar); 302 } 303 331 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 332 append(File.separatorChar); 333 base = buf.toString(); 334 buf.delete(0, buf.length()); 335 buf.append(base).append("xhtml.jar"); 336 target = buf.toString(); 337 buf.delete(0, buf.length()); 338 { 339 JarFileSystem jar = new JarFileSystem(); 340 jar.setJarFile(new File (target)); 341 rep.addFileSystem(jar); 342 } 343 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 344 append(File.separatorChar).append("dom").append(File.separatorChar); 345 base = buf.toString(); 346 buf.delete(0, buf.length()); 347 buf.append(base).append("xmlc-chtml.jar"); 348 target = buf.toString(); 349 buf.delete(0, buf.length()); 350 { 351 JarFileSystem jar = new JarFileSystem(); 352 jar.setJarFile(new File (target)); 353 rep.addFileSystem(jar); 354 } 355 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 356 append(File.separatorChar).append("dom").append(File.separatorChar); 357 base = buf.toString(); 358 buf.delete(0, buf.length()); 359 buf.append(base).append("xmlc-voicexml.jar"); 360 target = buf.toString(); 361 buf.delete(0, buf.length()); 362 { 363 JarFileSystem jar = new JarFileSystem(); 364 jar.setJarFile(new File (target)); 365 rep.addFileSystem(jar); 366 } 367 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("lib"). 368 append(File.separatorChar).append("dom").append(File.separatorChar); 369 base = buf.toString(); 370 buf.delete(0, buf.length()); 371 buf.append(base).append("xmlc-wml.jar"); 372 target = buf.toString(); 373 buf.delete(0, buf.length()); 374 { 375 JarFileSystem jar = new JarFileSystem(); 376 jar.setJarFile(new File (target)); 377 rep.addFileSystem(jar); 378 } 379 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("dods"). 382 append(File.separatorChar).append("lib").append(File.separatorChar); 383 base = buf.toString(); 384 buf.delete(0, buf.length()); 385 buf.append(base).append("dods.jar"); 386 target = buf.toString(); 387 buf.delete(0, buf.length()); 388 { 389 JarFileSystem jar = new JarFileSystem(); 390 jar.setJarFile(new File (target)); 391 rep.addFileSystem(jar); 392 } 393 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("dods"). 394 append(File.separatorChar).append("lib").append(File.separatorChar); 395 base = buf.toString(); 396 buf.delete(0, buf.length()); 397 buf.append(base).append("dbmanager.jar"); 398 target = buf.toString(); 399 buf.delete(0, buf.length()); 400 401 { 402 JarFileSystem jar = new JarFileSystem(); 403 jar.setJarFile(new File (target)); 404 rep.addFileSystem(jar); 405 } 406 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("dods"). 407 append(File.separatorChar).append("lib").append(File.separatorChar); 408 base = buf.toString(); 409 buf.delete(0, buf.length()); 410 buf.append(base).append("dbmanager-api.jar"); 411 target = buf.toString(); 412 buf.delete(0, buf.length()); 413 414 { 415 JarFileSystem jar = new JarFileSystem(); 416 jar.setJarFile(new File (target)); 417 rep.addFileSystem(jar); 418 } 419 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("dods"). 420 append(File.separatorChar).append("lib").append(File.separatorChar); 421 base = buf.toString(); 422 buf.delete(0, buf.length()); 423 buf.append(base).append("dsconnection.jar"); 424 target = buf.toString(); 425 buf.delete(0, buf.length()); 426 427 { 428 JarFileSystem jar = new JarFileSystem(); 429 jar.setJarFile(new File (target)); 430 rep.addFileSystem(jar); 431 } 432 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("dods"). 433 append(File.separatorChar).append("lib").append(File.separatorChar); 434 base = buf.toString(); 435 buf.delete(0, buf.length()); 436 buf.append(base).append("stdcaches.jar"); 437 target = buf.toString(); 438 buf.delete(0, buf.length()); 439 440 { 441 JarFileSystem jar = new JarFileSystem(); 442 jar.setJarFile(new File (target)); 443 rep.addFileSystem(jar); 444 } 445 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("dods"). 446 append(File.separatorChar).append("lib").append(File.separatorChar); 447 base = buf.toString(); 448 buf.delete(0, buf.length()); 449 buf.append(base).append("stdconnection.jar"); 450 target = buf.toString(); 451 buf.delete(0, buf.length()); 452 453 { 454 JarFileSystem jar = new JarFileSystem(); 455 jar.setJarFile(new File (target)); 456 rep.addFileSystem(jar); 457 } 458 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar).append("dods"). 459 append(File.separatorChar).append("lib").append(File.separatorChar); 460 base = buf.toString(); 461 buf.delete(0, buf.length()); 462 buf.append(base).append("stdtransaction.jar"); 463 target = buf.toString(); 464 buf.delete(0, buf.length()); 465 466 { 467 JarFileSystem jar = new JarFileSystem(); 468 jar.setJarFile(new File (target)); 469 rep.addFileSystem(jar); 470 } 471 buf.append(ToolBoxInfo.getEnhydraRoot()).append(File.separatorChar). 472 append("lib").append(File.separatorChar); 473 base = buf.toString(); 474 buf.delete(0, buf.length()); 475 buf.append(base).append("log4j.jar"); 476 target = buf.toString(); 477 buf.delete(0, buf.length()); 478 { 479 JarFileSystem jar = new JarFileSystem(); 480 jar.setJarFile(new File (target)); 481 rep.addFileSystem(jar); 482 } 483 484 487 char sep = File.separatorChar; 489 File fant = new File (System.getProperty("netbeans.user")+sep+"system"+ 490 sep+"Modules"+sep+"org-apache-tools-ant-module.xml"); 491 try{ 492 FileOutputStream fosant = new FileOutputStream (fant); 493 fosant.write(("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ 494 "<!DOCTYPE module PUBLIC \"-//NetBeans//DTD Module Status 1.0//EN\""+ 495 " \"http://www.netbeans.org/dtds/module-status-1_0.dtd\">"+ 496 "<module name=\"org.apache.tools.ant.module\">"+ 497 " <param name=\"autoload\">false</param>"+ 498 " <param name=\"enabled\">false</param>"+ 499 " <param name=\"jar\">ant.jar</param>"+ 500 " <param name=\"origin\">installation</param>"+ 501 " <param name=\"release\">2</param>"+ 502 " <param name=\"reloadable\">false</param>"+ 503 " <param name=\"specversion\">2.7.2</param>"+ 504 "</module>").getBytes()); 505 } catch (FileNotFoundException ex) { 506 } catch (IOException ex) { 507 } 508 509 } 510 511 readme = rootFile.getFileObject("readme", "html"); 513 XMLCDataObject target = null; 514 try { 516 target = (XMLCDataObject)DataObject.find(readme); 517 } catch (DataObjectNotFoundException e) { 518 System.err.println(e); 519 } 520 if (target != null) 521 { 522 ViewCookie viewit = (ViewCookie)target.getCookie(ViewCookie.class); 523 if (viewit != null) 524 viewit.view(); 525 } 526 } 527 528 } catch (GeneratorException e) { 529 e.printStackTrace(System.err); 530 } catch (CodeGenException e) { 531 e.printStackTrace(System.err); 532 } catch (IOException e) { 533 System.err.println(e); 534 } catch (PropertyVetoException e) { 535 System.err.println(e); 536 } 537 ((XMLCAction)SystemAction.get(XMLCAction.class)).setEnabled(true); 539 ((DeploymentAction)SystemAction.get(DeploymentAction.class)).setEnabled(true); 540 541 } 542 543 public String getName() { 544 return CodeGenWizard.getDefaultTitle(); 545 } 546 547 public boolean isEnabled() 548 { 549 return (new ForteProject().getRootFolder() != null); 550 } 551 552 protected String iconResource() { 553 return "smallicon.gif"; 554 } 555 556 public HelpCtx getHelpCtx() { 557 return HelpCtx.DEFAULT_HELP; 558 559 } 562 563 567 protected void initialize() { 568 super.initialize(); 569 putProperty(javax.swing.Action.SHORT_DESCRIPTION, 570 NbBundle.getMessage(AppWizardAction.class, 571 "HINT_AppWiz_Action")); 572 } 573 574 public void onSelection(GenSelectionEvent event) { 576 ForteProject project = new ForteProject(); 577 Generator gen = event.getGenerator(); 578 CodeGenWizard wizard = event.getWizard(); 579 try { 580 if (gen instanceof WebAppGenerator) { 581 util = new WebAppUtil(project, (WebAppGenerator) gen); 582 apptype = WEBAPP; 583 } else if (gen instanceof ServiceGenerator) { 584 util = new ServiceUtil(project, (ServiceGenerator) gen); 585 apptype = SERVICE; 586 } else if (gen instanceof Enhydra3AppGenerator) { 587 util = new Enhydra3AppUtil(project, 588 (Enhydra3AppGenerator) gen); 589 apptype = ENHYDRA; 590 } 591 if (getAddinSteps().length > 0) 592 util.getGenerator().setAddinSteps(getAddinSteps()); 593 String javaPath = System.getProperty("java.home"); 594 if (javaPath.endsWith(File.separatorChar + "jre")) 596 javaPath = javaPath.substring(0, javaPath.length() - 4); 597 else 598 { 599 StringBuffer buf = new StringBuffer (javaPath); 600 while (buf.charAt(buf.length() - 1) != File.separatorChar) 601 { 602 buf.deleteCharAt(buf.length() - 1); 603 } 604 buf.deleteCharAt(buf.length() - 1); 605 javaPath = buf.toString(); 606 } 607 util.getGenerator().setJavaPath(javaPath); 608 609 wizard.setCodeGen(util.getCodeGen()); 610 } catch (CodeGenException e) { 611 e.printStackTrace(System.err); 612 } 613 } 614 615 public void onHelp(HelpEvent event) { 617 URL url = null; 618 String [] home = new String [2]; 619 home[0] = System.getProperty("netbeans.home"); 620 home[1] = System.getProperty("netbeans.user"); 621 StringBuffer buf = new StringBuffer (); 622 buf.append(KelpInfo.getAddinHelpURL(home)); 623 buf.append('#').append(anchor); 624 try { 625 url = new URL (buf.toString()); 626 TopManager.getDefault().showUrl(url); 627 } catch (MalformedURLException e) { 628 e.printStackTrace(System.err); 629 } 630 } 631 632 private String [] getAddinSteps() { 634 ResourceBundle bundle = NbBundle.getBundle(AppWizardAction.class); 635 ArrayList list = new ArrayList (); 636 String [] steps = new String [0]; 637 638 if (apptype == WEBAPP) 639 { 640 list.add(bundle.getString("readmeWeb1")); 641 list.add(bundle.getString("readmeWeb2")); 642 list.add(bundle.getString("readmeWeb3")); 643 list.add(bundle.getString("readmeWeb4")); 644 } 645 else if (apptype == SERVICE) 646 { 647 return steps; 648 } 649 650 else 651 { 652 list.add(bundle.getString("readmeEnApp1")); 653 list.add(bundle.getString("readmeEnApp2")); 654 list.add(bundle.getString("readmeEnApp3")); 655 list.add(bundle.getString("readmeEnApp4")); 656 } 657 658 list.trimToSize(); 659 660 steps = new String [list.size()]; 661 steps = (String []) list.toArray(steps); 662 list.clear(); 663 return steps; 664 } 665 666 667 } 668 | Popular Tags |