1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.gridservice.client;
30
31 import javax.swing.JPopupMenu;
32 import javax.swing.JMenuItem;
33 import javax.swing.JOptionPane;
34
35 import java.awt.event.ActionListener;
36 import java.awt.event.ActionEvent;
37
38 import java.awt.Component;
39
40 import uk.ac.rdg.resc.jstyx.StyxException;
41
42 /***
43 * A popup menu which appears when the user right-clicks on a node in the tree
44 * in the SGSExplorer window. Only one instance of this class is ever created.
45 * Access this instance through the static <code>showContext()</code> method.
46 *
47 * @author Jon Blower
48 * $Revision: 530 $
49 * $Date: 2005-12-07 17:49:05 +0000 (Wed, 07 Dec 2005) $
50 * $Log$
51 * Revision 1.8 2005/12/07 17:49:05 jonblower
52 * Added getInstanceClient() method to CStyxFileNode
53 *
54 * Revision 1.7 2005/12/07 08:54:06 jonblower
55 * Changes due to SGSInstanceGUI.getGUI() throwing StyxException
56 *
57 * Revision 1.6 2005/07/08 12:19:58 jonblower
58 * Continuing to implement automatic updates of service instances
59 *
60 * Revision 1.5 2005/07/06 17:53:44 jonblower
61 * Implementing automatic update of SGS instances in SGS Explorer
62 *
63 * Revision 1.4 2005/05/27 17:05:07 jonblower
64 * Changes to incorporate GeneralCachingStreamReader
65 *
66 * Revision 1.3 2005/05/18 17:13:51 jonblower
67 * Created SGSInstanceGUI
68 *
69 * Revision 1.2 2005/05/18 08:03:24 jonblower
70 * Implemented creation of new service instances
71 *
72 * Revision 1.1 2005/05/17 18:21:36 jonblower
73 * Added initial pop-up menu support
74 *
75 */
76 class StyxExplorerPopupMenu extends JPopupMenu implements ActionListener
77 {
78
79 private static final StyxExplorerPopupMenu popupMenu = new StyxExplorerPopupMenu();
80
81 private JMenuItem newInstance;
82 private JMenuItem refresh;
83 private JMenuItem showGUI;
84 private JMenuItem destroyInstance;
85 private CStyxFileNode activeNode;
86
87 /*** Creates a new instance of StyxExplorerPopupMenu */
88 private StyxExplorerPopupMenu()
89 {
90 this.newInstance = new JMenuItem("New instance");
91 this.refresh = new JMenuItem("Refresh");
92 this.showGUI = new JMenuItem("Show GUI");
93 this.destroyInstance = new JMenuItem("Destroy");
94 this.add(this.newInstance);
95
96 this.add(this.showGUI);
97
98
99
100
101 for (int i = 0; i < this.getComponentCount(); i++)
102 {
103 Component comp = this.getComponent(i);
104 if (comp instanceof JMenuItem)
105 {
106 ((JMenuItem)comp).addActionListener(this);
107 }
108 }
109 }
110
111 /***
112 * Sets up the menu (i.e. shows/hides the appropriate menu items) for the
113 * given node
114 */
115 private void setupMenu(CStyxFileNode activeNode)
116 {
117 this.activeNode = activeNode;
118 int nodeType = this.activeNode.getType();
119
120
121 this.newInstance.setVisible(nodeType == CStyxFileNode.SERVICE);
122
123
124 this.showGUI.setVisible(nodeType == CStyxFileNode.INSTANCE);
125 this.destroyInstance.setVisible(nodeType == CStyxFileNode.INSTANCE);
126
127
128
129 }
130
131 /***
132 * Called when a button on the popup menu is clicked
133 */
134 public void actionPerformed(ActionEvent e)
135 {
136 Object source = e.getSource();
137 if (source == this.newInstance)
138 {
139 this.activeNode.createNewInstance();
140 }
141 else if (source == this.showGUI)
142 {
143 try
144 {
145 SGSInstanceClient client = this.activeNode.getInstanceClient();
146 SGSInstanceGUI gui = SGSInstanceGUI.getGUI(client);
147 gui.setVisible(true);
148 }
149 catch(StyxException se)
150 {
151
152
153 JOptionPane.showMessageDialog(null, "Error creating SGS instance" +
154 " client: " + se.getMessage());
155 }
156 }
157 else if (source == this.refresh)
158 {
159
160
161 this.activeNode.findChildren();
162 }
163 else if (source == this.destroyInstance)
164 {
165
166 }
167 }
168
169 /***
170 * Show the popup menu for the given CStyxFileNode
171 */
172 public static void showContext(CStyxFileNode node, Component invoker, int x, int y)
173 {
174 popupMenu.setupMenu(node);
175 popupMenu.show(invoker, x, y);
176 }
177
178 }