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.InstrumentationLogging;
019:
020: public class InstrumentationLoggingPanel extends
021: ConfigurationEditorPanel implements XmlObjectStructureListener {
022: private DsoClientDebugging m_dsoClientDebugging;
023: private InstrumentationLogging m_instrumentationLogging;
024: private Layout m_layout;
025:
026: public InstrumentationLoggingPanel(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_instrumentationLogging == null) {
037: removeListeners();
038: m_instrumentationLogging = m_dsoClientDebugging
039: .addNewInstrumentationLogging();
040: updateChildren();
041: addListeners();
042: }
043: }
044:
045: public void structureChanged(XmlObjectStructureChangeEvent ae) {
046: testRemoveInstrumenationLogging();
047: }
048:
049: private void testRemoveInstrumenationLogging() {
050: if (!hasAnySet()
051: && m_dsoClientDebugging.getInstrumentationLogging() != null) {
052: m_dsoClientDebugging.unsetInstrumentationLogging();
053: m_instrumentationLogging = null;
054: fireXmlObjectStructureChanged();
055: updateChildren();
056: }
057: fireClientChanged();
058: }
059:
060: private void fireXmlObjectStructureChanged() {
061: fireXmlObjectStructureChanged(m_dsoClientDebugging);
062: }
063:
064: public boolean hasAnySet() {
065: return m_instrumentationLogging != null
066: && (m_instrumentationLogging.isSetClass1()
067: || m_instrumentationLogging.isSetHierarchy()
068: || m_instrumentationLogging.isSetLocks()
069: || m_instrumentationLogging
070: .isSetTransientRoot()
071: || m_instrumentationLogging.isSetRoots() || m_instrumentationLogging
072: .isSetDistributedMethods());
073: }
074:
075: private void addListeners() {
076: ((XmlBooleanToggle) m_layout.m_classCheck.getData())
077: .addXmlObjectStructureListener(this );
078: ((XmlBooleanToggle) m_layout.m_hierarchyCheck.getData())
079: .addXmlObjectStructureListener(this );
080: ((XmlBooleanToggle) m_layout.m_locksCheck.getData())
081: .addXmlObjectStructureListener(this );
082: ((XmlBooleanToggle) m_layout.m_transientRootCheck.getData())
083: .addXmlObjectStructureListener(this );
084: ((XmlBooleanToggle) m_layout.m_distributedMethodsCheck
085: .getData()).addXmlObjectStructureListener(this );
086: ((XmlBooleanToggle) m_layout.m_rootsCheck.getData())
087: .addXmlObjectStructureListener(this );
088: }
089:
090: private void removeListeners() {
091: ((XmlBooleanToggle) m_layout.m_classCheck.getData())
092: .removeXmlObjectStructureListener(this );
093: ((XmlBooleanToggle) m_layout.m_hierarchyCheck.getData())
094: .removeXmlObjectStructureListener(this );
095: ((XmlBooleanToggle) m_layout.m_locksCheck.getData())
096: .removeXmlObjectStructureListener(this );
097: ((XmlBooleanToggle) m_layout.m_transientRootCheck.getData())
098: .removeXmlObjectStructureListener(this );
099: ((XmlBooleanToggle) m_layout.m_distributedMethodsCheck
100: .getData()).removeXmlObjectStructureListener(this );
101: ((XmlBooleanToggle) m_layout.m_rootsCheck.getData())
102: .removeXmlObjectStructureListener(this );
103: }
104:
105: private void updateChildren() {
106: m_layout.setInstrumentationLogging(m_instrumentationLogging);
107: }
108:
109: public void setup(DsoClientDebugging dsoClientDebugging) {
110: removeListeners();
111: setEnabled(true);
112:
113: m_dsoClientDebugging = dsoClientDebugging;
114: m_instrumentationLogging = m_dsoClientDebugging != null ? m_dsoClientDebugging
115: .getInstrumentationLogging()
116: : null;
117:
118: updateChildren();
119: addListeners();
120: }
121:
122: public void tearDown() {
123: removeListeners();
124:
125: m_dsoClientDebugging = null;
126: m_instrumentationLogging = null;
127:
128: ((XmlBooleanToggle) m_layout.m_classCheck.getData()).tearDown();
129: ((XmlBooleanToggle) m_layout.m_hierarchyCheck.getData())
130: .tearDown();
131: ((XmlBooleanToggle) m_layout.m_locksCheck.getData()).tearDown();
132: ((XmlBooleanToggle) m_layout.m_transientRootCheck.getData())
133: .tearDown();
134: ((XmlBooleanToggle) m_layout.m_distributedMethodsCheck
135: .getData()).tearDown();
136: ((XmlBooleanToggle) m_layout.m_rootsCheck.getData()).tearDown();
137:
138: setEnabled(false);
139: }
140:
141: private class Layout {
142: private static final String INSTRUMENTATION_LOGGING = "Instrumentation Logging";
143: private static final String CLASS = "Class";
144: private static final String HIERARCHY = "Hierarchy";
145: private static final String LOCKS = "Locks";
146: private static final String TRANSIENT_ROOT = "Transient Root";
147: private static final String DISTRIBUTED_METHODS = "Distributed Methods";
148: private static final String ROOTS = "Roots";
149:
150: private Button m_classCheck;
151: private Button m_hierarchyCheck;
152: private Button m_locksCheck;
153: private Button m_transientRootCheck;
154: private Button m_distributedMethodsCheck;
155: private Button m_rootsCheck;
156:
157: public void reset() {
158: m_classCheck.setSelection(false);
159: m_classCheck.setEnabled(false);
160: m_hierarchyCheck.setSelection(false);
161: m_hierarchyCheck.setEnabled(false);
162: m_locksCheck.setSelection(false);
163: m_locksCheck.setEnabled(false);
164: m_transientRootCheck.setSelection(false);
165: m_transientRootCheck.setEnabled(false);
166: m_distributedMethodsCheck.setSelection(false);
167: m_distributedMethodsCheck.setEnabled(false);
168: m_rootsCheck.setSelection(false);
169: m_rootsCheck.setEnabled(false);
170: }
171:
172: void setInstrumentationLogging(
173: InstrumentationLogging instrumentationLogging) {
174: ((XmlBooleanToggle) m_classCheck.getData())
175: .setup(instrumentationLogging);
176: ((XmlBooleanToggle) m_hierarchyCheck.getData())
177: .setup(instrumentationLogging);
178: ((XmlBooleanToggle) m_locksCheck.getData())
179: .setup(instrumentationLogging);
180: ((XmlBooleanToggle) m_transientRootCheck.getData())
181: .setup(instrumentationLogging);
182: ((XmlBooleanToggle) m_distributedMethodsCheck.getData())
183: .setup(instrumentationLogging);
184: ((XmlBooleanToggle) m_rootsCheck.getData())
185: .setup(instrumentationLogging);
186: }
187:
188: private Layout(Composite parent) {
189: parent.setLayout(new GridLayout());
190:
191: Group instrumentationLoggingGroup = new Group(parent,
192: SWT.SHADOW_NONE);
193: instrumentationLoggingGroup
194: .setText(INSTRUMENTATION_LOGGING);
195: GridLayout gridLayout = new GridLayout();
196: gridLayout.verticalSpacing = 3;
197: instrumentationLoggingGroup.setLayout(gridLayout);
198: GridData gridData = new GridData(GridData.FILL_HORIZONTAL
199: | GridData.VERTICAL_ALIGN_BEGINNING);
200: instrumentationLoggingGroup.setLayoutData(gridData);
201:
202: m_classCheck = new Button(instrumentationLoggingGroup,
203: SWT.CHECK);
204: m_classCheck.setText(CLASS);
205: initBooleanField(m_classCheck,
206: InstrumentationLogging.class, "class1");
207:
208: m_hierarchyCheck = new Button(instrumentationLoggingGroup,
209: SWT.CHECK);
210: m_hierarchyCheck.setText(HIERARCHY);
211: initBooleanField(m_hierarchyCheck,
212: InstrumentationLogging.class, "hierarchy");
213:
214: m_locksCheck = new Button(instrumentationLoggingGroup,
215: SWT.CHECK);
216: m_locksCheck.setText(LOCKS);
217: initBooleanField(m_locksCheck,
218: InstrumentationLogging.class, "locks");
219:
220: m_transientRootCheck = new Button(
221: instrumentationLoggingGroup, SWT.CHECK);
222: m_transientRootCheck.setText(TRANSIENT_ROOT);
223: initBooleanField(m_transientRootCheck,
224: InstrumentationLogging.class, "transient-root");
225:
226: m_distributedMethodsCheck = new Button(
227: instrumentationLoggingGroup, SWT.CHECK);
228: m_distributedMethodsCheck.setText(DISTRIBUTED_METHODS);
229: initBooleanField(m_distributedMethodsCheck,
230: InstrumentationLogging.class, "distributed-methods");
231:
232: m_rootsCheck = new Button(instrumentationLoggingGroup,
233: SWT.CHECK);
234: m_rootsCheck.setText(ROOTS);
235: initBooleanField(m_rootsCheck,
236: InstrumentationLogging.class, "roots");
237: }
238: }
239: }
|