1 19 20 package org.netbeans.modules.html; 21 22 import org.openide.awt.HtmlBrowser; 23 import org.openide.cookies.ViewCookie; 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.FileStateInvalidException; 26 import org.openide.loaders.DataNode; 27 import org.openide.loaders.DataObjectExistsException; 28 import org.openide.loaders.MultiDataObject; 29 import org.openide.loaders.UniFileLoader; 30 import org.openide.nodes.Children; 31 import org.openide.nodes.CookieSet; 32 import org.openide.nodes.Node; 33 34 38 public class HtmlDataObject extends MultiDataObject implements CookieSet.Factory { 39 40 static final long serialVersionUID =8354927561693097159L; 41 42 47 public HtmlDataObject(FileObject pf, UniFileLoader loader) throws DataObjectExistsException { 48 super(pf, loader); 49 CookieSet set = getCookieSet(); 50 set.add(HtmlEditorSupport.class, this); 51 set.add(ViewSupport.class, this); 52 } 53 54 protected org.openide.nodes.Node createNodeDelegate () { 55 DataNode n = new HtmlDataNode (this, Children.LEAF); 56 n.setIconBaseWithExtension("org/netbeans/modules/html/htmlObject.png"); return n; 58 } 59 60 61 public Node.Cookie createCookie(Class klass) { 62 if (klass.isAssignableFrom (HtmlEditorSupport.class)) { 63 HtmlEditorSupport es = new HtmlEditorSupport(this); 64 return es; 65 } else if (klass.isAssignableFrom (ViewSupport.class)) { 66 return new ViewSupport(getPrimaryEntry()); 67 } else { 68 return null; 69 } 70 } 71 72 CookieSet getCookieSet0() { 74 return getCookieSet(); 75 } 76 77 static final class ViewSupport implements ViewCookie { 78 79 private MultiDataObject.Entry primary; 80 81 82 public ViewSupport(MultiDataObject.Entry primary) { 83 this.primary = primary; 84 } 85 86 public void view () { 87 try { 88 HtmlBrowser.URLDisplayer.getDefault ().showURL (primary.getFile ().getURL ()); 89 } catch (FileStateInvalidException e) { 90 } 91 } 92 } 93 94 } 95 | Popular Tags |