diff options
Diffstat (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java')
-rw-r--r-- | plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java new file mode 100644 index 0000000..38e38b1 --- /dev/null +++ b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java | |||
@@ -0,0 +1,63 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2012 BMW Car IT GmbH. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * BMW Car IT - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.ide.preferences; | ||
12 | |||
13 | import org.eclipse.jface.dialogs.IInputValidator; | ||
14 | import org.yocto.sdk.ide.YoctoProfileElement; | ||
15 | import org.yocto.sdk.ide.YoctoSDKMessages; | ||
16 | |||
17 | public class ProfileNameInputValidator implements IInputValidator { | ||
18 | private static final String WARNING_CONTAINS_COMMA = "Preferences.Profile.Validator.InvalidName.Comma"; | ||
19 | private static final String WARNING_CONTAINS_DOUBLEQUOTE = "Preferences.Profile.Validator.InvalidName.Quote"; | ||
20 | private static final String PROFILE_NAME_IS_EMPTY = "Preferences.Profile.Validator.InvalidName.Empty"; | ||
21 | private static final String WARNING_ALREADY_EXISTS = "Preferences.Profile.Validator.InvalidName.Exists"; | ||
22 | |||
23 | private final String selectedItem; | ||
24 | private final YoctoProfileElement profileSetting; | ||
25 | |||
26 | public ProfileNameInputValidator(YoctoProfileElement profileSetting) { | ||
27 | this(profileSetting, ""); | ||
28 | } | ||
29 | |||
30 | public ProfileNameInputValidator(YoctoProfileElement profileSetting, String selectedItem) { | ||
31 | this.selectedItem = selectedItem; | ||
32 | this.profileSetting = profileSetting; | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | public String isValid(String newText) { | ||
37 | if (newText.contains(",")) { | ||
38 | return YoctoSDKMessages.getString(WARNING_CONTAINS_COMMA); | ||
39 | } | ||
40 | |||
41 | if (newText.contains("\"")) { | ||
42 | return YoctoSDKMessages.getString(WARNING_CONTAINS_DOUBLEQUOTE); | ||
43 | } | ||
44 | |||
45 | if (newText.isEmpty()) { | ||
46 | return YoctoSDKMessages.getString(PROFILE_NAME_IS_EMPTY); | ||
47 | } | ||
48 | |||
49 | if (selectedItemEquals(newText)) { | ||
50 | return null; | ||
51 | } | ||
52 | |||
53 | if (profileSetting.contains(newText)) { | ||
54 | return YoctoSDKMessages.getString(WARNING_ALREADY_EXISTS); | ||
55 | } | ||
56 | |||
57 | return null; | ||
58 | } | ||
59 | |||
60 | private boolean selectedItemEquals(String newText) { | ||
61 | return !selectedItem.isEmpty() && newText.equals(selectedItem); | ||
62 | } | ||
63 | } | ||