KickJava   Java API By Example, From Geeks To Geeks.

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


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.openide.nodes.Children;
23 import org.openide.util.NbBundle;
24 import org.netbeans.modules.xml.xam.ComponentEvent;
25 import org.netbeans.modules.xml.schema.model.ComplexContentDefinition;
26 import org.netbeans.modules.xml.schema.model.ComplexContentRestriction;
27 import org.netbeans.modules.xml.schema.model.ComplexExtension;
28 import org.netbeans.modules.xml.schema.model.GlobalType;
29 import org.netbeans.modules.xml.schema.model.SimpleContentRestriction;
30 import org.netbeans.modules.xml.schema.model.SimpleExtension;
31 import org.netbeans.modules.xml.schema.model.ComplexContent;
32 import org.netbeans.modules.xml.schema.model.ComplexTypeDefinition;
33 import org.netbeans.modules.xml.schema.model.LocalComplexType;
34 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
35 import org.netbeans.modules.xml.schema.model.SimpleContent;
36 import org.netbeans.modules.xml.schema.ui.nodes.NewTypesFactory;
37 import org.netbeans.modules.xml.schema.ui.nodes.RefreshableChildren;
38 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext;
39 import org.netbeans.modules.xml.schema.ui.nodes.schema.LocalComplexTypeNode;
40 import org.netbeans.modules.xml.schema.ui.nodes.categorized.customizer.ComplexTypeCustomizer;
41 import org.netbeans.modules.xml.xam.ui.customizer.Customizer;
42 import org.netbeans.modules.xml.xam.ui.customizer.CustomizerProvider;
43
44 /**
45  *
46  * @author Todd Fast, todd.fast@sun.com
47  */

48 public class AdvancedLocalComplexTypeNode extends LocalComplexTypeNode {
49     /**
50      *
51      *
52      */

53     public AdvancedLocalComplexTypeNode(SchemaUIContext context,
54             SchemaComponentReference<LocalComplexType> reference,
55             Children children) {
56         super(context,reference,children);
57     }
58     
59     
60     public void childrenAdded(ComponentEvent evt) {
61         if (! isValid()) return;
62         super.childrenAdded(evt);
63         Object JavaDoc source = evt.getSource();
64         LocalComplexType type = getReference().get();
65         ComplexTypeDefinition definition = type.getDefinition();
66         if(source == type || source == definition) {
67             fireDisplayNameChange(null,getDisplayName());
68         }
69         if(definition instanceof ComplexContent) {
70             if(source == definition ||
71                     source == ((ComplexContent)definition).getLocalDefinition()) {
72                 ((RefreshableChildren) getChildren()).refreshChildren();
73             }
74             if(source == type || source == definition) {
75                 fireDisplayNameChange(null,getDisplayName());
76             }
77         } else if(definition instanceof SimpleContent) {
78             if(source == definition ||
79                     source == ((SimpleContent)definition).getLocalDefinition()) {
80                 ((RefreshableChildren) getChildren()).refreshChildren();
81             }
82         }
83     }
84     
85     public void childrenDeleted(ComponentEvent evt) {
86         if (! isValid()) return;
87         super.childrenDeleted(evt);
88         Object JavaDoc source = evt.getSource();
89         LocalComplexType type = getReference().get();
90         ComplexTypeDefinition definition = type.getDefinition();
91         if(source == type || source == definition) {
92             fireDisplayNameChange(null,getDisplayName());
93         }
94         if(definition instanceof ComplexContent) {
95             if(source == definition ||
96                     source == ((ComplexContent)definition).getLocalDefinition()) {
97                 ((RefreshableChildren) getChildren()).refreshChildren();
98             }
99         } else if(definition instanceof SimpleContent) {
100             if(source == definition ||
101                     source == ((SimpleContent)definition).getLocalDefinition()) {
102                 ((RefreshableChildren) getChildren()).refreshChildren();
103             }
104         }
105     }
106     
107     public void valueChanged(ComponentEvent evt) {
108         if (! isValid()) return;
109         super.valueChanged(evt);
110         Object JavaDoc source = evt.getSource();
111         LocalComplexType type = getReference().get();
112         ComplexTypeDefinition definition = type.getDefinition();
113         if(definition instanceof ComplexContent) {
114             ComplexContentDefinition contentDef =
115                     ((ComplexContent)definition).getLocalDefinition();
116             if(source == contentDef) {
117                 fireDisplayNameChange(null,getDisplayName());
118                 if(contentDef instanceof ComplexExtension) {
119                     ((RefreshableChildren) getChildren()).refreshChildren();
120                 }
121             }
122         } else if(definition instanceof SimpleContent) {
123             if(source == ((SimpleContent)definition).getLocalDefinition()) {
124                 fireDisplayNameChange(null,getDisplayName());
125             }
126         }
127     }
128     
129     /**
130      *
131      *
132      */

133     @Override JavaDoc
134     protected NewTypesFactory getNewTypesFactory() {
135         return new AdvancedNewTypesFactory();
136     }
137     
138     @Override JavaDoc
139     public boolean hasCustomizer() {
140         return isEditable();
141     }
142     
143     public CustomizerProvider getCustomizerProvider() {
144         return new CustomizerProvider() {
145             
146             public Customizer getCustomizer() {
147                 return new ComplexTypeCustomizer<LocalComplexType>(getReference());
148             }
149         };
150     }
151     
152     public String JavaDoc getHtmlDisplayName() {
153         GlobalType gt = getSuperDefinition();
154         if(gt == null) return super.getHtmlDisplayName();
155         String JavaDoc retValue = getDefaultDisplayName();
156         ComplexTypeDefinition definition = getReference().get().getDefinition();
157         String JavaDoc supertypeLabel = null;
158         if(definition instanceof ComplexContent &&
159                 ((ComplexContent)definition).getLocalDefinition()
160                 instanceof ComplexContentRestriction ||
161                 definition instanceof SimpleContent &&
162                 ((SimpleContent)definition).getLocalDefinition()
163                 instanceof SimpleContentRestriction) {
164             supertypeLabel = NbBundle.getMessage(AdvancedGlobalComplexTypeNode.class,
165                     "LBL_ComplexType_Restriction",gt.getName());
166         } else if(definition instanceof ComplexContent &&
167                 ((ComplexContent)definition).getLocalDefinition()
168                 instanceof ComplexExtension ||
169                 definition instanceof SimpleContent &&
170                 ((SimpleContent)definition).getLocalDefinition()
171                 instanceof SimpleExtension) {
172             supertypeLabel = NbBundle.getMessage(AdvancedGlobalComplexTypeNode.class,
173                     "LBL_ComplexType_Extension",gt.getName());
174         }
175         if(supertypeLabel!=null) {
176             retValue = retValue+"<font color='#999999'> ("+supertypeLabel+")</font>";
177         }
178         return applyHighlights(retValue);
179     }
180 }
181
Popular Tags