KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.modules.xml.schema.model.Import;
25 import org.netbeans.modules.xml.schema.ui.nodes.ReadOnlyCookie;
26 import org.netbeans.modules.xml.xam.locator.CatalogModelException;
27 import org.openide.nodes.AbstractNode;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Node;
30 import org.openide.util.NbBundle;
31 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
32 import org.netbeans.modules.xml.schema.model.SchemaModel;
33 import org.netbeans.modules.xml.schema.model.SchemaModelReference;
34 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext;
35 import org.netbeans.modules.xml.xam.Model;
36
37 /**
38  *
39  * @author Ajit Bhate
40  */

41 public class ReferencedSchemaModelChildren<C extends SchemaModelReference>
42         extends CategorizedChildren<C>
43 {
44     /**
45      *
46      *
47      */

48     public ReferencedSchemaModelChildren(SchemaUIContext context,
49             SchemaComponentReference<C> reference)
50     {
51         super(context,reference);
52     }
53     
54     
55     @Override JavaDoc
56     protected void removeNotify()
57     {
58         setKeys(Collections.emptyList());
59     }
60     
61     @Override JavaDoc
62     protected void addNotify()
63     {
64         Children.MUTEX.postWriteRequest(new Runnable JavaDoc()
65         {
66             public void run()
67             {
68                 setKeys(createKeys());
69             }
70         });
71     }
72     
73     @Override JavaDoc
74     public void refreshChildren()
75     {
76         Children.MUTEX.postWriteRequest(new Runnable JavaDoc()
77         {
78             public void run()
79             {
80                 setKeys(createKeys());
81             }
82         });
83     }
84
85
86     /**
87      *
88      *
89      */

90     protected List JavaDoc<Node> createKeys()
91     {
92         List JavaDoc<Node> keys=super.createKeys();
93         
94         // do not show reference children in readonly context
95
ReadOnlyCookie roc = (ReadOnlyCookie) getContext().getLookup().lookup(
96                 ReadOnlyCookie.class);
97         if(roc!=null && roc.isReadOnly()) return keys;
98
99         C component = getReference().get();
100         if(component instanceof Import &&
101                 component.getModel()!=getContext().getModel())
102             return keys;
103         SchemaModel refModel;
104         try
105         {
106             refModel = component.resolveReferencedModel();
107         } catch (CatalogModelException ex)
108         {
109             refModel = null;
110         }
111         if (refModel != null && refModel.getState() != Model.State.NOT_WELL_FORMED)
112         {
113             Node refNode = getContext().getFactory().createNode(refModel.getSchema());
114             Node dummyNode = new DummySchemaNode(refNode);
115             for(Node child:dummyNode.getChildren().getNodes())
116             {
117                 keys.add(new ReadOnlySchemaComponentNode(child));
118             }
119         }
120         else
121         {
122             AbstractNode node=new AbstractNode(Children.LEAF);
123             node.setIconBaseWithExtension(
124                     "org/netbeans/modules/xml/schema/core/resources/Schema_File.png"); // NOI18N
125
node.setDisplayName(
126                     NbBundle.getMessage(ReferencedSchemaModelChildren.class,
127                     "LBL_BrokenReference")); // NOI18N
128
keys.add(node);
129         }
130         return keys;
131     }
132 }
133
Popular Tags