001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package org.terracotta.dso.editors;
006:
007: import org.eclipse.swt.SWT;
008: import org.eclipse.swt.layout.GridData;
009: import org.eclipse.swt.layout.GridLayout;
010: import org.eclipse.swt.widgets.Composite;
011: import org.eclipse.swt.widgets.Group;
012: import org.eclipse.swt.widgets.Label;
013: import org.eclipse.swt.widgets.Spinner;
014: import org.terracotta.dso.editors.xmlbeans.XmlIntegerSpinner;
015: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureChangeEvent;
016: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureListener;
017: import org.terracotta.ui.util.SWTUtil;
018:
019: import com.terracottatech.config.Client;
020: import com.terracottatech.config.DsoClientData;
021:
022: public class DsoClientDataPanel extends ConfigurationEditorPanel
023: implements XmlObjectStructureListener {
024: private Client m_client;
025: private DsoClientData m_dsoClientData;
026: private Layout m_layout;
027:
028: public DsoClientDataPanel(Composite parent, int style) {
029: super (parent, style);
030: m_layout = new Layout(this );
031: SWTUtil.setBGColorRecurse(this .getDisplay().getSystemColor(
032: SWT.COLOR_WHITE), this );
033: }
034:
035: public void ensureXmlObject() {
036: super .ensureXmlObject();
037:
038: if (m_dsoClientData == null) {
039: removeListeners();
040: m_dsoClientData = m_client.addNewDso();
041: updateChildren();
042: addListeners();
043: }
044: }
045:
046: public boolean hasAnySet() {
047: return m_dsoClientData != null
048: && m_dsoClientData.isSetDebugging()
049: || ((XmlIntegerSpinner) m_layout.m_faultCountSpinner
050: .getData()).isSet();
051: }
052:
053: public void structureChanged(XmlObjectStructureChangeEvent e) {
054: testUnsetDsoClientData();
055: }
056:
057: private void testUnsetDsoClientData() {
058: if (!hasAnySet() && m_client.getDso() != null) {
059: m_client.unsetDso();
060: m_dsoClientData = null;
061: fireXmlObjectStructureChanged();
062: updateChildren();
063: } else {
064: fireClientChanged();
065: }
066: }
067:
068: private void fireXmlObjectStructureChanged() {
069: fireXmlObjectStructureChanged(m_client);
070: }
071:
072: private void addListeners() {
073: m_layout.m_dsoClientDebugging
074: .addXmlObjectStructureListener(this );
075: ((XmlIntegerSpinner) m_layout.m_faultCountSpinner.getData())
076: .addXmlObjectStructureListener(this );
077: }
078:
079: private void removeListeners() {
080: m_layout.m_dsoClientDebugging
081: .removeXmlObjectStructureListener(this );
082: ((XmlIntegerSpinner) m_layout.m_faultCountSpinner.getData())
083: .removeXmlObjectStructureListener(this );
084: }
085:
086: private void updateChildren() {
087: m_layout.setDsoClientData(m_dsoClientData);
088: }
089:
090: public void setup(Client client) {
091: removeListeners();
092: setEnabled(true);
093:
094: m_client = client;
095: m_dsoClientData = m_client != null ? m_client.getDso() : null;
096:
097: updateChildren();
098: addListeners();
099: }
100:
101: public void tearDown() {
102: removeListeners();
103: m_layout.m_dsoClientDebugging.tearDown();
104: ((XmlIntegerSpinner) m_layout.m_faultCountSpinner.getData())
105: .tearDown();
106: setEnabled(false);
107: }
108:
109: private class Layout {
110: private static final String DSO_CLIENT_DATA = "Dso Client Data";
111: private static final String FAULT_COUNT = "Fault Count";
112:
113: private DsoClientDebuggingPanel m_dsoClientDebugging;
114: private Spinner m_faultCountSpinner;
115:
116: void setDsoClientData(DsoClientData dsoClientData) {
117: m_dsoClientDebugging.setup(dsoClientData);
118: ((XmlIntegerSpinner) m_faultCountSpinner.getData())
119: .setup(dsoClientData);
120: }
121:
122: public void reset() {
123: m_faultCountSpinner.setSelection(0);
124: }
125:
126: private Layout(Composite parent) {
127: parent.setLayout(new GridLayout());
128:
129: Group panel = new Group(parent, SWT.SHADOW_NONE);
130: panel.setText(DSO_CLIENT_DATA);
131: GridLayout gridLayout = new GridLayout();
132: panel.setLayout(gridLayout);
133: GridData gridData = new GridData(GridData.FILL_BOTH);
134: panel.setLayoutData(gridData);
135:
136: m_dsoClientDebugging = new DsoClientDebuggingPanel(panel,
137: SWT.NONE);
138: m_dsoClientDebugging.setLayoutData(new GridData(
139: GridData.FILL_BOTH));
140: createFaultCountPane(panel);
141: }
142:
143: private void createFaultCountPane(Composite parent) {
144: Composite faultCountPane = new Composite(parent, SWT.NONE);
145: faultCountPane.setLayout(new GridLayout(2, false));
146: faultCountPane.setLayoutData(new GridData(
147: GridData.FILL_HORIZONTAL
148: | GridData.VERTICAL_ALIGN_BEGINNING));
149: Label faultCountLabel = new Label(faultCountPane, SWT.NONE);
150: faultCountLabel.setText(FAULT_COUNT);
151: faultCountLabel.setLayoutData(new GridData(
152: GridData.VERTICAL_ALIGN_CENTER));
153: m_faultCountSpinner = new Spinner(faultCountPane,
154: SWT.BORDER);
155: m_faultCountSpinner
156: .setLayoutData(new GridData(
157: GridData.FILL_HORIZONTAL
158: | GridData.GRAB_HORIZONTAL));
159: initIntegerSpinnerField(m_faultCountSpinner,
160: DsoClientData.class, "fault-count");
161: }
162: }
163: }
|