1 19 20 21 package org.netbeans.modules.form; 22 23 import org.openide.cookies.EditCookie; 24 import org.openide.cookies.OpenCookie; 25 import org.openide.filesystems.FileObject; 26 import org.openide.loaders.DataObjectExistsException; 27 import org.openide.loaders.FileEntry; 28 import org.openide.loaders.MultiDataObject; 29 import org.openide.nodes.Node; 30 import org.openide.nodes.Node.Cookie; 31 32 36 public class FormDataObject extends MultiDataObject { 37 38 40 43 50 transient private FormEditorSupport formEditor; 51 52 transient private OpenEdit openEdit; 53 54 55 FileEntry formEntry; 56 57 60 static final long serialVersionUID =-975322003627854168L; 61 62 public FormDataObject(FileObject ffo, FileObject jfo, FormDataLoader loader) 63 throws DataObjectExistsException 64 { 65 super(jfo, loader); 66 formEntry = (FileEntry)registerEntry(ffo); 67 } 68 69 72 @Override 73 public <T extends Cookie> T getCookie(Class <T> type) { 74 T retValue; 75 76 if (OpenCookie.class.equals(type) || EditCookie.class.equals(type)) { 77 if (openEdit == null) 78 openEdit = new OpenEdit(); 79 retValue = type.cast(openEdit); 80 } else if (type.isAssignableFrom(FormEditorSupport.class)) { 81 retValue = (T) getFormEditorSupport(); 82 } else { 83 retValue = super.getCookie(type); 84 } 85 return retValue; 86 } 87 88 private class OpenEdit implements OpenCookie, EditCookie { 89 public void open() { 90 getFormEditorSupport().openFormEditor(true); 92 } 93 public void edit() { 94 getFormEditorSupport().open(); 96 } 97 } 98 99 public FileObject getFormFile() { 100 return formEntry.getFile(); 101 } 102 103 public boolean isReadOnly() { 104 FileObject javaFO = getPrimaryFile(); 105 FileObject formFO = formEntry.getFile(); 106 return !javaFO.canWrite() || !formFO.canWrite(); 107 } 108 109 public boolean formFileReadOnly() { 110 return !formEntry.getFile().canWrite(); 111 } 112 113 public synchronized FormEditorSupport getFormEditorSupport() { 114 if (formEditor == null) { 115 formEditor = new FormEditorSupport(getPrimaryEntry(), this, getCookieSet()); 116 } 117 return formEditor; 118 } 119 120 public FormEditorSupport getFormEditor() { 122 return getFormEditorSupport(); 123 } 124 126 FileEntry getFormEntry() { 127 return formEntry; 128 } 129 130 139 protected Node createNodeDelegate() { 140 FormDataNode node = new FormDataNode(this); 141 return node; 142 } 143 144 147 private void readObject(java.io.ObjectInputStream is) 148 throws java.io.IOException , ClassNotFoundException { 149 is.defaultReadObject(); 150 } 151 152 } 153 | Popular Tags |