KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > nodes > ContentModelNode


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 package org.netbeans.modules.xml.schema.abe.nodes;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23 import org.netbeans.modules.xml.axi.AXIContainer;
24 import org.netbeans.modules.xml.axi.Compositor;
25 import org.netbeans.modules.xml.axi.ContentModel;
26 import org.netbeans.modules.xml.schema.abe.InstanceUIContext;
27 import org.netbeans.modules.xml.schema.abe.action.AttributeOnElementNewType;
28 import org.netbeans.modules.xml.schema.abe.action.CompositorOnElementNewType;
29 import org.netbeans.modules.xml.schema.abe.action.ElementOnElementNewType;
30 import org.netbeans.modules.xml.schema.abe.nodes.properties.BaseABENodeProperty;
31 import org.openide.nodes.Sheet;
32 import org.openide.util.NbBundle;
33 import org.openide.util.datatransfer.NewType;
34
35 /**
36  *
37  * @author Samaresh (Samaresh.Panda@Sun.Com)
38  */

39 public class ContentModelNode extends ABEAbstractNode {
40     
41     
42     /**
43      * Creates a new instance of ContentModelNode
44      */

45     public ContentModelNode(ContentModel contentModel, InstanceUIContext context) {
46         super(contentModel, context);
47     }
48     
49     public ContentModelNode(ContentModel contentModel) {
50         super(contentModel,new ABENodeChildren(contentModel));
51         setIconBaseWithExtension(
52                 "org/netbeans/modules/xml/schema/abe/resources/complextype.png");
53         
54     }
55     
56     protected void populateProperties(Sheet sheet) {
57         Sheet.Set set = sheet.get(Sheet.PROPERTIES);
58         if(set == null) {
59             set = sheet.createPropertiesSet();
60         }
61         
62         try {
63             BaseABENodeProperty property = new BaseABENodeProperty(
64                     this,
65                     String JavaDoc.class,
66                     ContentModel.PROP_NAME,
67                     NbBundle.getMessage(ContentModelNode.class, "PROP_ContentModelNode_Name"),
68                     NbBundle.getMessage(ContentModelNode.class, "PROP_ContentModelNode_NameDesc"));
69             set.put(property);
70         } catch (Exception JavaDoc ex) {
71         }
72         
73         sheet.put(set);
74     }
75     
76     public String JavaDoc getName(){
77         if((ContentModel) super.getAXIComponent() != null)
78             return ((ContentModel) super.getAXIComponent()).getName();
79         else
80             return "";
81     }
82     
83     public NewType[] getNewTypes() {
84         if(getAXIComponent().isReadOnly())
85             return new NewType[0];
86         List JavaDoc<NewType> ntl = new ArrayList JavaDoc<NewType>();
87         NewType nt = new ElementOnElementNewType(getContext());
88         ntl.add(nt);
89         nt = new AttributeOnElementNewType(getContext());
90         ntl.add(nt);
91         if( ((AXIContainer)getAXIComponent()).getCompositor() == null ){
92             nt = new CompositorOnElementNewType(getContext(), Compositor.
93                     CompositorType.SEQUENCE);
94             ntl.add(nt);
95             nt = new CompositorOnElementNewType(getContext(), Compositor.
96                     CompositorType.CHOICE);
97             ntl.add(nt);
98             nt = new CompositorOnElementNewType(getContext(), Compositor.
99                     CompositorType.ALL);
100             ntl.add(nt);
101         }
102         return ntl.toArray(new NewType[ntl.size()]);
103     }
104     
105     protected String JavaDoc getTypeDisplayName() {
106     return NbBundle.getMessage(AttributeNode.class,"LBL_ComplexType");
107     }
108 }
109
Popular Tags