KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > ejbext > WSEjbExtToolBarMVElement


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.ejbext;
20
21 import java.io.IOException JavaDoc;
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 /**
32  *
33  * @author dlipin
34  */

35 public class WSEjbExtToolBarMVElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener JavaDoc{
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 JavaDoc addExtensionAction, removeExtensionAction;
43     private static final long serialVersionUID = 76737428339792L;
44     private static final String JavaDoc 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 JavaDoc() {
57             public void run() {
58                 javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
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 JavaDoc lastActive = comp.getLastActive();
71         if (lastActive!=null) {
72             ((SectionView)view).openPanel(lastActive);
73         } else {
74             //((SectionView)view).openPanel("welcome_files"); //NOI18N
75
}
76         view.checkValidity();
77         //dObj.checkParseable();
78
}
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         //view=new WSEjbExtView(dObj);
96
comp.setContentView(view);
97         try {
98             view.openPanel(dObj.getEjbExt());
99         } catch(java.io.IOException JavaDoc ex){}
100         view.checkValidity();
101     }
102     
103     public void componentOpened() {
104         super.componentOpened();
105         try {
106             dObj.getEjbExt().addPropertyChangeListener(this);
107         } catch(IOException JavaDoc ex) {
108             ex=null;
109         }
110     }
111     
112     public void componentClosed() {
113         super.componentClosed();
114         try {
115             dObj.getEjbExt().removePropertyChangeListener(this);
116         } catch(IOException JavaDoc ex) {
117             ex=null;
118         }
119     }
120     
121     public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
122         if (!dObj.isChangedFromUI()) {
123             String JavaDoc name = evt.getPropertyName();
124             if ( name.indexOf("EjbJarExt")>0 ) { //NOI18
125
// repaint view if the wiew is active and something is changed with filters
126
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 JavaDoc 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             // add panels
164
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 JavaDoc[]{addExtensionAction});
188             
189             // creatings section panels for ResRefs
190
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 JavaDoc[]{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 JavaDoc {
205         
206         AddExtensionAction(String JavaDoc actionName) {
207             super(actionName);
208             //char mnem = NbBundle.getMessage(PagesMultiViewElement.class,"LBL_addJspPG_mnem").charAt(0);
209
//putValue(MNEMONIC_KEY,new Integer((int)mnem));
210
}
211         public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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                 //rr.setTitle("Binding Item #"+number);
228
ejbext.addEjbExtensions(ejbExtension);
229                 //////////////////////////////////
230
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 JavaDoc[]{removeExtensionAction});
238                 
239                 ((WSEjbExtView)view).getEjbExtensionsContainer().addSection(sectionPanel,true);
240                 dObj.setChangedFromUI(false);
241                 
242             } catch (java.io.IOException JavaDoc ex) {
243             } catch (java.lang.IllegalArgumentException JavaDoc ex) {
244             }
245         }
246     }
247     private class RemoveExtensionAction extends javax.swing.AbstractAction JavaDoc {
248         
249         RemoveExtensionAction(String JavaDoc actionName) {
250             super(actionName);
251             //char mnem = NbBundle.getMessage(PagesMultiViewElement.class,"LBL_remove_mnem").charAt(0);
252
//putValue(MNEMONIC_KEY,new Integer((int)mnem));
253
}
254         
255         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
256             
257             SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel();
258             EjbExtensionsType ejbExtension = (EjbExtensionsType)sectionPanel.getKey();
259             // removing from data model
260

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

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(ejbext.getXmiId());
351
setDisplayName("Extended Deployment Information");
352             //setIconBaseWithExtension("org/netbeans/modules/ejbextmultiview/ws6.gif"); //NOI18N
353
}
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             //setIconBaseWithExtension("org/netbeans/modules/ejbextmultiview/ws.gif"); //NOI18N
361
}
362     }
363     /*
364     public static class ServletsCacheConfigNode extends org.openide.nodes.AbstractNode {
365         ServletsCacheConfigNode() {
366             super(org.openide.nodes.Children.LEAF);
367             setDisplayName("Servlet Cache Configs");
368             //setIconBaseWithExtension("org/netbeans/modules/ejbextmultiview/ws.gif"); //NOI18N
369         }
370     }
371      
372     public static class EjbRefNode extends org.openide.nodes.AbstractNode {
373         EjbRefNode() {
374             super(org.openide.nodes.Children.LEAF);
375             setDisplayName("Binding Item #");
376             //setIconBaseWithExtension("org/netbeans/modules/ejbextmultiview/ws.gif"); //NOI18N
377         }
378      
379     }
380      
381     public static class ResEnvRefNode extends org.openide.nodes.AbstractNode {
382         ResEnvRefNode() {
383             super(org.openide.nodes.Children.LEAF);
384             setDisplayName("Binding Item #");
385             //setIconBaseWithExtension("org/netbeans/modules/ejbextmultiview/ws.gif"); //NOI18N
386         }
387     }*/

388 }
389
Popular Tags