[Buix-commits] r961 - in lutinjaxx/trunk/jaxx-core/src/main/java/jaxx: compiler runtime tags/validator
Author: tchemit Date: 2008-10-18 00:56:40 +0000 (Sat, 18 Oct 2008) New Revision: 961 Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java Log: automatic boxing by a JXLayer for any component attached toa validator Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java 2008-10-18 00:53:46 UTC (rev 960) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java 2008-10-18 00:56:40 UTC (rev 961) @@ -133,8 +133,9 @@ public static boolean isValidID(String id) { boolean valid = true; - if (id.length() == 0) + if (id.length() == 0) { valid = false; + } if (valid) { if (!Character.isJavaIdentifierStart(id.charAt(0))) { valid = false; @@ -467,13 +468,21 @@ String delegateCode = containerDelegate != null ? "." + containerDelegate + "()" : ""; child.setParent(this); + String javaCode = child.getJavaCode(); + if (compiler.hasValidator()) { + // some validators are defined on this object + boolean found = compiler.isComponentUsedByValidator(child.getId()); + if (found) { + // box the child component in a JxLayer + javaCode = "jaxx.runtime.Util.boxComponentWithJxLayer(" + javaCode + ")"; + } + } if (constraints != null) { - appendAdditionCode(getJavaCode() + delegateCode + ".add(" + child.getJavaCode() + ", " + constraints + ");"); + appendAdditionCode(getJavaCode() + delegateCode + ".add(" + javaCode + ", " + constraints + ");"); + } else { + appendAdditionCode(getJavaCode() + delegateCode + ".add(" + javaCode + ");"); } - else { - appendAdditionCode(getJavaCode() + delegateCode + ".add(" + child.getJavaCode() + ");"); - } } } @@ -487,8 +496,9 @@ compiler.registerDataBinding(src, getId() + "." + property, assignment); } + /** @return the array of generic types of the compiled object, or a empty array if none defined */ public ClassDescriptor[] getGenericTypes() { - if (genericTypes==null) { + if (genericTypes == null) { return new ClassDescriptor[0]; } try { Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-18 00:53:46 UTC (rev 960) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-18 00:56:40 UTC (rev 961) @@ -181,6 +181,9 @@ /** list of validators */ protected List<CompiledBeanValidator> validators = new ArrayList<CompiledBeanValidator>(); + /** list of objectId attached to a validator * */ + protected List<String> validatedComponents = new ArrayList<String>(); + private SymbolTable symbolTable = new SymbolTable(); // TODO: replace these public StringBuffers with something a little less stupid @@ -2181,15 +2184,32 @@ this.failed = failed; } + /** + * Register in this compiler a new compiled validator. + * + * @param validator the compiled validator to register + */ public void registerValidator(CompiledBeanValidator validator) { validators.add(validator); + validatedComponents.addAll(validator.getFields().values()); } + /** @return <code>true</code> if some validators were detected, <code>false</code> otherwise */ public boolean hasValidator() { return !validators.isEmpty(); } /** + * Test if a given CompiledObject is attached to a validator. + * + * @param componentId the compiled object to test + * @return <code>true</code> if the given compiled object is attached to a validator, <code>false</code> otherwise + */ + public boolean isComponentUsedByValidator(String componentId) { + return validatedComponents.contains(componentId); + } + + /** * Check that a reference exists in symbol table on second compil pass * * @param tag the current tag Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java 2008-10-18 00:53:46 UTC (rev 960) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java 2008-10-18 00:56:40 UTC (rev 961) @@ -2,6 +2,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jdesktop.jxlayer.JXLayer; import javax.swing.JComponent; import java.awt.Component; @@ -282,7 +283,7 @@ * * @param clazz la classe ou recherche les champs * @param container le container ou rechercher les composants d'edition - * @return + * @return le dictionnaire des composants recherches. */ public static Map<String, JComponent> lookingForEditor(Class clazz, Container container) { Map<String, JComponent> result = new HashMap<String, JComponent>(); @@ -331,4 +332,15 @@ return result; } + /** + * Box a component in a {@link org.jdesktop.jxlayer.JXLayer}. + * + * @param component the component to box + * @return the {@link org.jdesktop.jxlayer.JXLayer} boxing the component + */ + public static JXLayer boxComponentWithJxLayer(JComponent component) { + JXLayer layer = new org.jdesktop.jxlayer.JXLayer(); + layer.add(component); + return layer; + } } Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-18 00:53:46 UTC (rev 960) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-18 00:56:40 UTC (rev 961) @@ -176,6 +176,11 @@ // editor component not find on ui continue; } + if (compiler.isComponentUsedByValidator(component)) { + // component is already used by another validator + compiler.reportError("component '"+component+"' is already used by another validator."); + continue; + } String keyCode = TypeManager.getJavaCode(propertyName); info.appendAdditionCode(info.getJavaCode() + ".setFieldRepresentation(" + keyCode + ", " + component + ");");
participants (1)
-
tchemit@users.labs.libre-entreprise.org