001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.admin.dso;
006:
007: import com.tc.admin.AdminClient;
008: import com.tc.admin.AdminClientContext;
009: import com.tc.admin.ConnectionContext;
010: import com.tc.admin.common.ComponentNode;
011: import com.tc.admin.common.XAbstractAction;
012:
013: import java.awt.event.ActionEvent;
014: import java.awt.event.KeyEvent;
015:
016: import javax.swing.Icon;
017: import javax.swing.JCheckBoxMenuItem;
018: import javax.swing.JMenuItem;
019: import javax.swing.JPopupMenu;
020: import javax.swing.KeyStroke;
021: import javax.swing.event.PopupMenuEvent;
022: import javax.swing.event.PopupMenuListener;
023:
024: public class LocksNode extends ComponentNode implements
025: PopupMenuListener {
026: private ConnectionContext m_cc;
027: private JPopupMenu m_popupMenu;
028: private JCheckBoxMenuItem m_enableStatsToggle;
029: private EnableAllClientTracesAction m_enableAllClientTracesAction;
030: private DisableAllClientTracesAction m_disableAllClientTracesAction;
031:
032: private static final String REFRESH_ACTION = "RefreshAction";
033:
034: public LocksNode(ConnectionContext cc) {
035: super ();
036:
037: m_cc = cc;
038:
039: setLabel(AdminClient.getContext().getMessage("dso.locks"));
040: setComponent(new LocksPanel(m_cc));
041:
042: initMenu();
043: }
044:
045: private void initMenu() {
046: RefreshAction refreshAction = new RefreshAction();
047:
048: m_popupMenu = new JPopupMenu("Lock Actions");
049: m_popupMenu.add(refreshAction);
050: m_popupMenu.add(m_enableStatsToggle = new JCheckBoxMenuItem(
051: new StatsEnabledAction()));
052: m_popupMenu
053: .add(new JMenuItem(
054: m_enableAllClientTracesAction = new EnableAllClientTracesAction()));
055: m_popupMenu
056: .add(new JMenuItem(
057: m_disableAllClientTracesAction = new DisableAllClientTracesAction()));
058:
059: addActionBinding(REFRESH_ACTION, refreshAction);
060:
061: m_popupMenu.addPopupMenuListener(this );
062: }
063:
064: public JPopupMenu getPopupMenu() {
065: return m_popupMenu;
066: }
067:
068: public Icon getIcon() {
069: return LocksHelper.getHelper().getLocksIcon();
070: }
071:
072: public void refresh() {
073: ((LocksPanel) getComponent()).refresh();
074: }
075:
076: public class StatsEnabledAction extends XAbstractAction {
077: StatsEnabledAction() {
078: super ("Stats enabled");
079: }
080:
081: public void actionPerformed(ActionEvent ae) {
082: setLockStatisticsEnabled(m_enableStatsToggle.isSelected());
083: }
084: }
085:
086: public class EnableAllClientTracesAction extends XAbstractAction {
087: EnableAllClientTracesAction() {
088: super ("Enable all client traces");
089: }
090:
091: public void actionPerformed(ActionEvent ae) {
092: setAllStatsEnabled(true);
093: }
094: }
095:
096: public class DisableAllClientTracesAction extends XAbstractAction {
097: DisableAllClientTracesAction() {
098: super ("Disable all client traces");
099: }
100:
101: public void actionPerformed(ActionEvent ae) {
102: setAllStatsEnabled(false);
103: }
104: }
105:
106: private class RefreshAction extends XAbstractAction {
107: private RefreshAction() {
108: super ();
109:
110: AdminClientContext acc = AdminClient.getContext();
111:
112: setName(acc.getMessage("refresh.name"));
113: setSmallIcon(LocksHelper.getHelper().getRefreshIcon());
114: setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0,
115: true));
116: }
117:
118: public void actionPerformed(ActionEvent ae) {
119: refresh();
120: }
121: }
122:
123: public void popupMenuCanceled(PopupMenuEvent e) {/**/
124: }
125:
126: public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {/**/
127: }
128:
129: public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
130: boolean lockStatsEnabled = isLockStatisticsEnabled();
131: m_enableStatsToggle.setSelected(lockStatsEnabled);
132: m_enableAllClientTracesAction.setEnabled(lockStatsEnabled);
133: m_disableAllClientTracesAction.setEnabled(lockStatsEnabled);
134: }
135:
136: private boolean isLockStatisticsEnabled() {
137: return ((LocksPanel) getComponent()).isLockStatisticsEnabled();
138: }
139:
140: private void setLockStatisticsEnabled(boolean lockStatsEnabled) {
141: ((LocksPanel) getComponent())
142: .setLockStatisticsEnabled(lockStatsEnabled);
143: }
144:
145: private void setAllStatsEnabled(boolean allStatsEnabled) {
146: ((LocksPanel) getComponent())
147: .setAllClientTracesEnabled(allStatsEnabled);
148: }
149:
150: public void tearDown() {
151: super.tearDown();
152:
153: m_cc = null;
154: m_popupMenu = null;
155: }
156: }
|