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.exposed.SessionsProductMBean; 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 SessionsProductNode extends ComponentNode implements NotificationListener { 26 private ConnectionContext m_cc; 27 private ObjectName m_beanName; 28 private JPopupMenu m_popupMenu; 29 private RefreshAction m_refreshAction; 30 31 private static final String REFRESH_ACTION = "RefreshAction"; 32 33 public SessionsProductNode(ConnectionContext cc, SessionsProductMBean bean, ObjectName beanName) { 34 super(); 35 36 m_cc = cc; 37 m_beanName = beanName; 38 39 setLabel(beanName.getKeyProperty("node")); 40 setComponent(new SessionsProductPanel(bean)); 41 42 initMenu(); 43 startListening(); 44 } 45 46 private ObjectName getMBeanServerDelegate() { 47 try { 48 return m_cc.queryName("JMImplementation:type=MBeanServerDelegate"); 49 } catch(Exception ioe) { 50 return null; 51 } 52 } 53 54 private void startListening() { 55 ObjectName mbsd = getMBeanServerDelegate(); 56 57 if(mbsd != null) { 58 try { 59 m_cc.addNotificationListener(mbsd, this); 60 } catch(Exception e) {} 61 } 62 } 63 64 private void stopListening() { 65 ObjectName mbsd = getMBeanServerDelegate(); 66 67 if(mbsd != null) { 68 try { 69 m_cc.removeNotificationListener(mbsd, this); 70 } catch(Exception e) {} 71 } 72 } 73 74 public void handleNotification(Notification notification, Object handback) { 75 if(notification instanceof MBeanServerNotification ) { 76 MBeanServerNotification mbsn = (MBeanServerNotification )notification; 77 String type = notification.getType(); 78 ObjectName name = mbsn.getMBeanName(); 79 80 if(type.equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) { 81 if(name.equals(m_beanName)) { 82 stopListening(); 83 ((DefaultTreeModel )getModel()).removeNodeFromParent(this); 84 } 85 } 86 } 87 } 88 89 private void initMenu() { 90 m_refreshAction = new RefreshAction(); 91 92 m_popupMenu = new JPopupMenu ("SessionMonitor Actions"); 93 m_popupMenu.add(m_refreshAction); 94 95 addActionBinding(REFRESH_ACTION, m_refreshAction); 96 } 97 98 public JPopupMenu getPopupMenu() { 99 return m_popupMenu; 100 } 101 102 public void refresh() { 103 ((SessionsProductPanel)getComponent()).refresh(); 104 } 105 106 private class RefreshAction extends XAbstractAction { 107 private RefreshAction() { 108 super(); 109 110 setName(AdminClient.getContext().getMessage("refresh.name")); 111 setSmallIcon(ClassesHelper.getHelper().getRefreshIcon()); 112 setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true)); 113 } 114 115 public void actionPerformed(ActionEvent ae) { 116 refresh(); 117 } 118 } 119 120 public void nodeClicked(MouseEvent me) { 121 m_refreshAction.actionPerformed(null); 122 } 123 } 124 | Popular Tags |