1 4 package org.terracotta.dso.editors; 5 6 import org.dijon.ContainerResource; 7 8 import org.terracotta.dso.editors.xmlbeans.XmlBooleanToggle; 9 import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureChangeEvent; 10 import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureListener; 11 import com.terracottatech.config.DsoClientDebugging; 12 import com.terracottatech.config.RuntimeLogging; 13 14 import java.awt.event.ActionEvent ; 15 import java.awt.event.ActionListener ; 16 17 public class RuntimeLoggingPanel extends ConfigurationEditorPanel 18 implements ActionListener , 19 XmlObjectStructureListener 20 { 21 private DsoClientDebugging m_dsoClientDebugging; 22 private RuntimeLogging m_runtimeLogging; 23 private XmlBooleanToggle m_lockDebug; 24 private XmlBooleanToggle m_waitNotifyDebug; 25 private XmlBooleanToggle m_distributedMethodDebug; 26 private XmlBooleanToggle m_newObjectDebug; 27 28 public RuntimeLoggingPanel() { 29 super(); 30 } 31 32 public void load(ContainerResource containerRes) { 33 super.load(containerRes); 34 35 m_lockDebug = (XmlBooleanToggle)findComponent("LockDebug"); 36 init(m_lockDebug, "lock-debug"); 37 38 m_waitNotifyDebug = (XmlBooleanToggle)findComponent("WaitNotifyDebug"); 39 init(m_waitNotifyDebug, "wait-notify-debug"); 40 41 m_distributedMethodDebug = 42 (XmlBooleanToggle)findComponent("DistributedMethodDebug"); 43 init(m_distributedMethodDebug, "distributed-method-debug"); 44 45 m_newObjectDebug = (XmlBooleanToggle)findComponent("NewObjectDebug"); 46 init(m_newObjectDebug, "new-object-debug"); 47 } 48 49 public void ensureXmlObject() { 50 super.ensureXmlObject(); 51 52 if(m_runtimeLogging == null) { 53 removeListeners(); 54 m_runtimeLogging = m_dsoClientDebugging.addNewRuntimeLogging(); 55 updateChildren(); 56 addListeners(); 57 } 58 } 59 60 public void structureChanged(XmlObjectStructureChangeEvent e) { 61 syncModel(); 62 } 63 64 public void actionPerformed(ActionEvent ae) { 65 setDirty(); 66 } 67 68 public boolean hasAnySet() { 69 return m_runtimeLogging != null && 70 (m_runtimeLogging.isSetLockDebug() || 71 m_runtimeLogging.isSetWaitNotifyDebug() || 72 m_runtimeLogging.isSetDistributedMethodDebug() || 73 m_runtimeLogging.isSetNewObjectDebug()); 74 } 75 76 private void syncModel() { 77 if(!hasAnySet() && m_dsoClientDebugging.getRuntimeLogging() != null) { 78 m_dsoClientDebugging.unsetRuntimeLogging(); 79 m_runtimeLogging = null; 80 fireXmlObjectStructureChanged(); 81 updateChildren(); 82 } 83 else { 84 setDirty(); 85 } 86 } 87 88 private void fireXmlObjectStructureChanged() { 89 fireXmlObjectStructureChanged(m_dsoClientDebugging); 90 } 91 92 private void addListeners() { 93 m_lockDebug.addActionListener(this); 94 m_lockDebug.addXmlObjectStructureListener(this); 95 96 m_waitNotifyDebug.addActionListener(this); 97 m_waitNotifyDebug.addXmlObjectStructureListener(this); 98 99 m_distributedMethodDebug.addActionListener(this); 100 m_distributedMethodDebug.addXmlObjectStructureListener(this); 101 102 m_newObjectDebug.addActionListener(this); 103 m_newObjectDebug.addXmlObjectStructureListener(this); 104 } 105 106 private void removeListeners() { 107 m_lockDebug.removeActionListener(this); 108 m_lockDebug.removeXmlObjectStructureListener(this); 109 110 m_waitNotifyDebug.removeActionListener(this); 111 m_waitNotifyDebug.removeXmlObjectStructureListener(this); 112 113 m_distributedMethodDebug.removeActionListener(this); 114 m_distributedMethodDebug.removeXmlObjectStructureListener(this); 115 116 m_newObjectDebug.removeActionListener(this); 117 m_newObjectDebug.removeXmlObjectStructureListener(this); 118 } 119 120 private void updateChildren() { 121 setup(m_lockDebug); 122 setup(m_waitNotifyDebug); 123 setup(m_distributedMethodDebug); 124 setup(m_newObjectDebug); 125 } 126 127 public void setup(DsoClientDebugging dsoClientDebugging) { 128 removeListeners(); 129 setEnabled(true); 130 131 m_dsoClientDebugging = dsoClientDebugging; 132 m_runtimeLogging = m_dsoClientDebugging != null ? 133 m_dsoClientDebugging.getRuntimeLogging() : null; 134 135 updateChildren(); 136 addListeners(); 137 } 138 139 public void tearDown() { 140 removeListeners(); 141 142 m_dsoClientDebugging = null; 143 m_runtimeLogging = null; 144 145 m_lockDebug.tearDown(); 146 m_waitNotifyDebug.tearDown(); 147 m_distributedMethodDebug.tearDown(); 148 m_newObjectDebug.tearDown(); 149 150 setEnabled(false); 151 } 152 153 private void init(XmlBooleanToggle toggle, String elementName) { 154 toggle.init(RuntimeLogging.class, elementName); 155 } 156 157 private void setup(XmlBooleanToggle toggle) { 158 toggle.setup(m_runtimeLogging); 159 } 160 } 161 | Popular Tags |