KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > ejbbnd > WSEjbBndToolBarMVElement


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.ejbbnd;
20
21 import java.io.IOException JavaDoc;
22 import org.netbeans.modules.j2ee.websphere6.dd.beans.EjbBindingsType;
23 import org.netbeans.modules.j2ee.websphere6.dd.beans.WSEjbBnd;
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 /**
32  *
33  * @author dlipin
34  */

35 public class WSEjbBndToolBarMVElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener JavaDoc{
36     private ToolBarDesignEditor comp;
37     private SectionView view;
38     private WSEjbBndDataObject dObj;
39     private PanelFactory factory;
40     private RequestProcessor.Task repaintingTask;
41     private boolean needInit=true;
42     private javax.swing.Action JavaDoc addBindingAction, removeBindingAction;
43     private static final long serialVersionUID = 76737428339792L;
44     private static final String JavaDoc EJBBND_MV_ID = WSMultiViewDataObject.MULTIVIEW_EJBBND +
45             WSMultiViewDataObject.DD_MULTIVIEW_POSTFIX;
46     
47     public WSEjbBndToolBarMVElement(WSEjbBndDataObject dObj) {
48         super(dObj);
49         this.dObj=dObj;
50         comp = new ToolBarDesignEditor();
51         factory=new PanelFactory(comp,dObj);
52         
53         addBindingAction = new AddBindingAction(NbBundle.getMessage(WSEjbBndToolBarMVElement.class,"LBL_addEjbBinding"));
54         removeBindingAction = new RemoveBindingAction(NbBundle.getMessage(WSEjbBndToolBarMVElement.class,"LBL_removeEjbBinding"));
55         
56         setVisualEditor(comp);
57         repaintingTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
58             public void run() {
59                 javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
60                     public void run() {
61                         repaintView();
62                     }
63                 });
64             }
65         });
66     }
67     
68     private void repaintView() {
69         view =new WSEjbBndView(dObj);
70         comp.setContentView(view);
71         Object JavaDoc lastActive = comp.getLastActive();
72         if (lastActive!=null) {
73             ((SectionView)view).openPanel(lastActive);
74         } else {
75             //((SectionView)view).openPanel("welcome_files"); //NOI18N
76
}
77         view.checkValidity();
78         //dObj.checkParseable();
79
}
80     
81     
82     
83     public SectionView getSectionView() {
84         return view;
85     }
86     public WSEjbBndView getEjbBndView() {
87         return (WSEjbBndView)view;
88     }
89     
90     public void componentShowing() {
91         super.componentShowing();
92         if (needInit) {
93             repaintView();
94             needInit=false;
95         }
96         //view=new WSEjbBndView(dObj);
97
comp.setContentView(view);
98         try {
99             ((SectionView)view).openPanel(dObj.getEjbBnd());
100         } catch(java.io.IOException JavaDoc e) {
101         }
102         view.checkValidity();
103     }
104     
105     public void componentOpened() {
106         super.componentOpened();
107         try {
108             dObj.getEjbBnd().addPropertyChangeListener(this);
109         } catch(IOException JavaDoc ex) {
110             ex=null;
111         }
112     }
113     
114     public void componentClosed() {
115         super.componentClosed();
116         try {
117             dObj.getEjbBnd().removePropertyChangeListener(this);
118         } catch(IOException JavaDoc ex) {
119             ex=null;
120         }
121     }
122     
123     public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
124         if (!dObj.isChangedFromUI()) {
125             String JavaDoc name = evt.getPropertyName();
126             if ( name.indexOf("EjbJarBnd")>0 ) { //NOI18
127
// repaint view if the wiew is active and something is changed with filters
128
if (EJBBND_MV_ID.equals(dObj.getSelectedPerspective().preferredID())) {
129                     repaintingTask.schedule(100);
130                 } else {
131                     needInit=true;
132                 }
133             }
134         }
135     }
136     
137     private class WSEjbBndView extends SectionView {
138         private SectionContainer bindingsCont;
139         private WSEjbBnd ejbbnd;
140         WSEjbBndView(WSEjbBndDataObject dObj) {
141             super(factory);
142             
143             Children rootChildren = new Children.Array();
144             Node root = new AbstractNode(rootChildren);
145             try {
146                 this.ejbbnd=dObj.getEjbBnd();
147                 rootChildren.add(new Node[]{
148                     createEjbBndAttrNode(),
149                     createEjbBindingsNode()
150                 });
151             } catch (java.io.IOException JavaDoc ex) {
152                 System.out.println("ex="+ex);
153                 root.setDisplayName("Invalid EjbBnd");
154             } finally {
155                 setRoot(root);
156             }
157             
158         }
159         
160         
161         public SectionContainer getEjbBindingsContainer() {
162             return bindingsCont;
163         }
164         
165         private Node createEjbBndAttrNode() {
166             Node ejbbndNode = new WSEjbBndNode(dObj);
167             // add panels
168
addSection(new SectionPanel(this,ejbbndNode,ejbbnd));
169             return ejbbndNode;
170         }
171         private Node createEjbBindingsNode() {
172             
173             EjbBindingsType[] bindings = ejbbnd.getEjbBindings();
174             Children extch = new Children.Array();
175             Node[] bindingNodes=null;
176             
177             if(bindings!=null && bindings.length>0) {
178                 bindingNodes = new Node[bindings.length];
179                 for (int i=0;i<bindings.length;i++) {
180                     bindingNodes[i] = new BindingNode();
181                     bindingNodes[i].setDisplayName("Ejb Binding #"+(i+1));
182                 }
183                 extch.add(bindingNodes);
184             }
185             
186             Node bindingsNode = new SectionContainerNode(extch);
187             bindingsNode.setDisplayName("Ejb Bindings");
188             
189             
190             bindingsCont = new SectionContainer(this,bindingsNode,"Ejb Bindings");
191             bindingsCont.setHeaderActions(new javax.swing.Action JavaDoc[]{addBindingAction});
192             
193             
194             // creatings section panels for ResRefs
195
if(bindings!=null) {
196                 SectionPanel[] pan = new SectionPanel[bindings.length];
197                 
198                 for (int i=0;i<bindings.length;i++) {
199                     pan[i] = new SectionPanel(this, bindingNodes[i], bindings[i]);
200                     pan[i].setHeaderActions(new javax.swing.Action JavaDoc[]{removeBindingAction});
201                     bindingsCont.addSection(pan[i]);
202                 }
203             }
204             addSection(bindingsCont);
205             
206             return bindingsNode;
207         }
208         
209     }
210     
211     private class AddBindingAction extends javax.swing.AbstractAction JavaDoc {
212         
213         AddBindingAction(String JavaDoc actionName) {
214             super(actionName);
215             //char mnem = NbBundle.getMessage(PagesMultiViewElement.class,"LBL_addJspPG_mnem").charAt(0);
216
//putValue(MNEMONIC_KEY,new Integer((int)mnem));
217
}
218         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
219             
220             try{
221                 dObj.setChangedFromUI(true);
222                 long time_id=java.lang.System.currentTimeMillis();
223                 WSEjbBnd ejbbnd=dObj.getEjbBnd();
224                 int number=ejbbnd.sizeEjbBindings()+1;
225                 
226                 
227                 EjbBindingsType ejbBinding=new EjbBindingsType();
228                 ejbBinding.setEnterpriseBean("");
229                 
230                 ejbBinding.setJndiName("Binding_"+time_id);
231                 ejbBinding.setXmiId("Binding_"+time_id);
232                 ejbBinding.setHref("EnterpriseBean_"+time_id);
233                 
234                 
235                 //rr.setTitle("Binding Item #"+number);
236
ejbbnd.addEjbBindings(ejbBinding);
237                 //////////////////////////////////
238
Node bindingNode = new BindingNode();
239                 view.getRoot().getChildren().add(new Node[]{bindingNode});
240                 bindingNode.setDisplayName(bindingNode.getDisplayName()+number);
241                 dObj.setChangedFromUI(true);
242                 dObj.modelUpdatedFromUI();
243                 //EjbBindingsType[] bindings = ejbbnd.getEjbBindings();
244
SectionPanel sectionPanel=new SectionPanel(view,bindingNode,ejbBinding);
245                 sectionPanel.setHeaderActions(new javax.swing.Action JavaDoc[]{removeBindingAction});
246                 
247                 ((WSEjbBndView)view).getEjbBindingsContainer().addSection(sectionPanel,true);
248                 dObj.setChangedFromUI(false);
249                 
250             } catch (java.io.IOException JavaDoc ex) {
251             } catch (java.lang.IllegalArgumentException JavaDoc ex) {
252             }
253         }
254     }
255     private class RemoveBindingAction extends javax.swing.AbstractAction JavaDoc {
256         
257         RemoveBindingAction(String JavaDoc actionName) {
258             super(actionName);
259             //char mnem = NbBundle.getMessage(PagesMultiViewElement.class,"LBL_remove_mnem").charAt(0);
260
//putValue(MNEMONIC_KEY,new Integer((int)mnem));
261
}
262         
263         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
264             
265             SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel();
266             EjbBindingsType ejbBinding = (EjbBindingsType)sectionPanel.getKey();
267             // removing from data model
268

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

351         return null;
352     }
353     
354     
355     public static class WSEjbBndNode extends org.openide.nodes.AbstractNode {
356         WSEjbBndNode(WSEjbBndDataObject ejbbnd) {
357             super(org.openide.nodes.Children.LEAF);
358             //setDisplayName(ejbbnd.getXmiId());
359
setDisplayName("Binding Deployment Information");
360             //setIconBaseWithExtension("org/netbeans/modules/ejbbndmultiview/ws6.gif"); //NOI18N
361
}
362     }
363     
364     public static class BindingNode extends org.openide.nodes.AbstractNode {
365         
366         public BindingNode() {
367             super(org.openide.nodes.Children.LEAF);
368             setDisplayName("Ejb Binding #");
369             //setIconBaseWithExtension("org/netbeans/modules/ejbbndmultiview/ws.gif"); //NOI18N
370

371         }
372     }
373     
374     /*
375      *
376     public static class ServletsCacheConfigNode extends org.openide.nodes.AbstractNode {
377         ServletsCacheConfigNode() {
378             super(org.openide.nodes.Children.LEAF);
379             setDisplayName("Servlet Cache Configs");
380             //setIconBaseWithExtension("org/netbeans/modules/ejbbndmultiview/ws.gif"); //NOI18N
381         }
382     }
383      
384     public static class EjbRefNode extends org.openide.nodes.AbstractNode {
385         EjbRefNode() {
386             super(org.openide.nodes.Children.LEAF);
387             setDisplayName("Binding Item #");
388             //setIconBaseWithExtension("org/netbeans/modules/ejbbndmultiview/ws.gif"); //NOI18N
389         }
390      
391     }
392      
393     public static class ResEnvRefNode extends org.openide.nodes.AbstractNode {
394         ResEnvRefNode() {
395             super(org.openide.nodes.Children.LEAF);
396             setDisplayName("Binding Item #");
397             //setIconBaseWithExtension("org/netbeans/modules/ejbbndmultiview/ws.gif"); //NOI18N
398         }
399     }*/

400 }
401
Popular Tags