KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > derby > DerbyDatabaseAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.derby;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.AbstractAction JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.JMenu JavaDoc;
27 import javax.swing.JMenuItem JavaDoc;
28 import javax.swing.JPopupMenu JavaDoc;
29 import javax.swing.event.MenuEvent JavaDoc;
30 import javax.swing.event.MenuListener JavaDoc;
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 /**
39  * A dummy action serving as the Derby Database menu item. Allows
40  * showing and hiding the menu item programmatically.
41  *
42  * @author Andrei Badea
43  */

44 public class DerbyDatabaseAction extends AbstractAction JavaDoc implements Presenter.Menu {
45     
46     private JMenuItem JavaDoc menuPresenter = null;
47     
48     public DerbyDatabaseAction() {
49         super(NbBundle.getMessage(DerbyDatabaseAction.class, "LBL_DerbyDatabase"));
50     }
51     
52     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
53     }
54
55     public JMenuItem JavaDoc getMenuPresenter() {
56         if (menuPresenter == null) {
57             menuPresenter = new MenuPresenter();
58         }
59         return menuPresenter;
60     }
61     
62     private final class MenuPresenter extends JMenu JavaDoc implements DynamicMenuContent, MenuListener JavaDoc {
63         
64         public MenuPresenter() {
65             super((String JavaDoc)getValue(Action.NAME));
66             addMenuListener(this);
67         }
68         
69         public JComponent JavaDoc[] synchMenuPresenters(javax.swing.JComponent JavaDoc[] items) {
70             return getMenuPresenters();
71         }
72
73         public JComponent JavaDoc[] getMenuPresenters() {
74             if (!DerbyOptions.getDefault().isLocationNull()) {
75                 return new JComponent JavaDoc[] { this };
76             } else {
77                 return new JComponent JavaDoc[0];
78             }
79         }
80
81         public void menuSelected(MenuEvent JavaDoc e) {
82             getPopupMenu().removeAll();
83             JPopupMenu JavaDoc menu = Utilities.actionsToPopup(new Action JavaDoc[] {
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 JavaDoc c = menu.getComponent(0);
90                 menu.remove(0);
91                 getPopupMenu().add(c);
92             }
93         }
94         
95         public void menuCanceled(MenuEvent JavaDoc e) {
96         }
97         
98         public void menuDeselected(MenuEvent JavaDoc e) {
99         }
100     }
101 }
102
Popular Tags