KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > ExtensibilityElementsFolderNode


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 /*
21  * Created on May 17, 2005
22  *
23  * To change the template for this generated file go to
24  * Window - Preferences - Java - Code Generation - Code and Comments
25  */

26 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Set JavaDoc;
32
33 import org.netbeans.modules.xml.wsdl.model.Definitions;
34 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
35 import org.netbeans.modules.xml.wsdl.ui.cookies.AddChildWSDLElementCookie;
36 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
37 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory;
38 import org.openide.util.NbBundle;
39 import org.openide.util.datatransfer.NewType;
40
41 /**
42  * @author Ritesh Adval
43  *
44  *
45  */

46 public class ExtensibilityElementsFolderNode extends FolderNode {
47     
48     private Definitions mDef = null;
49     private Set JavaDoc<String JavaDoc> mSpecialTargetNamespaces;
50     
51     
52     public ExtensibilityElementsFolderNode(Definitions element) {
53         super(new ExtensibilityElementsFolderChildren(element),
54                 element, ExtensibilityElement.class);
55         mDef = element;
56         this.setDisplayName(NbBundle.
57                 getMessage(ExtensibilityElementsFolderNode.class,
58                 "EXTENSIBILITY_ELEMENTS_FOLDER_NODE_NAME"));
59         getLookupContents().add(new AddChildWSDLElementCookie(element));
60         this.addNodeListener(new WSDLNodeListener(this));
61     }
62     
63     public ExtensibilityElementsFolderNode(Definitions element, Set JavaDoc<String JavaDoc> specialTargetNamespaces) {
64         super(new ExtensibilityElementsFolderChildren(element, specialTargetNamespaces),
65                 element, ExtensibilityElement.class);
66         mDef = element;
67         mSpecialTargetNamespaces = specialTargetNamespaces;
68         this.setDisplayName(NbBundle.
69                 getMessage(ExtensibilityElementsFolderNode.class,
70                 "EXTENSIBILITY_ELEMENTS_FOLDER_NODE_NAME"));
71         getLookupContents().add(new AddChildWSDLElementCookie(element));
72         this.addNodeListener(new WSDLNodeListener(this));
73     }
74
75     
76     @Override JavaDoc
77     public final NewType[] getNewTypes() {
78         if (isEditable()) {
79             // hack for showing only partnerlink types in partner view.
80
// this filters the new types to be of only which are specified in mSpecialTargetNamespaces.
81
if (mSpecialTargetNamespaces != null && mSpecialTargetNamespaces.size() > 0) {
82                 return new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_DEFINITIONS,
83                         mSpecialTargetNamespaces.toArray(new String JavaDoc[mSpecialTargetNamespaces.size()])).getNewTypes(mDef);
84             }
85             return new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_DEFINITIONS).getNewTypes(mDef);
86         }
87         return new NewType[] {};
88     }
89     
90     
91     public Object JavaDoc getWSDLConstruct() {
92         return mDef;
93     }
94     
95     public static final class ExtensibilityElementsFolderChildren extends GenericWSDLComponentChildren {
96         private Set JavaDoc<String JavaDoc> specialTargetNS;
97         
98         public ExtensibilityElementsFolderChildren(Definitions definitions, Set JavaDoc<String JavaDoc> specialTargetNamespaces) {
99             super(definitions);
100             specialTargetNS = specialTargetNamespaces;
101         }
102         public ExtensibilityElementsFolderChildren(Definitions definitions) {
103             super(definitions);
104         }
105         
106         @Override JavaDoc
107         protected Collection JavaDoc getKeys() {
108             Definitions def = (Definitions) getWSDLComponent();
109             
110             List JavaDoc<ExtensibilityElement> list = def.getExtensibilityElements();
111             if (specialTargetNS == null) return list;
112             
113             List JavaDoc<ExtensibilityElement> finalList = new ArrayList JavaDoc<ExtensibilityElement>();
114             if (list != null) {
115                 for (ExtensibilityElement element : list) {
116                     if (specialTargetNS.contains(element.getQName().getNamespaceURI())) {
117                         continue;
118                     }
119                     finalList.add(element);
120                 }
121             }
122             return finalList;
123         }
124     }
125
126     @Override JavaDoc
127     public Class JavaDoc getType() {
128         return ExtensibilityElement.class;
129     }
130 }
131
132
Popular Tags