KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.xml.schema.model.Enumeration;
23 import org.netbeans.modules.xml.schema.model.SimpleType;
24 import org.openide.nodes.AbstractNode;
25 import org.openide.nodes.Children;
26 import org.openide.nodes.Node;
27 import org.openide.nodes.NodeAdapter;
28 import org.openide.util.NbBundle;
29 import org.netbeans.modules.xml.schema.model.SchemaComponent;
30 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
31 import org.netbeans.modules.xml.schema.ui.nodes.DefaultExpandedCookie;
32 import org.netbeans.modules.xml.schema.ui.nodes.SchemaComponentNode;
33 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext;
34 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
35 import org.netbeans.modules.xml.schema.model.GlobalSimpleType;
36 import org.netbeans.modules.xml.schema.model.List;
37 import org.netbeans.modules.xml.schema.model.LocalSimpleType;
38 import org.netbeans.modules.xml.schema.model.SimpleTypeDefinition;
39 import org.netbeans.modules.xml.schema.model.SimpleTypeRestriction;
40
41 /**
42  *
43  * @author Ajit Bhate
44  */

45 public class SimpleTypeChildren<C extends SimpleType>
46         extends CategorizedChildren<C>
47 {
48     /**
49      *
50      *
51      */

52     public SimpleTypeChildren(SchemaUIContext context,
53             SchemaComponentReference<C> reference) {
54         super(context,reference);
55     }
56     
57     
58     /**
59      *
60      *
61      */

62     protected java.util.List JavaDoc<Node> createKeys() {
63         java.util.List JavaDoc<Node> keys=super.createKeys();
64         
65         int index=0;
66         
67         // Insert the inherited node after the details node
68
if (keys.size() > 0 && keys.get(0) instanceof DetailsNode)
69             index=1;
70         
71         LocalSimpleType inlineType = null;
72         SimpleTypeDefinition definition = getReference().get().getDefinition();
73         if(definition instanceof SimpleTypeRestriction) {
74             SimpleTypeRestriction str = (SimpleTypeRestriction)definition;
75             inlineType = str.getInlineType();
76         }
77         if(definition instanceof List) {
78             List list = (List)definition;
79             inlineType = list.getInlineType();
80         }
81         if(definition instanceof SimpleTypeRestriction ||
82                 definition instanceof List) {
83             for (int i=0;i<keys.size();i++) {
84                 Node n = keys.get(i);
85                 SchemaComponentNode scn = (SchemaComponentNode)n.getCookie
86                         (SchemaComponentNode.class);
87                 if(scn!=null && scn.getReference().get()==definition) {
88                     index = i;
89                     keys.remove(index);
90                     break;
91                 }
92             }
93         }
94         if(inlineType != null) {
95             Node inlineNode=
96                     getContext().getFactory().createNode(inlineType);
97             
98             DefaultExpandedCookie expanded=(DefaultExpandedCookie)
99             inlineNode.getCookie(DefaultExpandedCookie.class);
100             if (expanded!=null)
101                 expanded.setDefaultExpanded(true);
102             
103             keys.add(index++,inlineNode);
104         }
105         if(definition instanceof SimpleTypeRestriction) {
106             // add enum children
107
java.util.List JavaDoc<Enumeration> enumChildren =
108                     definition.getChildren(Enumeration.class);
109             for(Enumeration e:enumChildren) {
110                 keys.add(index++,getContext().getFactory().createNode(e));
111             }
112         }
113         return keys;
114     }
115 }
116
Popular Tags