KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > forte > node > XMLCDataObject


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Lisa Reese
21  *
22  */

23
24 package org.enhydra.kelp.forte.node;
25
26 import org.openide.actions.*;
27 import org.openide.cookies.*;
28 import org.openide.loaders.*;
29 import org.openide.nodes.*;
30 import org.openide.util.HelpCtx;
31 import org.openide.TopManager;
32 import org.openide.text.EditorSupport;
33 import org.openide.filesystems.FileObject;
34 import org.openide.filesystems.FileSystem;
35 import org.openide.filesystems.FileStateInvalidException;
36
37 //import org.netbeans.modules.html.*;
38

39 import org.enhydra.kelp.forte.services.*;
40 import org.enhydra.kelp.forte.XMLCSettings;
41
42 import org.enhydra.kelp.common.PathUtil;
43
44 import java.io.File JavaDoc;
45
46
47 /** Represents a XMLC object in the Repository.
48  *
49  * @author rees0234
50  */

51 public class XMLCDataObject extends MultiDataObject {
52
53     private static final long serialVersionUID = -556335052709447405L;
54
55     protected XMLCSettings settings = null;
56     
57     public XMLCDataObject (FileObject pf, XMLCDataLoader loader) throws DataObjectExistsException
58     {
59         super (pf, loader);
60         init ();
61     }
62
63     private void init ()
64     {
65         CookieSet cookies = getCookieSet ();
66         cookies.add(new XMLCEditorSupport(this));
67         cookies.add(new ViewSupport(getPrimaryEntry()));
68         settings = XMLCSettings.getDefault();
69     }
70
71     public HelpCtx getHelpCtx ()
72     {
73         return HelpCtx.DEFAULT_HELP;
74         // If you add context help, change to:
75
// return new HelpCtx (XMLCDataObject.class);
76
}
77
78     protected Node createNodeDelegate ()
79     {
80         return new XMLCDataNode (this);
81     }
82
83         /** Creates a Node.Cookie of given class. The method
84      * may be called more than once.
85      */

86    public Node.Cookie createCookie(Class JavaDoc klass)
87    {
88 // if (CompilerCookie.class.isAssignableFrom(klass)) {
89
// MultiDataObject.Entry entry = getPrimaryEntry();
90
// return new XMLCCompilerSupport.Compile(entry);
91
// }
92
if (klass == XMLCEditorSupport.class)
93          {
94             return new XMLCEditorSupport(this);
95          }
96          else if (klass == ViewSupport.class)
97          {
98             return new ViewSupport(getPrimaryEntry());
99          }
100
101         return null;
102     }
103     
104     public String JavaDoc getPath()
105     {
106         FileObject file = getPrimaryFile();
107         StringBuffer JavaDoc res = new StringBuffer JavaDoc();
108         FileSystem fs = null;
109         try
110         {
111            fs = file.getFileSystem();
112         } catch (FileStateInvalidException e)
113         {
114            System.err.println(e);
115            return "invalid";
116         }
117
118         res.append(fs.getSystemName());
119         String JavaDoc pack = file.getPackageNameExt(File.separatorChar, '.');
120         res.append(File.separatorChar);
121         res.append(pack);
122          
123         return res.toString();
124     }
125
126     public String JavaDoc getProperty(String JavaDoc key)
127     {
128        String JavaDoc path = PathUtil.compressPathRelativeToProject(new ForteProject(), getPath());
129        return (String JavaDoc)settings.getNodeProperty(path + key);
130     }
131
132     public void setProperty(String JavaDoc key, String JavaDoc value)
133     {
134         String JavaDoc path = PathUtil.compressPathRelativeToProject(new ForteProject(), getPath());
135         settings.setNodeProperty(path + key, value);
136     }
137     
138     static final class ViewSupport implements ViewCookie
139     {
140         /** entry */
141       private MultiDataObject.Entry primary;
142         
143         /** Constructs new ViewSupport */
144       public ViewSupport(MultiDataObject.Entry primary) {
145             this.primary = primary;
146         }
147         
148          public void view () {
149              try {
150                  TopManager.getDefault ().showUrl (primary.getFile ().getURL ());
151              } catch (FileStateInvalidException e) {
152                  e.printStackTrace(System.err);
153              }
154          }
155     }
156     
157 }
158
Popular Tags