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: import org.eclipse.swt.widgets.Text;
018:
019: import com.tc.util.event.EventMulticaster;
020: import com.tc.util.event.UpdateEvent;
021: import com.tc.util.event.UpdateEventListener;
022: import com.terracottatech.config.LockLevel;
023:
024: public class NamedLockDialog extends MessageDialog {
025:
026: private static final String TITLE = "Specify Named-Lock Attributes";
027: private final EventMulticaster m_valueListener;
028: private Layout m_layout;
029:
030: public NamedLockDialog(Shell shell, String message) {
031: super (shell, TITLE, null, message, MessageDialog.NONE,
032: new String[] { IDialogConstants.OK_LABEL,
033: IDialogConstants.CANCEL_LABEL }, 0);
034: this .m_valueListener = new EventMulticaster();
035: }
036:
037: public void addValueListener(UpdateEventListener listener) {
038: m_valueListener.addListener(listener);
039: }
040:
041: protected Control createCustomArea(Composite parent) {
042: m_layout = new Layout(parent);
043: return parent;
044: }
045:
046: protected void buttonPressed(int buttonId) {
047: if (buttonId == IDialogConstants.OK_ID) {
048: LockLevel.Enum lockLevel;
049: if (m_layout.m_read.getSelection())
050: lockLevel = LockLevel.READ;
051: else if (m_layout.m_write.getSelection())
052: lockLevel = LockLevel.WRITE;
053: else if (m_layout.m_synchronousWrite.getSelection())
054: lockLevel = LockLevel.SYNCHRONOUS_WRITE;
055: else
056: lockLevel = LockLevel.CONCURRENT;
057:
058: m_valueListener
059: .fireUpdateEvent(new UpdateEvent(new Object[] {
060: m_layout.m_name.getText(), lockLevel }));
061: }
062: super .buttonPressed(buttonId);
063: }
064:
065: // --------------------------------------------------------------------------------
066:
067: private static class Layout {
068: private static final String NAME = "Name";
069: private static final String TYPE = "Type";
070: private static final String READ = "Read";
071: private static final String WRITE = "Write";
072: private static final String CONCURRENT = "Concurrent";
073: private static final String SYNCHRONOUS_WRITE = "Synchronous-write";
074: private final Text m_name;
075: private final Button m_read;
076: private final Button m_write;
077: private final Button m_synchronousWrite;
078: private final Button m_concurrent;
079:
080: private Layout(Composite parent) {
081: Composite comp = new Composite(parent, SWT.NONE);
082: comp.setLayout(new GridLayout());
083: comp.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER,
084: true, true));
085:
086: Group typeGroup = new Group(comp, SWT.NONE);
087: typeGroup.setText(TYPE);
088: typeGroup.setLayout(new GridLayout(4, false));
089: m_read = new Button(typeGroup, SWT.RADIO);
090: m_read.setText(READ);
091: m_write = new Button(typeGroup, SWT.RADIO);
092: m_write.setText(WRITE);
093: m_write.setSelection(true);
094: m_synchronousWrite = new Button(typeGroup, SWT.RADIO);
095: m_synchronousWrite.setText(SYNCHRONOUS_WRITE);
096: m_concurrent = new Button(typeGroup, SWT.RADIO);
097: m_concurrent.setText(CONCURRENT);
098:
099: Group nameGroup = new Group(comp, SWT.NONE);
100: nameGroup.setText(NAME);
101: nameGroup.setLayout(new GridLayout());
102: nameGroup.setLayoutData(new GridData(
103: GridData.FILL_HORIZONTAL));
104: m_name = new Text(nameGroup, SWT.BORDER);
105: m_name
106: .setLayoutData(new GridData(
107: GridData.FILL_HORIZONTAL));
108: }
109: }
110: }
|