1 22 package org.enhydra.kelp.jbuilder.node; 23 24 import org.enhydra.tool.common.PathHandle; 26 27 import com.borland.jbuilder.node.JBProject; 29 import com.borland.primetime.node.FileNode; 30 import com.borland.primetime.node.Node; 31 import com.borland.primetime.vfs.Url; 32 33 import org.enhydra.kelp.common.Constants; 35 import org.enhydra.kelp.common.PathUtil; 36 import org.enhydra.kelp.common.PropUtil; 37 import org.enhydra.kelp.common.node.PropertyKeys; 38 import org.enhydra.kelp.common.node.OtterNode; 39 import org.enhydra.kelp.common.node.OtterFileNode; 40 import org.enhydra.kelp.common.node.OtterProject; 41 42 import java.io.File ; 44 import javax.swing.SwingUtilities ; 45 46 52 public class PrimeNode implements OtterFileNode { 53 private Node nativeNode = null; 54 private Throwable exception = null; 55 56 60 public PrimeNode() {} 61 62 67 public PrimeNode(Node n) { 68 nativeNode = n; 69 } 70 71 public PrimeNode(OtterNode otterNode, String path) { 72 JBProject nativeProject = null; 73 Node containerNode = null; 74 75 if (otterNode.getProject().getNativeProject() instanceof JBProject) { 76 nativeProject = 77 (JBProject) otterNode.getProject().getNativeProject(); 78 } 79 if (otterNode.getNativeNode() instanceof Node) { 80 containerNode = (Node) otterNode.getNativeNode(); 81 } 82 if (nativeProject != null && containerNode != null) { 83 Url url = null; 84 Node found = null; 85 86 url = new Url(new File (path)); 87 found = nativeProject.findNode(url); 88 if (found == null) { 89 Node newNode = null; 90 91 newNode = nativeProject.getNode(url); 92 setNativeNode(newNode); 93 SwingUtilities.invokeLater(new ParentSetter(containerNode)); 94 } else { 95 setNativeNode(found); 96 } 97 } 98 } 99 100 101 public OtterProject getProject() { 102 return (new PrimeProject((JBProject) nativeNode.getProject())); 103 } 104 105 110 public String getFilePath() { 111 File out = null; 112 113 if (nativeNode != null) { 114 if (nativeNode instanceof FileNode) { 115 FileNode fileNode; 116 117 fileNode = (FileNode) nativeNode; 118 out = fileNode.getUrl().getFileObject(); 119 } 120 } 121 return PathHandle.createPathString(out); 122 } 123 124 public String getXMLCOptionFilePath() { 125 String path = new String (); 126 File file = null; 127 PathHandle handle = null; 128 129 file = 130 PathUtil.getFileRelativeToProject(this, 131 PropertyKeys.NAME_XMLC_OPTION_FILEPATH); 132 handle = PathHandle.createPathHandle(file); 133 if (handle.isFile() && handle.hasExtension(Constants.TYPE_XMLC)) { 134 path = handle.getPath(); 135 } 136 return path; 137 } 138 139 public void setXMLCOptionFilePath(String n) { 140 PathHandle handle = null; 141 String relFilename = new String (); 142 143 handle = PathHandle.createPathHandle(n); 144 if (handle.isFile() && handle.hasExtension(Constants.TYPE_XMLC)) { 145 relFilename = PathUtil.compressPathRelativeToProject(this, 146 handle.getPath()); 147 } 148 setProperty(PropertyKeys.NAME_XMLC_OPTION_FILEPATH, relFilename); 149 } 150 151 public String getXMLCParameters() { 152 String out = new String (); 153 154 out = getProperty(PropertyKeys.NAME_XMLC_PARAMETERS); 155 out = PropUtil.cleanXMLCParameters(out); 156 return out; 157 } 158 159 public void setXMLCParameters(String in) { 160 String out = new String (); 161 162 out = PropUtil.cleanXMLCParameters(in); 163 setProperty(PropertyKeys.NAME_XMLC_PARAMETERS, out); 164 } 165 166 174 public String getProperty(String property) { 175 String out = null; 176 177 if (nativeNode != null) { 178 out = nativeNode.getProperty(property); 179 } 180 return out; 181 } 182 183 190 public void setProperty(String property, String value) { 191 if (nativeNode != null) { 192 nativeNode.setProperty(property, value); 193 } 194 } 195 196 public void setProperty(String property, int i) { 197 String value = Integer.toString(i); 198 199 setProperty(property, value); 200 } 201 202 208 public Object getNativeNode() { 209 return nativeNode; 210 } 211 212 218 public void setNativeNode(Object n) { 219 nativeNode = (Node) n; 220 } 221 222 public OtterNode getParent() { 223 OtterNode parent = null; 224 Node nativeParent = null; 225 226 nativeParent = nativeNode.getParent(); 227 if (nativeParent instanceof JBProject) { 228 parent = getProject(); 229 } else { 230 parent = new PrimeNode(nativeParent); 231 } 232 return parent; 233 } 234 235 public boolean isSelected() { 236 String in = getProperty(PropertyKeys.NAME_SELECTED); 237 238 return PropUtil.stringToBoolean(in, false); 239 } 240 241 public void setSelected(boolean b) { 242 setProperty(PropertyKeys.NAME_SELECTED, PropUtil.booleanToString(b)); 243 } 244 245 252 public void setException(Throwable e) { 253 exception = e; 254 } 255 256 260 public Throwable getException() { 261 return exception; 262 } 263 264 public void save() { 265 FileNode fileNode = null; 266 267 if (getNativeNode() instanceof FileNode) { 268 fileNode = (FileNode) getNativeNode(); 269 try { 270 fileNode.save(); 271 } catch (Exception e) { 272 e.printStackTrace(); 273 } 274 } 275 } 276 277 protected class ParentSetter implements Runnable { 278 private Node conNode = null; 279 280 protected ParentSetter(Node con) { 281 conNode = con; 282 } 283 284 synchronized public void run() { 285 Node nativeNode = null; 286 Node nativeParent = null; 287 JBProject nativeProject = null; 288 289 nativeNode = (Node) getNativeNode(); 290 nativeNode.setParent(conNode); 291 nativeProject = (JBProject) getProject().getNativeProject(); 292 nativeNode.check(); 293 nativeProject.fireChildrenChanged(nativeNode); 294 } 295 296 } 297 } 298 | Popular Tags |