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.editors;
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 Text m_moduleName;
21: private Text m_moduleVersion;
22: private ValueListener m_valueListener;
23:
24: public AddModuleDialog(Shell parentShell, String title,
25: String message) {
26: super (parentShell, title, null, message, MessageDialog.NONE,
27: new String[] { IDialogConstants.OK_LABEL,
28: IDialogConstants.CANCEL_LABEL }, 0);
29: }
30:
31: protected Control createCustomArea(Composite parent) {
32: final Composite comp = new Composite(parent, SWT.NONE);
33: GridLayout gridLayout = new GridLayout();
34: gridLayout.numColumns = 2;
35: comp.setLayout(gridLayout);
36: comp.setLayoutData(new GridData(GridData.FILL_BOTH));
37:
38: GridData gridData = new GridData();
39: gridData.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER;
40: Label nameLabel = new Label(comp, SWT.RIGHT);
41: nameLabel.setText("Name");
42: nameLabel.setLayoutData(gridData);
43:
44: m_moduleName = new Text(comp, SWT.SINGLE | SWT.BORDER);
45: m_moduleName.setLayoutData(new GridData(
46: GridData.FILL_HORIZONTAL));
47:
48: Label versionLabel = new Label(comp, SWT.RIGHT);
49: versionLabel.setText("Version");
50: versionLabel.setLayoutData(gridData);
51:
52: m_moduleVersion = new Text(comp, SWT.SINGLE | SWT.BORDER);
53: m_moduleVersion.setLayoutData(new GridData(
54: GridData.FILL_HORIZONTAL));
55:
56: return comp;
57: }
58:
59: protected void buttonPressed(int buttonId) {
60: if (buttonId == IDialogConstants.OK_ID) {
61: if (m_valueListener != null)
62: m_valueListener.setValues(m_moduleName.getText(),
63: m_moduleVersion.getText());
64: }
65: super .buttonPressed(buttonId);
66: }
67:
68: public void addValueListener(ValueListener listener) {
69: this .m_valueListener = listener;
70: }
71:
72: // --------------------------------------------------------------------------------
73:
74: public static interface ValueListener {
75: void setValues(String name, String version);
76: }
77: }
|