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 org.terracotta.dso.editors;
005:
006: import org.eclipse.swt.SWT;
007: import org.eclipse.swt.layout.GridData;
008: import org.eclipse.swt.layout.GridLayout;
009: import org.eclipse.swt.widgets.Button;
010: import org.eclipse.swt.widgets.Composite;
011: import org.eclipse.swt.widgets.Group;
012: import org.terracotta.dso.editors.xmlbeans.XmlBooleanToggle;
013: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureChangeEvent;
014: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureListener;
015: import org.terracotta.ui.util.SWTUtil;
016:
017: import com.terracottatech.config.DsoClientDebugging;
018: import com.terracottatech.config.RuntimeLogging;
019:
020: public class RuntimeLoggingPanel extends ConfigurationEditorPanel
021: implements XmlObjectStructureListener {
022: private DsoClientDebugging m_dsoClientDebugging;
023: private RuntimeLogging m_runtimeLogging;
024: private Layout m_layout;
025:
026: public RuntimeLoggingPanel(Composite parent, int style) {
027: super (parent, style);
028: m_layout = new Layout(this );
029: SWTUtil.setBGColorRecurse(this .getDisplay().getSystemColor(
030: SWT.COLOR_WHITE), this );
031: }
032:
033: public void ensureXmlObject() {
034: super .ensureXmlObject();
035:
036: if (m_runtimeLogging == null) {
037: removeListeners();
038: m_runtimeLogging = m_dsoClientDebugging
039: .addNewRuntimeLogging();
040: updateChildren();
041: addListeners();
042: }
043: }
044:
045: public void structureChanged(XmlObjectStructureChangeEvent e) {
046: testRemoveRuntimeLogging();
047: }
048:
049: public boolean hasAnySet() {
050: return m_runtimeLogging != null
051: && (m_runtimeLogging.isSetLockDebug()
052: || m_runtimeLogging.isSetWaitNotifyDebug()
053: || m_runtimeLogging
054: .isSetDistributedMethodDebug() || m_runtimeLogging
055: .isSetNewObjectDebug());
056: }
057:
058: private void testRemoveRuntimeLogging() {
059: if (!hasAnySet()
060: && m_dsoClientDebugging.getRuntimeLogging() != null) {
061: m_dsoClientDebugging.unsetRuntimeLogging();
062: m_runtimeLogging = null;
063: fireXmlObjectStructureChanged();
064: updateChildren();
065: }
066: fireClientChanged();
067: }
068:
069: private void fireXmlObjectStructureChanged() {
070: fireXmlObjectStructureChanged(m_dsoClientDebugging);
071: }
072:
073: private void addListeners() {
074: ((XmlBooleanToggle) m_layout.m_lockDebugCheck.getData())
075: .addXmlObjectStructureListener(this );
076: ((XmlBooleanToggle) m_layout.m_distributedMethodDebugCheck
077: .getData()).addXmlObjectStructureListener(this );
078: ((XmlBooleanToggle) m_layout.m_fieldChangeDebugCheck.getData())
079: .addXmlObjectStructureListener(this );
080: ((XmlBooleanToggle) m_layout.m_nonPortableDumpCheck.getData())
081: .addXmlObjectStructureListener(this );
082: ((XmlBooleanToggle) m_layout.m_waitNotifyDebugCheck.getData())
083: .addXmlObjectStructureListener(this );
084: ((XmlBooleanToggle) m_layout.m_newObjectDebugCheck.getData())
085: .addXmlObjectStructureListener(this );
086: }
087:
088: private void removeListeners() {
089: ((XmlBooleanToggle) m_layout.m_lockDebugCheck.getData())
090: .removeXmlObjectStructureListener(this );
091: ((XmlBooleanToggle) m_layout.m_distributedMethodDebugCheck
092: .getData()).removeXmlObjectStructureListener(this );
093: ((XmlBooleanToggle) m_layout.m_fieldChangeDebugCheck.getData())
094: .removeXmlObjectStructureListener(this );
095: ((XmlBooleanToggle) m_layout.m_nonPortableDumpCheck.getData())
096: .removeXmlObjectStructureListener(this );
097: ((XmlBooleanToggle) m_layout.m_waitNotifyDebugCheck.getData())
098: .removeXmlObjectStructureListener(this );
099: ((XmlBooleanToggle) m_layout.m_newObjectDebugCheck.getData())
100: .removeXmlObjectStructureListener(this );
101: }
102:
103: private void updateChildren() {
104: m_layout.setRuntimeLogging(m_runtimeLogging);
105: }
106:
107: public void setup(DsoClientDebugging dsoClientDebugging) {
108: removeListeners();
109: setEnabled(true);
110:
111: m_dsoClientDebugging = dsoClientDebugging;
112: m_runtimeLogging = m_dsoClientDebugging != null ? m_dsoClientDebugging
113: .getRuntimeLogging()
114: : null;
115:
116: updateChildren();
117: addListeners();
118: }
119:
120: public void tearDown() {
121: removeListeners();
122:
123: m_dsoClientDebugging = null;
124: m_runtimeLogging = null;
125:
126: ((XmlBooleanToggle) m_layout.m_lockDebugCheck.getData())
127: .tearDown();
128: ((XmlBooleanToggle) m_layout.m_distributedMethodDebugCheck
129: .getData()).tearDown();
130: ((XmlBooleanToggle) m_layout.m_fieldChangeDebugCheck.getData())
131: .tearDown();
132: ((XmlBooleanToggle) m_layout.m_nonPortableDumpCheck.getData())
133: .tearDown();
134: ((XmlBooleanToggle) m_layout.m_waitNotifyDebugCheck.getData())
135: .tearDown();
136: ((XmlBooleanToggle) m_layout.m_newObjectDebugCheck.getData())
137: .tearDown();
138:
139: setEnabled(false);
140: }
141:
142: private class Layout {
143: private static final String RUNTIME_LOGGING = "Runtime Logging";
144: private static final String LOCK_DEBUG = "Lock Debug";
145: private static final String DISTRIBUTED_METHOD_DEBUG = "Distributed Method Debug";
146: private static final String FIELD_CHANGE_DEBUG = "Field Change Debug";
147: private static final String NON_PORTABLE_DUMP = "Non-portable Dump";
148: private static final String WAIT_NOTIFY_DEBUG = "Wait Notify Debug";
149: private static final String NEW_OBJECT_DEBUG = "New Object Debug";
150:
151: private Button m_lockDebugCheck;
152: private Button m_distributedMethodDebugCheck;
153: private Button m_fieldChangeDebugCheck;
154: private Button m_nonPortableDumpCheck;
155: private Button m_waitNotifyDebugCheck;
156: private Button m_newObjectDebugCheck;
157:
158: public void reset() {
159: m_lockDebugCheck.setSelection(false);
160: m_lockDebugCheck.setEnabled(false);
161: m_distributedMethodDebugCheck.setSelection(false);
162: m_distributedMethodDebugCheck.setEnabled(false);
163: m_fieldChangeDebugCheck.setSelection(false);
164: m_fieldChangeDebugCheck.setEnabled(false);
165: m_nonPortableDumpCheck.setSelection(false);
166: m_nonPortableDumpCheck.setEnabled(false);
167: m_waitNotifyDebugCheck.setSelection(false);
168: m_waitNotifyDebugCheck.setEnabled(false);
169: m_newObjectDebugCheck.setSelection(false);
170: m_newObjectDebugCheck.setEnabled(false);
171: }
172:
173: void setRuntimeLogging(RuntimeLogging runtimeLogging) {
174: ((XmlBooleanToggle) m_lockDebugCheck.getData())
175: .setup(runtimeLogging);
176: ((XmlBooleanToggle) m_distributedMethodDebugCheck.getData())
177: .setup(runtimeLogging);
178: ((XmlBooleanToggle) m_fieldChangeDebugCheck.getData())
179: .setup(runtimeLogging);
180: ((XmlBooleanToggle) m_nonPortableDumpCheck.getData())
181: .setup(runtimeLogging);
182: ((XmlBooleanToggle) m_waitNotifyDebugCheck.getData())
183: .setup(runtimeLogging);
184: ((XmlBooleanToggle) m_newObjectDebugCheck.getData())
185: .setup(runtimeLogging);
186: }
187:
188: private Layout(Composite parent) {
189: parent.setLayout(new GridLayout());
190:
191: Group runtimeLoggingGroup = new Group(parent,
192: SWT.SHADOW_NONE);
193: runtimeLoggingGroup.setText(RUNTIME_LOGGING);
194: GridLayout gridLayout = new GridLayout();
195: gridLayout.verticalSpacing = 3;
196: runtimeLoggingGroup.setLayout(gridLayout);
197: GridData gridData = new GridData(GridData.FILL_HORIZONTAL
198: | GridData.VERTICAL_ALIGN_BEGINNING);
199: runtimeLoggingGroup.setLayoutData(gridData);
200:
201: m_lockDebugCheck = new Button(runtimeLoggingGroup,
202: SWT.CHECK);
203: m_lockDebugCheck.setText(LOCK_DEBUG);
204: initBooleanField(m_lockDebugCheck, RuntimeLogging.class,
205: "lock-debug");
206:
207: m_distributedMethodDebugCheck = new Button(
208: runtimeLoggingGroup, SWT.CHECK);
209: m_distributedMethodDebugCheck
210: .setText(DISTRIBUTED_METHOD_DEBUG);
211: initBooleanField(m_distributedMethodDebugCheck,
212: RuntimeLogging.class, "distributed-method-debug");
213:
214: m_fieldChangeDebugCheck = new Button(runtimeLoggingGroup,
215: SWT.CHECK);
216: m_fieldChangeDebugCheck.setText(FIELD_CHANGE_DEBUG);
217: initBooleanField(m_fieldChangeDebugCheck,
218: RuntimeLogging.class, "field-change-debug");
219:
220: m_nonPortableDumpCheck = new Button(runtimeLoggingGroup,
221: SWT.CHECK);
222: m_nonPortableDumpCheck.setText(NON_PORTABLE_DUMP);
223: initBooleanField(m_nonPortableDumpCheck,
224: RuntimeLogging.class, "non-portable-dump");
225:
226: m_waitNotifyDebugCheck = new Button(runtimeLoggingGroup,
227: SWT.CHECK);
228: m_waitNotifyDebugCheck.setText(WAIT_NOTIFY_DEBUG);
229: initBooleanField(m_waitNotifyDebugCheck,
230: RuntimeLogging.class, "wait-notify-debug");
231:
232: m_newObjectDebugCheck = new Button(runtimeLoggingGroup,
233: SWT.CHECK);
234: m_newObjectDebugCheck.setText(NEW_OBJECT_DEBUG);
235: initBooleanField(m_newObjectDebugCheck,
236: RuntimeLogging.class, "new-object-debug");
237: }
238: }
239: }
|