1 23 24 package org.enhydra.kelp.forte.node; 25 26 import java.io.IOException ; 27 28 import org.openide.cookies.EditCookie; 29 import org.openide.cookies.EditorCookie; 30 import org.openide.cookies.OpenCookie; 31 import org.openide.cookies.PrintCookie; 32 import org.openide.cookies.SaveCookie; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileLock; 35 import org.openide.nodes.Node.Cookie; 36 import org.openide.text.DataEditorSupport; 37 import org.openide.windows.CloneableOpenSupport; 38 import org.openide.loaders.DataObject; 39 import org.openide.loaders.MultiDataObject; 40 42 47 public class XMLCEditorSupport extends DataEditorSupport implements OpenCookie, EditCookie, EditorCookie, PrintCookie { 48 49 50 public XMLCEditorSupport(DataObject obj) { 51 super(obj, new Environment(obj)); 52 53 setMIMEType("text/xml"); } 55 57 private final SaveCookie saveCookie = new SaveCookie() { 58 59 public void save() throws IOException { 60 XMLCEditorSupport.this.saveDocument(); 61 XMLCEditorSupport.this.getDataObject().setModified(false); 62 } 63 }; 64 65 70 protected boolean notifyModified () { 71 if (!super.notifyModified()) 72 return false; 73 74 addSaveCookie(); 75 76 return true; 77 } 78 79 80 protected void notifyUnmodified () { 81 super.notifyUnmodified(); 82 83 removeSaveCookie(); 84 } 85 86 87 private void addSaveCookie() { 88 XMLCMultiDataObject obj = (XMLCMultiDataObject)getDataObject(); 89 90 if(obj.getCookie(SaveCookie.class) == null) { 92 obj.getXMLCCookieSet().add(saveCookie); 93 obj.setModified(true); 94 } 95 } 96 97 98 private void removeSaveCookie() { 99 XMLCMultiDataObject obj = (XMLCMultiDataObject)getDataObject(); 100 101 Cookie cookie = obj.getCookie(SaveCookie.class); 103 104 if(cookie != null && cookie.equals(saveCookie)) { 105 obj.getXMLCCookieSet().remove(saveCookie); 106 obj.setModified(false); 107 } 108 } 109 110 111 112 private static class Environment extends DataEditorSupport.Env { 113 114 115 public Environment(DataObject obj) { 116 super(obj); 117 } 118 119 120 121 protected FileObject getFile() { 122 return getDataObject().getPrimaryFile(); 123 } 124 125 126 protected FileLock takeLock() throws IOException { 127 return ((XMLCMultiDataObject)getDataObject()).getPrimaryEntry().takeLock(); 128 } 129 130 134 public CloneableOpenSupport findCloneableOpenSupport() { 135 return (XMLCEditorSupport)((XMLCMultiDataObject)getDataObject()).getXMLCCookieSet().getCookie(XMLCEditorSupport.class); 136 } 137 } 139 } 140 141 | Popular Tags |