KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > beanbrowser > RefinedBeanNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.beanbrowser;
21
22 import java.beans.IntrospectionException JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.beans.VetoableChangeListener JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.util.Date JavaDoc;
29 import javax.swing.Action JavaDoc;
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 /** The variant of BeanNode to use.
42  * Special behavior: supports editing FileObject beans.
43  */

44 public class RefinedBeanNode extends BeanNode {
45     
46     public RefinedBeanNode(Object JavaDoc bean) throws IntrospectionException JavaDoc {
47         super(bean);
48         if (bean instanceof FileObject) {
49             getCookieSet().add(new FileObjectEditorSupport((FileObject)bean));
50         }
51     }
52     
53     public Action JavaDoc[] getActions(boolean context) {
54         Action JavaDoc[] a = super.getActions(context);
55         if (getBean() instanceof FileObject) {
56             Action JavaDoc[] a2 = new Action JavaDoc[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         // XXX should offer to open Java class implementing bean?
64
}
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 JavaDoc messageName() {
76             return fo.getNameExt();
77         }
78         
79         protected String JavaDoc messageToolTip() {
80             return fo.getPath();
81         }
82         
83         protected String JavaDoc messageOpened() {
84             return ""; // NOI18N
85
}
86         protected String JavaDoc messageOpening() {
87             return ""; // NOI18N
88
}
89         protected String JavaDoc messageSave() {
90             return ""; // NOI18N
91
}
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 JavaDoc l) {}
104             
105             public void addVetoableChangeListener(VetoableChangeListener JavaDoc l) {}
106             
107             public CloneableOpenSupport findCloneableOpenSupport() {
108                 return new FileObjectEditorSupport(fo);
109             }
110             
111             public String JavaDoc getMimeType() {
112                 return fo.getMIMEType();
113             }
114             
115             public Date JavaDoc getTime() {
116                 return fo.lastModified();
117             }
118             
119             public InputStream JavaDoc inputStream() throws IOException JavaDoc {
120                 return fo.getInputStream();
121             }
122             
123             public boolean isValid() {
124                 return fo.isValid();
125             }
126             
127             public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
128             }
129             
130             public void removeVetoableChangeListener(VetoableChangeListener JavaDoc l) {
131             }
132             
133             // XXX for now, r/o
134

135             public OutputStream JavaDoc outputStream() throws IOException JavaDoc {
136                 throw new IOException JavaDoc();
137             }
138             
139             public boolean isModified() {
140                 return false;
141             }
142             
143             public void markModified() throws IOException JavaDoc {
144                 throw new IOException JavaDoc();
145             }
146             
147             public void unmarkModified() {
148             }
149             
150         }
151         
152     }
153     
154 }
155
Popular Tags