blob: cee73f6d5ee1ccab0d424f5224ab381ae58b22f7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/*******************************************************************************
* 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 2.0 which accompanies this distribution, and is
* available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.ui.controls.validator;
/**
* Verify listener for text widgets to receive port numbers.
*/
public class PortNumberVerifyListener extends NumberVerifyListener {
// regular expression for hex validation
protected static final String PORT_REGEX_DEC = "([0-9]{0,5})"; //$NON-NLS-1$
protected static final String PORT_REGEX_HEX = "(0((x|X)[0-9a-fA-F]{0,4})?)"; //$NON-NLS-1$
// arguments
public static final int ATTR_DECIMAL = 1;
public static final int ATTR_HEX = 2;
/**
* Constructor
* @param decimal true if decimal value is allowed
* @param hex true if hex value (0x####) is allowed
*/
public PortNumberVerifyListener(int attributes) {
super(attributes, getRegEx(attributes), 0, 65535);
}
/*
* Static method to generate regular expression for constructor super call.
*/
private static String getRegEx(int attributes) {
String regex = null;
if (isAttribute(ATTR_DECIMAL, attributes) || !isAttribute(ATTR_HEX, attributes)) {
regex = PORT_REGEX_DEC;
}
if (isAttribute(ATTR_HEX, attributes) || !isAttribute(ATTR_DECIMAL, attributes)) {
regex = (regex != null) ? (regex + "|" + PORT_REGEX_HEX) : PORT_REGEX_HEX; //$NON-NLS-1$
}
return regex;
}
}
|