001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.admin.sessions;
005:
006: import com.tc.admin.AdminClient;
007: import com.tc.admin.ConnectionContext;
008: import com.tc.admin.common.ComponentNode;
009: import com.tc.admin.common.XAbstractAction;
010: import com.tc.admin.dso.ClassesHelper;
011: import com.tc.management.beans.sessions.SessionMonitorMBean;
012:
013: import java.awt.event.ActionEvent;
014: import java.awt.event.KeyEvent;
015: import java.awt.event.MouseEvent;
016:
017: import javax.management.MBeanServerNotification;
018: import javax.management.Notification;
019: import javax.management.NotificationListener;
020: import javax.management.ObjectName;
021: import javax.swing.JPopupMenu;
022: import javax.swing.KeyStroke;
023: import javax.swing.tree.DefaultTreeModel;
024:
025: public class SessionMonitorNode extends ComponentNode implements
026: NotificationListener {
027: ObjectName m_beanName;
028: SessionMonitorMBean m_bean;
029: private JPopupMenu m_popupMenu;
030: private RefreshAction m_refreshAction;
031:
032: private static final String REFRESH_ACTION = "RefreshAction";
033:
034: public SessionMonitorNode(ConnectionContext cc,
035: SessionMonitorMBean bean, ObjectName beanName) {
036: super ();
037:
038: try {
039: ObjectName mbsd = cc
040: .queryName("JMImplementation:type=MBeanServerDelegate");
041:
042: if (mbsd != null) {
043: cc.addNotificationListener(mbsd, this );
044: }
045: } catch (Exception ioe) {
046: ioe.printStackTrace();
047: }
048:
049: m_beanName = beanName;
050: m_bean = bean;
051:
052: setLabel(beanName.getKeyProperty("node"));
053: setComponent(new SessionMonitorPanel(bean));
054:
055: initMenu();
056: }
057:
058: public void handleNotification(Notification notification,
059: Object handback) {
060: if (notification instanceof MBeanServerNotification) {
061: MBeanServerNotification mbsn = (MBeanServerNotification) notification;
062: String type = notification.getType();
063: ObjectName name = mbsn.getMBeanName();
064:
065: if (type
066: .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
067: if (name.equals(m_beanName)) {
068: ((DefaultTreeModel) getModel())
069: .removeNodeFromParent(SessionMonitorNode.this );
070: }
071: }
072: }
073: }
074:
075: private void initMenu() {
076: m_refreshAction = new RefreshAction();
077:
078: m_popupMenu = new JPopupMenu("SessionMonitor Actions");
079: m_popupMenu.add(m_refreshAction);
080:
081: addActionBinding(REFRESH_ACTION, m_refreshAction);
082: }
083:
084: public JPopupMenu getPopupMenu() {
085: return m_popupMenu;
086: }
087:
088: public void refresh() {
089: ((SessionMonitorPanel) getComponent()).refresh();
090: }
091:
092: private class RefreshAction extends XAbstractAction {
093: private RefreshAction() {
094: super ();
095:
096: setName(AdminClient.getContext().getMessage("refresh.name"));
097: setSmallIcon(ClassesHelper.getHelper().getRefreshIcon());
098: setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0,
099: true));
100: }
101:
102: public void actionPerformed(ActionEvent ae) {
103: refresh();
104: }
105: }
106:
107: public void nodeClicked(MouseEvent me) {
108: m_refreshAction.actionPerformed(null);
109: }
110: }
|