KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > categorized > DetailsNode


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.ui.nodes.categorized;
21
22 import java.lang.ref.SoftReference JavaDoc;
23 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext;
24 import org.netbeans.modules.xml.xam.ui.column.Column;
25 import org.netbeans.modules.xml.xam.ui.column.ColumnProvider;
26 import org.netbeans.modules.xml.xam.ui.customizer.CustomizerProvider;
27 import org.openide.filesystems.FileObject;
28 import org.openide.loaders.DataObject;
29 import org.openide.loaders.DataObjectNotFoundException;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.AbstractNode;
32 import org.openide.nodes.Node;
33 import org.openide.util.Lookup;
34 import org.openide.util.NbBundle;
35 import org.openide.util.lookup.AbstractLookup;
36 import org.openide.util.lookup.InstanceContent;
37 import org.openide.util.lookup.Lookups;
38 import org.openide.util.lookup.ProxyLookup;
39
40 /**
41  * @author Ajit Bhate
42  */

43 public class DetailsNode extends AbstractNode
44 {
45     
46     private CustomizerProvider provider;
47     /**
48      * If readlony
49      */

50     private boolean readonly;
51     
52     
53     public DetailsNode(SchemaUIContext context, CustomizerProvider provider)
54     {
55         this(context,provider,new InstanceContent());
56     }
57     
58     private DetailsNode(SchemaUIContext context,
59             CustomizerProvider provider,
60             InstanceContent contents)
61     {
62         
63         super(Children.LEAF, createLookup(context, contents));
64         setDisplayName(getTypeDisplayName());
65         setIconBaseWithExtension(
66                     "org/netbeans/modules/xml/schema/ui/nodes/resources/"+
67                     "XML-Schema-element-details.png");
68         
69         this.provider = provider;
70         
71         contents.add(this);
72         contents.add(context);
73         contents.add(provider);
74         contents.add(
75         new ColumnProvider()
76         {
77             public Column getColumn()
78             {
79                 DetailsColumn column=columnRef!=null ?
80                     columnRef.get() : null;
81                 if (column==null)
82                 {
83                     column=createColumn();
84                     columnRef=new SoftReference JavaDoc<DetailsColumn>(column);
85                 }
86                 column.setReadOnly(isReadOnly());
87                 return column;
88             }
89             
90             private SoftReference JavaDoc<DetailsColumn> columnRef;
91         });
92                 try {
93                     // Include the data object in order for the Navigator to
94
// show the structure of the current document.
95
FileObject fobj = (FileObject) context.getModel().
96                             getModelSource().getLookup().lookup(FileObject.class);
97                     if (fobj != null) {
98                         contents.add(DataObject.find(fobj));
99                     }
100                 } catch (DataObjectNotFoundException donfe) {
101                 }
102     }
103
104         /**
105          * Create a lookup for this node, based on the given contents.
106          *
107          * @param context from which a Lookup is retrieved.
108          * @param contents the basis of our new lookup.
109          */

110         private static Lookup createLookup(SchemaUIContext context,
111                 InstanceContent contents) {
112             // We want our lookup to be based on the lookup from the context,
113
// which provides a few necessary objects, such as a SaveCookie.
114
// However, we do not want the Nodes or DataObjects, since we
115
// provide our own.
116
return new ProxyLookup(new Lookup[] {
117                 Lookups.exclude(context.getLookup(), new Class JavaDoc[] {
118                     Node.class,
119                     DataObject.class,
120                 }),
121                 new AbstractLookup(contents),
122             });
123         }
124
125     public boolean isReadOnly()
126     {
127         return readonly;
128     }
129
130     public void setReadOnly(boolean readonly)
131     {
132         this.readonly = readonly;
133     }
134     
135     /**
136      * create column
137      */

138     protected DetailsColumn createColumn()
139     {
140         return new DetailsColumn(provider.getCustomizer());
141     }
142     
143     
144     
145     /**
146      * return display name
147      */

148     public String JavaDoc getTypeDisplayName()
149     {
150         return NbBundle.getMessage(DetailsNode.class, "LBL_DetailsNode"); // NOI18N
151
}
152
153     public int hashCode()
154     {
155         return provider.hashCode();
156     }
157
158 }
159
Popular Tags