1 19 package org.netbeans.modules.j2ee.websphere6.dd.loaders.webbnd; 20 21 import java.io.IOException ; 22 import org.netbeans.modules.j2ee.websphere6.dd.beans.DDXmiConstants; 23 import org.netbeans.modules.j2ee.websphere6.dd.beans.EjbRefBindingsType; 24 import org.netbeans.modules.j2ee.websphere6.dd.beans.ResEnvRefBindingsType; 25 import org.netbeans.modules.j2ee.websphere6.dd.beans.ResRefBindingsType; 26 import org.netbeans.modules.j2ee.websphere6.dd.beans.WSWebBnd; 27 import org.netbeans.modules.j2ee.websphere6.dd.loaders.WSMultiViewDataObject; 28 import org.netbeans.modules.j2ee.websphere6.dd.loaders.ui.WSReferenceBindingsPanel; 29 import org.netbeans.modules.j2ee.websphere6.dd.loaders.SectionNodes.*; 30 import org.netbeans.modules.xml.multiview.*; 31 import org.netbeans.modules.xml.multiview.ui.*; 32 import org.openide.nodes.*; 33 import org.openide.util.RequestProcessor; 34 import org.openide.util.NbBundle; 35 import org.netbeans.modules.xml.multiview.Error; 36 40 public class WSWebBndToolBarMVElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener , DDXmiConstants{ 41 private ToolBarDesignEditor comp; 42 private SectionView view; 43 private WSWebBndDataObject dObj; 44 private PanelFactory factory; 45 private RequestProcessor.Task repaintingTask; 46 private boolean needInit=true; 47 private javax.swing.Action addResRefAction, removeResRefAction; 48 private javax.swing.Action addEjbRefAction, removeEjbRefAction; 49 private javax.swing.Action addResEnvRefAction, removeResEnvRefAction; 50 private static final long serialVersionUID = 76123745399723L; 51 private static final String WEBBND_MV_ID = WSMultiViewDataObject.MULTIVIEW_WEBBND + 52 WSMultiViewDataObject.DD_MULTIVIEW_POSTFIX; 53 54 public WSWebBndToolBarMVElement(WSWebBndDataObject dObj) { 55 super(dObj); 56 this.dObj=dObj; 57 comp = new ToolBarDesignEditor(); 58 factory=new PanelFactory(comp,dObj); 59 addResRefAction = new AddResRefAction("Add New Resource Reference Binding.."); 60 removeResRefAction = new RemoveResRefAction("Remove This Binding"); 61 62 addEjbRefAction = new AddEjbRefAction("Add New Ejb Reference Binding.."); 63 removeEjbRefAction = new RemoveEjbRefAction("Remove This Binding"); 64 65 addResEnvRefAction = new AddResEnvRefAction("Add New Resource Env Reference Binding.."); 66 removeResEnvRefAction = new RemoveResEnvRefAction("Remove This Binding"); 67 68 69 setVisualEditor(comp); 70 repaintingTask = RequestProcessor.getDefault().create(new Runnable () { 71 public void run() { 72 javax.swing.SwingUtilities.invokeLater(new Runnable () { 73 public void run() { 74 repaintView(); 75 } 76 }); 77 } 78 }); 79 80 } 81 private void repaintView() { 82 view =new WSWebBndView(dObj); 83 comp.setContentView(view); 84 Object lastActive = comp.getLastActive(); 85 if (lastActive!=null) { 86 ((SectionView)view).openPanel(lastActive); 87 } else { 88 } 90 view.checkValidity(); 91 } 93 94 95 96 public SectionView getSectionView() { 97 return view; 98 } 99 public WSWebBndView getWebBndView() { 100 return (WSWebBndView)view; 101 } 102 103 public void componentShowing() { 104 super.componentShowing(); 105 if (needInit) { 106 repaintView(); 107 needInit=false; 108 } 109 comp.setContentView(view); 111 try { 112 ((SectionView)view).openPanel(dObj.getWebBnd()); 113 } catch(java.io.IOException e) { 114 115 } 116 117 view.checkValidity(); 118 } 119 public void componentOpened() { 120 super.componentOpened(); 121 try { 122 dObj.getWebBnd().addPropertyChangeListener(this); 123 } catch(IOException ex) { 124 ex=null; 125 } 126 } 127 128 public void componentClosed() { 129 super.componentClosed(); 130 try { 131 dObj.getWebBnd().removePropertyChangeListener(this); 132 } catch(IOException ex) { 133 ex=null; 134 } 135 } 136 public void propertyChange(java.beans.PropertyChangeEvent evt) { 137 if (!dObj.isChangedFromUI()) { 138 String name = evt.getPropertyName(); 139 if ( name.indexOf("WebApplicationBnd")>0 ) { if (WEBBND_MV_ID.equals(dObj.getSelectedPerspective().preferredID())) { 142 repaintingTask.schedule(100); 143 } else { 144 needInit=true; 145 } 146 } 147 } 148 } 149 150 private class AddResRefAction extends javax.swing.AbstractAction { 151 152 AddResRefAction(String actionName) { 153 super(actionName); 154 } 157 public void actionPerformed(java.awt.event.ActionEvent evt) { 158 try{ 159 dObj.setChangedFromUI(true); 160 WSWebBnd webbnd=dObj.getWebBnd(); 161 ResRefBindingsType rr=new ResRefBindingsType(WEB_APPLICATION); 162 rr.setDefaults(); 163 int number=webbnd.getResRefBindings().length+1; 164 165 webbnd.addResRefBindings(rr); 167 Node resrefNode = new ResRefNode(); 169 view.getRoot().getChildren().add(new Node[]{resrefNode}); 170 resrefNode.setDisplayName(resrefNode.getDisplayName()+number); 171 dObj.setChangedFromUI(true); 172 dObj.modelUpdatedFromUI(); 173 ResRefBindingsType[] resrefs = webbnd.getResRefBindings(); 174 SectionPanel sectionPanel=new SectionPanel(view,resrefNode,rr); 175 sectionPanel.setHeaderActions(new javax.swing.Action []{removeResRefAction}); 176 ((WSWebBndView)view).getResRefsContainer().addSection(sectionPanel,true); 177 dObj.setChangedFromUI(false); 178 179 } catch (java.io.IOException ex) { 180 } catch (java.lang.IllegalArgumentException ex) { 181 } 182 } 183 } 184 private class RemoveResRefAction extends javax.swing.AbstractAction { 185 186 RemoveResRefAction(String actionName) { 187 super(actionName); 188 } 191 192 public void actionPerformed(java.awt.event.ActionEvent evt) { 193 SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel(); 194 ResRefBindingsType resref = (ResRefBindingsType)sectionPanel.getKey(); 195 197 try { 198 dObj.modelUpdatedFromUI(); 199 dObj.setChangedFromUI(true); 200 dObj.getWebBnd().removeResRefBindings(resref); 201 sectionPanel.getSectionView().removeSection(sectionPanel.getNode()); 202 } catch (java.io.IOException ec) { 203 204 } finally { 205 dObj.setChangedFromUI(false); 206 } 207 208 } 209 } 210 211 212 private class AddEjbRefAction extends javax.swing.AbstractAction { 213 214 AddEjbRefAction(String actionName) { 215 super(actionName); 216 } 219 public void actionPerformed(java.awt.event.ActionEvent evt) { 220 221 try{ 222 dObj.setChangedFromUI(true); 223 WSWebBnd webbnd=dObj.getWebBnd(); 224 EjbRefBindingsType er=new EjbRefBindingsType(WEB_APPLICATION); 225 er.setDefaults(); 226 int number=webbnd.getEjbRefBindings().length+1; 227 228 webbnd.addEjbRefBindings(er); 230 Node ejbrefNode = new EjbRefNode(); 232 Node root=view.getRoot(); 233 root.getChildren().add(new Node[]{ejbrefNode}); 234 ejbrefNode.setDisplayName(ejbrefNode.getDisplayName()+number); 235 dObj.setChangedFromUI(true); 236 dObj.modelUpdatedFromUI(); 237 EjbRefBindingsType[] ejbrefs = webbnd.getEjbRefBindings(); 238 SectionPanel sectionPanel=new SectionPanel(view,ejbrefNode,er); 239 sectionPanel.setHeaderActions(new javax.swing.Action []{removeEjbRefAction}); 240 ((WSWebBndView)view).getEjbRefsContainer().addSection(sectionPanel,true); 241 dObj.setChangedFromUI(false); 242 243 } catch (java.io.IOException ex) { 244 } catch (java.lang.IllegalArgumentException ex) { 245 } 246 } 247 } 248 private class RemoveEjbRefAction extends javax.swing.AbstractAction { 249 250 RemoveEjbRefAction(String actionName) { 251 super(actionName); 252 } 255 256 public void actionPerformed(java.awt.event.ActionEvent evt) { 257 SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel(); 258 EjbRefBindingsType ejbref = (EjbRefBindingsType)sectionPanel.getKey(); 259 261 try { 262 dObj.modelUpdatedFromUI(); 263 dObj.setChangedFromUI(true); 264 dObj.getWebBnd().removeEjbRefBindings(ejbref); 265 sectionPanel.getSectionView().removeSection(sectionPanel.getNode()); 266 } catch (java.io.IOException ec) { 267 268 } finally { 269 dObj.setChangedFromUI(false); 270 } 271 272 273 } 274 } 275 276 277 278 private class AddResEnvRefAction extends javax.swing.AbstractAction { 279 280 AddResEnvRefAction(String actionName) { 281 super(actionName); 282 } 285 public void actionPerformed(java.awt.event.ActionEvent evt) { 286 try{ 287 WSWebBnd webbnd=dObj.getWebBnd(); 288 ResEnvRefBindingsType rer=new ResEnvRefBindingsType(WEB_APPLICATION); 289 rer.setDefaults(); 290 int number=webbnd.getResEnvRefBindings().length+1; 291 292 webbnd.addResEnvRefBindings(rer); 294 Node resenvrefNode = new ResEnvRefNode(); 296 view.getRoot().getChildren().add(new Node[]{resenvrefNode}); 297 resenvrefNode.setDisplayName(resenvrefNode.getDisplayName()+number); 298 dObj.setChangedFromUI(true); 299 dObj.modelUpdatedFromUI(); 300 ResEnvRefBindingsType[] resenvrefs = webbnd.getResEnvRefBindings(); 301 SectionPanel sectionPanel=new SectionPanel(view,resenvrefNode,rer); 302 sectionPanel.setHeaderActions(new javax.swing.Action []{removeResEnvRefAction}); 303 ((WSWebBndView)view).getResEnvRefsContainer().addSection(sectionPanel,true); 304 dObj.setChangedFromUI(false); 305 306 } catch (java.io.IOException ex) { 307 } catch (java.lang.IllegalArgumentException ex) { 308 } 309 } 310 } 311 private class RemoveResEnvRefAction extends javax.swing.AbstractAction { 312 313 RemoveResEnvRefAction(String actionName) { 314 super(actionName); 315 } 318 319 public void actionPerformed(java.awt.event.ActionEvent evt) { 320 SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel(); 321 ResEnvRefBindingsType resenvref = (ResEnvRefBindingsType)sectionPanel.getKey(); 322 324 try { 325 dObj.modelUpdatedFromUI(); 326 dObj.setChangedFromUI(true); 327 dObj.getWebBnd().removeResEnvRefBindings(resenvref); 328 sectionPanel.getSectionView().removeSection(sectionPanel.getNode()); 329 } catch (java.io.IOException ec) { 330 331 } finally { 332 dObj.setChangedFromUI(false); 333 } 334 335 } 336 } 337 338 339 private class WSWebBndView extends SectionView { 340 private SectionContainer resrefsCont; 341 private SectionContainer ejbrefsCont; 342 private SectionContainer resenvrefsCont; 343 private WSWebBnd webbnd; 344 XmlMultiViewDataSynchronizer sync; 345 WSWebBndView(WSWebBndDataObject dObj) { 346 super(factory); 347 Children rootChildren = new Children.Array(); 348 Node root = new AbstractNode(rootChildren); 349 try { 350 this.webbnd=dObj.getWebBnd(); 351 rootChildren.add(new Node[]{ 352 createWebBndAttrNode(), 353 createResRefNode(), 354 createEjbRefNode(), 355 createResEnvRefNode()} 356 ); 357 } catch (java.io.IOException ex) { 358 System.out.println("ex="+ex); 359 root.setDisplayName("Invalid WebBnd"); 360 } finally { 361 setRoot(root); 362 } 363 } 364 365 366 private Node createWebBndAttrNode() { 367 Node webbndNode = new WSWebBndNode(); 368 addSection(new SectionPanel(this,webbndNode,webbnd)); 370 return webbndNode; 371 } 372 373 private Node createResRefNode() { 374 ResRefBindingsType[] resrefs = webbnd.getResRefBindings(); 375 Children resch = new Children.Array(); 376 Node[] resrefNode=null; 377 378 if(resrefs!=null && resrefs.length>0) { 379 resrefNode = new Node[resrefs.length]; 380 for (int i=0;i<resrefs.length;i++) { 381 resrefNode[i] = new ResRefNode(); 382 resrefNode[i].setDisplayName("Binding Item #"+(i+1)); 383 } 384 resch.add(resrefNode); 385 } 386 387 Node resrefsNode = new SectionContainerNode(resch); 388 resrefsNode.setDisplayName("Resource Reference Bindings"); 389 390 resrefsCont = new SectionContainer(this,resrefsNode,"Resource Reference Bindings"); 392 resrefsCont.setHeaderActions(new javax.swing.Action []{addResRefAction}); 393 394 if(resrefs!=null) { 396 SectionPanel[] pan = new SectionPanel[resrefs.length]; 397 for (int i=0;i<resrefs.length;i++) { 398 pan[i] = new SectionPanel(this, resrefNode[i], resrefs[i]); 399 pan[i].setHeaderActions(new javax.swing.Action []{removeResRefAction}); 400 resrefsCont.addSection(pan[i]); 401 } 402 } 403 addSection(resrefsCont); 404 return resrefsNode; 405 } 406 407 private Node createEjbRefNode() { 408 EjbRefBindingsType[] ejbrefs = webbnd.getEjbRefBindings(); 410 Children ejbch = new Children.Array(); 411 Node[] ejbrefNode=null; 412 413 if(ejbrefs!=null && ejbrefs.length>0) { 414 ejbrefNode = new Node[ejbrefs.length]; 415 for (int i=0;i<ejbrefs.length;i++) { 416 ejbrefNode[i] = new EjbRefNode(); 417 ejbrefNode[i].setDisplayName("Binding Item #"+(i+1)); 418 } 419 ejbch.add(ejbrefNode); 420 } 421 422 Node ejbrefsNode = new SectionContainerNode(ejbch); 423 ejbrefsNode.setDisplayName("Ejb Reference Bindings"); 424 425 ejbrefsCont = new SectionContainer(this,ejbrefsNode,"Ejb Reference Bindings"); 426 ejbrefsCont.setHeaderActions(new javax.swing.Action []{addEjbRefAction}); 427 428 if(ejbrefs!=null) { 430 SectionPanel[] pan = new SectionPanel[ejbrefs.length]; 431 for (int i=0;i<ejbrefs.length;i++) { 432 pan[i] = new SectionPanel(this, ejbrefNode[i], ejbrefs[i]); 433 pan[i].setHeaderActions(new javax.swing.Action []{removeEjbRefAction}); 434 ejbrefsCont.addSection(pan[i]); 435 } 436 } 437 addSection(ejbrefsCont); 438 return ejbrefsNode; 439 } 440 441 private Node createResEnvRefNode() { 442 ResEnvRefBindingsType[] resenvrefs = webbnd.getResEnvRefBindings(); 443 Children resenvch = new Children.Array(); 444 Node[] resenvrefNode=null; 445 446 if(resenvrefs!=null && resenvrefs.length>0) { 447 resenvrefNode = new Node[resenvrefs.length]; 448 for (int i=0;i<resenvrefs.length;i++) { 449 resenvrefNode[i] = new ResEnvRefNode(); 450 resenvrefNode[i].setDisplayName("Binding Item #"+(i+1)); 451 } 452 resenvch.add(resenvrefNode); 453 } 454 455 Node resenvrefsNode = new SectionContainerNode(resenvch); 456 resenvrefsNode.setDisplayName("Resource Env Reference Bindings"); 457 458 resenvrefsCont = new SectionContainer(this,resenvrefsNode,"Resource Env Reference Bindings"); 460 resenvrefsCont.setHeaderActions(new javax.swing.Action []{addResEnvRefAction}); 461 462 if(resenvrefs!=null) { 464 SectionPanel[] pan = new SectionPanel[resenvrefs.length]; 465 for (int i=0;i<resenvrefs.length;i++) { 466 pan[i] = new SectionPanel(this, resenvrefNode[i], resenvrefs[i]); 467 pan[i].setHeaderActions(new javax.swing.Action []{removeResEnvRefAction}); 468 resenvrefsCont.addSection(pan[i]); 469 } 470 } 471 addSection(resenvrefsCont); 472 return resenvrefsNode; 473 474 } 475 476 public SectionContainer getResRefsContainer() { 477 return resrefsCont; 478 } 479 public SectionContainer getEjbRefsContainer() { 480 return ejbrefsCont; 481 } 482 public SectionContainer getResEnvRefsContainer() { 483 return resenvrefsCont; 484 } 485 } 486 487 488 489 public Error validateView() { 490 try { 491 WSWebBnd webbnd = dObj.getWebBnd(); 492 493 ResRefBindingsType[] resrefs = webbnd.getResRefBindings(); 494 if(resrefs==null) { 495 return null; 496 } 497 for (int i=0;i<resrefs.length;i++) { 498 String title = resrefs[i].getBindingReference(); 499 if (title==null || title.length()==0) { 500 Error.ErrorLocation loc = new Error.ErrorLocation (resrefs[i],"title"); 501 return new Error (Error.MISSING_VALUE_MESSAGE, "Title", loc); 502 } 503 for (int j=0;j<resrefs.length;j++) { 504 String tit = resrefs[j].getBindingReference(); 505 if (i!=j && title.equals(tit)) { 506 Error.ErrorLocation loc = new Error.ErrorLocation (resrefs[i],"title"); 507 return new Error (Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc); 508 } 509 } 510 } 511 512 EjbRefBindingsType[] ejbrefs = webbnd.getEjbRefBindings(); 513 if(ejbrefs==null) { 514 return null; 515 } 516 for (int i=0;i<ejbrefs.length;i++) { 517 String title = ejbrefs[i].getBindingReference(); 518 if (title==null || title.length()==0) { 519 Error.ErrorLocation loc = new Error.ErrorLocation (ejbrefs[i],"title"); 520 return new Error (Error.MISSING_VALUE_MESSAGE, "Title", loc); 521 } 522 for (int j=0;j<ejbrefs.length;j++) { 523 String tit = ejbrefs[j].getBindingReference(); 524 if (i!=j && title.equals(tit)) { 525 Error.ErrorLocation loc = new Error.ErrorLocation (ejbrefs[i],"title"); 526 return new Error (Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc); 527 } 528 } 529 } 530 531 ResEnvRefBindingsType[] resenvrefs = webbnd.getResEnvRefBindings(); 532 if(resenvrefs==null) { 533 return null; 534 } 535 for (int i=0;i<resenvrefs.length;i++) { 536 String title = resenvrefs[i].getBindingReference(); 537 if (title==null || title.length()==0) { 538 Error.ErrorLocation loc = new Error.ErrorLocation (resenvrefs[i],"title"); 539 return new Error (Error.MISSING_VALUE_MESSAGE, "Title", loc); 540 } 541 for (int j=0;j<resenvrefs.length;j++) { 542 String tit = resenvrefs[j].getBindingReference(); 543 if (i!=j && title.equals(tit)) { 544 Error.ErrorLocation loc = new Error.ErrorLocation (resenvrefs[i],"title"); 545 return new Error (Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc); 546 } 547 } 548 } 549 } catch (java.io.IOException ex){} 550 return null; 551 } 552 553 554 public static class WSWebBndNode extends org.openide.nodes.AbstractNode { 555 WSWebBndNode() { 556 super(org.openide.nodes.Children.LEAF); 557 setDisplayName("General Deployment Binding Information"); 558 } 560 } 561 562 } 563 | Popular Tags |