KickJava   Java API By Example, From Geeks To Geeks.

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


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