KickJava   Java API By Example, From Geeks To Geeks.

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


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.beans.PropertyChangeEvent JavaDoc;
23 import org.netbeans.modules.xml.schema.model.LocalElement;
24 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
25 import org.netbeans.modules.xml.schema.ui.nodes.NewTypesFactory;
26 import org.netbeans.modules.xml.schema.ui.nodes.RefreshableChildren;
27 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext;
28 import org.netbeans.modules.xml.schema.ui.nodes.categorized.customizer.AdvancedLocalElementCustomizer;
29 import org.netbeans.modules.xml.schema.ui.nodes.schema.LocalElementNode;
30 import org.netbeans.modules.xml.xam.ui.customizer.Customizer;
31 import org.netbeans.modules.xml.xam.ui.customizer.CustomizerProvider;
32 import org.openide.nodes.Children;
33 import org.openide.util.NbBundle;
34
35 /**
36  *
37  * @author Todd Fast, todd.fast@sun.com
38  */

39 public class AdvancedLocalElementNode extends LocalElementNode {
40     /**
41      *
42      *
43      */

44     public AdvancedLocalElementNode(SchemaUIContext context,
45             SchemaComponentReference<LocalElement> reference,
46             Children children) {
47         super(context,reference,children);
48     }
49     
50     
51     /**
52      *
53      *
54      */

55     @Override JavaDoc
56     public String JavaDoc getHtmlDisplayName() {
57         LocalElement element=getReference().get();
58         
59         String JavaDoc max=element.getMaxOccursEffective();
60         if (max.equals("unbounded"))
61             max="*";
62         
63         String JavaDoc decoration="["+element.getMinOccursEffective()+".."+max+"]";
64         if(element.getType()!=null && element.getType().get()!=null) {
65             String JavaDoc supertypeLabel = NbBundle.getMessage(
66                     AdvancedLocalElementNode.class, "LBL_InstanceOf",
67                     element.getType().get().getName());
68             decoration = decoration+" ("+supertypeLabel+")";
69         }
70         String JavaDoc name = getDefaultDisplayName()+" <font color='#999999'>"+decoration+"</font>";
71         return applyHighlights(name);
72     }
73     
74     
75     /**
76      *
77      *
78      */

79     protected NewTypesFactory getNewTypesFactory() {
80         return new AdvancedNewTypesFactory();
81     }
82     
83     @Override JavaDoc
84     public boolean hasCustomizer() {
85         return isEditable();
86     }
87     
88     public CustomizerProvider getCustomizerProvider() {
89         return new CustomizerProvider() {
90             
91             public Customizer getCustomizer() {
92                 return new AdvancedLocalElementCustomizer(getReference());
93             }
94         };
95     }
96     
97     public void propertyChange(PropertyChangeEvent JavaDoc event) {
98         if(!isValid()) return;
99         super.propertyChange(event);
100         String JavaDoc property = event.getPropertyName();
101         if(event.getSource() == getReference().get()) {
102             if(LocalElement.TYPE_PROPERTY.equals(property)) {
103                 ((RefreshableChildren)getChildren()).refreshChildren();
104                 fireDisplayNameChange(null,getDisplayName());
105             }
106             if(LocalElement.MIN_OCCURS_PROPERTY.equals(property) ||
107                     LocalElement.MAX_OCCURS_PROPERTY.equals(property)) {
108                 fireDisplayNameChange(null,getDisplayName());
109             }
110         }
111     }
112     
113 }
114
Popular Tags