KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > beaninfo > DataLoaderPool


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.beaninfo;
21
22 import java.awt.Image JavaDoc;
23 import java.beans.*;
24
25 import org.openide.loaders.DataLoader;
26 import org.openide.loaders.UniFileLoader;
27 import org.openide.loaders.MultiFileLoader;
28 import org.openide.util.Exceptions;
29 import org.openide.util.Utilities;
30 import org.openide.util.NbBundle;
31
32 public class DataLoaderPool {
33
34     /** Create read-only 'extensions' property. Method used in [Folder|Instance]LoaderBeanInfo.
35      */

36     private static PropertyDescriptor[] createExtensionsPropertyDescriptor () {
37         try {
38             PropertyDescriptor extensions = new PropertyDescriptor ("extensions", UniFileLoader.class); // NOI18N
39
extensions.setDisplayName (NbBundle.getBundle (DataLoaderPool.class).getString ("PROP_UniFileLoader_extensions"));
40             extensions.setShortDescription (NbBundle.getBundle (DataLoaderPool.class).getString ("HINT_UniFileLoader_extensions"));
41             extensions.setWriteMethod(null);
42             return new PropertyDescriptor[] { extensions };
43         }
44         catch (IntrospectionException ie) {
45             Exceptions.printStackTrace(ie);
46             return null;
47         }
48     }
49     
50     public static class FolderLoaderBeanInfo extends SimpleBeanInfo {
51         
52         public BeanInfo[] getAdditionalBeanInfo () {
53             try {
54                 // FolderLoader bean info uses MultiFileLoader's bean info instead of
55
// UniFileLoader's one. That is why it is necessary to remove 'extensions'
56
// property (declared in UniFileLoaderBeanInfo).
57
// Currently this property is only addition to MultiFileLoader bean info
58
// provided by UniFileLoaderBeanInfo.
59
return new BeanInfo[] { Introspector.getBeanInfo (MultiFileLoader.class) };
60             } catch (IntrospectionException ie) {
61                 Exceptions.printStackTrace(ie);
62                 return null;
63             }
64         }
65
66         public PropertyDescriptor[] getPropertyDescriptors () {
67              return createExtensionsPropertyDescriptor();
68         }
69
70         public Image JavaDoc getIcon (int type) {
71             if ((type == BeanInfo.ICON_COLOR_16x16) || (type == BeanInfo.ICON_MONO_16x16)) {
72                 return Utilities.loadImage("org/openide/loaders/defaultFolder.gif"); // NOI18N
73
} else {
74                 return Utilities.loadImage("org/openide/loaders/defaultFolder32.gif"); // NOI18N
75
}
76         }
77     }
78
79     public static class InstanceLoaderBeanInfo extends SimpleBeanInfo {
80
81         public BeanInfo[] getAdditionalBeanInfo () {
82             try {
83                 // InstanceLoader bean info uses MultiFileLoader's bean info instead of
84
// UniFileLoader's one. That is why it is necessary to change 'extensions'
85
// property from r/w (declared in UniFileLoaderBeanInfo) to r/o property.
86
// Currently this property is only addition to MultiFileLoader bean info
87
// provided by UniFileLoaderBeanInfo.
88
return new BeanInfo[] { Introspector.getBeanInfo (MultiFileLoader.class) };
89             } catch (IntrospectionException ie) {
90                 Exceptions.printStackTrace(ie);
91                 return null;
92             }
93         }
94
95         public PropertyDescriptor[] getPropertyDescriptors () {
96              return createExtensionsPropertyDescriptor();
97         }
98         
99         public Image JavaDoc getIcon (int type) {
100             if ((type == BeanInfo.ICON_COLOR_16x16) || (type == BeanInfo.ICON_MONO_16x16)) {
101                 return Utilities.loadImage("org/netbeans/core/resources/action.gif"); // NOI18N
102
} else {
103                 return Utilities.loadImage ("org/netbeans/core/resources/action32.gif"); // NOI18N
104
}
105         }
106
107     }
108
109     public static class DefaultLoaderBeanInfo extends SimpleBeanInfo {
110
111         public BeanInfo[] getAdditionalBeanInfo () {
112             try {
113                 return new BeanInfo[] { Introspector.getBeanInfo (DataLoader.class) };
114             } catch (IntrospectionException ie) {
115                 Exceptions.printStackTrace(ie);
116                 return null;
117             }
118         }
119
120         public Image JavaDoc getIcon (int type) {
121             if ((type == BeanInfo.ICON_COLOR_16x16) || (type == BeanInfo.ICON_MONO_16x16)) {
122                 return Utilities.loadImage ("org/openide/resources/pending.gif"); // NOI18N
123
} else {
124                 return Utilities.loadImage ("org/openide/resources/pending32.gif"); // NOI18N
125
}
126         }
127
128     }
129
130     public static class ShadowLoaderBeanInfo extends SimpleBeanInfo {
131         public BeanInfo[] getAdditionalBeanInfo () {
132             try {
133                 return new BeanInfo[] { Introspector.getBeanInfo (DataLoader.class) };
134             } catch (IntrospectionException ie) {
135                 Exceptions.printStackTrace(ie);
136                 return null;
137             }
138         }
139
140         public PropertyDescriptor[] getPropertyDescriptors () {
141             try {
142                 // Hide the actions property from users, since shadows inherit actions anyway:
143
Class JavaDoc c = Class.forName ("org.openide.loaders.DataLoaderPool$ShadowLoader"); // NOI18N
144
PropertyDescriptor actions = new PropertyDescriptor ("actions", c); // NOI18N
145
actions.setHidden (true);
146                 return new PropertyDescriptor[] { actions };
147             } catch (ClassNotFoundException JavaDoc ie) {
148                 Exceptions.printStackTrace(ie);
149                 return null;
150             } catch (IntrospectionException ie) {
151                 Exceptions.printStackTrace(ie);
152                 return null;
153             }
154         }
155
156         public Image JavaDoc getIcon (int type) {
157             if ((type == BeanInfo.ICON_COLOR_16x16) || (type == BeanInfo.ICON_MONO_16x16)) {
158                 return Utilities.loadImage("org/openide/resources/actions/copy.gif"); // NOI18N
159
} else {
160                 // [PENDING]
161
//return Utilities.loadImage ("org/openide/resources/actions/copy32.gif"); // NOI18N
162
return null;
163             }
164         }
165
166     }
167
168 }
169
Popular Tags