1 19 20 package org.netbeans.modules.j2ee.ddloaders.web; 21 22 import java.awt.Component ; 23 import java.awt.Dialog ; 24 import java.awt.event.*; 25 import java.beans.*; 26 import java.io.*; 27 import java.util.*; 28 import javax.swing.JButton ; 29 import javax.swing.event.ChangeListener ; 30 31 import org.openide.DialogDescriptor; 32 import org.openide.filesystems.*; 33 import org.openide.loaders.*; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.RequestProcessor; 36 37 import org.xml.sax.*; 38 import org.openide.ErrorManager; 39 import org.openide.util.NbBundle; 40 41 import org.netbeans.modules.j2ee.ddloaders.web.event.*; 42 import org.netbeans.modules.j2ee.dd.api.web.*; 43 import org.netbeans.modules.j2ee.dd.api.common.InitParam; 44 import org.netbeans.modules.j2ee.dd.api.common.RootInterface; 45 import org.netbeans.api.xml.cookies.ValidateXMLCookie; 46 import org.netbeans.api.xml.cookies.CheckXMLCookie; 47 import org.netbeans.spi.xml.cookies.*; 48 import org.openide.DialogDisplayer; 49 import org.netbeans.modules.j2ee.dd.impl.web.WebAppProxy; 50 import org.netbeans.modules.j2ee.dd.impl.web.WebParseUtils; 51 import org.netbeans.api.java.project.JavaProjectConstants; 52 import org.netbeans.api.project.FileOwnerQuery; 53 import org.netbeans.api.project.Project; 54 import org.netbeans.api.project.ProjectUtils; 55 56 import org.netbeans.modules.web.api.webmodule.WebModule; 57 import org.netbeans.api.project.SourceGroup; 58 import org.netbeans.api.project.Sources; 59 60 import org.netbeans.modules.j2ee.ddloaders.web.multiview.*; 61 import org.netbeans.modules.j2ee.ddloaders.multiview.DDMultiViewDataObject; 62 import org.netbeans.modules.xml.multiview.DesignMultiViewDesc; 63 import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement; 64 65 69 public class DDDataObject extends DDMultiViewDataObject 70 implements DDChangeListener, ChangeListener , PropertyChangeListener { 71 private transient WebApp webApp; 72 private transient FileObject srcRoots[]; 73 protected transient final static RequestProcessor RP = new RequestProcessor("XML Parsing"); protected boolean changedFromUI; 75 76 private static final long serialVersionUID = 8857563089355069362L; 77 78 79 public static final String PROP_DOCUMENT_DTD = "documentDTD"; public static final String HELP_ID_PREFIX_OVERVIEW="dd_multiview_overview_"; public static final String HELP_ID_PREFIX_SERVLETS="dd_multiview_servlets_"; public static final String HELP_ID_PREFIX_FILTERS="dd_multiview_filters_"; public static final String HELP_ID_PREFIX_PAGES="dd_multiview_pages_"; public static final String HELP_ID_PREFIX_REFERENCES="dd_multiview_references_"; public static final String HELP_ID_PREFIX_SECURITY="dd_multiview_security_"; 87 88 89 private String documentDTD; 90 91 92 private Vector updates; 93 94 private transient RequestProcessor.Task updateTask; 95 private transient FileObjectObserver fileListener; 96 97 public DDDataObject (FileObject pf, DDDataLoader loader) throws DataObjectExistsException { 98 super (pf, loader); 99 init (pf,loader); 100 } 101 102 private void init (FileObject fo,DDDataLoader loader) { 103 InputSource in = DataObjectAdapters.inputSource(this); 105 CheckXMLCookie checkCookie = new CheckXMLSupport(in); 106 getCookieSet().add(checkCookie); 107 ValidateXMLCookie validateCookie = new ValidateXMLSupport(in); 108 getCookieSet().add(validateCookie); 109 110 fileListener = new FileObjectObserver(fo); 111 112 Project project = FileOwnerQuery.getOwner (getPrimaryFile ()); 113 if (project != null) { 114 Sources sources = ProjectUtils.getSources(project); 115 sources.addChangeListener (this); 116 } 117 refreshSourceFolders (); 118 addPropertyChangeListener(this); 119 } 120 121 private void refreshSourceFolders () { 122 ArrayList srcRootList = new ArrayList (); 123 124 Project project = FileOwnerQuery.getOwner (getPrimaryFile ()); 125 if (project != null) { 126 Sources sources = ProjectUtils.getSources(project); 127 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 128 for (int i = 0; i < groups.length; i++) { 129 if (WebModule.getWebModule (groups [i].getRootFolder ()) != null) { 130 srcRootList.add (groups [i].getRootFolder ()); 131 DataLoaderPool.getDefault().removeOperationListener(operationListener); DataLoaderPool.getDefault().addOperationListener(operationListener); 133 } 134 } 135 } 136 srcRoots = (FileObject []) srcRootList.toArray (new FileObject [srcRootList.size ()]); 137 } 138 139 private String getPackageName (FileObject clazz) { 140 for (int i = 0; i < srcRoots.length; i++) { 141 String rp = FileUtil.getRelativePath (srcRoots [i], clazz); 142 if (rp != null) { 143 if (clazz.getExt ().length () > 0) { 144 rp = rp.substring (0, rp.length () - clazz.getExt ().length () - 1); 145 } 146 return rp.replace ('/', '.'); 147 } 148 } 149 return null; 150 } 151 152 public WebApp getWebApp() { 153 if (webApp == null) { 154 try { 155 webApp = createWebApp(); 156 } catch (IOException ex) { 157 ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex); 158 } 159 } 160 return webApp; 161 } 162 163 public void propertyChange(java.beans.PropertyChangeEvent evt) { 164 if (DDDataObject.PROP_DOCUMENT_VALID.equals (evt.getPropertyName ())) { 165 ((DDDataNode)getNodeDelegate()).iconChanged(); 166 } 167 } 168 169 private WebApp createWebApp() throws java.io.IOException { 170 WebApp webApp = DDProvider.getDefault().getDDRoot(getPrimaryFile()); 171 if (webApp != null) { 172 setSaxError(webApp.getError()); 173 } 174 return webApp; 175 } 176 177 protected org.openide.nodes.Node createNodeDelegate () { 178 return new DDDataNode(this); 179 } 180 181 185 public void setReasonableMappings(ServletMapping[] mappings) { 186 List newMappings = new ArrayList(); 187 Servlet[] servlets = webApp.getServlet(); 188 for (int i=0;i<mappings.length;i++) { 189 for (int j=0;j<servlets.length;j++) { 190 if (servlets[j].getServletName().equals(mappings[i].getServletName())) { 191 newMappings.add(mappings[i]); 192 break; 193 } 194 } 195 } 196 ServletMapping[] maps = new ServletMapping[newMappings.size()]; 197 newMappings.toArray(maps); 198 webApp.setServletMapping(maps); 199 } 202 203 protected void parseDocument() throws IOException { 204 if (webApp == null || ((WebAppProxy) webApp).getOriginal() == null) { 205 try { 206 webApp = DDProvider.getDefault().getDDRoot(getPrimaryFile()); 207 } catch (IOException e) { 208 if (webApp == null) { 209 webApp = new WebAppProxy(null, null); 210 } 211 } 212 } 213 parseDocument(true); 215 } 216 217 protected void validateDocument() throws IOException { 218 parseDocument(false); 220 } 221 222 private void parseDocument(boolean updateWebApp) throws IOException { 223 WebAppProxy webAppProxy = (WebAppProxy) webApp; 224 try { 225 SAXParseException error = WebParseUtils.parse(new InputSource(createReader())); 227 setSaxError(error); 228 229 String version = WebParseUtils.getVersion(new InputSource(createReader())); 230 WebAppProxy app = new WebAppProxy(org.netbeans.modules.j2ee.dd.impl.common.DDUtils.createWebApp( 232 createInputStream(), version), version); 233 if (updateWebApp) { 234 if (version.equals(webAppProxy.getVersion()) && webAppProxy.getOriginal() != null) { 235 webApp.merge(app, WebApp.MERGE_UPDATE); 236 } else if (app.getOriginal() != null) { 237 webApp = webAppProxy = app; 238 } 239 } 240 webAppProxy.setStatus(error != null ? WebApp.STATE_INVALID_PARSABLE : WebApp.STATE_VALID); 241 webAppProxy.setError(error); 242 } catch (SAXException ex) { 243 webAppProxy.setStatus(WebApp.STATE_INVALID_UNPARSABLE); 244 if (ex instanceof SAXParseException) { 245 webAppProxy.setError((SAXParseException) ex); 246 } else if (ex.getException() instanceof SAXParseException) { 247 webAppProxy.setError((SAXParseException) ex.getException()); 248 } 249 setSaxError(ex); 250 } 251 } 252 253 protected RootInterface getDDModel() { 254 return getWebApp(); 255 } 256 257 public boolean isDocumentParseable() { 258 return WebApp.STATE_INVALID_UNPARSABLE != getWebApp().getStatus(); 259 } 260 261 protected String getPrefixMark() { 262 return "<web-app"; 263 } 264 265 274 private void createDefaultServletConfiguration (String clazz, String urlPattern) { 275 WebApp wappTo = getWebApp (); 277 try { 278 Servlet newSrvlt = (Servlet)webApp.createBean("Servlet"); 279 newSrvlt.setServletClass (clazz); 280 String name = DDUtils.findFreeName (wappTo.getServlet (), "ServletName" , "Servlet_"+clazz); newSrvlt.setServletName (name); 282 newSrvlt.setDescription (NbBundle.getMessage (DDDataObject.class, "TXT_newServletElementDescription")); 283 newSrvlt.setDisplayName ("Servlet "+clazz); wappTo.addServlet (newSrvlt); 285 286 ServletMapping newSM = (ServletMapping)webApp.createBean("ServletMapping"); 287 newSM.setServletName (name); 288 newSM.setUrlPattern (urlPattern); 289 wappTo.addServletMapping (newSM); 290 291 } catch (ClassNotFoundException ex) {} 294 } 295 296 protected DataObject handleCopy(DataFolder f) throws IOException { 297 DataObject dObj = super.handleCopy(f); 298 try { dObj.setValid(false); }catch(java.beans.PropertyVetoException e){} 299 return dObj; 300 } 301 302 protected void dispose () { 303 synchronized (this) { 305 updates = null; 306 if (updateTask != null) { 307 updateTask.cancel(); 308 } 309 } 310 super.dispose (); 311 } 312 313 316 public String getDocumentDTD () { 317 if (documentDTD == null) { 318 WebApp wa = getWebApp (); 319 } 320 return documentDTD; 321 } 322 323 326 public void deploymentChange (DDChangeEvent evt) { 327 if (evt.getType() == DDChangeEvent.SERVLET_ADDED && servletDefined(evt.getNewValue())) { 329 return; 330 } 331 332 else if (evt.getType() == DDChangeEvent.LISTENER_DELETED 334 || evt.getType() == DDChangeEvent.FILTER_DELETED 335 || evt.getType() == DDChangeEvent.SERVLET_DELETED){ 336 337 return; 338 } 339 340 synchronized (this) { 341 if (updates == null) { 342 updates = new Vector (); 343 } 344 updates.addElement (evt); 345 } 346 347 if (updateTask == null) { 349 updateTask = RequestProcessor.getDefault().post (new Runnable () { 350 public void run () { 351 java.util.List changes = null; 352 synchronized (DDDataObject.this) { 353 if (!DDDataObject.this.isValid()) { 354 return; 355 } 356 if (updates != null) { 357 changes = updates; 358 updates = null; 359 } 360 } 361 if (changes != null) { 362 showDDChangesDialog(changes); 363 } 364 } 365 }, 2000, Thread.MIN_PRIORITY); 366 } 367 else { 368 updateTask.schedule (2000); 369 } 370 } 371 372 private boolean servletDefined(String classname) { 373 WebApp webApp = getWebApp(); 374 if (webApp == null) { 375 return true; 376 } 377 Servlet[] servlets = webApp.getServlet(); 378 for ( int i = 0; i < servlets.length; i++ ) { 379 if (servlets[i].getServletClass() != null && servlets[i].getServletClass().equals(classname)) { 380 return true; 381 } 382 } 383 return false; 384 } 385 386 private void showDDChangesDialog (List changes) { 387 final JButton processButton; 388 final JButton processAllButton; 389 final JButton closeButton; 390 final DDChangesPanel connectionPanel; 391 final DialogDescriptor confirmChangesDescriptor; 392 final Dialog confirmChangesDialog[] = { null }; 393 394 processButton = new JButton (NbBundle.getMessage (DDDataObject.class, "LAB_processButton")); 395 processButton.setMnemonic (NbBundle.getMessage (DDDataObject.class, "LAB_processButton_Mnemonic").charAt (0)); 396 processButton.setToolTipText (NbBundle.getMessage (DDDataObject.class, "ACS_processButtonA11yDesc")); 397 processAllButton = new JButton (NbBundle.getMessage (DDDataObject.class, "LAB_processAllButton")); 398 processAllButton.setMnemonic (NbBundle.getMessage (DDDataObject.class, "LAB_processAllButton_Mnemonic").charAt (0)); 399 processAllButton.setToolTipText (NbBundle.getMessage (DDDataObject.class, "ACS_processAllButtonA11yDesc")); 400 closeButton = new JButton (NbBundle.getMessage (DDDataObject.class, "LAB_closeButton")); 401 closeButton.setMnemonic (NbBundle.getMessage (DDDataObject.class, "LAB_closeButton_Mnemonic").charAt (0)); 402 closeButton.setToolTipText (NbBundle.getMessage (DDDataObject.class, "ACS_closeButtonA11yDesc")); 403 final Object [] options = new Object [] { 404 processButton, 405 processAllButton 406 }; 407 final Object [] additionalOptions = new Object [] { 408 closeButton 409 }; 410 WebModule wm = WebModule.getWebModule(getPrimaryFile ()); 411 String fsname=""; if (wm!=null) { 413 fsname=wm.getContextPath(); 414 } 415 String caption = NbBundle.getMessage (DDDataObject.class, "MSG_SynchronizeCaption", fsname); 416 connectionPanel = new DDChangesPanel (caption, processButton); 417 confirmChangesDescriptor = new DialogDescriptor ( 418 connectionPanel, 419 NbBundle.getMessage (DDDataObject.class, "LAB_ConfirmDialog"), 420 true, 421 options, 422 processButton, 423 DialogDescriptor.RIGHT_ALIGN, 424 HelpCtx.DEFAULT_HELP, 425 new ActionListener () { 426 public void actionPerformed (ActionEvent e) { 427 if (e.getSource () instanceof Component ) { 428 Component root; 429 430 root = javax.swing.SwingUtilities.getRoot ((Component )e.getSource ()); 432 if (!root.isDisplayable ()) { 433 return; 434 } 435 } 436 if (options[0].equals (e.getSource ())) { 437 int min = connectionPanel.changesList.getMinSelectionIndex (); 438 int max = connectionPanel.changesList.getMaxSelectionIndex (); 439 for (int i = max; i >= min; i--) { 440 if (connectionPanel.changesList.isSelectedIndex (i)) { 441 final DDChangeEvent ev = (DDChangeEvent)connectionPanel.listModel.getElementAt (i); 442 processDDChangeEvent (ev); 443 connectionPanel.listModel.removeElementAt (i); 444 } 445 } 446 if (connectionPanel.listModel.isEmpty ()) { 447 confirmChangesDialog[0].setVisible (false); 448 } 449 else { 450 processButton.setEnabled (false); 451 } 452 } 453 else if (options[1].equals (e.getSource ())) { 454 Enumeration en = connectionPanel.listModel.elements (); 455 while (en.hasMoreElements ()) { 456 processDDChangeEvent ((DDChangeEvent)en.nextElement ()); 457 } 458 confirmChangesDialog[0].setVisible (false); 459 connectionPanel.setChanges (null); 460 } 461 else if (additionalOptions[0].equals (e.getSource ())) { 462 confirmChangesDialog[0].setVisible (false); 463 connectionPanel.setChanges (null); 464 } 465 } 466 } 467 ); 468 confirmChangesDescriptor.setAdditionalOptions (additionalOptions); 469 470 processButton.setEnabled (false); 471 processAllButton.requestFocus (); 472 connectionPanel.setChanges (changes); 473 474 try { 475 confirmChangesDialog[0] = DialogDisplayer.getDefault ().createDialog (confirmChangesDescriptor); 476 confirmChangesDialog[0].setVisible(true); 477 } finally { 478 confirmChangesDialog[0].dispose (); 479 } 480 } 481 482 private void processDDChangeEvent (DDChangeEvent evt) { 483 if (!isValid()) { 484 return; 485 } 486 487 if (evt.getType () == DDChangeEvent.SERVLET_ADDED) { 488 String clz = evt.getNewValue (); 489 490 String urimapping = "/servlet/"+clz; createDefaultServletConfiguration (clz, urimapping); 493 } 494 else if (evt.getType () == DDChangeEvent.SERVLET_CHANGED) { 495 String old = evt.getOldValue (); 497 if (old == null) { 498 return; 499 } 500 501 Servlet [] servlets = getWebApp ().getServlet (); 502 for (int i=0; i<servlets.length; i++) { 503 if (old.equals (servlets[i].getServletClass ())) { 504 servlets[i].setServletClass ((String )evt.getNewValue ()); 505 } 506 } 507 } 508 else if (evt.getType () == DDChangeEvent.SERVLET_DELETED) { 509 String clz = evt.getNewValue (); 511 if (clz == null) { 512 return; 513 } 514 515 WebApp wa = getWebApp (); 516 Servlet [] servlets = wa.getServlet (); 517 java.util.Vector servletNames = new java.util.Vector (); 518 for (int i=0; i<servlets.length; i++) { 519 if (clz.equals (servlets[i].getServletClass ())) { 520 servletNames.addElement (servlets[i].getServletName ()); 521 wa.removeServlet (servlets[i]); 522 } 523 } 524 ServletMapping [] mappings = wa.getServletMapping (); 525 for (int i=0; i<mappings.length; i++) { 526 if (servletNames.contains (mappings[i].getServletName ())) { 527 wa.removeServletMapping (mappings[i]); 528 } 529 } 530 } 531 else if (evt.getType () == DDChangeEvent.FILTER_CHANGED) { 532 String old = evt.getOldValue (); 533 if (old == null) { 534 return; 535 } 536 537 Filter [] filters = getWebApp ().getFilter (); 538 for (int i=0; i<filters.length; i++) { 539 if (old.equals (filters[i].getFilterClass ())) { 540 filters[i].setFilterClass ((String )evt.getNewValue ()); 541 } 542 } 543 } 544 else if (evt.getType () == DDChangeEvent.FILTER_DELETED) { 545 String clz = evt.getNewValue (); 546 if (clz == null) { 547 return; 548 } 549 550 WebApp wa = getWebApp (); 551 Filter [] filters = wa.getFilter (); 552 java.util.Vector filterNames = new java.util.Vector (); 553 for (int i=0; i<filters.length; i++) { 554 if (clz.equals (filters[i].getFilterClass ())) { 555 filterNames.addElement (filters[i].getFilterName ()); 556 wa.removeFilter (filters[i]); 557 } 558 } 559 FilterMapping [] mappings = wa.getFilterMapping (); 560 for (int i=0; i<mappings.length; i++) { 561 if (filterNames.contains (mappings[i].getFilterName ())) { 562 wa.removeFilterMapping (mappings[i]); 563 } 564 } 565 } 566 else if (evt.getType () == DDChangeEvent.LISTENER_CHANGED) { 567 String old = evt.getOldValue (); 568 if (old == null) { 569 return; 570 } 571 572 Listener [] listeners = getWebApp ().getListener (); 573 for (int i=0; i<listeners.length; i++) { 574 if (old.equals (listeners[i].getListenerClass ())) { 575 listeners[i].setListenerClass ((String )evt.getNewValue ()); 576 } 577 } 578 } 579 else if (evt.getType () == DDChangeEvent.LISTENER_DELETED) { 580 String clz = evt.getNewValue (); 581 if (clz == null) { 582 return; 583 } 584 585 WebApp wa = getWebApp (); 586 Listener [] listeners = wa.getListener (); 587 for (int i=0; i<listeners.length; i++) { 588 if (clz.equals (listeners[i].getListenerClass ())) { 589 wa.removeListener (listeners[i]); 590 break; 591 } 592 } 593 } 594 try { 595 writeModel(getWebApp()); 596 } catch (IOException e) { 597 ErrorManager.getDefault().notify(e); 598 } 599 } 600 601 private OperationListener operationListener = new OperationAdapter() { 602 public void operationDelete(OperationEvent ev) { 603 FileObject fo = ev.getObject().getPrimaryFile(); 604 String resourceName = getPackageName (fo); 605 if (resourceName != null && "java".equals(fo.getExt()) && getWebApp() != null) { boolean foundElement=false; 607 Servlet[] servlets = getWebApp().getServlet(); 608 for (int i=0;i<servlets.length;i++) { 609 if (resourceName.equals(servlets[i].getServletClass())) { 610 DDChangeEvent ddEvent = new DDChangeEvent(DDDataObject.this,DDDataObject.this,null,resourceName,DDChangeEvent.SERVLET_DELETED); 611 deploymentChange (ddEvent); 612 foundElement=true; 613 break; 614 } 615 } 616 if (foundElement) { 617 return; 618 } 619 Filter[] filters = getWebApp().getFilter(); 620 for (int i=0;i<filters.length;i++) { 621 if (resourceName.equals(filters[i].getFilterClass())) { 622 DDChangeEvent ddEvent = new DDChangeEvent(DDDataObject.this,DDDataObject.this,null,resourceName,DDChangeEvent.FILTER_DELETED); 623 deploymentChange (ddEvent); 624 foundElement=true; 625 break; 626 } 627 } 628 if (foundElement) { 629 return; 630 } 631 Listener [] listeners = getWebApp().getListener(); 632 for (int i=0;i<listeners.length;i++) { 633 if (resourceName.equals(listeners[i].getListenerClass())) { 634 DDChangeEvent ddEvent = new DDChangeEvent(DDDataObject.this,DDDataObject.this,null,resourceName,DDChangeEvent.LISTENER_DELETED); 635 deploymentChange (ddEvent); 636 break; } 638 } 639 } 640 } 641 }; 642 643 public void stateChanged (javax.swing.event.ChangeEvent e) { 644 refreshSourceFolders (); 645 } 646 647 public HelpCtx getHelpCtx() { 648 return new HelpCtx(HELP_ID_PREFIX_OVERVIEW+"overviewNode"); } 650 651 654 protected boolean isModelCreated() { 655 return (webApp!=null && ((org.netbeans.modules.j2ee.dd.impl.web.WebAppProxy)webApp).getOriginal()!=null); 656 } 657 658 660 private class FileObjectObserver implements FileChangeListener { 661 FileObjectObserver (FileObject fo) { 662 fo.addFileChangeListener((FileChangeListener)org.openide.util.WeakListeners.create( 663 FileChangeListener.class, this, fo)); 664 } 665 666 public void fileAttributeChanged(FileAttributeEvent fileAttributeEvent) { 667 } 668 669 public void fileChanged(FileEvent fileEvent) { 670 683 } 684 685 public void fileDataCreated(FileEvent fileEvent) { 686 } 687 688 public void fileDeleted(FileEvent fileEvent) { 689 } 690 691 public void fileFolderCreated(FileEvent fileEvent) { 692 } 693 694 public void fileRenamed(FileRenameEvent fileRenameEvent) { 695 } 696 } 697 698 699 public static final String DD_MULTIVIEW_PREFIX = "dd_multiview"; public static final String MULTIVIEW_OVERVIEW = "Overview"; public static final String MULTIVIEW_SERVLETS = "Servlets"; public static final String MULTIVIEW_FILTERS = "Filters"; public static final String MULTIVIEW_PAGES = "Pages"; public static final String MULTIVIEW_REFERENCES = "References"; public static final String MULTIVIEW_SECURITY = "Security"; 707 private ServletsMultiViewElement servletMVElement; 708 709 protected DesignMultiViewDesc[] getMultiViewDesc() { 710 return new DesignMultiViewDesc[] { 711 new DDView(this,MULTIVIEW_OVERVIEW), 712 new DDView(this,MULTIVIEW_SERVLETS), 713 new DDView(this,MULTIVIEW_FILTERS), 714 new DDView(this,MULTIVIEW_PAGES), 715 new DDView(this,MULTIVIEW_REFERENCES), 716 new DDView(this, MULTIVIEW_SECURITY) 717 }; 719 } 720 721 private static class DDView extends DesignMultiViewDesc implements Serializable { 722 private static final long serialVersionUID = -4814134594154669985L; 723 private String name; 724 725 DDView() {} 726 727 DDView(DDDataObject dObj,String name) { 728 super(dObj, name); 729 this.name=name; 730 } 731 732 public org.netbeans.core.spi.multiview.MultiViewElement createElement() { 733 DDDataObject dObj = (DDDataObject)getDataObject(); 734 if (name.equals(MULTIVIEW_OVERVIEW)) { 735 return new OverviewMultiViewElement(dObj,0); 736 } else if (name.equals(MULTIVIEW_SERVLETS)) { 737 return new ServletsMultiViewElement(dObj,1); 738 } else if (name.equals(MULTIVIEW_FILTERS)) { 739 return new FiltersMultiViewElement(dObj,2); 740 } else if(name.equals(MULTIVIEW_PAGES)) { 741 return new PagesMultiViewElement(dObj,3); 742 } else if(name.equals(MULTIVIEW_REFERENCES)) { 743 return new ReferencesMultiViewElement(dObj,4); 744 } else if (name.equals(MULTIVIEW_SECURITY)) { 745 return new SecurityMultiViewElement(dObj, 5); 746 } 747 return null; 748 } 749 750 public HelpCtx getHelpCtx() { 751 if (name.equals(MULTIVIEW_OVERVIEW)) { 752 return new HelpCtx(HELP_ID_PREFIX_OVERVIEW+"overviewNode"); } else if (name.equals(MULTIVIEW_SERVLETS)) { 754 return new HelpCtx(HELP_ID_PREFIX_SERVLETS+"servletsNode"); } else if (name.equals(MULTIVIEW_FILTERS)) { 756 return new HelpCtx(HELP_ID_PREFIX_FILTERS+"filtersNode"); } else if(name.equals(MULTIVIEW_PAGES)) { 758 return new HelpCtx(HELP_ID_PREFIX_OVERVIEW+"overviewNode"); } else if(name.equals(MULTIVIEW_REFERENCES)) { 760 return new HelpCtx(HELP_ID_PREFIX_REFERENCES+"references"); } 762 return null; 763 } 764 765 public java.awt.Image getIcon() { 766 return org.openide.util.Utilities.loadImage("org/netbeans/modules/j2ee/ddloaders/web/resources/DDDataIcon.gif"); } 768 769 public String preferredID() { 770 return DD_MULTIVIEW_PREFIX+name; 771 } 772 773 public String getDisplayName() { 774 return NbBundle.getMessage(DDDataObject.class,"TTL_"+name); 775 } 776 } 777 778 781 public void showElement(Object element) { 782 Object target=null; 783 if (element instanceof Servlet) { 784 openView(1); 785 target=element; 786 } else if (element instanceof Filter) { 787 openView(2); 788 target=element; 789 } else if (element instanceof Listener ) { 790 openView(0); 791 target="listeners"; } else if (element instanceof InitParam) { 793 InitParam param = (InitParam)element; 794 InitParam[] params = getWebApp().getContextParam(); 795 for (int i=0;i<params.length;i++) { 796 if (params[i]==param) { 797 openView(0); 798 target="context_params"; break; 800 } 801 } 802 } else if (element instanceof ErrorPage) { 803 openView(3); 804 target="error_pages"; } 806 if (target!=null) { 807 final Object key=target; 808 org.netbeans.modules.xml.multiview.Utils.runInAwtDispatchThread(new Runnable () { 809 public void run() { 810 ToolBarMultiViewElement mvEl = getActiveMVElement(); 811 if (mvEl!=null) mvEl.getSectionView().openPanel(key); 812 } 813 }); 814 } 815 } 816 819 public boolean isDeleteAllowed() { 820 return WebApp.VERSION_2_5.equals(getWebApp().getVersion()); 821 } 822 824 public ToolBarMultiViewElement getActiveMVElement() { 825 return (ToolBarMultiViewElement)super.getActiveMultiViewElement(); 826 } 827 828 public boolean isChangedFromUI() { 829 return changedFromUI; 830 } 831 832 public void setChangedFromUI(boolean changedFromUI) { 833 this.changedFromUI=changedFromUI; 834 } 835 } 836 | Popular Tags |