KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > refactoring > WSDLUIHelper


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 package org.netbeans.modules.xml.wsdl.refactoring;
21
22 import java.awt.Image JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.swing.Action JavaDoc;
27 import org.netbeans.modules.xml.refactoring.RefactoringManager;
28
29 import org.netbeans.modules.xml.refactoring.spi.UIHelper;
30 import org.netbeans.modules.xml.schema.model.SchemaComponent;
31 import org.netbeans.modules.xml.schema.model.SchemaModel;
32 import org.netbeans.modules.xml.wsdl.model.Definitions;
33 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
34 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
35 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.WSDLDataObject;
36 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.NodesFactory;
37 import org.netbeans.modules.xml.xam.Component;
38 import org.netbeans.modules.xml.xam.Model;
39 import org.netbeans.modules.xml.xam.ModelSource;
40 import org.netbeans.modules.xml.xam.dom.DocumentModel;
41 import org.netbeans.modules.xml.xam.ui.actions.GoToAction;
42 import org.openide.filesystems.FileObject;
43 import org.openide.loaders.DataObject;
44 import org.openide.nodes.AbstractNode;
45 import org.openide.nodes.Children;
46 import org.openide.nodes.FilterNode;
47 import org.openide.nodes.Node;
48 import org.openide.util.actions.SystemAction;
49
50 /**
51  *
52  * @author Jeri Lockhart
53  */

54 public class WSDLUIHelper extends UIHelper{
55     
56     private static final SystemAction[] ACTIONS =
57         new SystemAction[] {
58             SystemAction.get(GoToAction.class)
59         };
60     
61     private WSDLHelperNode displayNode;
62     
63     /**
64      * Creates a new instance of WSDLUIHelper
65      */

66     public WSDLUIHelper() {
67         super();
68     }
69
70   /**
71      * Return UI relevant path from root. Specific implementation should
72      * override.
73      */

74     @Override JavaDoc
75     public List JavaDoc<Component> getRelevantPathFromRoot(Component component) {
76         ArrayList JavaDoc<Component> pathFromRoot = new ArrayList JavaDoc<Component>();
77         Component dc = component;
78         pathFromRoot.add(dc);
79         while (dc.getParent() != null) {
80             dc = dc.getParent();
81             if(!(dc instanceof Definitions)) {
82                 pathFromRoot.add(0, dc);
83             }
84             
85         }
86         return pathFromRoot;
87     }
88     /**
89      * Returns specific node for displaying the component in a preview window.
90      *
91      * The Node should return the following information that will be used
92      * in the refactoring UI:
93      *
94      * getActions(boolean) -
95      * other Actions for the Component, preferably navigational actions
96      * Minimally, getActions() should return a Go To Source Action, which
97      * will open the source (text) view with the cursor at the Component line
98      * The Actions should also implement org.openide.util.actions.Presenter.
99      * When the action is invoked from a prefuse graph node,
100      * actionPerformed(ActionEvent) is called with the Component as the source
101      * in the ActionEvent.
102      *
103      * getDisplayName() -
104      * a String that will be used as the label on the Component's explorer and
105      * graph nodes.
106      *
107      * getHtmlDisplayName() -
108      * For the usage component, a one line code snippet with the name
109      * of the query component bolded. The Html display name is used in the
110      * Find Usages explorer and the refactoring preview explorer on the
111      * usage node.
112      * The string should be formatted to use &lt and &gt for
113      * the XML tags, and < and > for the HTML tags. In the following example,
114      * Find Usages was run on a schema global type named "POSLogCurrencyCode".
115      * The Node represents a schema local element that uses POSLogCurrencyCode.
116      * getHtmlDisplayName() returns the first line of the local element.
117      * The text "POSLogCurrencyCode" in the snippet will be bolded because it is
118      * the name of the query Component.
119      *
120      * &lt;xs:element name="CurrencyCode" type="<b>POSLogCurrencyCode</b>" minOccurs="0"/&gt;
121      *
122      * getIcon() -
123      * an Image for the icon on the Components explorer and graph nodes.
124      *
125      * getPreferredAction() -
126      * the Action which navigates to the primary view of the Component
127      */

128     @Override JavaDoc
129     public Node getDisplayNode(Component component) {
130         if (! (component instanceof WSDLComponent) &&
131             ! (component instanceof SchemaComponent))
132         {
133             return super.getDisplayNode(component);
134         }
135         
136         if (component instanceof SchemaComponent) {
137             SchemaComponent sc = (SchemaComponent) component;
138             SchemaModel sm = sc.getModel();
139             assert sm != null : "Given a dead component";
140             UIHelper delegate = RefactoringManager.getInstance().getTargetComponentUIHelper(sm);
141             if (delegate != null) {
142                 return delegate.getDisplayNode(component);
143             } else {
144                 return super.getDisplayNode(component);
145             }
146         }
147         
148         Model model = component.getModel();
149         try {
150         if(model instanceof WSDLModel) {
151             ModelSource ms = model.getModelSource();
152             FileObject fo = (FileObject) ms.getLookup().lookup(FileObject.class);
153             if(fo != null) {
154                 DataObject dObj = DataObject.find(fo);
155                 if(dObj != null && dObj instanceof WSDLDataObject) {
156                     Node node = NodesFactory.getInstance().create(component);
157                     if(node != null) {
158                         Node filterNode = new FilterNode(node) {
159                              @Override JavaDoc
160                             public SystemAction[] getActions(boolean val) {
161                                 return ACTIONS;
162                              }
163                              
164                              @Override JavaDoc
165                             public Action JavaDoc getPreferredAction() {
166                                   return ACTIONS[0];
167                              }
168                         };
169                         
170                         return filterNode;
171                     }
172                 }
173             }
174         }
175         } catch(Exception JavaDoc ex) {
176             ex.printStackTrace();
177         }
178         
179          if (displayNode == null){
180             displayNode = new WSDLHelperNode(component);
181         }
182         
183         return displayNode;
184     }
185     
186     @Override JavaDoc
187     public Node getDisplayNode(Model model) {
188         if (model instanceof DocumentModel) {
189             return getDisplayNode(((DocumentModel)model).getRootComponent());
190         } else {
191             return super.getDisplayNode(model);
192         }
193     }
194     
195    public class WSDLHelperNode extends AbstractNode {
196        private Component comp;
197               
198        public WSDLHelperNode(Component component){
199            super(Children.LEAF);
200            this.comp = component;
201            initialize();
202        }
203        
204        public void initialize() {
205             this.setName("Temporary Name"); // Name
206
}
207        
208         @Override JavaDoc
209         public Image JavaDoc getIcon(int i) {
210             return super.getIcon(i);
211         }
212
213         /**
214          * XML code snippet
215          *
216          */

217         @Override JavaDoc
218         public String JavaDoc getHtmlDisplayName() {
219             return "Temporary <b>Name</b>";
220         }
221
222         @Override JavaDoc
223         public Action JavaDoc[] getActions(boolean b) {
224             return null;
225         }
226
227         @Override JavaDoc
228         public Action JavaDoc getPreferredAction() {
229             return null;
230         }
231         
232        
233    }
234   
235    
236    
237     
238 }
239
Popular Tags