KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > navigation > graph > actions > PageFlowPopupProvider


1 /*
2  * NodePopupMenuProvider.java
3  *
4  * Created on February 2, 2007, 6:46 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.web.jsf.navigation.graph.actions;
11
12 import java.awt.Point JavaDoc;
13 import java.awt.event.ActionEvent JavaDoc;
14 import java.awt.event.ActionListener JavaDoc;
15 import java.lang.ref.WeakReference JavaDoc;
16 import javax.swing.JMenuItem JavaDoc;
17 import javax.swing.JPopupMenu JavaDoc;
18 import org.netbeans.api.visual.action.PopupMenuProvider;
19 import org.netbeans.api.visual.widget.Widget;
20 import org.netbeans.modules.web.jsf.navigation.graph.PageFlowScene;
21 import org.openide.util.Lookup;
22 import org.openide.util.NbBundle;
23 import org.openide.util.Utilities;
24 import org.openide.util.lookup.AbstractLookup;
25 import org.openide.util.lookup.InstanceContent;
26
27 /**
28  *
29  * @author joelle
30  */

31 public class PageFlowPopupProvider implements PopupMenuProvider {
32     
33     PageFlowScene graphScene;
34     
35     private JMenuItem JavaDoc miAddWebPage;
36     private JPopupMenu JavaDoc graphPopup;
37     
38     private String JavaDoc addPage = NbBundle.getMessage(GraphPopupProvider.class, "MSG_AddPage");
39     
40     /**
41      * Creates a Popup for any right click on Page Flow Editor
42      * @param graphScene The related PageFlow Scene.
43      */

44     public PageFlowPopupProvider(PageFlowScene graphScene) {
45         
46         this.graphScene = graphScene;
47         initialize();
48     }
49     
50     
51     // <actions from layers>
52
private static final String JavaDoc PATH_PAGEFLOW_ACTIONS = "PageFlowEditor/PopupActions"; // NOI18N
53
// private static final String PATH_PAGEFLOW_ACTIONS = "PageFlowEditor/application/x-pageflow/Popup"; // NOI18N
54
private void initialize() {
55         graphPopup = Utilities.actionsToPopup(
56                 SystemFileSystemSupport.getActions(PATH_PAGEFLOW_ACTIONS),
57                 getLookup());
58         // graphPopup = new JPopupMenu("Transition Menu");
59
//
60
// graphPopup = new JPopupMenu();
61
// miAddWebPage = new JMenuItem(addPage);
62
// miAddWebPage.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK));
63
// miAddWebPage.addActionListener(this);
64
// graphPopup.add(miAddWebPage);
65
}
66     
67     
68     
69     public JPopupMenu JavaDoc getPopupMenu(Widget widget, Point JavaDoc point){
70         return graphPopup;
71     }
72     
73     
74     /** Weak reference to the lookup. */
75     private WeakReference JavaDoc lookupWRef = new WeakReference JavaDoc(null);
76     
77     /** Adds <code>NavigatorLookupHint</code> into the original lookup,
78      * for the navigator. */

79     private Lookup getLookup() {
80         Lookup lookup = (Lookup)lookupWRef.get();
81         
82         if (lookup == null) {
83             InstanceContent ic = new InstanceContent();
84             // ic.add(firstObject);
85
ic.add(graphScene);
86             lookup = new AbstractLookup(ic);
87             lookupWRef = new WeakReference JavaDoc(lookup);
88         }
89         
90         return lookup;
91     }
92     
93 }
94
Popular Tags