001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package org.terracotta.dso.dialogs;
006:
007: import org.eclipse.jface.dialogs.IDialogConstants;
008: import org.eclipse.jface.dialogs.MessageDialog;
009: import org.eclipse.swt.SWT;
010: import org.eclipse.swt.layout.GridData;
011: import org.eclipse.swt.layout.GridLayout;
012: import org.eclipse.swt.widgets.Button;
013: import org.eclipse.swt.widgets.Composite;
014: import org.eclipse.swt.widgets.Control;
015: import org.eclipse.swt.widgets.Group;
016: import org.eclipse.swt.widgets.Shell;
017:
018: import com.tc.util.event.EventMulticaster;
019: import com.tc.util.event.UpdateEvent;
020: import com.tc.util.event.UpdateEventListener;
021: import com.terracottatech.config.LockLevel;
022:
023: public class AutolockDialog extends MessageDialog {
024:
025: private static final String TITLE = "Specify Autolock Attributes";
026: private final EventMulticaster m_valueListener;
027: private Layout m_layout;
028:
029: public AutolockDialog(Shell shell, String message) {
030: super (shell, TITLE, null, message, MessageDialog.NONE,
031: new String[] { IDialogConstants.OK_LABEL,
032: IDialogConstants.CANCEL_LABEL }, 0);
033: this .m_valueListener = new EventMulticaster();
034: }
035:
036: public void addValueListener(UpdateEventListener listener) {
037: m_valueListener.addListener(listener);
038: }
039:
040: protected Control createCustomArea(Composite parent) {
041: m_layout = new Layout(parent);
042: return parent;
043: }
044:
045: protected void buttonPressed(int buttonId) {
046: if (buttonId == IDialogConstants.OK_ID) {
047: LockLevel.Enum lockLevel;
048: if (m_layout.m_read.getSelection())
049: lockLevel = LockLevel.READ;
050: else if (m_layout.m_write.getSelection())
051: lockLevel = LockLevel.WRITE;
052: else if (m_layout.m_synchronousWrite.getSelection())
053: lockLevel = LockLevel.SYNCHRONOUS_WRITE;
054: else
055: lockLevel = LockLevel.CONCURRENT;
056:
057: m_valueListener.fireUpdateEvent(new UpdateEvent(
058: new Object[] { m_layout.m_autoSync.getSelection(),
059: lockLevel }));
060: }
061: super .buttonPressed(buttonId);
062: }
063:
064: // --------------------------------------------------------------------------------
065:
066: private static class Layout {
067: private static final String AUTO_SYNCHRONIZE = "Auto-synchronize";
068: private static final String TYPE = "Type";
069: private static final String READ = "Read";
070: private static final String WRITE = "Write";
071: private static final String CONCURRENT = "Concurrent";
072: private static final String SYNCHRONOUS_WRITE = "Synchronous-write";
073: private final Button m_autoSync;
074: private final Button m_read;
075: private final Button m_write;
076: private final Button m_synchronousWrite;
077: private final Button m_concurrent;
078:
079: private Layout(Composite parent) {
080: Composite comp = new Composite(parent, SWT.NONE);
081: comp.setLayout(new GridLayout());
082: comp.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER,
083: true, true));
084:
085: Group typeGroup = new Group(comp, SWT.NONE);
086: typeGroup.setText(TYPE);
087: typeGroup.setLayout(new GridLayout(4, false));
088: m_read = new Button(typeGroup, SWT.RADIO);
089: m_read.setText(READ);
090: m_write = new Button(typeGroup, SWT.RADIO);
091: m_write.setText(WRITE);
092: m_write.setSelection(true);
093: m_synchronousWrite = new Button(typeGroup, SWT.RADIO);
094: m_synchronousWrite.setText(SYNCHRONOUS_WRITE);
095: m_concurrent = new Button(typeGroup, SWT.RADIO);
096: m_concurrent.setText(CONCURRENT);
097:
098: m_autoSync = new Button(comp, SWT.CHECK);
099: m_autoSync.setText(AUTO_SYNCHRONIZE);
100: m_autoSync.setLayoutData(new GridData(SWT.BEGINNING,
101: SWT.BEGINNING, false, false));
102: }
103: }
104: }
|