1 19 package org.netbeans.modules.editor; 20 21 import java.awt.event.ActionEvent ; 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import javax.swing.Action ; 25 import javax.swing.JMenu ; 26 import javax.swing.JMenuItem ; 27 import javax.swing.JPopupMenu ; 28 import javax.swing.JSeparator ; 29 30 import org.openide.cookies.InstanceCookie; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileSystem; 33 import org.openide.filesystems.Repository; 34 import org.openide.loaders.DataFolder; 35 import org.openide.loaders.DataObject; 36 import org.openide.util.HelpCtx; 37 import org.openide.util.NbBundle; 38 import org.openide.util.actions.Presenter; 39 import org.openide.util.actions.SystemAction; 40 41 42 46 public final class NbSelectInPopupAction extends SystemAction implements Presenter.Popup { 47 48 private ArrayList actions = null; 49 50 public String getName() { 51 return NbBundle.getMessage(NbSelectInPopupAction.class, "Editors/text/base/Popup/org-netbeans-modules-editor-NbSelectInPopupAction.instance"); } 53 54 public void actionPerformed(ActionEvent ev) { 55 } 57 58 public HelpCtx getHelpCtx() { 59 return HelpCtx.DEFAULT_HELP; 60 } 61 62 public javax.swing.JMenuItem getPopupPresenter() { 63 return new SubMenu(getName()); 64 } 65 66 public class SubMenu extends JMenu { 67 68 public SubMenu(String s){ 69 super(s); 70 } 71 72 73 public JPopupMenu getPopupMenu() { 74 JPopupMenu pm = super.getPopupMenu(); 75 pm.removeAll(); 76 FileSystem dfs = Repository.getDefault().getDefaultFileSystem(); 77 FileObject fo = dfs.findResource("Actions/Window/SelectDocumentNode"); DataFolder df = fo != null ? DataFolder.findFolder(fo) : null; 79 80 if (df != null) { 81 DataObject actionObjects[] = df.getChildren(); 82 for (int i = 0; i < actionObjects.length; i++) { 83 InstanceCookie ic = (InstanceCookie) actionObjects[i].getCookie(InstanceCookie.class); 84 if (ic == null) continue; 85 Object instance; 86 try { 87 instance = ic.instanceCreate(); 88 } catch (IOException e) { 89 e.printStackTrace(); 91 continue; 92 } catch (ClassNotFoundException e) { 93 e.printStackTrace(); 95 continue; 96 } 97 if (instance instanceof JSeparator ) { 98 pm.add((JSeparator ) instance); 99 } else if (instance instanceof Presenter.Popup) { 100 pm.add(((Presenter.Popup)instance).getPopupPresenter()); 101 } else if (instance instanceof Presenter.Menu) { 102 JMenuItem temp = ((Presenter.Menu)instance).getMenuPresenter(); 103 temp.setIcon(null); 104 pm.add(temp); 105 } else if (instance instanceof Action ) { 106 JMenuItem temp = new JMenuItem ((Action )instance); 107 temp.setIcon(null); 108 pm.add(temp); 109 } 110 } 111 } 112 pm.pack(); 113 return pm; 114 } 115 } 116 } 117 | Popular Tags |