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.events.SelectionAdapter;
008: import org.eclipse.swt.events.SelectionEvent;
009: import org.eclipse.swt.layout.GridData;
010: import org.eclipse.swt.layout.GridLayout;
011: import org.eclipse.swt.widgets.Button;
012: import org.eclipse.swt.widgets.Composite;
013: import org.eclipse.swt.widgets.Group;
014: import org.eclipse.swt.widgets.Label;
015: import org.eclipse.swt.widgets.Text;
016: import org.terracotta.dso.editors.chooser.FolderBehavior;
017: import org.terracotta.dso.editors.chooser.NavigatorBehavior;
018: import org.terracotta.dso.editors.chooser.PackageNavigator;
019: import org.terracotta.dso.editors.xmlbeans.XmlIntegerField;
020: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureChangeEvent;
021: import org.terracotta.dso.editors.xmlbeans.XmlObjectStructureListener;
022: import org.terracotta.dso.editors.xmlbeans.XmlStringField;
023: import org.terracotta.ui.util.SWTLayout;
024: import org.terracotta.ui.util.SWTUtil;
025:
026: import com.tc.util.event.UpdateEvent;
027: import com.tc.util.event.UpdateEventListener;
028: import com.terracottatech.config.Server;
029:
030: public class ServerPanel extends ConfigurationEditorPanel implements
031: XmlObjectStructureListener {
032: private Server m_server;
033: private Layout m_layout;
034:
035: private LogsBrowseSelectionHandler m_logsBrowseSelectionHandler;
036: private DataBrowseSelectionHandler m_dataBrowseSelectionHandler;
037:
038: public ServerPanel(Composite parent, int style) {
039: super (parent, style);
040: m_layout = new Layout(this );
041:
042: m_logsBrowseSelectionHandler = new LogsBrowseSelectionHandler();
043: m_dataBrowseSelectionHandler = new DataBrowseSelectionHandler();
044:
045: SWTUtil.setBGColorRecurse(this .getDisplay().getSystemColor(
046: SWT.COLOR_WHITE), this );
047: }
048:
049: public void structureChanged(XmlObjectStructureChangeEvent e) {
050: fireChanged();
051: }
052:
053: void fireChanged() {
054: ServersPanel serversPanel = (ServersPanel) SWTUtil
055: .getAncestorOfClass(ServersPanel.class, this );
056: serversPanel.fireServerChanged(m_server);
057: }
058:
059: public boolean hasAnySet() {
060: return m_server != null
061: && (m_server.isSetData() || m_server.isSetLogs()
062: || m_server.isSetDsoPort()
063: || m_server.isSetDso()
064: || m_server.isSetJmxPort()
065: || m_server.isSetAuthentication()
066: || m_server.isSetName() || m_server.isSetHost() || m_server
067: .isSetL2GroupPort());
068: }
069:
070: private void addListeners() {
071: ((XmlStringField) m_layout.m_nameField.getData())
072: .addXmlObjectStructureListener(this );
073: ((XmlStringField) m_layout.m_hostField.getData())
074: .addXmlObjectStructureListener(this );
075: ((XmlStringField) m_layout.m_dsoPortField.getData())
076: .addXmlObjectStructureListener(this );
077: ((XmlStringField) m_layout.m_jmxPortField.getData())
078: .addXmlObjectStructureListener(this );
079: ((XmlStringField) m_layout.m_dataLocation.getData())
080: .addXmlObjectStructureListener(this );
081: ((XmlStringField) m_layout.m_logsLocation.getData())
082: .addXmlObjectStructureListener(this );
083: m_layout.m_dataBrowse
084: .addSelectionListener(m_dataBrowseSelectionHandler);
085: m_layout.m_logsBrowse
086: .addSelectionListener(m_logsBrowseSelectionHandler);
087: m_layout.m_dsoServerDataPanel
088: .addXmlObjectStructureListener(this );
089: }
090:
091: private void removeListeners() {
092: ((XmlStringField) m_layout.m_nameField.getData())
093: .removeXmlObjectStructureListener(this );
094: ((XmlStringField) m_layout.m_hostField.getData())
095: .removeXmlObjectStructureListener(this );
096: ((XmlStringField) m_layout.m_dsoPortField.getData())
097: .removeXmlObjectStructureListener(this );
098: ((XmlStringField) m_layout.m_jmxPortField.getData())
099: .removeXmlObjectStructureListener(this );
100: ((XmlStringField) m_layout.m_dataLocation.getData())
101: .removeXmlObjectStructureListener(this );
102: ((XmlStringField) m_layout.m_logsLocation.getData())
103: .removeXmlObjectStructureListener(this );
104: m_layout.m_dataBrowse
105: .removeSelectionListener(m_dataBrowseSelectionHandler);
106: m_layout.m_logsBrowse
107: .removeSelectionListener(m_logsBrowseSelectionHandler);
108: m_layout.m_dsoServerDataPanel
109: .removeXmlObjectStructureListener(this );
110: }
111:
112: private void updateChildren() {
113: m_layout.setServer(m_server);
114: }
115:
116: public void setup(Server server) {
117: setEnabled(true);
118: removeListeners();
119:
120: if ((m_server = server) != null) {
121: updateChildren();
122: addListeners();
123: } else {
124: setEnabled(false);
125: }
126: }
127:
128: public void tearDown() {
129: removeListeners();
130: m_server = null;
131: m_layout.tearDown();
132: setEnabled(false);
133: }
134:
135: private class Layout implements SWTLayout {
136: private static final String BROWSE = "Browse...";
137: private static final String NAME = "Name";
138: private static final String HOST = "Host";
139: private static final String DSO_PORT = "DSO Port";
140: private static final String JMX_PORT = "JMX Port";
141: private static final String SERVER = "Server";
142: private static final String DATA = "Data";
143: private static final String LOGS = "Logs";
144:
145: private Text m_nameField;
146: private Text m_hostField;
147: private Text m_dsoPortField;
148: private Text m_jmxPortField;
149: private Text m_dataLocation;
150: private Text m_logsLocation;
151: private Button m_logsBrowse;
152: private Button m_dataBrowse;
153: private Group m_serverGroup;
154: private DsoServerDataPanel m_dsoServerDataPanel;
155:
156: public void reset() {
157: resetServerFields(false);
158: }
159:
160: void tearDown() {
161: ((XmlStringField) m_nameField.getData()).tearDown();
162: ((XmlStringField) m_hostField.getData()).tearDown();
163: ((XmlIntegerField) m_dsoPortField.getData()).tearDown();
164: ((XmlIntegerField) m_jmxPortField.getData()).tearDown();
165: ((XmlStringField) m_dataLocation.getData()).tearDown();
166: ((XmlStringField) m_logsLocation.getData()).tearDown();
167:
168: m_dsoServerDataPanel.tearDown();
169: }
170:
171: private void setServer(Server server) {
172: ((XmlStringField) m_nameField.getData()).setup(server);
173: ((XmlStringField) m_hostField.getData()).setup(server);
174: ((XmlIntegerField) m_dsoPortField.getData()).setup(server);
175: ((XmlIntegerField) m_jmxPortField.getData()).setup(server);
176: ((XmlStringField) m_dataLocation.getData()).setup(server);
177: ((XmlStringField) m_logsLocation.getData()).setup(server);
178:
179: m_dsoServerDataPanel.setup(server);
180: }
181:
182: private void resetServerFields(boolean enabled) {
183: m_nameField.setText("");
184: m_nameField.setEnabled(enabled);
185: m_hostField.setText("");
186: m_hostField.setEnabled(enabled);
187: m_dsoPortField.setText("");
188: m_dsoPortField.setEnabled(enabled);
189: m_jmxPortField.setText("");
190: m_jmxPortField.setEnabled(enabled);
191: m_dataLocation.setText("");
192: m_dataLocation.setEnabled(enabled);
193: m_logsLocation.setText("");
194: m_logsLocation.setEnabled(enabled);
195: m_dataBrowse.setEnabled(enabled);
196: m_logsBrowse.setEnabled(enabled);
197: }
198:
199: private Layout(Composite parent) {
200: GridLayout gridLayout = new GridLayout();
201: parent.setLayout(gridLayout);
202:
203: m_serverGroup = new Group(parent, SWT.SHADOW_NONE);
204: m_serverGroup.setText(SERVER);
205: m_serverGroup.setLayout(new GridLayout(2, true));
206: m_serverGroup
207: .setLayoutData(new GridData(GridData.FILL_BOTH));
208:
209: Composite fieldGroup = new Composite(m_serverGroup,
210: SWT.NONE);
211: gridLayout = new GridLayout(5, false);
212: fieldGroup.setLayout(gridLayout);
213: fieldGroup.setLayoutData(new GridData(SWT.FILL,
214: SWT.BEGINNING, true, true));
215:
216: Label nameLabel = new Label(fieldGroup, SWT.NONE);
217: nameLabel.setText(NAME);
218: m_nameField = new Text(fieldGroup, SWT.BORDER);
219: GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
220: gridData.minimumWidth = SWTUtil.textColumnsToPixels(
221: m_nameField, 10);
222: m_nameField.setLayoutData(gridData);
223: initStringField(m_nameField, Server.class, "name");
224:
225: new Label(fieldGroup, SWT.NONE); // space
226:
227: Label dsoPortLabel = new Label(fieldGroup, SWT.NONE);
228: dsoPortLabel.setText(DSO_PORT);
229: m_dsoPortField = new Text(fieldGroup, SWT.BORDER);
230: SWTUtil.makeIntField(m_dsoPortField);
231: gridData = new GridData(GridData.GRAB_HORIZONTAL);
232: gridData.minimumWidth = SWTUtil.textColumnsToPixels(
233: m_dsoPortField, 6);
234: m_dsoPortField.setLayoutData(gridData);
235: initIntegerField(m_dsoPortField, Server.class, "dso-port");
236:
237: Label hostLabel = new Label(fieldGroup, SWT.NONE);
238: hostLabel.setText(HOST);
239: m_hostField = new Text(fieldGroup, SWT.BORDER);
240: m_hostField.setLayoutData(new GridData(
241: GridData.FILL_HORIZONTAL));
242: initStringField(m_hostField, Server.class, "host");
243:
244: new Label(fieldGroup, SWT.NONE); // space
245:
246: Label jmxPortLabel = new Label(fieldGroup, SWT.NONE);
247: jmxPortLabel.setText(JMX_PORT);
248: m_jmxPortField = new Text(fieldGroup, SWT.BORDER);
249: SWTUtil.makeIntField(m_jmxPortField);
250: gridData = new GridData(GridData.GRAB_HORIZONTAL);
251: gridData.minimumWidth = SWTUtil.textColumnsToPixels(
252: m_jmxPortField, 6);
253: m_jmxPortField.setLayoutData(gridData);
254: initIntegerField(m_jmxPortField, Server.class, "jmx-port");
255:
256: Label dataLabel = new Label(fieldGroup, SWT.NONE);
257: dataLabel.setText(DATA);
258:
259: Composite dataPanel = new Composite(fieldGroup, SWT.NONE);
260: gridLayout = new GridLayout(2, false);
261: gridLayout.marginWidth = gridLayout.marginHeight = 0;
262: dataPanel.setLayout(gridLayout);
263: gridData = new GridData(GridData.FILL_BOTH);
264: gridData.horizontalSpan = 4;
265: dataPanel.setLayoutData(gridData);
266:
267: m_dataLocation = new Text(dataPanel, SWT.BORDER);
268: gridData = new GridData(GridData.FILL_HORIZONTAL);
269: m_dataLocation.setLayoutData(gridData);
270: initStringField(m_dataLocation, Server.class, "data");
271:
272: m_dataBrowse = new Button(dataPanel, SWT.PUSH);
273: m_dataBrowse.setText(BROWSE);
274: SWTUtil.applyDefaultButtonSize(m_dataBrowse);
275:
276: Label logsLabel = new Label(fieldGroup, SWT.NONE);
277: logsLabel.setText(LOGS);
278:
279: Composite logsPanel = new Composite(fieldGroup, SWT.NONE);
280: gridLayout = new GridLayout(2, false);
281: gridLayout.marginWidth = gridLayout.marginHeight = 0;
282: logsPanel.setLayout(gridLayout);
283: gridData = new GridData(GridData.FILL_BOTH);
284: gridData.horizontalSpan = 4;
285: logsPanel.setLayoutData(gridData);
286:
287: m_logsLocation = new Text(logsPanel, SWT.BORDER);
288: m_logsLocation.setLayoutData(new GridData(
289: GridData.FILL_HORIZONTAL));
290: initStringField(m_logsLocation, Server.class, "logs");
291:
292: m_logsBrowse = new Button(logsPanel, SWT.PUSH);
293: m_logsBrowse.setText(BROWSE);
294: SWTUtil.applyDefaultButtonSize(m_logsBrowse);
295:
296: m_dsoServerDataPanel = new DsoServerDataPanel(
297: m_serverGroup, SWT.NONE);
298: m_dsoServerDataPanel.setLayoutData(new GridData(SWT.FILL,
299: SWT.BEGINNING, true, true));
300: }
301: }
302:
303: class LogsBrowseSelectionHandler extends SelectionAdapter {
304: public void widgetSelected(SelectionEvent e) {
305: NavigatorBehavior behavior = new FolderBehavior();
306: PackageNavigator dialog = new PackageNavigator(getShell(),
307: behavior.getTitle(), getProject(), behavior);
308: dialog.addValueListener(new UpdateEventListener() {
309: public void handleUpdate(UpdateEvent event) {
310: m_server.setLogs((String) event.data);
311: fireChanged();
312: }
313: });
314: dialog.open();
315: }
316: }
317:
318: class DataBrowseSelectionHandler extends SelectionAdapter {
319: public void widgetSelected(SelectionEvent e) {
320: NavigatorBehavior behavior = new FolderBehavior();
321: PackageNavigator dialog = new PackageNavigator(getShell(),
322: behavior.getTitle(), getProject(), behavior);
323: dialog.addValueListener(new UpdateEventListener() {
324: public void handleUpdate(UpdateEvent event) {
325: m_server.setData((String) event.data);
326: fireChanged();
327: }
328: });
329: dialog.open();
330: }
331: }
332: }
|