1 19 20 package org.netbeans.modules.xml.xam.ui.customizer; 21 22 import java.awt.EventQueue ; 23 import java.io.IOException ; 24 import java.net.URI ; 25 import java.net.URISyntaxException ; 26 import java.util.Collections ; 27 import org.netbeans.modules.xml.xam.ModelSource; 28 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 29 import org.netbeans.modules.xml.retriever.catalog.CatalogEntry; 30 import org.netbeans.modules.xml.retriever.catalog.CatalogWriteModel; 31 import org.netbeans.modules.xml.xam.Model; 32 import org.netbeans.modules.xml.xam.ui.ModelCookie; 33 import org.openide.filesystems.FileObject; 34 import org.openide.loaders.DataObjectNotFoundException; 35 import org.openide.nodes.AbstractNode; 36 import org.openide.nodes.Children; 37 import org.openide.nodes.Node; 38 import org.openide.util.NbBundle; 39 import org.openide.loaders.DataObject; 40 41 45 public class RetrievedFilesChildren extends Children.Keys { 46 private CatalogWriteModel cwm; 47 private ExternalReferenceDecorator decorator; 48 49 50 public RetrievedFilesChildren(CatalogWriteModel cwm, 51 ExternalReferenceDecorator decorator) { 52 super(); 53 this.cwm = cwm; 54 this.decorator = decorator; 55 } 56 57 protected Node[] createNodes(Object key) { 58 if (key == WaitNode.WAIT_KEY) { 59 return WaitNode.createNode(); 60 } else if (key instanceof CatalogEntry) { 61 CatalogEntry entry = (CatalogEntry) key; 62 try { 63 ModelSource modelSource = cwm.getModelSource(new URI (entry.getSource())); 64 if (modelSource == null) { 65 return new Node[0]; 66 } 67 FileObject fobj = (FileObject) modelSource. 68 getLookup().lookup(FileObject.class); 69 if (fobj == null) { 70 return new Node[0]; 71 } 72 DataObject dobj = DataObject.find(fobj); 73 if (dobj == null) { 74 return new Node[0]; 75 } 76 ModelCookie cookie = (ModelCookie) dobj.getCookie(ModelCookie.class); 77 if (cookie == null) { 78 return new Node[0]; 79 } 80 Model model = cookie.getModel(); 81 if (model == null) { 82 return new Node[0]; 83 } 84 String targetNS = decorator.getNamespace(model); 85 RetrievedFileNode childNode = new RetrievedFileNode(entry, 86 targetNS, Children.LEAF, decorator); 87 childNode.setDisplayName(entry.getSource()); 88 Children.Array children = new Children.Array(); 89 children.add(new Node[] { childNode }); 90 return new Node[] { 91 new RetrievedFileNode(entry, targetNS, children, decorator) 92 }; 93 } catch (URISyntaxException urise) { 94 } catch (CatalogModelException cme) { 95 } catch (DataObjectNotFoundException donfe) { 96 } catch (IOException ioe) { 97 } 98 } 99 return new Node[0]; 100 } 101 102 protected void addNotify() { 103 setKeys(WaitNode.getKeys()); 104 EventQueue.invokeLater(new Runnable () { 105 public void run() { 106 setKeys(cwm.getCatalogEntries()); 107 } 108 }); 109 } 110 111 @Override 112 protected void removeNotify() { 113 setKeys(Collections.emptySet()); 114 } 115 116 public static class RetrievedFileNode extends AbstractNode 117 implements ExternalReferenceNode { 118 private boolean valid; 119 private String location; 120 private String targetNS; 121 private ExternalReferenceDecorator decorator; 122 123 126 RetrievedFileNode(CatalogEntry entry, String targetNS, 127 org.openide.nodes.Children children, 128 ExternalReferenceDecorator decorator) { 129 super(children); 130 this.location = entry.getSource(); 131 this.valid = entry.isValid(); 132 this.targetNS = targetNS; 133 this.decorator = decorator; 134 setName(targetNS); 135 if (targetNS == null) { 136 setDisplayName(NbBundle.getMessage(RetrievedFileNode.class, 137 "LBL_NoTargetNamespace")); 138 } 139 setIconBaseWithExtension( 140 "org/netbeans/modules/xml/xam/ui/customizer/Schema_File.png"); } 142 143 public String getLocation() { 144 return location; 145 } 146 147 public String getNamespace() { 148 return targetNS; 149 } 150 151 public boolean isValid() { 152 return valid; 153 } 154 155 public String getHtmlDisplayName() { 156 String name = super.getHtmlDisplayName(); 157 if (isValid()) { 158 if (decorator != null) { 159 if (name == null) { 160 name = getDisplayName(); 161 } 162 name = decorator.getHtmlDisplayName(name, this); 163 } 164 } else { 165 return "<s>" + name == null ? getDisplayName() : name + "</s>"; 166 } 167 return name; 168 } 169 170 public Model getModel() { 171 return null; 172 } 173 174 public boolean hasModel() { 175 return false; 176 } 177 } 178 } 179 | Popular Tags |