author | egahlin |
Fri, 25 May 2012 12:24:57 +0200 | |
changeset 12851 | 3334e1c781d0 |
parent 5506 | 202f599c92aa |
child 14342 | 8435a30053c1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.tools.jconsole; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.event.*; |
|
30 |
import java.beans.*; |
|
31 |
import java.lang.reflect.*; |
|
32 |
import java.util.*; |
|
33 |
import java.util.List; |
|
34 |
import java.util.Timer; |
|
35 |
import javax.swing.*; |
|
36 |
import javax.swing.plaf.*; |
|
37 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
38 |
|
2 | 39 |
import com.sun.tools.jconsole.JConsolePlugin; |
40 |
import com.sun.tools.jconsole.JConsoleContext; |
|
41 |
||
42 |
import static sun.tools.jconsole.ProxyClient.*; |
|
43 |
||
44 |
@SuppressWarnings("serial") |
|
45 |
public class VMPanel extends JTabbedPane implements PropertyChangeListener { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
46 |
|
2 | 47 |
private ProxyClient proxyClient; |
48 |
private Timer timer; |
|
49 |
private int updateInterval; |
|
50 |
private String hostName; |
|
51 |
private int port; |
|
52 |
private String userName; |
|
53 |
private String password; |
|
54 |
private String url; |
|
55 |
private VMInternalFrame vmIF = null; |
|
56 |
private static ArrayList<TabInfo> tabInfos = new ArrayList<TabInfo>(); |
|
57 |
private boolean wasConnected = false; |
|
58 |
||
59 |
// The everConnected flag keeps track of whether the window can be |
|
60 |
// closed if the user clicks Cancel after a failed connection attempt. |
|
61 |
// |
|
62 |
private boolean everConnected = false; |
|
63 |
||
64 |
// The initialUpdate flag is used to enable/disable tabs each time |
|
65 |
// a connect or reconnect takes place. This flag avoids having to |
|
66 |
// enable/disable tabs on each update call. |
|
67 |
// |
|
68 |
private boolean initialUpdate = true; |
|
69 |
||
70 |
// Each VMPanel has its own instance of the JConsolePlugin |
|
71 |
// A map of JConsolePlugin to the previous SwingWorker |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
72 |
private Map<JConsolePlugin, SwingWorker<?, ?>> plugins = null; |
2 | 73 |
private boolean pluginTabsAdded = false; |
74 |
||
75 |
// Update these only on the EDT |
|
76 |
private JOptionPane optionPane; |
|
77 |
private JProgressBar progressBar; |
|
78 |
private long time0; |
|
79 |
||
80 |
static { |
|
81 |
tabInfos.add(new TabInfo(OverviewTab.class, OverviewTab.getTabName(), true)); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
82 |
tabInfos.add(new TabInfo(MemoryTab.class, MemoryTab.getTabName(), true)); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
83 |
tabInfos.add(new TabInfo(ThreadTab.class, ThreadTab.getTabName(), true)); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
84 |
tabInfos.add(new TabInfo(ClassTab.class, ClassTab.getTabName(), true)); |
2 | 85 |
tabInfos.add(new TabInfo(SummaryTab.class, SummaryTab.getTabName(), true)); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
86 |
tabInfos.add(new TabInfo(MBeansTab.class, MBeansTab.getTabName(), true)); |
2 | 87 |
} |
88 |
||
89 |
public static TabInfo[] getTabInfos() { |
|
90 |
return tabInfos.toArray(new TabInfo[tabInfos.size()]); |
|
91 |
} |
|
92 |
||
93 |
VMPanel(ProxyClient proxyClient, int updateInterval) { |
|
94 |
this.proxyClient = proxyClient; |
|
95 |
this.updateInterval = updateInterval; |
|
96 |
this.hostName = proxyClient.getHostName(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
97 |
this.port = proxyClient.getPort(); |
2 | 98 |
this.userName = proxyClient.getUserName(); |
99 |
this.password = proxyClient.getPassword(); |
|
100 |
this.url = proxyClient.getUrl(); |
|
101 |
||
102 |
for (TabInfo tabInfo : tabInfos) { |
|
103 |
if (tabInfo.tabVisible) { |
|
104 |
addTab(tabInfo); |
|
105 |
} |
|
106 |
} |
|
107 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
108 |
plugins = new LinkedHashMap<JConsolePlugin, SwingWorker<?, ?>>(); |
2 | 109 |
for (JConsolePlugin p : JConsole.getPlugins()) { |
110 |
p.setContext(proxyClient); |
|
111 |
plugins.put(p, null); |
|
112 |
} |
|
113 |
||
114 |
Utilities.updateTransparency(this); |
|
115 |
||
116 |
ToolTipManager.sharedInstance().registerComponent(this); |
|
117 |
||
118 |
// Start listening to connection state events |
|
119 |
// |
|
120 |
proxyClient.addPropertyChangeListener(this); |
|
121 |
||
122 |
addMouseListener(new MouseAdapter() { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
123 |
|
2 | 124 |
public void mouseClicked(MouseEvent e) { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
125 |
if (connectedIconBounds != null && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0 && connectedIconBounds.contains(e.getPoint())) { |
2 | 126 |
|
127 |
if (isConnected()) { |
|
128 |
disconnect(); |
|
129 |
wasConnected = false; |
|
130 |
} else { |
|
131 |
connect(); |
|
132 |
} |
|
133 |
repaint(); |
|
134 |
} |
|
135 |
} |
|
136 |
}); |
|
137 |
||
138 |
} |
|
139 |
private static Icon connectedIcon16 = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
140 |
new ImageIcon(VMPanel.class.getResource("resources/connected16.png")); |
2 | 141 |
private static Icon connectedIcon24 = |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
142 |
new ImageIcon(VMPanel.class.getResource("resources/connected24.png")); |
2 | 143 |
private static Icon disconnectedIcon16 = |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
144 |
new ImageIcon(VMPanel.class.getResource("resources/disconnected16.png")); |
2 | 145 |
private static Icon disconnectedIcon24 = |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
146 |
new ImageIcon(VMPanel.class.getResource("resources/disconnected24.png")); |
2 | 147 |
private Rectangle connectedIconBounds; |
148 |
||
149 |
// Override to increase right inset for tab area, |
|
150 |
// in order to reserve space for the connect toggle. |
|
151 |
public void setUI(TabbedPaneUI ui) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
152 |
Insets insets = (Insets) UIManager.getLookAndFeelDefaults().get("TabbedPane.tabAreaInsets"); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
153 |
insets = (Insets) insets.clone(); |
2 | 154 |
insets.right += connectedIcon24.getIconWidth() + 8; |
155 |
UIManager.put("TabbedPane.tabAreaInsets", insets); |
|
156 |
super.setUI(ui); |
|
157 |
} |
|
158 |
||
159 |
// Override to paint the connect toggle |
|
160 |
protected void paintComponent(Graphics g) { |
|
161 |
super.paintComponent(g); |
|
162 |
||
163 |
Icon icon; |
|
164 |
Component c0 = getComponent(0); |
|
165 |
if (c0 != null && c0.getY() > 24) { |
|
166 |
icon = isConnected() ? connectedIcon24 : disconnectedIcon24; |
|
167 |
} else { |
|
168 |
icon = isConnected() ? connectedIcon16 : disconnectedIcon16; |
|
169 |
} |
|
170 |
Insets insets = getInsets(); |
|
171 |
int x = getWidth() - insets.right - icon.getIconWidth() - 4; |
|
172 |
int y = insets.top; |
|
173 |
if (c0 != null) { |
|
174 |
y = (c0.getY() - icon.getIconHeight()) / 2; |
|
175 |
} |
|
176 |
icon.paintIcon(this, g, x, y); |
|
177 |
connectedIconBounds = new Rectangle(x, y, icon.getIconWidth(), icon.getIconHeight()); |
|
178 |
} |
|
179 |
||
180 |
public String getToolTipText(MouseEvent event) { |
|
181 |
if (connectedIconBounds.contains(event.getPoint())) { |
|
182 |
if (isConnected()) { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
183 |
return Messages.CONNECTED_PUNCTUATION_CLICK_TO_DISCONNECT_; |
2 | 184 |
} else { |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
185 |
return Messages.DISCONNECTED_PUNCTUATION_CLICK_TO_CONNECT_; |
2 | 186 |
} |
187 |
} else { |
|
188 |
return super.getToolTipText(event); |
|
189 |
} |
|
190 |
} |
|
191 |
||
192 |
private synchronized void addTab(TabInfo tabInfo) { |
|
193 |
Tab tab = instantiate(tabInfo); |
|
194 |
if (tab != null) { |
|
195 |
addTab(tabInfo.name, tab); |
|
196 |
} else { |
|
197 |
tabInfo.tabVisible = false; |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
private synchronized void insertTab(TabInfo tabInfo, int index) { |
|
202 |
Tab tab = instantiate(tabInfo); |
|
203 |
if (tab != null) { |
|
204 |
insertTab(tabInfo.name, null, tab, null, index); |
|
205 |
} else { |
|
206 |
tabInfo.tabVisible = false; |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
public synchronized void removeTabAt(int index) { |
|
211 |
super.removeTabAt(index); |
|
212 |
} |
|
213 |
||
214 |
private Tab instantiate(TabInfo tabInfo) { |
|
215 |
try { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
216 |
Constructor<?> con = tabInfo.tabClass.getConstructor(VMPanel.class); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
217 |
return (Tab) con.newInstance(this); |
2 | 218 |
} catch (Exception ex) { |
219 |
System.err.println(ex); |
|
220 |
return null; |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
boolean isConnected() { |
|
225 |
return proxyClient.isConnected(); |
|
226 |
} |
|
227 |
||
228 |
public int getUpdateInterval() { |
|
229 |
return updateInterval; |
|
230 |
} |
|
231 |
||
232 |
/** |
|
233 |
* WARNING NEVER CALL THIS METHOD TO MAKE JMX REQUEST |
|
234 |
* IF assertThread == false. |
|
235 |
* DISPATCHER THREAD IS NOT ASSERTED. |
|
236 |
* IT IS USED TO MAKE SOME LOCAL MANIPULATIONS. |
|
237 |
*/ |
|
238 |
ProxyClient getProxyClient(boolean assertThread) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
239 |
if (assertThread) { |
2 | 240 |
return getProxyClient(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
241 |
} else { |
2 | 242 |
return proxyClient; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
243 |
} |
2 | 244 |
} |
245 |
||
246 |
public ProxyClient getProxyClient() { |
|
247 |
String threadClass = Thread.currentThread().getClass().getName(); |
|
248 |
if (threadClass.equals("java.awt.EventDispatchThread")) { |
|
249 |
String msg = "Calling VMPanel.getProxyClient() from the Event Dispatch Thread!"; |
|
250 |
new RuntimeException(msg).printStackTrace(); |
|
251 |
System.exit(1); |
|
252 |
} |
|
253 |
return proxyClient; |
|
254 |
} |
|
255 |
||
256 |
public void cleanUp() { |
|
257 |
//proxyClient.disconnect(); |
|
258 |
for (Tab tab : getTabs()) { |
|
259 |
tab.dispose(); |
|
260 |
} |
|
261 |
for (JConsolePlugin p : plugins.keySet()) { |
|
262 |
p.dispose(); |
|
263 |
} |
|
264 |
// Cancel pending update tasks |
|
265 |
// |
|
266 |
if (timer != null) { |
|
267 |
timer.cancel(); |
|
268 |
} |
|
269 |
// Stop listening to connection state events |
|
270 |
// |
|
271 |
proxyClient.removePropertyChangeListener(this); |
|
272 |
} |
|
273 |
||
274 |
// Call on EDT |
|
275 |
public void connect() { |
|
276 |
if (isConnected()) { |
|
277 |
// create plugin tabs if not done |
|
278 |
createPluginTabs(); |
|
279 |
// Notify tabs |
|
280 |
fireConnectedChange(true); |
|
281 |
// Enable/disable tabs on initial update |
|
282 |
initialUpdate = true; |
|
283 |
// Start/Restart update timer on connect/reconnect |
|
284 |
startUpdateTimer(); |
|
285 |
} else { |
|
286 |
new Thread("VMPanel.connect") { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
287 |
|
2 | 288 |
public void run() { |
289 |
proxyClient.connect(); |
|
290 |
} |
|
291 |
}.start(); |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
// Call on EDT |
|
296 |
public void disconnect() { |
|
297 |
proxyClient.disconnect(); |
|
298 |
updateFrameTitle(); |
|
299 |
} |
|
300 |
||
301 |
// Called on EDT |
|
302 |
public void propertyChange(PropertyChangeEvent ev) { |
|
303 |
String prop = ev.getPropertyName(); |
|
304 |
||
305 |
if (prop == CONNECTION_STATE_PROPERTY) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
306 |
ConnectionState oldState = (ConnectionState) ev.getOldValue(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
307 |
ConnectionState newState = (ConnectionState) ev.getNewValue(); |
2 | 308 |
switch (newState) { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
309 |
case CONNECTING: |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
310 |
onConnecting(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
311 |
break; |
2 | 312 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
313 |
case CONNECTED: |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
314 |
if (progressBar != null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
315 |
progressBar.setIndeterminate(false); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
316 |
progressBar.setValue(100); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
317 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
318 |
closeOptionPane(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
319 |
updateFrameTitle(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
320 |
// create tabs if not done |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
321 |
createPluginTabs(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
322 |
repaint(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
323 |
// Notify tabs |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
324 |
fireConnectedChange(true); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
325 |
// Enable/disable tabs on initial update |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
326 |
initialUpdate = true; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
327 |
// Start/Restart update timer on connect/reconnect |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
328 |
startUpdateTimer(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
329 |
break; |
2 | 330 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
331 |
case DISCONNECTED: |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
332 |
if (progressBar != null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
333 |
progressBar.setIndeterminate(false); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
334 |
progressBar.setValue(0); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
335 |
closeOptionPane(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
336 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
337 |
vmPanelDied(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
338 |
if (oldState == ConnectionState.CONNECTED) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
339 |
// Notify tabs |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
340 |
fireConnectedChange(false); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
341 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
342 |
break; |
2 | 343 |
} |
344 |
} |
|
345 |
} |
|
346 |
||
347 |
// Called on EDT |
|
348 |
private void onConnecting() { |
|
349 |
time0 = System.currentTimeMillis(); |
|
350 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
351 |
SwingUtilities.getWindowAncestor(this); |
2 | 352 |
|
353 |
String connectionName = getConnectionName(); |
|
354 |
progressBar = new JProgressBar(); |
|
355 |
progressBar.setIndeterminate(true); |
|
356 |
JPanel progressPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); |
|
357 |
progressPanel.add(progressBar); |
|
358 |
||
359 |
Object[] message = { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
360 |
"<html><h3>" + Resources.format(Messages.CONNECTING_TO1, connectionName) + "</h3></html>", |
2 | 361 |
progressPanel, |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
362 |
"<html><b>" + Resources.format(Messages.CONNECTING_TO2, connectionName) + "</b></html>" |
2 | 363 |
}; |
364 |
||
365 |
optionPane = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
366 |
SheetDialog.showOptionDialog(this, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
367 |
message, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
368 |
JOptionPane.DEFAULT_OPTION, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
369 |
JOptionPane.INFORMATION_MESSAGE, null, |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
370 |
new String[]{Messages.CANCEL}, |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
371 |
0); |
2 | 372 |
|
373 |
||
374 |
} |
|
375 |
||
376 |
// Called on EDT |
|
377 |
private void closeOptionPane() { |
|
378 |
if (optionPane != null) { |
|
379 |
new Thread("VMPanel.sleeper") { |
|
380 |
public void run() { |
|
381 |
long elapsed = System.currentTimeMillis() - time0; |
|
382 |
if (elapsed < 2000) { |
|
383 |
try { |
|
384 |
sleep(2000 - elapsed); |
|
385 |
} catch (InterruptedException ex) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
386 |
// Ignore |
2 | 387 |
} |
388 |
} |
|
389 |
SwingUtilities.invokeLater(new Runnable() { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
390 |
|
2 | 391 |
public void run() { |
392 |
optionPane.setVisible(false); |
|
393 |
progressBar = null; |
|
394 |
} |
|
395 |
}); |
|
396 |
} |
|
397 |
}.start(); |
|
398 |
} |
|
399 |
} |
|
400 |
||
401 |
void updateFrameTitle() { |
|
402 |
VMInternalFrame vmIF = getFrame(); |
|
403 |
if (vmIF != null) { |
|
404 |
String displayName = getDisplayName(); |
|
405 |
if (!proxyClient.isConnected()) { |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
406 |
displayName = Resources.format(Messages.CONNECTION_NAME__DISCONNECTED_, displayName); |
2 | 407 |
} |
408 |
vmIF.setTitle(displayName); |
|
409 |
} |
|
410 |
} |
|
411 |
||
412 |
private VMInternalFrame getFrame() { |
|
413 |
if (vmIF == null) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
414 |
vmIF = (VMInternalFrame) SwingUtilities.getAncestorOfClass(VMInternalFrame.class, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
415 |
this); |
2 | 416 |
} |
417 |
return vmIF; |
|
418 |
} |
|
419 |
||
420 |
// TODO: this method is not needed when all JConsole tabs |
|
421 |
// are migrated to use the new JConsolePlugin API. |
|
422 |
// |
|
423 |
// A thread safe clone of all JConsole tabs |
|
424 |
synchronized List<Tab> getTabs() { |
|
425 |
ArrayList<Tab> list = new ArrayList<Tab>(); |
|
426 |
int n = getTabCount(); |
|
427 |
for (int i = 0; i < n; i++) { |
|
428 |
Component c = getComponentAt(i); |
|
429 |
if (c instanceof Tab) { |
|
430 |
list.add((Tab) c); |
|
431 |
} |
|
432 |
} |
|
433 |
return list; |
|
434 |
} |
|
435 |
||
436 |
private void startUpdateTimer() { |
|
437 |
if (timer != null) { |
|
438 |
timer.cancel(); |
|
439 |
} |
|
440 |
TimerTask timerTask = new TimerTask() { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
441 |
|
2 | 442 |
public void run() { |
443 |
update(); |
|
444 |
} |
|
445 |
}; |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
446 |
String timerName = "Timer-" + getConnectionName(); |
2 | 447 |
timer = new Timer(timerName, true); |
448 |
timer.schedule(timerTask, 0, updateInterval); |
|
449 |
} |
|
450 |
||
451 |
// Call on EDT |
|
452 |
private void vmPanelDied() { |
|
453 |
disconnect(); |
|
454 |
||
455 |
JOptionPane optionPane; |
|
456 |
String msgTitle, msgExplanation, buttonStr; |
|
457 |
||
458 |
if (wasConnected) { |
|
459 |
wasConnected = false; |
|
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
460 |
msgTitle = Messages.CONNECTION_LOST1; |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
461 |
msgExplanation = Resources.format(Messages.CONNECTING_TO2, getConnectionName()); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
462 |
buttonStr = Messages.RECONNECT; |
2 | 463 |
} else { |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
464 |
msgTitle =Messages.CONNECTION_FAILED1; |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
465 |
msgExplanation = Resources.format(Messages.CONNECTION_FAILED2, getConnectionName()); |
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
466 |
buttonStr = Messages.CONNECT; |
2 | 467 |
} |
468 |
||
469 |
optionPane = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
470 |
SheetDialog.showOptionDialog(this, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
471 |
"<html><h3>" + msgTitle + "</h3>" + |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
472 |
"<b>" + msgExplanation + "</b>", |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
473 |
JOptionPane.DEFAULT_OPTION, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
474 |
JOptionPane.WARNING_MESSAGE, null, |
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
475 |
new String[]{buttonStr, Messages.CANCEL}, |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
476 |
0); |
2 | 477 |
|
478 |
optionPane.addPropertyChangeListener(new PropertyChangeListener() { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
479 |
|
2 | 480 |
public void propertyChange(PropertyChangeEvent event) { |
481 |
if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) { |
|
482 |
Object value = event.getNewValue(); |
|
483 |
||
12851
3334e1c781d0
7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents:
5506
diff
changeset
|
484 |
if (value == Messages.RECONNECT || value == Messages.CONNECT) { |
2 | 485 |
connect(); |
486 |
} else if (!everConnected) { |
|
487 |
try { |
|
488 |
getFrame().setClosed(true); |
|
489 |
} catch (PropertyVetoException ex) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
490 |
// Should not happen, but can be ignored. |
2 | 491 |
} |
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
}); |
|
496 |
} |
|
497 |
||
498 |
// Note: This method is called on a TimerTask thread. Any GUI manipulation |
|
499 |
// must be performed with invokeLater() or invokeAndWait(). |
|
500 |
private Object lockObject = new Object(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
501 |
|
2 | 502 |
private void update() { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
503 |
synchronized (lockObject) { |
2 | 504 |
if (!isConnected()) { |
505 |
if (wasConnected) { |
|
506 |
EventQueue.invokeLater(new Runnable() { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
507 |
|
2 | 508 |
public void run() { |
509 |
vmPanelDied(); |
|
510 |
} |
|
511 |
}); |
|
512 |
} |
|
513 |
wasConnected = false; |
|
514 |
return; |
|
515 |
} else { |
|
516 |
wasConnected = true; |
|
517 |
everConnected = true; |
|
518 |
} |
|
519 |
proxyClient.flush(); |
|
520 |
List<Tab> tabs = getTabs(); |
|
521 |
final int n = tabs.size(); |
|
522 |
for (int i = 0; i < n; i++) { |
|
523 |
final int index = i; |
|
524 |
try { |
|
525 |
if (!proxyClient.isDead()) { |
|
526 |
// Update tab |
|
527 |
// |
|
528 |
tabs.get(index).update(); |
|
529 |
// Enable tab on initial update |
|
530 |
// |
|
531 |
if (initialUpdate) { |
|
532 |
EventQueue.invokeLater(new Runnable() { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
533 |
|
2 | 534 |
public void run() { |
535 |
setEnabledAt(index, true); |
|
536 |
} |
|
537 |
}); |
|
538 |
} |
|
539 |
} |
|
540 |
} catch (Exception e) { |
|
541 |
// Disable tab on initial update |
|
542 |
// |
|
543 |
if (initialUpdate) { |
|
544 |
EventQueue.invokeLater(new Runnable() { |
|
545 |
public void run() { |
|
546 |
setEnabledAt(index, false); |
|
547 |
} |
|
548 |
}); |
|
549 |
} |
|
550 |
} |
|
551 |
} |
|
552 |
||
553 |
// plugin GUI update |
|
554 |
for (JConsolePlugin p : plugins.keySet()) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
555 |
SwingWorker<?, ?> sw = p.newSwingWorker(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
556 |
SwingWorker<?, ?> prevSW = plugins.get(p); |
2 | 557 |
// schedule SwingWorker to run only if the previous |
558 |
// SwingWorker has finished its task and it hasn't started. |
|
559 |
if (prevSW == null || prevSW.isDone()) { |
|
560 |
if (sw == null || sw.getState() == SwingWorker.StateValue.PENDING) { |
|
561 |
plugins.put(p, sw); |
|
562 |
if (sw != null) { |
|
563 |
sw.execute(); |
|
564 |
} |
|
565 |
} |
|
566 |
} |
|
567 |
} |
|
568 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
569 |
// Set the first enabled tab in the tab's list |
2 | 570 |
// as the selected tab on initial update |
571 |
// |
|
572 |
if (initialUpdate) { |
|
573 |
EventQueue.invokeLater(new Runnable() { |
|
574 |
public void run() { |
|
575 |
// Select first enabled tab if current tab isn't. |
|
576 |
int index = getSelectedIndex(); |
|
577 |
if (index < 0 || !isEnabledAt(index)) { |
|
578 |
for (int i = 0; i < n; i++) { |
|
579 |
if (isEnabledAt(i)) { |
|
580 |
setSelectedIndex(i); |
|
581 |
break; |
|
582 |
} |
|
583 |
} |
|
584 |
} |
|
585 |
} |
|
586 |
}); |
|
587 |
initialUpdate = false; |
|
588 |
} |
|
589 |
} |
|
590 |
} |
|
591 |
||
592 |
public String getHostName() { |
|
593 |
return hostName; |
|
594 |
} |
|
595 |
||
596 |
public int getPort() { |
|
597 |
return port; |
|
598 |
} |
|
599 |
||
600 |
public String getUserName() { |
|
601 |
return userName; |
|
602 |
} |
|
603 |
||
604 |
public String getUrl() { |
|
605 |
return url; |
|
606 |
} |
|
607 |
||
608 |
public String getPassword() { |
|
609 |
return password; |
|
610 |
} |
|
611 |
||
612 |
public String getConnectionName() { |
|
613 |
return proxyClient.connectionName(); |
|
614 |
} |
|
615 |
||
616 |
public String getDisplayName() { |
|
617 |
return proxyClient.getDisplayName(); |
|
618 |
} |
|
619 |
||
620 |
static class TabInfo { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
621 |
|
2 | 622 |
Class<? extends Tab> tabClass; |
623 |
String name; |
|
624 |
boolean tabVisible; |
|
625 |
||
626 |
TabInfo(Class<? extends Tab> tabClass, String name, boolean tabVisible) { |
|
627 |
this.tabClass = tabClass; |
|
628 |
this.name = name; |
|
629 |
this.tabVisible = tabVisible; |
|
630 |
} |
|
631 |
} |
|
632 |
||
633 |
private void createPluginTabs() { |
|
634 |
// add plugin tabs if not done |
|
635 |
if (!pluginTabsAdded) { |
|
636 |
for (JConsolePlugin p : plugins.keySet()) { |
|
637 |
Map<String, JPanel> tabs = p.getTabs(); |
|
638 |
for (Map.Entry<String, JPanel> e : tabs.entrySet()) { |
|
639 |
addTab(e.getKey(), e.getValue()); |
|
640 |
} |
|
641 |
} |
|
642 |
pluginTabsAdded = true; |
|
643 |
} |
|
644 |
} |
|
645 |
||
646 |
private void fireConnectedChange(boolean connected) { |
|
647 |
for (Tab tab : getTabs()) { |
|
648 |
tab.firePropertyChange(JConsoleContext.CONNECTION_STATE_PROPERTY, !connected, connected); |
|
649 |
} |
|
650 |
} |
|
651 |
} |