001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xml.refactoring.spi;
042:
043: import java.util.ArrayList;
044: import java.util.List;
045: import org.netbeans.modules.xml.xam.Component;
046: import org.netbeans.modules.xml.xam.Model;
047: import org.netbeans.modules.xml.xam.Named;
048: import org.openide.filesystems.FileObject;
049: import org.openide.nodes.AbstractNode;
050: import org.openide.nodes.Children;
051: import org.openide.nodes.Node;
052:
053: /**
054: * Default UI Helper.
055: *
056: * @author Nam Nguyen
057: */
058: public class UIHelper {
059:
060: /**
061: * Returns specific node for displaying the component in a preview window.
062: *
063: * The Node should return the following information that will be used
064: * in the refactoring UI:
065: *
066: * getActions(boolean) -
067: * other Actions for the Component, preferably navigational actions
068: * Minimally, getActions() should return a Go To Source Action, which
069: * will open the source (text) view with the cursor at the Component line
070: * The Actions should also implement org.openide.util.actions.Presenter.
071: * When the action is invoked from a prefuse graph node,
072: * actionPerformed(ActionEvent) is called with the Component as the source
073: * in the ActionEvent.
074: *
075: * getDisplayName() -
076: * a String that will be used as the label on the Component's explorer and
077: * graph nodes.
078: *
079: * getHtmlDisplayName() -
080: * For the usage component, a one line code snippet with the name
081: * of the query component bolded. The Html display name is used in the
082: * Find Usages explorer and the refactoring preview explorer on the
083: * usage node.
084: * The string should be formatted to use < and > for
085: * the XML tags, and < and > for the HTML tags. In the following example,
086: * Find Usages was run on a schema global type named "POSLogCurrencyCode".
087: * The Node represents a schema local element that uses POSLogCurrencyCode.
088: * getHtmlDisplayName() returns the first line of the local element.
089: * The text "POSLogCurrencyCode" in the snippet will be bolded because it is
090: * the name of the query Component.
091: *
092: * <xs:element name="CurrencyCode" type="<b>POSLogCurrencyCode</b>" minOccurs="0"/>
093: *
094: * getIcon() -
095: * an Image for the icon on the Components explorer and graph nodes.
096: *
097: * getPreferredAction() -
098: * the Action which navigates to the primary view of the Component
099: *
100: */
101: public Node getDisplayNode(Component component) {
102: AbstractNode n = new AbstractNode(Children.LEAF);
103: String name = component instanceof Named ? ((Named) component)
104: .getName() : component.getClass().getName();
105: n.setName(name);
106: return n;
107: }
108:
109: public Node getDisplayNode(Model model) {
110: AbstractNode n = new AbstractNode(Children.LEAF);
111: FileObject fo = (FileObject) model.getModelSource().getLookup()
112: .lookup(FileObject.class);
113: assert fo != null : "Model source does not provide FileObject lookup";
114: n.setName(fo.getName());
115: return n;
116: }
117:
118: /**
119: * Return UI relevant path from root. Specific implementation should
120: * override.
121: */
122: public List<Component> getRelevantPathFromRoot(Component component) {
123: ArrayList<Component> pathFromRoot = new ArrayList<Component>();
124: Component dc = component;
125: pathFromRoot.add(dc);
126: while (dc.getParent() != null) {
127: dc = (Component) dc.getParent();
128: pathFromRoot.add(0, dc);
129: }
130: return pathFromRoot;
131: }
132:
133: /**
134: * Return UI relevant path from root. Specific implementation should
135: * override.
136: * @deprecated use #getRelevantPathFromRoot(Component item) instead
137: */
138: // public List<Component> getRelevantPathFromRoot(Usage item) {
139: // return getRelevantPathFromRoot(item.getComponent());
140: // }
141: }
|