[Buix-commits] r1196 - in jaxx/trunk: . jaxx-compiler-validator jaxx-compiler-validator/src/main/java/jaxx/tags/validator jaxx-example jaxx-runtime-validator jaxx-runtime-validator/src/main/java/jaxx/runtime/validator jaxx-runtime-validator-swing jaxx-runtime-validator-swing/src jaxx-runtime-validator-swing/src/main jaxx-runtime-validator-swing/src/main/java jaxx-runtime-validator-swing/src/main/java/jaxx jaxx-runtime-validator-swing/src/main/java/jaxx/runtime jaxx-runtime-validator-swing/src/main/java/jaxx
Author: tchemit Date: 2009-02-03 15:49:43 +0000 (Tue, 03 Feb 2009) New Revision: 1196 Added: jaxx/trunk/jaxx-runtime-validator-swing/ jaxx/trunk/jaxx-runtime-validator-swing/LICENSE.txt jaxx/trunk/jaxx-runtime-validator-swing/README.txt jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt jaxx/trunk/jaxx-runtime-validator-swing/pom.xml jaxx/trunk/jaxx-runtime-validator-swing/src/ jaxx/trunk/jaxx-runtime-validator-swing/src/main/ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/SwingValidationUtil.java jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/ui/ jaxx/trunk/jaxx-runtime-validator-swing/src/main/resources/ jaxx/trunk/jaxx-runtime-validator-swing/src/site/ jaxx/trunk/jaxx-runtime-validator-swing/src/site/fr/ jaxx/trunk/jaxx-runtime-validator-swing/src/site/fr/rst/ jaxx/trunk/jaxx-runtime-validator-swing/src/test/ jaxx/trunk/jaxx-runtime-validator-swing/src/test/java/ jaxx/trunk/jaxx-runtime-validator-swing/src/test/resources/ Removed: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/swing/ Modified: jaxx/trunk/jaxx-compiler-validator/pom.xml jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java jaxx/trunk/jaxx-example/pom.xml jaxx/trunk/jaxx-runtime-validator/changelog.txt jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidationUtil.java jaxx/trunk/pom.xml Log: creation du module jaxx-runtimevalidator-swing pour le code specific swing du validator Modified: jaxx/trunk/jaxx-compiler-validator/pom.xml =================================================================== --- jaxx/trunk/jaxx-compiler-validator/pom.xml 2009-02-03 09:37:45 UTC (rev 1195) +++ jaxx/trunk/jaxx-compiler-validator/pom.xml 2009-02-03 15:49:43 UTC (rev 1196) @@ -29,6 +29,12 @@ <dependency> <groupId>${project.groupId}</groupId> + <artifactId>jaxx-runtime-validator-swing</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>jaxx-compiler-api</artifactId> <version>${project.version}</version> </dependency> Modified: jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java =================================================================== --- jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2009-02-03 09:37:45 UTC (rev 1195) +++ jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2009-02-03 15:49:43 UTC (rev 1196) @@ -11,7 +11,7 @@ import jaxx.introspection.JAXXPropertyDescriptor; import jaxx.reflect.ClassDescriptor; import jaxx.reflect.ClassDescriptorLoader; -import jaxx.runtime.validator.ValidationUtil; +import jaxx.runtime.validator.SwingValidationUtil; import jaxx.runtime.validator.swing.SwingValidator; import jaxx.runtime.validator.swing.ui.AbstractBeanValidatorUI; import jaxx.tags.DefaultObjectHandler; @@ -482,7 +482,7 @@ } } - String code = ValidationUtil.class.getName() + ".registerErrorListMouseListener(" + errorList + ");"; + String code = SwingValidationUtil.class.getName() + ".registerErrorListMouseListener(" + errorList + ");"; appendAdditionCode(code); return false; @@ -502,7 +502,7 @@ } } - String code = ValidationUtil.class.getName() + ".registerErrorTableMouseListener(" + errorTable + ");"; + String code = SwingValidationUtil.class.getName() + ".registerErrorTableMouseListener(" + errorTable + ");"; appendAdditionCode(code); return false; Modified: jaxx/trunk/jaxx-example/pom.xml =================================================================== --- jaxx/trunk/jaxx-example/pom.xml 2009-02-03 09:37:45 UTC (rev 1195) +++ jaxx/trunk/jaxx-example/pom.xml 2009-02-03 15:49:43 UTC (rev 1196) @@ -27,7 +27,7 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>jaxx-runtime-validator</artifactId> + <artifactId>jaxx-runtime-validator-swing</artifactId> <version>${project.version}</version> </dependency> Modified: jaxx/trunk/jaxx-runtime-validator/changelog.txt =================================================================== --- jaxx/trunk/jaxx-runtime-validator/changelog.txt 2009-02-03 09:37:45 UTC (rev 1195) +++ jaxx/trunk/jaxx-runtime-validator/changelog.txt 2009-02-03 15:49:43 UTC (rev 1196) @@ -1,4 +1,5 @@ 1.1 chemit 200901?? + * 20090203 [chemit] - move swing specific code to jaxx-runtime-validator-swing module * 20090202 [chemit] - rename Util to ValidationUtil - refactor validator mecanism to extract validation from swing * 20090122 [chemit] - refactor poms (sibling dependencies, pluginsManagment,...) Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidationUtil.java =================================================================== --- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidationUtil.java 2009-02-03 09:37:45 UTC (rev 1195) +++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidationUtil.java 2009-02-03 15:49:43 UTC (rev 1196) @@ -2,14 +2,9 @@ import jaxx.runtime.JAXXObject; import jaxx.runtime.JAXXValidator; -import jaxx.runtime.validator.swing.SwingValidatorErrorListMouseListener; -import jaxx.runtime.validator.swing.SwingValidatorErrorTableMouseListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.swing.JList; -import javax.swing.JTable; -import java.awt.event.MouseListener; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; @@ -32,45 +27,6 @@ // no instance } - public static void registerErrorListMouseListener(JList list) { - if (list == null) { - return; - } - for (MouseListener listener : list.getMouseListeners()) { - if (listener instanceof SwingValidatorErrorListMouseListener) { - // already have a such listener - log.info("already registered a such MouseListener : " + listener); - return; - } - } - list.addMouseListener(new SwingValidatorErrorListMouseListener()); - } - - public static void registerErrorTableMouseListener(JTable table) { - if (table == null) { - return; - } - for (MouseListener listener : table.getMouseListeners()) { - if (listener instanceof SwingValidatorErrorTableMouseListener) { - // already have a such listener - log.info("already registered a such MouseListener : " + listener); - return; - } - } - table.addMouseListener(new SwingValidatorErrorTableMouseListener()); - } - - public static SwingValidatorErrorTableMouseListener getErrorTableMouseListener(JTable table) { - if (table != null) { - for (MouseListener listener : table.getMouseListeners()) { - if (listener instanceof SwingValidatorErrorTableMouseListener) { - return (SwingValidatorErrorTableMouseListener) listener; - } - } - } - return null; - } - /** * Convinient method to attach a bean to all validators of an JAXXObject. * <p/> Added: jaxx/trunk/jaxx-runtime-validator-swing/LICENSE.txt =================================================================== --- jaxx/trunk/jaxx-runtime-validator-swing/LICENSE.txt (rev 0) +++ jaxx/trunk/jaxx-runtime-validator-swing/LICENSE.txt 2009-02-03 15:49:43 UTC (rev 1196) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Added: jaxx/trunk/jaxx-runtime-validator-swing/README.txt =================================================================== --- jaxx/trunk/jaxx-runtime-validator-swing/README.txt (rev 0) +++ jaxx/trunk/jaxx-runtime-validator-swing/README.txt 2009-02-03 15:49:43 UTC (rev 1196) @@ -0,0 +1,2 @@ +To deploy new version of pom: mvn deploy +To install localy: mvn install Added: jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt =================================================================== --- jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt (rev 0) +++ jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt 2009-02-03 15:49:43 UTC (rev 1196) @@ -0,0 +1,2 @@ +1.1 chemit 200901?? + * 20090203 [chemit] - introduce this module specific to swing \ No newline at end of file Added: jaxx/trunk/jaxx-runtime-validator-swing/pom.xml =================================================================== --- jaxx/trunk/jaxx-runtime-validator-swing/pom.xml (rev 0) +++ jaxx/trunk/jaxx-runtime-validator-swing/pom.xml 2009-02-03 15:49:43 UTC (rev 1196) @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + + <parent> + <groupId>org.codelutin</groupId> + <artifactId>jaxx</artifactId> + <version>1.1-SNAPSHOT</version> + </parent> + + <groupId>org.codelutin.jaxx</groupId> + <artifactId>jaxx-runtime-validator-swing</artifactId> + + <dependencies> + + <!-- sibling dependencies --> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>jaxx-runtime-validator</artifactId> + <version>${project.version}</version> + </dependency> + + </dependencies> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + + <name>${project.artifactId}</name> + <description>Jaxx validation swing extension</description> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + <packaging>jar</packaging> + + <!-- ************************************************************* --> + <!-- *** Build Environment ************************************** --> + <!-- ************************************************************* --> + <scm> + <url>${maven.scm.url.child}</url> + <connection>${maven.scm.connection.child}</connection> + <developerConnection>${maven.scm.developerConnection.child}</developerConnection> + </scm> +</project> Added: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/SwingValidationUtil.java =================================================================== --- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/SwingValidationUtil.java (rev 0) +++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/SwingValidationUtil.java 2009-02-03 15:49:43 UTC (rev 1196) @@ -0,0 +1,64 @@ +package jaxx.runtime.validator; + +import jaxx.runtime.validator.swing.SwingValidatorErrorListMouseListener; +import jaxx.runtime.validator.swing.SwingValidatorErrorTableMouseListener; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JList; +import javax.swing.JTable; +import java.awt.event.MouseListener; + +/** + * The helper class for validation module. + * + * @author chemit + */ +public class SwingValidationUtil extends ValidationUtil { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private final Log log = LogFactory.getLog(SwingValidationUtil.class); + + protected SwingValidationUtil() { + // no instance + } + + public static void registerErrorListMouseListener(JList list) { + if (list == null) { + return; + } + for (MouseListener listener : list.getMouseListeners()) { + if (listener instanceof SwingValidatorErrorListMouseListener) { + // already have a such listener + log.info("already registered a such MouseListener : " + listener); + return; + } + } + list.addMouseListener(new SwingValidatorErrorListMouseListener()); + } + + public static void registerErrorTableMouseListener(JTable table) { + if (table == null) { + return; + } + for (MouseListener listener : table.getMouseListeners()) { + if (listener instanceof SwingValidatorErrorTableMouseListener) { + // already have a such listener + log.info("already registered a such MouseListener : " + listener); + return; + } + } + table.addMouseListener(new SwingValidatorErrorTableMouseListener()); + } + + public static SwingValidatorErrorTableMouseListener getErrorTableMouseListener(JTable table) { + if (table != null) { + for (MouseListener listener : table.getMouseListeners()) { + if (listener instanceof SwingValidatorErrorTableMouseListener) { + return (SwingValidatorErrorTableMouseListener) listener; + } + } + } + return null; + } +} \ No newline at end of file Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing (from rev 1194, jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/swing) Deleted: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java =================================================================== --- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java 2009-02-03 01:38:07 UTC (rev 1194) +++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java 2009-02-03 15:49:43 UTC (rev 1196) @@ -1,175 +0,0 @@ -package jaxx.runtime.validator.swing; - -import jaxx.runtime.validator.SimpleBeanValidator; -import jaxx.runtime.validator.ValidatorField; -import jaxx.runtime.validator.ui.AbstractBeanValidatorUI; -import jaxx.runtime.validator.ui.IconValidationUI; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.jxlayer.JXLayer; - -import javax.swing.JComponent; -import javax.swing.SwingUtilities; -import java.awt.Container; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -/** - * La surcharge de {@link jaxx.runtime.validator.SimpleBeanValidator} pour les ui swing - * - * @author chemit - */ -public class SwingValidator<B> extends SimpleBeanValidator<B> { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private final Log log = LogFactory.getLog(SwingValidator.class); - - static private final Class<? extends AbstractBeanValidatorUI> DEFAULT_UI_CLASS = IconValidationUI.class; - - /** permet de faire le lien en un champs du bean et l'objet qui permet de l'editer */ - protected Map<String, JComponent> fieldRepresentation; - - /** Object servant a contenir la liste des erreurs */ - protected SwingValidatorErrorListModel errorListModel; - - /** Object servant a contenir la liste des erreurs */ - protected SwingValidatorErrorTableModel errorTableModel; - - /** ui renderer class */ - protected Class<? extends AbstractBeanValidatorUI> uiClass; - - - public SwingValidator(Class<B> beanClass, String contextName) { - super(beanClass, contextName); - fieldRepresentation = new HashMap<String, JComponent>(); - } - - public JComponent getFieldRepresentation(String fieldname) { - return fieldRepresentation.get(fieldname); - } - - public Class<? extends AbstractBeanValidatorUI> getUiClass() { - return uiClass; - } - - public void setErrorListModel(SwingValidatorErrorListModel errorListModel) { - this.errorListModel = errorListModel; - if (errorListModel != null) { - // register the validator in the model list - errorListModel.registerValidator(this); - } - } - - public void setErrorTableModel(SwingValidatorErrorTableModel errorTableModel) { - this.errorTableModel = errorTableModel; - if (errorTableModel != null) { - // register the validator in the model table - errorTableModel.registerValidator(this); - } - } - - public void setUiClass(Class<? extends AbstractBeanValidatorUI> uiClass) { - this.uiClass = uiClass; - } - - @Override - public void setContextName(String contextName) { - super.setContextName(contextName); - // must reinstall ui - installUIs(); - } - - /** - * Permet d'indiquer le composant graphique responsable de l'affichage - * d'un attribut du bean - * - * @param fieldname the field name in the bean - * @param c the editor component for the field - */ - public void setFieldRepresentation(String fieldname, JComponent c) { - ValidatorField<B> field = getField(fieldname); - if (field == null) { - // no field registred in the validator - log.warn("the field '" + fieldname + "' is not defined in validator (no rules on it)"); - return; - } - fieldRepresentation.put(fieldname, c); - } - - public void setFieldRepresentation(Map<String, JComponent> fieldRepresentation) { - for (Map.Entry<String, JComponent> e : fieldRepresentation.entrySet()) { - setFieldRepresentation(e.getKey(), e.getValue()); - } - } - - @Override - public SwingValidator<?> getParentValidator() { - return (SwingValidator<?>) super.getParentValidator(); - } - - public void setParentValidator(SwingValidator<?> parentValidator) { - super.setParentValidator(parentValidator); - } - - /** install ui on required components */ - public void installUIs() { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - if (uiClass == null) { - // use the default one - uiClass = DEFAULT_UI_CLASS; - } - for (Entry<String, JComponent> entry : fieldRepresentation.entrySet()) { - try { - setErrorRepresentation(entry.getKey(), null, entry.getValue(), uiClass); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - }); - } - - protected void setErrorRepresentation(String fieldname, JComponent old, JComponent c, Class<? extends AbstractBeanValidatorUI> uiClass) - throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { - if (old == c) { - // same component, nothing to do - return; - } - ValidatorField<B> field = getField(fieldname); - - if (field == null) { - // this case should not appear since fieldName has already been check in method addFieldRepresentation - return; - } - if (old != null) { - // suppression du jxlayer sous l'ancien composant - Container container = old.getParent(); - if (container instanceof JXLayer) { - JXLayer<?> jx = (JXLayer<?>) container; - Object ui = jx.getUI(); - if (ui != null && ui instanceof AbstractBeanValidatorUI) { - field.removeValidatorErrorListener((AbstractBeanValidatorUI) ui); - } - jx.setUI(null); - } - } - if (c != null) { - // ajout du jxlayer sous ce composant - Container container = c.getParent(); - if (container instanceof JXLayer) { - Constructor<? extends AbstractBeanValidatorUI> cons = uiClass.getConstructor(ValidatorField.class); - AbstractBeanValidatorUI ui = cons.newInstance(field); - ui.setEnabled(true); - JXLayer<JComponent> jx = (JXLayer<JComponent>) container; - field.addValidatorErrorListener(ui); - jx.setUI(ui); - } - } - } - - -} Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java (from rev 1195, jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java) =================================================================== --- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java (rev 0) +++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java 2009-02-03 15:49:43 UTC (rev 1196) @@ -0,0 +1,249 @@ +package jaxx.runtime.validator.swing; + +import jaxx.runtime.validator.BeanValidator; +import jaxx.runtime.validator.ValidatorField; +import jaxx.runtime.validator.swing.ui.AbstractBeanValidatorUI; +import jaxx.runtime.validator.swing.ui.IconValidationUI; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.jxlayer.JXLayer; + +import javax.swing.JComponent; +import javax.swing.SwingUtilities; +import java.awt.Container; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +/** + * La surcharge de {@link jaxx.runtime.validator.BeanValidator} pour les ui swing + * <p/> + * /** + * <p/> + * Permet d'ajouter facilement le support de la validation des champs d'un + * bean et de le relier a une interface graphique. + * Utilise xwork pour la validation et JXLayer pour la visualisation. + * <p/> + * <p/> + * Le mieux pour son integration dans Jaxx est de faire de la generation pour + * force la compilation du code suivant: + * <p/> + * <pre> + * myValidor.getBean().get<field>(); + * </pre> + * <p/> + * et ceci pour chaque field ajoute a la map fieldRepresentation. De cette + * facon meme si le champs field est en texte on a une verification de son + * existance a la compilation. + * <p/> + * <p/> + * La representation en tag pourrait etre + * <pre> + * <validator id="myValidator" beanClass="{Personne.class}" errorList="$list"> + * <field name="name" component="$name"/> + * <field name="firstName" component="$firstName"/> + * <field name="birthDate" component="$birthDate"/> + * </validator> + * <validator beanClass="{Personne.class}" autoField="true" errorList="$list"> + * <fieldRepresentation name="name" component="$lastName"/> + * </validator> + * </pre> + * <p/> + * dans le premier exemple on fait un mapping explicite des champs, mais on voit + * que le nom du composant graphique est le meme que celui du champs. Pour eviter + * de longue saisie, il est possible d'utiliser le flag <b>autoField</b> + * qui pour chaque champs du ayant une methode get du bean recherche un composant + * avec cet Id. Il est aussi possible de surcharge un champs explicitement + * comme ici name, dans le cas ou le composant qui porterait ce nom serait + * utilise pour autre chose. + * <p/> + * <p/> + * Il faut un handler particulier pour ce composant car les attributs + * <b>beanClass</b> et <b>autoField</b> ne sont present que dans le XML jaxx et + * servent a la generation. Il faut aussi prendre en compte les elements + * fieldRepresentation fils du tag validator. + * <p/> + * <p/> + * Voici ce que pourrait etre le code genere par jaxx + * <pre> + * // declaration du bean + * BeanValidator<beanClass> $myValidator; + * // init du bean + * protected void createMyValidator() { + * $myValidator = new BeanValidator<beanClass>(); + * // genere seulement si autoField = true + * for (Method m : beanClass.getMethod()) { + * if (m.getName().startsWith("get")) { + * String fieldName = m.getName().substring(3).toLowerCase(); + * $myValidator.setFieldRepresentation(fieldName, $objectMap.get(fieldName)); + * } + * } + * // pour chaque tag fieldRepresentation + * myValidator.setFieldRepresentation("name", $lastName); + * // si beanClass est specifie et n'est pas Object, on force l'acces au champs + * // pour validation a la compilation + * $myValidator.getBean().getName(); + * $objectMap.put("myValidator", $myValidator); + * } + * </pre> + * + * @author poussin + * @author chemit + * @version 1.0 + * <p/> + * Last update: $Date: 3 févr. 2009 $ + * By : $Author: chatellier $ + */ +public class SwingValidator<B> extends BeanValidator<B> { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private final Log log = LogFactory.getLog(SwingValidator.class); + + static private final Class<? extends AbstractBeanValidatorUI> DEFAULT_UI_CLASS = IconValidationUI.class; + + /** permet de faire le lien en un champs du bean et l'objet qui permet de l'editer */ + protected Map<String, JComponent> fieldRepresentation; + + /** Object servant a contenir la liste des erreurs */ + protected SwingValidatorErrorListModel errorListModel; + + /** Object servant a contenir la liste des erreurs */ + protected SwingValidatorErrorTableModel errorTableModel; + + /** ui renderer class */ + protected Class<? extends AbstractBeanValidatorUI> uiClass; + + + public SwingValidator(Class<B> beanClass, String contextName) { + super(beanClass, contextName); + fieldRepresentation = new HashMap<String, JComponent>(); + } + + public JComponent getFieldRepresentation(String fieldname) { + return fieldRepresentation.get(fieldname); + } + + public Class<? extends AbstractBeanValidatorUI> getUiClass() { + return uiClass; + } + + public void setErrorListModel(SwingValidatorErrorListModel errorListModel) { + this.errorListModel = errorListModel; + if (errorListModel != null) { + // register the validator in the model list + errorListModel.registerValidator(this); + } + } + + public void setErrorTableModel(SwingValidatorErrorTableModel errorTableModel) { + this.errorTableModel = errorTableModel; + if (errorTableModel != null) { + // register the validator in the model table + errorTableModel.registerValidator(this); + } + } + + public void setUiClass(Class<? extends AbstractBeanValidatorUI> uiClass) { + this.uiClass = uiClass; + } + + @Override + public void setContextName(String contextName) { + super.setContextName(contextName); + // must reinstall ui + installUIs(); + } + + /** + * Permet d'indiquer le composant graphique responsable de l'affichage + * d'un attribut du bean + * + * @param fieldname the field name in the bean + * @param c the editor component for the field + */ + public void setFieldRepresentation(String fieldname, JComponent c) { + ValidatorField<B> field = getField(fieldname); + if (field == null) { + // no field registred in the validator + log.warn("the field '" + fieldname + "' is not defined in validator (no rules on it)"); + return; + } + fieldRepresentation.put(fieldname, c); + } + + public void setFieldRepresentation(Map<String, JComponent> fieldRepresentation) { + for (Map.Entry<String, JComponent> e : fieldRepresentation.entrySet()) { + setFieldRepresentation(e.getKey(), e.getValue()); + } + } + + @Override + public SwingValidator<?> getParentValidator() { + return (SwingValidator<?>) super.getParentValidator(); + } + + public void setParentValidator(SwingValidator<?> parentValidator) { + super.setParentValidator(parentValidator); + } + + /** install ui on required components */ + public void installUIs() { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + if (uiClass == null) { + // use the default one + uiClass = DEFAULT_UI_CLASS; + } + for (Entry<String, JComponent> entry : fieldRepresentation.entrySet()) { + try { + setErrorRepresentation(entry.getKey(), null, entry.getValue(), uiClass); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + }); + } + + protected void setErrorRepresentation(String fieldname, JComponent old, JComponent c, Class<? extends AbstractBeanValidatorUI> uiClass) + throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { + if (old == c) { + // same component, nothing to do + return; + } + ValidatorField<B> field = getField(fieldname); + + if (field == null) { + // this case should not appear since fieldName has already been check in method addFieldRepresentation + return; + } + if (old != null) { + // suppression du jxlayer sous l'ancien composant + Container container = old.getParent(); + if (container instanceof JXLayer) { + JXLayer<?> jx = (JXLayer<?>) container; + Object ui = jx.getUI(); + if (ui != null && ui instanceof AbstractBeanValidatorUI) { + field.removeValidatorErrorListener((AbstractBeanValidatorUI) ui); + } + jx.setUI(null); + } + } + if (c != null) { + // ajout du jxlayer sous ce composant + Container container = c.getParent(); + if (container instanceof JXLayer) { + Constructor<? extends AbstractBeanValidatorUI> cons = uiClass.getConstructor(ValidatorField.class); + AbstractBeanValidatorUI ui = cons.newInstance(field); + ui.setEnabled(true); + JXLayer<JComponent> jx = (JXLayer<JComponent>) container; + field.addValidatorErrorListener(ui); + jx.setUI(ui); + } + } + } + + +} Deleted: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java =================================================================== --- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java 2009-02-03 01:38:07 UTC (rev 1194) +++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java 2009-02-03 15:49:43 UTC (rev 1196) @@ -1,117 +0,0 @@ -package jaxx.runtime.validator.swing; - -import jaxx.runtime.validator.SimpleBeanValidator; -import jaxx.runtime.validator.ValidatorErrorEvent; -import jaxx.runtime.validator.ValidatorErrorListener; -import jaxx.runtime.validator.ValidatorField; - -import javax.swing.DefaultListModel; -import javax.swing.JComponent; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.Set; - -/** - * The model of the list of errors - * - * @author chemit - */ -public class SwingValidatorErrorListModel extends DefaultListModel implements ValidatorErrorListener { - - private static final long serialVersionUID = 1L; - - /** list of registred validators */ - protected transient List<SimpleBeanValidator<?>> validators; - - - public SwingValidatorErrorListModel() { - validators = new ArrayList<SimpleBeanValidator<?>>(); - } - - public void registerValidator(SimpleBeanValidator<?> validator) { - if (validators.contains(validator)) { - throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this); - } - validators.add(validator); - // the model listen on each field of the validator - for (ValidatorField<?> field : validator.getFields()) { - field.addValidatorErrorListener(this); - } - } - - - /** - * Invoked when a validator detects a error on a field. - * - * @param event the event - */ - @Override - public void onNewError(ValidatorErrorEvent event) { - ValidatorField field = event.getField(); - SwingValidator validator = (SwingValidator) event.getSource(); - Set<String> errors = event.getErrors(); - - // must remove all previously error for this field and validator - List<SwingValidatorErrorModel> newErrors = new ArrayList<SwingValidatorErrorModel>(); - JComponent editor = validator.getFieldRepresentation(field.getName()); - Enumeration enumeration = elements(); - while (enumeration.hasMoreElements()) { - SwingValidatorErrorModel error = (SwingValidatorErrorModel) enumeration.nextElement(); - if (error.getValidator() == validator && error.getField() == field) { - // this error can be skipped - continue; - } - newErrors.add(error); - } - // add new errors - for (String error : errors) { - newErrors.add(new SwingValidatorErrorModel(validator, field, error, editor)); - } - java.util.Collections.sort(newErrors); - - // clean model and reinject new errors - removeAllElements(); - - // reinject in list model, all the errors - for (SwingValidatorErrorModel error : newErrors) { - addElement(error); - } - //FIXME, this is not performant, prefer use a isValueAdjusting property on SwingValidator - // notify that the model has changed - } - - /** - * Invoked when a validator detetcs that a previously error is - * no more exisitng. - * - * @param event the event - */ - @Override - public void onResolvedError(ValidatorErrorEvent event) { - SwingValidator validator = (SwingValidator) event.getSource(); - ValidatorField field = event.getField(); - // must remove all previously error for this field - - boolean somethingChange = false; - Enumeration enumeration = elements(); - List<SwingValidatorErrorModel> newList = new ArrayList<SwingValidatorErrorModel>(); - while (enumeration.hasMoreElements()) { - SwingValidatorErrorModel error = (SwingValidatorErrorModel) enumeration.nextElement(); - if (error.getValidator() == validator && error.getField() == field) { - // this error can be skipped - somethingChange = true; - } else { - newList.add(error); - } - } - // clean model and reinject new errors - removeAllElements(); - - if (somethingChange) { - for (SwingValidatorErrorModel errorModel : newList) { - addElement(errorModel); - } - } - } -} \ No newline at end of file Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java (from rev 1195, jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java) =================================================================== --- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java (rev 0) +++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java 2009-02-03 15:49:43 UTC (rev 1196) @@ -0,0 +1,117 @@ +package jaxx.runtime.validator.swing; + +import jaxx.runtime.validator.BeanValidator; +import jaxx.runtime.validator.ValidatorErrorEvent; +import jaxx.runtime.validator.ValidatorErrorListener; +import jaxx.runtime.validator.ValidatorField; + +import javax.swing.DefaultListModel; +import javax.swing.JComponent; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Set; + +/** + * The model of the list of errors + * + * @author chemit + */ +public class SwingValidatorErrorListModel extends DefaultListModel implements ValidatorErrorListener { + + private static final long serialVersionUID = 1L; + + /** list of registred validators */ + protected transient List<BeanValidator<?>> validators; + + + public SwingValidatorErrorListModel() { + validators = new ArrayList<BeanValidator<?>>(); + } + + public void registerValidator(BeanValidator<?> validator) { + if (validators.contains(validator)) { + throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this); + } + validators.add(validator); + // the model listen on each field of the validator + for (ValidatorField<?> field : validator.getFields()) { + field.addValidatorErrorListener(this); + } + } + + + /** + * Invoked when a validator detects a error on a field. + * + * @param event the event + */ + @Override + public void onNewError(ValidatorErrorEvent event) { + ValidatorField field = event.getField(); + SwingValidator validator = (SwingValidator) event.getSource(); + Set<String> errors = event.getErrors(); + + // must remove all previously error for this field and validator + List<SwingValidatorErrorModel> newErrors = new ArrayList<SwingValidatorErrorModel>(); + JComponent editor = validator.getFieldRepresentation(field.getName()); + Enumeration enumeration = elements(); + while (enumeration.hasMoreElements()) { + SwingValidatorErrorModel error = (SwingValidatorErrorModel) enumeration.nextElement(); + if (error.getValidator() == validator && error.getField() == field) { + // this error can be skipped + continue; + } + newErrors.add(error); + } + // add new errors + for (String error : errors) { + newErrors.add(new SwingValidatorErrorModel(validator, field, error, editor)); + } + java.util.Collections.sort(newErrors); + + // clean model and reinject new errors + removeAllElements(); + + // reinject in list model, all the errors + for (SwingValidatorErrorModel error : newErrors) { + addElement(error); + } + //FIXME, this is not performant, prefer use a isValueAdjusting property on SwingValidator + // notify that the model has changed + } + + /** + * Invoked when a validator detetcs that a previously error is + * no more exisitng. + * + * @param event the event + */ + @Override + public void onResolvedError(ValidatorErrorEvent event) { + SwingValidator validator = (SwingValidator) event.getSource(); + ValidatorField field = event.getField(); + // must remove all previously error for this field + + boolean somethingChange = false; + Enumeration enumeration = elements(); + List<SwingValidatorErrorModel> newList = new ArrayList<SwingValidatorErrorModel>(); + while (enumeration.hasMoreElements()) { + SwingValidatorErrorModel error = (SwingValidatorErrorModel) enumeration.nextElement(); + if (error.getValidator() == validator && error.getField() == field) { + // this error can be skipped + somethingChange = true; + } else { + newList.add(error); + } + } + // clean model and reinject new errors + removeAllElements(); + + if (somethingChange) { + for (SwingValidatorErrorModel errorModel : newList) { + addElement(errorModel); + } + } + } +} \ No newline at end of file Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/ui (from rev 1195, jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/swing/ui) Modified: jaxx/trunk/pom.xml =================================================================== --- jaxx/trunk/pom.xml 2009-02-03 09:37:45 UTC (rev 1195) +++ jaxx/trunk/pom.xml 2009-02-03 15:49:43 UTC (rev 1196) @@ -22,6 +22,7 @@ <module>jaxx-runtime-api</module> <module>jaxx-runtime-swing</module> <module>jaxx-runtime-validator</module> + <module>jaxx-runtime-validator-swing</module> <module>jaxx-compiler-api</module> <module>jaxx-compiler-swing</module>
participants (1)
-
tchemit@users.labs.libre-entreprise.org