KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > actions > ActionHelper


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * Created on Jul 6, 2005
22  *
23  * To change the template for this generated file go to
24  * Window - Preferences - Java - Code Generation - Code and Comments
25  */

26 package org.netbeans.modules.xml.wsdl.ui.actions;
27
28 import java.beans.PropertyVetoException JavaDoc;
29 import javax.swing.SwingUtilities JavaDoc;
30 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
31 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
32 import org.netbeans.modules.xml.wsdl.ui.cookies.WSDLDefinitionNodeCookie;
33 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.Utils;
34 import org.netbeans.modules.xml.xam.ui.cookies.ViewComponentCookie;
35 import org.openide.explorer.ExplorerManager;
36 import org.openide.filesystems.FileObject;
37 import org.openide.loaders.DataObject;
38 import org.openide.loaders.DataObjectNotFoundException;
39 import org.openide.nodes.Node;
40
41 /**
42  * @author radval
43  *
44  * To change the template for this generated type comment go to
45  * Window - Preferences - Java - Code Generation - Code and Comments
46  */

47 public class ActionHelper {
48
49     /**
50      * Show and select the Node which represents the given component.
51      *
52      * @param comp model component to select.
53      */

54     public static void selectNode(WSDLComponent comp) {
55         DataObject dobj = getDataObject(comp);
56         if (dobj != null) {
57             ViewComponentCookie cookie = (ViewComponentCookie) dobj.getCookie(
58                     ViewComponentCookie.class);
59             if (cookie != null) {
60                 // Do not switch views, use the currently showing view.
61
cookie.view(ViewComponentCookie.View.CURRENT, comp,
62                         (Object JavaDoc[]) null);
63             }
64         }
65     }
66     
67     public static DataObject getDataObject(WSDLComponent comp) {
68         try {
69             WSDLModel model = comp.getModel();
70             if (model != null) {
71                 FileObject fobj = (FileObject) model.getModelSource().
72                         getLookup().lookup(FileObject.class);
73                 if (fobj != null) {
74                     return DataObject.find(fobj);
75                 }
76             }
77         } catch (DataObjectNotFoundException donfe) {
78             // fall through to return null
79
}
80         return null;
81     }
82
83     public static DataObject getDataObject(WSDLModel model) {
84         try {
85             if (model != null) {
86                 FileObject fobj = (FileObject) model.getModelSource().
87                 getLookup().lookup(FileObject.class);
88                 if (fobj != null) {
89                     return DataObject.find(fobj);
90                 }
91             }
92         } catch (DataObjectNotFoundException donfe) {
93             // fall through to return null
94
}
95         return null;
96     }
97 /* public static void selectNode(Component child, Node parent) {
98         if(child != null && parent != null) {
99             Children children = parent.getChildren();
100             Node[] nodes = children.getNodes();
101             if(nodes != null)
102                 for(int i = 0; i < nodes.length; i++) {
103                     Node childNode = nodes[i];
104                     WSDLElementCookie cookie = (WSDLElementCookie) childNode.getCookie(WSDLElementCookie.class);
105                     if(cookie != null && child.equals(cookie.getWSDLComponent())) {
106                         selectNode(childNode);
107                         break;
108                     }
109             }
110         }
111     }*/

112     
113 /* public static void selectNode(Element element, Node parent) {
114         if(element != null && parent != null) {
115             Children children = parent.getChildren();
116             Node[] nodes = children.getNodes();
117             if(nodes != null)
118                 for(int i = 0; i < nodes.length; i++) {
119                     Node childNode = nodes[i];
120                     SchemaElementCookie cookie = (SchemaElementCookie) childNode.getCookie(WSDLElementCookie.class);
121                     if(cookie != null && element.equals(cookie.getElement())) {
122                         selectNode(childNode);
123                         break;
124                     }
125             }
126         }
127     }*/

128     
129     public static void selectNode(final Node node) {
130         if(node == null) {
131             return;
132         }
133         
134         WSDLDefinitionNodeCookie cookie = Utils.getWSDLDefinitionNodeCookie(node);
135         if(cookie != null) {
136             final ExplorerManager manager = cookie.getDefinitionsNode().getExplorerManager();
137             
138             Runnable JavaDoc run = new Runnable JavaDoc() {
139                 public void run() {
140                     if(manager != null) {
141                             try {
142                                 manager.setExploredContextAndSelection(node, new Node[] {node});
143                             } catch(PropertyVetoException JavaDoc ex) {
144                                 //ignore this
145
}
146                         
147                     }
148                 }
149             };
150             SwingUtilities.invokeLater(run);
151         }
152     }
153     
154     public static void selectNode(final Node node, final Node parentNode) {
155         if(node == null) {
156             return;
157         }
158         
159         WSDLDefinitionNodeCookie cookie = Utils.getWSDLDefinitionNodeCookie(node);
160         if(cookie != null) {
161             final ExplorerManager manager = cookie.getDefinitionsNode().getExplorerManager();
162             
163             Runnable JavaDoc run = new Runnable JavaDoc() {
164                 public void run() {
165                     if(manager != null) {
166                             try {
167                                 manager.setExploredContextAndSelection(node, new Node[] {node});
168                             } catch(PropertyVetoException JavaDoc ex) {
169                                 //ignore this
170
}
171                         
172                     }
173                 }
174             };
175             SwingUtilities.invokeLater(run);
176         }
177     }
178
179     public static void selectExploredContext(final Node node) {
180         if(node == null) {
181             return;
182         }
183         WSDLDefinitionNodeCookie cookie = Utils.getWSDLDefinitionNodeCookie(node);
184         if(cookie != null) {
185             final ExplorerManager manager = cookie.getDefinitionsNode().getExplorerManager();
186             
187             Runnable JavaDoc run = new Runnable JavaDoc() {
188                 public void run() {
189                     if(manager != null) {
190                         manager.setExploredContext(node);
191                     }
192                 }
193             };
194             
195             SwingUtilities.invokeLater(run);
196             
197         }
198     }
199 }
200
Popular Tags