1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.commonclipse.preferences;
18
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.jdt.core.JavaConventions;
21 import org.eclipse.swt.widgets.Composite;
22
23 /***
24 * ComboFieldEditor with check for valid class.CONSTANT values.
25 * @author fgiust
26 * @version $Revision: 1.3 $ ($Author: fgiust $)
27 */
28 public class ClassConstantFieldEditor extends ComboFieldEditor
29 {
30
31 /***
32 * @see net.sf.commonclipse.preferences.ComboFieldEditor#ComboFieldEditor(String, String, Composite)
33 */
34 public ClassConstantFieldEditor(String name, String labelText, Composite parent)
35 {
36 super(name, labelText, parent);
37 }
38
39 /***
40 * Overrides default validation to check for a valid class.CONSTANT value.
41 * @return <code>true</code> if the field value is valid, and <code>false</code> if invalid
42 */
43 protected boolean doCheckState()
44 {
45 String txt = getTextControl().getText();
46
47 if (txt != null && !"".equals(txt))
48 {
49 int lastDot = txt.lastIndexOf(".");
50
51 if (lastDot == -1)
52 {
53 return false;
54 }
55
56
57 String typeToken = txt.substring(0, lastDot);
58 String fieldToken = txt.substring(lastDot + 1);
59
60
61 IStatus status1 = JavaConventions.validateJavaTypeName(typeToken);
62 IStatus status2 = JavaConventions.validateFieldName(fieldToken);
63
64 if ((status1.getCode() != IStatus.OK) || (status2.getCode() != IStatus.OK))
65 {
66 return false;
67 }
68 }
69
70 return true;
71 }
72
73 }