01: package com.calipso.xmleditor;
02:
03: import javax.swing.*;
04: import java.util.Enumeration;
05:
06: /**
07: *
08: * User: soliveri
09: * Date: 03-oct-2003
10: * Time: 12:25:38
11: *
12: */
13:
14: public class XmlEditorSubPanelValidator {
15:
16: /**
17: * Valida las entradas de un subpanel.
18: * @param subPanel
19: * @param definition
20: * @return
21: */
22: public static String validateFrom(XmlEditorSubPanel subPanel,
23: XmlEditorTreeDefinitionNode definition) {
24: String elementWrong = null;
25: Enumeration enumeration = definition.getItemsKeys().elements();
26: for (int i = 0; i < subPanel.getInputComponents().size(); i++) {
27: XmlEditorTreeNodeItemDefinition item = (XmlEditorTreeNodeItemDefinition) definition
28: .getItems().get(
29: enumeration.nextElement().toString());
30: if (!item.isOptional()) {
31: if (!isValid(subPanel.getInputComponents().elementAt(i))) {
32: elementWrong = item.getName();
33: break;
34: }
35: }
36: }
37: return elementWrong;
38: }
39:
40: public static boolean isValid(Object object) {
41: if (object instanceof JTextField) {
42: if (((JTextField) object).getText().equals("")) {
43: return false;
44: }
45: }
46: return true;
47: }
48: }
|