1 19 package org.netbeans.modules.j2ee.websphere6.dd.loaders.webext; 20 21 import java.io.IOException ; 22 import org.netbeans.modules.j2ee.websphere6.dd.beans.*; 23 import org.netbeans.modules.j2ee.websphere6.dd.loaders.WSMultiViewDataObject; 24 import org.netbeans.modules.xml.multiview.*; 25 import org.netbeans.modules.xml.multiview.ui.*; 26 import org.openide.nodes.*; 27 import org.openide.util.RequestProcessor; 28 import org.openide.util.NbBundle; 29 import org.netbeans.modules.xml.multiview.Error; 30 34 public class WSWebExtToolBarMVElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener { 35 private ToolBarDesignEditor comp; 36 private SectionView view; 37 private WSWebExtDataObject dObj; 38 private PanelFactory factory; 39 private RequestProcessor.Task repaintingTask; 40 private boolean needInit=true; 41 private javax.swing.Action addServletAction, removeServletAction; 42 private static final long serialVersionUID = 76757425329721L; 43 private static final String WEBEXT_MV_ID= WSMultiViewDataObject.MULTIVIEW_WEBEXT + 44 WSMultiViewDataObject.DD_MULTIVIEW_POSTFIX; 45 public WSWebExtToolBarMVElement(WSWebExtDataObject dObj) { 46 super(dObj); 47 this.dObj=dObj; 48 comp = new ToolBarDesignEditor(); 49 factory=new PanelFactory(comp,dObj); 50 addServletAction = new AddServletAction(NbBundle.getMessage(WSWebExtToolBarMVElement.class,"LBL_AddExtendedServlet")); 51 removeServletAction = new RemoveServletAction(NbBundle.getMessage(WSWebExtToolBarMVElement.class,"LBL_RemoveExtendedServlet")); 52 setVisualEditor(comp); 53 repaintingTask = RequestProcessor.getDefault().create(new Runnable () { 54 public void run() { 55 javax.swing.SwingUtilities.invokeLater(new Runnable () { 56 public void run() { 57 repaintView(); 58 } 59 }); 60 } 61 }); 62 63 } 64 private void repaintView() { 65 view =new WSWebExtView(dObj); 66 comp.setContentView(view); 67 Object lastActive = comp.getLastActive(); 68 if (lastActive!=null) { 69 ((SectionView)view).openPanel(lastActive); 70 } else { 71 } 73 view.checkValidity(); 74 } 76 77 78 79 public SectionView getSectionView() { 80 return view; 81 } 82 public WSWebExtView getWebExtView() { 83 return (WSWebExtView)view; 84 } 85 86 public void componentShowing() { 87 super.componentShowing(); 88 if (needInit) { 89 repaintView(); 90 needInit=false; 91 } 92 comp.setContentView(view); 94 try { 95 view.openPanel(dObj.getWebExt()); 96 } catch(java.io.IOException ex){} 97 view.checkValidity(); 98 } 99 public void componentOpened() { 100 super.componentOpened(); 101 try { 102 dObj.getWebExt().addPropertyChangeListener(this); 103 } catch(IOException ex) { 104 ex=null; 105 } 106 } 107 108 public void componentClosed() { 109 super.componentClosed(); 110 try { 111 dObj.getWebExt().removePropertyChangeListener(this); 112 } catch(IOException ex) { 113 ex=null; 114 } 115 } 116 117 public void propertyChange(java.beans.PropertyChangeEvent evt) { 118 if (!dObj.isChangedFromUI()) { 119 String name = evt.getPropertyName(); 120 if ( name.indexOf("WebApplicationExt")>0 ) { if (WEBEXT_MV_ID.equals(dObj.getSelectedPerspective().preferredID())) { 123 repaintingTask.schedule(100); 124 } else { 125 needInit=true; 126 } 127 } 128 } 129 } 130 131 private class WSWebExtView extends SectionView { 132 private SectionContainer servletsCont; 133 private WSWebExt webext; 134 135 WSWebExtView(WSWebExtDataObject dObj) { 136 super(factory); 137 138 Children rootChildren = new Children.Array(); 139 Node root = new AbstractNode(rootChildren); 140 try { 141 this.webext=dObj.getWebExt(); 142 rootChildren.add(new Node[]{ 143 createWebExtAttrNode(), 144 createServletsNode() 145 }); 146 153 } catch (java.io.IOException ex) { 154 System.out.println("ex="+ex); 155 root.setDisplayName("Invalid WebExt"); 156 } finally { 157 setRoot(root); 158 } 159 } 160 161 162 private Node createWebExtAttrNode() { 163 Node webextNode = new WSWebExtNode(webext); 164 addSection(new SectionPanel(this,webextNode,webext)); 166 return webextNode; 167 } 168 private Node createServletsNode(){ 169 ExtendedServletsType[] servlets = webext.getExtendedServlets(); 170 Children servch = new Children.Array(); 171 Node[] servletNode=null; 172 173 if(servlets!=null && servlets.length>0) { 174 servletNode = new Node[servlets.length]; 175 for (int i=0;i<servlets.length;i++) { 176 servletNode[i] = new ServletsNode(); 177 servletNode[i].setDisplayName("Extended Servlet #"+(i+1)); 178 } 179 servch.add(servletNode); 180 } 181 182 Node servletsNode = new SectionContainerNode(servch); 183 servletsNode.setDisplayName("Extended Servlets"); 184 185 servletsCont = new SectionContainer(this,servletsNode,"Extended Servlets"); 186 servletsCont.setHeaderActions(new javax.swing.Action []{addServletAction}); 187 188 if(servlets!=null) { 190 SectionPanel[] pan = new SectionPanel[servlets.length]; 191 for (int i=0;i<servlets.length;i++) { 192 pan[i] = new SectionPanel(this, servletNode[i], servlets[i]); 193 pan[i].setHeaderActions(new javax.swing.Action []{removeServletAction}); 194 servletsCont.addSection(pan[i]); 195 } 196 } 197 addSection(servletsCont); 198 return servletsNode; 199 } 200 private Node createServletsCacheConfigNode(){ 201 Node servletsCCNode=new ServletsCacheConfigNode(); 202 addSection(new SectionPanel(this,servletsCCNode,webext)); 203 return servletsCCNode; 204 } 205 206 public SectionContainer getServletsContainer() { 207 return servletsCont; 208 } 209 210 } 211 212 private class AddServletAction extends javax.swing.AbstractAction { 213 214 AddServletAction(String actionName) { 215 super(actionName); 216 } 219 public void actionPerformed(java.awt.event.ActionEvent evt) { 220 try{ 221 dObj.setChangedFromUI(true); 222 WSWebExt webext=dObj.getWebExt(); 223 ExtendedServletsType es=new ExtendedServletsType(); 224 es.setDefaults(); 225 int number=webext.getExtendedServlets().length+1; 226 long time_id=java.lang.System.currentTimeMillis(); 227 228 es.setExtendedServlet(""); 229 es.setXmiId("ServletExtension_"+time_id); 230 es.setHref(""); 231 232 webext.addExtendedServlets(es); 234 Node servletNode = new ServletsNode(); 236 view.getRoot().getChildren().add(new Node[]{servletNode}); 237 servletNode.setDisplayName(servletNode.getDisplayName()+number); 238 239 dObj.modelUpdatedFromUI(); 240 ExtendedServletsType[] servlets = webext.getExtendedServlets(); 241 SectionPanel sectionPanel=new SectionPanel(view,servletNode,es); 242 sectionPanel.setHeaderActions(new javax.swing.Action []{removeServletAction}); 243 ((WSWebExtView)view).getServletsContainer().addSection(sectionPanel,true); 244 dObj.setChangedFromUI(false); 245 246 } catch (java.io.IOException ex) { 247 } catch (java.lang.IllegalArgumentException ex) { 248 } 249 } 250 } 251 private class RemoveServletAction extends javax.swing.AbstractAction { 252 253 RemoveServletAction(String actionName) { 254 super(actionName); 255 } 258 259 public void actionPerformed(java.awt.event.ActionEvent evt) { 260 SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel(); 261 ExtendedServletsType servlet = (ExtendedServletsType)sectionPanel.getKey(); 262 264 try { 265 dObj.setChangedFromUI(true); 266 dObj.getWebExt().removeExtendedServlets(servlet); 267 sectionPanel.getSectionView().removeSection(sectionPanel.getNode()); 268 sectionPanel.getSectionView().updateUI(); 269 sectionPanel.updateUI(); 270 271 dObj.modelUpdatedFromUI(); 272 273 } catch (java.io.IOException ec) { 274 275 } finally { 276 dObj.setChangedFromUI(false); 277 } 278 279 } 280 } 281 282 283 public Error validateView() { 284 346 return null; 347 } 348 349 350 public static class WSWebExtNode extends org.openide.nodes.AbstractNode { 351 WSWebExtNode(WSWebExt webext) { 352 super(org.openide.nodes.Children.LEAF); 353 setDisplayName("Extended Deployment Information"); 355 } 357 } 358 359 public static class ServletsNode extends org.openide.nodes.AbstractNode { 360 ServletsNode() { 361 super(org.openide.nodes.Children.LEAF); 362 setDisplayName("Extended Servlet #"); 363 } 365 } 366 public static class ServletsCacheConfigNode extends org.openide.nodes.AbstractNode { 367 ServletsCacheConfigNode() { 368 super(org.openide.nodes.Children.LEAF); 369 setDisplayName("Servlet Cache Configs"); 370 } 372 } 373 } 374 | Popular Tags |