1 19 20 package org.netbeans.modules.apisupport.beanbrowser; 21 22 import java.beans.IntrospectionException ; 23 import java.beans.PropertyChangeListener ; 24 import java.beans.VetoableChangeListener ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.OutputStream ; 28 import java.util.Date ; 29 import javax.swing.Action ; 30 import org.openide.actions.EditAction; 31 import org.openide.cookies.CloseCookie; 32 import org.openide.cookies.EditCookie; 33 import org.openide.cookies.EditorCookie; 34 import org.openide.cookies.PrintCookie; 35 import org.openide.filesystems.FileObject; 36 import org.openide.nodes.BeanNode; 37 import org.openide.text.CloneableEditorSupport; 38 import org.openide.util.actions.SystemAction; 39 import org.openide.windows.CloneableOpenSupport; 40 41 44 public class RefinedBeanNode extends BeanNode { 45 46 public RefinedBeanNode(Object bean) throws IntrospectionException { 47 super(bean); 48 if (bean instanceof FileObject) { 49 getCookieSet().add(new FileObjectEditorSupport((FileObject)bean)); 50 } 51 } 52 53 public Action [] getActions(boolean context) { 54 Action [] a = super.getActions(context); 55 if (getBean() instanceof FileObject) { 56 Action [] a2 = new Action [a.length + 2]; 57 a2[0] = SystemAction.get(EditAction.class); 58 System.arraycopy(a, 0, a2, 2, a.length); 59 return a2; 60 } else { 61 return a; 62 } 63 } 65 66 private static final class FileObjectEditorSupport extends CloneableEditorSupport implements EditCookie, CloseCookie, PrintCookie, EditorCookie.Observable { 67 68 private final FileObject fo; 69 70 public FileObjectEditorSupport(FileObject fo) { 71 super(new FOEnv(fo)); 72 this.fo = fo; 73 } 74 75 protected String messageName() { 76 return fo.getNameExt(); 77 } 78 79 protected String messageToolTip() { 80 return fo.getPath(); 81 } 82 83 protected String messageOpened() { 84 return ""; } 86 protected String messageOpening() { 87 return ""; } 89 protected String messageSave() { 90 return ""; } 92 93 private static final class FOEnv implements CloneableEditorSupport.Env { 94 95 private static final long serialVersionUID = 78267653L; 96 97 private final FileObject fo; 98 99 public FOEnv(FileObject fo) { 100 this.fo = fo; 101 } 102 103 public void addPropertyChangeListener(PropertyChangeListener l) {} 104 105 public void addVetoableChangeListener(VetoableChangeListener l) {} 106 107 public CloneableOpenSupport findCloneableOpenSupport() { 108 return new FileObjectEditorSupport(fo); 109 } 110 111 public String getMimeType() { 112 return fo.getMIMEType(); 113 } 114 115 public Date getTime() { 116 return fo.lastModified(); 117 } 118 119 public InputStream inputStream() throws IOException { 120 return fo.getInputStream(); 121 } 122 123 public boolean isValid() { 124 return fo.isValid(); 125 } 126 127 public void removePropertyChangeListener(PropertyChangeListener l) { 128 } 129 130 public void removeVetoableChangeListener(VetoableChangeListener l) { 131 } 132 133 135 public OutputStream outputStream() throws IOException { 136 throw new IOException (); 137 } 138 139 public boolean isModified() { 140 return false; 141 } 142 143 public void markModified() throws IOException { 144 throw new IOException (); 145 } 146 147 public void unmarkModified() { 148 } 149 150 } 151 152 } 153 154 } 155 | Popular Tags |