01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12:
13: package com.eviware.x.form;
14:
15: import java.util.ArrayList;
16:
17: public class ComponentEnabler implements XFormFieldListener {
18: private final XFormField formField;
19:
20: // Cannot use HashMap, because the XFormField may be a Proxy.
21: private ArrayList<FieldValue> fields = new ArrayList<FieldValue>();
22:
23: private static class FieldValue {
24: XFormField field;
25: String value;
26:
27: public FieldValue(XFormField field, String value) {
28: this .field = field;
29: this .value = value;
30: }
31: }
32:
33: public ComponentEnabler(XFormField formField) {
34: this .formField = formField;
35:
36: formField.addFormFieldListener(this );
37: }
38:
39: /**
40: * This should not be called directly from the dialog builders,
41: * because <code>field</code> may be a Proxy (on the Eclipse platform).
42: * Instead, call <code>addComponentEnablesFor(field, value)</code> on the combo box.
43: * @param field
44: * @param value
45: */
46: void add(XFormField field, String value) {
47: String fieldValue = formField.getValue();
48: boolean enable = (fieldValue == null ? value == null
49: : fieldValue.equals(value));
50: field.setEnabled(enable);
51: fields.add(new FieldValue(field, value));
52: }
53:
54: public void valueChanged(XFormField sourceField, String newValue,
55: String oldValue) {
56: for (FieldValue f : fields) {
57: boolean enable = newValue.equals(f.value);
58: f.field.setEnabled(enable);
59: }
60: }
61: }
|