1 23 24 package org.enhydra.kelp.forte.node; 25 26 import org.openide.actions.*; 27 import org.openide.cookies.*; 28 import org.openide.loaders.*; 29 import org.openide.nodes.*; 30 import org.openide.util.HelpCtx; 31 import org.openide.TopManager; 32 import org.openide.text.EditorSupport; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileSystem; 35 import org.openide.filesystems.FileStateInvalidException; 36 37 39 import org.enhydra.kelp.forte.services.*; 40 import org.enhydra.kelp.forte.XMLCSettings; 41 42 import org.enhydra.kelp.common.PathUtil; 43 44 import java.io.File ; 45 46 47 51 public class XMLCDataObject extends MultiDataObject { 52 53 private static final long serialVersionUID = -556335052709447405L; 54 55 protected XMLCSettings settings = null; 56 57 public XMLCDataObject (FileObject pf, XMLCDataLoader loader) throws DataObjectExistsException 58 { 59 super (pf, loader); 60 init (); 61 } 62 63 private void init () 64 { 65 CookieSet cookies = getCookieSet (); 66 cookies.add(new XMLCEditorSupport(this)); 67 cookies.add(new ViewSupport(getPrimaryEntry())); 68 settings = XMLCSettings.getDefault(); 69 } 70 71 public HelpCtx getHelpCtx () 72 { 73 return HelpCtx.DEFAULT_HELP; 74 } 77 78 protected Node createNodeDelegate () 79 { 80 return new XMLCDataNode (this); 81 } 82 83 86 public Node.Cookie createCookie(Class klass) 87 { 88 if (klass == XMLCEditorSupport.class) 93 { 94 return new XMLCEditorSupport(this); 95 } 96 else if (klass == ViewSupport.class) 97 { 98 return new ViewSupport(getPrimaryEntry()); 99 } 100 101 return null; 102 } 103 104 public String getPath() 105 { 106 FileObject file = getPrimaryFile(); 107 StringBuffer res = new StringBuffer (); 108 FileSystem fs = null; 109 try 110 { 111 fs = file.getFileSystem(); 112 } catch (FileStateInvalidException e) 113 { 114 System.err.println(e); 115 return "invalid"; 116 } 117 118 res.append(fs.getSystemName()); 119 String pack = file.getPackageNameExt(File.separatorChar, '.'); 120 res.append(File.separatorChar); 121 res.append(pack); 122 123 return res.toString(); 124 } 125 126 public String getProperty(String key) 127 { 128 String path = PathUtil.compressPathRelativeToProject(new ForteProject(), getPath()); 129 return (String )settings.getNodeProperty(path + key); 130 } 131 132 public void setProperty(String key, String value) 133 { 134 String path = PathUtil.compressPathRelativeToProject(new ForteProject(), getPath()); 135 settings.setNodeProperty(path + key, value); 136 } 137 138 static final class ViewSupport implements ViewCookie 139 { 140 141 private MultiDataObject.Entry primary; 142 143 144 public ViewSupport(MultiDataObject.Entry primary) { 145 this.primary = primary; 146 } 147 148 public void view () { 149 try { 150 TopManager.getDefault ().showUrl (primary.getFile ().getURL ()); 151 } catch (FileStateInvalidException e) { 152 e.printStackTrace(System.err); 153 } 154 } 155 } 156 157 } 158 | Popular Tags |