From c7da892cb23d50d4d85746c9a0b6b14bf570989d Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 26 Jun 2014 13:23:09 +0200 Subject: initial commit for Enea Linux 4.0 Migrated from the internal git server on the daisy-enea branch Signed-off-by: Adrian Dudau --- .../ide/preferences/ProfileNameInputValidator.java | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java (limited to 'plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/ProfileNameInputValidator.java') 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 @@ +/******************************************************************************* + * Copyright (c) 2012 BMW Car IT GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * BMW Car IT - initial API and implementation + *******************************************************************************/ +package org.yocto.sdk.ide.preferences; + +import org.eclipse.jface.dialogs.IInputValidator; +import org.yocto.sdk.ide.YoctoProfileElement; +import org.yocto.sdk.ide.YoctoSDKMessages; + +public class ProfileNameInputValidator implements IInputValidator { + private static final String WARNING_CONTAINS_COMMA = "Preferences.Profile.Validator.InvalidName.Comma"; + private static final String WARNING_CONTAINS_DOUBLEQUOTE = "Preferences.Profile.Validator.InvalidName.Quote"; + private static final String PROFILE_NAME_IS_EMPTY = "Preferences.Profile.Validator.InvalidName.Empty"; + private static final String WARNING_ALREADY_EXISTS = "Preferences.Profile.Validator.InvalidName.Exists"; + + private final String selectedItem; + private final YoctoProfileElement profileSetting; + + public ProfileNameInputValidator(YoctoProfileElement profileSetting) { + this(profileSetting, ""); + } + + public ProfileNameInputValidator(YoctoProfileElement profileSetting, String selectedItem) { + this.selectedItem = selectedItem; + this.profileSetting = profileSetting; + } + + @Override + public String isValid(String newText) { + if (newText.contains(",")) { + return YoctoSDKMessages.getString(WARNING_CONTAINS_COMMA); + } + + if (newText.contains("\"")) { + return YoctoSDKMessages.getString(WARNING_CONTAINS_DOUBLEQUOTE); + } + + if (newText.isEmpty()) { + return YoctoSDKMessages.getString(PROFILE_NAME_IS_EMPTY); + } + + if (selectedItemEquals(newText)) { + return null; + } + + if (profileSetting.contains(newText)) { + return YoctoSDKMessages.getString(WARNING_ALREADY_EXISTS); + } + + return null; + } + + private boolean selectedItemEquals(String newText) { + return !selectedItem.isEmpty() && newText.equals(selectedItem); + } +} -- cgit v1.2.3-54-g00ecf