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 ElementNavigatorProviderImpl implements NavigatorPanel { 49 50 private JComponent panel; 51 private final ExplorerManager manager = new ExplorerManager(); 52 53 56 public ElementNavigatorProviderImpl() { 57 manager.addPropertyChangeListener(new PropertyChangeListener () { 58 public void propertyChange(PropertyChangeEvent evt) { 59 if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { 60 List <Highlight> result = new ArrayList <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); } 72 } 73 }); 74 } 75 76 public String getDisplayName() { 77 return NbBundle.getMessage(ElementNavigatorProviderImpl.class, "NM_Elements"); 78 } 79 80 public String getDisplayHint() { 81 return NbBundle.getMessage(ElementNavigatorProviderImpl.class, "SD_Elements"); 82 } 83 84 public JComponent 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 implements ExplorerManager.Provider, Lookup.Provider { 90 private final Lookup lookup = ExplorerUtils.createLookup(manager, new ActionMap ()); 92 { 93 setLayout(new BorderLayout ()); 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 (); 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 |