KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > webext > WSWebExtToolBarMVElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.websphere6.dd.loaders.webext;
20
21 import java.io.IOException JavaDoc;
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 /**
31  *
32  * @author dlipin
33  */

34 public class WSWebExtToolBarMVElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener JavaDoc{
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 JavaDoc addServletAction, removeServletAction;
42     private static final long serialVersionUID = 76757425329721L;
43     private static final String JavaDoc 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 JavaDoc() {
54             public void run() {
55                 javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
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 JavaDoc lastActive = comp.getLastActive();
68         if (lastActive!=null) {
69             ((SectionView)view).openPanel(lastActive);
70         } else {
71             //((SectionView)view).openPanel("welcome_files"); //NOI18N
72
}
73         view.checkValidity();
74         //dObj.checkParseable();
75
}
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         //view=new WSWebExtView(dObj);
93
comp.setContentView(view);
94         try {
95             view.openPanel(dObj.getWebExt());
96         } catch(java.io.IOException JavaDoc ex){}
97         view.checkValidity();
98     }
99     public void componentOpened() {
100         super.componentOpened();
101         try {
102             dObj.getWebExt().addPropertyChangeListener(this);
103         } catch(IOException JavaDoc ex) {
104             ex=null;
105         }
106     }
107     
108     public void componentClosed() {
109         super.componentClosed();
110         try {
111             dObj.getWebExt().removePropertyChangeListener(this);
112         } catch(IOException JavaDoc ex) {
113             ex=null;
114         }
115     }
116     
117     public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
118         if (!dObj.isChangedFromUI()) {
119             String JavaDoc name = evt.getPropertyName();
120             if ( name.indexOf("WebApplicationExt")>0 ) { //NOI18
121
// repaint view if the wiew is active and something is changed with filters
122
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                 /*
147                 rootChildren.add(new Node[]{
148                     createWebExtAttrNode(),
149                     createResRefNode(),
150                     createEjbRefNode(),
151                     createResEnvRefNode()}
152                 );*/

153             } catch (java.io.IOException JavaDoc 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             // add panels
165
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 JavaDoc[]{addServletAction});
187             
188             // creatings section panels for ResRefs
189
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 JavaDoc[]{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 JavaDoc {
213         
214         AddServletAction(String JavaDoc actionName) {
215             super(actionName);
216             //char mnem = NbBundle.getMessage(PagesMultiViewElement.class,"LBL_addJspPG_mnem").charAt(0);
217
//putValue(MNEMONIC_KEY,new Integer((int)mnem));
218
}
219         public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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                 //rr.setTitle("Binding Item #"+number);
233
webext.addExtendedServlets(es);
234                 //////////////////////////////////
235
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 JavaDoc[]{removeServletAction});
243                 ((WSWebExtView)view).getServletsContainer().addSection(sectionPanel,true);
244                 dObj.setChangedFromUI(false);
245                 
246             } catch (java.io.IOException JavaDoc ex) {
247             } catch (java.lang.IllegalArgumentException JavaDoc ex) {
248             }
249         }
250     }
251     private class RemoveServletAction extends javax.swing.AbstractAction JavaDoc {
252         
253         RemoveServletAction(String JavaDoc actionName) {
254             super(actionName);
255             //char mnem = NbBundle.getMessage(PagesMultiViewElement.class,"LBL_remove_mnem").charAt(0);
256
//putValue(MNEMONIC_KEY,new Integer((int)mnem));
257
}
258         
259         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
260             SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel();
261             ExtendedServletsType servlet = (ExtendedServletsType)sectionPanel.getKey();
262             // removing from data model
263

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 JavaDoc ec) {
274                 
275             } finally {
276                 dObj.setChangedFromUI(false);
277             }
278             
279         }
280     }
281     
282     
283     public Error JavaDoc validateView() {
284         /*try {
285          
286             WSWebExt webext = dObj.getWebExt();
287          
288             ResRefBindingsType[] resrefs = webext.getResRefBindings();
289             if(resrefs==null) {
290                 return null;
291             }
292             for (int i=0;i<resrefs.length;i++) {
293                 String title = resrefs[i].getBindingResourceRef();
294                 if (title==null || title.length()==0) {
295                     Error.ErrorLocation loc = new Error.ErrorLocation(resrefs[i],"title");
296                     return new Error(Error.MISSING_VALUE_MESSAGE, "Title", loc);
297                 }
298                 for (int j=0;j<resrefs.length;j++) {
299                     String tit = resrefs[j].getBindingResourceRef();
300                     if (i!=j && title.equals(tit)) {
301                         Error.ErrorLocation loc = new Error.ErrorLocation(resrefs[i],"title");
302                         return new Error(Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc);
303                     }
304                 }
305             }
306          
307             EjbRefBindingsType[] ejbrefs = webext.getEjbRefBindings();
308             if(ejbrefs==null) {
309                 return null;
310             }
311             for (int i=0;i<ejbrefs.length;i++) {
312                 String title = ejbrefs[i].getBindingEjbRef();
313                 if (title==null || title.length()==0) {
314                     Error.ErrorLocation loc = new Error.ErrorLocation(ejbrefs[i],"title");
315                     return new Error(Error.MISSING_VALUE_MESSAGE, "Title", loc);
316                 }
317                 for (int j=0;j<ejbrefs.length;j++) {
318                     String tit = ejbrefs[j].getBindingEjbRef();
319                     if (i!=j && title.equals(tit)) {
320                         Error.ErrorLocation loc = new Error.ErrorLocation(ejbrefs[i],"title");
321                         return new Error(Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc);
322                     }
323                 }
324             }
325          
326             ResEnvRefBindingsType[] resenvrefs = webext.getResEnvRefBindings();
327             if(resenvrefs==null) {
328                 return null;
329             }
330             for (int i=0;i<resenvrefs.length;i++) {
331                 String title = resenvrefs[i].getBindingResourceEnvRef();
332                 if (title==null || title.length()==0) {
333                     Error.ErrorLocation loc = new Error.ErrorLocation(resenvrefs[i],"title");
334                     return new Error(Error.MISSING_VALUE_MESSAGE, "Title", loc);
335                 }
336                 for (int j=0;j<resenvrefs.length;j++) {
337                     String tit = resenvrefs[j].getBindingResourceEnvRef();
338                     if (i!=j && title.equals(tit)) {
339                         Error.ErrorLocation loc = new Error.ErrorLocation(resenvrefs[i],"title");
340                         return new Error(Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, title, loc);
341                     }
342                 }
343             }
344         } //catch (java.io.IOException ex){}
345          **/

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(webext.getXmiId());
354
setDisplayName("Extended Deployment Information");
355             //setIconBaseWithExtension("org/netbeans/modules/webextmultiview/ws6.gif"); //NOI18N
356
}
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             //setIconBaseWithExtension("org/netbeans/modules/webextmultiview/ws.gif"); //NOI18N
364
}
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             //setIconBaseWithExtension("org/netbeans/modules/webextmultiview/ws.gif"); //NOI18N
371
}
372     }
373 }
374
Popular Tags