KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > beaninfo > editors > HtmlBrowser


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.editors;
21
22 import java.beans.PropertyEditorSupport JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import org.netbeans.core.UIExceptions;
26 import org.openide.cookies.InstanceCookie;
27 import org.openide.filesystems.FileObject;
28 import org.openide.filesystems.FileStateInvalidException;
29 import org.openide.filesystems.Repository;
30 import org.openide.loaders.DataFolder;
31 import org.openide.loaders.DataObject;
32 import org.openide.util.Exceptions;
33 import org.openide.util.Lookup;
34 import org.openide.util.NbBundle;
35
36 /**
37  * Defines editor for choosing of Web browser.
38  *
39  * @author Radim Kubacki
40  */

41 public class HtmlBrowser extends Object JavaDoc {
42
43     public static class FactoryEditor extends PropertyEditorSupport JavaDoc {
44         
45         /** extended attribute that signals that this object should not be visible to the user */
46         private static final String JavaDoc EA_HIDDEN = "hidden"; // NOI18N
47

48         private static final String JavaDoc BROWSER_FOLDER = "Services/Browsers"; // NOI18N
49

50         /** Creates new FactoryEditor */
51         public FactoryEditor () {
52         }
53         
54         public String JavaDoc getAsText () {
55             try {
56                 org.openide.awt.HtmlBrowser.Factory f = (org.openide.awt.HtmlBrowser.Factory)getValue ();
57                 
58                 Lookup.Item<org.openide.awt.HtmlBrowser.Factory> i = Lookup.getDefault().lookupItem(
59                     new Lookup.Template<org.openide.awt.HtmlBrowser.Factory> (org.openide.awt.HtmlBrowser.Factory.class, null, f)
60                 );
61                 if (i != null)
62                     return i.getDisplayName();
63             }
64             catch (Exception JavaDoc ex) {
65                 Exceptions.printStackTrace(ex);
66             }
67             return NbBundle.getMessage (FactoryEditor.class, "CTL_UnspecifiedBrowser"); //NOI18N
68
}
69         
70         public void setAsText (java.lang.String JavaDoc str) throws java.lang.IllegalArgumentException JavaDoc {
71             try {
72                 if (NbBundle.getMessage (FactoryEditor.class, "CTL_UnspecifiedBrowser").equals (str) //NOI18N
73
|| str == null) {
74                     setValue (null);
75                     return;
76                 }
77                 Lookup.Result<org.openide.awt.HtmlBrowser.Factory> r = Lookup.getDefault().lookupResult(org.openide.awt.HtmlBrowser.Factory.class);
78         for (Lookup.Item<org.openide.awt.HtmlBrowser.Factory> i: r.allItems()) {
79                     if (str.equals(i.getDisplayName())) {
80                         setValue (i.getInstance());
81                         return;
82                     }
83                 }
84             }
85             catch (Exception JavaDoc e) {
86             IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc (e.getMessage());
87             String JavaDoc msg = e.getLocalizedMessage();
88             if (msg == null) {
89                 msg = MessageFormat.format(
90                     NbBundle.getMessage(
91                     HtmlBrowser.class, "FMT_EXC_GENERIC_BAD_VALUE"), //NOI18N
92
new Object JavaDoc[] {str});
93             }
94             UIExceptions.annotateUser(iae, str, msg, e, new java.util.Date JavaDoc());
95             throw iae;
96             }
97         }
98         
99         public java.lang.String JavaDoc[] getTags () {
100             ArrayList JavaDoc<String JavaDoc> list = new ArrayList JavaDoc<String JavaDoc> (6);
101             Lookup.Result<org.openide.awt.HtmlBrowser.Factory> r = Lookup.getDefault().lookupResult(org.openide.awt.HtmlBrowser.Factory.class);
102             for (Lookup.Item<org.openide.awt.HtmlBrowser.Factory> i: r.allItems()) {
103                 list.add(i.getDisplayName());
104             }
105             
106             // PENDING need to get rid of this filtering
107
FileObject fo = Repository.getDefault ()
108             .getDefaultFileSystem ().findResource (BROWSER_FOLDER);
109             if (fo != null) {
110                 DataFolder folder = DataFolder.findFolder (fo);
111                 DataObject [] dobjs = folder.getChildren ();
112                 for (int i = 0; i<dobjs.length; i++) {
113                     // Must not be hidden and have to provide instances (we assume instance is HtmlBrowser.Factory)
114
if (Boolean.TRUE.equals(dobjs[i].getPrimaryFile().getAttribute(EA_HIDDEN)) ||
115                             dobjs[i].getCookie(InstanceCookie.class) == null) {
116                         FileObject fo2 = dobjs[i].getPrimaryFile();
117                         String JavaDoc n = fo2.getName();
118                         try {
119                             n = fo2.getFileSystem().getStatus().annotateName(n, dobjs[i].files());
120                         } catch (FileStateInvalidException e) {
121                             // Never mind.
122
}
123                         list.remove(n);
124                     }
125                 }
126             }
127             String JavaDoc[] retValue = new String JavaDoc[list.size ()];
128             
129             list.toArray (retValue);
130             return retValue;
131         }
132         
133     }
134                 
135 }
136
Popular Tags