01: package org.pentaho.designstudio.editors.actionsequence.preferences;
02:
03: import java.util.Arrays;
04: import java.util.List;
05:
06: import org.eclipse.jface.dialogs.IInputValidator;
07: import org.eclipse.jface.dialogs.InputDialog;
08: import org.eclipse.swt.widgets.Shell;
09: import org.pentaho.designstudio.messages.Messages;
10:
11: public class InputSourceDialog extends InputDialog {
12:
13: static class Validator implements IInputValidator {
14:
15: List existingSources;
16:
17: Validator(String[] existingSources) {
18: this .existingSources = Arrays.asList(existingSources);
19: }
20:
21: public String isValid(String newText) {
22: String msg = null;
23: newText = newText.trim();
24: if (newText.length() > 0) {
25: if (existingSources.contains(newText)) {
26: msg = Messages
27: .getString("InputSourceDialog.DUPLICATE_SOURCE_NAME"); //$NON-NLS-1$
28: } else if (newText.indexOf(":") != -1) { //$NON-NLS-1$
29: msg = Messages
30: .getString("InputSourceDialog.INVALID_NAME_1"); //$NON-NLS-1$
31: } else if (!Character.isLetter(newText.charAt(0))) {
32: msg = Messages
33: .getString("InputSourceDialog.INVALID_NAME_2"); //$NON-NLS-1$
34: } else {
35: for (int i = 0; i < newText.length(); i++) {
36: if (Character.isWhitespace(newText.charAt(i))) {
37: msg = Messages
38: .getString("InputSourceDialog.INVALID_NAME_3"); //$NON-NLS-1$
39: }
40: }
41: }
42: }
43: return msg;
44: }
45:
46: };
47:
48: public InputSourceDialog(Shell parentShell,
49: String[] existingCustomDestinations) {
50: super (
51: parentShell,
52: Messages
53: .getString("InputSourceDialog.NEW_INPUT_SOURCE"), Messages.getString("InputSourceDialog.ENTER_SOURCE_NAME"), "", new Validator(existingCustomDestinations)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
54: }
55: }
|