01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package org.terracotta.dso.dialogs;
06:
07: import org.eclipse.jface.dialogs.IDialogConstants;
08: import org.eclipse.jface.dialogs.MessageDialog;
09: import org.eclipse.swt.SWT;
10: import org.eclipse.swt.layout.GridData;
11: import org.eclipse.swt.layout.GridLayout;
12: import org.eclipse.swt.widgets.Composite;
13: import org.eclipse.swt.widgets.Control;
14: import org.eclipse.swt.widgets.Label;
15: import org.eclipse.swt.widgets.Shell;
16: import org.eclipse.swt.widgets.Text;
17:
18: public class AddModuleDialog extends MessageDialog {
19:
20: private static final String NAME = "Name";
21: private static final String VERSION = "Version";
22: private Text m_moduleName;
23: private Text m_moduleVersion;
24: private ValueListener m_valueListener;
25:
26: public AddModuleDialog(Shell parentShell, String title,
27: String message) {
28: super (parentShell, title, null, message, MessageDialog.NONE,
29: new String[] { IDialogConstants.OK_LABEL,
30: IDialogConstants.CANCEL_LABEL }, 0);
31: }
32:
33: protected Control createCustomArea(Composite parent) {
34: final Composite comp = new Composite(parent, SWT.NONE);
35: GridLayout gridLayout = new GridLayout();
36: gridLayout.numColumns = 2;
37: comp.setLayout(gridLayout);
38: comp.setLayoutData(new GridData(GridData.FILL_BOTH));
39:
40: Label nameLabel = new Label(comp, SWT.RIGHT);
41: nameLabel.setText(NAME);
42: nameLabel.setLayoutData(new GridData(
43: GridData.VERTICAL_ALIGN_CENTER));
44:
45: m_moduleName = new Text(comp, SWT.SINGLE | SWT.BORDER);
46: m_moduleName.setLayoutData(new GridData(GridData.FILL_BOTH
47: | GridData.VERTICAL_ALIGN_CENTER));
48:
49: Label versionLabel = new Label(comp, SWT.RIGHT);
50: versionLabel.setText(VERSION);
51: versionLabel.setLayoutData(new GridData(
52: GridData.VERTICAL_ALIGN_CENTER));
53:
54: m_moduleVersion = new Text(comp, SWT.SINGLE | SWT.BORDER);
55: m_moduleVersion.setLayoutData(new GridData(GridData.FILL_BOTH
56: | GridData.VERTICAL_ALIGN_CENTER));
57:
58: return comp;
59: }
60:
61: protected void buttonPressed(int buttonId) {
62: if (buttonId == IDialogConstants.OK_ID) {
63: if (m_valueListener != null)
64: m_valueListener.setValues(m_moduleName.getText(),
65: m_moduleVersion.getText());
66: }
67: super .buttonPressed(buttonId);
68: }
69:
70: public void addValueListener(ValueListener listener) {
71: this .m_valueListener = listener;
72: }
73:
74: // --------------------------------------------------------------------------------
75:
76: public static interface ValueListener {
77: void setValues(String name, String version);
78: }
79: }
|