1 19 20 package org.netbeans.modules.xml.schema.refactoring; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import javax.swing.Action ; 25 import org.netbeans.modules.xml.refactoring.Usage; 26 import org.netbeans.modules.xml.refactoring.spi.UIHelper; 27 import org.netbeans.modules.xml.schema.model.Redefine; 28 import org.netbeans.modules.xml.schema.model.SchemaComponent; 29 import org.netbeans.modules.xml.schema.refactoring.ui.DisplayInfoVisitor; 30 import org.netbeans.modules.xml.schema.refactoring.ui.DisplayInfoVisitor.DisplayInfo; 31 import org.netbeans.modules.xml.schema.refactoring.ui.QueryUtilities; 32 import org.netbeans.modules.xml.schema.ui.nodes.SchemaNodeFactory; 33 import org.netbeans.modules.xml.schema.ui.nodes.categorized.CategorizedSchemaNodeFactory; 34 import org.netbeans.modules.xml.xam.Component; 35 import org.netbeans.modules.xml.xam.Named; 36 import org.netbeans.modules.xml.xam.ui.actions.GoToAction; 37 import org.netbeans.modules.xml.xam.ui.actions.ShowSourceAction; 38 import org.openide.nodes.Children; 39 import org.openide.nodes.FilterNode; 40 import org.openide.nodes.Node; 41 import org.openide.util.Lookup; 42 import org.openide.util.actions.SystemAction; 43 import org.openide.util.lookup.Lookups; 44 45 49 public class SchemaUIHelper extends UIHelper{ 50 51 57 public List <Component> getRelevantPathFromRoot(Usage item) { 58 List <Component> path = item.getPathFromRoot(); 59 ArrayList <Component> relevantPath = null; 60 if (path != null && path.size()>0){ 61 relevantPath = new ArrayList <Component>(); 62 for (Component c:path){ 63 if (c instanceof Named || c instanceof Redefine){ 64 relevantPath.add(c); 65 } 66 } 67 } 68 return relevantPath; 69 } 70 71 111 public Node getDisplayNode(Component component) { 112 assert component instanceof SchemaComponent:"This UIHelper handles SchemaComponents only"; 113 SchemaComponent sc = SchemaComponent.class.cast(component); 114 115 return createNode(sc); 116 } 117 118 private Node createNode(final SchemaComponent sc) { 119 CategorizedSchemaNodeFactory nodeFactory = 120 new CategorizedSchemaNodeFactory(sc.getModel(), Lookups.singleton(sc)); 121 return new FilteredSchemaNode(nodeFactory.createNode(sc),sc); 122 } 123 124 public class FilteredSchemaNode extends FilterNode { 125 private final SchemaComponent sc; 126 127 FilteredSchemaNode(Node n, SchemaComponent sc) { 128 super(n,Children.LEAF); 129 disableDelegation(DELEGATE_GET_SHORT_DESCRIPTION | 130 DELEGATE_SET_SHORT_DESCRIPTION | 131 DELEGATE_GET_DISPLAY_NAME | 132 DELEGATE_GET_CONTEXT_ACTIONS | 133 DELEGATE_GET_ACTIONS | 134 DELEGATE_DESTROY); 135 this.sc = sc; 136 137 DisplayInfoVisitor div = new DisplayInfoVisitor(); 138 DisplayInfo dInfo = div.getDisplayInfo(sc); 139 this.setShortDescription(dInfo.getCompType()); this.setDisplayName(dInfo.getElementType()); } 142 143 147 public String getHtmlDisplayName() { 148 return QueryUtilities.getTextForSchemaComponent(sc); 149 } 150 151 public Action [] getActions(boolean b) { 152 return ACTIONS; 153 } 154 155 public Action getPreferredAction() { 156 return SystemAction.get(ShowSourceAction.class); 157 } 158 159 } 160 161 private static final SystemAction[] ACTIONS = 162 new SystemAction[] { 163 SystemAction.get(GoToAction.class) 164 }; 165 166 } 167 | Popular Tags |