Author: tchemit Date: 2010-05-04 11:50:39 +0200 (Tue, 04 May 2010) New Revision: 1871 Url: http://nuiton.org/repositories/revision/jaxx/1871 Log: can use now expression to define a explicit property editor Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java 2010-05-04 09:49:03 UTC (rev 1870) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java 2010-05-04 09:50:39 UTC (rev 1871) @@ -791,10 +791,10 @@ // property not find on bean continue; } - if (!compiler.checkReference(tag, component, true, null)) { - // editor component not find on ui - continue; - } +// if (!compiler.checkReference(tag, component, true, null)) { +// // editor component not find on ui +// continue; +// } String keyCode = TypeManager.getJavaCode(propertyName); appendAdditionCode(getJavaCode() + ".setFieldRepresentation(" + keyCode + ", " + component + ");"); @@ -848,7 +848,8 @@ } } - public void registerField(String id, String component, + public void registerField(String id, + String component, JAXXCompiler compiler) { if (fields.containsKey(id)) { compiler.reportError( Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java 2010-05-04 09:49:03 UTC (rev 1870) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/FieldValidatorHandler.java 2010-05-04 09:50:39 UTC (rev 1871) @@ -27,6 +27,8 @@ import jaxx.compiler.CompilerException; import jaxx.compiler.JAXXCompiler; +import jaxx.compiler.binding.DataBindingHelper; +import jaxx.compiler.reflect.ClassDescriptor; import jaxx.compiler.reflect.ClassDescriptorLoader; import jaxx.compiler.tags.TagHandler; import jaxx.compiler.tags.validator.BeanValidatorHandler.CompiledBeanValidator; @@ -40,12 +42,14 @@ public class FieldValidatorHandler implements TagHandler { public static final String TAG = "field"; + public static final String NAME_ATTRIBUTE = "name"; + public static final String COMPONENT_ATTRIBUTE = "component"; + /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(FieldValidatorHandler.class); - public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { if (compiler.getConfiguration().isVerbose()) { log.debug(tag); @@ -59,41 +63,88 @@ log.debug(tag); } - if (!ClassDescriptorLoader.getClassDescriptor(SwingValidator.class).isAssignableFrom(compiler.getOpenComponent().getObjectClass())) { - compiler.reportError(TAG + " tag may only appear within " + BeanValidatorHandler.TAG + " tag but was " + tag); + ClassDescriptor descriptor = + ClassDescriptorLoader.getClassDescriptor(SwingValidator.class); + if (!descriptor.isAssignableFrom( + compiler.getOpenComponent().getObjectClass())) { + compiler.reportError( + TAG + " tag may only appear within " + + BeanValidatorHandler.TAG + " tag but was " + tag); return; } - CompiledBeanValidator info = (CompiledBeanValidator) compiler.getOpenComponent(); + CompiledBeanValidator info = + (CompiledBeanValidator) compiler.getOpenComponent(); String name = tag.getAttribute(NAME_ATTRIBUTE); String component = tag.getAttribute(COMPONENT_ATTRIBUTE); if (name == null || name.trim().isEmpty()) { - compiler.reportError(TAG + " tag requires a " + NAME_ATTRIBUTE + " attribute"); + compiler.reportError(TAG + " tag requires a " + NAME_ATTRIBUTE + + " attribute"); return; } name = name.trim(); if (component == null || component.trim().isEmpty()) { // try to use the name as component if (!compiler.checkReference(tag, name, false, name)) { - compiler.reportError(TAG + " tag requires a " + COMPONENT_ATTRIBUTE + " attribute, try to use the name attribute [" + name + "] for the component, but no such component found"); + compiler.reportError( + TAG + " tag requires a " + COMPONENT_ATTRIBUTE + + " attribute, try to use the name attribute [" + name + + "] for the component, but no such component found"); return; } component = name; } component = component.trim(); + boolean complexType = false; + if (component.startsWith("{") && component.endsWith("}")) { + + complexType = true; + + // means a complex reference (says a java Code in facts) + component = compiler.preprocessScript(component.substring(1, component.length() - 1)); + } + + if (log.isDebugEnabled()) { + log.debug("Check '" + component + "' reference"); + } + // check component is not already used by this compiled object if (info.getFields().containsValue(component)) { - compiler.reportError(TAG + " tag found a attribute " + COMPONENT_ATTRIBUTE + " [" + component + "] already used in this validator"); + compiler.reportError( + TAG + " tag found a attribute " + COMPONENT_ATTRIBUTE + + " [" + component + "] already used in this validator"); return; } - // check component exist (again perharps, but let the error knows exactly which tag failed...) - if (compiler.checkReference(tag, component, true, COMPONENT_ATTRIBUTE)) { + + if (complexType) { + String binding = DataBindingHelper.processDataBindings(component); + boolean withBinding = binding != null; + + if (log.isDebugEnabled()) { + log.debug("apply data binding on [" + component + "] : " + withBinding); + } + + // this means reference is ok, can safely add field + // add a field info.registerField(name, component, compiler); + return; } + // simple reference, check it directly on compiler + // check component exist (again perharps, but let the error knows + // exactly which tag failed...) + if (compiler.checkReference(tag, + component, + true, + COMPONENT_ATTRIBUTE)) { + // add a field + info.registerField(name, component, compiler); + } + + } }