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.RuntimeOutputOptions;
019:
020: public class RuntimeOutputOptionsPanel extends ConfigurationEditorPanel
021: implements XmlObjectStructureListener {
022: private DsoClientDebugging m_dsoClientDebugging;
023: private RuntimeOutputOptions m_runtimeOutputOptions;
024: private Layout m_layout;
025:
026: public RuntimeOutputOptionsPanel(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_runtimeOutputOptions == null) {
037: removeListeners();
038: m_runtimeOutputOptions = m_dsoClientDebugging
039: .addNewRuntimeOutputOptions();
040: updateChildren();
041: addListeners();
042: }
043: }
044:
045: public boolean hasAnySet() {
046: return m_runtimeOutputOptions != null
047: && (m_runtimeOutputOptions.isSetAutoLockDetails()
048: || m_runtimeOutputOptions.isSetCaller() || m_runtimeOutputOptions
049: .isSetFullStack());
050: }
051:
052: private void testRemoveRuntimeOutputOptions() {
053: if (!hasAnySet()
054: && m_dsoClientDebugging.getRuntimeOutputOptions() != null) {
055: m_dsoClientDebugging.unsetRuntimeOutputOptions();
056: m_runtimeOutputOptions = null;
057: fireXmlObjectStructureChanged();
058: }
059: fireClientChanged();
060: }
061:
062: private void fireXmlObjectStructureChanged() {
063: fireXmlObjectStructureChanged(m_dsoClientDebugging);
064: }
065:
066: public void structureChanged(XmlObjectStructureChangeEvent e) {
067: testRemoveRuntimeOutputOptions();
068: }
069:
070: private void addListeners() {
071: ((XmlBooleanToggle) m_layout.m_autoLockDetailsCheck.getData())
072: .addXmlObjectStructureListener(this );
073: ((XmlBooleanToggle) m_layout.m_callerCheck.getData())
074: .addXmlObjectStructureListener(this );
075: ((XmlBooleanToggle) m_layout.m_fullStackCheck.getData())
076: .addXmlObjectStructureListener(this );
077: }
078:
079: private void removeListeners() {
080: ((XmlBooleanToggle) m_layout.m_autoLockDetailsCheck.getData())
081: .removeXmlObjectStructureListener(this );
082: ((XmlBooleanToggle) m_layout.m_callerCheck.getData())
083: .removeXmlObjectStructureListener(this );
084: ((XmlBooleanToggle) m_layout.m_fullStackCheck.getData())
085: .removeXmlObjectStructureListener(this );
086: }
087:
088: private void updateChildren() {
089: m_layout.setRuntimeOutputOptions(m_runtimeOutputOptions);
090: }
091:
092: public void setup(DsoClientDebugging dsoClientDebugging) {
093: removeListeners();
094: setEnabled(true);
095:
096: m_dsoClientDebugging = dsoClientDebugging;
097: m_runtimeOutputOptions = m_dsoClientDebugging != null ? m_dsoClientDebugging
098: .getRuntimeOutputOptions()
099: : null;
100:
101: updateChildren();
102: addListeners();
103: }
104:
105: public void tearDown() {
106: removeListeners();
107:
108: m_dsoClientDebugging = null;
109: m_runtimeOutputOptions = null;
110:
111: m_layout.tearDown();
112:
113: setEnabled(false);
114: }
115:
116: private class Layout {
117: private static final String RUNTIME_OUTPUT_OPTIONS = "Runtime Output Options";
118: private static final String AUTOLOCK_DETAILS = "Autolock Details";
119: private static final String CALLER = "Caller";
120: private static final String FULL_STACK = "Full Stack";
121:
122: private Button m_autoLockDetailsCheck;
123: private Button m_callerCheck;
124: private Button m_fullStackCheck;
125:
126: public void reset() {
127: m_autoLockDetailsCheck.setSelection(false);
128: m_autoLockDetailsCheck.setEnabled(false);
129: m_callerCheck.setSelection(false);
130: m_callerCheck.setEnabled(false);
131: m_fullStackCheck.setSelection(false);
132: m_fullStackCheck.setEnabled(false);
133: }
134:
135: void setRuntimeOutputOptions(
136: RuntimeOutputOptions runtimeOutputOptions) {
137: ((XmlBooleanToggle) m_autoLockDetailsCheck.getData())
138: .setup(runtimeOutputOptions);
139: ((XmlBooleanToggle) m_callerCheck.getData())
140: .setup(runtimeOutputOptions);
141: ((XmlBooleanToggle) m_fullStackCheck.getData())
142: .setup(runtimeOutputOptions);
143: }
144:
145: void tearDown() {
146: ((XmlBooleanToggle) m_autoLockDetailsCheck.getData())
147: .tearDown();
148: ((XmlBooleanToggle) m_callerCheck.getData()).tearDown();
149: ((XmlBooleanToggle) m_fullStackCheck.getData()).tearDown();
150: }
151:
152: private Layout(Composite parent) {
153: parent.setLayout(new GridLayout());
154:
155: Group runtimeOutputOptionsGroup = new Group(parent,
156: SWT.SHADOW_NONE);
157: runtimeOutputOptionsGroup.setText(RUNTIME_OUTPUT_OPTIONS);
158: GridLayout gridLayout = new GridLayout();
159: gridLayout.verticalSpacing = 3;
160: runtimeOutputOptionsGroup.setLayout(gridLayout);
161: runtimeOutputOptionsGroup.setLayoutData(new GridData(
162: GridData.FILL_HORIZONTAL
163: | GridData.VERTICAL_ALIGN_BEGINNING));
164:
165: m_autoLockDetailsCheck = new Button(
166: runtimeOutputOptionsGroup, SWT.CHECK);
167: m_autoLockDetailsCheck.setText(AUTOLOCK_DETAILS);
168: initBooleanField(m_autoLockDetailsCheck,
169: RuntimeOutputOptions.class, "auto-lock-details");
170:
171: m_callerCheck = new Button(runtimeOutputOptionsGroup,
172: SWT.CHECK);
173: m_callerCheck.setText(CALLER);
174: initBooleanField(m_callerCheck, RuntimeOutputOptions.class,
175: "caller");
176:
177: m_fullStackCheck = new Button(runtimeOutputOptionsGroup,
178: SWT.CHECK);
179: m_fullStackCheck.setText(FULL_STACK);
180: initBooleanField(m_fullStackCheck,
181: RuntimeOutputOptions.class, "full-stack");
182: }
183: }
184: }
|