KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > ui > nodes > elements > EnumChildren


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.ui.nodes.elements;
21
22 import org.netbeans.modules.java.ui.nodes.SourceNodeFactory;
23 import org.netbeans.jmi.javamodel.JavaEnum;
24 import org.netbeans.jmi.javamodel.EnumConstant;
25 import org.openide.nodes.Node;
26
27 import javax.jmi.reflect.JmiException;
28 import java.util.Collection JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.LinkedList JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 /**
34  * implementation of children list for an enum element node
35  */

36 public final class EnumChildren extends ClassChildren {
37     public EnumChildren(SourceNodeFactory factory, JavaEnum element) {
38         super(factory, element);
39     }
40
41     public Class JavaDoc getFilterClass() {
42         return EnumFilter.class;
43     }
44
45     protected Node[] createNodesImpl(Object JavaDoc key) throws JmiException {
46         if (key instanceof EnumConstant) {
47             EnumConstant ec = (EnumConstant) key;
48             hookNodeName(ec);
49             return new Node[] { getFactory().createEnumConstantNode(ec) };
50         }
51         
52         return super.createNodesImpl(key);
53     }
54
55     protected List JavaDoc getKeysOfType(Collection JavaDoc/*<ClassMemeber>*/ elements, int elementType) {
56         // here collect constants
57
List JavaDoc keys;
58         if ((elementType & EnumFilter.CONSTANTS) != 0) {
59             keys = new LinkedList JavaDoc();
60             for (Iterator JavaDoc it = elements.iterator(); it.hasNext();) {
61                 Object JavaDoc member = it.next();
62                 if ((elementType & EnumFilter.CONSTANTS) != 0 && member instanceof EnumConstant) {
63                     keys.add(member);
64                 }
65             }
66         } else {
67             keys = super.getKeysOfType(elements, elementType);
68         }
69         return keys;
70     }
71
72     protected int[] getOrder() {
73         return (filter == null || (filter.getOrder() == null))
74                ? EnumFilter.DEFAULT_ORDER : filter.getOrder();
75     }
76
77     protected void refreshAllKeys() {
78         refreshKeys(EnumFilter.ALL);
79     }
80 }
81
Popular Tags