1 23 24 package org.enhydra.kelp.forte.node; 25 26 import org.enhydra.tool.common.PathHandle; 28 29 import org.openide.loaders.DataNode; 32 import org.openide.nodes.Node; 33 import org.openide.nodes.FilterNode; 34 import org.openide.cookies.ProjectCookie; 35 import org.openide.loaders.DataObject; 36 import org.openide.loaders.DataObjectNotFoundException; 37 import org.openide.loaders.DataShadow; 38 import org.openide.loaders.DataFolder; 39 import org.openide.filesystems.FileSystem; 40 import org.openide.filesystems.FileObject; 41 import org.openide.filesystems.FileStateInvalidException; 42 import org.openide.filesystems.LocalFileSystem; 43 44 import org.enhydra.kelp.common.Constants; 46 import org.enhydra.kelp.common.PathUtil; 47 import org.enhydra.kelp.common.PropUtil; 48 import org.enhydra.kelp.common.node.PropertyKeys; 49 import org.enhydra.kelp.common.node.OtterNode; 50 import org.enhydra.kelp.common.node.OtterFileNode; 51 import org.enhydra.kelp.common.node.OtterProject; 52 53 import org.enhydra.kelp.forte.XMLCSettings; 54 import org.enhydra.kelp.forte.DeploySettings; 55 56 import java.io.File ; 58 import javax.swing.SwingUtilities ; 59 import java.util.Enumeration ; 60 import java.util.StringTokenizer ; 61 import java.net.URL ; 62 import java.net.MalformedURLException ; 63 68 public class ForteNode implements OtterFileNode 69 { 70 protected DataObject nativeNode = null; 71 private Throwable exception = null; 72 73 78 public ForteNode(DataObject dob) 79 { 80 nativeNode = dob; 81 } 82 83 89 public ForteNode(OtterNode parent, String path) { 91 setNativeNode(FindData(path)); 92 } 93 94 protected DataObject FindData(String path) 95 { DataObject data = null; 97 FileObject file = null; 98 99 FileSystem fs = null; 100 try { 101 fs = ((ForteProject)getProject()).getRootFolder().getFileSystem(); 102 } catch (FileStateInvalidException e){ 103 System.err.println(e); 104 } 105 String adjPath = path; 106 String sysVal = fs.getSystemName(); 107 if (path.startsWith(sysVal)) 108 adjPath = path.substring(sysVal.length()+ 1); 109 file = fs.findResource(adjPath); 110 if (file != null) 111 try 112 { 113 data = DataObject.find(file); 114 }catch (DataObjectNotFoundException e) 115 { 116 System.err.println(e); 117 } 118 return data; 119 } 120 121 122 public OtterProject getProject() 123 { 124 return new ForteProject(); 125 } 126 127 132 public String getFilePath() 133 { 134 if ((nativeNode != null)) 135 { 136 if (nativeNode instanceof DataShadow) 137 nativeNode = ((DataShadow)nativeNode).getOriginal(); 138 if (nativeNode != null) 139 { 140 FileSystem fs = null; 141 StringBuffer res = new StringBuffer (); 142 FileObject file = nativeNode.getPrimaryFile(); 143 try 144 { 145 fs = file.getFileSystem(); 146 } catch (FileStateInvalidException e) 147 { 148 System.err.println(e); 149 return "invalid"; 150 } 151 152 res.append(fs.getSystemName()); 153 154 String pack = new String (); 155 156 if (nativeNode instanceof DataFolder) 157 { 158 pack = file.getPackageName(File.separatorChar); 159 160 } 161 else 162 { 163 pack = file.getPackageNameExt(File.separatorChar, '.'); 164 } 165 if (pack.length() > 0) 166 { 167 res.append(File.separatorChar); 168 res.append(pack); 169 } 170 171 return res.toString(); 172 } 173 174 } 175 176 return null; } 178 179 public String getXMLCOptionFilePath() 180 { 181 return null; 183 } 184 185 public void setXMLCOptionFilePath(String n) 186 { 187 } 189 190 public String getXMLCParameters() 191 { 192 return null; 194 } 195 196 public void setXMLCParameters(String in) 197 { 198 199 } 201 202 210 public String getProperty(String property) 211 { 212 String path = PathUtil.compressPathRelativeToProject(this, getFilePath()); 213 214 if (property.startsWith("enhydra.xmlc")) 215 return XMLCSettings.getDefault().getNodeProperty(path + property); 216 else 217 return DeploySettings.getDefault().getNodeProperty(path + property); 218 } 219 220 226 public void setProperty(String property, String value) 227 { 228 String path = PathUtil.compressPathRelativeToProject(this, getFilePath()); 229 if (property.startsWith("enhydra.xmlc")) 230 XMLCSettings.getDefault().setNodeProperty(path + property, value); 231 else 232 DeploySettings.getDefault().setNodeProperty(path + property, value); 233 } 234 241 242 public void setProperty(String property, int i) 243 { 244 String value = Integer.toString(i); 245 246 setProperty(property, value); 247 } 248 249 255 public Object getNativeNode() 256 { 257 return nativeNode; 258 } 259 260 266 public void setNativeNode(Object n) 267 { 268 nativeNode = (DataObject) n; 269 } 270 271 public OtterNode getParent() 272 { 273 DataFolder nativeParent = null; 274 275 nativeParent = nativeNode.getFolder(); 276 if (nativeParent == null) { 278 return new ForteProject(); 279 } 280 else 281 { 282 return new ForteFolderNode(nativeParent); 283 } 284 } 285 286 public boolean isSelected() 287 { 288 return false; 289 } 290 291 public void setSelected(boolean b) 292 { 293 System.out.println("wrong setSelected"); 294 } 295 296 303 public void setException(Throwable e) 304 { 305 exception = e; 306 } 307 308 312 public Throwable getException() 313 { 314 return exception; 315 } 316 317 public void save() 318 { 319 } 321 322 323 } 324 | Popular Tags |