1 19 20 package org.netbeans.beaninfo.editors; 21 22 import java.beans.PropertyEditorSupport ; 23 import java.text.MessageFormat ; 24 import java.util.ArrayList ; 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 41 public class HtmlBrowser extends Object { 42 43 public static class FactoryEditor extends PropertyEditorSupport { 44 45 46 private static final String EA_HIDDEN = "hidden"; 48 private static final String BROWSER_FOLDER = "Services/Browsers"; 50 51 public FactoryEditor () { 52 } 53 54 public String 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 ex) { 65 Exceptions.printStackTrace(ex); 66 } 67 return NbBundle.getMessage (FactoryEditor.class, "CTL_UnspecifiedBrowser"); } 69 70 public void setAsText (java.lang.String str) throws java.lang.IllegalArgumentException { 71 try { 72 if (NbBundle.getMessage (FactoryEditor.class, "CTL_UnspecifiedBrowser").equals (str) || 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 e) { 86 IllegalArgumentException iae = new IllegalArgumentException (e.getMessage()); 87 String msg = e.getLocalizedMessage(); 88 if (msg == null) { 89 msg = MessageFormat.format( 90 NbBundle.getMessage( 91 HtmlBrowser.class, "FMT_EXC_GENERIC_BAD_VALUE"), new Object [] {str}); 93 } 94 UIExceptions.annotateUser(iae, str, msg, e, new java.util.Date ()); 95 throw iae; 96 } 97 } 98 99 public java.lang.String [] getTags () { 100 ArrayList <String > list = new ArrayList <String > (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 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 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 n = fo2.getName(); 118 try { 119 n = fo2.getFileSystem().getStatus().annotateName(n, dobjs[i].files()); 120 } catch (FileStateInvalidException e) { 121 } 123 list.remove(n); 124 } 125 } 126 } 127 String [] retValue = new String [list.size ()]; 128 129 list.toArray (retValue); 130 return retValue; 131 } 132 133 } 134 135 } 136 | Popular Tags |