1 19 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ejbext; 20 21 import java.io.IOException ; 22 import org.netbeans.modules.j2ee.websphere6.dd.beans.EjbExtensionsType; 23 import org.netbeans.modules.j2ee.websphere6.dd.beans.WSEjbExt; 24 import org.netbeans.modules.j2ee.websphere6.dd.loaders.WSMultiViewDataObject; 25 import org.netbeans.modules.xml.multiview.*; 26 import org.netbeans.modules.xml.multiview.ui.*; 27 import org.openide.nodes.*; 28 import org.openide.util.RequestProcessor; 29 import org.openide.util.NbBundle; 30 import org.netbeans.modules.xml.multiview.Error; 31 35 public class WSEjbExtToolBarMVElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener { 36 private ToolBarDesignEditor comp; 37 private SectionView view; 38 private WSEjbExtDataObject dObj; 39 private PanelFactory factory; 40 private RequestProcessor.Task repaintingTask; 41 private boolean needInit=true; 42 private javax.swing.Action addExtensionAction, removeExtensionAction; 43 private static final long serialVersionUID = 76737428339792L; 44 private static final String EJBEXT_MV_ID = WSMultiViewDataObject.MULTIVIEW_EJBEXT + 45 WSMultiViewDataObject.DD_MULTIVIEW_POSTFIX; 46 public WSEjbExtToolBarMVElement(WSEjbExtDataObject dObj) { 47 super(dObj); 48 this.dObj=dObj; 49 comp = new ToolBarDesignEditor(); 50 factory=new PanelFactory(comp,dObj); 51 52 addExtensionAction = new AddExtensionAction(NbBundle.getMessage(WSEjbExtToolBarMVElement.class,"LBL_addEjbExtension")); 53 removeExtensionAction = new RemoveExtensionAction(NbBundle.getMessage(WSEjbExtToolBarMVElement.class,"LBL_removeEjbExtension")); 54 55 setVisualEditor(comp); 56 repaintingTask = RequestProcessor.getDefault().create(new Runnable () { 57 public void run() { 58 javax.swing.SwingUtilities.invokeLater(new Runnable () { 59 public void run() { 60 repaintView(); 61 } 62 }); 63 } 64 }); 65 } 66 67 private void repaintView() { 68 view =new WSEjbExtView(dObj); 69 comp.setContentView(view); 70 Object lastActive = comp.getLastActive(); 71 if (lastActive!=null) { 72 ((SectionView)view).openPanel(lastActive); 73 } else { 74 } 76 view.checkValidity(); 77 } 79 80 81 82 public SectionView getSectionView() { 83 return view; 84 } 85 public WSEjbExtView getEjbExtView() { 86 return (WSEjbExtView)view; 87 } 88 89 public void componentShowing() { 90 super.componentShowing(); 91 if (needInit) { 92 repaintView(); 93 needInit=false; 94 } 95 comp.setContentView(view); 97 try { 98 view.openPanel(dObj.getEjbExt()); 99 } catch(java.io.IOException ex){} 100 view.checkValidity(); 101 } 102 103 public void componentOpened() { 104 super.componentOpened(); 105 try { 106 dObj.getEjbExt().addPropertyChangeListener(this); 107 } catch(IOException ex) { 108 ex=null; 109 } 110 } 111 112 public void componentClosed() { 113 super.componentClosed(); 114 try { 115 dObj.getEjbExt().removePropertyChangeListener(this); 116 } catch(IOException ex) { 117 ex=null; 118 } 119 } 120 121 public void propertyChange(java.beans.PropertyChangeEvent evt) { 122 if (!dObj.isChangedFromUI()) { 123 String name = evt.getPropertyName(); 124 if ( name.indexOf("EjbJarExt")>0 ) { if (EJBEXT_MV_ID.equals(dObj.getSelectedPerspective().preferredID())) { 127 repaintingTask.schedule(100); 128 } else { 129 needInit=true; 130 } 131 } 132 } 133 } 134 135 private class WSEjbExtView extends SectionView { 136 private SectionContainer extensionsCont; 137 private WSEjbExt ejbext; 138 139 WSEjbExtView(WSEjbExtDataObject dObj) { 140 super(factory); 141 142 Children rootChildren = new Children.Array(); 143 Node root = new AbstractNode(rootChildren); 144 try { 145 this.ejbext=dObj.getEjbExt(); 146 rootChildren.add(new Node[]{ 147 createEjbExtAttrNode(), 148 createEjbExtensionsNode() 149 }); 150 } catch (java.io.IOException ex) { 151 System.out.println("ex="+ex); 152 root.setDisplayName("Invalid EjbExt"); 153 } finally { 154 setRoot(root); 155 } 156 } 157 public SectionContainer getEjbExtensionsContainer() { 158 return extensionsCont; 159 } 160 161 private Node createEjbExtAttrNode() { 162 Node ejbextNode = new WSEjbExtNode(ejbext); 163 addSection(new SectionPanel(this,ejbextNode,ejbext)); 165 return ejbextNode; 166 } 167 private Node createEjbExtensionsNode() { 168 169 EjbExtensionsType[] extensions = ejbext.getEjbExtensions(); 170 Children extch = new Children.Array(); 171 Node[] extensionNode=null; 172 173 if(extensions!=null && extensions.length>0) { 174 extensionNode = new Node[extensions.length]; 175 for (int i=0;i<extensions.length;i++) { 176 extensionNode[i] = new ExtensionNode(); 177 extensionNode[i].setDisplayName("Ejb Extension #"+(i+1)); 178 } 179 extch.add(extensionNode); 180 } 181 182 Node extensionsNode = new SectionContainerNode(extch); 183 extensionsNode.setDisplayName("Ejb Extensions"); 184 185 186 extensionsCont = new SectionContainer(this,extensionsNode,"Ejb Extension"); 187 extensionsCont.setHeaderActions(new javax.swing.Action []{addExtensionAction}); 188 189 if(extensions!=null) { 191 SectionPanel[] pan = new SectionPanel[extensions.length]; 192 for (int i=0;i<extensions.length;i++) { 193 pan[i] = new SectionPanel(this, extensionNode[i], extensions[i]); 194 pan[i].setHeaderActions(new javax.swing.Action []{removeExtensionAction}); 195 extensionsCont.addSection(pan[i]); 196 } 197 } 198 addSection(extensionsCont); 199 return extensionsNode; 200 } 201 202 } 203 204 private class AddExtensionAction extends javax.swing.AbstractAction { 205 206 AddExtensionAction(String actionName) { 207 super(actionName); 208 } 211 public void actionPerformed(java.awt.event.ActionEvent evt) { 212 213 try{ 214 dObj.setChangedFromUI(true); 215 long time_id=java.lang.System.currentTimeMillis(); 216 WSEjbExt ejbext=dObj.getEjbExt(); 217 int number=ejbext.sizeEjbExtensions()+1; 218 219 220 EjbExtensionsType ejbExtension=new EjbExtensionsType(); 221 ejbExtension.setEnterpriseBean(""); 222 ejbExtension.setXmiName("Extension_"+time_id); 223 ejbExtension.setXmiId("Extension_"+time_id); 224 ejbExtension.setHref(""); 225 226 227 ejbext.addEjbExtensions(ejbExtension); 229 Node extensionNode = new ExtensionNode(); 231 view.getRoot().getChildren().add(new Node[]{extensionNode}); 232 extensionNode.setDisplayName(extensionNode.getDisplayName()+number); 233 dObj.setChangedFromUI(true); 234 dObj.modelUpdatedFromUI(); 235 EjbExtensionsType[] extensions = ejbext.getEjbExtensions(); 236 SectionPanel sectionPanel=new SectionPanel(view,extensionNode,ejbExtension); 237 sectionPanel.setHeaderActions(new javax.swing.Action []{removeExtensionAction}); 238 239 ((WSEjbExtView)view).getEjbExtensionsContainer().addSection(sectionPanel,true); 240 dObj.setChangedFromUI(false); 241 242 } catch (java.io.IOException ex) { 243 } catch (java.lang.IllegalArgumentException ex) { 244 } 245 } 246 } 247 private class RemoveExtensionAction extends javax.swing.AbstractAction { 248 249 RemoveExtensionAction(String actionName) { 250 super(actionName); 251 } 254 255 public void actionPerformed(java.awt.event.ActionEvent evt) { 256 257 SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel(); 258 EjbExtensionsType ejbExtension = (EjbExtensionsType)sectionPanel.getKey(); 259 261 try { 262 dObj.setChangedFromUI(true); 263 dObj.getEjbExt().removeEjbExtensions(ejbExtension); 264 sectionPanel.getSectionView().removeSection(sectionPanel.getNode()); 265 sectionPanel.getSectionView().updateUI(); 266 sectionPanel.updateUI(); 267 268 dObj.modelUpdatedFromUI(); 269 270 } catch (java.io.IOException ec) { 271 272 } finally { 273 dObj.setChangedFromUI(false); 274 } 275 276 } 277 } 278 279 280 public Error validateView() { 281 343 return null; 344 } 345 346 347 public static class WSEjbExtNode extends org.openide.nodes.AbstractNode { 348 WSEjbExtNode(WSEjbExt ejbext) { 349 super(org.openide.nodes.Children.LEAF); 350 setDisplayName("Extended Deployment Information"); 352 } 354 } 355 356 public static class ExtensionNode extends org.openide.nodes.AbstractNode { 357 ExtensionNode() { 358 super(org.openide.nodes.Children.LEAF); 359 setDisplayName("Ejb Extension #"); 360 } 362 } 363 388 } 389 | Popular Tags |