1 19 package org.netbeans.modules.xml.refactoring.spi; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 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 37 public class UIHelper { 38 39 80 public Node getDisplayNode(Component component) { 81 AbstractNode n = new AbstractNode(Children.LEAF); 82 String 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 100 public List <Component> getRelevantPathFromRoot(Component component) { 101 ArrayList <Component> pathFromRoot = new ArrayList <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 116 public List <Component> getRelevantPathFromRoot(Usage item) { 117 return getRelevantPathFromRoot(item.getComponent()); 118 } 119 } 120 | Popular Tags |