KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > editors > AddModuleDialog


1 /*
2  * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package org.terracotta.dso.editors;
6
7 import org.eclipse.jface.dialogs.IDialogConstants;
8 import org.eclipse.jface.dialogs.MessageDialog;
9 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 JavaDoc title, String JavaDoc message) {
25     super(parentShell, title, null, message, MessageDialog.NONE, new String JavaDoc[] {
26       IDialogConstants.OK_LABEL,
27       IDialogConstants.CANCEL_LABEL }, 0);
28   }
29
30   protected Control createCustomArea(Composite parent) {
31     final Composite comp = new Composite(parent, SWT.NONE);
32     GridLayout gridLayout = new GridLayout();
33     gridLayout.numColumns = 2;
34     comp.setLayout(gridLayout);
35     comp.setLayoutData(new GridData(GridData.FILL_BOTH));
36
37     GridData gridData = new GridData();
38     gridData.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER;
39     Label nameLabel = new Label(comp, SWT.RIGHT);
40     nameLabel.setText("Name");
41     nameLabel.setLayoutData(gridData);
42
43     m_moduleName = new Text(comp, SWT.SINGLE | SWT.BORDER);
44     m_moduleName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
45
46     Label versionLabel = new Label(comp, SWT.RIGHT);
47     versionLabel.setText("Version");
48     versionLabel.setLayoutData(gridData);
49
50     m_moduleVersion = new Text(comp, SWT.SINGLE | SWT.BORDER);
51     m_moduleVersion.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
52
53     return comp;
54   }
55
56   protected void buttonPressed(int buttonId) {
57     if (buttonId == IDialogConstants.OK_ID) {
58       if (m_valueListener != null) m_valueListener.setValues(m_moduleName.getText(), m_moduleVersion.getText());
59     }
60     super.buttonPressed(buttonId);
61   }
62
63   public void addValueListener(ValueListener listener) {
64     this.m_valueListener = listener;
65   }
66
67   // --------------------------------------------------------------------------------
68

69   public static interface ValueListener {
70     void setValues(String JavaDoc name, String JavaDoc version);
71   }
72 }
73
Popular Tags