blob: ca20e3f712e8a736fbfc1cfc77541f1713cef7c3 (
plain)
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
|
package com.ibm.ServerWizard2.view;
import org.eclipse.jface.viewers.ICellEditorValidator;
import com.ibm.ServerWizard2.model.Field;
public class AttributeValidator implements ICellEditorValidator {
Field f;
public AttributeValidator(Field f) {
this.f=f;
}
public String isValid(Object arg0) {
String s = (String)arg0;
String rtn=null;
if (f.type.equals("uint8_t")) {
if (!this.isValidByte(s)) {
rtn="Invalid number format for uint8_t";
}
} else if (f.type.equals("uint32_t") || f.type.equals("uint16_t")) {
if (!this.isValidInt(s)) {
rtn="Invalid number format for uint16_t or uint32_t";
}
}
return rtn;
}
private boolean isValidByte(String s) {
/* try {
Byte.decode(s);
} catch (Exception e) {
return false;
}*/
return true;
}
private boolean isValidInt(String s) {
try {
Integer.decode(s);
} catch (Exception e) {
return false;
}
return true;
}
}
|