diff options
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/NameOrIPVerifyListener.java')
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/NameOrIPVerifyListener.java | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/NameOrIPVerifyListener.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/NameOrIPVerifyListener.java index 6e6ad4f8d..8762b56a4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/NameOrIPVerifyListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/NameOrIPVerifyListener.java @@ -1,73 +1,73 @@ -/*******************************************************************************
- * Copyright (c) 2011 Wind River Systems, Inc. and others. 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.ui.controls.validator;
-
-/**
- * Verify listener for text widgets to receive host names or IP addresses.
- */
-public class NameOrIPVerifyListener extends RegexVerifyListener {
-
- // regular expressions
- // characters that can be set at the beginning
- private static final String NAME_START_REGEX = "[a-zA-Z]"; //$NON-NLS-1$
- // characters that can be set after the starting character
- private static final String NAME_FOLLOW_REGEX = "[a-zA-Z0-9]"; //$NON-NLS-1$
- // allowed separators in fragments
- private static final String NAME_SEPERATOR_REGEX = "(\\-|_)"; //$NON-NLS-1$
- // complete name fragment
- public static final String NAME_FRAGMENT_REGEX =
- "(" + NAME_START_REGEX + NAME_FOLLOW_REGEX + "*" + //$NON-NLS-1$ //$NON-NLS-2$
- "(" + NAME_SEPERATOR_REGEX + NAME_FOLLOW_REGEX + "+)*)"; //$NON-NLS-1$ //$NON-NLS-2$
- // open name fragment during typing
- private static final String OPEN_NAME_FRAGMENT_REGEX =
- "(" + NAME_FRAGMENT_REGEX + NAME_SEPERATOR_REGEX + "?)"; //$NON-NLS-1$ //$NON-NLS-2$
- // multiple
- public static final String OPEN_NAME_REGEX =
- "((" + NAME_FRAGMENT_REGEX + "\\.)*" + OPEN_NAME_FRAGMENT_REGEX + "?)?[ ]*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- public static final String IP_FRAGMENT_REGEX = "([0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])"; //$NON-NLS-1$
- public static final String OPEN_IP_REGEX = "((" + IP_FRAGMENT_REGEX + "?\\.){0,3}" + IP_FRAGMENT_REGEX + "?)?[ ]*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- public static final String OPEN_TIPC_REGEX = "((" + IP_FRAGMENT_REGEX + "?\\.){0,2}" + IP_FRAGMENT_REGEX + "?)?[ ]*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- // arguments
- public static final int ATTR_NAME = 1;
- public static final int ATTR_IP = 2;
- public static final int ATTR_TIPC = 4;
-
- /**
- * Constructor
- * @param decimal true if decimal value is allowed
- * @param hex true if hex value (0x####) is allowed
- */
- public NameOrIPVerifyListener(int attributes) {
- super(attributes, getRegEx(attributes));
- }
-
- /*
- * Static method to generate regular expression for constructor super call.
- */
- private static String getRegEx(int attributes) {
- String regex = null;
-
- if (isAttribute(ATTR_TIPC, attributes)) {
- regex = OPEN_TIPC_REGEX;
- }
- else {
- if (isAttribute(ATTR_NAME, attributes) || !isAttribute(ATTR_IP, attributes)) {
- regex = OPEN_NAME_REGEX;
- }
- if (isAttribute(ATTR_IP, attributes) || !isAttribute(ATTR_NAME, attributes)) {
- regex = (regex != null) ? (regex + "|" + OPEN_IP_REGEX) : OPEN_IP_REGEX; //$NON-NLS-1$
- }
- }
-
- return regex;
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2013 Wind River Systems, Inc. and others. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.controls.validator; + +/** + * Verify listener for text widgets to receive host names or IP addresses. + */ +public class NameOrIPVerifyListener extends RegexVerifyListener { + + // regular expressions + // characters that can be set at the beginning + private static final String NAME_START_REGEX = "[a-zA-Z]"; //$NON-NLS-1$ + // characters that can be set after the starting character + private static final String NAME_FOLLOW_REGEX = "[a-zA-Z0-9]"; //$NON-NLS-1$ + // allowed separators in fragments + private static final String NAME_SEPERATOR_REGEX = "(\\-|_)"; //$NON-NLS-1$ + // complete name fragment + public static final String NAME_FRAGMENT_REGEX = + "(" + NAME_START_REGEX + NAME_FOLLOW_REGEX + "*" + //$NON-NLS-1$ //$NON-NLS-2$ + "(" + NAME_SEPERATOR_REGEX + NAME_FOLLOW_REGEX + "+)*)"; //$NON-NLS-1$ //$NON-NLS-2$ + // open name fragment during typing + private static final String OPEN_NAME_FRAGMENT_REGEX = + "(" + NAME_FRAGMENT_REGEX + NAME_SEPERATOR_REGEX + "?)"; //$NON-NLS-1$ //$NON-NLS-2$ + // multiple + public static final String OPEN_NAME_REGEX = + "((" + NAME_FRAGMENT_REGEX + "\\.)*" + OPEN_NAME_FRAGMENT_REGEX + "?)?[ ]*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + public static final String IP_FRAGMENT_REGEX = "([0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])"; //$NON-NLS-1$ + public static final String OPEN_IP_REGEX = "((" + IP_FRAGMENT_REGEX + "?\\.){0,3}" + IP_FRAGMENT_REGEX + "?)?[ ]*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + public static final String OPEN_TIPC_REGEX = "((" + IP_FRAGMENT_REGEX + "?\\.){0,2}" + IP_FRAGMENT_REGEX + "?)?[ ]*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + // arguments + public static final int ATTR_NAME = 1; + public static final int ATTR_IP = 2; + public static final int ATTR_TIPC = 4; + + /** + * Constructor + * @param decimal true if decimal value is allowed + * @param hex true if hex value (0x####) is allowed + */ + public NameOrIPVerifyListener(int attributes) { + super(attributes, getRegEx(attributes)); + } + + /* + * Static method to generate regular expression for constructor super call. + */ + private static String getRegEx(int attributes) { + String regex = null; + + if (isAttribute(ATTR_TIPC, attributes)) { + regex = OPEN_TIPC_REGEX; + } + else { + if (isAttribute(ATTR_NAME, attributes) || !isAttribute(ATTR_IP, attributes)) { + regex = OPEN_NAME_REGEX; + } + if (isAttribute(ATTR_IP, attributes) || !isAttribute(ATTR_NAME, attributes)) { + regex = (regex != null) ? (regex + "|" + OPEN_IP_REGEX) : OPEN_IP_REGEX; //$NON-NLS-1$ + } + } + + return regex; + } +} |