KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.List JavaDoc;
25 import org.openide.nodes.Node;
26 import org.openide.util.Lookup;
27
28 import org.netbeans.modules.xml.schema.model.AppInfo;
29 import org.netbeans.modules.xml.schema.ui.basic.spi.AppInfoProvider;
30 import org.netbeans.modules.xml.schema.ui.nodes.SchemaComponentNode;
31 import org.netbeans.modules.xml.schema.ui.nodes.ReferencingNodeProvider;
32 import org.netbeans.modules.xml.schema.model.Annotation;
33 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
34 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext;
35
36 /**
37  *
38  * @author Ajit Bhate
39  */

40 public class AnnotationChildren extends CategorizedChildren<Annotation> {
41     public AnnotationChildren(SchemaUIContext context,
42             SchemaComponentReference<Annotation> reference) {
43         super(context,reference);
44     }
45     
46     
47     /**
48      *
49      *
50      */

51     protected List JavaDoc<Node> createKeys() {
52         List JavaDoc<Node> keys=super.createKeys();
53         Lookup.Result providerLookups =
54                 Lookup.getDefault().lookup(new Lookup.Template(AppInfoProvider.class));
55         Collection JavaDoc providers = providerLookups.allInstances();
56         if (providers != null && !providers.isEmpty()) {
57             ArrayList JavaDoc<Node> customNodes = new ArrayList JavaDoc<Node>();
58             ArrayList JavaDoc<AppInfo> customAppInfos = new ArrayList JavaDoc<AppInfo>();
59             Node parent = getNode();
60             if(parent!=null) {
61                 SchemaComponentNode scn = (SchemaComponentNode)parent.getCookie
62                         (SchemaComponentNode.class);
63                 if(scn!=null) {
64                 ArrayList JavaDoc<Node> path = new ArrayList JavaDoc<Node>();
65                     path.add(parent);
66                     while(true) {
67                         parent = parent.getParentNode();
68                         if(parent == null) {
69                             ReferencingNodeProvider refProvider =
70                                     (ReferencingNodeProvider)path.get(0).getLookup().
71                                     lookup(ReferencingNodeProvider.class);
72                             if(refProvider!=null) parent = refProvider.getNode();
73                         }
74                         if (parent == null) break;
75                         path.add(0,parent);
76                     }
77                     for(Object JavaDoc provider:providers) {
78                         Node customNode = null;
79                         AppInfoProvider aiProvider = (AppInfoProvider)provider;
80                         if(aiProvider.isActive(getReference().get().getModel()) &&
81                                 (customNode = aiProvider.getNode(path))!=null) {
82                             customNodes.add(customNode);
83                             AppInfo customAppInfo = (AppInfo)customNode.
84                                     getLookup().lookup(AppInfo.class);
85                             if(customAppInfo!=null)
86                                 customAppInfos.add(customAppInfo);
87                         }
88                     }
89                 }
90             }
91             for(int idx = keys.size(); idx>0; idx--) {
92                 Node n = keys.get(idx-1);
93                 SchemaComponentNode scn = (SchemaComponentNode)n.getCookie
94                         (SchemaComponentNode.class);
95                 if(scn!=null && scn.getReference().get() instanceof AppInfo) {
96                     AppInfo appInfo = (AppInfo)scn.getReference().get();
97                     if(customAppInfos.contains(appInfo)) keys.remove(n);
98                 }
99             }
100             keys.addAll(customNodes);
101         }
102         
103         return keys;
104     }
105 }
106
Popular Tags