1 19 20 package org.netbeans.modules.xml.wsdl.refactoring; 21 22 import java.awt.Image ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 import javax.swing.Action ; 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 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 66 public WSDLUIHelper() { 67 super(); 68 } 69 70 74 @Override 75 public List <Component> getRelevantPathFromRoot(Component component) { 76 ArrayList <Component> pathFromRoot = new ArrayList <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 128 @Override 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 160 public SystemAction[] getActions(boolean val) { 161 return ACTIONS; 162 } 163 164 @Override 165 public Action getPreferredAction() { 166 return ACTIONS[0]; 167 } 168 }; 169 170 return filterNode; 171 } 172 } 173 } 174 } 175 } catch(Exception ex) { 176 ex.printStackTrace(); 177 } 178 179 if (displayNode == null){ 180 displayNode = new WSDLHelperNode(component); 181 } 182 183 return displayNode; 184 } 185 186 @Override 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"); } 207 208 @Override 209 public Image getIcon(int i) { 210 return super.getIcon(i); 211 } 212 213 217 @Override 218 public String getHtmlDisplayName() { 219 return "Temporary <b>Name</b>"; 220 } 221 222 @Override 223 public Action [] getActions(boolean b) { 224 return null; 225 } 226 227 @Override 228 public Action getPreferredAction() { 229 return null; 230 } 231 232 233 } 234 235 236 237 238 } 239 | Popular Tags |