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.eclipse.swt.widgets.Group;
011: import org.eclipse.swt.widgets.Label;
012: import org.eclipse.swt.widgets.Spinner;
013: import org.terracotta.dso.editors.xmlbeans.XmlIntegerSpinner;
014: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureChangeEvent;
015: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureListener;
016: import org.terracotta.ui.util.SWTLayout;
017: import org.terracotta.ui.util.SWTUtil;
018:
019: import com.terracottatech.config.DsoServerData;
020: import com.terracottatech.config.Server;
021:
022: public class DsoServerDataPanel extends ConfigurationEditorPanel
023: implements XmlObjectStructureListener {
024: private Server m_server;
025: private DsoServerData m_dsoServerData;
026: private Layout m_layout;
027:
028: public DsoServerDataPanel(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_dsoServerData == null) {
039: removeListeners();
040: m_dsoServerData = m_server.addNewDso();
041: updateChildren();
042: addListeners();
043: }
044: }
045:
046: public boolean hasAnySet() {
047: return m_dsoServerData != null
048: && (m_dsoServerData.isSetGarbageCollection()
049: || m_dsoServerData.isSetPersistence() || m_dsoServerData
050: .isSetClientReconnectWindow());
051: }
052:
053: public void structureChanged(XmlObjectStructureChangeEvent e) {
054: testUnsetDsoServerData();
055: }
056:
057: private void testUnsetDsoServerData() {
058: if (!hasAnySet() && m_server.getDso() != null) {
059: m_server.unsetDso();
060: m_dsoServerData = null;
061: fireXmlObjectStructureChanged();
062: updateChildren();
063: }
064: fireServerChanged();
065: }
066:
067: void fireServerChanged() {
068: ServersPanel serversPanel = (ServersPanel) SWTUtil
069: .getAncestorOfClass(ServersPanel.class, this );
070: serversPanel.fireServerChanged(m_server);
071: }
072:
073: private void fireXmlObjectStructureChanged() {
074: fireXmlObjectStructureChanged(m_server);
075: }
076:
077: private void addListeners() {
078: ((XmlIntegerSpinner) m_layout.m_clientReconnectWindowSpinner
079: .getData()).addXmlObjectStructureListener(this );
080: m_layout.m_garbageCollectionPanel
081: .addXmlObjectStructureListener(this );
082: m_layout.m_persistencePanel.addXmlObjectStructureListener(this );
083: }
084:
085: private void removeListeners() {
086: ((XmlIntegerSpinner) m_layout.m_clientReconnectWindowSpinner
087: .getData()).removeXmlObjectStructureListener(this );
088: m_layout.m_garbageCollectionPanel
089: .removeXmlObjectStructureListener(this );
090: m_layout.m_persistencePanel
091: .removeXmlObjectStructureListener(this );
092: }
093:
094: private void updateChildren() {
095: m_layout.setDsoServerData(m_dsoServerData);
096: }
097:
098: public void setup(Server server) {
099: setEnabled(true);
100: removeListeners();
101:
102: m_server = server;
103: m_dsoServerData = m_server != null ? m_server.getDso() : null;
104:
105: updateChildren();
106: addListeners();
107: }
108:
109: public void tearDown() {
110: removeListeners();
111:
112: m_server = null;
113: m_dsoServerData = null;
114:
115: m_layout.tearDown();
116:
117: setEnabled(false);
118: }
119:
120: private class Layout implements SWTLayout {
121: private static final String CLIENT_RECONNECT = "Client re-connect";
122: private static final String CLIENT_RECONNECT_WINDOW = "Window (sec.)";
123:
124: private Spinner m_clientReconnectWindowSpinner;
125: private GarbageCollectionPanel m_garbageCollectionPanel;
126: private PersistencePanel m_persistencePanel;
127:
128: void tearDown() {
129: ((XmlIntegerSpinner) m_clientReconnectWindowSpinner
130: .getData()).tearDown();
131: m_garbageCollectionPanel.tearDown();
132: m_persistencePanel.tearDown();
133: }
134:
135: public void reset() {
136: setDsoServerData(null);
137: }
138:
139: private void setDsoServerData(DsoServerData dsoServerData) {
140: ((XmlIntegerSpinner) m_clientReconnectWindowSpinner
141: .getData()).setup(dsoServerData);
142: m_garbageCollectionPanel.setup(dsoServerData);
143: m_persistencePanel.setup(dsoServerData);
144: }
145:
146: private Layout(Composite parent) {
147: parent.setLayout(new GridLayout());
148:
149: Group clientReconnectGroup = new Group(parent, SWT.NONE);
150: clientReconnectGroup.setText(CLIENT_RECONNECT);
151: GridLayout gridLayout = new GridLayout(2, false);
152: gridLayout.marginWidth = gridLayout.marginHeight = 10;
153: clientReconnectGroup.setLayout(gridLayout);
154:
155: Label label = new Label(clientReconnectGroup, SWT.NONE);
156: label.setText(CLIENT_RECONNECT_WINDOW);
157:
158: m_clientReconnectWindowSpinner = new Spinner(
159: clientReconnectGroup, SWT.BORDER);
160: initIntegerSpinnerField(m_clientReconnectWindowSpinner,
161: DsoServerData.class, "client-reconnect-window");
162: clientReconnectGroup.setLayoutData(new GridData(
163: GridData.FILL_HORIZONTAL));
164:
165: m_garbageCollectionPanel = new GarbageCollectionPanel(
166: parent, SWT.NONE);
167: m_garbageCollectionPanel.setLayoutData(new GridData(
168: GridData.FILL_HORIZONTAL));
169:
170: m_persistencePanel = new PersistencePanel(parent, SWT.NONE);
171: m_persistencePanel.setLayoutData(new GridData(
172: GridData.FILL_HORIZONTAL));
173: }
174: }
175: }
|