1 4 package com.tc.admin.sessions; 5 6 import com.tc.admin.AdminClient; 7 import com.tc.admin.ConnectionContext; 8 import com.tc.admin.common.ComponentNode; 9 import com.tc.admin.common.XAbstractAction; 10 import com.tc.admin.dso.ClassesHelper; 11 import com.tc.management.beans.sessions.SessionMonitorMBean; 12 13 import java.awt.event.ActionEvent ; 14 import java.awt.event.KeyEvent ; 15 import java.awt.event.MouseEvent ; 16 17 import javax.management.MBeanServerNotification ; 18 import javax.management.Notification ; 19 import javax.management.NotificationListener ; 20 import javax.management.ObjectName ; 21 import javax.swing.JPopupMenu ; 22 import javax.swing.KeyStroke ; 23 import javax.swing.tree.DefaultTreeModel ; 24 25 public class SessionMonitorNode extends ComponentNode implements NotificationListener { 26 ObjectName m_beanName; 27 SessionMonitorMBean m_bean; 28 private JPopupMenu m_popupMenu; 29 private RefreshAction m_refreshAction; 30 31 private static final String REFRESH_ACTION = "RefreshAction"; 32 33 public SessionMonitorNode(ConnectionContext cc, SessionMonitorMBean bean, ObjectName beanName) { 34 super(); 35 36 try { 37 ObjectName mbsd = cc.queryName("JMImplementation:type=MBeanServerDelegate"); 38 39 if(mbsd != null) { 40 cc.addNotificationListener(mbsd, this); 41 } 42 } catch(Exception ioe) { 43 ioe.printStackTrace(); 44 } 45 46 m_beanName = beanName; 47 m_bean = bean; 48 49 setLabel(beanName.getKeyProperty("node")); 50 setComponent(new SessionMonitorPanel(bean)); 51 52 initMenu(); 53 } 54 55 public void handleNotification(Notification notification, Object handback) { 56 if(notification instanceof MBeanServerNotification ) { 57 MBeanServerNotification mbsn = (MBeanServerNotification )notification; 58 String type = notification.getType(); 59 ObjectName name = mbsn.getMBeanName(); 60 61 if(type.equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) { 62 if(name.equals(m_beanName)) { 63 ((DefaultTreeModel )getModel()).removeNodeFromParent(SessionMonitorNode.this); 64 } 65 } 66 } 67 } 68 69 private void initMenu() { 70 m_refreshAction = new RefreshAction(); 71 72 m_popupMenu = new JPopupMenu ("SessionMonitor Actions"); 73 m_popupMenu.add(m_refreshAction); 74 75 addActionBinding(REFRESH_ACTION, m_refreshAction); 76 } 77 78 public JPopupMenu getPopupMenu() { 79 return m_popupMenu; 80 } 81 82 public void refresh() { 83 ((SessionMonitorPanel)getComponent()).refresh(); 84 } 85 86 private class RefreshAction extends XAbstractAction { 87 private RefreshAction() { 88 super(); 89 90 setName(AdminClient.getContext().getMessage("refresh.name")); 91 setSmallIcon(ClassesHelper.getHelper().getRefreshIcon()); 92 setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true)); 93 } 94 95 public void actionPerformed(ActionEvent ae) { 96 refresh(); 97 } 98 } 99 100 public void nodeClicked(MouseEvent me) { 101 m_refreshAction.actionPerformed(null); 102 } 103 } 104 | Popular Tags |