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.RuntimeOutputOptions; 13 14 import java.awt.event.ActionEvent ; 15 import java.awt.event.ActionListener ; 16 17 public class RuntimeOutputOptionsPanel extends ConfigurationEditorPanel 18 implements ActionListener , 19 XmlObjectStructureListener 20 { 21 private DsoClientDebugging m_dsoClientDebugging; 22 private RuntimeOutputOptions m_runtimeOutputOptions; 23 private XmlBooleanToggle m_autoLockDetails; 24 private XmlBooleanToggle m_caller; 25 private XmlBooleanToggle m_fullStack; 26 27 public RuntimeOutputOptionsPanel() { 28 super(); 29 } 30 31 public void load(ContainerResource containerRes) { 32 super.load(containerRes); 33 34 m_autoLockDetails = (XmlBooleanToggle)findComponent("AutoLockDetails"); 35 init(m_autoLockDetails, "auto-lock-details"); 36 37 m_caller = (XmlBooleanToggle)findComponent("Caller"); 38 init(m_caller, "caller"); 39 40 m_fullStack = (XmlBooleanToggle)findComponent("FullStack"); 41 init(m_fullStack, "full-stack"); 42 } 43 44 public void ensureXmlObject() { 45 super.ensureXmlObject(); 46 47 if(m_runtimeOutputOptions == null) { 48 removeListeners(); 49 m_runtimeOutputOptions = 50 m_dsoClientDebugging.addNewRuntimeOutputOptions(); 51 updateChildren(); 52 addListeners(); 53 } 54 } 55 56 public boolean hasAnySet() { 57 return m_runtimeOutputOptions != null && 58 (m_runtimeOutputOptions.isSetAutoLockDetails() || 59 m_runtimeOutputOptions.isSetCaller() || 60 m_runtimeOutputOptions.isSetFullStack()); 61 } 62 63 private void syncModel() { 64 if(!hasAnySet() && 65 m_dsoClientDebugging.getRuntimeOutputOptions() != null) 66 { 67 m_dsoClientDebugging.unsetRuntimeOutputOptions(); 68 m_runtimeOutputOptions = null; 69 fireXmlObjectStructureChanged(); 70 } 71 else { 72 setDirty(); 73 } 74 } 75 76 private void fireXmlObjectStructureChanged() { 77 fireXmlObjectStructureChanged(m_dsoClientDebugging); 78 } 79 80 public void structureChanged(XmlObjectStructureChangeEvent e) { 81 syncModel(); 82 } 83 84 public void actionPerformed(ActionEvent ae) { 85 setDirty(); 86 } 87 88 private void addListeners() { 89 m_autoLockDetails.addActionListener(this); 90 m_autoLockDetails.addXmlObjectStructureListener(this); 91 92 m_caller.addActionListener(this); 93 m_caller.addXmlObjectStructureListener(this); 94 95 m_fullStack.addActionListener(this); 96 m_fullStack.addXmlObjectStructureListener(this); 97 } 98 99 private void removeListeners() { 100 m_autoLockDetails.removeActionListener(this); 101 m_autoLockDetails.removeXmlObjectStructureListener(this); 102 103 m_caller.removeActionListener(this); 104 m_caller.removeXmlObjectStructureListener(this); 105 106 m_fullStack.removeActionListener(this); 107 m_fullStack.removeXmlObjectStructureListener(this); 108 } 109 110 private void updateChildren() { 111 setup(m_autoLockDetails); 112 setup(m_caller); 113 setup(m_fullStack); 114 } 115 116 public void setup(DsoClientDebugging dsoClientDebugging) { 117 removeListeners(); 118 setEnabled(true); 119 120 m_dsoClientDebugging = dsoClientDebugging; 121 m_runtimeOutputOptions = m_dsoClientDebugging != null ? 122 m_dsoClientDebugging.getRuntimeOutputOptions() : 123 null; 124 125 updateChildren(); 126 addListeners(); 127 } 128 129 public void tearDown() { 130 removeListeners(); 131 132 m_dsoClientDebugging = null; 133 m_runtimeOutputOptions = null; 134 135 m_autoLockDetails.tearDown(); 136 m_caller.tearDown(); 137 m_fullStack.tearDown(); 138 139 setEnabled(false); 140 } 141 142 private void init(XmlBooleanToggle toggle, String elementName) { 143 toggle.init(RuntimeOutputOptions.class, elementName); 144 } 145 146 private void setup(XmlBooleanToggle toggle) { 147 toggle.setup(m_runtimeOutputOptions); 148 } 149 } 150 | Popular Tags |