KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > 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.wsdl.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.wsdl.model.WSDLModel;
33 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.WSDLDataObject;
34 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.NodesFactory;
35 import org.netbeans.modules.xml.xam.Component;
36 import org.netbeans.modules.xml.xam.Model;
37 import org.netbeans.modules.xml.xam.ModelSource;
38 import org.openide.filesystems.FileObject;
39 import org.openide.loaders.DataObject;
40 import org.openide.nodes.Node;
41 import org.openide.util.Utilities;
42 import org.openide.util.lookup.Lookups;
43
44 /**
45  *
46  * @author Sonali Kochar
47  */

48 public class ComponentTreeElement implements TreeElement {
49     
50    Node node;
51    Object JavaDoc parent;
52    Component comp;
53      
54        
55     ComponentTreeElement(Object JavaDoc element) {
56         comp = (Component)element;
57        
58         try {
59             Model model = comp.getModel();
60             if(model instanceof WSDLModel) {
61                 ModelSource ms = model.getModelSource();
62                 FileObject fo = (FileObject) ms.getLookup().lookup(FileObject.class);
63                     if(fo != null) {
64                         DataObject dObj = DataObject.find(fo);
65                         if(dObj != null && dObj instanceof WSDLDataObject) {
66                             node = NodesFactory.getInstance().create(comp);
67                     }
68                 }
69             }
70         }catch (Exception JavaDoc e){
71             e.printStackTrace();
72         }
73     }
74     
75     public TreeElement getParent(boolean isLogical) {
76         if(parent instanceof ComponentTreeElement)
77            return (ComponentTreeElement)parent;
78        else
79            return TreeElementFactory.getTreeElement((FileObject)parent);
80        
81     }
82     
83    void setParent(Object JavaDoc p) {
84         this.parent = p;
85     }
86      
87  
88     public Icon JavaDoc getIcon() {
89         if(node != null)
90             return new ImageIcon JavaDoc(node.getIcon(BeanInfo.ICON_COLOR_16x16));
91         else
92             return new ImageIcon JavaDoc(
93                 Utilities.loadImage(
94                 "org/netbeans/modules/xml/wsdl/ui/netbeans/module/resources/"+
95                 "columns_view.png"));
96     }
97
98     public String JavaDoc getText(boolean isLogical) {
99         if(node != null)
100             return node.getName();
101         else
102             return "";
103         
104     }
105
106     public Object JavaDoc getUserObject() {
107         return comp;
108                 
109     }
110 }
111
Popular Tags