KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > tree > ComponentTreeElement


1
2 /*
3  * The contents of this file are subject to the terms of the Common Development
4  * and Distribution License (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
8  * or http://www.netbeans.org/cddl.txt.
9  *
10  * When distributing Covered Code, include this CDDL Header Notice in each file
11  * and include the License file at http://www.netbeans.org/cddl.txt.
12  * If applicable, add the following below the CDDL Header, with the fields
13  * enclosed by brackets [] replaced by your own identifying information:
14  * "Portions Copyrighted [year] [name of copyright owner]"
15  *
16  * The Original Software is NetBeans. The Initial Developer of the Original
17  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
18  * Microsystems, Inc. All Rights Reserved.
19  */

20
21 package org.netbeans.modules.xml.schema.ui.tree;
22
23 import java.beans.BeanInfo JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.Icon JavaDoc;
26 import javax.swing.ImageIcon JavaDoc;
27
28 import org.netbeans.modules.refactoring.api.RefactoringElement;
29 import org.netbeans.modules.refactoring.spi.ui.TreeElement;
30 import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
31 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
32 import org.netbeans.modules.xml.refactoring.spi.UIHelper;
33 import org.netbeans.modules.xml.schema.model.SchemaComponent;
34 import org.netbeans.modules.xml.schema.model.SchemaModel;
35 import org.netbeans.modules.xml.schema.ui.nodes.categorized.CategorizedSchemaNodeFactory;
36 import org.netbeans.modules.xml.xam.Component;
37 import org.openide.filesystems.FileObject;
38 import org.openide.nodes.Node;
39 import org.openide.util.Utilities;
40 import org.openide.util.lookup.Lookups;
41
42 /**
43  *
44  * @author Sonali Kochar
45  */

46 public class ComponentTreeElement implements TreeElement {
47     
48    Node node;
49    Object JavaDoc parent;
50    Component comp;
51      
52        
53     ComponentTreeElement(Object JavaDoc element) {
54         comp = (Component)element;
55         if(comp == null)
56             System.out.println("COMPONENT TREE ELEMENT IS NULL???");
57         else
58             System.out.println("The class is " + comp.getClass().getName());
59         CategorizedSchemaNodeFactory nodeFactory = new CategorizedSchemaNodeFactory((SchemaModel) comp.getModel(), Lookups.singleton(comp));
60         this.node = nodeFactory.createNode((SchemaComponent) comp);
61     }
62     
63     public TreeElement getParent(boolean isLogical) {
64         if(parent instanceof ComponentTreeElement)
65            return (ComponentTreeElement)parent;
66        else
67            return TreeElementFactory.getTreeElement((FileObject)parent);
68        
69     }
70     
71    void setParent(Object JavaDoc p) {
72         this.parent = p;
73     }
74      
75  
76     public Icon JavaDoc getIcon() {
77         return new ImageIcon JavaDoc(node.getIcon(BeanInfo.ICON_COLOR_16x16));
78     }
79
80     public String JavaDoc getText(boolean isLogical) {
81           return node.getName();
82     }
83
84     public Object JavaDoc getUserObject() {
85         return comp;
86                 
87     }
88 }
89
Popular Tags