1 19 20 package org.netbeans.modules.derby; 21 22 import java.awt.Component ; 23 import javax.swing.AbstractAction ; 24 import javax.swing.Action ; 25 import javax.swing.JComponent ; 26 import javax.swing.JMenu ; 27 import javax.swing.JMenuItem ; 28 import javax.swing.JPopupMenu ; 29 import javax.swing.event.MenuEvent ; 30 import javax.swing.event.MenuListener ; 31 import org.openide.ErrorManager; 32 import org.openide.awt.DynamicMenuContent; 33 import org.openide.util.NbBundle; 34 import org.openide.util.Utilities; 35 import org.openide.util.actions.Presenter; 36 import org.openide.util.actions.SystemAction; 37 38 44 public class DerbyDatabaseAction extends AbstractAction implements Presenter.Menu { 45 46 private JMenuItem menuPresenter = null; 47 48 public DerbyDatabaseAction() { 49 super(NbBundle.getMessage(DerbyDatabaseAction.class, "LBL_DerbyDatabase")); 50 } 51 52 public void actionPerformed(java.awt.event.ActionEvent e) { 53 } 54 55 public JMenuItem getMenuPresenter() { 56 if (menuPresenter == null) { 57 menuPresenter = new MenuPresenter(); 58 } 59 return menuPresenter; 60 } 61 62 private final class MenuPresenter extends JMenu implements DynamicMenuContent, MenuListener { 63 64 public MenuPresenter() { 65 super((String )getValue(Action.NAME)); 66 addMenuListener(this); 67 } 68 69 public JComponent [] synchMenuPresenters(javax.swing.JComponent [] items) { 70 return getMenuPresenters(); 71 } 72 73 public JComponent [] getMenuPresenters() { 74 if (!DerbyOptions.getDefault().isLocationNull()) { 75 return new JComponent [] { this }; 76 } else { 77 return new JComponent [0]; 78 } 79 } 80 81 public void menuSelected(MenuEvent e) { 82 getPopupMenu().removeAll(); 83 JPopupMenu menu = Utilities.actionsToPopup(new Action [] { 84 SystemAction.get(StartAction.class), 85 SystemAction.get(StopAction.class), 86 SystemAction.get(CreateDatabaseAction.class), 87 }, Utilities.actionsGlobalContext()); 88 while (menu.getComponentCount() > 0) { 89 Component c = menu.getComponent(0); 90 menu.remove(0); 91 getPopupMenu().add(c); 92 } 93 } 94 95 public void menuCanceled(MenuEvent e) { 96 } 97 98 public void menuDeselected(MenuEvent e) { 99 } 100 } 101 } 102 | Popular Tags |