KickJava   Java API By Example, From Geeks To Geeks.

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


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.xml.schema.ui.tree;
21
22 import java.beans.BeanInfo JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27 import javax.swing.Icon JavaDoc;
28 import javax.swing.ImageIcon JavaDoc;
29
30 import org.netbeans.modules.refactoring.api.RefactoringElement;
31 import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
32 import org.netbeans.modules.refactoring.spi.ui.*;
33 import org.netbeans.modules.xml.refactoring.Usage;
34 import org.netbeans.modules.xml.refactoring.ui.readers.WhereUsedReader;
35 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
36 import org.netbeans.modules.xml.schema.model.SchemaComponent;
37 import org.netbeans.modules.xml.schema.ui.nodes.categorized.CategorizedSchemaNodeFactory;
38 import org.netbeans.modules.xml.xam.Component;
39 import org.netbeans.modules.xml.xam.Named;
40 import org.netbeans.modules.xml.xam.Referenceable;
41 import org.openide.nodes.Node;
42 import org.openide.util.NbBundle;
43 import org.openide.util.lookup.Lookups;
44
45 /**
46  *
47  * @author Jan Becicka
48  */

49 public class XMLSchemaTreeElement implements TreeElement {
50     
51     RefactoringElement element;
52     Usage usage;
53     Node node;
54     CategorizedSchemaNodeFactory nodeFactory;
55        
56     XMLSchemaTreeElement(RefactoringElement element) {
57         this.element = element;
58         this.usage = (Usage)element.getComposite();
59         Component component = usage.getComponent();
60         
61         assert component instanceof SchemaComponent:"This TreeElement handles SchemaComponents only";
62          
63         SchemaComponent sc = SchemaComponent.class.cast(component);
64         nodeFactory = new CategorizedSchemaNodeFactory(sc.getModel(), Lookups.singleton(sc));
65         this.node = nodeFactory.createNode(sc);
66         
67     }
68     
69     public TreeElement getParent(boolean isLogical) {
70          TreeElement result = null;
71          
72          List JavaDoc<Component> aPath = usage.getPathFromRoot();
73          Map JavaDoc<Component,ComponentTreeElement> componentsInModel = new HashMap JavaDoc<Component,ComponentTreeElement>();
74          for (int i = 0; i< aPath.size()-1; i++) {
75                 Component comp = aPath.get(i);
76                 ComponentTreeElement compElement = new ComponentTreeElement(comp);
77                 componentsInModel.put(comp, compElement);
78                 if (i==0){
79                     // the first Component in the path is a child of the file node
80
compElement.setParent(usage.getContainer().getFileObject());
81                 } else {
82                     ComponentTreeElement parentNode = null;
83                     Component parent = aPath.get(i-1);
84                     parentNode = componentsInModel.get(Component.class.cast(parent));
85                     assert parentNode != null:"The relevantPath is invalid";
86                     compElement.setParent(parentNode);
87                 }
88                 if(i == aPath.size()-2); {
89                     result=compElement;
90                 }
91                
92          }
93                  
94          return result;
95     }
96                 
97          
98  
99     public Icon JavaDoc getIcon() {
100        return new ImageIcon JavaDoc(node.getIcon(BeanInfo.ICON_COLOR_16x16));
101         
102     }
103
104     public String JavaDoc getText(boolean isLogical) {
105         String JavaDoc htmlDisplayName = node.getHtmlDisplayName();
106         String JavaDoc usageTreeNodeLabel =
107                             MessageFormat.format(
108                             NbBundle.getMessage(
109                             XMLSchemaTreeElement.class,
110                             "LBL_Usage_Node"),
111                             new Object JavaDoc[] {
112                         node.getName(),
113                         node.getShortDescription(), // comp type
114
htmlDisplayName==null?"":htmlDisplayName
115                     });
116         return usageTreeNodeLabel;
117         
118        
119        
120     }
121
122     public Object JavaDoc getUserObject() {
123        return element;
124     }
125 }
126
Popular Tags