1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.importer.wizard.dialog;
19
20 import org.eclipse.jface.dialogs.IDialogConstants;
21 import org.eclipse.jface.dialogs.IInputValidator;
22 import org.eclipse.jface.dialogs.InputDialog;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.SelectionAdapter;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Shell;
29
30 import pl.edu.agh.cast.importer.wizard.util.Messages;
31 import pl.edu.agh.cast.ui.util.MsgBoxHelper;
32
33
34
35
36
37
38 public class DataSetNameDialog extends InputDialog {
39
40 private final String defaultName;
41
42 private Button defaultNameBtn;
43
44
45
46
47
48
49
50
51
52 public DataSetNameDialog(Shell parent, String initialValue) {
53 super(parent, Messages.DataSetNameDialog_Title, Messages.DataSetNameDialog_0, initialValue,
54 new DataSetNameValidator());
55 defaultName = initialValue;
56 }
57
58
59
60
61
62
63
64
65 @Override
66 protected void createButtonsForButtonBar(Composite parent) {
67
68
69 createButton(parent, IDialogConstants.OK_ID, Messages.DataSetNameDialog_Save, true);
70
71 Button cancelBtn = createButton(parent, IDialogConstants.CLIENT_ID, IDialogConstants.CANCEL_LABEL, false);
72 cancelBtn.addSelectionListener(new SelectionAdapter() {
73 @Override
74 public void widgetSelected(SelectionEvent e) {
75 if (MsgBoxHelper.showQuestionBox(getParentShell(), Messages.DataSetNameDialog_3,
76 Messages.DataSetNameDialog_4) == SWT.YES) {
77 cancelPressed();
78 }
79 }
80 });
81 defaultNameBtn = createButton(parent, IDialogConstants.CLIENT_ID + 1, Messages.DataSetNameDialog_1, false);
82 defaultNameBtn.addSelectionListener(new SelectionAdapter() {
83
84 @Override
85 public void widgetSelected(SelectionEvent e) {
86 getText().setText(defaultName);
87 getText().selectAll();
88 }
89 });
90
91
92
93 getText().setFocus();
94 if (getValue() != null) {
95 getText().setText(getValue());
96 getText().selectAll();
97 }
98 }
99
100
101
102
103
104 static class DataSetNameValidator implements IInputValidator {
105
106
107
108
109
110
111
112
113
114 @Override
115 public String isValid(String newText) {
116 if (newText == null || newText.trim().length() == 0) {
117 return Messages.DataSetNameDialog_2;
118 }
119
120
121 return null;
122 }
123 }
124
125 }