KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > nodes > IndexedNode


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 package org.openide.nodes;
20
21 import javax.swing.JPanel JavaDoc;
22
23
24 /** An implementation of a node that has children and
25 * supports reordering by providing Index implementor.
26 * Index implementor and children can be the same instance,
27 * allowing us to use either Index.ArrayChildren or Index.MapChildren
28 *
29 * @author Jaroslav Tulach, Dafe Simonek
30 */

31 public class IndexedNode extends AbstractNode {
32     /** Index implementation */
33     private Index indexImpl;
34
35     /** Create an indexed node. Uses {@link Index.ArrayChildren} to both
36     * hold the children, and as an implementation of {@link Index}.
37     */

38     public IndexedNode() {
39         super(new Index.ArrayChildren());
40         indexImpl = (Index) getChildren();
41     }
42
43     /** Allows subclasses to provide their own children and
44     * index handling.
45     * @param children the children implementation
46     * @param indexImpl the index implementation
47     */

48     protected IndexedNode(Children children, Index indexImpl) {
49         super(children);
50         this.indexImpl = indexImpl;
51     }
52
53     /*
54     * @return false to signal that the customizer should not be used.
55     * Subclasses can override this method to enable customize action
56     * and use customizer provided by this class.
57     */

58     public boolean hasCustomizer() {
59         return false;
60     }
61
62     /* Returns the customizer component.
63     * @return the component
64     */

65     public java.awt.Component JavaDoc getCustomizer() {
66         java.awt.Container JavaDoc c = new JPanel JavaDoc();
67         @SuppressWarnings JavaDoc("deprecation")
68         IndexedCustomizer customizer = new IndexedCustomizer(c, false);
69         customizer.setObject(indexImpl);
70
71         return c;
72     }
73
74     /** Get a cookie.
75     * @param clazz representation class
76     * @return the index implementation or children if these match the cookie class,
77     * else using the superclass cookie lookup
78     */

79     public <T extends Node.Cookie> T getCookie(Class JavaDoc<T> clazz) {
80         if (clazz.isInstance(indexImpl)) {
81             // ok, Index implementor is enough
82
return clazz.cast(indexImpl);
83         }
84
85         Children ch = getChildren();
86
87         if (clazz.isInstance(ch)) {
88             // ok, children are enough
89
return clazz.cast(ch);
90         }
91
92         return super.getCookie(clazz);
93     }
94 }
95
Popular Tags