1 19 20 package org.netbeans.modules.xml.text.navigator; 21 22 import java.util.Collection ; 23 import javax.swing.JComponent ; 24 import org.netbeans.spi.navigator.NavigatorPanel; 25 import org.openide.loaders.DataObject; 26 import org.openide.util.Lookup; 27 import org.openide.util.LookupEvent; 28 import org.openide.util.LookupListener; 29 import org.openide.util.NbBundle; 30 31 36 public class XMLNavigatorPanel implements NavigatorPanel { 37 38 private NavigatorContent navigator = NavigatorContent.getDefault(); 39 40 private Lookup.Result selection; 41 private final LookupListener selectionListener = new LookupListener() { 42 public void resultChanged(LookupEvent ev) { 43 navigate(selection.allInstances()); 44 } 45 }; 46 47 48 public XMLNavigatorPanel() { 49 } 50 51 public String getDisplayHint() { 52 return NbBundle.getMessage(XMLNavigatorPanel.class, "XML_files_navigator"); 53 } 54 55 public String getDisplayName() { 56 return NbBundle.getMessage(XMLNavigatorPanel.class, "XML_View"); 57 } 58 59 public JComponent getComponent() { 60 return navigator; 61 } 62 63 public Lookup getLookup() { 64 return null; 65 } 66 67 public void panelActivated(Lookup context) { 68 selection = context.lookup(new Lookup.Template(DataObject.class)); 69 selection.addLookupListener(selectionListener); 70 selectionListener.resultChanged(null); 71 } 72 73 public void panelDeactivated() { 74 selection.removeLookupListener(selectionListener); 75 selection = null; 76 navigator.release(); } 78 79 public void navigate(Collection selectedFiles) { 80 if(selectedFiles.size() == 1) { 81 DataObject d = (DataObject) selectedFiles.iterator().next(); 82 navigator.navigate(d); 83 } 84 } 85 86 } 87 | Popular Tags |