KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > debug > TreeNavigatorProviderImpl


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 package org.netbeans.modules.java.debug;
20
21 import com.sun.source.util.TreePath;
22 import java.awt.BorderLayout JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27 import javax.swing.ActionMap JavaDoc;
28 import javax.swing.JComponent JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.ListSelectionModel JavaDoc;
31 import org.netbeans.api.java.source.CancellableTask;
32 import org.netbeans.api.java.source.CompilationInfo;
33 import org.netbeans.modules.editor.highlights.spi.Highlight;
34 import org.netbeans.modules.editor.highlights.spi.Highlighter;
35 import org.netbeans.spi.navigator.NavigatorPanel;
36 import org.openide.explorer.ExplorerManager;
37 import org.openide.explorer.ExplorerUtils;
38 import org.openide.explorer.view.BeanTreeView;
39 import org.openide.filesystems.FileObject;
40 import org.openide.nodes.Node;
41 import org.openide.util.Lookup;
42 import org.openide.util.NbBundle;
43
44 /**
45  *
46  * @author Jan Lahoda
47  */

48 public class TreeNavigatorProviderImpl implements NavigatorPanel {
49     
50     private JComponent JavaDoc panel;
51     private final ExplorerManager manager = new ExplorerManager();
52     
53     /**
54      * Default constructor for layer instance.
55      */

56     public TreeNavigatorProviderImpl() {
57         manager.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
58             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
59                 if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
60                     FileObject file = TreeNavigatorJavaSourceFactory.getInstance().getFile();
61                     
62                     if (file == null)
63                         return ;
64                     
65                     List JavaDoc<Highlight> result = new ArrayList JavaDoc<Highlight>();
66                     
67                     for (Node n : manager.getSelectedNodes()) {
68                         if (n instanceof Highlight)
69                             result.add((Highlight) n);
70                     }
71                     
72                     Highlighter.getDefault().setHighlights(file, "tree", result); //NOI18N
73
}
74             }
75         });
76     }
77     
78     public String JavaDoc getDisplayName() {
79         return NbBundle.getMessage(TreeNavigatorProviderImpl.class, "NM_Trees");
80     }
81     
82     public String JavaDoc getDisplayHint() {
83         return NbBundle.getMessage(TreeNavigatorProviderImpl.class, "SD_Trees");
84     }
85     
86     public JComponent JavaDoc getComponent() {
87         if (panel == null) {
88             final BeanTreeView view = new BeanTreeView();
89             view.setRootVisible(true);
90             view.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
91             class Panel extends JPanel JavaDoc implements ExplorerManager.Provider, Lookup.Provider {
92                 // Make sure action context works correctly:
93
private final Lookup lookup = ExplorerUtils.createLookup(manager, new ActionMap JavaDoc());
94                 {
95                     setLayout(new BorderLayout JavaDoc());
96                     add(view, BorderLayout.CENTER);
97                 }
98                 public ExplorerManager getExplorerManager() {
99                     return manager;
100                 }
101                 public Lookup getLookup() {
102                     return lookup;
103                 }
104             }
105             panel = new Panel JavaDoc();
106         }
107         return panel;
108     }
109     
110     public Lookup getLookup() {
111         return null;
112     }
113
114     public void panelActivated(Lookup context) {
115         TreeNavigatorJavaSourceFactory.getInstance().setLookup(context, new TaskImpl());
116     }
117
118     public void panelDeactivated() {
119         TreeNavigatorJavaSourceFactory.getInstance().setLookup(Lookup.EMPTY, null);
120     }
121
122     private final class TaskImpl implements CancellableTask<CompilationInfo> {
123         
124         public void cancel() {
125         }
126
127         public void run(CompilationInfo info) {
128             manager.setRootContext(TreeNode.getTree(info, new TreePath(info.getCompilationUnit())));
129         }
130         
131     }
132     
133 }
134
Popular Tags