KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > refactoring > query > views > ResultsPanel


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

19
20 /*
21  * ResultsPanel.java
22  *
23  * Created on July 14, 2006, 4:30 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.refactoring.query.views;
30
31 import java.awt.BorderLayout JavaDoc;
32 import java.awt.Dimension JavaDoc;
33 import java.awt.event.ComponentAdapter JavaDoc;
34 import java.awt.event.ComponentEvent JavaDoc;
35 import java.beans.PropertyChangeEvent JavaDoc;
36 import java.beans.PropertyChangeListener JavaDoc;
37 import javax.swing.JComponent JavaDoc;
38 import javax.swing.JPanel JavaDoc;
39 import javax.swing.KeyStroke JavaDoc;
40 import javax.swing.SwingUtilities JavaDoc;
41 import javax.swing.tree.TreeSelectionModel JavaDoc;
42 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
43 import org.openide.explorer.ExplorerManager;
44 import org.openide.explorer.view.BeanTreeView;
45 import org.openide.nodes.Children;
46 import org.openide.nodes.Node;
47 import org.openide.windows.TopComponent;
48 import org.netbeans.modules.xml.schema.refactoring.SchemaUIHelper.FilteredSchemaNode;
49
50 /**
51  *
52  * @author Jeri Lockhart
53  */

54 public class ResultsPanel extends JPanel JavaDoc implements ExplorerManager.Provider,
55              PropertyChangeListener JavaDoc{
56         
57         private ExplorerManager explorerManager;
58         private static final long serialVersionUID = 1L;
59         private TView treeView;
60         
61         public ResultsPanel(Node root) {
62             super();
63             initialize(root);
64         }
65         
66         
67         private void initialize(Node root) {
68 // nodePreferredAction = new WhereUsedAction(customizer.getColView());
69
explorerManager = new ExplorerManager();
70             removeAll();
71             setPreferredSize(new Dimension JavaDoc(200,200));
72             setLayout(new BorderLayout JavaDoc());
73             treeView=new TView();
74             treeView.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
75             treeView.setRootVisible(true);
76             treeView.setDefaultActionAllowed(true);
77             Object JavaDoc key = "org.openide.actions.PopupAction";
78             KeyStroke JavaDoc ks = KeyStroke.getKeyStroke("shift F10");
79             treeView.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(ks, key);
80             
81             add(treeView,BorderLayout.CENTER);
82             explorerManager.setRootContext(root);
83             explorerManager.addPropertyChangeListener(this);
84             
85             addComponentListener(new ComponentAdapter JavaDoc(){
86                 public void componentResized(ComponentEvent JavaDoc e) {
87                     // Don't expand nodes if scrolling will be needed
88
// Nodes for Primitive types are not expanded
89
removeComponentListener(this); // only check once
90
// System.out.println("WhereUsedExplorer component listener removed.");
91

92                     int rh = treeView.getRowHeight();
93                     Node root = explorerManager.getRootContext();
94                     int count = getRowCount(root);
95 // int totalH = rh * count;
96
// if (d.height > totalH){
97
// expand nodes
98
Node[] catNodes = root.getChildren().getNodes();
99                         for (int i = 0; i < catNodes.length;i++) {
100                                 treeView.expandNode(catNodes[i]);
101                         }
102 // }
103
}
104             });
105             
106         }
107         
108         private int getRowCount(Node root){
109             int count = 0;
110             if (root != null){
111                 count++;
112             }
113             else return count;
114             Children children = root.getChildren();
115             if (children != null){
116                 Node[] catNodes = children.getNodes();
117                 for (Node n:catNodes){
118                     count++;
119                     Children unusedCh = n.getChildren();
120                     if (unusedCh != null){
121                         count += unusedCh.getNodesCount();
122                     }
123                 }
124             }
125             return count;
126         }
127         
128         
129         
130         ///////////////////////////////////////////////////////////////////////
131
// Implement ExplorerManager.Provider
132
///////////////////////////////////////////////////////////////////////
133
public ExplorerManager getExplorerManager() {
134             return explorerManager;
135         }
136         
137         
138         
139         ////////////////////////////////////////////////////////////////////
140
// Implement PropertyChangeListener
141
////////////////////////////////////////////////////////////////////
142
public void propertyChange(PropertyChangeEvent JavaDoc evt){
143             if(ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())){
144                 Node[] selNodes = (Node[]) evt.getNewValue();
145                 TopComponent parent = (TopComponent)SwingUtilities.
146                         getAncestorOfClass(TopComponent.class,treeView);
147                 if (parent != null){
148                     parent.setActivatedNodes(selNodes);
149                 }
150             }
151         }// end propertyChange()
152

153         
154     public class TView extends BeanTreeView{
155         public static final long serialVersionUID = 1L;
156         
157         public TView(){
158             super();
159         }
160         
161         public int getRowHeight() {
162             return tree.getRowHeight();
163         }
164     }
165     }
166
167
168
Popular Tags