KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
23 import org.openide.nodes.Node;
24 import org.openide.util.NbBundle;
25 import org.netbeans.modules.xml.schema.model.SchemaComponent;
26 import org.netbeans.modules.xml.schema.model.ComplexContent;
27 import org.netbeans.modules.xml.schema.model.ComplexContentDefinition;
28 import org.netbeans.modules.xml.schema.model.ComplexContentRestriction;
29 import org.netbeans.modules.xml.schema.model.ComplexExtension;
30 import org.netbeans.modules.xml.schema.model.ComplexType;
31 import org.netbeans.modules.xml.schema.model.ComplexTypeDefinition;
32 import org.netbeans.modules.xml.schema.model.GlobalType;
33 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
34 import org.netbeans.modules.xml.schema.model.SimpleContent;
35 import org.netbeans.modules.xml.schema.model.SimpleContentDefinition;
36 import org.netbeans.modules.xml.schema.model.SimpleContentRestriction;
37 import org.netbeans.modules.xml.schema.model.SimpleExtension;
38 import org.netbeans.modules.xml.schema.ui.nodes.SchemaComponentNode;
39 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext;
40
41 /**
42  *
43  * @author Ajit Bhate
44  */

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

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

62     protected List JavaDoc<Node> createKeys() {
63         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         SchemaComponent extensionOrRestriction = null;
72         GlobalType extensionBase = null;
73         ComplexType type = getReference().get();
74         if (type.getModel() == null) {
75             // Without a model, this will all fail.
76
return keys;
77         }
78         ComplexTypeDefinition definition = type.getDefinition();
79         if(definition instanceof ComplexContent) {
80             ComplexContentDefinition contentDef =
81                     ((ComplexContent)definition).getLocalDefinition();
82             if (contentDef instanceof ComplexContentRestriction) {
83                 extensionOrRestriction = contentDef;
84             }
85             if (contentDef instanceof ComplexExtension) {
86                 extensionOrRestriction = contentDef;
87                 ComplexExtension ce = (ComplexExtension)extensionOrRestriction;
88                 if(ce.getBase()!=null) extensionBase = ce.getBase().get();
89             }
90         } else if(definition instanceof SimpleContent) {
91             SimpleContentDefinition contentDef =
92                     ((SimpleContent)definition).getLocalDefinition();
93             if (contentDef instanceof SimpleContentRestriction) {
94                 extensionOrRestriction = contentDef;
95             }
96             if (contentDef instanceof SimpleExtension) {
97                 extensionOrRestriction = contentDef;
98                 SimpleExtension ce = (SimpleExtension)extensionOrRestriction;
99                 if(ce.getBase()!=null) extensionBase = ce.getBase().get();
100             }
101         }
102         if(definition instanceof ComplexContent ||
103                 definition instanceof SimpleContent) {
104             for (int i=0;i<keys.size();i++) {
105                 Node n = keys.get(i);
106                 SchemaComponentNode scn = (SchemaComponentNode)n.getCookie
107                         (SchemaComponentNode.class);
108                 if(scn!=null && scn.getReference().get()==definition) {
109                     index = i;
110                     keys.remove(index);
111                     break;
112                 }
113             }
114         }
115         if(extensionOrRestriction!= null) {
116             if(extensionBase!=null) {
117             keys.add(index++, new ReadOnlySchemaComponentNode(
118                     getContext().getFactory().createNode(extensionBase),
119                     NbBundle.getMessage(ComplexTypeChildren.class,
120                     "LBL_InheritedFrom")));
121             }
122             for (SchemaComponent c : extensionOrRestriction.getChildren()) {
123                 Node cNode = getContext().getFactory().createNode(c);
124                 keys.add(index++,cNode);
125             }
126         }
127         return keys;
128     }
129 }
130
Popular Tags