1 19 package org.netbeans.modules.java.debug; 20 21 import com.sun.source.util.TreePath; 22 import java.awt.BorderLayout ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import javax.swing.ActionMap ; 28 import javax.swing.JComponent ; 29 import javax.swing.JPanel ; 30 import javax.swing.ListSelectionModel ; 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 48 public class TreeNavigatorProviderImpl implements NavigatorPanel { 49 50 private JComponent panel; 51 private final ExplorerManager manager = new ExplorerManager(); 52 53 56 public TreeNavigatorProviderImpl() { 57 manager.addPropertyChangeListener(new PropertyChangeListener () { 58 public void propertyChange(PropertyChangeEvent 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 <Highlight> result = new ArrayList <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); } 74 } 75 }); 76 } 77 78 public String getDisplayName() { 79 return NbBundle.getMessage(TreeNavigatorProviderImpl.class, "NM_Trees"); 80 } 81 82 public String getDisplayHint() { 83 return NbBundle.getMessage(TreeNavigatorProviderImpl.class, "SD_Trees"); 84 } 85 86 public JComponent 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 implements ExplorerManager.Provider, Lookup.Provider { 92 private final Lookup lookup = ExplorerUtils.createLookup(manager, new ActionMap ()); 94 { 95 setLayout(new BorderLayout ()); 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 (); 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 |