Author: tchemit Date: 2008-10-15 18:35:54 +0000 (Wed, 15 Oct 2008) New Revision: 919 Added: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/pom.xml lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/resources/ Removed: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/pom.xml lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/pom.xml lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/LabelStyle/ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/BeanValidator.java lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/Toto.java lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/resources/examples/Validation/Toto-validation.xml Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/Validation.jaxx Log: introduce BeanValidator + example for validation Deleted: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/pom.xml =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/pom.xml 2008-10-15 18:33:00 UTC (rev 918) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/pom.xml 2008-10-15 18:35:54 UTC (rev 919) @@ -1,148 +0,0 @@ -<?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>lutinjaxx</artifactId> - <version>0.5-SNAPSHOT</version> - </parent> - - <artifactId>Validattion</artifactId> - - <dependencies> - - <dependency> - <groupId>org.codelutin</groupId> - <artifactId>jaxx-core</artifactId> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>com.opensymphony</groupId> - <artifactId>xwork</artifactId> - <version>2.1.1</version> - </dependency> - - <dependency> - <groupId>org.swinglabs</groupId> - <artifactId>jxlayer</artifactId> - <version>3.0.1</version> - </dependency> - - </dependencies> - - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - <name>Validattion example</name> - <version>0.5-SNAPSHOT</version> - <inceptionYear>2008</inceptionYear> - <description>Jaxx Validattion (with xwork validation) example</description> - <url>${example.home.url}</url> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - - <packaging>jar</packaging> - - <properties> - <maven.jar.main.class>examples.${project.artifactId}.${project.artifactId}</maven.jar.main.class> - </properties> - <build> - <finalName>${project.artifactId}</finalName> - - <pluginManagement> - <plugins> - <plugin> - <groupId>org.codelutin</groupId> - <artifactId>maven-jaxx-plugin</artifactId> - <configuration> - <src>${basedir}/src/main/java</src> - <force>true</force> - </configuration> - <dependencies> - <dependency> - <groupId>org.swinglabs</groupId> - <artifactId>jxlayer</artifactId> - <version>3.0.1</version> - </dependency> - </dependencies> - <executions> - <execution> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <configuration> - <outputDirectory>${project.build.directory}/lib</outputDirectory> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <configuration> - <archive> - <manifest> - <addClasspath>true</addClasspath> - <mainClass>${maven.jar.main.class}</mainClass> - <classpathPrefix>lib/</classpathPrefix> - </manifest> - </archive> - </configuration> - </plugin> - </plugins> - </pluginManagement> - - <plugins> - - <plugin> - <groupId>org.codelutin</groupId> - <artifactId>maven-jaxx-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - </plugin> - - <plugin> - <artifactId>maven-antrun-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.codehaus.mojo.webstart</groupId> - <artifactId>webstart-maven-plugin</artifactId> - </plugin> - - </plugins> - </build> - - <repositories> - <repository> - <id>dowload-javanet-repository</id> - <name>JavaNetRepository</name> - <url>http://download.java.net/maven/2</url> - </repository> - </repositories> -</project> \ No newline at end of file Copied: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation (from rev 916, lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2) Deleted: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/pom.xml =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/pom.xml 2008-10-15 13:56:48 UTC (rev 916) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/pom.xml 2008-10-15 18:35:54 UTC (rev 919) @@ -1,66 +0,0 @@ -<?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-example-pom</artifactId> - <version>0.5-SNAPSHOT</version> - </parent> - - <artifactId>LabelStyle2</artifactId> - - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - <name>LabelStyle2 example</name> - <version>0.5-SNAPSHOT</version> - <inceptionYear>2008</inceptionYear> - <description>Jaxx LabelStyle2 (with xwork validation) example</description> - <url>${example.home.url}</url> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - - <packaging>jar</packaging> - - <build> - <finalName>${project.artifactId}</finalName> - <plugins> - - <plugin> - <groupId>org.codelutin</groupId> - <artifactId>maven-jaxx-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - </plugin> - - <plugin> - - <artifactId>maven-antrun-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.codehaus.mojo.webstart</groupId> - <artifactId>webstart-maven-plugin</artifactId> - </plugin> - - </plugins> - </build> -</project> \ No newline at end of file Copied: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/pom.xml (from rev 917, lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/pom.xml) =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/pom.xml (rev 0) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/pom.xml 2008-10-15 18:35:54 UTC (rev 919) @@ -0,0 +1,136 @@ +<?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>lutinjaxx</artifactId> + <version>0.5-SNAPSHOT</version> + </parent> + + <artifactId>Validation</artifactId> + + <dependencies> + + <dependency> + <groupId>org.codelutin</groupId> + <artifactId>jaxx-core</artifactId> + <scope>compile</scope> + </dependency> + + </dependencies> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + <name>Validattion example</name> + <version>0.5-SNAPSHOT</version> + <inceptionYear>2008</inceptionYear> + <description>Jaxx Validattion (with xwork validation) example</description> + <url>${example.home.url}</url> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + + <packaging>jar</packaging> + + <properties> + <maven.jar.main.class>examples.${project.artifactId}.${project.artifactId}</maven.jar.main.class> + </properties> + <build> + <finalName>${project.artifactId}</finalName> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.codelutin</groupId> + <artifactId>maven-jaxx-plugin</artifactId> + <configuration> + <src>${basedir}/src/main/java</src> + <force>true</force> + </configuration> + <dependencies> + <dependency> + <groupId>org.swinglabs</groupId> + <artifactId>jxlayer</artifactId> + <version>3.0.1</version> + </dependency> + </dependencies> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <configuration> + <outputDirectory>${project.build.directory}/lib</outputDirectory> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <mainClass>${maven.jar.main.class}</mainClass> + <classpathPrefix>lib/</classpathPrefix> + </manifest> + </archive> + </configuration> + </plugin> + </plugins> + </pluginManagement> + + <plugins> + + <plugin> + <groupId>org.codelutin</groupId> + <artifactId>maven-jaxx-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + </plugin> + + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo.webstart</groupId> + <artifactId>webstart-maven-plugin</artifactId> + </plugin> + + </plugins> + </build> + + <repositories> + <repository> + <id>dowload-javanet-repository</id> + <name>JavaNetRepository</name> + <url>http://download.java.net/maven/2</url> + </repository> + </repositories> +</project> \ No newline at end of file Copied: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation (from rev 917, lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/src/main/java/examples/Validation) Deleted: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/BeanValidator.java =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/src/main/java/examples/Validation/BeanValidator.java 2008-10-15 15:20:25 UTC (rev 917) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/BeanValidator.java 2008-10-15 18:35:54 UTC (rev 919) @@ -1,494 +0,0 @@ -/* *##% - * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - *##%*/ - -package examples.Validation; - - -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.ValidationAwareSupport; -import com.opensymphony.xwork2.config.Configuration; -import com.opensymphony.xwork2.config.ConfigurationManager; -import com.opensymphony.xwork2.util.ValueStack; -import com.opensymphony.xwork2.util.ValueStackFactory; -import com.opensymphony.xwork2.validator.ActionValidatorManager; -import com.opensymphony.xwork2.validator.DelegatingValidatorContext; -import com.opensymphony.xwork2.validator.ValidationException; -import java.awt.AlphaComposite; -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; -import java.awt.Graphics2D; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.RenderingHints; -import java.awt.image.BufferedImage; -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JList; -import javax.swing.ListModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.jxlayer.JXLayer; -import org.jdesktop.jxlayer.plaf.AbstractLayerUI; - -/** - * <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> - * Le mieux pour son integration dans Jaxx est de faire de la generation pour - * force la compilation du code suivant: - * - * <pre> - * myValidor.getBean().get<field>(); - * </pre> - * - * 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> - * 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> - * - * 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> - * 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> - * 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 - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class BeanValidator<T> { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(BeanValidator.class); - - protected PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - protected ValidationAwareSupport validationSupport = new ValidationAwareSupport(); - protected DelegatingValidatorContext validationContext = - new DelegatingValidatorContext(validationSupport); - - protected transient ActionValidatorManager validator = null; - - /** indique si le bean a ete modifie depuis sont arrive */ - protected boolean changed = false; - /** le bean a surveiller */ - protected T bean = null; - /** l'objet qui recoit les notifications de modification du bean */ - protected Listener l = new Listener(); - /** permet de faire le lien en un champs du bean et l'objet qui permet de l'editer */ - protected Map<String, JComponent> fieldRepresentation = new HashMap<String, JComponent>(); - /** Objet servant a afficher toutes les erreurs */ - protected JList errorList = null; - - public BeanValidator() { - } - - /** - * Permet de modifier l'objet permettant d'afficher toutes les errors - * @param errorList si null arrete d'afficher les errors - */ - public void setErrorList(JList errorList) { - this.errorList = errorList; - } - - public JList getErrorList() { - return errorList; - } - - /** - * Permet d'indiquer le composant graphique responsable de l'affichage - * d'un attribut du bean - * @param fieldname - * @param c - */ - public void setFieldRepresentation(String fieldname, JComponent c) { - JComponent old = fieldRepresentation.put(fieldname, c); - setErrorRepresentation(fieldname, old, c); - } - - public void setFieldRepresentation(Map<String, JComponent> fieldRepresentation) { - for(Map.Entry<String, JComponent> e : fieldRepresentation.entrySet()) { - setFieldRepresentation(e.getKey(), e.getValue()); - } - } - - - - public JComponent getFieldRepresentation(String fieldname) { - return fieldRepresentation.get(fieldname); - } - - - /** - * Retourne vrai si l'objet bean a ete modifie depuis le dernier - * {@link #setBean} - * @return - */ - public boolean isChanged() { - return changed; - } - - /** - * Permet de force la remise a false de l'etat de changement du bean - * @param changed - */ - public void setChanged(boolean changed) { - boolean oldChanged = this.changed; - this.changed = changed; - pcs.firePropertyChange("changed", oldChanged, changed); - } - - public T getBean() { - return bean; - } - - public void setBean(T bean) { - T oldBean = this.bean; - if (this.bean != null) { - try { - Method method = this.bean.getClass().getMethod("removePropertyChangeListener", PropertyChangeListener.class); - method.invoke(this.bean, l); - } catch (Exception eee) { - log.info("Can't register as listener", eee); - } - } - this.bean = bean; - if (this.bean != null) { - try { - Method method = this.bean.getClass().getMethod("addPropertyChangeListener", PropertyChangeListener.class); - method.invoke(this.bean, l); - } catch (Exception eee) { - log.info("Can't register as listener", eee); - } - } - validate(); - pcs.firePropertyChange("bean", oldBean, bean); - } - - protected ActionValidatorManager getValidator() { - if (validator == null) { - ConfigurationManager confManager = new ConfigurationManager(); - Configuration conf = confManager.getConfiguration(); - - ValueStackFactory vsf = conf.getContainer().getInstance( - ValueStackFactory.class); - ValueStack vs = vsf.createValueStack(); - ActionContext context = new ActionContext(vs.getContext()); - ActionContext.setContext(context); - - validator = conf.getContainer().getInstance( - ActionValidatorManager.class, "no-annotations"); - } - return validator; - } - - /** - * il faut eviter le code re-intrant (durant une validation, une autre est - * demandee). Pour cela on fait la validation dans un thread, et tant - * que la premiere validation n'est pas fini, on ne repond pas aux - * solicitations. - * Cette method est public pour permettre de force une validation par - * programmation, ce qui est utile par exemple si le bean ne supporte - * pas les {@link PropertyChangeListener} - */ - public void validate() { - // on ne valide que si il y a un bean et que le resultat de la validation - // pourra etre affiche quelque part - if (bean != null && (getErrorList() != null || fieldRepresentation.size() != 0)) { - try { - - validationSupport.clearErrorsAndMessages(); - getValidator().validate(bean, null, validationContext); - - if(log.isDebugEnabled()) { - log.debug("Action errors: " + validationContext.getActionErrors()); - log.debug("Action messages: " + validationContext.getActionMessages()); - log.debug("Field errors: " + validationContext.getFieldErrors()); - } - - System.out.println(validationContext.getFieldErrors()); - - // TODO: trouver autre chose - // On est obliger de le refaire ici car avec jaxx, lors du - // setFieldRepresentation le composant n'a pas encore de pere :( - for (String fieldname : fieldRepresentation.keySet()) { - JComponent c = fieldRepresentation.get(fieldname); - setErrorRepresentation(fieldname, null, c); - } - } catch (ValidationException eee) { - log.warn("Error during validation", eee); - } - } - } - - protected void setErrorRepresentation(String fieldname, JComponent old, JComponent c) { - if (old != c) { - if (old != null) { - // suppression du jxlayer sous l'ancien composant - Container container = old.getParent(); - if (container instanceof JXLayer) { - JXLayer<JComponent> jx = (JXLayer<JComponent>)container; - jx.setUI(null); - } - } - if (c != null) { - // ajout du jxlayer sous ce composant - Container container = c.getParent(); - if (container instanceof JXLayer) { - IconValidationUI ui = new IconValidationUI(fieldname, validationSupport.getFieldErrors()); -// TranslucentValidationUI ui = new TranslucentValidationUI(fieldname, validationSupport.getFieldErrors()); - ui.setEnabled(true); - - JXLayer<JComponent> jx = (JXLayer<JComponent>)container; - jx.setUI(ui); - } - } - } - } - - /** - * Permet d'afficher les messages d'error dans L'ui - */ - protected ListModel getListModel() { - // FIXME a implanter - return null; - } - - protected class Listener implements PropertyChangeListener { - - public void propertyChange(PropertyChangeEvent evt) { - validate(); - setChanged(true); - } - - } - - /** - * recherche les composants portant le meme nom que les champs de la classe - * clazz. Cette methode est statique pour pouvoir eventuellement l'utiliser - * dans un autre context (je pense par exemple a la generation jaxx). - * - * <p> - * Si la recherche echoue pour quelque raison que se soit, aucune exception - * n'est leve, et la map retournee est tout simplement vide ou incomplete - * - * @param clazz la classe ou recherche les champs - * @param container le container ou rechercher les composants d'edition - * @return - */ - public static Map<String, JComponent> lookingForEditor(Class clazz, Container container) { - Map<String, JComponent> result = new HashMap<String, JComponent>(); - try { - // looking for all component with name set - Map<String, JComponent> allNamedComponent = new HashMap<String, JComponent>(); - List<Container> todo = new LinkedList<Container>(); - todo.add(container); - while (todo.size() > 0) { - for (ListIterator<Container> i = todo.listIterator(); i.hasNext();) { - Container parent = i.next(); - i.remove(); - for (Component c : parent.getComponents()) { - if (c instanceof Container) { - i.add((Container) c); - String name = c.getName(); - if (c instanceof JComponent && - name != null && !"".equals(name)) { - allNamedComponent.put(name, (JComponent)c); - } - } - } - } - } - - // looking for all properties on class - BeanInfo info = Introspector.getBeanInfo(clazz); - PropertyDescriptor[] props = info.getPropertyDescriptors(); - - // find if one properties have same name that component - for (PropertyDescriptor prop : props) { - String name = prop.getName(); - if (allNamedComponent.containsKey(name)) { - result.put(name, allNamedComponent.get(name)); - } - } - - } catch (IntrospectionException eee) { - log.warn("Can't introspect bean", eee); - } - - System.out.println("Result: " + result); - - return result; - } - - public static class TranslucentValidationUI extends AbstractLayerUI<JComponent> { - - protected String field = null; - protected Map resultValidation = null; - public TranslucentValidationUI(String field, Map resultValidation) { - this.field = field; - this.resultValidation = resultValidation; - } - - @Override - protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) { - // paints the layer as is - super.paintLayer(g2, l); - - // to be in sync with the view if the layer has a border - Insets layerInsets = l.getInsets(); - g2.translate(layerInsets.left, layerInsets.top); - - JComponent view = l.getView(); - // To prevent painting on view's border - Insets insets = view.getInsets(); - g2.clip(new Rectangle(insets.left, insets.top, - view.getWidth() - insets.left - insets.right, - view.getHeight() - insets.top - insets.bottom)); - - g2.setColor(!resultValidation.containsKey(field) ? - Color.GREEN : Color.RED); - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .2f)); - g2.fillRect(0, 0, l.getWidth(), l.getHeight()); - } - } - - public static class IconValidationUI extends AbstractLayerUI<JComponent> { - - // The red icon to be shown at the layer's corner - private final static BufferedImage INVALID_ICON; - - static { - int width = 7; - int height = 8; - INVALID_ICON = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2 = (Graphics2D) INVALID_ICON.getGraphics(); - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - g2.setColor(Color.RED); - g2.fillRect(0, 0, width, height); - g2.setColor(Color.WHITE); - g2.drawLine(0, 0, width, height); - g2.drawLine(0, height, width, 0); - g2.dispose(); - } - - protected String field = null; - protected Map resultValidation = null; - public IconValidationUI(String field, Map resultValidation) { - this.field = field; - this.resultValidation = resultValidation; - } - - @Override - public void installUI(JComponent c) { - super.installUI(c); - c.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 3)); - } - - @Override - public void uninstallUI(JComponent c) { - super.uninstallUI(c); - c.setBorder(null); - } - - @Override - protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) { - super.paintLayer(g2, l); - - // There is no need to take insets into account for this painter - if (resultValidation.containsKey(field)) { - g2.drawImage(INVALID_ICON, l.getWidth() - INVALID_ICON.getWidth() - 1, 0, null); -// g2.drawImage(INVALID_ICON, 0, 0, null); - } - } - } - -} Deleted: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/Toto.java =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/src/main/java/examples/Validation/Toto.java 2008-10-15 15:20:25 UTC (rev 917) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/Toto.java 2008-10-15 18:35:54 UTC (rev 919) @@ -1,41 +0,0 @@ -package examples.Validation; - -import java.beans.*; - -class Toto { - - String text = "initial"; - - PropertyChangeSupport p; - - public Toto() { - p = new PropertyChangeSupport(this); - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - p.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - p.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - p.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - p.removePropertyChangeListener(propertyName, listener); - } - - - public String getText() { - return text; - } - - public void setText(String text) { - String oldText = this.text; - this.text = text; - p.firePropertyChange("text", oldText, text); - } -} Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/Validation.jaxx =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/src/main/java/examples/Validation/Validation.jaxx 2008-10-15 15:20:25 UTC (rev 917) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-15 18:35:54 UTC (rev 919) @@ -1,14 +1,14 @@ <Application title="Validation.jaxx"> <style source="Validation.css"/> - + <Model id='model'/> <script> import org.jdesktop.jxlayer.JXLayer; +import jaxx.runtime.BeanValidator; -Toto toto = new Toto(); - BeanValidator validator = new BeanValidator(); validator.setFieldRepresentation("text", text); -validator.setBean(toto); +validator.setFieldRepresentation("text2", text2); +validator.setBean(model); </script> <Table anchor='north' fill='both'> @@ -16,21 +16,21 @@ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'> <Table anchor='west' fill='both'> <row> - <cell><JLabel text='Email:'/></cell> + <cell><JLabel text='Text:'/></cell> <cell weightx='1'> <org.jdesktop.jxlayer.JXLayer> - <JTextField id='text' text='{toto.getText()}' - onKeyReleased='toto.setText(text.getText())'/> + <JTextField id='text' text='{model.getText()}' + onKeyReleased='model.setText(text.getText())'/> </org.jdesktop.jxlayer.JXLayer> </cell> </row> <row> <cell> - <JLabel text='Email:'/> + <JLabel text='Text2 :'/> </cell> <cell weightx='1'> <org.jdesktop.jxlayer.JXLayer> - <JTextField id='text2' text='{toto.getText()}' onKeyReleased='toto.setText(text2.getText())'/> + <JTextField id='text2' text='{model.getText2()}' onKeyReleased='model.setText2(text2.getText())'/> </org.jdesktop.jxlayer.JXLayer> </cell> </row> @@ -64,7 +64,7 @@ margin='0' horizontalAlignment='center' verticalAlignment='middle'> - <JLabel text='{toto.getText()}' font-size='{csize.getValue()}' foreground='{new Color(red.getValue(), green.getValue(), blue.getValue())}'/> + <JLabel text='{model.getText()}' font-size='{csize.getValue()}' foreground='{new Color(red.getValue(), green.getValue(), blue.getValue())}'/> </VBox> </JPanel> </cell> Copied: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/resources (from rev 917, lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/src/main/resources) Deleted: lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/resources/examples/Validation/Toto-validation.xml =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/examples/LabelStyle2/src/main/resources/examples/Validation/Toto-validation.xml 2008-10-15 15:20:25 UTC (rev 917) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/examples/Validation/src/main/resources/examples/Validation/Toto-validation.xml 2008-10-15 18:35:54 UTC (rev 919) @@ -1,19 +0,0 @@ -<!DOCTYPE validators PUBLIC - "-//OpenSymphony Group//XWork Validator 1.0.2//EN" - "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> - <validators> - <!-- Field Validators for email field --> - <field name="text"> - <field-validator type="required" short-circuit="true"> - <message>You must enter a value for text.</message> - </field-validator> - <field-validator type="email" short-circuit="true"> - <message>Not a valid e-mail.</message> - </field-validator> - </field> - <!-- Plain Validator 1 --> - <validator type="expression"> - <param name="expression">text.startsWith("poussin")</param> - <message>Email not starts with poussin</message> - </validator> - </validators> \ No newline at end of file