KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > spi > UIHelper


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 package org.netbeans.modules.xml.refactoring.spi;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23 import org.netbeans.modules.xml.refactoring.Usage;
24 import org.netbeans.modules.xml.xam.Component;
25 import org.netbeans.modules.xml.xam.Model;
26 import org.netbeans.modules.xml.xam.Named;
27 import org.openide.filesystems.FileObject;
28 import org.openide.nodes.AbstractNode;
29 import org.openide.nodes.Children;
30 import org.openide.nodes.Node;
31
32 /**
33  * Default UI Helper.
34  *
35  * @author Nam Nguyen
36  */

37 public class UIHelper {
38
39     /**
40      * Returns specific node for displaying the component in a preview window.
41      *
42      * The Node should return the following information that will be used
43      * in the refactoring UI:
44      *
45      * getActions(boolean) -
46      * other Actions for the Component, preferably navigational actions
47      * Minimally, getActions() should return a Go To Source Action, which
48      * will open the source (text) view with the cursor at the Component line
49      * The Actions should also implement org.openide.util.actions.Presenter.
50      * When the action is invoked from a prefuse graph node,
51      * actionPerformed(ActionEvent) is called with the Component as the source
52      * in the ActionEvent.
53      *
54      * getDisplayName() -
55      * a String that will be used as the label on the Component's explorer and
56      * graph nodes.
57      *
58      * getHtmlDisplayName() -
59      * For the usage component, a one line code snippet with the name
60      * of the query component bolded. The Html display name is used in the
61      * Find Usages explorer and the refactoring preview explorer on the
62      * usage node.
63      * The string should be formatted to use < and > for
64      * the XML tags, and < and > for the HTML tags. In the following example,
65      * Find Usages was run on a schema global type named "POSLogCurrencyCode".
66      * The Node represents a schema local element that uses POSLogCurrencyCode.
67      * getHtmlDisplayName() returns the first line of the local element.
68      * The text "POSLogCurrencyCode" in the snippet will be bolded because it is
69      * the name of the query Component.
70      *
71      * &lt;xs:element name="CurrencyCode" type="<b>POSLogCurrencyCode</b>" minOccurs="0"/&gt;
72      *
73      * getIcon() -
74      * an Image for the icon on the Components explorer and graph nodes.
75      *
76      * getPreferredAction() -
77      * the Action which navigates to the primary view of the Component
78      *
79      */

80     public Node getDisplayNode(Component component) {
81         AbstractNode n = new AbstractNode(Children.LEAF);
82         String JavaDoc name = component instanceof Named ?
83             ((Named) component).getName() : component.getClass().getName();
84         n.setName(name);
85         return n;
86     }
87
88     public Node getDisplayNode(Model model) {
89         AbstractNode n = new AbstractNode(Children.LEAF);
90         FileObject fo = (FileObject) model.getModelSource().getLookup().lookup(FileObject.class);
91         assert fo != null : "Model source does not provide FileObject lookup";
92         n.setName(fo.getName());
93         return n;
94     }
95     
96     /**
97      * Return UI relevant path from root. Specific implementation should
98      * override.
99      */

100     public List JavaDoc<Component> getRelevantPathFromRoot(Component component) {
101         ArrayList JavaDoc<Component> pathFromRoot = new ArrayList JavaDoc<Component>();
102         Component dc = component;
103         pathFromRoot.add(dc);
104         while (dc.getParent() != null) {
105             dc = (Component) dc.getParent();
106             pathFromRoot.add(0, dc);
107         }
108         return pathFromRoot;
109     }
110     
111     /**
112      * Return UI relevant path from root. Specific implementation should
113      * override.
114      * @deprecated use #getRelevantPathFromRoot(Component item) instead
115      */

116     public List JavaDoc<Component> getRelevantPathFromRoot(Usage item) {
117         return getRelevantPathFromRoot(item.getComponent());
118     }
119 }
120
Popular Tags