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.Composite;
010: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureChangeEvent;
011: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureListener;
012: import org.terracotta.ui.util.SWTUtil;
013:
014: import com.terracottatech.config.DsoClientData;
015: import com.terracottatech.config.DsoClientDebugging;
016:
017: public class DsoClientDebuggingPanel extends ConfigurationEditorPanel
018: implements XmlObjectStructureListener {
019: private DsoClientData m_dsoClientData;
020: private DsoClientDebugging m_dsoClientDebugging;
021: private Layout m_layout;
022:
023: public DsoClientDebuggingPanel(Composite parent, int style) {
024: super (parent, style);
025: m_layout = new Layout(this );
026: SWTUtil.setBGColorRecurse(this .getDisplay().getSystemColor(
027: SWT.COLOR_WHITE), this );
028: }
029:
030: public void ensureXmlObject() {
031: super .ensureXmlObject();
032:
033: if (m_dsoClientDebugging == null) {
034: removeListeners();
035: m_dsoClientDebugging = m_dsoClientData.addNewDebugging();
036: updateChildren();
037: addListeners();
038: }
039: }
040:
041: public boolean hasAnySet() {
042: return m_dsoClientDebugging != null
043: && (m_dsoClientDebugging.isSetInstrumentationLogging()
044: || m_dsoClientDebugging.isSetRuntimeLogging() || m_dsoClientDebugging
045: .isSetRuntimeOutputOptions());
046: }
047:
048: private void addListeners() {
049: m_layout.m_instrumentationLoggingPanel
050: .addXmlObjectStructureListener(this );
051: m_layout.m_runtimeLoggingPanel
052: .addXmlObjectStructureListener(this );
053: m_layout.m_runtimeOutputOptionsPanel
054: .addXmlObjectStructureListener(this );
055: }
056:
057: private void removeListeners() {
058: m_layout.m_instrumentationLoggingPanel
059: .removeXmlObjectStructureListener(this );
060: m_layout.m_runtimeLoggingPanel
061: .removeXmlObjectStructureListener(this );
062: m_layout.m_runtimeOutputOptionsPanel
063: .removeXmlObjectStructureListener(this );
064: }
065:
066: public void structureChanged(XmlObjectStructureChangeEvent e) {
067: if (!hasAnySet() && m_dsoClientData.getDebugging() != null) {
068: m_dsoClientData.unsetDebugging();
069: m_dsoClientDebugging = null;
070: fireXmlObjectStructureChanged();
071: }
072: }
073:
074: private void fireXmlObjectStructureChanged() {
075: fireXmlObjectStructureChanged(m_dsoClientData);
076: }
077:
078: private void updateChildren() {
079: m_layout.setup(m_dsoClientDebugging);
080: }
081:
082: public void setup(DsoClientData dsoClientData) {
083: removeListeners();
084: setEnabled(true);
085:
086: m_dsoClientData = dsoClientData;
087: m_dsoClientDebugging = m_dsoClientData != null ? m_dsoClientData
088: .getDebugging()
089: : null;
090:
091: updateChildren();
092: addListeners();
093: }
094:
095: public void tearDown() {
096: removeListeners();
097:
098: m_dsoClientData = null;
099: m_dsoClientDebugging = null;
100:
101: m_layout.m_instrumentationLoggingPanel.tearDown();
102: m_layout.m_runtimeLoggingPanel.tearDown();
103: m_layout.m_runtimeOutputOptionsPanel.tearDown();
104:
105: setEnabled(false);
106: }
107:
108: private class Layout {
109: private InstrumentationLoggingPanel m_instrumentationLoggingPanel;
110: private RuntimeLoggingPanel m_runtimeLoggingPanel;
111: private RuntimeOutputOptionsPanel m_runtimeOutputOptionsPanel;
112:
113: void setup(DsoClientDebugging dsoClientDebugging) {
114: m_instrumentationLoggingPanel.setup(m_dsoClientDebugging);
115: m_runtimeLoggingPanel.setup(m_dsoClientDebugging);
116: m_runtimeOutputOptionsPanel.setup(m_dsoClientDebugging);
117: }
118:
119: private Layout(Composite parent) {
120: parent.setLayout(new GridLayout());
121:
122: Composite comp = new Composite(parent, SWT.NONE);
123: GridLayout gridLayout = new GridLayout(3, false);
124: gridLayout.marginWidth = gridLayout.marginHeight = 0;
125: comp.setLayout(gridLayout);
126: comp.setLayoutData(new GridData(GridData.FILL_BOTH));
127:
128: m_instrumentationLoggingPanel = new InstrumentationLoggingPanel(
129: comp, SWT.NONE);
130: m_instrumentationLoggingPanel.setLayoutData(new GridData(
131: SWT.END, SWT.BEGINNING, true, false));
132:
133: m_runtimeLoggingPanel = new RuntimeLoggingPanel(comp,
134: SWT.NONE);
135: m_runtimeLoggingPanel.setLayoutData(new GridData(
136: SWT.CENTER, SWT.BEGINNING, false, false));
137:
138: m_runtimeOutputOptionsPanel = new RuntimeOutputOptionsPanel(
139: comp, SWT.NONE);
140: m_runtimeOutputOptionsPanel.setLayoutData(new GridData(
141: SWT.BEGINNING, SWT.BEGINNING, true, false));
142: }
143: }
144: }
|