Loading, Validating, Saving
XMLDialog keeps a handle to the ScriptExecutionContext passed to its constructor.
It also keeps a list of components implementing XMLDataWidget
It uses these when loading, validating, and saving data.
|
public class XMLDialog extends KDialog {
private ScriptExecutionContext context;
private Vector components = new Vector();
public XMLDialog(... ScriptExecutionContext context) {
...
this.context = context;
parseNode(doc.getDocumentElement());
loadData();
...
}
private void addComponent(Component component) {
XMLBox box = (XMLBox)containers.peek();
if (component instanceof XMLDataWidget) {
components.add(component);
}
box.add(component);
}
private void loadData() {
Iterator i = components.iterator();
while (i.hasNext()) {
XMLDataWidget widget = (XMLDataWidget)i.next();
widget.loadData(context);
}
}
private boolean validateData() {
Iterator i = components.iterator();
while (i.hasNext()) {
Object object = i.next();
if (object instanceof XMLDataValidator) {
XMLDataValidator widget = (XMLDataValidator)object;
if (!widget.validateData()) {
return false;
}
}
}
return true;
}
private void saveData() {
Iterator i = components.iterator();
while (i.hasNext()) {
XMLDataWidget widget = (XMLDataWidget)i.next();
widget.saveData(context);
}
}
}
|
|