KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > loaders > appbnd > WSAppBndToolBarMVElement


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.appbnd;
20
21 import java.io.IOException JavaDoc;
22 import org.netbeans.modules.j2ee.websphere6.dd.beans.AuthorizationsType;
23 import org.netbeans.modules.j2ee.websphere6.dd.beans.WSAppBnd;
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 WSAppBndToolBarMVElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener JavaDoc{
36     private ToolBarDesignEditor comp;
37     private SectionView view;
38     private WSAppBndDataObject dObj;
39     private PanelFactory factory;
40     private RequestProcessor.Task repaintingTask;
41     private boolean needInit=true;
42     private static final long serialVersionUID = 76117428339792L;
43     
44     private javax.swing.Action JavaDoc addAuthorizationAction, removeAuthorizationAction;
45     private static final String JavaDoc APPBND_MV_ID = WSMultiViewDataObject.MULTIVIEW_APPBND +
46             WSMultiViewDataObject.DD_MULTIVIEW_POSTFIX;
47     public WSAppBndToolBarMVElement(WSAppBndDataObject dObj) {
48         super(dObj);
49         this.dObj=dObj;
50         comp = new ToolBarDesignEditor();
51         factory=new PanelFactory(comp,dObj);
52         
53         addAuthorizationAction = new AddAuthorizationAction(NbBundle.getMessage(WSAppBndToolBarMVElement.class,"LBL_addAuthorization"));
54         removeAuthorizationAction = new RemoveAuthorizationAction(NbBundle.getMessage(WSAppBndToolBarMVElement.class,"LBL_removeAuthorization"));
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 WSAppBndView(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 WSAppBndView getAppBndView() {
87         return (WSAppBndView)view;
88     }
89     
90     public void componentShowing() {
91         super.componentShowing();
92         if (needInit) {
93             repaintView();
94             needInit=false;
95         }
96         //view=new WSAppBndView(dObj);
97
comp.setContentView(view);
98         try {
99             ((SectionView)view).openPanel(dObj.getAppBnd());
100         } catch(java.io.IOException JavaDoc e) {
101         }
102         view.checkValidity();
103     }
104     
105      public void componentOpened() {
106         super.componentOpened();
107         try {
108             dObj.getAppBnd().addPropertyChangeListener(this);
109         } catch(IOException JavaDoc ex) {
110             ex=null;
111         }
112     }
113     
114     public void componentClosed() {
115         super.componentClosed();
116         try {
117             dObj.getAppBnd().removePropertyChangeListener(this);
118         } catch(IOException JavaDoc ex) {
119             ex=null;
120         }
121     }
122     public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
123         if (!dObj.isChangedFromUI()) {
124             String JavaDoc name = evt.getPropertyName();
125             if ( name.indexOf("ApplicationBnd")>0 ) { //NOI18
126
// repaint view if the wiew is active and something is changed with filters
127
if (APPBND_MV_ID.equals(dObj.getSelectedPerspective().preferredID())) {
128                     repaintingTask.schedule(100);
129                 } else {
130                     needInit=true;
131                 }
132             }
133         }
134     }
135     
136     private class WSAppBndView extends SectionView {
137         private SectionContainer bindingsCont;
138         private WSAppBnd appbnd;
139         private SectionContainer authorizationsCont;
140         
141         WSAppBndView(WSAppBndDataObject dObj) {
142             super(factory);
143             
144             Children rootChildren = new Children.Array();
145             Node root = new AbstractNode(rootChildren);
146             try {
147                 this.appbnd=dObj.getAppBnd();
148                 rootChildren.add(new Node[]{
149                     createAppBndAttrNode(),
150                     createAppAuthorizationsNode()
151                 });
152             } catch (java.io.IOException JavaDoc ex) {
153                 System.out.println("ex="+ex);
154                 root.setDisplayName("Invalid AppBnd");
155             } finally {
156                 setRoot(root);
157             }
158             
159         }
160         
161         
162         public SectionContainer getAuthorizationsContainer() {
163             return authorizationsCont;
164         }
165         
166         private Node createAppBndAttrNode() {
167             Node appbndNode = new WSAppBndNode(dObj);
168             // add panels
169
addSection(new SectionPanel(this,appbndNode,appbnd));
170             return appbndNode;
171         }
172         
173         private Node createAppAuthorizationsNode() {
174             
175             AuthorizationsType[] authorizations = appbnd.getAuthorizationTable().getAuthorizations();
176             Children extch = new Children.Array();
177             Node[] authorizationNodes=null;
178             
179             if(authorizations!=null && authorizations.length>0) {
180                 authorizationNodes = new Node[authorizations.length];
181                 for (int i=0;i<authorizations.length;i++) {
182                     authorizationNodes[i] = new AuthorizationNode();
183                     authorizationNodes[i].setDisplayName("Authorization #"+(i+1));
184                 }
185                 extch.add(authorizationNodes);
186             }
187             
188             Node authorizationsNode = new SectionContainerNode(extch);
189             authorizationsNode.setDisplayName("Authorizations");
190             
191             
192             authorizationsCont = new SectionContainer(this,authorizationsNode,"Authorizations");
193             authorizationsCont.setHeaderActions(new javax.swing.Action JavaDoc[]{addAuthorizationAction});
194             
195             
196             // creatings section panels for ResRefs
197
if(authorizations!=null) {
198                 SectionPanel[] pan = new SectionPanel[authorizations.length];
199                 
200                 for (int i=0;i<authorizations.length;i++) {
201                     pan[i] = new SectionPanel(this, authorizationNodes[i], authorizations[i]);
202                     pan[i].setHeaderActions(new javax.swing.Action JavaDoc[]{removeAuthorizationAction});
203                     authorizationsCont.addSection(pan[i]);
204                 }
205             }
206             addSection(authorizationsCont);
207             
208             return authorizationsNode;
209         }
210     }
211     
212     private class AddAuthorizationAction extends javax.swing.AbstractAction JavaDoc {
213         
214         AddAuthorizationAction(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             
221             try{
222                 dObj.setChangedFromUI(true);
223                 long time_id=java.lang.System.currentTimeMillis();
224                 WSAppBnd appbnd=dObj.getAppBnd();
225                 int number=appbnd.getAuthorizationTable().sizeAuthorizations()+1;
226                 AuthorizationsType appAuthorization=new AuthorizationsType();
227                 appAuthorization.setDefaults();
228                 appbnd.getAuthorizationTable().addAuthorization(appAuthorization);
229
230                 
231                 Node authorizationNode = new AuthorizationNode();
232                 view.getRoot().getChildren().add(new Node[]{authorizationNode});
233                 authorizationNode.setDisplayName(authorizationNode.getDisplayName()+number);
234                 dObj.setChangedFromUI(true);
235                 dObj.modelUpdatedFromUI();
236                 //AppAuthorizationsType[] authorizations = appbnd.getAppAuthorizations();
237
SectionPanel sectionPanel=new SectionPanel(view,authorizationNode,appAuthorization);
238                 sectionPanel.setHeaderActions(new javax.swing.Action JavaDoc[]{removeAuthorizationAction});
239                 
240                 ((WSAppBndView)view).getAuthorizationsContainer().addSection(sectionPanel,true);
241                 dObj.setChangedFromUI(false);
242                 
243             } catch (java.io.IOException JavaDoc ex) {
244             } catch (java.lang.IllegalArgumentException JavaDoc ex) {
245             }
246         }
247     }
248     private class RemoveAuthorizationAction extends javax.swing.AbstractAction JavaDoc {
249         
250         RemoveAuthorizationAction(String JavaDoc actionName) {
251             super(actionName);
252             //char mnem = NbBundle.getMessage(PagesMultiViewElement.class,"LBL_remove_mnem").charAt(0);
253
//putValue(MNEMONIC_KEY,new Integer((int)mnem));
254
}
255         
256         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
257             
258             SectionPanel sectionPanel = ((SectionPanel.HeaderButton)evt.getSource()).getSectionPanel();
259             AuthorizationsType appAuthorization = (AuthorizationsType) sectionPanel.getKey();
260             // removing from data model
261

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

344         return null;
345     }
346     
347     
348     public static class WSAppBndNode extends org.openide.nodes.AbstractNode {
349         WSAppBndNode(WSAppBndDataObject appbnd) {
350             super(org.openide.nodes.Children.LEAF);
351             //setDisplayName(appbnd.getXmiId());
352
setDisplayName("Binding Deployment Information");
353             //setIconBaseWithExtension("org/netbeans/modules/appbndmultiview/ws6.gif"); //NOI18N
354
}
355     }
356     
357     public static class AuthorizationNode extends org.openide.nodes.AbstractNode {
358         
359         public AuthorizationNode() {
360             super(org.openide.nodes.Children.LEAF);
361             setDisplayName("Authorization #");
362             //setIconBaseWithExtension("org/netbeans/modules/ejbbndmultiview/ws.gif"); //NOI18N
363

364         }
365     }
366 }
367
Popular Tags