KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > html > HtmlDataObject


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.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 /** Object that represents one html file.
35 *
36 * @author Ian Formanek
37 */

38 public class HtmlDataObject extends MultiDataObject implements CookieSet.Factory {
39
40     static final long serialVersionUID =8354927561693097159L;
41     
42     /** New instance.
43     * @param pf primary file object for this data object
44     * @param loader the data loader creating it
45     * @exception DataObjectExistsException if there was already a data object for it
46     */

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"); // NOI18N
57
return n;
58     }
59     
60     /** Creates new Cookie */
61     public Node.Cookie createCookie(Class JavaDoc 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     // Package accessibility for HtmlEditorSupport:
73
CookieSet getCookieSet0() {
74         return getCookieSet();
75     }
76     
77     static final class ViewSupport implements ViewCookie {
78         /** entry */
79         private MultiDataObject.Entry primary;
80         
81         /** Constructs new ViewSupport */
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