Jaxx-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
March 2009
- 2 participants
- 33 discussions
[Buix-commits] r1282 - jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing
by sletellier@users.labs.libre-entreprise.org 30 Mar '09
by sletellier@users.labs.libre-entreprise.org 30 Mar '09
30 Mar '09
Author: sletellier
Date: 2009-03-30 13:42:57 +0000 (Mon, 30 Mar 2009)
New Revision: 1282
Modified:
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java
Log:
Adding blocking color
Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java 2009-03-29 13:36:44 UTC (rev 1281)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/BlockingLayerUI2.java 2009-03-30 13:42:57 UTC (rev 1282)
@@ -1,5 +1,7 @@
package jaxx.runtime.swing;
+import java.awt.AlphaComposite;
+import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.Point;
@@ -51,6 +53,10 @@
*/
protected BufferedImage acceptIcon;
/**
+ * Optinal color to put fill background when blocking
+ */
+ protected Color blockingColor;
+ /**
* Internal state to known when we can accept click
*/
protected boolean canClick;
@@ -85,6 +91,10 @@
super.setDirty(isDirty);
}
+ public void setBlockingColor(Color blockingColor) {
+ this.blockingColor = blockingColor;
+ }
+
public void setBlockIcon(BufferedImage blockIcon) {
this.blockIcon = blockIcon;
}
@@ -107,22 +117,19 @@
clone.acceptAction = acceptAction;
clone.acceptIcon = acceptIcon;
clone.blockIcon = blockIcon;
+ clone.blockingColor = blockingColor;
clone.setCanClick(false);
return clone;
}
@Override
protected void processKeyEvent(KeyEvent e, JXLayer<JComponent> l) {
-
e.consume();
-
}
@Override
protected void processMouseMotionEvent(MouseEvent e, JXLayer<JComponent> l) {
-
e.consume();
-
}
@Override
@@ -140,25 +147,29 @@
}
break;
}
- e.consume();
+ e.consume();
}
@Override
protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) {
super.paintLayer(g2, l);
-
- // to be in sync with the view if the layer has a border
+ if (blockingColor != null) {
+ // to be in sync with the view if the layer has a border
/*Insets layerInsets = l.getInsets();
- g2.translate(layerInsets.left, layerInsets.top);
+ 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));
- */
+ 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(blockingColor);
+ g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .1f));
+ g2.fillRect(0, 0, l.getWidth(), l.getHeight());
+ }
if (getCurrentIcon() != null) {
g2.drawImage(getCurrentIcon(), l.getWidth() - getCurrentIcon().getWidth() - 1, 0, null);
}
1
0
[Buix-commits] r1281 - in jaxx/trunk/maven-jaxx-plugin: . src/main/java/org/codelutin/jaxx src/main/resources src/test/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org 29 Mar '09
by tchemit@users.labs.libre-entreprise.org 29 Mar '09
29 Mar '09
Author: tchemit
Date: 2009-03-29 13:36:44 +0000 (Sun, 29 Mar 2009)
New Revision: 1281
Added:
jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java
jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxHelpGeneratorMojo.java
jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/NodeItem.java
jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/TemplateGenerator.java
jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultContent.html.vm
jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm
jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultI18n.java.vm
jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultIndex.xml.vm
jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultMap.jhm.vm
jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultToc.xml.vm
jaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/NodeItemTest.java
Modified:
jaxx/trunk/maven-jaxx-plugin/changelog.txt
jaxx/trunk/maven-jaxx-plugin/pom.xml
jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
jaxx/trunk/maven-jaxx-plugin/src/main/resources/log4j.properties
Log:
add generate-help goal
Modified: jaxx/trunk/maven-jaxx-plugin/changelog.txt
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-03-29 13:36:21 UTC (rev 1280)
+++ jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-03-29 13:36:44 UTC (rev 1281)
@@ -1,4 +1,5 @@
1.3 chemit 20090321
+ * 20090327 [chemit] - add javax help mecanism
* 20090301 [chemit] - add a profile mode (-Djaxx.profile)
1.2 letelier 2009022?
Modified: jaxx/trunk/maven-jaxx-plugin/pom.xml
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/pom.xml 2009-03-29 13:36:21 UTC (rev 1280)
+++ jaxx/trunk/maven-jaxx-plugin/pom.xml 2009-03-29 13:36:44 UTC (rev 1281)
@@ -1,3 +1,4 @@
+
<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>
@@ -87,6 +88,16 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.5</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ </dependency>
</dependencies>
Added: jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,170 @@
+/* *##%
+ * Copyright (C) 2007
+ * JaxxPlugin, Code Lutin
+ *
+ * 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 org.codelutin.jaxx;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+
+/**
+ * Abract Jaxx Mojo.
+ *
+ * @author chemit
+ *
+ * @since 1.3
+ */
+public abstract class AbstractJaxxMojo extends AbstractMojo {
+
+ /**
+ * Dépendance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ */
+ protected MavenProject project;
+ /**
+ * Repertoire de destination des fichiers java a generer.
+ *
+ * @parameter expression="${jaxx.outJava}" default-value="${basedir}/target/generated-sources/java"
+ */
+ protected File outJava;
+ /**
+ * verbose flag
+ *
+ * @parameter expression="${jaxx.verbose}" default-value="false"
+ *
+ * @since 1.3
+ */
+ protected boolean verbose;
+ /**
+ * to make compiler i18nable, says add the {@link org.codelutin.i18n.I18n#_(String, Object[])} method
+ * invocation on {@link jaxx.compiler.I18nHelper#I18N_ATTRIBUTES} attributes.
+ *
+ * @parameter expression="${jaxx.i18nable}" default-value="true"
+ * @see jaxx.compiler.I18nHelper
+ */
+ protected boolean i18nable;
+ /**
+ * The store of helpIds generated by {@link JaxxGeneratorMojo}.
+ * <p/>
+ *
+ * @parameter expression="${jaxx.helpIdStore}" default-value="target/helpIds.properties"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected File helpIdStore;
+ /**
+ * The name of the helpset to generate.
+ *
+ * @parameter expression="${jaxx.helpSetName}" default-value="${project.artifactId}"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String helpSetName;
+ /**
+ * The prefix to add to i18n key for any help i18n key.
+ *
+ * @parameter expression="${jaxx.helpsetI18nPrefix}" default-value="${jaxx.helpSetName}.help."
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String helpsetI18nPrefix;
+ /**
+ * The suffix to add to i18n key for an help Id.
+ *
+ * @parameter expression="${jaxx.helpsetTitleI18nSuffix}" default-value=".title"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String helpsetTitleI18nSuffix;
+ /**
+ * The suffix to add to i18n key for an toc Id.
+ *
+ * @parameter expression="${jaxx.helpsetTocI18nSuffix}" default-value=".toc"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String helpsetTocI18nSuffix;
+ /**
+ * The suffix to add to i18n key for an toc Id.
+ *
+ * @parameter expression="${jaxx.helpsetIndexI18nSuffix}" default-value=".index"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String helpsetIndexI18nSuffix;
+ protected boolean skip = true;
+ protected ClassLoader cl;
+
+ public abstract void init() throws Exception;
+
+ public abstract void doAction() throws Exception;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ try {
+ init();
+ } catch (Exception e) {
+ if (e instanceof MojoFailureException) {
+ throw (MojoFailureException) e;
+ }
+ if (e instanceof MojoExecutionException) {
+ throw (MojoExecutionException) e;
+ }
+ throw new MojoExecutionException("error in init : " + e.getMessage(), e);
+ }
+
+ if (skip) {
+ if (verbose) {
+ getLog().info("jaxx - skip!");
+ }
+ return;
+ }
+
+ try {
+
+ doAction();
+
+ } catch (Exception e) {
+ //getLog().error(e);
+ Throwable e2 = e;
+ while (e2.getCause() != null) {
+ e2 = e.getCause();
+ }
+ getLog().error(e2);
+
+ throw new MojoExecutionException(e2.getMessage(), e2);
+ } finally {
+ System.gc();
+ }
+
+ }
+
+}
\ No newline at end of file
Modified: jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2009-03-29 13:36:21 UTC (rev 1280)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2009-03-29 13:36:44 UTC (rev 1281)
@@ -16,7 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*##%*/
-
package org.codelutin.jaxx;
import jaxx.beaninfos.BeanInfoUtil;
@@ -25,17 +24,14 @@
import jaxx.compiler.JAXXCompilerLaunchor;
import jaxx.runtime.JAXXContext;
import jaxx.tags.TagManager;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.logging.Log;
-import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codelutin.util.FileUpdaterHelper;
import org.codelutin.util.MirroredFileUpdater;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
@@ -44,8 +40,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Properties;
import java.util.Set;
import jaxx.compiler.CompiledObjectDecorator;
+import jaxx.compiler.HelpRootCompiledObjectDecorator;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.project.MavenProject;
/**
* Classe permettant de transformer des sources jaxx vers du source java.
@@ -56,112 +56,79 @@
* @requiresDependencyResolution compile
* @requiresProject
*/
-public class JaxxGeneratorMojo extends AbstractMojo {
+public class JaxxGeneratorMojo extends AbstractJaxxMojo {
/**
- * Dépendance du projet.
- *
- * @parameter default-value="${project}"
- * @required
- * @readonly
- */
- protected MavenProject project;
-
- /**
* Le compilateur à utiliser (par défaut celui de Swing)
*
* @parameter expression="${jaxx.compilerFQN}" default-value="jaxx.compiler.SwingCompiler"
*/
protected String compilerFQN;
-
/**
* Le compilateur à utiliser (par défaut celui de Swing)
*
* @parameter expression="${jaxx.validatorFQN}" default-value="jaxx.runtime.validator.swing.SwingValidator"
*/
protected String validatorFQN;
-
/**
- * Repertoire de destination des fichiers java a generer.
- *
- * @parameter expression="${jaxx.outJava}" default-value="${basedir}/target/generated-sources/java"
- */
- protected File outJava;
- /**
- * flag to include in compiler classpath the java sources directories (src and outJava).
- * <p/>
- * By default, false.
- *
- * @parameter expression="${jaxx.addSourcesToClassPath}" default-value="false"
- */
- protected boolean addSourcesToClassPath;
-
- /**
- * flag to include in compiler classpath the project compile classpath.
- * <p/>
- * By default, false.
- *
- * @parameter expression="${jaxx.addProjectClassPath}" default-value="false"
- */
- protected boolean addProjectClassPath;
-
- /**
* chemin du repertoire de generation des resources.
*
* @parameter expression="${jaxx.outResource}" default-value="${basedir}/target/generated-sources/resources"
*/
protected File outResource;
-
/**
* chemin du repertoire de compilation des resources.
*
* @parameter expression="${jaxx.outClass}" default-value="${basedir}/target/classes"
*/
protected File outClass;
-
/**
- * verbose flag
- *
- * @parameter expression="${jaxx.verbose}" default-value="false"
- */
- protected boolean verbose;
-
- /**
* Repertoire sources des fichiers jaxx a generer.
*
* @parameter expression="${jaxx.src}" default-value="${maven.src.dir}/main/java"
*/
protected File src;
-
/**
* pour optimizer le code compile ou genere ?
*
* @parameter expression="${jaxx.optimize}" default-value="false"
*/
protected boolean optimize;
-
/**
* les options de la compilation
*
* @parameter expression="${jaxx.javaOpts}"
*/
protected String javaOpts = null;
-
/**
* pour filter les fichiers a traiter
*
* @parameter expression="${jaxx.includes}"
*/
protected String[] includes;
-
/**
* pour filter les fichiers a ne pas traiter
*
* @parameter expression="${jaxx.excludes}"
*/
protected String[] excludes;
-
/**
+ * flag to include in compiler classpath the java sources directories (src and outJava).
+ * <p/>
+ * By default, false.
+ *
+ * @parameter expression="${jaxx.addSourcesToClassPath}" default-value="false"
+ */
+ protected boolean addSourcesToClassPath;
+ /**
+ * flag to include in compiler classpath the project compile classpath.
+ * <p/>
+ * By default, false.
+ *
+ * @parameter expression="${jaxx.addProjectClassPath}" default-value="false"
+ */
+ protected boolean addProjectClassPath;
+ /**
* to force generation of java source for any jaxx files with no timestamp checking.
* <p/>
* By default, never force generation.
@@ -169,18 +136,7 @@
* @parameter expression="${jaxx.force}" default-value="false"
*/
protected boolean force;
-
/**
- * to make compiler i18nable, says add the {@link org.codelutin.i18n.I18n#_(String, Object[])} method
- * invocation on {@link jaxx.compiler.I18nHelper#I18N_ATTRIBUTES} attributes.
- *
- * @parameter expression="${jaxx.i18nable}" default-value="true"
- * @see jaxx.compiler.I18nHelper
- */
- protected boolean i18nable;
-
-
- /**
* flag to add logger to each generated jaxx file.
* <p/>
* By default, always add it.
@@ -196,7 +152,6 @@
* @parameter expression="${jaxx.resetAfterCompile}" default-value="true"
*/
protected boolean resetAfterCompile;
-
/**
* the name of implementation of {@link jaxx.runtime.JAXXContext}
* to be used on {@link jaxx.runtime.JAXXObject}.
@@ -207,7 +162,6 @@
* @required
*/
protected String jaxxContextImplementorClass;
-
/**
* extra path to be added in {@link java.beans.Introspector#setBeanInfoSearchPath(String[])}.
* <p/>
@@ -221,15 +175,22 @@
* @parameter expression="${jaxx.beanInfoSearchPath}"
*/
protected String[] beanInfoSearchPath;
-
/**
* list of fqn of class toimport for all generated jaxx files
*
* @parameter expression="${jaxx.extraImports}"
+ *
+ * @deprecated Prefer use of extraImportList as a string, so
+ * could be use in properties section.
*/
protected String[] extraImports;
-
/**
+ * list of fqn of class toimport for all generated jaxx files
+ *
+ * @parameter expression="${jaxx.extraImportList}"
+ */
+ protected String extraImportList;
+ /**
* the FQN of the ui to use for error notification.
* <p/>
* If not given, will use the one defined in validator
@@ -238,8 +199,7 @@
* @see jaxx.runtime.validator.swing.SwingValidator#DEFAULT_UI_CLASS
*/
protected String defaultErrorUIFQN;
-
- /**
+ /**
* the FQN of the ui to use for error notification.
* <p/>
* If not given, will use the one defined in validator
@@ -249,7 +209,6 @@
* @see jaxx.compiler.CompiledObjectDecorator
*/
protected String defaultDecoratorFQN;
-
/**
* a flag to use UIManager to retreave icons.
*
@@ -264,25 +223,37 @@
* @parameter expression="${jaxx.profile}" default-value="false"
*/
protected boolean profile;
-
+ /**
+ * flag to activate help generation process.
+ * <p/>
+ * By default, not active.
+ *
+ * @parameter expression="${jaxx.generateHelp}" default-value="false"
+ *
+ * @since 1.3
+ */
+ private boolean generateHelp;
+ /**
+ * the FQN of help broker
+ * <p/>
+ * By default, none.
+ *
+ * @parameter expression="${jaxx.helpBrokerFQN}"
+ *
+ * @since 1.3
+ */
+ private String helpBrokerFQN;
protected String[] files;
-
private static final String[] INCLUDES = {"**\\/*.jaxx"};
-
protected CompilerOptions options;
-
protected MirroredFileUpdater updater;
-
- protected boolean skip = true;
-
private Class<?> defaultErrorUIClass;
private Class<? extends CompiledObjectDecorator> defaultDecoratorClass;
-
- protected ClassLoader cl;
private Class<? extends JAXXCompiler> compilerClass;
@SuppressWarnings("unchecked")
- protected void init() throws ClassNotFoundException, MalformedURLException {
+ @Override
+ public void init() throws Exception {
if (project != null && ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()))) {
// nothing to be done for this type of packaging
@@ -291,12 +262,19 @@
return;
}
+ if (generateHelp) {
+ // check there is some bundle
+ if (helpIdStore == null) {
+ throw new MojoFailureException("you must set the helpIdStore property.");
+ }
+ }
+
compilerClass = (Class<? extends JAXXCompiler>) Class.forName(compilerFQN);
- defaultDecoratorClass = (Class<? extends CompiledObjectDecorator>) Class.forName(defaultDecoratorFQN);
-
+ defaultDecoratorClass = (Class<? extends CompiledObjectDecorator>) Class.forName(defaultDecoratorFQN);
+
// check the validator class is correct
Class.forName(validatorFQN);
-
+
if (defaultErrorUIFQN != null && !defaultErrorUIFQN.trim().isEmpty()) {
defaultErrorUIClass = Class.forName(defaultErrorUIFQN);
}
@@ -362,7 +340,18 @@
this.files = listFiles.toArray(new String[listFiles.size()]);
}
+ if (extraImportList != null && !extraImportList.isEmpty()) {
+ String[] imports = extraImportList.split(",");
+ int i = 0;
+ for (String importS : imports) {
+ imports[i++] = importS.trim();
+ }
+ if (verbose) {
+ getLog().info("extra imports " + java.util.Arrays.toString(imports));
+ }
+ extraImports = imports;
+ }
options = toCompilerOptions();
if (verbose) {
@@ -371,6 +360,43 @@
}
+ @Override
+ public void doAction() throws MojoExecutionException {
+ getLog().info("jaxx - detects " + this.files.length + " modify jaxx file(s). ");
+
+ try {
+
+ // force compiler init from here, not in a static block
+ TagManager.reset(verbose);
+
+ JAXXCompilerLaunchor launchor = JAXXCompilerLaunchor.newLaunchor(src, files, options);
+ boolean success = launchor.compile();
+ getLog().info("jaxx - generate " + launchor.getCompilerCount() + " file(s). ");
+
+ if (!success) {
+ throw new MojoExecutionException("Aborting due to errors reported by jaxxc");
+ }
+
+ if (generateHelp) {
+ // generate help
+ generateHelp();
+ }
+
+ } catch (MojoExecutionException e) {
+ getLog().error(e);
+ throw e;
+ } catch (Exception e) {
+ //getLog().error(e);
+ Throwable e2 = e;
+ while (e2.getCause() != null) {
+ e2 = e.getCause();
+ }
+ getLog().error(e2);
+
+ throw new MojoExecutionException(e2.getMessage(), e2);
+ }
+ }
+
public CompilerOptions toCompilerOptions() {
CompilerOptions result = new CompilerOptions();
result.setClassPath(src.getPath());
@@ -393,86 +419,116 @@
result.setDefaultErrorUI(defaultErrorUIClass);
result.setUseUIManagerForIcon(useUIManagerForIcon);
result.setDefaultDecoratorClass(defaultDecoratorClass);
+ result.setGenerateHelp(generateHelp);
+ result.setHelpBrokerFQN(helpBrokerFQN);
+ result.setHelpsetTitleI18nSuffix(helpsetTitleI18nSuffix);
+ result.setHelpsetIndexI18nSuffix(helpsetIndexI18nSuffix);
+ result.setHelpsetTocI18nSuffix(helpsetTocI18nSuffix);
+ result.setHelpSetName(helpSetName);
+ result.setHelpsetI18nPrefix(helpsetI18nPrefix);
+
if (cl != null) {
result.setClassLoader(cl);
}
return result;
}
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
+ protected void fixCompileSourceRoots() {
+ //fixme should remove this silly test when we will make real maven plugin tests :)
+ if (project != null) {
+ if (!project.getCompileSourceRoots().contains(outJava.getPath())) {
+ project.addCompileSourceRoot(outJava.getPath());
+ }
+ }
+ }
- try {
- init();
- } catch (ClassNotFoundException e) {
- throw new MojoExecutionException("error in init : " + e.getMessage(), e);
- } catch (MalformedURLException e) {
- throw new MojoExecutionException("error in init : " + e.getMessage(), e);
+ protected void printInit() {
+ getLog().info(options.toString());
+ getLog().info("includes : " + Arrays.toString(includes));
+ for (String file : files) {
+ getLog().info("will generate " + file);
}
- if (skip) {
- if (verbose) {
- getLog().info("jaxx - skip!");
+ ClassLoader threadLoader = Thread.currentThread().getContextClassLoader();
+ getLog().info(threadLoader.toString());
+ if (threadLoader.getClass().getSimpleName().equals("RealmClassLoader")) {
+ try {
+ java.lang.reflect.Method m = threadLoader.getClass().getDeclaredMethod("getURLs");
+ m.setAccessible(true);
+ URL[] urls = (URL[]) m.invoke(threadLoader);
+
+ for (URL url : urls) {
+ getLog().info("url in class loader " + url);
+ }
+ } catch (Exception e) {
+ getLog().warn("??? : " + e.getMessage(), e);
}
- return;
}
- if (files.length == 0) {
- getLog().info("jaxx - no jaxx file to treate. ");
- return;
+ //fixme should remove this silly test when we will make real maven plugin tests :)
+ if (getPluginContext() != null) {
+ for (Object e : getPluginContext().keySet()) {
+ getLog().info("pluginContext " + e + " : " + getPluginContext().get(e));
+ }
}
+ }
+ protected void checkJaxxContextImplementorClass() {
+ if (jaxxContextImplementorClass == null) {
+ throw new IllegalArgumentException("jaxxContextImplementor can not be null");
+ }
try {
- doAction();
- } finally {
- System.gc();
+ Class jaxxContextImplementor = Class.forName(jaxxContextImplementorClass);
+ if (!JAXXContext.class.isAssignableFrom(jaxxContextImplementor)) {
+ throw new IllegalArgumentException("jaxxContextImplementor '" + jaxxContextImplementor + "' does not implements " + JAXXContext.class);
+ }
+ if (Modifier.isAbstract(jaxxContextImplementor.getModifiers())) {
+ throw new IllegalArgumentException("jaxxContextImplementor '" + jaxxContextImplementor + "' can not be abstract.");
+
+ }
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("could not find jaxxContextImplementor class : " + jaxxContextImplementorClass);
}
-
}
- public void doAction() throws MojoExecutionException {
- getLog().info("jaxx - detects " + this.files.length + " modify jaxx file(s). ");
+ protected void generateHelp() throws IOException {
+ Set<String> helpIds = HelpRootCompiledObjectDecorator.getHelpIds();
+ if (helpIds.isEmpty()) {
+ if (verbose) {
+ // no ids detected in this compilation round
+ getLog().info("no helpIds detected.");
+ }
+ return;
+ }
- try {
+ if (!helpIdStore.getParentFile().exists()) {
+ helpIdStore.getParentFile().mkdirs();
+ }
- // force compiler init from here, not in a static block
- TagManager.reset(verbose);
+ Properties p = new Properties();
- JAXXCompilerLaunchor launchor = JAXXCompilerLaunchor.newLaunchor(src, files, options);
- boolean success = launchor.compile();
- getLog().info("jaxx - generate " + launchor.getCompilerCount() + " file(s). ");
+ for (String helpId : helpIds) {
+ String path = helpId.replaceAll("\\.", File.separator);
+ path = removeQuote(path) + ".html";
+ p.put(removeQuote(helpId), path);
+ }
- if (!success) {
- throw new MojoExecutionException("Aborting due to errors reported by jaxxc");
- }
+ FileOutputStream w = new FileOutputStream(helpIdStore);
- } catch (MojoExecutionException e) {
- getLog().error(e);
- throw e;
- } catch (Exception e) {
- //getLog().error(e);
- Throwable e2 = e;
- while (e2.getCause() != null) {
- e2 = e.getCause();
- }
- getLog().error(e2);
-
- throw new MojoExecutionException(e2.getMessage(), e2);
+ try {
+ p.store(w, null);
+ } finally {
+ w.close();
}
- }
- protected void fixCompileSourceRoots() {
- //fixme should remove this silly test when we will make real maven plugin tests :)
- if (project != null) {
- if (!project.getCompileSourceRoots().contains(outJava.getPath())) {
- project.addCompileSourceRoot(outJava.getPath());
- }
- }
+ getLog().info("helpIdStore generated in " + helpIdStore);
+
+ helpIds.clear();
}
@SuppressWarnings({"unchecked"})
- protected URLClassLoader initClassLoader(MavenProject project, Log log) throws MalformedURLException {
- URLClassLoader loader;
+ protected URLClassLoader initClassLoader(MavenProject project, org.apache.maven.plugin.logging.Log log) throws MalformedURLException {
+ URLClassLoader loader = null;
if (project != null) {
URLClassLoader result;
@@ -499,7 +555,7 @@
result = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader());
} catch (IOException e) {
- throw new RuntimeException("Can't create ClassLoader for script, bad directory: " + outClass + " for reason " + e.getMessage(), e);
+ throw new RuntimeException("Can't create ClassLoader for reason " + e.getMessage(), e);
}
loader = result;
} else {
@@ -517,53 +573,13 @@
return loader;
}
- protected void printInit() {
- getLog().info(options.toString());
- getLog().info("includes : " + Arrays.toString(includes));
- for (String file : files) {
- getLog().info("will generate " + file);
+ protected String removeQuote(String txt) {
+ if (txt.startsWith("\"")) {
+ txt = txt.substring(1);
}
-
- ClassLoader threadLoader = Thread.currentThread().getContextClassLoader();
- getLog().info(threadLoader.toString());
- if (threadLoader.getClass().getSimpleName().equals("RealmClassLoader")) {
- try {
- java.lang.reflect.Method m = threadLoader.getClass().getDeclaredMethod("getURLs");
- m.setAccessible(true);
- URL[] urls = (URL[]) m.invoke(threadLoader);
-
- for (URL url : urls) {
- getLog().info("url in class loader " + url);
- }
- } catch (Exception e) {
- getLog().warn("??? : " + e.getMessage(), e);
- }
+ if (txt.endsWith("\"")) {
+ txt = txt.substring(0, txt.length() - 1);
}
-
- //fixme should remove this silly test when we will make real maven plugin tests :)
- if (getPluginContext() != null) {
- for (Object e : getPluginContext().keySet()) {
- getLog().info("pluginContext " + e + " : " + getPluginContext().get(e));
- }
- }
+ return txt;
}
-
- protected void checkJaxxContextImplementorClass() {
- if (jaxxContextImplementorClass == null) {
- throw new IllegalArgumentException("jaxxContextImplementor can not be null");
- }
- try {
- Class jaxxContextImplementor = Class.forName(jaxxContextImplementorClass);
- if (!JAXXContext.class.isAssignableFrom(jaxxContextImplementor)) {
- throw new IllegalArgumentException("jaxxContextImplementor '" + jaxxContextImplementor + "' does not implements " + JAXXContext.class);
- }
- if (Modifier.isAbstract(jaxxContextImplementor.getModifiers())) {
- throw new IllegalArgumentException("jaxxContextImplementor '" + jaxxContextImplementor + "' can not be abstract.");
-
- }
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("could not find jaxxContextImplementor class : " + jaxxContextImplementorClass);
- }
- }
-
}
\ No newline at end of file
Added: jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxHelpGeneratorMojo.java
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxHelpGeneratorMojo.java (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxHelpGeneratorMojo.java 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,792 @@
+/* *##%
+ * Copyright (C) 2007
+ * JaxxPlugin, Code Lutin
+ *
+ * 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 org.codelutin.jaxx;
+
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Stack;
+import org.apache.maven.model.Resource;
+import org.codelutin.i18n.I18n;
+import org.codelutin.util.FileUtil;
+import org.codelutin.util.SortedProperties;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+import static org.codelutin.i18n.I18n._;
+
+/**
+ * Mojo to generate javax help stuff for your project.
+ *
+ * HelpIds should have been discovered by the JaxxMojo.
+ *
+ * @author chemit
+ * @goal generate-help
+ * @phase process-sources
+ *
+ * @requiresProject
+ * @requiresDependencyResolution compile
+ * @since 1.3
+ */
+public class JaxxHelpGeneratorMojo extends AbstractJaxxMojo {
+
+ /**
+ * The directory where to generate javaHelp skeleton files.
+ * <p/>
+ * Is required if generateHelp is on.
+ *
+ * @parameter expression="${jaxx.helpTarget}" alias="target" default-value="${maven.src.dir}/main/help"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected File target;
+ /**
+ * The locale to generate for help.
+ *
+ * By default, stay in France.
+ *
+ * @parameter expression="${jaxx.locale}" default-value="fr"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String locale;
+ /**
+ * The package where to generate i18n java file.
+ *
+ * @parameter expression="${jaxx.packageName}" default-value="${project.groupId}"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String packageName;
+ /**
+ * The file name of the helpset to generate.
+ *
+ * @parameter expression="${jaxx.helpSetFileName}" default-value="${jaxx.helpSetName}.hs"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String helpsetFileName;
+ /**
+ * The file name of the helpset map to generate.
+ *
+ * @parameter expression="${jaxx.mapFileName}" default-value="${jaxx.helpSetName}Map.jhm"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String mapFileName;
+ /**
+ * The file name of the helpset index to generate.
+ *
+ * @parameter expression="${jaxx.indexFileName}" default-value="${jaxx.helpSetName}Index.xml"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String indexFileName;
+ /**
+ * The file name of the helpset toc to generate.
+ *
+ * @parameter expression="${jaxx.tocFileName}" default-value="${jaxx.helpSetName}TOC.xml"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String tocFileName;
+ /**
+ * The file name of the i18n java file to generate.
+ *
+ * @parameter expression="${jaxx.i8nFileName}" default-value="${jaxx.helpSetName}I18n.java"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected String i8nFileName;
+ /**
+ * The template used to generate helpset file.
+ *
+ * Must be an existing file or a ressource in classp-ath
+ *
+ * @parameter expression="${jaxx.helpSetTemplate}" default-value="/defaultHelpSet.hs.vm"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected File helpSetTemplate;
+ /**
+ * The template used to generate helpset map file.
+ *
+ * Must be an existing file or a ressource in classp-ath
+ *
+ * @parameter expression="${jaxx.mapTemplate}" default-value="/defaultMap.jhm.vm"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected File mapTemplate;
+ /**
+ * The template used to generate helpset index file.
+ *
+ * Must be an existing file or a ressource in classp-ath
+ *
+ * @parameter expression="${jaxx.indexTemplate}" default-value="/defaultIndex.xml.vm"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected File indexTemplate;
+ /**
+ * The template used to generate helpset toc file.
+ *
+ * Must be an existing file or a ressource in classp-ath
+ *
+ * @parameter expression="${jaxx.tocTemplate}" default-value="/defaultToc.xml.vm"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected File tocTemplate;
+ /**
+ * The template used to generate helpset content file.
+ *
+ * Must be an existing file or a ressource in classp-ath
+ *
+ * @parameter expression="${jaxx.contentTemplate}" default-value="/defaultContent.html.vm"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected File contentTemplate;
+ /**
+ * The template used to generate helpset content file.
+ *
+ * Must be an existing file or a ressource in classp-ath
+ *
+ * @parameter expression="${jaxx.i18nTemplate}" default-value="/defaultI18n.java.vm"
+ * @required
+ *
+ * @since 1.3
+ */
+ protected File i18nTemplate;
+ /**
+ * The help ids discovered by Jaxx compilation
+ */
+ protected Properties helpIds;
+ private static final String AUTOREMOVE_LINE = "REMOVE THS LINE TO DISABLE AUTO-REGENERATE THE FILE";
+
+ @Override
+ public void init() throws Exception {
+
+ if (project != null && ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()))) {
+ // nothing to be done for this type of packaging
+ skip = true;
+ getLog().info("skip generate goal for packaging " + project.getPackaging());
+ return;
+ }
+
+ if (!helpIdStore.exists()) {
+ skip = true;
+ getLog().info("no helpIdStore to react at " + helpIdStore);
+ return;
+ }
+
+ // check there is some bundle
+ if (locale == null) {
+ throw new MojoFailureException("you must set the bundles property.");
+ }
+ // check there is some bundle
+ if (target == null) {
+ throw new MojoFailureException("you must set the target property.");
+ }
+ // check ressources
+ checkResource(helpSetTemplate);
+ checkResource(mapTemplate);
+ checkResource(indexTemplate);
+ checkResource(tocTemplate);
+ checkResource(contentTemplate);
+
+ if (!target.exists()) {
+ getLog().info("mkdir " + target);
+ target.mkdirs();
+ }
+
+
+ helpIds = new SortedProperties();
+
+ InputStream stream = new FileInputStream(helpIdStore);
+
+ helpIds.load(stream);
+
+ stream.close();
+
+ if (helpIds.isEmpty()) {
+
+ // no ids detected
+ getLog().warn("no helpIds detected, will skip.");
+ skip = true;
+ return;
+ }
+
+ skip = false;
+ }
+
+ @Override
+ public void doAction() throws Exception {
+
+ if (i18nable) {
+
+ List<URL> lUrls = new java.util.ArrayList<URL>();
+ List resources = project.getResources();
+ for (Object o : resources) {
+ Resource resource = (Resource) o;
+ lUrls.add(new File(resource.getDirectory()).toURI().toURL());
+ }
+ I18n.setExtraURL(lUrls.toArray(new URL[lUrls.size()]));
+ I18n.init(locale, null);
+ }
+
+ File file;
+
+ Properties env = new Properties();
+
+ env.put("helpSetName", helpSetName);
+ env.put("helpSetFileName", helpsetFileName);
+ env.put("mapFileName", mapFileName);
+ env.put("indexFileName", indexFileName);
+ env.put("tocFileName", tocFileName);
+ env.put("separator", " ");
+ env.put("autoremoveLine", AUTOREMOVE_LINE);
+
+
+ int touchedFiles = 0;
+
+ // ---------------------------------------------------------------
+ // --- main helpset file -----------------------------------------
+ // ---------------------------------------------------------------
+
+
+ file = new File(target, helpsetFileName);
+
+ boolean doCreate = generateHelSetFile(file, env);
+
+ if (doCreate) {
+ touchedFiles++;
+ }
+
+ // ---------------------------------------------------------------
+ // --- helpset map file ------------------------------------------
+ // ---------------------------------------------------------------
+
+ file = new File(target, mapFileName);
+
+ Properties mergedHelpIds = generateMapFile(file, env);
+ touchedFiles++;
+
+ // ---------------------------------------------------------------
+ // --- helpset index file ----------------------------------------
+ // ---------------------------------------------------------------
+
+ file = new File(target, indexFileName);
+
+ NodeItem indexRootItem = generateIndexFile(file, env);
+ touchedFiles++;
+
+ // ---------------------------------------------------------------
+ // --- helpset toc file ------------------------------------------
+ // ---------------------------------------------------------------
+
+ file = new File(target, tocFileName);
+
+ NodeItem tocRootItem = generateTocFile(file, env);
+ touchedFiles++;
+
+ // ---------------------------------------------------------------
+ // --- helpset content files -------------------------------------
+ // ---------------------------------------------------------------
+
+ TemplateGenerator gen = prepareGenerator(contentTemplate);
+
+ Enumeration keys = helpIds.keys();
+
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ String url = (String) helpIds.get(key);
+ url = helpSetName + File.separator + url;
+
+ File f = new File(target, url);
+
+ boolean exist = f.exists();
+
+ if (exist) {
+ // check if there is a autoremoveLine in content
+ String content = FileUtil.readAsString(f);
+ if (!content.contains(AUTOREMOVE_LINE)) {
+ // no regenerate marker detected, so skip this file
+ if (verbose) {
+ getLog().debug("skip existing file " + f);
+ }
+ continue;
+ }
+ }
+
+ f.getParentFile().mkdirs();
+
+ if (verbose) {
+ if (exist) {
+ getLog().info("regenerate content file " + f);
+ } else {
+ getLog().info("generate content file " + f);
+ }
+ }
+
+ env.put("helpId", key);
+ String i18n = helpsetI18nPrefix + key + helpsetTitleI18nSuffix;
+ env.put("helpIdTitle", _(i18n));
+ env.put("helpIdUrl", url);
+
+ gen.generate(env, f);
+ touchedFiles++;
+ }
+
+ // ---------------------------------------------------------------
+ // --- i18n file -------------------------------------------------
+ // ---------------------------------------------------------------
+
+ String path = packageName.replaceAll("\\.", File.separator);
+ path += File.separator + i8nFileName;
+ file = new File(outJava, path);
+ generateI18nFile(file, env, mergedHelpIds, indexRootItem, tocRootItem);
+ touchedFiles++;
+
+ getLog().info(touchedFiles + " file(s) treated.");
+ }
+
+ protected void generateI18nFile(File file, Properties env, Properties mergedHelpIds, NodeItem indexRootItem, NodeItem tocRootItem) throws Exception {
+
+ boolean create = !file.exists();
+
+ if (!file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+
+ Set<String> keys = new java.util.HashSet<String>();
+
+ for (Object k : mergedHelpIds.keySet()) {
+ String key = helpsetI18nPrefix + k + helpsetTitleI18nSuffix;
+ keys.add(key);
+ }
+ indexRootItem.extractI18n(keys, helpsetI18nPrefix, helpsetIndexI18nSuffix);
+ tocRootItem.extractI18n(keys, helpsetI18nPrefix, helpsetTocI18nSuffix);
+
+ env.put("keys", keys);
+ env.put("packageName", packageName);
+ String className = file.getName();
+ int index = className.lastIndexOf(".");
+ className = className.substring(0, index);
+ env.put("className", className);
+
+ if (verbose) {
+ if (create) {
+ getLog().info("generate i18n java file " + file);
+ } else {
+ getLog().info("udpate i18n java file " + file);
+ }
+ }
+
+ doGen(i18nTemplate, file, env);
+
+ }
+
+ protected boolean generateHelSetFile(File file, Properties env) throws Exception {
+
+ if (file.exists()) {
+ // check the auto removeline presence
+ String content = FileUtil.readAsString(file);
+ if (!content.contains(AUTOREMOVE_LINE)) {
+ // no regenerate marker detected, so skip this file
+ if (verbose) {
+ getLog().info("skip existing helpset main file " + file);
+ }
+ return false;
+ }
+ }
+
+ if (verbose) {
+ if (file.exists()) {
+ getLog().info("regenerate helpset main file " + file);
+ } else {
+ getLog().info("generate helpset main file " + file);
+ }
+ }
+ doGen(helpSetTemplate, file, env);
+ return true;
+ }
+
+ protected Properties generateMapFile(File file, Properties env) throws Exception {
+
+ boolean create;
+
+ Properties mergedHelpIds = null;
+ if (file.exists()) {
+
+ // get back the exisiting data and merge it with incoming ones
+
+ if (verbose) {
+ getLog().info("loading existing helpset map file " + file);
+ }
+
+ mergedHelpIds = getExistingHelpIds(file);
+ create = false;
+
+ } else {
+
+ mergedHelpIds = new SortedProperties();
+ create = true;
+ }
+
+ // inject new helpIds
+
+ for (Object k : helpIds.keySet()) {
+ mergedHelpIds.put(k, helpSetName + "/" + helpIds.get(k));
+ }
+
+ if (!mergedHelpIds.contains("top")) {
+ // on ajoute une entree vers le root du helpset
+
+ String topUrl = helpSetName + ".html";
+ helpIds.put("top", topUrl);
+ mergedHelpIds.put("top", helpSetName + "/" + topUrl);
+ if (verbose) {
+ getLog().debug("add top entry with url " + topUrl);
+ }
+ }
+
+ if (verbose) {
+ if (create) {
+ getLog().info("generate helpset map file " + file);
+ } else {
+ getLog().info("udpate helpset map file " + file);
+ }
+ }
+
+ env.put("helpIds", mergedHelpIds);
+ doGen(mapTemplate, file, env);
+ env.remove("helpIds");
+ return mergedHelpIds;
+ }
+
+ protected NodeItem generateIndexFile(File file, Properties env) throws Exception {
+ NodeItem rootItem = null;
+
+ boolean create;
+
+ if (file.exists()) {
+
+ create = false;
+
+ rootItem = getExistingItems("indexitem", file);
+ } else {
+ create = true;
+ }
+
+ if (rootItem == null) {
+ rootItem = new NodeItem("top", helpSetName);
+ }
+
+ // inject new index entries
+
+ for (Object k : helpIds.keySet()) {
+ NodeItem toc = rootItem.findChild(k + "");
+ if (verbose) {
+ getLog().debug("index " + k + " : " + toc);
+ }
+ }
+
+ //String prefix = helpsetI18nPrefix;
+ //String prefix = helpsetI18nPrefix + helpSetName + ".";
+ rootItem.applyI18n(helpsetI18nPrefix, helpsetIndexI18nSuffix);
+
+ if (verbose) {
+ if (create) {
+ getLog().info("generate helpset index file " + file);
+ } else {
+ getLog().info("udpate helpset index file " + file);
+ }
+ }
+
+ env.put("rootItem", rootItem);
+ doGen(indexTemplate, file, env);
+ env.remove("rootItem");
+ return rootItem;
+ }
+
+ protected NodeItem generateTocFile(File file, Properties env) throws Exception {
+ NodeItem rootItem = null;
+
+ boolean create;
+
+ if (file.exists()) {
+
+ create = false;
+
+ rootItem = getExistingItems("tocitem", file);
+ } else {
+ create = true;
+ }
+
+ if (rootItem == null) {
+ rootItem = new NodeItem("top", helpSetName);
+ }
+ // inject new toc entries
+
+ for (Object k : helpIds.keySet()) {
+ NodeItem toc = rootItem.findChild(k + "");
+ if (verbose) {
+ getLog().debug("toc " + k + " : " + toc);
+ }
+ }
+
+ //String prefix = helpsetI18nPrefix + helpSetName + ".";
+ rootItem.applyI18n(helpsetI18nPrefix, helpsetTocI18nSuffix);
+
+ if (verbose) {
+ if (create) {
+ getLog().info("generate helpset toc file " + file);
+ } else {
+ getLog().info("udpate helpset toc file " + file);
+ }
+ }
+
+ env.put("rootItem", rootItem);
+ doGen(tocTemplate, file, env);
+ env.remove("rootItem");
+ return rootItem;
+ }
+
+ protected void doGen(File template, File f, Properties env) throws Exception {
+ TemplateGenerator gen = prepareGenerator(template);
+ gen.generate(env, f);
+ }
+
+ protected TemplateGenerator prepareGenerator(File template) throws Exception {
+ URL templateURL = getTemplate(template);
+
+ if (verbose) {
+ getLog().info("using template " + templateURL);
+ }
+ TemplateGenerator gen = new TemplateGenerator(project, templateURL);
+ return gen;
+ }
+
+ protected URL getTemplate(File f) throws IOException {
+ URL r = null;
+ InputStream s = null;
+ if (f.exists()) {
+ r = f.toURI().toURL();
+ } else {
+ r = getClass().getResource(f.toString());
+ }
+ return r;
+ }
+
+ protected void checkResource(File f) throws MojoFailureException {
+ if (!f.exists()) {
+ // test in classPath
+ InputStream r = getClass().getResourceAsStream(f.toString());
+ if (r == null) {
+ throw new MojoFailureException("could not find ressource " + f);
+ }
+ }
+ }
+
+ protected Properties getExistingHelpIds(File file) throws SAXException, IOException {
+
+ final Properties result = new SortedProperties();
+
+ XMLReader parser = XMLReaderFactory.createXMLReader();
+
+ parser.setContentHandler(new ContentHandlerAdapter() {
+
+ String target;
+ String url;
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+ if ("mapID".equals(localName)) {
+ target = atts.getValue("target");
+ url = atts.getValue("url");
+ if (verbose) {
+ getLog().debug("detect map entry : " + target + " : " + url);
+ }
+ result.put(target, url);
+ }
+ }
+ });
+
+ InputStream s = new FileInputStream(file);
+ try {
+ parser.parse(new InputSource(s));
+ } finally {
+ s.close();
+ }
+ return result;
+ }
+
+ protected NodeItem getExistingItems(String tagName, File file) throws SAXException, IOException {
+
+ XMLReader parser = XMLReaderFactory.createXMLReader();
+ NodeItemHandler handler = new NodeItemHandler(tagName);
+
+ parser.setContentHandler(handler);
+
+ NodeItem rootItem = null;
+ InputStream s = new FileInputStream(file);
+ try {
+ parser.parse(new InputSource(s));
+ rootItem = handler.rootItem;
+ } finally {
+ s.close();
+ }
+ return rootItem;
+ }
+
+ static class NodeItemHandler extends ContentHandlerAdapter {
+
+ NodeItem rootItem;
+ NodeItem currentItem;
+ final Stack<NodeItem> stack;
+ final String tagName;
+
+ public NodeItemHandler(String tagName) {
+ this.tagName = tagName;
+ this.stack = new Stack<NodeItem>();
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ rootItem = new NodeItem("top", null);
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+ if (tagName.equals(localName)) {
+
+ String target = atts.getValue("target");
+ String text = atts.getValue("text");
+
+ // debut d'un item
+ if (currentItem == null) {
+ // premier item
+ if (rootItem.getTarget().equals(target)) {
+ // le premier item est bien top
+ //rootItem.setText(text);
+ currentItem = rootItem;
+ } else {
+ // le premier noeud n'est pas top
+ // en l'encapsule
+ stack.push(rootItem);
+ currentItem = new NodeItem(target, text);
+ rootItem.addChild(currentItem);
+ }
+ } else {
+ NodeItem newItem = new NodeItem(target, text);
+ currentItem.addChild(newItem);
+ currentItem = newItem;
+ }
+ currentItem.adjustTarget();
+ stack.push(currentItem);
+
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ if (tagName.equals(localName)) {
+ // fin d'un item
+ stack.pop();
+ if (!stack.isEmpty()) {
+ currentItem = stack.peek();
+ }
+ }
+ }
+ }
+
+ static class ContentHandlerAdapter implements ContentHandler {
+
+ @Override
+ public void setDocumentLocator(Locator locator) {
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ }
+
+ @Override
+ public void endDocument() throws SAXException {
+ }
+
+ @Override
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ }
+
+ @Override
+ public void endPrefixMapping(String prefix) throws SAXException {
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ }
+
+ @Override
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+ }
+
+ @Override
+ public void processingInstruction(String target, String data) throws SAXException {
+ }
+
+ @Override
+ public void skippedEntity(String name) throws SAXException {
+ }
+ }
+}
\ No newline at end of file
Added: jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/NodeItem.java
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/NodeItem.java (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/NodeItem.java 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,137 @@
+package org.codelutin.jaxx;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import static org.codelutin.i18n.I18n._;
+
+public class NodeItem {
+
+ String absoluteTarget;
+ private String target;
+ private String text;
+ private List<NodeItem> childs;
+
+ public NodeItem(String target, String text) {
+ this.target = target;
+ this.absoluteTarget = target;
+
+ this.text = text;
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+ public String getAbsoluteTarget() {
+ return absoluteTarget;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public List<NodeItem> getChilds() {
+ return childs;
+ }
+
+ public NodeItem findChild(String path) {
+ NodeItem result = null;
+ String[] paths = path.split("\\.");
+ for (int i = 0, j = paths.length; i < j; i++) {
+ String p = paths[i];
+ if (result == null) {
+
+ // first node
+ if (target.equals(p)) {
+ result = this;
+ continue;
+ }
+ result = getChild(p);
+ if (result == null) {
+ result = new NodeItem(p, null);
+ addChild(result);
+ adjutsAbsoluteTarget(result);
+ }
+ continue;
+ }
+ NodeItem child = result.getChild(p);
+ if (child == null) {
+ child = new NodeItem(p, null);
+ result.addChild(child);
+ result.adjutsAbsoluteTarget(child);
+ result = child;
+ } else {
+ result = child;
+ }
+ }
+ return result;
+ }
+
+ public NodeItem getChild(int index) {
+ return childs.get(index);
+ }
+
+ public NodeItem getChild(String target) {
+ if (isLeaf()) {
+ return null;
+ }
+ for (NodeItem i : childs) {
+ if (i.target.equals(target)) {
+ return i;
+ }
+ }
+ return null;
+ }
+
+ public void addChild(NodeItem child) {
+ if (childs == null) {
+ childs = new ArrayList<NodeItem>();
+ }
+
+ childs.add(child);
+ }
+
+ public void adjutsAbsoluteTarget(NodeItem child) {
+ if (!"top".equals(target)) {
+ // on ne prefixe pas les fils direct du root
+ child.absoluteTarget = absoluteTarget + "." + child.target;
+ }
+ }
+
+ public void adjustTarget() {
+ int index = target.lastIndexOf(".");
+ if (index > -1) {
+ target = target.substring(index + 1);
+ }
+ }
+
+ public boolean isLeaf() {
+ return childs == null || childs.isEmpty();
+ }
+
+ public void applyI18n(String prefix, String suffix) {
+ String key = prefix + getAbsoluteTarget() + suffix;
+ text = _(key);
+ if (!isLeaf()) {
+ for (NodeItem i : getChilds()) {
+ i.applyI18n(prefix, suffix);
+ }
+ }
+ }
+
+ public void extractI18n(Set<String> keys, String prefix, String suffix) {
+ String key = prefix + getAbsoluteTarget() + suffix;
+ keys.add(key);
+ if (!isLeaf()) {
+ for (NodeItem i : getChilds()) {
+ i.extractI18n(keys, prefix, suffix);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "<target:" + target + ", text:" + text + ", nbChilds:" + (isLeaf() ? 0 : childs.size()) + ">";
+ }
+}
Added: jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/TemplateGenerator.java
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/TemplateGenerator.java (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/TemplateGenerator.java 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License" );
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.codelutin.jaxx;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.maven.project.MavenProject;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+
+/**
+ * Generator of template base on velocity.
+ *
+ * @author chemit
+ * @since 1.3
+ *
+ */
+public class TemplateGenerator {
+
+ protected VelocityEngine engine;
+ protected final MavenProject mavenProject;
+ protected Template velocityTemplate;
+
+ protected TemplateGenerator(MavenProject mavenProject, URL template) throws URISyntaxException {
+
+ if (mavenProject == null) {
+ throw new IllegalArgumentException("mavenProject must not be null");
+ }
+
+ if (template == null) {
+ throw new IllegalArgumentException("template must not be null");
+ }
+
+ this.mavenProject = mavenProject;
+
+ Properties props = new Properties();
+
+ String templateName;
+
+ if (template.toURI().isOpaque()) {
+
+ // template is in a jar
+
+ props = new Properties();
+ props.setProperty("resource.loader", "jar");
+ props.setProperty("jar.resource.loader.description", "Jar resource loader for default webstart templates");
+ props.setProperty("jar.resource.loader.class", "org.apache.velocity.runtime.resource.loader.JarResourceLoader");
+
+ // obtain the jar url
+
+ String url = template.toString();
+ int i = url.indexOf("!");
+ templateName = url.substring(i + 2);
+
+ props.setProperty("jar.resource.loader.path", url.substring(0, i + 2));
+
+ } else {
+
+
+ templateName = new File(template.getFile()).getName();
+
+ //props.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogSystem");
+ props.setProperty("file.resource.loader.path", template.getFile());
+
+ }
+
+ try {
+ engine = new VelocityEngine();
+ //engine.setProperty("runtime.log.logsystem", new NullLogSystem());
+ engine.init(props);
+ } catch (Exception e) {
+ IllegalArgumentException iae = new IllegalArgumentException("Could not initialise Velocity");
+ iae.initCause(e);
+ throw iae;
+ }
+
+ try {
+ this.velocityTemplate = engine.getTemplate(templateName);
+ } catch (Exception e) {
+ IllegalArgumentException iae =
+ new IllegalArgumentException("Could not load the template file from '" + template + "'");
+ iae.initCause(e);
+ throw iae;
+ }
+ }
+
+ public void generate(Properties context, File outputFile) throws Exception {
+
+
+ VelocityContext vcontext = new VelocityContext();
+
+ // Note: properties that contain dots will not be properly parsed by Velocity. Should we replace dots with underscores ?
+ addPropertiesToContext(System.getProperties(), vcontext);
+
+ addPropertiesToContext(mavenProject.getProperties(), vcontext);
+ addPropertiesToContext(context, vcontext);
+
+ vcontext.put("project", mavenProject.getModel());
+
+ vcontext.put("outputFile", outputFile.getName());
+
+ FileWriter writer = new FileWriter(outputFile);
+
+ try {
+ velocityTemplate.merge(vcontext, writer);
+ writer.flush();
+ } catch (Exception e) {
+ throw new Exception("Could not generate the template " + velocityTemplate.getName() + ": " + e.getMessage(), e);
+ } finally {
+ writer.close();
+ }
+ }
+
+ protected void addPropertiesToContext(Properties properties, VelocityContext context) {
+
+ for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
+ String key = (String) iter.next();
+ Object value = properties.get(key);
+ context.put(key, value);
+ }
+
+ }
+}
Added: jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultContent.html.vm
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultContent.html.vm (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultContent.html.vm 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<HTML>
+<HEAD>
+<TITLE>
+$helpIdTitle
+</TITLE>
+</HEAD>
+<BODY BGCOLOR="#ffffff">
+<H1>$helpIdTitle</H1>
+
+<!-- $autoremoveLine -->
+
+</BODY>
+</HTML>
Added: jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultHelpSet.hs.vm 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,44 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE helpset
+ PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN"
+ "http://java.sun.com/products/javahelp/helpset_1_0.dtd">
+
+<helpset version="1.0">
+
+ <!-- $autoremoveLine -->
+
+ <!-- title -->
+ <title>${helpSetTitle}</title>
+
+ <!-- maps -->
+ <maps>
+ <homeID>top</homeID>
+ <mapref location="$mapFileName"/>
+ </maps>
+
+ <!-- views -->
+ <view>
+ <name>TOC</name>
+ <label>Table Of Contents</label>
+ <type>javax.help.TOCView</type>
+ <data>$tocFileName</data>
+ </view>
+
+ <view>
+ <name>Index</name>
+ <label>Index</label>
+ <type>javax.help.IndexView</type>
+ <data>$indexFileName</data>
+ </view>
+
+#if ( $!searchData != "" )
+ <view>
+ <name>Search</name>
+ <label>Search</label>
+ <type>javax.help.SearchView</type>
+ <data engine="com.sun.java.help.search.DefaultSearchEngine">
+ $searchData
+ </data>
+ </view>
+#end
+</helpset>
Added: jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultI18n.java.vm
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultI18n.java.vm (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultI18n.java.vm 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,16 @@
+package $packageName;
+
+$!commentaire
+public class $className { // $className
+
+{
+// BEGIN DO NOT REMOVE : used to detect helper i18n keys
+//
+#foreach( $key in $keys )
+// _("$key");
+#end
+//
+// END DO NOT REMOVE : used to detect helper i18n keys
+}
+
+} // $className
\ No newline at end of file
Added: jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultIndex.xml.vm
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultIndex.xml.vm (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultIndex.xml.vm 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,21 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE index
+ PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Index Version 1.0//EN"
+ "http://buix.labs.libre-entreprise.org/javahelp/index_1_0.dtd">
+
+## pour afficher un org.codelutin.jaxx.NodeItem
+#macro ( renderItem $item $prefix )
+#if ( $item.isLeaf() )
+$prefix<indexitem target="$item.absoluteTarget" text="$!item.text"/>
+#else
+$prefix<indexitem target="$item.absoluteTarget" text="$!item.text">
+#foreach( $child in $item.getChilds() )
+#renderItem( $child "$prefix$separator" )
+#end
+$prefix</indexitem>
+#end
+#end
+
+<index version="1.0">
+#renderItem( $rootItem $separator )
+</index>
Added: jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultMap.jhm.vm
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultMap.jhm.vm (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultMap.jhm.vm 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,16 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE map
+ PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN"
+ "http://java.sun.com/products/javahelp/map_1_0.dtd">
+<map version="1.0">
+
+#if ( !$helpIds.get("toplevelfolder"))
+ <!-- use this entry to go up in navigation -->
+ <!--mapID target="toplevelfolder" url="images/toplevel.gif" /-->
+#end
+
+#foreach( $key in $helpIds.keys() )
+ <mapID target="$key" url="$helpIds.get($key)" />
+#end
+
+</map>
Added: jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultToc.xml.vm
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultToc.xml.vm (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/resources/defaultToc.xml.vm 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,20 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE toc
+ PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN"
+ "http://buix.labs.libre-entreprise.org/javahelp/toc_1_0.dtd">
+
+## pour afficher un org.codelutin.jaxx.NodeItem
+#macro ( renderItem $item $prefix )
+#if ( $item.isLeaf() )
+$prefix<tocitem target="$item.absoluteTarget" text="$!item.text"/>
+#else
+$prefix<tocitem target="$item.absoluteTarget" text="$!item.text">
+#foreach( $child in $item.getChilds() )
+#renderItem( $child "$prefix$separator" )
+#end
+$prefix</tocitem>
+#end
+#end
+<toc version="1.0">
+#renderItem( $rootItem $separator )
+</toc>
Modified: jaxx/trunk/maven-jaxx-plugin/src/main/resources/log4j.properties
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/resources/log4j.properties 2009-03-29 13:36:21 UTC (rev 1280)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/resources/log4j.properties 2009-03-29 13:36:44 UTC (rev 1281)
@@ -5,5 +5,5 @@
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
-#log4j.logger.org.codelutin.jaxx=DEBUG
+log4j.logger.org.codelutin.i18n=ERROR
#log4j.logger.jaxx=DEBUG
Added: jaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/NodeItemTest.java
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/NodeItemTest.java (rev 0)
+++ jaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/NodeItemTest.java 2009-03-29 13:36:44 UTC (rev 1281)
@@ -0,0 +1,54 @@
+package org.codelutin.jaxx;
+
+import org.junit.Assert;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author tony
+ */
+public class NodeItemTest {
+
+ @Test
+ public void testFindChild() {
+ System.out.println("findChild");
+ String path = "a";
+ NodeItem instance = new NodeItem("a", "rootItem text");
+ NodeItem expResult = new NodeItem("a", "rootItem text");
+ NodeItem result = instance.findChild(path);
+ assertTocItemEquals(expResult, result);
+
+ path = "a.b";
+ expResult = new NodeItem("b", null);
+ result = instance.findChild(path);
+ assertTocItemEquals(expResult, result);
+ assertTrue(instance.getChild("b") == result);
+ assertTrue(instance.findChild("b") == result);
+
+ NodeItem b = result;
+
+ path = "ab";
+ expResult = new NodeItem("ab", null);
+ result = instance.findChild(path);
+ assertTocItemEquals(expResult, result);
+ assertTrue(instance.getChild("ab") == result);
+ assertTrue(instance.findChild("ab") == result);
+
+ path = "a.b.cd";
+ expResult = new NodeItem("cd", null);
+ result = instance.findChild(path);
+ assertTocItemEquals(expResult, result);
+ assertTrue(b.getChild("cd") == result);
+ assertTrue(b.findChild("b.cd") == result);
+ assertTrue(b.findChild("cd") == result);
+ assertTrue(instance.findChild("b.cd") == result);
+ assertTrue(instance.findChild("a.b.cd") == result);
+ }
+
+ protected void assertTocItemEquals(NodeItem t, NodeItem t2) {
+ Assert.assertEquals(t.getTarget(), t2.getTarget());
+ Assert.assertEquals(t.getText(), t2.getText());
+
+ }
+}
\ No newline at end of file
1
0
[Buix-commits] r1280 - in jaxx/trunk: . jaxx-compiler-api jaxx-compiler-api/src/main/java/jaxx/compiler jaxx-compiler-api/src/main/java/jaxx/tags jaxx-compiler-swing jaxx-compiler-swing/src/main/java/jaxx jaxx-compiler-swing/src/main/java/jaxx/compiler jaxx-runtime-swing jaxx-runtime-swing/src/main/java/jaxx/runtime jaxx-runtime-swing/src/main/java/jaxx/runtime/swing
by tchemit@users.labs.libre-entreprise.org 29 Mar '09
by tchemit@users.labs.libre-entreprise.org 29 Mar '09
29 Mar '09
Author: tchemit
Date: 2009-03-29 13:36:21 +0000 (Sun, 29 Mar 2009)
New Revision: 1280
Added:
jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/compiler/HelpRootCompiledObjectDecorator.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/JaxxHelpUI.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java
Modified:
jaxx/trunk/changelog.txt
jaxx/trunk/jaxx-compiler-api/changelog.txt
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompiledObject.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompilerOptions.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/DefaultCompiledObjectDecorator.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java
jaxx/trunk/jaxx-compiler-swing/changelog.txt
jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/SwingInitializer.java
jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/compiler/BoxedCompiledObjectDecorator.java
jaxx/trunk/jaxx-runtime-swing/changelog.txt
Log:
add generate-help goal
Modified: jaxx/trunk/changelog.txt
===================================================================
--- jaxx/trunk/changelog.txt 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/changelog.txt 2009-03-29 13:36:21 UTC (rev 1280)
@@ -1,4 +1,5 @@
1.3 chemit 20090320
+ * 20090329 [chemit] - add java help mojo
* 20090313 [chemit] - use i18n 0.10
1.2 ??? 2009????
Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-29 13:36:21 UTC (rev 1280)
@@ -1,4 +1,7 @@
1.3 chemit 20090321
+ * 20090327 [chemit] - refactor clientProperties (no more generation in handler but in decorator)
+ - add javax help mecanism
+
* 20090321 [chemit] - add compilerCount in launchro to known how mush files where generated
* 20090313 [chemit] - can now use geneticType on javaBean object
- add an extra method $afterCompleteSetup method to be included if find in script at last statement of $completeSetup method
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompiledObject.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompiledObject.java 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompiledObject.java 2009-03-29 13:36:21 UTC (rev 1280)
@@ -72,6 +72,10 @@
* the decorator (if null will use {@link DefaultCompiledObjectDecorator}).
*/
private CompiledObjectDecorator decorator;
+ /**
+ * client properties
+ */
+ private Map<String,String> clientProperties;
public class ChildRef {
@@ -433,6 +437,29 @@
properties.put(property, value);
}
+ public boolean hasClientProperties() {
+ return clientProperties != null && !clientProperties.isEmpty();
+ }
+
+ public void addClientProperty(String property, String value) {
+ getClientProperties().put(property, value);
+ }
+
+ public String getClientProperty(String key) {
+ if (!hasClientProperties()) {
+ return null;
+ }
+ return clientProperties.get(key);
+ }
+
+ public Map<String, String> getClientProperties() {
+ if (clientProperties == null) {
+ clientProperties = new HashMap<String, String>();
+ }
+ return clientProperties;
+ }
+
+
/**
* Returns all properties which have been set for this object.
*
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompilerOptions.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompilerOptions.java 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompilerOptions.java 2009-03-29 13:36:21 UTC (rev 1280)
@@ -44,6 +44,40 @@
/** a flag to use {@link javax.swing.UIManager} to retreave icons. */
private boolean useUIManagerForIcon;
+ /** a flag to generate javax help for any */
+ private boolean generateHelp;
+
+ private String helpBrokerFQN;
+ /**
+ * The prefix to add to i18n key for any help i18n key.
+ *
+ * @since 1.3
+ */
+ protected String helpsetI18nPrefix;
+ /**
+ * The suffix to add to i18n key for an help Id.
+ *
+ * @since 1.3
+ */
+ protected String helpsetTitleI18nSuffix;
+ /**
+ * The suffix to add to i18n key for an toc Id.
+ *
+ * @since 1.3
+ */
+ protected String helpsetTocI18nSuffix;
+ /**
+ * The suffix to add to i18n key for an toc Id.
+ *
+ * @since 1.3
+ */
+ protected String helpsetIndexI18nSuffix;
+ /**
+ * The helpset name
+ *
+ * @since 1.3
+ */
+ protected String helpSetName;
/** the default compiled object decorator to use if none specifed via decorator attribute */
private Class<? extends CompiledObjectDecorator> defaultDecoratorClass;
@@ -291,5 +325,61 @@
this.profile = profile;
}
+ public boolean isGenerateHelp() {
+ return generateHelp;
+ }
+
+ public void setGenerateHelp(boolean generateHelp) {
+ this.generateHelp = generateHelp;
+ }
+
+ public String getHelpBrokerFQN() {
+ return helpBrokerFQN;
+ }
+
+ public void setHelpBrokerFQN(String helpBrokerFQN) {
+ this.helpBrokerFQN = helpBrokerFQN;
+ }
+
+ public String getHelpsetIndexI18nSuffix() {
+ return helpsetIndexI18nSuffix;
+ }
+
+ public void setHelpsetIndexI18nSuffix(String helpsetIndexI18nSuffix) {
+ this.helpsetIndexI18nSuffix = helpsetIndexI18nSuffix;
+ }
+
+ public String getHelpsetTitleI18nSuffix() {
+ return helpsetTitleI18nSuffix;
+ }
+
+ public void setHelpsetTitleI18nSuffix(String helpsetTitleI18nSuffix) {
+ this.helpsetTitleI18nSuffix = helpsetTitleI18nSuffix;
+ }
+
+ public String getHelpsetTocI18nSuffix() {
+ return helpsetTocI18nSuffix;
+ }
+
+ public void setHelpsetTocI18nSuffix(String helpsetTocI18nSuffix) {
+ this.helpsetTocI18nSuffix = helpsetTocI18nSuffix;
+ }
+
+ public String getHelpSetName() {
+ return helpSetName;
+ }
+
+ public void setHelpSetName(String helpSetName) {
+ this.helpSetName = helpSetName;
+ }
+
+ public String getHelpsetI18nPrefix() {
+ return helpsetI18nPrefix;
+ }
+
+ public void setHelpsetI18nPrefix(String helpsetI18nPrefix) {
+ this.helpsetI18nPrefix = helpsetI18nPrefix;
+ }
+
}
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/DefaultCompiledObjectDecorator.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/DefaultCompiledObjectDecorator.java 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/DefaultCompiledObjectDecorator.java 2009-03-29 13:36:21 UTC (rev 1280)
@@ -5,6 +5,7 @@
package jaxx.compiler;
import java.lang.reflect.Modifier;
+import java.util.Map.Entry;
import jaxx.CompilerException;
import jaxx.types.TypeManager;
@@ -75,10 +76,18 @@
@Override
public String createCompleteSetupMethod(JAXXCompiler compiler, CompiledObject object, JavaFile javaFile, StringBuffer initDataBindings) {
StringBuffer code = new StringBuffer();
+ //TC-20090327 generate client properties
+ if (object.hasClientProperties()) {
+ // generate putClientProperty invocations
+ for (Entry<String,String> entry : object.getClientProperties().entrySet()) {
+ object.appendAdditionCode(object.getJavaCode() + ".putClientProperty(\"" + entry.getKey() + "\", " + entry.getValue() + ");");
+ }
+
+ }
//TC - 20081017 only generate the method if not empty ?
if (object.getId().startsWith("$")) {
code.append(object.getAdditionCode()).append(JAXXCompiler.getLineSeparator());
- } else {
+ } else {
String additionCode = object.getAdditionCode();
if (additionCode.length() > 0) {
code.append(object.getAdditionMethodName()).append("();").append(JAXXCompiler.getLineSeparator());
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java 2009-03-29 13:36:21 UTC (rev 1280)
@@ -204,7 +204,9 @@
if (stringValue.startsWith("{")) {
stringValue = stringValue.substring(1, stringValue.length() - 1);
}
- object.appendAdditionCode(object.getJavaCode() + ".putClientProperty(\"" + propertyName.substring(1) + "\", " + stringValue + ");");
+ object.addClientProperty(propertyName.substring(1), stringValue);
+ //TC-20090327 rather not generating code here
+ //object.appendAdditionCode(object.getJavaCode() + ".putClientProperty(\"" + propertyName.substring(1) + "\", " + stringValue + ");");
return;
}
if ("icon".equals(propertyName)) {
Modified: jaxx/trunk/jaxx-compiler-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-swing/changelog.txt 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/jaxx-compiler-swing/changelog.txt 2009-03-29 13:36:21 UTC (rev 1280)
@@ -1,6 +1,7 @@
1.3 chemit 20090320
+ * 20090327 [chemit] - introduce javax help decorator
-1.1 chemit 20090220
+1.1 chemit 20090220
* 20090122 [chemit] - refactor poms (sibling dependencies, pluginsManagment,...)
1.0 chemit 20090111
Modified: jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/SwingInitializer.java
===================================================================
--- jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/SwingInitializer.java 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/SwingInitializer.java 2009-03-29 13:36:21 UTC (rev 1280)
@@ -31,6 +31,7 @@
import java.awt.Insets;
import jaxx.compiler.BoxedCompiledObjectDecorator;
import jaxx.compiler.CompiledObjectDecorator;
+import jaxx.compiler.HelpRootCompiledObjectDecorator;
public class SwingInitializer implements Initializer {
@@ -89,5 +90,6 @@
TypeManager.registerTypeConverter(KeyStroke.class, new KeyStrokeConverter());
CompiledObjectDecorator.registerDecorator("boxed", BoxedCompiledObjectDecorator.class);
+ CompiledObjectDecorator.registerDecorator("help", HelpRootCompiledObjectDecorator.class);
}
}
\ No newline at end of file
Modified: jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/compiler/BoxedCompiledObjectDecorator.java
===================================================================
--- jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/compiler/BoxedCompiledObjectDecorator.java 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/compiler/BoxedCompiledObjectDecorator.java 2009-03-29 13:36:21 UTC (rev 1280)
@@ -1,6 +1,7 @@
package jaxx.compiler;
import jaxx.compiler.CompiledObject.ChildRef;
+import jaxx.runtime.SwingUtil;
/**
* A decorator to surround a compiled object (should be a component at least)
@@ -17,7 +18,7 @@
for (ChildRef child : parent.getChilds()) {
if (child.getChild() == object) {
String javaCode = child.getChildJavaCode();
- child.setChildJavaCode("jaxx.runtime.SwingUtil.boxComponentWithJxLayer(" + javaCode + ")");
+ child.setChildJavaCode(SwingUtil.class.getName()+".boxComponentWithJxLayer(" + javaCode + ")");
break;
}
}
Added: jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/compiler/HelpRootCompiledObjectDecorator.java
===================================================================
--- jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/compiler/HelpRootCompiledObjectDecorator.java (rev 0)
+++ jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/compiler/HelpRootCompiledObjectDecorator.java 2009-03-29 13:36:21 UTC (rev 1280)
@@ -0,0 +1,93 @@
+package jaxx.compiler;
+
+import java.lang.reflect.Modifier;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A decorator to place on a root compiled object to process javaHelp on the file.
+ *
+ * @author tony
+ * @since 1.2
+ */
+public class HelpRootCompiledObjectDecorator extends DefaultCompiledObjectDecorator {
+
+ /**
+ * the list of discovered helpId
+ */
+ protected static Set<String> helpIds = new java.util.HashSet<String>();
+
+ protected String getBrokerFQN(JAXXCompiler compiler) {
+ String helpBrokerFQN = compiler.getOptions().getHelpBrokerFQN();
+ return helpBrokerFQN;
+ }
+
+ protected String getHelpId(CompiledObject o) {
+ String helpID = null;
+ if (o.hasClientProperties()) {
+ helpID = o.getClientProperty("help");
+ }
+ return helpID;
+ }
+
+ @Override
+ public void finalizeCompiler(JAXXCompiler compiler, CompiledObject root, CompiledObject object, JavaFile javaFile, String packageName, String className, String fullClassName) {
+ super.finalizeCompiler(compiler, root, object, javaFile, packageName, className, fullClassName);
+ CompilerOptions options = compiler.getOptions();
+
+ if (options.isGenerateHelp()) {
+
+ // add JaxxHelpUI interface
+ Class<?> validatorInterface = jaxx.runtime.JaxxHelpUI.class;
+ String helpBrokerFQN = getBrokerFQN(compiler);
+ javaFile.addInterface(JAXXCompiler.getCanonicalName(validatorInterface) + "<" + helpBrokerFQN + ">");
+
+ javaFile.addMethod(JavaMethod.newMethod(Modifier.PUBLIC, "void", "registerHelpId",
+ "broker.installUI(component, helpId);",
+ new JavaArgument(helpBrokerFQN, "broker"),
+ new JavaArgument("Component", "component"),
+ new JavaArgument("String", "helpId")));
+
+ javaFile.addMethod(JavaMethod.newMethod(Modifier.PUBLIC, "void", "showHelp",
+ "getBroker().showHelp(this, helpId);",
+ new JavaArgument("String", "helpId")));
+
+ StringBuilder buffer = new StringBuilder();
+
+ String lineSeparator = JAXXCompiler.getLineSeparator();
+
+ if (options.isGenerateHelp()) {
+
+ // add code to init javax help system
+ Iterator<CompiledObject> itr = compiler.getObjectCreationOrder();
+
+ for (; itr.hasNext();) {
+ CompiledObject o = itr.next();
+ String helpID = getHelpId(o);
+ if (helpID != null) {
+ buffer.append(lineSeparator);
+ // detects a helpId to register
+ buffer.append("registerHelpId(_broker, " + o.getJavaCode() + ", " + helpID + ");");
+ //keep the helpID for helpSet generation
+ helpIds.add(helpID);
+ }
+ }
+ }
+ if (buffer.length() > 0) {
+
+ StringBuilder extraCode = new StringBuilder(helpBrokerFQN).append(" _broker = getBroker();");
+
+ buffer.append(lineSeparator).append("_broker.prepareUI(this);");
+ buffer.append(lineSeparator);
+
+ // add the calls
+ compiler.appendLateInitializer(extraCode.toString());
+ compiler.appendLateInitializer(buffer.toString());
+ }
+ }
+ }
+
+ public static Set<String> getHelpIds() {
+ return helpIds;
+ }
+}
Modified: jaxx/trunk/jaxx-runtime-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-24 14:37:47 UTC (rev 1279)
+++ jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-29 13:36:21 UTC (rev 1280)
@@ -1,4 +1,5 @@
1.3 chemit 20090321
+ * 20090327 [chemit] - add javax help mecanism
* 20090318 [chemit] - introduce the BlockingLayerUI2 class (should be merge with BlockingLayerUI)
* 20090318 [chemit] - introduce the CardLayout2Ext class
* 20090312 [chemit] - add some usefull code from ObServe (load Nimbus L&F, load ui configuration)
Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/JaxxHelpUI.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/JaxxHelpUI.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/JaxxHelpUI.java 2009-03-29 13:36:21 UTC (rev 1280)
@@ -0,0 +1,23 @@
+package jaxx.runtime;
+
+import java.awt.Component;
+import jaxx.runtime.swing.JaxxHelpBroker;
+
+/**
+ *
+ * Contract to be added on JAXXObject wihch wants to use javax help.
+ *
+ * @param <B> type of broker.
+ *
+ * @author tony
+ * @since 1.3
+ * @see JaxxHelpBroker
+ */
+public interface JaxxHelpUI<B extends JaxxHelpBroker> {
+
+ B getBroker();
+
+ void registerHelpId(B broker, Component component, String helpId);
+
+ void showHelp(String helpId);
+}
Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java 2009-03-29 13:36:21 UTC (rev 1280)
@@ -0,0 +1,510 @@
+package jaxx.runtime.swing;
+
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.event.ActionListener;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+import javax.help.CSH;
+import javax.help.CSH.DisplayHelpFromSource;
+import javax.help.HelpBroker;
+import javax.help.HelpSet;
+import javax.swing.AbstractButton;
+import javax.swing.JComponent;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * La classe pour encapsuler l'aide de l'application.
+ *
+ * @param <B> le type de broker
+ * @author tony
+ * @since 1.4
+ */
+public abstract class JaxxHelpBroker<B extends JaxxHelpBroker> {
+
+ public static final String JAXX_CONTEXT_ENTRY = "jaxxcontext";
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(JaxxHelpBroker.class);
+ protected final String helpsetName;
+ protected final String defaultID;
+ protected final String helpKey;
+ // Main HelpSet & Broker
+ protected final HelpSet helpset;
+ protected final HelpBroker helpBroker;
+ protected ActionListener showHelpAction;
+ protected Hashtable<Component, Cursor> cursors;
+ protected Cursor onItemCursor;
+
+ protected JaxxHelpBroker(String helpsetName, String helpKey, String defaultID) {
+ if (helpsetName == null) {
+ throw new NullPointerException("parameter helpsetName can not be null!");
+ }
+ this.helpsetName = helpsetName;
+ this.helpKey = helpKey;
+ this.defaultID = defaultID;
+ try {
+ ClassLoader cl = getClass().getClassLoader();
+ URL url = HelpSet.findHelpSet(cl, helpsetName);
+ helpset = new HelpSet(cl, url);
+ helpBroker = helpset.createHelpBroker();
+ } catch (Exception ee) {
+ throw new IllegalStateException("could not find help set " + helpsetName + " for reason " + ee.getMessage(), ee);
+ }
+ }
+
+ public AbstractButton getShowHelperButton(JAXXObject c) {
+ return (AbstractButton) c.getObjectById("showHelp");
+ }
+
+ public void prepareUI(JAXXObject c) {
+ if (c == null) {
+ throw new NullPointerException("parameter c can not be null!");
+ }
+
+ // l'ui doit avoir un boutton showHelp
+ AbstractButton help = getShowHelperButton(c);
+
+ if (help == null) {
+ log.warn("no showButton detected for " + c.getClass());
+ } else {
+ boolean needListener = true;
+ for (ActionListener a : help.getActionListeners()) {
+ if (a instanceof DisplayHelpFromSource) {
+ needListener = false;
+ break;
+ }
+ }
+ if (needListener) {
+ // attach context to button
+ help.putClientProperty(JAXX_CONTEXT_ENTRY, c.getDelegateContext());
+ help.addActionListener(getShowHelpAction(c));
+ }
+
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("for " + c);
+ }
+
+ //installUI(c, new java.util.ArrayList<String>());
+ }
+
+ public HelpBroker getHelpBroker() {
+ return helpBroker;
+ }
+
+ public String getHelpKey() {
+ return helpKey;
+ }
+
+ public HelpSet getHelpset() {
+ return helpset;
+ }
+
+ public String getHelpsetName() {
+ return helpsetName;
+ }
+
+ public String getDefaultID() {
+ return defaultID;
+ }
+
+ public void showHelpSet() {
+ log.info(this);
+ new CSH.DisplayHelpFromSource(helpBroker);
+ }
+
+ public void showHelp(JAXXContext context, String helpId) {
+ }
+
+ public void installUI(Component comp, String helpId) {
+ CSH.setHelpIDString(comp, helpId);
+ }
+
+ protected void installUI(Object comp, List<String> scanned) {
+ //log.info(comp);
+ if (comp instanceof JComponent) {
+ JComponent c = (JComponent) comp;
+ if (scanned.contains(c.getName())) {
+ return;
+ } else {
+ scanned.add(c.getName());
+ }
+ Object id = c.getClientProperty(helpKey);
+ if (id != null && id instanceof String) {
+ String helpId = (String) id;
+
+ CSH.setHelpIDString(c, helpId);
+
+ log.info(c.getName() + " : " + helpId);
+
+ if (log.isDebugEnabled()) {
+ log.debug(c.getName() + " : " + helpId);
+
+ }
+ }
+ }
+
+ if (comp instanceof JAXXObject) {
+ JAXXObject jo = (JAXXObject) comp;
+
+
+ Map<String, Object> $objectMap = jo.get$objectMap();
+ for (String key : $objectMap.keySet()) {
+
+ if (scanned.contains(key)) {
+ continue;
+ }
+
+ Object o = $objectMap.get(key);
+
+ if (o == comp) {
+ continue;
+ }
+
+ if (o instanceof JAXXObject) {
+ installUI(o, scanned);
+ scanned.add(key);
+ continue;
+ }
+ if (o instanceof JComponent) {
+ installUI(o, scanned);
+ continue;
+ }
+ }
+ }
+ }
+
+ protected ActionListener getShowHelpAction(JAXXContext context) {
+ if (showHelpAction == null) {
+ showHelpAction = addShowHelpAction(context);
+ }
+ return showHelpAction;
+ }
+
+ protected ActionListener addShowHelpAction(JAXXContext context) {
+ return new CSH.DisplayHelpAfterTracking(helpBroker);
+ }
+
+ protected String getHelpID(Component source) {
+ String helpID = null;
+
+ // It is necessery for UIManager.get("HelpOnItemCursor");
+
+ // Get the onItemCursor
+ onItemCursor = (Cursor) UIManager.get("HelpOnItemCursor");
+ if (onItemCursor == null) {
+ return null;
+ }
+
+ // change all the cursors on all windows
+ Vector topComponents = null;
+ cursors = null;
+
+ if (onItemCursor != null) {
+ cursors = new Hashtable<Component, Cursor>();
+ topComponents = getTopContainers(source);
+ Enumeration enums = topComponents.elements();
+ while (enums.hasMoreElements()) {
+ setAndStoreCursors((Container) enums.nextElement(), onItemCursor);
+ }
+ }
+ /*MouseEvent event = getMouseEvent();
+
+ if (event != null) {
+ Component comp = (Component)event.getSource();
+ log.info("component traking!!!!!!!! " + comp.getName()+" : "+comp.getClass().getName());
+ }*/
+
+
+ Object o = CSH.trackCSEvents();
+
+ if (o instanceof Component) {
+
+ helpID = CSH.getHelpIDString((Component) o);
+
+ log.info("component traking " + ((Component) o).getName() + " : " + helpID);
+
+ if (log.isDebugEnabled()) {
+ log.debug("component traking " + ((Component) o).getName() + " : " + helpID);
+ }
+ }
+
+ /*HelpSet objHS = getHelpset();
+ try {
+ ID id = ID.create(helpID, objHS);
+ if (id == null) {
+ id = objHS.getHomeID();
+ }
+
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ }
+ if (helpID == null) {
+ helpID = getDefaultID();
+ }*/
+
+ // restore the old cursors
+ if (topComponents != null) {
+ Enumeration containers = topComponents.elements();
+ while (containers.hasMoreElements()) {
+ resetAndRestoreCursors((Container) containers.nextElement());
+ }
+ }
+ cursors = null;
+
+ return helpID;
+ }
+
+ /*
+ * Get all top level containers to change it's cursors
+ */
+ protected Vector getTopContainers(Object source) {
+ // This method is used to obtain all top level components of application
+ // for which the changing of cursor to question mark is wanted.
+ // Method Frame.getFrames() is used to get list of Frames and
+ // Frame.getOwnedWindows() method on elements of the list
+ // returns all Windows, Dialogs etc. It works correctly in application.
+ // Problem is in applets. There is no way how to get reference to applets
+ // from elsewhere than applet itself. So, if request for CSH (this means
+ // pressing help button or select help menu item) does't come from component
+ // in a Applet, cursor for applets is not changed to question mark. Only for
+ // Frames, Windows and Dialogs is cursor changed properly.
+
+ Vector<Component> containers = new Vector<Component>();
+ Component topComponent = null;
+ topComponent = getRoot(source);
+ if (topComponent instanceof Applet) {
+ try {
+ Enumeration<Applet> applets = ((Applet) topComponent).getAppletContext().getApplets();
+ while (applets.hasMoreElements()) {
+ containers.add(applets.nextElement());
+ }
+ } catch (NullPointerException npe) {
+ containers.add(topComponent);
+ }
+ }
+ Frame frames[] = Frame.getFrames();
+ for (int i = 0; i < frames.length; i++) {
+ Window[] windows = frames[i].getOwnedWindows();
+ for (int j = 0; j < windows.length; j++) {
+ containers.add(windows[j]);
+ }
+ if (!containers.contains(frames[i])) {
+ containers.add(frames[i]);
+ }
+ }
+ return containers;
+ }
+
+ protected Component getRoot(Object comp) {
+ Object parent = comp;
+ while (parent != null) {
+ comp = parent;
+ if (comp instanceof MenuComponent) {
+ parent = ((MenuComponent) comp).getParent();
+ } else if (comp instanceof Component) {
+ if (comp instanceof Window) {
+ break;
+ }
+ if (comp instanceof Applet) {
+ break;
+ }
+ parent = ((Component) comp).getParent();
+ } else {
+ break;
+ }
+ }
+ if (comp instanceof Component) {
+ return ((Component) comp);
+ }
+ return null;
+ }
+
+
+ /*
+ * Set the cursor for a component and its children.
+ * Store the old cursors for future resetting
+ */
+ protected void setAndStoreCursors(Component comp, Cursor cursor) {
+ if (comp == null) {
+ return;
+ }
+ Cursor compCursor = comp.getCursor();
+ if (compCursor != cursor) {
+ cursors.put(comp, compCursor);
+ log.debug("set cursor on " + comp);
+ comp.setCursor(cursor);
+ }
+ if (comp instanceof Container) {
+ Component component[] = ((Container) comp).getComponents();
+ for (int i = 0; i < component.length; i++) {
+ setAndStoreCursors(component[i], cursor);
+ }
+ }
+ }
+
+ /*
+ * Actually restore the cursor for a component and its children
+ */
+ protected void resetAndRestoreCursors(Component comp) {
+ if (comp == null) {
+ return;
+ }
+ Cursor oldCursor = cursors.get(comp);
+ if (oldCursor != null) {
+ log.debug("restored cursor " + oldCursor + " on " + comp);
+ comp.setCursor(oldCursor);
+ }
+ if (comp instanceof Container) {
+ Component component[] = ((Container) comp).getComponents();
+ for (int i = 0; i < component.length; i++) {
+ resetAndRestoreCursors(component[i]);
+ }
+ }
+ }
+
+ /**
+ * Context Sensitive Event Tracking
+ *
+ * Creates a new EventDispatchThread from which to dispatch events. This
+ * method returns when stopModal is invoked.
+ *
+ * @return MouseEvent The mouse event occurred. Null if
+ * cancelled on an undetermined object.
+ */
+ public static MouseEvent getMouseEvent() {
+ // Should the cursor change to a quesiton mark here or
+ // require the user to change the cursor externally to this method?
+ // The problem is that each component can have it's own cursor.
+ // For that reason it might be better to have the user change the
+ // cusor rather than us.
+
+ // To track context-sensitive events get the event queue and process
+ // the events the same way EventDispatchThread does. Filter out
+ // ContextSensitiveEvents SelectObject & Cancel (MouseDown & ???).
+ // Note: This code only handles mouse events. Accessiblity might
+ // require additional functionality or event trapping
+
+ // If the eventQueue can't be retrieved, the thread gets interrupted,
+ // or the thread isn't a instanceof EventDispatchThread then return
+ // a null as we won't be able to trap events.
+ try {
+ if (EventQueue.isDispatchThread()) {
+ EventQueue eq = null;
+
+ // Find the eventQueue. If we can't get to it then just return
+ // null since we won't be able to trap any events.
+
+ try {
+ eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
+ } catch (Exception ee) {
+ log.debug(ee);
+ }
+
+ // Safe guard
+ if (eq == null) {
+ return null;
+ }
+
+ int eventNumber = -1;
+
+ // Process the events until an object has been selected or
+ // the context-sensitive search has been canceled.
+ while (true) {
+ // This is essentially the body of EventDispatchThread
+ // modified to trap context-senstive events and act
+ // appropriately
+ eventNumber++;
+ AWTEvent event = eq.getNextEvent();
+ Object src = event.getSource();
+ // can't call eq.dispatchEvent
+ // so I pasted it's body here
+
+ // debug(event);
+
+ // Not sure if I should suppress ActiveEvents or not
+ // Modal dialogs do. For now we will not suppress the
+ // ActiveEvent events
+
+ if (event instanceof ActiveEvent) {
+ ((ActiveEvent) event).dispatch();
+ continue;
+ }
+
+ if (src instanceof Component) {
+ // Trap the context-sensitive events here
+ if (event instanceof KeyEvent) {
+ KeyEvent e = (KeyEvent) event;
+ // if this is the cancel key then exit
+ // otherwise pass all other keys up
+ if (e.getKeyCode() == KeyEvent.VK_CANCEL ||
+ e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ e.consume();
+ return null;
+ } else {
+ e.consume();
+ // dispatchEvent(event);
+ }
+ } else if (event instanceof MouseEvent) {
+ MouseEvent e = (MouseEvent) event;
+ int eID = e.getID();
+ if ((eID == MouseEvent.MOUSE_CLICKED ||
+ eID == MouseEvent.MOUSE_PRESSED ||
+ eID == MouseEvent.MOUSE_RELEASED) &&
+ SwingUtilities.isLeftMouseButton(e)) {
+ if (eID == MouseEvent.MOUSE_CLICKED) {
+ if (eventNumber == 0) {
+ dispatchEvent(event);
+ continue;
+ }
+ }
+ e.consume();
+ return e;
+ } else {
+ e.consume();
+ }
+ } else {
+ dispatchEvent(event);
+ }
+ } else if (src instanceof MenuComponent) {
+ if (event instanceof InputEvent) {
+ ((InputEvent) event).consume();
+ }
+ } else {
+ System.err.println("unable to dispatch event: " + event);
+ }
+ }
+ }
+ } catch (InterruptedException e) {
+ log.debug(e);
+ }
+ log.debug("Fall Through code");
+ return null;
+ }
+
+ private static void dispatchEvent(AWTEvent event) {
+ Object src = event.getSource();
+ if (event instanceof ActiveEvent) {
+ // This could become the sole method of dispatching in time.
+ ((ActiveEvent) event).dispatch();
+ } else if (src instanceof Component) {
+ ((Component) src).dispatchEvent(event);
+ } else if (src instanceof MenuComponent) {
+ ((MenuComponent) src).dispatchEvent(event);
+ } else {
+ System.err.println("unable to dispatch event: " + event);
+ }
+ }
+}
1
0
[Buix-commits] r1279 - in jaxx/trunk/jaxx-runtime-swing/src/main: java/jaxx/runtime java/jaxx/runtime/swing/wizard resources resources/icons
by tchemit@users.labs.libre-entreprise.org 24 Mar '09
by tchemit@users.labs.libre-entreprise.org 24 Mar '09
24 Mar '09
Author: tchemit
Date: 2009-03-24 14:37:47 +0000 (Tue, 24 Mar 2009)
New Revision: 1279
Added:
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-config-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-config.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-message-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-message.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-next-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-next.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-pause-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-pause.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-previous-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-previous.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-refresh-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-refresh.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-start-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-start.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-canceled-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-canceled.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-failed-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-failed.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-need_fix-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-need_fix.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-pending-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-pending.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-running-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-running.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-successed-16.png
jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-successed.png
Modified:
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java
Log:
add default icons for wizard framework
Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java 2009-03-24 00:58:12 UTC (rev 1278)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java 2009-03-24 14:37:47 UTC (rev 1279)
@@ -31,8 +31,10 @@
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Properties;
+import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
+import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
@@ -461,4 +463,20 @@
this.reverse = reverse;
}
}
+
+ public static JLabel newLabel(String text, Object iconKey, int aligment) {
+ Icon icon = null;
+ if (iconKey instanceof Icon) {
+ icon = (Icon) iconKey;
+ } else if (iconKey instanceof String) {
+ icon = jaxx.runtime.Util.getUIManagerActionIcon((String) iconKey);
+ }
+ JLabel result;
+ if (icon == null) {
+ result = new JLabel(text, aligment);
+ } else {
+ result = new JLabel(text, icon, aligment);
+ }
+ return result;
+ }
}
Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java 2009-03-24 00:58:12 UTC (rev 1278)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java 2009-03-24 14:37:47 UTC (rev 1279)
@@ -14,25 +14,81 @@
*/
public interface WizardUI<E extends WizardStep, M extends WizardModel<E>> {
+ /**
+ * @return le modèle de wizard
+ */
M getModel();
+ /**
+ *
+ * @return l'étape courante
+ */
E getSelectedStep();
+ /**
+ *
+ * @return l'ui de l'étape courante
+ */
WizardStepUI<E, M> getSelectedStepUI();
+ /**
+ *
+ * @param step l'étape donnée
+ * @return l'ui de l'étape donnée
+ */
WizardStepUI<E, M> getStepUI(E step);
-
+
+ /**
+ *
+ * @param stepIndex la position de l'étape
+ * @return l'ui de l'étape donée
+ */
WizardStepUI<E, M> getStepUI(int stepIndex);
+ /**
+ * démarre le wizard
+ */
void start();
+ /**
+ * //TODO il faudrait supprimer cette méthode
+ * @return le conteneur d'ui d'étapes
+ */
JTabbedPane getTabs();
+ /**
+ * Méthode invoqué lorsque la première opération du modèlé a été démarrée.
+ */
+ void onWasStarted();
+
+ /**
+ * Méthode invoquée lorsque l'univers des étapes a été modifié dans le
+ * modèle.
+ *
+ * @param steps les nouvelles étapes
+ */
void onStepsChanged(E[] steps);
-
+
+ /**
+ * Méthode invoquée lorsque l'étape courante a changé dans le modèle.
+ *
+ * @param newStep la nouvelle étape courante
+ */
void onStepChanged(E newStep);
+ /**
+ * Méthode invoquée lorsque l'état interne du modèle a changé.
+ *
+ * @param newState le nouvelle état du modèle de wizard
+ */
void onModelStateChanged(WizardOperationState newState);
+ /**
+ * Méthode invoqué lorsque l'état d'une opération a changé.
+ *
+ * @param step l'étape dont l'état a changé
+ * @param newState le nouvel état pour l'étape donné
+ */
void onOperationStateChanged(E step,WizardOperationState newState) ;
+
}
Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2009-03-24 00:58:12 UTC (rev 1278)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2009-03-24 14:37:47 UTC (rev 1279)
@@ -47,7 +47,7 @@
}
}
- public static void addTraceLogListener(final Log log,WizardModel model) {
+ public static void addTraceLogListener(final Log log, WizardModel model) {
if (log.isTraceEnabled()) {
model.addPropertyChangeListener(new PropertyChangeListener() {
@@ -65,7 +65,11 @@
@Override
@SuppressWarnings("unchecked")
public void propertyChange(PropertyChangeEvent evt) {
- String propertyName = evt.getPropertyName();
+ String propertyName = evt.getPropertyName();
+ if (WizardOperationModel.WAS_STARTED_PROPERTY_NAME.equals(propertyName)) {
+ ui.onWasStarted();
+ return;
+ }
if (WizardModel.STEPS_PROPERTY_NAME.equals(propertyName)) {
java.util.List<E> steps = (java.util.List<E>) evt.getNewValue();
ui.onStepsChanged(steps.toArray((E[]) Array.newInstance(ui.getModel().stepClass, steps.size())));
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-config-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-config-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-config.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-config.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-message-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-message-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-message.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-message.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-next-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-next-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-next.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-next.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-pause-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-pause-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-pause.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-pause.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-previous-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-previous-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-previous.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-previous.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-refresh-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-refresh-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-refresh.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-refresh.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-start-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-start-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-start.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-start.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-canceled-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-canceled-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-canceled.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-canceled.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-failed-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-failed-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-failed.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-failed.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-need_fix-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-need_fix-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-need_fix.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-need_fix.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-pending-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-pending-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-pending.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-pending.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-running-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-running-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-running.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-running.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-successed-16.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-successed-16.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-successed.png
===================================================================
(Binary files differ)
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/resources/icons/action-wizard-state-successed.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
1
0
[Buix-commits] r1278 - jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator
by tchemit@users.labs.libre-entreprise.org 24 Mar '09
by tchemit@users.labs.libre-entreprise.org 24 Mar '09
24 Mar '09
Author: tchemit
Date: 2009-03-24 00:58:12 +0000 (Tue, 24 Mar 2009)
New Revision: 1278
Modified:
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java
Log:
add scopes getter on BeanValidator
Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java 2009-03-23 11:34:36 UTC (rev 1277)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java 2009-03-24 00:58:12 UTC (rev 1278)
@@ -106,6 +106,10 @@
return fields;
}
+ public Set<BeanValidatorScope> getScopes() {
+ return new java.util.HashSet< BeanValidatorScope>(validators.keySet());
+ }
+
/**
* Retourne vrai si l'objet bean a ete modifie depuis le dernier
* {@link #setBean}
1
0
[Buix-commits] r1277 - jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing
by tchemit@users.labs.libre-entreprise.org 23 Mar '09
by tchemit@users.labs.libre-entreprise.org 23 Mar '09
23 Mar '09
Author: tchemit
Date: 2009-03-23 11:34:36 +0000 (Mon, 23 Mar 2009)
New Revision: 1277
Modified:
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java
Log:
can clear the validator models
Modified: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java 2009-03-23 00:02:52 UTC (rev 1276)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java 2009-03-23 11:34:36 UTC (rev 1277)
@@ -44,6 +44,14 @@
validator.addBeanValidatorListener(this);
}
+ public void clear() {
+ int i = data.size();
+ if (i > 0) {
+ data.clear();
+ fireIntervalRemoved(this, 0, i - 1);
+ }
+ }
+
@Override
public int getSize() {
return data.size();
Modified: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java 2009-03-23 00:02:52 UTC (rev 1276)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java 2009-03-23 11:34:36 UTC (rev 1277)
@@ -93,6 +93,14 @@
removeMessages(validator, field, scope, true, messages);
}
+ public void clear() {
+ int i = data.size();
+ if (i > 0) {
+ data.clear();
+ fireTableRowsDeleted(0, i - 1);
+ }
+ }
+
/**
* Obtain the message for a given row.
*
@@ -307,7 +315,7 @@
for (int i = getRowCount() - 1; i > -1; i--) {
SwingValidatorMessage error = data.get(i);
- if (error.getEditor() == editor && (scope==null || error.getScope() == scope) && error.getFieldName().equals(fieldName)) {
+ if (error.getEditor() == editor && (scope == null || error.getScope() == scope) && error.getFieldName().equals(fieldName)) {
// remove the message
data.remove(i);
if (notify) {
1
0
[Buix-commits] r1276 - jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime
by tchemit@users.labs.libre-entreprise.org 23 Mar '09
by tchemit@users.labs.libre-entreprise.org 23 Mar '09
23 Mar '09
Author: tchemit
Date: 2009-03-23 00:02:52 +0000 (Mon, 23 Mar 2009)
New Revision: 1276
Modified:
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/SwingValidatorUtil.java
Log:
when using validatorLabel, do not translate it immedialty
Modified: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/SwingValidatorUtil.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/SwingValidatorUtil.java 2009-03-21 16:13:18 UTC (rev 1275)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/SwingValidatorUtil.java 2009-03-23 00:02:52 UTC (rev 1276)
@@ -134,7 +134,7 @@
public static String getMessage(SwingValidatorMessage model) {
String text = model.getMessage();
- if (model.getField()!=null) {
+ if (model.getField() != null) {
text = model.getField().getI18nError(text);
}
return text;
@@ -144,12 +144,12 @@
String text = null;
JComponent editor = model.getEditor();
if (editor != null) {
- String l = (String) editor.getClientProperty("validatorLabel");
- if (l != null) {
+ text = (String) editor.getClientProperty("validatorLabel");
+ /*if (l != null) {
text = I18n._(l);
} else {
// TODO should try the text
- }
+ }*/
}
if (text == null) {
text = value;
1
0
21 Mar '09
Author: tchemit
Date: 2009-03-21 16:13:18 +0000 (Sat, 21 Mar 2009)
New Revision: 1275
Added:
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/SwingValidatorUtil.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessage.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListRenderer.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/BeanValidatorUtil.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorMessage.java
Removed:
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/SwingValidatorMessageModel.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator2.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidationUtil.java
Modified:
jaxx/trunk/jaxx-compiler-api/changelog.txt
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java
jaxx/trunk/jaxx-compiler-validator/changelog.txt
jaxx/trunk/jaxx-compiler-validator/pom.xml
jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/compiler/ValidatorGenerator.java
jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java
jaxx/trunk/jaxx-example/changelog.txt
jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationListDemo.jaxx
jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx
jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties
jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties
jaxx/trunk/jaxx-runtime-swing/changelog.txt
jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt
jaxx/trunk/jaxx-runtime-validator-swing/pom.xml
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/SwingValidatorMessageListModel.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListMouseListener.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableMouseListener.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableRenderer.java
jaxx/trunk/jaxx-runtime-validator/changelog.txt
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/JAXXValidator.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorEvent.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorField.java
jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/BeanValidatorTest.java
jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/AbstractFieldValidatorTest.java
jaxx/trunk/maven-jaxx-plugin/changelog.txt
jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
Log:
validator refactor end
Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,4 +1,5 @@
-1.3 chemit 20090320
+1.3 chemit 20090321
+ * 20090321 [chemit] - add compilerCount in launchro to known how mush files where generated
* 20090313 [chemit] - can now use geneticType on javaBean object
- add an extra method $afterCompleteSetup method to be included if find in script at last statement of $completeSetup method
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompilerLaunchor.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -141,6 +141,7 @@
protected LifeCycle currentPass;
protected int errorCount;
protected int warningCount;
+ protected int compilerCount;
protected JAXXProfile profiler;
protected JAXXCompilerLaunchor(File[] files, String[] classNames, CompilerOptions options) {
@@ -233,6 +234,7 @@
*/
public synchronized boolean compile() {
//reset(); // just to be safe...
+ compilerCount = 0;
jaxxFiles.addAll(Arrays.asList(files));
jaxxFileClassNames.addAll(Arrays.asList(classNames));
try {
@@ -375,6 +377,7 @@
e.printStackTrace();
return false;
} finally {
+ compilerCount = compilers.size();
//TC - 20081018 only reset when no error was detected
if (options.isResetAfterCompile() && errorCount == 0) {
reset();
@@ -382,6 +385,10 @@
}
}
+ public int getCompilerCount() {
+ return compilerCount;
+ }
+
protected JAXXCompiler getCompiler(String className, String message) {
JAXXCompiler compiler = compilers.get(className);
if (compiler == null) {
@@ -441,5 +448,4 @@
System.out.println();
System.out.println("See http://www.jaxxframework.org/ for full documentation.");
}
-
}
Modified: jaxx/trunk/jaxx-compiler-validator/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-validator/changelog.txt 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-compiler-validator/changelog.txt 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,4 +1,4 @@
-1.3 chemit 20090320
+1.3 chemit 20090321
1.1 chemit 20090220
* 20090202 [chemit] - refactor validators (this module will soon disappear to jaxx-compiler-swing-validator)
Modified: jaxx/trunk/jaxx-compiler-validator/pom.xml
===================================================================
--- jaxx/trunk/jaxx-compiler-validator/pom.xml 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-compiler-validator/pom.xml 2009-03-21 16:13:18 UTC (rev 1275)
@@ -28,6 +28,12 @@
<dependency>
<groupId>${project.groupId}</groupId>
+ <artifactId>jaxx-runtime-swing</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
<artifactId>jaxx-runtime-validator-swing</artifactId>
<version>${project.version}</version>
</dependency>
Modified: jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/compiler/ValidatorGenerator.java
===================================================================
--- jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/compiler/ValidatorGenerator.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/compiler/ValidatorGenerator.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -34,7 +34,7 @@
boolean found = BeanValidatorHandler.isComponentUsedByValidator(compiler, child.getChild().getId());
if (found) {
// box the child component in a JxLayer
- child.setChildJavaCode("jaxx.runtime.SwingUtil.boxComponentWithJxLayer(" + javaCode + ")");
+ child.setChildJavaCode(jaxx.runtime.SwingUtil.class.getName()+".boxComponentWithJxLayer(" + javaCode + ")");
}
}
}
@@ -45,7 +45,8 @@
compiler.appendLateInitializer(JAXXCompiler.getLineSeparator());
compiler.appendLateInitializer("getValidator(" + id + ").installUIs();");
compiler.appendLateInitializer(JAXXCompiler.getLineSeparator());
- compiler.appendLateInitializer("getValidator(" + id + ").validate();");
+ compiler.appendLateInitializer("getValidator(" + id + ").reloadBean();");
+ //compiler.appendLateInitializer("getValidator(" + id + ").validate();");
compiler.appendLateInitializer(JAXXCompiler.getLineSeparator());
}
compiler.appendLateInitializer("validatorIds = java.util.Collections.unmodifiableList(validatorIds);");
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-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-compiler-validator/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -11,7 +11,7 @@
import jaxx.introspection.JAXXPropertyDescriptor;
import jaxx.reflect.ClassDescriptor;
import jaxx.reflect.ClassDescriptorLoader;
-import jaxx.runtime.validator.SwingValidationUtil;
+import jaxx.runtime.SwingValidatorUtil;
import jaxx.runtime.validator.swing.SwingValidator;
import jaxx.runtime.validator.swing.ui.AbstractBeanValidatorUI;
import jaxx.tags.DefaultObjectHandler;
@@ -35,33 +35,23 @@
public static final String BEAN_ATTRIBUTE = "bean";
public static final String BEAN_CLASS_ATTRIBUTE = "beanClass";
public static final String BEAN_INITIALIZER_ATTRIBUTE = "beanInitializer";
-
public static final String ERROR_LIST_MODEL_ATTRIBUTE = "errorListModel";
public static final String ERROR_TABLE_MODEL_ATTRIBUTE = "errorTableModel";
public static final String ERROR_LIST_ATTRIBUTE = "errorList";
public static final String ERROR_TABLE_ATTRIBUTE = "errorTable";
-
public static final String ERROR_LIST_MODEL_DEFAULT = "errors";
public static final String ERROR_TABLE_MODEL_DEFAULT = "errors2";
-
public static final String ERROR_LIST_DEFAULT = "errorList";
public static final String ERROR_TABLE_DEFAULT = "errorTable";
-
public static final String AUTOFIELD_ATTRIBUTE = "autoField";
public static final String UI_CLASS_ATTRIBUTE = "uiClass";
public static final String STRICT_MODE_ATTRIBUTE = "strictMode";
-
public static final String CONTEXT_NAME_ATTRIBUTE = "contextName";
-
//public static final String SCOPE_ATTRIBUTE = "scope";
-
public static final String PARENT_VALIDATOR_ATTRIBUTE = "parentValidator";
-
/** to use log facility, just put in your code: log.info(\"...\"); */
static Log log = LogFactory.getLog(BeanValidatorHandler.class);
-
protected static Map<JAXXCompiler, List<CompiledBeanValidator>> validators = new HashMap<JAXXCompiler, List<CompiledBeanValidator>>();
-
protected static Map<JAXXCompiler, List<String>> validatedComponents = new HashMap<JAXXCompiler, List<String>>();
public BeanValidatorHandler(ClassDescriptor beanClass) {
@@ -116,11 +106,11 @@
}
/*if (!error) {
- error = info.addContextName(this, compiler);
+ error = info.addContextName(this, compiler);
}*/
/*if (!error) {
- error = info.addScope(this, compiler);
+ error = info.addScope(this, compiler);
}*/
if (!error) {
@@ -317,13 +307,13 @@
//TC-20090111 beanClass is mandatory
// get the real bean class name (from bean or beanClass)
/*if (beanClass != null) {
- beanClassName = beanClass;
+ beanClassName = beanClass;
} else {
- beanClassName = compiler.getSymbolTable().getClassTagIds().get(bean);
- if (beanClassName == null) {
- compiler.reportError("could not find class of the bean '" + bean + "'");
- return null;
- }
+ beanClassName = compiler.getSymbolTable().getClassTagIds().get(bean);
+ if (beanClassName == null) {
+ compiler.reportError("could not find class of the bean '" + bean + "'");
+ return null;
+ }
}*/
ClassDescriptor beanClassDescriptor = ClassDescriptorLoader.getClassDescriptor(beanClass);
beanDescriptor = DefaultObjectHandler.getJAXXBeanInfo(beanClassDescriptor);
@@ -419,21 +409,20 @@
}
/*protected boolean addContextName(BeanValidatorHandler handler, JAXXCompiler compiler) {
- if (contextName != null) {
- String code = handler.getSetPropertyCode(getJavaCode(), CONTEXT_NAME_ATTRIBUTE, TypeManager.getJavaCode(contextName), compiler);
- appendAdditionCode(code);
- }
- return false;
+ if (contextName != null) {
+ String code = handler.getSetPropertyCode(getJavaCode(), CONTEXT_NAME_ATTRIBUTE, TypeManager.getJavaCode(contextName), compiler);
+ appendAdditionCode(code);
+ }
+ return false;
}*/
/*protected boolean addScope(BeanValidatorHandler handler, JAXXCompiler compiler) {
- if (scope != null) {
- String code = handler.getSetPropertyCode(getJavaCode(), SCOPE_ATTRIBUTE, TypeManager.getJavaCode(scope), compiler);
- appendAdditionCode(code);
- }
- return false;
+ if (scope != null) {
+ String code = handler.getSetPropertyCode(getJavaCode(), SCOPE_ATTRIBUTE, TypeManager.getJavaCode(scope), compiler);
+ appendAdditionCode(code);
+ }
+ return false;
}*/
-
protected boolean addParentValidator(Element tag, BeanValidatorHandler handler, JAXXCompiler compiler) {
if (parentValidator != null) {
String initializer;
@@ -470,7 +459,7 @@
}
}
- String code = SwingValidationUtil.class.getName() + ".registerErrorListMouseListener(" + errorList + ");";
+ String code = SwingValidatorUtil.class.getName() + ".registerErrorListMouseListener(" + errorList + ");";
appendAdditionCode(code);
return false;
@@ -490,7 +479,7 @@
}
}
- String code = SwingValidationUtil.class.getName() + ".registerErrorTableMouseListener(" + errorTable + ");";
+ String code = SwingValidatorUtil.class.getName() + ".registerErrorTableMouseListener(" + errorTable + ");";
appendAdditionCode(code);
return false;
@@ -541,7 +530,7 @@
}
/*if (beanInitializer != null) {
- compiler.reportWarning("tag '" + tag + "' found a 'bean' and a 'beanInitializer' attributes, 'beanInitializer' is skipped");
+ compiler.reportWarning("tag '" + tag + "' found a 'bean' and a 'beanInitializer' attributes, 'beanInitializer' is skipped");
}*/
beanInitializer = bean;
}
@@ -603,9 +592,9 @@
continue;
}
/*if (compiler.isComponentUsedByValidator(component)) {
- // component is already used by another validator
- compiler.reportError("component '" + component + "' is already used by another validator.");
- continue;
+ // component is already used by another validator
+ compiler.reportError("component '" + component + "' is already used by another validator.");
+ continue;
}*/
String keyCode = TypeManager.getJavaCode(propertyName);
appendAdditionCode(getJavaCode() + ".setFieldRepresentation(" + keyCode + ", " + component + ");");
Modified: jaxx/trunk/jaxx-example/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-example/changelog.txt 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-example/changelog.txt 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,4 +1,4 @@
-1.3 chemit 20090320
+1.3 chemit 20090321
* 20090319 [chemit] - refactor Validator : now can deal with scopes, improve design
* 20090313 [chemit] - improve demo
Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationListDemo.jaxx
===================================================================
--- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationListDemo.jaxx 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationListDemo.jaxx 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,15 +1,10 @@
<DemoPanel>
<style source="Validation.css"/>
-<script>
-void $afterCompleteSetup() {
- validator.setBean(null);
- validator2.setBean(null);
- validator3.setBean(null);
- validator.setBean(model1);
- validator2.setBean(model2);
- validator3.setBean(identity);
-}
+<script><![CDATA[
+import static org.codelutin.i18n.I18n.n_;
+void $afterCompleteSetup() {
+}]]>
</script>
<!-- models -->
<Model id='model1'/>
@@ -48,6 +43,7 @@
</cell>
<cell weightx='1'>
<JTextField id='text' text='{model1.getText()}'
+ _validatorLabel='{n_("form.text")}'
onKeyReleased='model1.setText(text.getText())'/>
</cell>
</row>
@@ -57,6 +53,7 @@
</cell>
<cell weightx='1'>
<JTextField id='text2' text='{model1.getText2()}'
+ _validatorLabel='{n_("form.text2")}'
onKeyReleased='model1.setText2(text2.getText())'/>
</cell>
</row>
@@ -66,7 +63,9 @@
<JLabel text='Ratio:'/>
</cell>
<cell>
- <JSlider id='ratio' minimum='0' maximum='100' value='{model1.getRatio()}'
+ <JSlider id='ratio' minimum='0' maximum='100'
+ value='{model1.getRatio()}'
+ _validatorLabel='{n_("form.ratio")}'
onStateChanged='model1.setRatio(ratio.getValue())'/>
</cell>
</row>
@@ -117,6 +116,7 @@
</cell>
<cell weightx='1'>
<JTextField id='_text' text='{model2.getText()}'
+ _validatorLabel='{n_("form2.text")}'
onKeyReleased='model2.setText(_text.getText())'/>
</cell>
</row>
@@ -126,6 +126,7 @@
</cell>
<cell weightx='1'>
<JTextField id='_text2' text='{model2.getText2()}'
+ _validatorLabel='{n_("form2.text2")}'
onKeyReleased='model2.setText2(_text2.getText())'/>
</cell>
</row>
@@ -135,7 +136,9 @@
<JLabel text='Ratio:'/>
</cell>
<cell>
- <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ <JSlider id='_ratio' minimum='0' maximum='100'
+ value='{model2.getRatio()}'
+ _validatorLabel='{n_("form2.ratio")}'
onStateChanged='model2.setRatio(_ratio.getValue())'/>
</cell>
</row>
@@ -296,10 +299,11 @@
</row>
<row>
<cell columns='2' fill="both">
- <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200'
+ <JPanel border='{BorderFactory.createTitledBorder("Messages")}' layout='{new GridLayout()}' height='200'
width='500'>
<JScrollPane>
- <JList id='errorList' model='{errors}'/>
+ <JList id='errorList' model='{errors}'
+ cellRenderer='{new jaxx.runtime.validator.swing.SwingValidatorMessageListRenderer()}'/>
</JScrollPane>
</JPanel>
</cell>
Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx
===================================================================
--- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx 2009-03-21 16:13:18 UTC (rev 1275)
@@ -32,15 +32,9 @@
void $afterCompleteSetup() {
errorTable.setDefaultRenderer(Object.class, new jaxx.runtime.validator.swing.SwingValidatorMessageTableRenderer());
+ errorTable.getRowSorter().setSortKeys(java.util.Arrays.asList(new RowSorter.SortKey(0, SortOrder.ASCENDING)));
SwingUtil.setI18nTableHeaderRenderer(errorTable, n_("validator.scope"), n_("validator.scope.tip"), n_("validator.field"), n_("validator.field.tip"), n_("validator.message"), n_("validator.message.tip"));
SwingUtil.fixTableColumnWidth(errorTable, 0, 25);
-
- validator.setBean(null);
- validator2.setBean(null);
- validator3.setBean(null);
- validator.setBean(model1);
- validator2.setBean(model2);
- validator3.setBean(identity);
}
]]></script>
@@ -56,7 +50,9 @@
</cell>
<cell weightx='1'>
<JTextField id='text' text='{model1.getText()}'
- onKeyReleased='model1.setText(text.getText())'/>
+ onKeyReleased='model1.setText(text.getText())'
+ _validatorLabel='{n_("form.text")}'
+ />
</cell>
</row>
<row>
@@ -65,7 +61,9 @@
</cell>
<cell weightx='1'>
<JTextField id='text2' text='{model1.getText2()}'
- onKeyReleased='model1.setText2(text2.getText())'/>
+ onKeyReleased='model1.setText2(text2.getText())'
+ _validatorLabel='{n_("form.text2")}'
+ />
</cell>
</row>
@@ -74,7 +72,9 @@
<JLabel text='Ratio:'/>
</cell>
<cell>
- <JSlider id='ratio' minimum='0' maximum='100' value='{model1.getRatio()}'
+ <JSlider id='ratio' minimum='0' maximum='100'
+ value='{model1.getRatio()}'
+ _validatorLabel='{n_("form.ratio")}'
onStateChanged='model1.setRatio(ratio.getValue())'/>
</cell>
</row>
@@ -125,6 +125,7 @@
</cell>
<cell weightx='1'>
<JTextField id='_text' text='{model2.getText()}'
+ _validatorLabel='{n_("form2.text")}'
onKeyReleased='model2.setText(_text.getText())'/>
</cell>
</row>
@@ -134,6 +135,7 @@
</cell>
<cell weightx='1'>
<JTextField id='_text2' text='{model2.getText2()}'
+ _validatorLabel='{n_("form2.text2")}'
onKeyReleased='model2.setText2(_text2.getText())'/>
</cell>
</row>
@@ -143,7 +145,9 @@
<JLabel text='Ratio:'/>
</cell>
<cell>
- <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ <JSlider id='_ratio' minimum='0' maximum='100'
+ value='{model2.getRatio()}'
+ _validatorLabel='{n_("form2.ratio")}'
onStateChanged='model2.setRatio(_ratio.getValue())'/>
</cell>
</row>
@@ -304,10 +308,10 @@
</row>
<row>
<cell columns='2' fill="both">
- <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200'
+ <JPanel border='{BorderFactory.createTitledBorder("Messages")}' layout='{new GridLayout()}' height='200'
width='500'>
<JScrollPane columnHeaderView='{errorTable.getTableHeader()}'>
- <JTable id='errorTable' model='{errors2}' rowSelectionAllowed='true'
+ <JTable id='errorTable' model='{errors2}' rowSelectionAllowed='true' autoCreateRowSorter='true'
autoResizeMode='2' cellSelectionEnabled='false' selectionMode='0'/>
</JScrollPane>
</JPanel>
Modified: jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties
===================================================================
--- jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties 2009-03-21 16:13:18 UTC (rev 1275)
@@ -99,6 +99,12 @@
edit2=
edit3=
emptyNode=< empty node >
+form.ratio=Form \: ratio
+form.text=Form \: text
+form.text2=Form \: text2
+form2.ratio=Form2 \: ratio
+form2.text=Form2 \: text
+form2.text2=Form2 \: text2
no\ layer=
valid=
validator.field=Champ
Modified: jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties
===================================================================
--- jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties 2009-03-21 16:13:18 UTC (rev 1275)
@@ -99,6 +99,12 @@
edit2=
edit3=
emptyNode=< empty node >
+form.ratio=Form \: ratio
+form.text=Form \: text
+form.text2=Form \: text2
+form2.ratio=Form2 \: ratio
+form2.text=Form2 \: text
+form2.text2=Form2 \: text2
no\ layer=
valid=
validator.field=Champ
Modified: jaxx/trunk/jaxx-runtime-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,4 +1,4 @@
-1.3 chemit 20090320
+1.3 chemit 20090321
* 20090318 [chemit] - introduce the BlockingLayerUI2 class (should be merge with BlockingLayerUI)
* 20090318 [chemit] - introduce the CardLayout2Ext class
* 20090312 [chemit] - add some usefull code from ObServe (load Nimbus L&F, load ui configuration)
Modified: jaxx/trunk/jaxx-runtime-validator/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/changelog.txt 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator/changelog.txt 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,5 +1,6 @@
-1.3 chemit 20090320
- * 20090319 [chemit] - refactor Validator : now can deal with scopes, improve design
+1.3 chemit 20090321
+ * 20090320 [chemit] - rename and move ValidationUtil to jaxx.runtime.BeanValidatorUtil
+ * 20090319 [chemit] - refactor Validator : now can deal with scopes, improve design
1.1 chemit 20090220
* 20090203 [chemit] - move swing specific code to jaxx-runtime-validator-swing module
Added: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/BeanValidatorUtil.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/BeanValidatorUtil.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/BeanValidatorUtil.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -0,0 +1,152 @@
+package jaxx.runtime;
+
+import jaxx.runtime.validator.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.BeanInfo;
+import java.beans.EventSetDescriptor;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The helper class for validation module.
+ *
+ * @author chemit
+ */
+public class BeanValidatorUtil {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private final Log log = LogFactory.getLog(BeanValidatorUtil.class);
+
+ protected BeanValidatorUtil() {
+ // no instance
+ }
+
+ /**
+ * Convinient method to attach a bean to all validators of an JAXXObject.
+ * <p/>
+ * It is possible to exclude some validator to be treated.
+ *
+ * @param ui the ui containing the validatros to treate
+ * @param bean the bean to attach in validators (can be null)
+ * @param excludeIds the list of validator id to exclude
+ */
+ @SuppressWarnings({"unchecked"})
+ public static void setValidatorBean(JAXXObject ui, Object bean, String... excludeIds) {
+ if (!JAXXValidator.class.isAssignableFrom(ui.getClass())) {
+ return;
+ }
+ JAXXValidator jaxxValidator = (JAXXValidator) ui;
+ List<String> validatorIds = jaxxValidator.getValidatorIds();
+ if (excludeIds.length > 0) {
+ validatorIds = new ArrayList<String>(validatorIds);
+ for (String excludeId : excludeIds) {
+ validatorIds.remove(excludeId);
+ }
+ }
+ for (String validatorId : validatorIds) {
+ BeanValidator beanValidator = jaxxValidator.getValidator(validatorId);
+ if (bean == null || beanValidator.getBeanClass().isAssignableFrom(bean.getClass())) {
+ // touch validator, only if fits the bean type (or bean is null)
+ beanValidator.setBean(bean);
+ }
+ }
+ }
+
+ /**
+ * Convinient method to set the changed property to all validators of an JAXXObject.
+ * <p/>
+ * It is possible to exclude some validator to be treated.
+ *
+ * @param ui the ui containing the validatros to treate
+ * @param newValue the new value to set in changed validator property
+ * @param excludeIds the list of validator id to exclude
+ */
+ @SuppressWarnings({"unchecked"})
+ public static void setValidatorChanged(JAXXObject ui, boolean newValue, String... excludeIds) {
+ if (!JAXXValidator.class.isAssignableFrom(ui.getClass())) {
+ return;
+ }
+ JAXXValidator jaxxValidator = (JAXXValidator) ui;
+ List<String> validatorIds = jaxxValidator.getValidatorIds();
+ if (excludeIds.length > 0) {
+ validatorIds = new ArrayList<String>(validatorIds);
+ for (String excludeId : excludeIds) {
+ validatorIds.remove(excludeId);
+ }
+ }
+ for (String validatorId : validatorIds) {
+ BeanValidator beanValidator = jaxxValidator.getValidator(validatorId);
+ beanValidator.setChanged(newValue);
+ }
+ }
+
+ /**
+ * Convert a value to a given type and then if was succesffull try to set it in the bean manage by the validator.
+ *
+ * @param validator validator to be involved
+ * @param fieldName the name of the bean property
+ * @param value the actual value to convert
+ * @param valueClass the type of the conversion
+ */
+ public static void convert(BeanValidator<?> validator, String fieldName, String value, Class<?> valueClass) {
+
+ Object result = validator.convert(fieldName, value, valueClass);
+ if (result != null) {
+ try {
+ BeanInfo info = Introspector.getBeanInfo(validator.getBean().getClass());
+
+ for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
+ if (fieldName.equals(descriptor.getName()) && descriptor.getWriteMethod() != null) {
+
+ descriptor.getWriteMethod().invoke(validator.getBean(), result);
+ break;
+ }
+ }
+ } catch (IntrospectionException e) {
+ log.error("could not obtain beanInfo for " + valueClass.getClass() + ", reason : " + e.getMessage(), e);
+ } catch (InvocationTargetException e) {
+ log.error("could not obtain beanInfo for " + valueClass.getClass() + ", reason : " + e.getMessage(), e);
+ } catch (IllegalAccessException e) {
+ log.error("could not obtain beanInfo for " + valueClass.getClass() + ", reason : " + e.getMessage(), e);
+ }
+ } else {
+ //fixme : conversion failed, we should be able to notify ui that values has changed ?
+ // otherwise, bean value has not changed,...
+ }
+ }
+
+ public static EventSetDescriptor getPropertyChangeListenerDescriptor(Class beanClass) {
+ try {
+ // check that the bean is listenable, otherwise, can't use
+ // the validator on it
+ BeanInfo infos = Introspector.getBeanInfo(beanClass);
+ EventSetDescriptor[] events = infos.getEventSetDescriptors();
+ for (EventSetDescriptor event : events) {
+ if ("propertyChange".equals(event.getName())) {
+
+ if (event.getAddListenerMethod() == null) {
+ // no property event listener, so can not use the validator
+ throw new IllegalStateException("no addPropertyChangeListener method found for " + beanClass);
+ }
+ if (event.getRemoveListenerMethod() == null) {
+ // no property event listener, so can not use the validator
+ throw new IllegalStateException("no removePropertyChangeListener method found for " + beanClass);
+ }
+ return event;
+ }
+ }
+
+ // no property event listener, so can not use the validator
+ throw new IllegalStateException("no PropertyChangeListener access method found for " + beanClass);
+ } catch (IntrospectionException ex) {
+ throw new IllegalStateException("could not acquire PropertyChangeListener bean info for " + beanClass + " for reason " + ex.getMessage(), ex);
+ }
+ }
+
+}
Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/JAXXValidator.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/JAXXValidator.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/JAXXValidator.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -2,7 +2,7 @@
import java.util.List;
-import jaxx.runtime.validator.BeanValidator2;
+import jaxx.runtime.validator.BeanValidator;
/**
* The contract of a validator-able object.
@@ -17,7 +17,7 @@
* @param validatorId validator id
* @return the associated validator, or <code>null</code> if not find
*/
- BeanValidator2<?> getValidator(String validatorId);
+ BeanValidator<?> getValidator(String validatorId);
/** @return the list of ids of all registred validator */
List<String> getValidatorIds();
Copied: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java (from rev 1273, jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator2.java)
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -0,0 +1,459 @@
+package jaxx.runtime.validator;
+
+import jaxx.runtime.BeanValidatorUtil;
+import java.beans.EventSetDescriptor;
+import org.apache.commons.beanutils.ConversionException;
+import org.apache.commons.beanutils.Converter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.util.ConverterUtil;
+
+import java.beans.Introspector;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+import javax.swing.event.EventListenerList;
+
+/**
+ *
+ * A customized validator for a given bean.
+ *
+ * <b>Note:</b> The bean must be listenable on properyChange events (means
+ * must have public addPropertychangeListener and removePropertyChangeListener methods).
+ *
+ * @param <B> type of the bean to validate.
+ *
+ * @author chemit
+ */
+public class BeanValidator<B> {
+
+ /** la nom de la propriété bean */
+ static public final String BEAN_PROERTY = "bean";
+ /** la nom de la propriété contextName */
+ static public final String CONTEXT_NAME_PROPERTY = "contextName";
+ /** la nom de l'état valid */
+ static public final String VALID_PROERTY = "valid";
+ /** la nom de l'état changed */
+ static public final String CHANGED_PROERTY = "changed";
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static protected final Log log = LogFactory.getLog(BeanValidator.class);
+ /** the type of bean to watch */
+ protected final Class<B> beanClass;
+ /** the validation named context (can be null) */
+ protected String contextName;
+ /** to chain to a prent validator */
+ protected BeanValidator<?> parentValidator;
+ /** state to indicate that validator has changed since the last time bean was setted */
+ protected boolean changed = false;
+ /** state of the validator (is true if no errors of error scope is found) */
+ protected boolean valid = true;
+ /** bean to be watched */
+ protected B bean = null;
+ /** to add and remove PropertyChangeListener on watched beans */
+ protected EventSetDescriptor beanEventDescriptor;
+ /** list of fields watched by this validator */
+ protected Set<BeanValidatorField<B>> fields;
+ /** map of conversion errors detected by this validator */
+ protected Map<String, String> conversionErrors;
+ /** xworks scope validator **/
+ protected EnumMap<BeanValidatorScope, XWorkBeanValidator<B>> validators;
+ /** listener that listens on bean modification */
+ protected PropertyChangeListener l;
+ /** delegate property change support */
+ protected PropertyChangeSupport pcs;
+ /** A list of event listeners for this validators */
+ protected EventListenerList listenerList = new EventListenerList();
+
+ public BeanValidator(Class<B> beanClass, String contextName) {
+ this.beanClass = beanClass;
+ this.pcs = new PropertyChangeSupport(this);
+ this.conversionErrors = new TreeMap<String, String>();
+ this.validators = new EnumMap<BeanValidatorScope, XWorkBeanValidator<B>>(BeanValidatorScope.class);
+
+ setContextName(contextName);
+
+ l = new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ validate();
+ setValid(!hasErrors());
+ setChanged(true);
+ }
+ };
+ }
+
+ public Class<B> getBeanClass() {
+ return beanClass;
+ }
+
+ public BeanValidator<?> getParentValidator() {
+ return parentValidator;
+ }
+
+ public String getContextName() {
+ return contextName;
+ }
+
+ public Set<BeanValidatorField<B>> getFields() {
+ return fields;
+ }
+
+ /**
+ * Retourne vrai si l'objet bean a ete modifie depuis le dernier
+ * {@link #setBean}
+ *
+ * @return <code>true</code> if bean was modify since last {@link #setBean(Object)} invocation
+ */
+ public boolean isChanged() {
+ return changed;
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ public B getBean() {
+ return bean;
+ }
+
+ public BeanValidatorField<B> getField(String fieldName) {
+ for (BeanValidatorField<B> field : fields) {
+ if (fieldName.equals(field.getName())) {
+ return field;
+ }
+ }
+ return null;
+ }
+
+ public boolean hasErrors() {
+ for (BeanValidatorField<B> field : fields) {
+ if (field.hasErrors()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean hasWarnings() {
+ for (BeanValidatorField<B> field : fields) {
+ if (field.hasWarnings()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean hasInfos() {
+ for (BeanValidatorField<B> field : fields) {
+ if (field.hasInfos()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Test a the validator contains the field given his name
+ *
+ * @param fieldName the name of the searched field
+ * @return <code>true</code> if validator contaisn this field, <code>false</code> otherwise
+ */
+ public boolean containsField(String fieldName) {
+ BeanValidatorField<B> field = getField(fieldName);
+ return field != null;
+ }
+
+ public boolean isValid(String fieldName) {
+ BeanValidatorField<B> field = getField(fieldName);
+ if (field == null) {
+ throw new IllegalArgumentException("could not find a validator field " + fieldName);
+ }
+ return field.isValid();
+ }
+
+ /**
+ * Permet de force la remise a false de l'etat de changement du bean
+ *
+ * @param changed flag to force reset of property {@link #changed}
+ */
+ public void setChanged(boolean changed) {
+ this.changed = changed;
+ // force the property to be fired (never pass the older value)
+ pcs.firePropertyChange(CHANGED_PROERTY, null, changed);
+ }
+
+ public void setValid(boolean valid) {
+ this.valid = valid;
+ // force the property to be fired (never pass the older value)
+ pcs.firePropertyChange(VALID_PROERTY, null, valid);
+ }
+
+ public void setBean(B bean) {
+ B oldBean = this.bean;
+ if (log.isDebugEnabled()) {
+ log.debug(this + " : " + bean);
+ }
+
+ // clean conversions of previous bean
+ conversionErrors.clear();
+
+ if (oldBean != null) {
+ try {
+ getBeanEventDescriptor(oldBean).getRemoveListenerMethod().invoke(oldBean, l);
+ } catch (Exception eee) {
+ log.info("Can't register as listener for bean " + beanClass + " for reason " + eee.getMessage(), eee);
+ }
+ }
+ this.bean = bean;
+
+ if (bean == null) {
+
+ // remove all messages for all fields of the validator
+
+ for (BeanValidatorField<B> f : fields) {
+
+ f.updateMessages(this, null, null);
+ }
+
+ } else {
+ try {
+ getBeanEventDescriptor(bean).getAddListenerMethod().invoke(bean, l);
+ } catch (Exception eee) {
+ log.info("Can't register as listener for bean " + beanClass + " for reason " + eee.getMessage(), eee);
+ }
+ validate();
+ }
+ setChanged(false);
+ setValid(!hasErrors());
+ pcs.firePropertyChange(BEAN_PROERTY, oldBean, bean);
+ }
+
+ public void setContextName(String contextName) {
+ String oldValidationContextName = this.contextName;
+ this.contextName = contextName;
+ // changing contextName could change fields definition
+ // so dettach bean, must rebuild the fields
+ if (bean != null) {
+ setBean(null);
+ }
+ // rebuild the fields
+ initFields();
+ pcs.firePropertyChange(CONTEXT_NAME_PROPERTY, oldValidationContextName, contextName);
+ }
+
+ public void setParentValidator(BeanValidator<?> parentValidator) {
+ this.parentValidator = parentValidator;
+ }
+
+ /**
+ * Convert a value.
+ * <p/>
+ * If an error occurs, then add an error in validator.
+ *
+ * @param <T> the type of conversion
+ * @param fieldName the name of the bean property
+ * @param value the value to convert
+ * @param valueClass the type of converted value
+ * @return the converted value, or null if conversion was not ok
+ */
+ @SuppressWarnings({"unchecked"})
+ public <T> T convert(String fieldName, String value, Class<T> valueClass) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("fieldName can not be null");
+ }
+ if (valueClass == null) {
+ throw new IllegalArgumentException("valueClass can not be null");
+ }
+
+ // on ne convertit pas si il y a un bean et que le resultat de la validation
+ // pourra etre affiche quelque part
+ if (!canValidate() || value == null) {
+ return null;
+ }
+
+ // remove the previous conversion error for the field
+ conversionErrors.remove(fieldName);
+
+ T result;
+ try {
+ Converter converter = ConverterUtil.getConverter(valueClass);
+ if (converter == null) {
+ throw new RuntimeException("could not find converter for the type " + valueClass);
+ }
+ result = (T) converter.convert(valueClass, value);
+ /* Why this test ? if (result != null && !value.equals(result.toString())) {
+ conversionErrors.put(fieldName, "error.convertor." + Introspector.decapitalize(valueClass.getSimpleName()));
+ result = null;
+ validate();
+ }*/
+ } catch (ConversionException e) {
+ // get
+ conversionErrors.put(fieldName, "error.convertor." + Introspector.decapitalize(valueClass.getSimpleName()));
+ result = null;
+ validate();
+ }
+ return result;
+ }
+
+ /**
+ * 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 (!canValidate()) {
+ return;
+ }
+
+ for (BeanValidatorScope scope : validators.keySet()) {
+
+ XWorkBeanValidator<B> validator = validators.get(scope);
+
+ Map<String, List<String>> newMessages = validator.validate(bean);
+
+ if (scope == BeanValidatorScope.ERROR) {
+ // treate conversion errors
+ // reinject them
+ for (Entry<String, String> entry : conversionErrors.entrySet()) {
+ // remove from validation, errors occurs on this field
+ List<String> errors = newMessages.get(entry.getKey());
+ String conversionError = entry.getValue();
+ if (errors != null) {
+ errors.clear();
+ errors.add(conversionError);
+ } else {
+ errors = java.util.Collections.singletonList(conversionError);
+ // add the concrete conversion error
+ newMessages.put(entry.getKey(), errors);
+ }
+ }
+ }
+
+ // for each field, update his list of messages
+ for (BeanValidatorField<B> field : fields) {
+ List<String> messagesForField = newMessages.get(field.getName());
+ if (field.getScopes().contains(scope)) {
+ field.updateMessages(this, scope, messagesForField);
+ }
+ }
+ }
+
+ if (parentValidator != null) {
+ // chained validation
+ parentValidator.l.propertyChange(null);
+ }
+
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "<beanClass:" + beanClass + ", contextName:" + contextName + ">";
+ }
+
+ public void addBeanValidatorListener(BeanValidatorListener listener) {
+ listenerList.add(BeanValidatorListener.class, listener);
+ }
+
+ public void removeBeanValidatorListener(BeanValidatorListener listener) {
+ listenerList.remove(BeanValidatorListener.class, listener);
+ }
+
+ public BeanValidatorListener[] getBeanValidatorListeners() {
+ return listenerList.getListeners(BeanValidatorListener.class);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }
+
+ /** @return <code>true</code> if validation is enabled, <code>false</code> otherwise. */
+ protected boolean canValidate() {
+ return !(bean == null || fields.isEmpty());
+ }
+
+ protected void fireFieldChanged(BeanValidatorField<B> field, BeanValidatorScope scope, String[] toAdd, String[] toDelete) {
+
+ BeanValidatorEvent evt = new BeanValidatorEvent(this, field, scope, toAdd, toDelete);
+
+ for (BeanValidatorListener listener : listenerList.getListeners(BeanValidatorListener.class)) {
+ listener.onFieldChanged(evt);
+ }
+ }
+
+ protected synchronized void initFields() {
+
+ Set<String> detectedFieldNames = new java.util.HashSet<String>();
+ EnumMap<BeanValidatorScope, Set<String>> tmp = new EnumMap<BeanValidatorScope, Set<String>>(BeanValidatorScope.class);
+ Set<BeanValidatorField<B>> detectedFields = new java.util.HashSet<BeanValidatorField<B>>();
+
+ validators.clear();
+
+ for (BeanValidatorScope scope : BeanValidatorScope.values()) {
+ String scopeContext = (contextName == null ? "" : contextName + "-") + scope.name().toLowerCase();
+
+ XWorkBeanValidator<B> newValidator = new XWorkBeanValidator<B>(beanClass, scopeContext, false);
+ Set<String> fieldNames = newValidator.getFieldNames();
+ if (log.isDebugEnabled()) {
+ log.debug("detected validators for scope " + scopeContext + " : " + fieldNames);
+ }
+ if (!fieldNames.isEmpty()) {
+ // fields detected in this validator, keep it
+ validators.put(scope, newValidator);
+ detectedFieldNames.addAll(fieldNames);
+ tmp.put(scope, fieldNames);
+ }
+ }
+
+ List<BeanValidatorScope> scopes = new ArrayList<BeanValidatorScope>();
+ for (String fieldName : detectedFieldNames) {
+ scopes.clear();
+ // detect scopes for the field
+ for (BeanValidatorScope scope : BeanValidatorScope.values()) {
+ if (tmp.containsKey(scope) && tmp.get(scope).contains(fieldName)) {
+ scopes.add(scope);
+ }
+ }
+ BeanValidatorField<B> f = new BeanValidatorField<B>(beanClass, fieldName, scopes);
+ detectedFields.add(f);
+ }
+ tmp.clear();
+ detectedFieldNames.clear();
+
+ this.fields = java.util.Collections.unmodifiableSet(detectedFields);
+ }
+
+ protected EventSetDescriptor getBeanEventDescriptor(B bean) {
+ if (beanEventDescriptor == null) {
+ // check that the bean is listenable, otherwise, can't use the validator on it
+ this.beanEventDescriptor = BeanValidatorUtil.getPropertyChangeListenerDescriptor(bean.getClass());
+ }
+ return beanEventDescriptor;
+ }
+}
Property changes on: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator2.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator2.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator2.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,458 +0,0 @@
-package jaxx.runtime.validator;
-
-import java.beans.EventSetDescriptor;
-import org.apache.commons.beanutils.ConversionException;
-import org.apache.commons.beanutils.Converter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.util.ConverterUtil;
-
-import java.beans.Introspector;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.util.ArrayList;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.TreeMap;
-import javax.swing.event.EventListenerList;
-
-/**
- *
- * A customized validator for a given bean.
- *
- * <b>Note:</b> The bean must be listenable on properyChange events (means
- * must have public addPropertychangeListener and removePropertyChangeListener methods).
- *
- * @param <B> type of the bean to validate.
- *
- * @author chemit
- */
-public class BeanValidator2<B> {
-
- /** la nom de la propriété bean */
- static public final String BEAN_PROERTY = "bean";
- /** la nom de la propriété contextName */
- static public final String CONTEXT_NAME_PROPERTY = "contextName";
- /** la nom de l'état valid */
- static public final String VALID_PROERTY = "valid";
- /** la nom de l'état changed */
- static public final String CHANGED_PROERTY = "changed";
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static protected final Log log = LogFactory.getLog(BeanValidator2.class);
- /** the type of bean to watch */
- protected final Class<B> beanClass;
- /** the validation named context (can be null) */
- protected String contextName;
- /** to chain to a prent validator */
- protected BeanValidator2<?> parentValidator;
- /** state to indicate that validator has changed since the last time bean was setted */
- protected boolean changed = false;
- /** state of the validator (is true if no errors of error scope is found) */
- protected boolean valid = true;
- /** bean to be watched */
- protected B bean = null;
- /** to add and remove PropertyChangeListener on watched beans */
- protected EventSetDescriptor beanEventDescriptor;
- /** list of fields watched by this validator */
- protected Set<BeanValidatorField<B>> fields;
- /** map of conversion errors detected by this validator */
- protected Map<String, String> conversionErrors;
- /** xworks scope validator **/
- protected EnumMap<BeanValidatorScope, XWorkBeanValidator<B>> validators;
- /** listener that listens on bean modification */
- protected PropertyChangeListener l;
- /** delegate property change support */
- protected PropertyChangeSupport pcs;
- /** A list of event listeners for this validators */
- protected EventListenerList listenerList = new EventListenerList();
-
- public BeanValidator2(Class<B> beanClass, String contextName) {
- this.beanClass = beanClass;
- this.pcs = new PropertyChangeSupport(this);
- this.conversionErrors = new TreeMap<String, String>();
- this.validators = new EnumMap<BeanValidatorScope, XWorkBeanValidator<B>>(BeanValidatorScope.class);
-
- setContextName(contextName);
-
- l = new PropertyChangeListener() {
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- validate();
- setValid(!hasErrors());
- setChanged(true);
- }
- };
- }
-
- public Class<B> getBeanClass() {
- return beanClass;
- }
-
- public BeanValidator2<?> getParentValidator() {
- return parentValidator;
- }
-
- public String getContextName() {
- return contextName;
- }
-
- public Set<BeanValidatorField<B>> getFields() {
- return fields;
- }
-
- /**
- * Retourne vrai si l'objet bean a ete modifie depuis le dernier
- * {@link #setBean}
- *
- * @return <code>true</code> if bean was modify since last {@link #setBean(Object)} invocation
- */
- public boolean isChanged() {
- return changed;
- }
-
- public boolean isValid() {
- return valid;
- }
-
- public B getBean() {
- return bean;
- }
-
- public BeanValidatorField<B> getField(String fieldName) {
- for (BeanValidatorField<B> field : fields) {
- if (fieldName.equals(field.getName())) {
- return field;
- }
- }
- return null;
- }
-
- public boolean hasErrors() {
- for (BeanValidatorField<B> field : fields) {
- if (field.hasErrors()) {
- return true;
- }
- }
- return false;
- }
-
- public boolean hasWarnings() {
- for (BeanValidatorField<B> field : fields) {
- if (field.hasWarnings()) {
- return true;
- }
- }
- return false;
- }
-
- public boolean hasInfos() {
- for (BeanValidatorField<B> field : fields) {
- if (field.hasInfos()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Test a the validator contains the field given his name
- *
- * @param fieldName the name of the searched field
- * @return <code>true</code> if validator contaisn this field, <code>false</code> otherwise
- */
- public boolean containsField(String fieldName) {
- BeanValidatorField<B> field = getField(fieldName);
- return field != null;
- }
-
- public boolean isValid(String fieldName) {
- BeanValidatorField<B> field = getField(fieldName);
- if (field == null) {
- throw new IllegalArgumentException("could not find a validator field " + fieldName);
- }
- return field.isValid();
- }
-
- /**
- * Permet de force la remise a false de l'etat de changement du bean
- *
- * @param changed flag to force reset of property {@link #changed}
- */
- public void setChanged(boolean changed) {
- this.changed = changed;
- // force the property to be fired (never pass the older value)
- pcs.firePropertyChange(CHANGED_PROERTY, null, changed);
- }
-
- public void setValid(boolean valid) {
- this.valid = valid;
- // force the property to be fired (never pass the older value)
- pcs.firePropertyChange(VALID_PROERTY, null, valid);
- }
-
- public void setBean(B bean) {
- B oldBean = this.bean;
- if (log.isDebugEnabled()) {
- log.debug(this + " : " + bean);
- }
-
- // clean conversions of previous bean
- conversionErrors.clear();
-
- if (oldBean != null) {
- try {
- getBeanEventDescriptor(oldBean).getRemoveListenerMethod().invoke(oldBean, l);
- } catch (Exception eee) {
- log.info("Can't register as listener for bean " + beanClass + " for reason " + eee.getMessage(), eee);
- }
- }
- this.bean = bean;
-
- if (bean == null) {
-
- // remove all messages for all fields of the validator
-
- for (BeanValidatorField<B> f : fields) {
-
- f.updateMessages(this, null, null);
- }
-
- } else {
- try {
- getBeanEventDescriptor(bean).getAddListenerMethod().invoke(bean, l);
- } catch (Exception eee) {
- log.info("Can't register as listener for bean " + beanClass + " for reason " + eee.getMessage(), eee);
- }
- validate();
- }
- setChanged(false);
- setValid(!hasErrors());
- pcs.firePropertyChange(BEAN_PROERTY, oldBean, bean);
- }
-
- public void setContextName(String contextName) {
- String oldValidationContextName = this.contextName;
- this.contextName = contextName;
- // changing contextName could change fields definition
- // so dettach bean, must rebuild the fields
- if (bean != null) {
- setBean(null);
- }
- // rebuild the fields
- initFields();
- pcs.firePropertyChange(CONTEXT_NAME_PROPERTY, oldValidationContextName, contextName);
- }
-
- public void setParentValidator(BeanValidator2<?> parentValidator) {
- this.parentValidator = parentValidator;
- }
-
- /**
- * Convert a value.
- * <p/>
- * If an error occurs, then add an error in validator.
- *
- * @param <T> the type of conversion
- * @param fieldName the name of the bean property
- * @param value the value to convert
- * @param valueClass the type of converted value
- * @return the converted value, or null if conversion was not ok
- */
- @SuppressWarnings({"unchecked"})
- public <T> T convert(String fieldName, String value, Class<T> valueClass) {
- if (fieldName == null) {
- throw new IllegalArgumentException("fieldName can not be null");
- }
- if (valueClass == null) {
- throw new IllegalArgumentException("valueClass can not be null");
- }
-
- // on ne convertit pas si il y a un bean et que le resultat de la validation
- // pourra etre affiche quelque part
- if (!canValidate() || value == null) {
- return null;
- }
-
- // remove the previous conversion error for the field
- conversionErrors.remove(fieldName);
-
- T result;
- try {
- Converter converter = ConverterUtil.getConverter(valueClass);
- if (converter == null) {
- throw new RuntimeException("could not find converter for the type " + valueClass);
- }
- result = (T) converter.convert(valueClass, value);
- /* Why this test ? if (result != null && !value.equals(result.toString())) {
- conversionErrors.put(fieldName, "error.convertor." + Introspector.decapitalize(valueClass.getSimpleName()));
- result = null;
- validate();
- }*/
- } catch (ConversionException e) {
- // get
- conversionErrors.put(fieldName, "error.convertor." + Introspector.decapitalize(valueClass.getSimpleName()));
- result = null;
- validate();
- }
- return result;
- }
-
- /**
- * 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 (!canValidate()) {
- return;
- }
-
- for (BeanValidatorScope scope : validators.keySet()) {
-
- XWorkBeanValidator<B> validator = validators.get(scope);
-
- Map<String, List<String>> newMessages = validator.validate(bean);
-
- if (scope == BeanValidatorScope.ERROR) {
- // treate conversion errors
- // reinject them
- for (Entry<String, String> entry : conversionErrors.entrySet()) {
- // remove from validation, errors occurs on this field
- List<String> errors = newMessages.get(entry.getKey());
- String conversionError = entry.getValue();
- if (errors != null) {
- errors.clear();
- errors.add(conversionError);
- } else {
- errors = java.util.Collections.singletonList(conversionError);
- // add the concrete conversion error
- newMessages.put(entry.getKey(), errors);
- }
- }
- }
-
- // for each field, update his list of messages
- for (BeanValidatorField<B> field : fields) {
- List<String> messagesForField = newMessages.get(field.getName());
- if (field.getScopes().contains(scope)) {
- field.updateMessages(this, scope, messagesForField);
- }
- }
- }
-
- if (parentValidator != null) {
- // chained validation
- parentValidator.l.propertyChange(null);
- }
-
- }
-
- @Override
- public String toString() {
- return super.toString() + "<beanClass:" + beanClass + ", contextName:" + contextName + ">";
- }
-
- public void addBeanValidatorListener(BeanValidatorListener listener) {
- listenerList.add(BeanValidatorListener.class, listener);
- }
-
- public void removeBeanValidatorListener(BeanValidatorListener listener) {
- listenerList.remove(BeanValidatorListener.class, listener);
- }
-
- public BeanValidatorListener[] getBeanValidatorListeners() {
- return listenerList.getListeners(BeanValidatorListener.class);
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(propertyName, listener);
- }
-
- /** @return <code>true</code> if validation is enabled, <code>false</code> otherwise. */
- protected boolean canValidate() {
- return !(bean == null || fields.isEmpty());
- }
-
- protected void fireFieldChanged(BeanValidatorField<B> field, BeanValidatorScope scope, String[] toAdd, String[] toDelete) {
-
- BeanValidatorEvent evt = new BeanValidatorEvent(this, field, scope, toAdd, toDelete);
-
- for (BeanValidatorListener listener : listenerList.getListeners(BeanValidatorListener.class)) {
- listener.onFieldChanged(evt);
- }
- }
-
- protected synchronized void initFields() {
-
- Set<String> detectedFieldNames = new java.util.HashSet<String>();
- EnumMap<BeanValidatorScope, Set<String>> tmp = new EnumMap<BeanValidatorScope, Set<String>>(BeanValidatorScope.class);
- Set<BeanValidatorField<B>> detectedFields = new java.util.HashSet<BeanValidatorField<B>>();
-
- validators.clear();
-
- for (BeanValidatorScope scope : BeanValidatorScope.values()) {
- String scopeContext = (contextName == null ? "" : contextName + "-") + scope.name().toLowerCase();
-
- XWorkBeanValidator<B> newValidator = new XWorkBeanValidator<B>(beanClass, scopeContext, false);
- Set<String> fieldNames = newValidator.getFieldNames();
- if (log.isDebugEnabled()) {
- log.debug("detected validators for scope " + scopeContext + " : " + fieldNames);
- }
- if (!fieldNames.isEmpty()) {
- // fields detected in this validator, keep it
- validators.put(scope, newValidator);
- detectedFieldNames.addAll(fieldNames);
- tmp.put(scope, fieldNames);
- }
- }
-
- List<BeanValidatorScope> scopes = new ArrayList<BeanValidatorScope>();
- for (String fieldName : detectedFieldNames) {
- scopes.clear();
- // detect scopes for the field
- for (BeanValidatorScope scope : BeanValidatorScope.values()) {
- if (tmp.containsKey(scope) && tmp.get(scope).contains(fieldName)) {
- scopes.add(scope);
- }
- }
- BeanValidatorField<B> f = new BeanValidatorField<B>(beanClass, fieldName, scopes);
- detectedFields.add(f);
- }
- tmp.clear();
- detectedFieldNames.clear();
-
- this.fields = java.util.Collections.unmodifiableSet(detectedFields);
- }
-
- protected EventSetDescriptor getBeanEventDescriptor(B bean) {
- if (beanEventDescriptor == null) {
- // check that the bean is listenable, otherwise, can't use the validator on it
- this.beanEventDescriptor = ValidationUtil.getPropertyChangeListenerDescriptor(bean.getClass());
- }
- return beanEventDescriptor;
- }
-}
Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorEvent.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorEvent.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorEvent.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -17,7 +17,7 @@
String[] messagestoAdd;
String[] messagestoDelete;
- public BeanValidatorEvent(BeanValidator2 source, BeanValidatorField<?> field, BeanValidatorScope scope, String[] toAdd, String[] toDelete) {
+ public BeanValidatorEvent(BeanValidator source, BeanValidatorField<?> field, BeanValidatorScope scope, String[] toAdd, String[] toDelete) {
super(source);
this.field = field;
this.scope = scope;
@@ -26,8 +26,8 @@
}
@Override
- public BeanValidator2 getSource() {
- return (BeanValidator2) super.getSource();
+ public BeanValidator getSource() {
+ return (BeanValidator) super.getSource();
}
public String getFieldName() {
Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorField.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorField.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorField.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -107,7 +107,7 @@
return messages.get(scope);
}
- public void updateMessages(BeanValidator2<B> validator, BeanValidatorScope scope, List<String> messages) {
+ public void updateMessages(BeanValidator<B> validator, BeanValidatorScope scope, List<String> messages) {
if (scope == null) {
@@ -220,7 +220,7 @@
return sb.toString();
}
- protected void clearMessages(BeanValidatorScope scope, BeanValidator2<B> validator) {
+ protected void clearMessages(BeanValidatorScope scope, BeanValidator<B> validator) {
// remove all messages
Set<String> toDelete = getMessages(scope);
Added: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorMessage.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorMessage.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorMessage.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -0,0 +1,72 @@
+package jaxx.runtime.validator;
+
+/**
+ * The object to box a validation message.
+ *
+ * @param <E> type of message (use for override {@link #compareTo(E)} method.
+ *
+ * @author chemit
+ * @since 1.3
+ */
+public class BeanValidatorMessage<E extends BeanValidatorMessage> implements Comparable<E> {
+
+ /**
+ * the validator that produce the message
+ */
+ protected BeanValidator validator;
+ /**
+ * the field thatproduce the message
+ */
+ protected BeanValidatorField field;
+ /**
+ * the label of the message (to be displayed somewhere)
+ */
+ protected String message;
+ /**
+ * the scope of the message
+ */
+ protected BeanValidatorScope scope;
+
+ public BeanValidatorMessage(BeanValidator validator, BeanValidatorField field, String message, BeanValidatorScope scope) {
+ this.field = field;
+ this.validator = validator;
+ this.message = message;
+ this.scope = scope;
+ }
+
+ public BeanValidator getValidator() {
+ return validator;
+ }
+
+ public BeanValidatorField getField() {
+ return field;
+ }
+
+ public BeanValidatorScope getScope() {
+ return scope;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ @Override
+ public int compareTo(E o) {
+ // sort on scope
+ int result = getScope().compareTo(o.getScope());
+ if (result == 0) {
+ // sort on field name
+ result = field.getName().compareTo(o.field.getName());
+ if (result == 0) {
+ // sort on message
+ result = message.compareTo(o.message);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return scope + " - " + field.getI18nError(message);
+ }
+}
Deleted: 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-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidationUtil.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,153 +0,0 @@
-package jaxx.runtime.validator;
-
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.JAXXValidator;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.beans.BeanInfo;
-import java.beans.EventSetDescriptor;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The helper class for validation module.
- *
- * @author chemit
- */
-public class ValidationUtil {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private final Log log = LogFactory.getLog(ValidationUtil.class);
-
- protected ValidationUtil() {
- // no instance
- }
-
- /**
- * Convinient method to attach a bean to all validators of an JAXXObject.
- * <p/>
- * It is possible to exclude some validator to be treated.
- *
- * @param ui the ui containing the validatros to treate
- * @param bean the bean to attach in validators (can be null)
- * @param excludeIds the list of validator id to exclude
- */
- @SuppressWarnings({"unchecked"})
- public static void setValidatorBean(JAXXObject ui, Object bean, String... excludeIds) {
- if (!JAXXValidator.class.isAssignableFrom(ui.getClass())) {
- return;
- }
- JAXXValidator jaxxValidator = (JAXXValidator) ui;
- List<String> validatorIds = jaxxValidator.getValidatorIds();
- if (excludeIds.length > 0) {
- validatorIds = new ArrayList<String>(validatorIds);
- for (String excludeId : excludeIds) {
- validatorIds.remove(excludeId);
- }
- }
- for (String validatorId : validatorIds) {
- BeanValidator2 beanValidator = jaxxValidator.getValidator(validatorId);
- if (bean == null || beanValidator.getBeanClass().isAssignableFrom(bean.getClass())) {
- // touch validator, only if fits the bean type (or bean is null)
- beanValidator.setBean(bean);
- }
- }
- }
-
- /**
- * Convinient method to set the changed property to all validators of an JAXXObject.
- * <p/>
- * It is possible to exclude some validator to be treated.
- *
- * @param ui the ui containing the validatros to treate
- * @param newValue the new value to set in changed validator property
- * @param excludeIds the list of validator id to exclude
- */
- @SuppressWarnings({"unchecked"})
- public static void setValidatorChanged(JAXXObject ui, boolean newValue, String... excludeIds) {
- if (!JAXXValidator.class.isAssignableFrom(ui.getClass())) {
- return;
- }
- JAXXValidator jaxxValidator = (JAXXValidator) ui;
- List<String> validatorIds = jaxxValidator.getValidatorIds();
- if (excludeIds.length > 0) {
- validatorIds = new ArrayList<String>(validatorIds);
- for (String excludeId : excludeIds) {
- validatorIds.remove(excludeId);
- }
- }
- for (String validatorId : validatorIds) {
- BeanValidator2 beanValidator = jaxxValidator.getValidator(validatorId);
- beanValidator.setChanged(newValue);
- }
- }
-
- /**
- * Convert a value to a given type and then if was succesffull try to set it in the bean manage by the validator.
- *
- * @param validator validator to be involved
- * @param fieldName the name of the bean property
- * @param value the actual value to convert
- * @param valueClass the type of the conversion
- */
- public static void convert(BeanValidator2<?> validator, String fieldName, String value, Class<?> valueClass) {
-
- Object result = validator.convert(fieldName, value, valueClass);
- if (result != null) {
- try {
- BeanInfo info = Introspector.getBeanInfo(validator.getBean().getClass());
-
- for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
- if (fieldName.equals(descriptor.getName()) && descriptor.getWriteMethod() != null) {
-
- descriptor.getWriteMethod().invoke(validator.getBean(), result);
- break;
- }
- }
- } catch (IntrospectionException e) {
- log.error("could not obtain beanInfo for " + valueClass.getClass() + ", reason : " + e.getMessage(), e);
- } catch (InvocationTargetException e) {
- log.error("could not obtain beanInfo for " + valueClass.getClass() + ", reason : " + e.getMessage(), e);
- } catch (IllegalAccessException e) {
- log.error("could not obtain beanInfo for " + valueClass.getClass() + ", reason : " + e.getMessage(), e);
- }
- } else {
- //fixme : conversion failed, we should be able to notify ui that values has changed ?
- // otherwise, bean value has not changed,...
- }
- }
-
- static EventSetDescriptor getPropertyChangeListenerDescriptor(Class beanClass) {
- try {
- // check that the bean is listenable, otherwise, can't use
- // the validator on it
- BeanInfo infos = Introspector.getBeanInfo(beanClass);
- EventSetDescriptor[] events = infos.getEventSetDescriptors();
- for (EventSetDescriptor event : events) {
- if ("propertyChange".equals(event.getName())) {
-
- if (event.getAddListenerMethod() == null) {
- // no property event listener, so can not use the validator
- throw new IllegalStateException("no addPropertyChangeListener method found for " + beanClass);
- }
- if (event.getRemoveListenerMethod() == null) {
- // no property event listener, so can not use the validator
- throw new IllegalStateException("no removePropertyChangeListener method found for " + beanClass);
- }
- return event;
- }
- }
-
- // no property event listener, so can not use the validator
- throw new IllegalStateException("no PropertyChangeListener access method found for " + beanClass);
- } catch (IntrospectionException ex) {
- throw new IllegalStateException("could not acquire PropertyChangeListener bean info for " + beanClass + " for reason " + ex.getMessage(), ex);
- }
- }
-
-}
Modified: jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/BeanValidatorTest.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/BeanValidatorTest.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/BeanValidatorTest.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -15,8 +15,8 @@
public class BeanValidatorTest {
/** to use log facility, just put in your code: log.info(\"...\"); */
- static protected final Log log = LogFactory.getLog(BeanValidator2.class);
- protected BeanValidator2<SimpleBean> validator;
+ static protected final Log log = LogFactory.getLog(BeanValidator.class);
+ protected BeanValidator<SimpleBean> validator;
protected SimpleBean bean;
BeanValidatorListenerImpl errorListener;
BeanValidatorListenerImpl warningListener;
@@ -25,7 +25,7 @@
@Before
public void setUp() {
bean = new SimpleBean();
- validator = new BeanValidator2<SimpleBean>(SimpleBean.class, null);
+ validator = new BeanValidator<SimpleBean>(SimpleBean.class, null);
validator.addBeanValidatorListener(errorListener = new BeanValidatorListenerImpl(BeanValidatorScope.ERROR));
validator.addBeanValidatorListener(warningListener = new BeanValidatorListenerImpl(BeanValidatorScope.WARNING));
validator.addBeanValidatorListener(infoListener = new BeanValidatorListenerImpl(BeanValidatorScope.INFO));
Modified: jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/AbstractFieldValidatorTest.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/AbstractFieldValidatorTest.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/AbstractFieldValidatorTest.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,7 +1,7 @@
package jaxx.runtime.validator.field;
import java.io.File;
-import jaxx.runtime.validator.BeanValidator2;
+import jaxx.runtime.validator.BeanValidator;
import jaxx.runtime.validator.BeanValidatorField;
import jaxx.runtime.validator.ValidatorBean;
import org.apache.commons.logging.Log;
@@ -23,7 +23,7 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private final Log log = LogFactory.getLog(AbstractFieldValidatorTest.class);
- static protected BeanValidator2<ValidatorBean> validator;
+ static protected BeanValidator<ValidatorBean> validator;
static protected File basedir;
protected ValidatorBean bean;
@@ -53,7 +53,7 @@
b = new File("").getAbsolutePath();
}
basedir = new File(b);
- validator = new BeanValidator2<ValidatorBean>(ValidatorBean.class, null);
+ validator = new BeanValidator<ValidatorBean>(ValidatorBean.class, null);
}
protected void assertFieldInError(String fieldName, String error, boolean required) {
Modified: jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,4 +1,5 @@
-1.3 chemit 20090320
+1.3 chemit 20090321
+ * 20090320 [chemit] - rename and move SwingValidationUtil to jaxx.runtime.SwingValidatorUtil
* 20090319 [chemit] - refactor Validator : now can deal with scopes, improve design
1.1 chemit 20090220
Modified: jaxx/trunk/jaxx-runtime-validator-swing/pom.xml
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/pom.xml 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/pom.xml 2009-03-21 16:13:18 UTC (rev 1275)
@@ -25,6 +25,11 @@
<artifactId>jaxx-runtime-validator</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jaxx-runtime-swing</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
Added: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/SwingValidatorUtil.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/SwingValidatorUtil.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/SwingValidatorUtil.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -0,0 +1,175 @@
+package jaxx.runtime;
+
+import jaxx.runtime.validator.*;
+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 javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import jaxx.runtime.validator.swing.SwingValidatorMessageTableMouseListener;
+import jaxx.runtime.validator.swing.SwingValidatorMessageListMouseListener;
+import jaxx.runtime.validator.swing.SwingValidatorMessage;
+import org.codelutin.i18n.I18n;
+
+/**
+ * The helper class for validation module.
+ *
+ * @author chemit
+ */
+public class SwingValidatorUtil extends BeanValidatorUtil {
+
+ static ImageIcon errorIcon;
+ static ImageIcon warningIcon;
+ static ImageIcon infoIcon;
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private final Log log = LogFactory.getLog(SwingValidatorUtil.class);
+
+ public static ImageIcon getErrorIcon() {
+ if (errorIcon == null) {
+ errorIcon = jaxx.runtime.Util.createImageIcon("error.png");
+ }
+ return errorIcon;
+ }
+
+ public static ImageIcon getInfoIcon() {
+ if (infoIcon == null) {
+ infoIcon = jaxx.runtime.Util.createImageIcon("info.png");
+ }
+ return infoIcon;
+ }
+
+ public static ImageIcon getWarningIcon() {
+ if (warningIcon == null) {
+ warningIcon = jaxx.runtime.Util.createImageIcon("warning.png");
+ }
+ return warningIcon;
+ }
+
+ protected SwingValidatorUtil() {
+ // no instance
+ }
+
+ /**
+ * Register for a given validator list ui a validator mouse listener.
+ *
+ * Note: there is only one listener registred for a given list model, so
+ * invoking this method tiwce or more will have no effect.
+ *
+ * @param list the validation ui list
+ * @return the listener instanciate or found
+ * @see SwingValidatorMessageListMouseListener
+ */
+ public static SwingValidatorMessageListMouseListener registerErrorListMouseListener(JList list) {
+ SwingValidatorMessageListMouseListener listener = getErrorListMouseListener(list);
+
+ if (listener != null) {
+ return listener;
+ }
+ listener = new SwingValidatorMessageListMouseListener();
+ if (log.isDebugEnabled()) {
+ log.debug(listener.toString());
+ }
+ list.addMouseListener(listener);
+ return listener;
+ }
+
+ /**
+ * Register for a given validator table ui a validator mouse listener
+ *
+ * Note: there is onlt one listener registred for a givne table model, so
+ * invokin this method twice or more will have no effect.
+ *
+ * @param table the validator table ui
+ * @return the listener instanciate or found
+ * @see SwingValidatorMessageTableMouseListener
+ */
+ public static SwingValidatorMessageTableMouseListener registerErrorTableMouseListener(JTable table) {
+ SwingValidatorMessageTableMouseListener listener = getErrorTableMouseListener(table);
+
+ if (listener != null) {
+ return listener;
+ }
+ listener = new SwingValidatorMessageTableMouseListener();
+ if (log.isDebugEnabled()) {
+ log.debug(listener.toString());
+ }
+ table.addMouseListener(listener);
+ return listener;
+ }
+
+ /**
+ * @param list the validator list ui
+ * @return the validator list mouse listener, or <code>null</code> if not found
+ * @see SwingValidatorMessageListMouseListener
+ */
+ public static SwingValidatorMessageListMouseListener getErrorListMouseListener(JList list) {
+ if (list != null) {
+ for (MouseListener listener : list.getMouseListeners()) {
+ if (listener instanceof SwingValidatorMessageTableMouseListener) {
+ return (SwingValidatorMessageListMouseListener) listener;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @param table the validator table ui
+ * @return the validator table mouse listener, or <code>null</code> if not found
+ * @see SwingValidatorMessageTableMouseListener
+ */
+ public static SwingValidatorMessageTableMouseListener getErrorTableMouseListener(JTable table) {
+ if (table != null) {
+ for (MouseListener listener : table.getMouseListeners()) {
+ if (listener instanceof SwingValidatorMessageTableMouseListener) {
+ return (SwingValidatorMessageTableMouseListener) listener;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static String getMessage(SwingValidatorMessage model) {
+ String text = model.getMessage();
+ if (model.getField()!=null) {
+ text = model.getField().getI18nError(text);
+ }
+ return text;
+ }
+
+ public static String getFieldName(SwingValidatorMessage model, String value) {
+ String text = null;
+ JComponent editor = model.getEditor();
+ if (editor != null) {
+ String l = (String) editor.getClientProperty("validatorLabel");
+ if (l != null) {
+ text = I18n._(l);
+ } else {
+ // TODO should try the text
+ }
+ }
+ if (text == null) {
+ text = value;
+ }
+ return text;
+ }
+
+ public static ImageIcon getIcon(BeanValidatorScope scope) {
+ ImageIcon icon = null;
+ switch (scope) {
+ case ERROR:
+ icon = getErrorIcon();
+ break;
+ case WARNING:
+ icon = getWarningIcon();
+ break;
+ case INFO:
+ icon = getInfoIcon();
+ break;
+ }
+ return icon;
+ }
+}
\ No newline at end of file
Deleted: 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 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/SwingValidationUtil.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,65 +0,0 @@
-package jaxx.runtime.validator;
-
-
-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 jaxx.runtime.validator.swing.SwingValidatorMessageTableMouseListener;
-import jaxx.runtime.validator.swing.SwingValidatorMessageListMouseListener;
-
-/**
- * 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 SwingValidatorMessageListMouseListener) {
- // already have a such listener
- log.info("already registered a such MouseListener : " + listener);
- return;
- }
- }
- list.addMouseListener(new SwingValidatorMessageListMouseListener());
- }
-
- public static void registerErrorTableMouseListener(JTable table) {
- if (table == null) {
- return;
- }
- for (MouseListener listener : table.getMouseListeners()) {
- if (listener instanceof SwingValidatorMessageTableMouseListener) {
- // already have a such listener
- log.info("already registered a such MouseListener : " + listener);
- return;
- }
- }
- table.addMouseListener(new SwingValidatorMessageTableMouseListener());
- }
-
- public SwingValidatorMessageTableMouseListener getErrorTableMouseListener(JTable table) {
- if (table != null) {
- for (MouseListener listener : table.getMouseListeners()) {
- if (listener instanceof SwingValidatorMessageTableMouseListener) {
- return (SwingValidatorMessageTableMouseListener) listener;
- }
- }
- }
- return null;
- }
-}
\ No newline at end of file
Modified: 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/SwingValidator.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,6 +1,5 @@
package jaxx.runtime.validator.swing;
-
import jaxx.runtime.validator.swing.ui.AbstractBeanValidatorUI;
import jaxx.runtime.validator.swing.ui.IconValidationUI;
import org.apache.commons.logging.Log;
@@ -15,10 +14,9 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-import jaxx.runtime.validator.BeanValidator2;
+import jaxx.runtime.validator.BeanValidator;
import jaxx.runtime.validator.BeanValidatorField;
-
/**
* La surcharge de {@link jaxx.runtime.validator.BeanValidator} pour les ui swing
* <p/>
@@ -96,31 +94,40 @@
* @author chemit
* @version 1.0
*/
-public class SwingValidator<B> extends BeanValidator2<B> {
+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 SwingValidatorMessageListModel errorListModel;
-
/** Object servant a contenir la liste des erreurs */
protected SwingValidatorMessageTableModel errorTableModel;
-
/** ui renderer class */
protected Class<? extends AbstractBeanValidatorUI> uiClass;
-
public SwingValidator(Class<B> beanClass, String contextName) {
super(beanClass, contextName);
fieldRepresentation = new HashMap<String, JComponent>();
}
+ /**
+ * To reload a bean in the validator.
+ *
+ * This method is used to reload ui, since some editors
+ * could not exist when validator is init, so some messages
+ * should not be attached to an editor.
+ */
+ public void reloadBean() {
+ B b = getBean();
+ if (b != null) {
+ setBean(null);
+ setBean(b);
+ }
+ }
+
public JComponent getFieldRepresentation(String fieldname) {
return fieldRepresentation.get(fieldname);
}
@@ -154,27 +161,27 @@
/*Map<ValidatorField<B>, List<ValidatorErrorListener>> oldListeners = new HashMap<ValidatorField<B>, List<ValidatorErrorListener>>();
for (ValidatorField<B> field : fields) {
- ValidatorErrorListener[] listeners = field.getValidatorErrorListeners();
- List<ValidatorErrorListener> toReinject = new ArrayList<ValidatorErrorListener>();
- for (ValidatorErrorListener listener : listeners) {
- if (listener instanceof AbstractBeanValidatorUI) {
- // this listener will be reinject via installUIs method
- continue;
- }
- toReinject.add(listener);
- }
- oldListeners.put(field, toReinject);
+ ValidatorErrorListener[] listeners = field.getValidatorErrorListeners();
+ List<ValidatorErrorListener> toReinject = new ArrayList<ValidatorErrorListener>();
+ for (ValidatorErrorListener listener : listeners) {
+ if (listener instanceof AbstractBeanValidatorUI) {
+ // this listener will be reinject via installUIs method
+ continue;
+ }
+ toReinject.add(listener);
+ }
+ oldListeners.put(field, toReinject);
}*/
super.setContextName(contextName);
// must reinstall ui
installUIs();
// reinject none ui listeners
/*for (Entry<ValidatorField<B>, List<ValidatorErrorListener>> entry : oldListeners.entrySet()) {
- ValidatorField<B> field = getField(entry.getKey().getName());
- for (ValidatorErrorListener listener : entry.getValue()) {
- field.addValidatorErrorListener(listener);
- }
+ ValidatorField<B> field = getField(entry.getKey().getName());
+ for (ValidatorErrorListener listener : entry.getValue()) {
+ field.addValidatorErrorListener(listener);
}
+ }
oldListeners.clear();*/
}
@@ -213,6 +220,7 @@
/** install ui on required components */
public void installUIs() {
SwingUtilities.invokeLater(new Runnable() {
+
@Override
public void run() {
if (uiClass == null) {
@@ -249,9 +257,9 @@
JXLayer<?> jx = (JXLayer<?>) container;
Object ui = jx.getUI();
if (ui != null && ui instanceof AbstractBeanValidatorUI) {
- removeBeanValidatorListener((AbstractBeanValidatorUI)ui);
+ removeBeanValidatorListener((AbstractBeanValidatorUI) ui);
}
-
+
jx.setUI(null);
}
}
@@ -268,6 +276,4 @@
}
}
}
-
-
}
Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessage.java (from rev 1274, jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageModel.java)
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessage.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessage.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -0,0 +1,66 @@
+package jaxx.runtime.validator.swing;
+
+import javax.swing.JComponent;
+import jaxx.runtime.validator.BeanValidatorField;
+import jaxx.runtime.validator.BeanValidatorMessage;
+import jaxx.runtime.validator.BeanValidatorScope;
+
+/**
+ * The object to box a validation message within an u.
+ *
+ * @author chemit
+ * @since 1.3
+ * @see BeanValidatorMessage
+ */
+public class SwingValidatorMessage extends BeanValidatorMessage<SwingValidatorMessage> {
+
+ /**
+ * the optional field's editor
+ */
+ protected JComponent editor;
+ protected String fieldName;
+
+ public SwingValidatorMessage(SwingValidator validator, BeanValidatorField field, String message, BeanValidatorScope scope, JComponent editor) {
+ super(validator, field, message, scope);
+ this.fieldName = field.getName();
+ this.editor = editor;
+ }
+
+ public SwingValidatorMessage(SwingValidator validator, String fieldName, String message, BeanValidatorScope scope, JComponent editor) {
+ super(validator, null, message, scope);
+ this.fieldName = fieldName;
+ this.editor = editor;
+ }
+
+ public JComponent getEditor() {
+ return editor;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ @Override
+ public int compareTo(SwingValidatorMessage o) {
+ // sort on scope
+ int result = getScope().compareTo(o.getScope());
+ if (result == 0) {
+ // sort on field name
+ result = fieldName.compareTo(o.getFieldName());
+ if (result == 0) {
+ // sort on message
+ result = message.compareTo(o.getMessage());
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ String s = scope + " - " + (field == null ? message : field.getI18nError(message));
+ if (editor == null) {
+ return s;
+ }
+ return editor.getName() + " : " + s;
+ }
+}
Modified: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -2,13 +2,10 @@
import jaxx.runtime.validator.BeanValidatorEvent;
-import javax.swing.DefaultListModel;
import javax.swing.JComponent;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.List;
import jaxx.runtime.validator.BeanValidatorField;
-import jaxx.runtime.validator.BeanValidatorListener;
import jaxx.runtime.validator.BeanValidatorScope;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -18,18 +15,27 @@
*
* @author chemit
*/
-public class SwingValidatorMessageListModel extends DefaultListModel implements BeanValidatorListener {
+public class SwingValidatorMessageListModel
+ extends javax.swing.AbstractListModel
+ implements jaxx.runtime.validator.BeanValidatorListener {
+ private static final long serialVersionUID = 1L;
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(SwingValidatorMessageListModel.class);
- private static final long serialVersionUID = 1L;
/** list of registred validators */
protected transient List<SwingValidator<?>> validators;
+ /** list of messages actual displayed */
+ protected List<SwingValidatorMessage> data;
public SwingValidatorMessageListModel() {
validators = new ArrayList<SwingValidator<?>>();
+ data = new java.util.ArrayList<SwingValidatorMessage>();
}
+ public boolean isEmpty() {
+ return getSize() == 0;
+ }
+
public void registerValidator(SwingValidator<?> validator) {
if (validators.contains(validator)) {
throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
@@ -39,97 +45,90 @@
}
@Override
+ public int getSize() {
+ return data.size();
+ }
+
+ @Override
+ public Object getElementAt(int index) {
+ ensureRowIndex(index);
+ return data.get(index);
+ }
+
+ @Override
public void onFieldChanged(BeanValidatorEvent event) {
String[] toDelete = event.getMessagesToDelete();
String[] toAdd = event.getMessagesToAdd();
- BeanValidatorScope scope = event.getScope();
- SwingValidator validator = (SwingValidator) event.getSource();
BeanValidatorField field = event.getField();
+ BeanValidatorScope scope = event.getScope();
+ boolean mustAdd = toAdd != null && toAdd.length > 0;
+ boolean mustDel = toDelete != null && toDelete.length > 0;
if (log.isTraceEnabled()) {
log.trace("----------------------------------------------------------");
- log.trace(field + " - (" + getSize() + ") toAdd " + (toAdd == null ? null : toAdd.length));
- log.trace(field + " - (" + getSize() + ") toDelete " + (toDelete == null ? null : toDelete.length));
+ log.trace(field + " - (" + getSize() + ") toAdd " + mustAdd);
+ log.trace(field + " - (" + getSize() + ") toDelete " + mustDel);
}
- if ((toAdd == null || toAdd.length == 0) && (toDelete == null || toDelete.length == 0)) {
- // no data to add nor remove, so nothing to do
- return;
- }
+ SwingValidator validator = (SwingValidator) event.getSource();
- if (toAdd == null || toAdd.length == 0) {
+ if (mustDel) {
- if (log.isTraceEnabled()) {
- log.trace(field + " - toDelete : just delete some datas!");
- }
+ // removes datas and notify if no messages to add
+ removeMessages(validator, field, scope, !mustAdd, toDelete);
+ }
- // no add, no need to resort the datas, can direclty delete
- // messages we do not want any longer
+ if (mustAdd) {
- // delete some messages for the given field and given scope
- List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
- List<Integer> indexs = new java.util.ArrayList<Integer>(toDelete.length);
+ // add new messages, sort datas and notify
+ addMessages(validator, field, scope, true, toAdd);
+ }
+ }
- Enumeration enumeration = elements();
- int index = 0;
- while (enumeration.hasMoreElements()) {
- SwingValidatorMessageModel error = (SwingValidatorMessageModel) enumeration.nextElement();
+ protected void ensureRowIndex(int index) throws ArrayIndexOutOfBoundsException {
+ if (index < -1 || index >= getSize()) {
+ throw new ArrayIndexOutOfBoundsException("the rowIndex was " + index + ", but should be int [0," + (getSize() - 1) + "]");
+ }
+ }
- if (error.getValidator() == validator && error.getField() == field && ids.contains(error.getMessage())) {
- indexs.add(index);
- }
- index++;
- }
+ protected void addMessages(SwingValidator validator, BeanValidatorField field, BeanValidatorScope scope, boolean sort, String... messages) {
- java.util.Collections.reverse(indexs);
-
- for (Integer i : indexs) {
- removeElementAt(i);
+ JComponent editor = validator.getFieldRepresentation(field.getName());
+ // add new errors
+ for (String error : messages) {
+ SwingValidatorMessage row = new SwingValidatorMessage(validator, field, error, scope, editor);
+ data.add(row);
+ if (!sort) {
+ fireIntervalAdded(this, data.size() - 1, data.size() - 1);
}
-
- return;
}
- if (log.isTraceEnabled()) {
- log.trace(field + " - add and delete !");
- }
+ if (sort) {
- List<SwingValidatorMessageModel> newMessages = new ArrayList<SwingValidatorMessageModel>();
+ // resort datas
+ java.util.Collections.sort(data);
+ // notify
+ fireContentsChanged(this, 0, getSize() - 1);
+ }
+ }
+ protected void removeMessages(SwingValidator validator, BeanValidatorField field, BeanValidatorScope scope, boolean notify, String... messages) {
- // obtain all messages not to delete
+ List<String> messagesToDel = new java.util.ArrayList<String>(java.util.Arrays.asList(messages));
- List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
+ // do it in reverse mode (only one pass in that way since index
+ // will stay coherent while removing them)
- Enumeration enumeration = elements();
- while (enumeration.hasMoreElements()) {
- SwingValidatorMessageModel error = (SwingValidatorMessageModel) enumeration.nextElement();
-
- if (error.getValidator() != validator || error.getField() != field || !ids.contains(error.getMessage())) {
- // keep this row
- newMessages.add(error);
+ for (int i = getSize() - 1; i > -1; i--) {
+ SwingValidatorMessage error = data.get(i);
+ if (error.getValidator() == validator && error.getScope() == scope && error.getField() == field && messagesToDel.contains(error.getMessage())) {
+ // remove the message
+ data.remove(i);
+ if (notify) {
+ fireIntervalRemoved(this, i, i);
+ }
}
}
-
- if (toAdd != null && toAdd.length > 0) {
- JComponent editor = validator.getFieldRepresentation(field.getName());
- // add new messages
- for (String error : toAdd) {
- newMessages.add(new SwingValidatorMessageModel(validator, field, error, editor));
- }
- }
-
- // sort datas
-
- java.util.Collections.sort(newMessages);
-
- // clean model and reinject new errors
- removeAllElements();
-
- // reinject in list model, all the errors
- for (SwingValidatorMessageModel error : newMessages) {
- addElement(error);
- }
- }
+ }
}
Modified: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListMouseListener.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListMouseListener.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListMouseListener.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -25,7 +25,7 @@
super.mouseClicked(e);
if (e.getClickCount() == 2) {
- SwingValidatorMessageModel entry = getSelectedError(e);
+ SwingValidatorMessage entry = getSelectedMessage(e);
if (entry == null) {
// no entry found
return;
@@ -37,8 +37,7 @@
}
}
-
- protected SwingValidatorMessageModel getSelectedError(MouseEvent e) {
+ protected SwingValidatorMessage getSelectedMessage(MouseEvent e) {
JList list = (JList) e.getSource();
if (!(list.getModel() instanceof SwingValidatorMessageListModel)) {
log.warn("model must be a " + SwingValidatorMessageListModel.class + ", but was " + list.getModel());
@@ -51,7 +50,7 @@
// nothing is selected
return null;
}
- SwingValidatorMessageModel entry = (SwingValidatorMessageModel) model.getElementAt(index);
+ SwingValidatorMessage entry = (SwingValidatorMessage) model.getElementAt(index);
if (log.isDebugEnabled()) {
log.debug("selected index: " + index + " : error: " + entry);
}
Added: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListRenderer.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListRenderer.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListRenderer.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -0,0 +1,80 @@
+package jaxx.runtime.validator.swing;
+
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import java.awt.Component;
+import javax.swing.DefaultListCellRenderer;
+import jaxx.runtime.validator.BeanValidatorScope;
+import jaxx.runtime.SwingValidatorUtil;
+
+/**
+ * A simple render of a table of validator's messages, says a table that use
+ * a {@link SwingValidatorMessageTableModel} model.
+ *
+ * @author chemit
+ * @since 1.3
+ * @see SwingValidatorMessageTableModel
+ */
+public class SwingValidatorMessageListRenderer extends DefaultListCellRenderer {
+
+ private static final long serialVersionUID = 1L;
+ protected String format = "%1$-20s - %2$s";
+
+ public SwingValidatorMessageListRenderer() {
+ }
+
+ public SwingValidatorMessageListRenderer(String format) {
+ this.format = format;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+
+ JLabel rendererComponent = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+
+ SwingValidatorMessage model = (SwingValidatorMessage) value;
+
+ // scope
+ ImageIcon icon = SwingValidatorUtil.getIcon(model.getScope());
+
+ // field name
+ String fieldName = getFieldName(list, model.getField().getName(), index);
+
+ // message
+ String message = getMessage(model);
+
+ // text to display
+ String text = String.format(format, fieldName, message);
+
+ rendererComponent.setText(text);
+ rendererComponent.setIcon(icon);
+
+ return rendererComponent;
+ }
+
+ public ImageIcon getIcon(BeanValidatorScope scope) {
+ ImageIcon icon = SwingValidatorUtil.getIcon(scope);
+ return icon;
+ }
+
+ public String getMessage(SwingValidatorMessage model) {
+ String text = SwingValidatorUtil.getMessage(model);
+ return text;
+ }
+
+ public String getFieldName(JList list, String value, int row) {
+ SwingValidatorMessageListModel tableModel = (SwingValidatorMessageListModel) list.getModel();
+ SwingValidatorMessage model = (SwingValidatorMessage) tableModel.getElementAt(row);
+ String fieldName = SwingValidatorUtil.getFieldName(model, value);
+ return fieldName;
+ }
+}
\ No newline at end of file
Deleted: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageModel.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageModel.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,75 +0,0 @@
-package jaxx.runtime.validator.swing;
-
-import javax.swing.JComponent;
-import jaxx.runtime.validator.BeanValidatorField;
-
-/**
- * The object to box a validation message within an u.
- *
- * @author chemit
- * @since 1.3
- */
-public class SwingValidatorMessageModel implements Comparable<SwingValidatorMessageModel> {
-
- /**
- * the validator that produce the message
- */
- protected SwingValidator validator;
- /**
- * the field thatproduce the message
- */
- protected BeanValidatorField field;
- /**
- * the label of the message (to be displayed somewhere)
- */
- protected String message;
- /**
- * the optional field's editor
- */
- protected JComponent editor;
-
- public SwingValidatorMessageModel(SwingValidator validator, BeanValidatorField field, String message, JComponent editor) {
- this.field = field;
- this.validator = validator;
- this.message = message;
- this.editor = editor;
- }
-
- public JComponent getEditor() {
- return editor;
- }
-
- public SwingValidator getValidator() {
- return validator;
- }
-
- public BeanValidatorField getField() {
- return field;
- }
-
- public String getMessage() {
- return message;
- }
-
- @Override
- public int compareTo(SwingValidatorMessageModel o) {
- int result = field.getScope().compareTo(o.field.getScope());
- if (result != 0) {
- return result;
- }
- result = field.getName().compareTo(o.field.getName());
- if (result != 0) {
- return result;
- }
- result = message.compareTo(o.message);
- return result;
- }
-
- @Override
- public String toString() {
- if (editor == null) {
- return field.getI18nError(message);
- }
- return editor.getName() + " : " + field.getI18nError(message);
- }
-}
Modified: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -3,156 +3,317 @@
import jaxx.runtime.validator.BeanValidatorEvent;
import javax.swing.JComponent;
-import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Enumeration;
import java.util.List;
-import java.util.Vector;
import jaxx.runtime.validator.BeanValidatorField;
-import jaxx.runtime.validator.BeanValidatorListener;
+import jaxx.runtime.validator.BeanValidatorScope;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * The model of the list of errors
+ * The model of the table of errors.
*
+ * The model listens validators messages and update his internal model from it.
+ *
* @author chemit
+ * @since 1.3
*/
-public class SwingValidatorMessageTableModel extends DefaultTableModel implements BeanValidatorListener {
+public class SwingValidatorMessageTableModel
+ extends javax.swing.table.AbstractTableModel
+ implements jaxx.runtime.validator.BeanValidatorListener {
+ private static final long serialVersionUID = 1L;
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(SwingValidatorMessageTableMouseListener.class);
- private static final long serialVersionUID = 1L;
public static final String[] columnNames = {"validator.scope", "validator.field", "validator.message"};
+ public static final Class<?>[] columnClasses = {BeanValidatorScope.class, String.class, String.class};
/** list of registred validators */
protected transient List<SwingValidator<?>> validators;
- /** comporator of errors */
- protected transient Comparator<SwingValidatorMessageModel> comparator;
+ /** list of messages actual displayed */
+ protected List<SwingValidatorMessage> data;
public SwingValidatorMessageTableModel() {
- super(columnNames, 0);
+ super();
validators = new ArrayList<SwingValidator<?>>();
+ data = new java.util.ArrayList<SwingValidatorMessage>();
}
- public int getErrorColumn() {
- return findColumn(columnNames[2]);
+ /**
+ * Register a validator for this model.
+ *
+ *
+ * Note: a validator can not be register twice in the same model.
+ *
+ * @param validator the validator to register
+ */
+ public void registerValidator(SwingValidator<?> validator) {
+ if (validators.contains(validator)) {
+ throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
+ }
+ validators.add(validator);
+ validator.addBeanValidatorListener(this);
}
+ public void addMessages(SwingValidator validator, String fieldName, BeanValidatorScope scope, String... messages) {
+ addMessages(validator, fieldName, scope, true, messages);
+ }
+
+ public void addMessages(JComponent editor, String fieldName, BeanValidatorScope scope, String... messages) {
+ addMessages(editor, fieldName, scope, true, messages);
+ }
+
+ public void addMessages(SwingValidator validator, BeanValidatorField field, BeanValidatorScope scope, String... messages) {
+ addMessages(validator, field, scope, true, messages);
+ }
+
+ public void removeMessages(JComponent editor, BeanValidatorScope scope) {
+
+ // do it in reverse mode (only one pass in that way since index
+ // will stay coherent while removing them)
+
+ for (int i = getRowCount() - 1; i > -1; i--) {
+ SwingValidatorMessage error = data.get(i);
+ if (error.getEditor() == editor && (scope == null || error.getScope() == scope)) {
+ // remove the message
+ data.remove(i);
+ fireTableRowsDeleted(i, i);
+ }
+ }
+ }
+
+ public void removeMessages(SwingValidator validator, String fieldName, BeanValidatorScope scope, String... messages) {
+ removeMessages(validator, fieldName, scope, true, messages);
+ }
+
+ public void removeMessages(JComponent editor, String fieldName, BeanValidatorScope scope) {
+ removeMessages(editor, fieldName, scope, true);
+ }
+
+ public void removeMessages(SwingValidator validator, BeanValidatorField field, BeanValidatorScope scope, String... messages) {
+ removeMessages(validator, field, scope, true, messages);
+ }
+
+ /**
+ * Obtain the message for a given row.
+ *
+ * @param rowIndex the row index
+ * @return the message for the given row index
+ */
+ public SwingValidatorMessage getRow(int rowIndex) {
+ ensureRowIndex(rowIndex);
+ return data.get(rowIndex);
+ }
+
@Override
public boolean isCellEditable(int row, int column) {
// cells are never editable in this model
return false;
}
- public void registerValidator(SwingValidator<?> validator) {
- if (validators.contains(validator)) {
- throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
- }
- validators.add(validator);
- validator.addBeanValidatorListener(this);
+ @Override
+ public Class<?> getColumnClass(int columnIndex) {
+ ensureColumnIndex(columnIndex);
+ return columnClasses[columnIndex];
}
@Override
+ public String getColumnName(int column) {
+ ensureColumnIndex(column);
+ return columnNames[column];
+ }
+
+ @Override
public void onFieldChanged(BeanValidatorEvent event) {
String[] toDelete = event.getMessagesToDelete();
String[] toAdd = event.getMessagesToAdd();
BeanValidatorField field = event.getField();
+ BeanValidatorScope scope = event.getScope();
+ boolean mustAdd = toAdd != null && toAdd.length > 0;
+ boolean mustDel = toDelete != null && toDelete.length > 0;
if (log.isTraceEnabled()) {
log.trace("----------------------------------------------------------");
- log.trace(field + " - (" + getRowCount() + ") toAdd " + (toAdd == null ? null : toAdd.length));
- log.trace(field + " - (" + getRowCount() + ") toDelete " + (toDelete == null ? null : toDelete.length));
+ log.trace(field + " - (" + getRowCount() + ") toAdd " + mustAdd);
+ log.trace(field + " - (" + getRowCount() + ") toDelete " + mustDel);
}
- if ((toAdd == null || toAdd.length == 0) && (toDelete == null || toDelete.length == 0)) {
- // no data to add nor remove, so nothing to do
- return;
- }
SwingValidator validator = (SwingValidator) event.getSource();
+ if (mustDel) {
- int errorColumn = getErrorColumn();
+ // removes datas and notify if no messages to add
+ removeMessages(validator, field, scope, !mustAdd, toDelete);
+ }
- if (toAdd == null || toAdd.length == 0) {
+ if (mustAdd) {
+ // add new messages, sort datas and notify
+ addMessages(validator, field, scope, true, toAdd);
+ }
+ }
- if (log.isTraceEnabled()) {
- log.trace(field + " - toDelete : just delete some datas!");
- }
+ @Override
+ public int getRowCount() {
+ return data.size();
+ }
- // no add, no need to resort the datas, can direclty delete
- // messages we do not want any longer
+ @Override
+ public int getColumnCount() {
+ return columnNames.length;
+ }
- // delete some messages for the given field and given scope
- List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
- List<Integer> indexs = new java.util.ArrayList<Integer>(toDelete.length);
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ ensureColumnIndex(columnIndex);
+ ensureRowIndex(rowIndex);
- Enumeration enumeration = getDataVector().elements();
+ SwingValidatorMessage row = data.get(rowIndex);
+ if (columnIndex == 0) {
+ // the icon
+ return row.getScope();
+ }
+ if (columnIndex == 1) {
+ // the field
+ return row.getFieldName();
+ }
+ if (columnIndex == 2) {
+ // the message
+ return row.getMessage();
+ }
- int index = 0;
- while (enumeration.hasMoreElements()) {
- Vector row = (Vector) enumeration.nextElement();
- SwingValidatorMessageModel error = (SwingValidatorMessageModel) row.get(errorColumn);
- if (error.getValidator() == validator && error.getField() == field && ids.contains(error.getMessage())) {
- // remo the message
- indexs.add(index);
- }
- index++;
- }
- java.util.Collections.reverse(indexs);
+ // should never come here
+ return null;
+ }
- for (Integer i : indexs) {
- removeRow(i);
+ protected void ensureRowIndex(int rowIndex) throws ArrayIndexOutOfBoundsException {
+ if (rowIndex < -1 || rowIndex >= getRowCount()) {
+ throw new ArrayIndexOutOfBoundsException("the rowIndex was " + rowIndex + ", but should be int [0," + (getRowCount() - 1) + "]");
+ }
+ }
+
+ protected void ensureColumnIndex(int index) throws ArrayIndexOutOfBoundsException {
+ if (index < -1 || index >= getColumnCount()) {
+ throw new ArrayIndexOutOfBoundsException("the columnIndex was " + index + ", but should be int [0," + (getColumnCount() - 1) + "]");
+ }
+ }
+
+ protected void addMessages(SwingValidator validator, BeanValidatorField field, BeanValidatorScope scope, boolean sort, String... messages) {
+
+ JComponent editor = validator == null ? null : validator.getFieldRepresentation(field.getName());
+ // add new errors
+ for (String error : messages) {
+ SwingValidatorMessage row = new SwingValidatorMessage(validator, field, error, scope, editor);
+ data.add(row);
+ if (!sort) {
+ fireTableRowsInserted(data.size() - 1, data.size() - 1);
}
+ }
- return;
+ if (sort) {
+
+ // resort datas
+ java.util.Collections.sort(data);
+
+ // notify
+ fireTableDataChanged();
}
+ }
- if (log.isTraceEnabled()) {
- log.trace(field + " - add and delete !");
+ protected void addMessages(SwingValidator validator, String fieldName, BeanValidatorScope scope, boolean sort, String... messages) {
+
+ JComponent editor = validator == null ? null : validator.getFieldRepresentation(fieldName);
+ // add new errors
+ for (String error : messages) {
+ SwingValidatorMessage row = new SwingValidatorMessage(validator, fieldName, error, scope, editor);
+ data.add(row);
+ if (!sort) {
+ fireTableRowsInserted(data.size() - 1, data.size() - 1);
+ }
}
- // rebuild all the data (since we are some adding data and we ensure
- // an order on datas)
+ if (sort) {
- List<SwingValidatorMessageModel> newMessages = new ArrayList<SwingValidatorMessageModel>();
+ // resort datas
+ java.util.Collections.sort(data);
- // delete some messages for the given field and given scope
- List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
+ // notify
+ fireTableDataChanged();
+ }
+ }
- Enumeration enumeration = getDataVector().elements();
+ protected void addMessages(JComponent editor, String fieldName, BeanValidatorScope scope, boolean sort, String... messages) {
- while (enumeration.hasMoreElements()) {
- Vector row = (Vector) enumeration.nextElement();
- SwingValidatorMessageModel error = (SwingValidatorMessageModel) row.get(errorColumn);
- if (error.getValidator() != validator || error.getField() != field || !ids.contains(error.getMessage())) {
- // keep this row
- newMessages.add(error);
+ // add new errors
+ for (String error : messages) {
+ SwingValidatorMessage row = new SwingValidatorMessage(null, fieldName, error, scope, editor);
+ data.add(row);
+ if (!sort) {
+ fireTableRowsInserted(data.size() - 1, data.size() - 1);
}
}
- if (toAdd != null && toAdd.length > 0) {
- JComponent editor = validator.getFieldRepresentation(field.getName());
- // add new errors
- for (String error : toAdd) {
- SwingValidatorMessageModel errorModel = new SwingValidatorMessageModel(validator, field, error, editor);
- newMessages.add(errorModel);
+ if (sort) {
+
+ // resort datas
+ java.util.Collections.sort(data);
+
+ // notify
+ fireTableDataChanged();
+ }
+ }
+
+ protected void removeMessages(SwingValidator validator, BeanValidatorField field, BeanValidatorScope scope, boolean notify, String... messages) {
+
+ List<String> messagesToDel = new java.util.ArrayList<String>(java.util.Arrays.asList(messages));
+
+ // do it in reverse mode (only one pass in that way since index
+ // will stay coherent while removing them)
+
+ for (int i = getRowCount() - 1; i > -1; i--) {
+ SwingValidatorMessage error = data.get(i);
+ if (error.getValidator() == validator && error.getScope() == scope && error.getFieldName().equals(field.getName()) && messagesToDel.contains(error.getMessage())) {
+ // remove the message
+ data.remove(i);
+ if (notify) {
+ fireTableRowsDeleted(i, i);
+ }
}
}
+ }
- // sort datas
+ protected void removeMessages(SwingValidator validator, String fieldName, BeanValidatorScope scope, boolean notify, String... messages) {
- java.util.Collections.sort(newMessages);
+ List<String> messagesToDel = new java.util.ArrayList<String>(java.util.Arrays.asList(messages));
- // clean table model and reinject new messages
- getDataVector().clear();
+ // do it in reverse mode (only one pass in that way since index
+ // will stay coherent while removing them)
- // reinject in list model, all the errors
- for (SwingValidatorMessageModel error : newMessages) {
- addRow(new Object[]{error.getField().getScope(), error.getField().getName(), error});
+ for (int i = getRowCount() - 1; i > -1; i--) {
+ SwingValidatorMessage error = data.get(i);
+ if (error.getValidator() == validator && error.getScope() == scope && error.getFieldName().equals(fieldName) && messagesToDel.contains(error.getMessage())) {
+ // remove the message
+ data.remove(i);
+ if (notify) {
+ fireTableRowsDeleted(i, i);
+ }
+ }
}
+ }
- fireTableDataChanged();
+ protected void removeMessages(JComponent editor, String fieldName, BeanValidatorScope scope, boolean notify) {
+
+ // do it in reverse mode (only one pass in that way since index
+ // will stay coherent while removing them)
+
+ for (int i = getRowCount() - 1; i > -1; i--) {
+ SwingValidatorMessage error = data.get(i);
+ if (error.getEditor() == editor && (scope==null || error.getScope() == scope) && error.getFieldName().equals(fieldName)) {
+ // remove the message
+ data.remove(i);
+ if (notify) {
+ fireTableRowsDeleted(i, i);
+ }
+ }
+ }
}
}
\ No newline at end of file
Modified: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableMouseListener.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableMouseListener.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableMouseListener.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -36,7 +36,7 @@
super.mouseClicked(e);
if (e.getClickCount() == 2) {
- SwingValidatorMessageModel entry = getSelectedError(e);
+ SwingValidatorMessage entry = getSelectedMessage(e);
if (entry == null) {
// no entry found
return;
@@ -52,7 +52,7 @@
}
- protected SwingValidatorMessageModel getSelectedError(MouseEvent e) {
+ protected SwingValidatorMessage getSelectedMessage(MouseEvent e) {
JTable table = (JTable) e.getSource();
if (!(table.getModel() instanceof SwingValidatorMessageTableModel)) {
log.warn("model must be a " + SwingValidatorMessageTableModel.class + ", but was " + table.getModel());
@@ -65,8 +65,10 @@
// nothing is selected
return null;
}
- int col = model.getErrorColumn();
- SwingValidatorMessageModel entry = (SwingValidatorMessageModel) model.getValueAt(index, col);
+ if (table.getRowSorter() != null) {
+ index = table.getRowSorter().convertRowIndexToModel(index);
+ }
+ SwingValidatorMessage entry = model.getRow(index);
if (log.isDebugEnabled()) {
log.debug("selected index: " + index + " : error: " + entry);
}
Modified: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableRenderer.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableRenderer.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableRenderer.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -6,56 +6,70 @@
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Component;
import jaxx.runtime.validator.BeanValidatorScope;
+import jaxx.runtime.SwingValidatorUtil;
-/** @author chemit */
+/**
+ * A simple render of a table of validator's messages, says a table that use
+ * a {@link SwingValidatorMessageTableModel} model.
+ *
+ * @author chemit
+ * @since 1.3
+ * @see SwingValidatorMessageTableModel
+ */
public class SwingValidatorMessageTableRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 1L;
- ImageIcon errorIcon;
- ImageIcon warningIcon;
- ImageIcon infoIcon;
- public SwingValidatorMessageTableRenderer() {
- errorIcon = jaxx.runtime.Util.createImageIcon("error.png");
- warningIcon = jaxx.runtime.Util.createImageIcon("warning.png");
- infoIcon = jaxx.runtime.Util.createImageIcon("info.png");
- }
-
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel rendererComponent = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
ImageIcon icon = null;
String text = null;
- if (value instanceof BeanValidatorScope) {
- BeanValidatorScope scope = (BeanValidatorScope) value;
- switch (scope) {
- case ERROR:
- icon = errorIcon;
- break;
- case WARNING:
- icon = warningIcon;
- break;
- case INFO:
- icon = infoIcon;
- break;
- }
- } else if (value instanceof SwingValidatorMessageModel) {
- SwingValidatorMessageModel model = (SwingValidatorMessageModel) value;
- String error = model.getMessage();
- text = model.getField().getI18nError(error);
- } else {
- // keep text rendered
- text = rendererComponent.getText();
+ column = table.convertColumnIndexToModel(column);
+ if (table.getRowSorter() != null) {
+ row = table.getRowSorter().convertRowIndexToModel(row);
}
+
+ switch (column) {
+ case 0:
+ // scope
+ icon = SwingValidatorUtil.getIcon((BeanValidatorScope) value);
+ break;
+
+ case 1:
+ // field name
+ text = getFieldName(table, (String) value, row);
+ break;
+
+ case 2:
+ // message
+ text = getMessage(table, (String) value, row);
+ break;
+ }
+
rendererComponent.setText(text);
rendererComponent.setIcon(icon);
return rendererComponent;
}
- @Override
- protected void setValue(Object value) {
- super.setValue(value);
+ public ImageIcon getIcon(BeanValidatorScope scope) {
+ ImageIcon icon = SwingValidatorUtil.getIcon(scope);
+ return icon;
}
+
+ public String getMessage(JTable table, String value, int row) {
+ SwingValidatorMessageTableModel tableModel = (SwingValidatorMessageTableModel) table.getModel();
+ SwingValidatorMessage model = tableModel.getRow(row);
+ String text = SwingValidatorUtil.getMessage(model);
+ return text;
+ }
+
+ public String getFieldName(JTable table, String value, int row) {
+ SwingValidatorMessageTableModel tableModel = (SwingValidatorMessageTableModel) table.getModel();
+ SwingValidatorMessage model = tableModel.getRow(row);
+ String fieldName = SwingValidatorUtil.getFieldName(model, value);
+ return fieldName;
+ }
}
\ No newline at end of file
Modified: jaxx/trunk/maven-jaxx-plugin/changelog.txt
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-03-21 16:13:18 UTC (rev 1275)
@@ -1,4 +1,4 @@
-1.3 chemit 20090320
+1.3 chemit 20090321
* 20090301 [chemit] - add a profile mode (-Djaxx.profile)
1.2 letelier 2009022?
Modified: jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2009-03-21 08:22:03 UTC (rev 1274)
+++ jaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2009-03-21 16:13:18 UTC (rev 1275)
@@ -281,6 +281,7 @@
protected ClassLoader cl;
private Class<? extends JAXXCompiler> compilerClass;
+ @SuppressWarnings("unchecked")
protected void init() throws ClassNotFoundException, MalformedURLException {
if (project != null && ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()))) {
@@ -353,7 +354,7 @@
}
} else {
if (verbose) {
- getLog().info("jaxx - will generate file [" + file + "].");
+ getLog().info("jaxx - detect modify file [" + file + "].");
}
listFiles.add(file);
}
@@ -430,7 +431,7 @@
}
public void doAction() throws MojoExecutionException {
- getLog().info("jaxx - will generate " + this.files.length + " jaxx file(s). ");
+ getLog().info("jaxx - detects " + this.files.length + " modify jaxx file(s). ");
try {
@@ -438,8 +439,10 @@
TagManager.reset(verbose);
JAXXCompilerLaunchor launchor = JAXXCompilerLaunchor.newLaunchor(src, files, options);
+ boolean success = launchor.compile();
+ getLog().info("jaxx - generate " + launchor.getCompilerCount() + " file(s). ");
- if (!launchor.compile()) {
+ if (!success) {
throw new MojoExecutionException("Aborting due to errors reported by jaxxc");
}
1
0
21 Mar '09
Author: tchemit
Date: 2009-03-21 08:22:03 +0000 (Sat, 21 Mar 2009)
New Revision: 1274
Added:
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListMouseListener.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageModel.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableMouseListener.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableRenderer.java
jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-error-validation.xml
Removed:
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/SwingValidatorErrorListMouseListener.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorModel.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableModel.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableMouseListener.java
jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableRenderer.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorErrorEvent.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorErrorListener.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorField.java
jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-validation.xml
Modified:
jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationListDemo.jaxx
jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx
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/SwingValidator.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorListener.java
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidationUtil.java
jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/AbstractFieldValidatorTest.java
jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorListModel.jaxx
jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorTableModel.jaxx
jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Validation.jaxx
jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/ValidationBeanClass.jaxx
Log:
remplacement des classes swingValidatorError* en SwingValidatorMessage*
Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationListDemo.jaxx
===================================================================
--- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationListDemo.jaxx 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationListDemo.jaxx 2009-03-21 08:22:03 UTC (rev 1274)
@@ -17,7 +17,7 @@
<Identity id='identity'/>
<!-- errors model -->
- <jaxx.runtime.validator.swing.SwingValidatorErrorListModel id='errors'
+ <jaxx.runtime.validator.swing.SwingValidatorMessageListModel id='errors'
onContentsChanged='ok.setEnabled(errors.isEmpty())'/>
<!-- validators -->
Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx
===================================================================
--- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx 2009-03-21 08:22:03 UTC (rev 1274)
@@ -7,7 +7,7 @@
<Identity id='identity'/>
<!-- errors model -->
- <jaxx.runtime.validator.swing.SwingValidatorErrorTableModel id='errors2'
+ <jaxx.runtime.validator.swing.SwingValidatorMessageTableModel id='errors2'
onTableChanged='ok.setEnabled(errors2.getRowCount()==0)'/>
<!-- validators -->
@@ -31,7 +31,7 @@
import jaxx.runtime.SwingUtil;
void $afterCompleteSetup() {
- errorTable.setDefaultRenderer(Object.class, new jaxx.runtime.validator.swing.SwingValidatorErrorTableRenderer());
+ errorTable.setDefaultRenderer(Object.class, new jaxx.runtime.validator.swing.SwingValidatorMessageTableRenderer());
SwingUtil.setI18nTableHeaderRenderer(errorTable, n_("validator.scope"), n_("validator.scope.tip"), n_("validator.field"), n_("validator.field.tip"), n_("validator.message"), n_("validator.message.tip"));
SwingUtil.fixTableColumnWidth(errorTable, 0, 25);
Deleted: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,476 +0,0 @@
-package jaxx.runtime.validator;
-
-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.FieldValidator;
-import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.Validator;
-import com.opensymphony.xwork2.validator.ValidatorScope;
-import java.beans.EventSetDescriptor;
-import org.apache.commons.beanutils.ConversionException;
-import org.apache.commons.beanutils.Converter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.util.ConverterUtil;
-
-import java.beans.Introspector;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TreeMap;
-
-/**
- *
- * A customized validator for a given bean.
- *
- * <b>Note:</b> The bean must be listenable on properyChange events (means
- * must have public addPropertychangeListener and removePropertyChangeListener methods).
- *
- * @param <B> type of the bean to validate.
- *
- * @author chemit
- */
-@Deprecated
-public class BeanValidator<B> {
-
- /** la nom de la propriété bean */
- static public final String BEAN_PROERTY = "bean";
-
- /** la nom de la propriété contextName */
- static public final String CONTEXT_NAME_PROPERTY = "contextName";
-
- /** la nom de l'état valid */
- static public final String VALID_PROERTY = "valid";
-
- /** la nom de l'état changed */
- static public final String CHANGED_PROERTY = "changed";
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static protected final Log log = LogFactory.getLog(BeanValidator.class);
-
- /** the type of bean to watch */
- protected final Class<B> beanClass;
-
- /** the validation named context (can be null) */
- protected String contextName;
-
- /** to chain to a prent validator */
- protected BeanValidator<?> parentValidator;
-
- /** state to indicate that validator has changed since the last time bean was setted */
- protected boolean changed = false;
-
- /** state of the validator (is true if no errors of error scope is found) */
- protected boolean valid = true;
-
- /** bean to be watched */
- protected B bean = null;
-
- /**
- * map of fields by scope
- * TODO use this and remove fields property and xworks patch :)
- */
- protected EnumMap<ValidatorScope, List<ValidatorField<B>>> fieldsByScope;
-
- /** list of fields watched by this validator */
- protected List<ValidatorField<B>> fields;
-
- /** map of conversion errors detected by this validator */
- protected Map<String, String> conversionErrors;
-
- /** delgate property change support */
- protected PropertyChangeSupport pcs;
-
- /** listener that listens on bean modification */
- protected PropertyChangeListener l;
-
- protected ValidationAwareSupport validationSupport;
- protected DelegatingValidatorContext validationContext;
- protected transient ActionValidatorManager validator;
- protected ActionContext context;
-
- protected EventSetDescriptor beanEventDescriptor;
-
- public BeanValidator(Class<B> beanClass, String contextName) {
- // check that the bean is listenable, otherwise, can't use the validator on it
- beanEventDescriptor = ValidationUtil.getPropertyChangeListenerDescriptor(beanClass);
-
- this.beanClass = beanClass;
- this.contextName = contextName;
- pcs = new PropertyChangeSupport(this);
- validationSupport = new ValidationAwareSupport();
- validationContext = new DelegatingValidatorContext(validationSupport);
-
- // init context
- ConfigurationManager confManager = new ConfigurationManager();
- Configuration conf = confManager.getConfiguration();
-
- ValueStackFactory vsf = conf.getContainer().getInstance(
- ValueStackFactory.class);
- ValueStack vs = vsf.createValueStack();
- context = new ActionContext(vs.getContext());
- ActionContext.setContext(context);
-
- // init validator
- validator = conf.getContainer().getInstance(ActionValidatorManager.class, "no-annotations");
- initFields();
-
- conversionErrors = new TreeMap<String, String>();
-
- l = new PropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- validate();
- setValid(!hasErrors());
- setChanged(true);
- }
- };
- }
-
- protected void initFields() {
- // init fields from detected fieldValidator in XWorks framework
- fields = new ArrayList<ValidatorField<B>>();
- for (Validator v : validator.getValidators(beanClass, contextName)) {
- // we only work on FieldValidator at the moment
- if (v instanceof FieldValidator) {
- FieldValidator fieldValidator = (FieldValidator) v;
- String fName = fieldValidator.getFieldName();
- ValidatorScope fScope = fieldValidator.getValidatorScope();
- ValidatorField<B> field = new ValidatorField<B>(beanClass, fName, fScope);
- if (!fields.contains(field)) {
- fields.add(field);
- }
- }
- }
-
- fields = Collections.unmodifiableList(fields);
- }
-
- public Class<B> getBeanClass() {
- return beanClass;
- }
-
- public BeanValidator<?> getParentValidator() {
- return parentValidator;
- }
-
- public String getContextName() {
- return contextName;
- }
-
- public List<ValidatorField<B>> getFields() {
- return fields;
- }
-
- public ValidatorField<B> getField(String fieldName) {
- for (ValidatorField<B> field : fields) {
- if (fieldName.equals(field.getName())) {
- return field;
- }
- }
- return null;
- }
-
- /**
- * Retourne vrai si l'objet bean a ete modifie depuis le dernier
- * {@link #setBean}
- *
- * @return <code>true</code> if bean was modify since last {@link #setBean(Object)} invocation
- */
- public boolean isChanged() {
- return changed;
- }
-
- public boolean isValid() {
- return valid;
- }
-
- public B getBean() {
- return bean;
- }
-
- /**
- * Permet de force la remise a false de l'etat de changement du bean
- *
- * @param changed flag to force reset of property {@link #changed}
- */
- public void setChanged(boolean changed) {
- this.changed = changed;
- // force the property to be fired (never pass the older value)
- pcs.firePropertyChange(CHANGED_PROERTY, null, changed);
- }
-
- public void setValid(boolean valid) {
- this.valid = valid;
- // force the property to be fired (never pass the older value)
- pcs.firePropertyChange(VALID_PROERTY, null, valid);
- }
-
- public void setBean(B bean) {
- B oldBean = this.bean;
- if (log.isDebugEnabled()) {
- log.debug(this + " : " + bean);
- }
- // clean conversions of previous bean
- conversionErrors.clear();
-
- if (oldBean != null) {
- try {
- beanEventDescriptor.getRemoveListenerMethod().invoke(oldBean, l);
- //Method method = this.bean.getClass().getMethod("removePropertyChangeListener", PropertyChangeListener.class);
- //method.invoke(oldBean, l);
- } catch (Exception eee) {
- log.info("Can't register as listener for bean "+beanClass+" for reason "+eee.getMessage(), eee);
- }
- }
- this.bean = bean;
-
- if (bean == null) {
- // must remove all errors from this validator on errorListModel
- validationSupport.clearErrorsAndMessages();
-
- // dispatch in each field the new errors
- dispatchErrorsToFields();
- } else {
- try {
- beanEventDescriptor.getAddListenerMethod().invoke(bean, l);
- //Method method = this.bean.getClass().getMethod("addPropertyChangeListener", PropertyChangeListener.class);
- //method.invoke(bean, l);
- } catch (Exception eee) {
- log.info("Can't register as listener for bean "+beanClass+" for reason "+eee.getMessage(), eee);
- }
- validate();
- }
- setChanged(false);
- setValid(!hasErrors());
- pcs.firePropertyChange(BEAN_PROERTY, oldBean, bean);
- }
-
- //FIXME At the moment we do not allow to change contextName, but we should be able to do it
- public void setContextName(String contextName) {
- String oldValidationContextName = this.contextName;
- this.contextName = contextName;
- // changing contextName could change fields definition
- // so dettach bean, must rebuild the fields
- setBean(null);
- initFields();
- pcs.firePropertyChange(CONTEXT_NAME_PROPERTY, oldValidationContextName, contextName);
- }
-
- public void setParentValidator(BeanValidator<?> parentValidator) {
- this.parentValidator = parentValidator;
- }
-
- /** @return <code>true</code> if errors are detected, <code>false</code> otherwise */
- public boolean hasErrors() {
- for (ValidatorField<B> field : fields) {
- if (field.hasErrors()) {
- return true;
- }
- }
- return false;
- }
-
- public boolean hasWarnings() {
- for (ValidatorField<B> field : fields) {
- if (field.hasWarnings()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Test a the validator contains the field given his name
- *
- * @param fieldName the name of the searched field
- * @return <code>true</code> if validator contaisn this field, <code>false</code> otherwise
- */
- public boolean containsField(String fieldName) {
- ValidatorField<B> field = getField(fieldName);
- return field != null;
- }
-
- public boolean isValid(String fieldName) {
- ValidatorField<B> field = getField(fieldName);
- if (field == null) {
- throw new IllegalArgumentException("could not find a validator field " + fieldName);
- }
- return field.isValid();
- }
-
- /**
- * Convert a value.
- * <p/>
- * If an error occurs, then add an error in validator.
- *
- * @param <T> the type of conversion
- * @param fieldName the name of the bean property
- * @param value the value to convert
- * @param valueClass the type of converted value
- * @return the converted value, or null if conversion was not ok
- */
- @SuppressWarnings({"unchecked"})
- public <T> T convert(String fieldName, String value, Class<T> valueClass) {
- if (fieldName == null) {
- throw new IllegalArgumentException("fieldName can not be null");
- }
- if (valueClass == null) {
- throw new IllegalArgumentException("valueClass can not be null");
- }
-
- // on ne convertit pas si il y a un bean et que le resultat de la validation
- // pourra etre affiche quelque part
- if (!canValidate() || value == null) {
- return null;
- }
-
- // remove the previous conversion error for the field
- conversionErrors.remove(fieldName);
-
- T result;
- try {
- Converter converter = ConverterUtil.getConverter(valueClass);
- if (converter == null) {
- throw new RuntimeException("could not find converter for the type " + valueClass);
- }
- result = (T) converter.convert(valueClass, value);
- /* Why this test ? if (result != null && !value.equals(result.toString())) {
- conversionErrors.put(fieldName, "error.convertor." + Introspector.decapitalize(valueClass.getSimpleName()));
- result = null;
- validate();
- }*/
- } catch (ConversionException e) {
- // get
- conversionErrors.put(fieldName, "error.convertor." + Introspector.decapitalize(valueClass.getSimpleName()));
- result = null;
- validate();
- }
- return result;
- }
-
- /**
- * 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 (!canValidate()) {
- return;
- }
-
- try {
-
- validationSupport.clearErrorsAndMessages();
-
- //TC - 20081024 : since context is in a ThreadLocal variable, we must do the check
- if (ActionContext.getContext() == null) {
- ActionContext.setContext(context);
- }
-
- validator.validate(bean, contextName, validationContext);
-
- // add the registred conversion errors
- transfertConversionErrorsToFieldErrors();
-
- if (log.isTraceEnabled()) {
- log.trace("Action errors: " + validationContext.getActionErrors());
- log.trace("Action messages: " + validationContext.getActionMessages());
- log.trace("Field errors: " + validationContext.getFieldErrors());
- }
-
- if (log.isDebugEnabled()) {
- log.debug(this + " : " + validationContext.getFieldErrors());
- }
-
- // dispatch in each field the new errors
- dispatchErrorsToFields();
-
- if (parentValidator != null) {
- // chained validation
- parentValidator.l.propertyChange(null);
- }
- } catch (ValidationException eee) {
- log.warn("Error during validation", eee);
- }
- }
-
- @Override
- public String toString() {
- return super.toString() + "<beanClass:" + beanClass + ", contextName:" + contextName + ">";
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(propertyName, listener);
- }
-
- /** @return <code>true</code> if validation is enabled, <code>false</code> otherwise. */
- protected boolean canValidate() {
- return !(bean == null || fields.isEmpty());
- }
-
- /**
- * Transfer the registred conversion errors to fieldErrors.
- * <p/>
- * The previously filed errors of a given field where a conversion error occurs will be removed.
- */
- @SuppressWarnings({"unchecked"})
- protected void transfertConversionErrorsToFieldErrors() {
- Map map = validationContext.getFieldErrors();
- for (Entry<String, String> entry : conversionErrors.entrySet()) {
- // remove from validation, errors occurs on this field
- List errors = (List) map.get(entry.getKey());
- if (errors != null) {
- errors.clear();
- errors.add(entry.getValue());
- } else {
- errors = Collections.singletonList(entry.getValue());
- }
- // add the concrete conversion error
- map.put(entry.getKey(), errors);
- }
- validationContext.setFieldErrors(map);
- }
-
- /** synchronize the errors found in this validator to each field. */
- protected void dispatchErrorsToFields() {
-
- Map map = validationContext.getFieldErrors();
- for (ValidatorField<B> field : fields) {
- String fieldName = field.getName();
- boolean detectedErrors = map.containsKey(fieldName);
- field.addErrors(this, detectedErrors ? (List) map.get(fieldName) : null);
- }
- }
-
-}
Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorListener.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorListener.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidatorListener.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -14,19 +14,4 @@
* @param event the event
*/
void onFieldChanged(BeanValidatorEvent event);
-
- /**
- * Invoked when a validator detects a new message on a field.
- *
- * @param event the event
- */
- //void onNewMessages(BeanValidatorEvent event);
-
- /**
- * Invoked when a validator detetcs that a previously message is
- * no more exisitng.
- *
- * @param event the event
- */
- //void onResolvedMessages(BeanValidatorEvent event);
}
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-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidationUtil.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -95,7 +95,7 @@
* @param value the actual value to convert
* @param valueClass the type of the conversion
*/
- public static void convert(BeanValidator<?> validator, String fieldName, String value, Class<?> valueClass) {
+ public static void convert(BeanValidator2<?> validator, String fieldName, String value, Class<?> valueClass) {
Object result = validator.convert(fieldName, value, valueClass);
if (result != null) {
Deleted: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorErrorEvent.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorErrorEvent.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorErrorEvent.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,46 +0,0 @@
-package jaxx.runtime.validator;
-
-import com.opensymphony.xwork2.validator.ValidatorScope;
-
-import java.util.Set;
-
-/**
- * The definition of an event on {@link ValidatorErrorListener}
- * to be fired by a {@link BeanValidator}.
- *
- * @author chemit
- */
-@Deprecated
-public class ValidatorErrorEvent {
-
- /** the source of the event */
- BeanValidator source;
-
- /** the field impacted by the validator */
- ValidatorField<?> field;
-
- public ValidatorErrorEvent(BeanValidator source, ValidatorField<?> field) {
- this.source = source;
- this.field = field;
- }
-
- public BeanValidator getSource() {
- return source;
- }
-
- public String getFieldName() {
- return field.getName();
- }
-
- public Set<String> getErrors() {
- return field.getErrors();
- }
-
- public ValidatorScope getScope() {
- return field.getScope();
- }
-
- public ValidatorField getField() {
- return field;
- }
-}
Deleted: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorErrorListener.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorErrorListener.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorErrorListener.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,25 +0,0 @@
-package jaxx.runtime.validator;
-
-/**
- * The listener contract to be used on {@link BeanValidator]
- *
- * @author chemit
- */
-@Deprecated
-public interface ValidatorErrorListener extends java.util.EventListener {
- /**
- * Invoked when a validator detects a error on a field.
- *
- * @param event the event
- */
- void onNewError(ValidatorErrorEvent event);
-
- /**
- * Invoked when a validator detetcs that a previously error is
- * no more exisitng.
- *
- * @param event the event
- */
- void onResolvedError(ValidatorErrorEvent event);
-
-}
Deleted: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorField.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorField.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/ValidatorField.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,187 +0,0 @@
-package jaxx.runtime.validator;
-
-import com.opensymphony.xwork2.validator.ValidatorScope;
-import static org.codelutin.i18n.I18n._;
-
-import javax.swing.event.EventListenerList;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-/**
- * Definition of a field to be handled in a {@link BeanValidator].
- * <p/>
- * <p/>
- * A such class is only registred in {@link BeanValidator } when the field of the bean
- * was found in validator xml configuration file for a {@link com.opensymphony.xwork2.validator.FieldValidator} only.
- * <p/>
- * This class use properties {@link #beanClass}, {@link #name} to define
- * his naturel order.
- *
- * @author chemit
- * @param <B> the type of the bean handled by the validator and this field of validation.
- */
-@Deprecated
-public class ValidatorField<B> {
-
- /** the class of bean */
- protected final Class<B> beanClass;
-
- /** name of field in bean */
- protected String name;
-
- /** the scope of the field */
- protected ValidatorScope scope;
-
- /** the list of error for this field */
- protected Set<String> errors;
-
- /** A list of event listeners for this validators */
- protected EventListenerList listenerList = new EventListenerList();
-
- public ValidatorField(Class<B> beanClass, String name, ValidatorScope scope) {
- this.beanClass = beanClass;
- this.name = name;
- this.scope = scope;
- this.errors = new HashSet<String>();
- }
-
- public String getName() {
- return name;
- }
-
- public ValidatorScope getScope() {
- return scope;
- }
-
- public Class<B> getBeanClass() {
- return beanClass;
- }
-
- public Set<String> getErrors() {
- return errors;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setScope(ValidatorScope scope) {
- this.scope = scope;
- }
-
- /**
- * @return <code>true</code> if this field is valid (says is in error
- * scope and has errors), <code>false</code> otherwise.
- */
- public boolean isValid() {
- return hasErrors();
- }
-
- public boolean hasErrors() {
- return scope == ValidatorScope.ERROR && !errors.isEmpty();
- }
-
- public boolean hasWarnings() {
- return scope == ValidatorScope.WARNING && !errors.isEmpty();
- }
-
- public void addErrors(BeanValidator<B> validator, List errors) {
- boolean hasPreviousError = !this.errors.isEmpty();
-
- // reset errors for this field
- this.errors.clear();
-
- if (errors == null) {
- // no error to assign to this field
- if (hasPreviousError) {
- // there were previously errors, but any longer
- // so fire a resolvedErrorEvent for this field
- fireResolvedError(validator);
- }
- return;
- }
-
- for (Object error : errors) {
- this.errors.add(error.toString());
- }
- // fire a newErrorEvent for this field
- fireNewError(validator);
- }
-
- public String getI18nError(String error) {
- String text;
- if (error.indexOf("##") == -1) {
- text = _(error);
- } else {
- StringTokenizer stk = new StringTokenizer(error, "##");
- String errorName = stk.nextToken();
- List<String> args = new ArrayList<String>();
- while (stk.hasMoreTokens()) {
- args.add(stk.nextToken());
- }
- text = _(errorName, args.toArray());
- }
- return text;
- }
-
- public void addValidatorErrorListener(ValidatorErrorListener listener) {
- listenerList.add(ValidatorErrorListener.class, listener);
- }
-
- public void removeValidatorErrorListener(ValidatorErrorListener listener) {
- listenerList.remove(ValidatorErrorListener.class, listener);
- }
-
- public ValidatorErrorListener[] getValidatorErrorListeners() {
- return listenerList.getListeners(ValidatorErrorListener.class);
- }
-
- protected void fireNewError(BeanValidator<B> validator) {
- ValidatorErrorEvent evt = new ValidatorErrorEvent(validator, this);
- for (ValidatorErrorListener listener : listenerList.getListeners(ValidatorErrorListener.class)) {
- listener.onNewError(evt);
- }
- }
-
- protected void fireResolvedError(BeanValidator<B> validator) {
- ValidatorErrorEvent evt = new ValidatorErrorEvent(validator, this);
- for (ValidatorErrorListener listener : listenerList.getListeners(ValidatorErrorListener.class)) {
- listener.onResolvedError(evt);
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof ValidatorField)) {
- return false;
- }
-
- ValidatorField that = (ValidatorField) o;
- return beanClass.equals(that.beanClass) && name.equals(that.name);
- }
-
- @Override
- public int hashCode() {
- int result = beanClass.hashCode();
- result = 31 * result + name.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("<").append(super.toString());
- sb.append(" beanClass:").append(beanClass);
- sb.append(", name:").append(name);
- sb.append(", scope:").append(scope);
- sb.append(", errors:").append(errors);
- sb.append('>');
- return sb.toString();
- }
-}
Modified: jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/AbstractFieldValidatorTest.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/AbstractFieldValidatorTest.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/AbstractFieldValidatorTest.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,9 +1,9 @@
package jaxx.runtime.validator.field;
import java.io.File;
-import jaxx.runtime.validator.BeanValidator;
+import jaxx.runtime.validator.BeanValidator2;
+import jaxx.runtime.validator.BeanValidatorField;
import jaxx.runtime.validator.ValidatorBean;
-import jaxx.runtime.validator.ValidatorField;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
@@ -23,7 +23,7 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private final Log log = LogFactory.getLog(AbstractFieldValidatorTest.class);
- static protected BeanValidator<ValidatorBean> validator;
+ static protected BeanValidator2<ValidatorBean> validator;
static protected File basedir;
protected ValidatorBean bean;
@@ -53,16 +53,17 @@
b = new File("").getAbsolutePath();
}
basedir = new File(b);
- validator = new BeanValidator<ValidatorBean>(ValidatorBean.class, null);
+ validator = new BeanValidator2<ValidatorBean>(ValidatorBean.class, null);
}
protected void assertFieldInError(String fieldName, String error, boolean required) {
- ValidatorField<ValidatorBean> field = validator.getField(fieldName);
-
- for (String o : field.getErrors()) {
- if (o.equals(error)) {
- assertTrue(required);
- return;
+ BeanValidatorField<ValidatorBean> field = validator.getField(fieldName);
+ if (field !=null && field.getErrors() != null) {
+ for (String o : field.getErrors()) {
+ if (o.equals(error)) {
+ assertTrue(required);
+ return;
+ }
}
}
// error was not found
Copied: jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-error-validation.xml (from rev 1273, jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-validation.xml)
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-error-validation.xml (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-error-validation.xml 2009-03-21 08:22:03 UTC (rev 1274)
@@ -0,0 +1,95 @@
+<!DOCTYPE validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+<validators>
+
+ <field name="stringValue">
+ <field-validator type="requiredstring" short-circuit="true">
+ <message>stringValue.required</message>
+ </field-validator>
+ </field>
+
+ <field name="existingFile">
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>existingFile.required</message>
+ </field-validator>
+ <field-validator type="existingFile" short-circuit="true">
+ <message>existingFile.not.exist</message>
+ </field-validator>
+ </field>
+
+ <field name="notExistingFile">
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>notExistingFile.required</message>
+ </field-validator>
+ <field-validator type="notExistingFile" short-circuit="true">
+ <message>notExistingFile.exist</message>
+ </field-validator>
+ </field>
+
+ <field name="existingDirectory">
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>existingDirectory.required</message>
+ </field-validator>
+
+ <field-validator type="existingDirectory" short-circuit="true">
+ <message>existingDirectory.not.exist</message>
+ </field-validator>
+ </field>
+
+ <field name="notExistingDirectory">
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>notExistingDirectory.required</message>
+ </field-validator>
+
+ <field-validator type="notExistingDirectory" short-circuit="true">
+ <message>notExistingDirectory.exist</message>
+ </field-validator>
+ </field>
+
+ <field name="entries">
+ <field-validator type="collectionFieldExpression">
+ <param name="mode">AT_LEAST_ONE</param>
+ <param name="expression"><![CDATA[ intValue == 0 && stringValue == "stringValue" ]]></param>
+ <message>collectionFieldExpression.atLeastOne</message>
+ </field-validator>
+ <field-validator type="collectionFieldExpression">
+ <param name="mode">EXACTLY_ONE</param>
+ <param name="expression"><![CDATA[ intValue == 0 && stringValue == "stringValue" ]]></param>
+ <message>collectionFieldExpression.exactlyOne</message>
+ </field-validator>
+ <field-validator type="collectionFieldExpression">
+ <param name="mode">ALL</param>
+ <param name="expression"><![CDATA[ intValue == 0 && stringValue == "stringValue" ]]></param>
+ <message>collectionFieldExpression.all</message>
+ </field-validator>
+ <field-validator type="collectionFieldExpression">
+ <param name="mode">NONE</param>
+ <param name="expression"><![CDATA[ intValue == 0 && stringValue == "stringValue" ]]></param>
+ <message>collectionFieldExpression.none</message>
+ </field-validator>
+
+ <field-validator type="collectionUniqueKey">
+ <param name="keys">intValue</param>
+ <message>collectionUniqueKey.one.failed</message>
+ </field-validator>
+ <field-validator type="collectionUniqueKey">
+ <param name="keys">stringValue</param>
+ <message>collectionUniqueKey.two.failed</message>
+ </field-validator>
+ <field-validator type="collectionUniqueKey">
+ <param name="keys">intValue,stringValue</param>
+ <message>collectionUniqueKey.three.failed</message>
+ </field-validator>
+ <field-validator type="collectionUniqueKey">
+ <param name="keys">intValue,stringValue,stringValue2</param>
+ <message>collectionUniqueKey.four.failed</message>
+ </field-validator>
+ <field-validator type="collectionUniqueKey">
+ <param name="keys">stringValue</param>
+ <param name="againstProperty">entry</param>
+ <message>collectionUniqueKey.five.failed</message>
+ </field-validator>
+ </field>
+
+</validators>
\ No newline at end of file
Deleted: jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-validation.xml
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-validation.xml 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-validation.xml 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,95 +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 name="stringValue">
- <field-validator type="requiredstring" short-circuit="true">
- <message>stringValue.required</message>
- </field-validator>
- </field>
-
- <field name="existingFile">
- <field-validator type="requiredFile" short-circuit="true" validatorScope="ERROR">
- <message>existingFile.required</message>
- </field-validator>
- <field-validator type="existingFile" short-circuit="true">
- <message>existingFile.not.exist</message>
- </field-validator>
- </field>
-
- <field name="notExistingFile">
- <field-validator type="requiredFile" short-circuit="true">
- <message>notExistingFile.required</message>
- </field-validator>
- <field-validator type="notExistingFile" short-circuit="true">
- <message>notExistingFile.exist</message>
- </field-validator>
- </field>
-
- <field name="existingDirectory">
- <field-validator type="requiredFile" short-circuit="true">
- <message>existingDirectory.required</message>
- </field-validator>
-
- <field-validator type="existingDirectory" short-circuit="true">
- <message>existingDirectory.not.exist</message>
- </field-validator>
- </field>
-
- <field name="notExistingDirectory">
- <field-validator type="requiredFile" short-circuit="true">
- <message>notExistingDirectory.required</message>
- </field-validator>
-
- <field-validator type="notExistingDirectory" short-circuit="true">
- <message>notExistingDirectory.exist</message>
- </field-validator>
- </field>
-
- <field name="entries">
- <field-validator type="collectionFieldExpression">
- <param name="mode">AT_LEAST_ONE</param>
- <param name="expression"><![CDATA[ intValue == 0 && stringValue == "stringValue" ]]></param>
- <message>collectionFieldExpression.atLeastOne</message>
- </field-validator>
- <field-validator type="collectionFieldExpression">
- <param name="mode">EXACTLY_ONE</param>
- <param name="expression"><![CDATA[ intValue == 0 && stringValue == "stringValue" ]]></param>
- <message>collectionFieldExpression.exactlyOne</message>
- </field-validator>
- <field-validator type="collectionFieldExpression">
- <param name="mode">ALL</param>
- <param name="expression"><![CDATA[ intValue == 0 && stringValue == "stringValue" ]]></param>
- <message>collectionFieldExpression.all</message>
- </field-validator>
- <field-validator type="collectionFieldExpression">
- <param name="mode">NONE</param>
- <param name="expression"><![CDATA[ intValue == 0 && stringValue == "stringValue" ]]></param>
- <message>collectionFieldExpression.none</message>
- </field-validator>
-
- <field-validator type="collectionUniqueKey">
- <param name="keys">intValue</param>
- <message>collectionUniqueKey.one.failed</message>
- </field-validator>
- <field-validator type="collectionUniqueKey">
- <param name="keys">stringValue</param>
- <message>collectionUniqueKey.two.failed</message>
- </field-validator>
- <field-validator type="collectionUniqueKey">
- <param name="keys">intValue,stringValue</param>
- <message>collectionUniqueKey.three.failed</message>
- </field-validator>
- <field-validator type="collectionUniqueKey">
- <param name="keys">intValue,stringValue,stringValue2</param>
- <message>collectionUniqueKey.four.failed</message>
- </field-validator>
- <field-validator type="collectionUniqueKey">
- <param name="keys">stringValue</param>
- <param name="againstProperty">entry</param>
- <message>collectionUniqueKey.five.failed</message>
- </field-validator>
- </field>
-
-</validators>
\ No newline at end of file
Modified: 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 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/SwingValidationUtil.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,13 +1,14 @@
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;
+import jaxx.runtime.validator.swing.SwingValidatorMessageTableMouseListener;
+import jaxx.runtime.validator.swing.SwingValidatorMessageListMouseListener;
/**
* The helper class for validation module.
@@ -28,13 +29,13 @@
return;
}
for (MouseListener listener : list.getMouseListeners()) {
- if (listener instanceof SwingValidatorErrorListMouseListener) {
+ if (listener instanceof SwingValidatorMessageListMouseListener) {
// already have a such listener
log.info("already registered a such MouseListener : " + listener);
return;
}
}
- list.addMouseListener(new SwingValidatorErrorListMouseListener());
+ list.addMouseListener(new SwingValidatorMessageListMouseListener());
}
public static void registerErrorTableMouseListener(JTable table) {
@@ -42,20 +43,20 @@
return;
}
for (MouseListener listener : table.getMouseListeners()) {
- if (listener instanceof SwingValidatorErrorTableMouseListener) {
+ if (listener instanceof SwingValidatorMessageTableMouseListener) {
// already have a such listener
log.info("already registered a such MouseListener : " + listener);
return;
}
}
- table.addMouseListener(new SwingValidatorErrorTableMouseListener());
+ table.addMouseListener(new SwingValidatorMessageTableMouseListener());
}
- public static SwingValidatorErrorTableMouseListener getErrorTableMouseListener(JTable table) {
+ public SwingValidatorMessageTableMouseListener getErrorTableMouseListener(JTable table) {
if (table != null) {
for (MouseListener listener : table.getMouseListeners()) {
- if (listener instanceof SwingValidatorErrorTableMouseListener) {
- return (SwingValidatorErrorTableMouseListener) listener;
+ if (listener instanceof SwingValidatorMessageTableMouseListener) {
+ return (SwingValidatorMessageTableMouseListener) listener;
}
}
}
Modified: 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/SwingValidator.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidator.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -107,10 +107,10 @@
protected Map<String, JComponent> fieldRepresentation;
/** Object servant a contenir la liste des erreurs */
- protected SwingValidatorErrorListModel errorListModel;
+ protected SwingValidatorMessageListModel errorListModel;
/** Object servant a contenir la liste des erreurs */
- protected SwingValidatorErrorTableModel errorTableModel;
+ protected SwingValidatorMessageTableModel errorTableModel;
/** ui renderer class */
protected Class<? extends AbstractBeanValidatorUI> uiClass;
@@ -129,7 +129,7 @@
return uiClass;
}
- public void setErrorListModel(SwingValidatorErrorListModel errorListModel) {
+ public void setErrorListModel(SwingValidatorMessageListModel errorListModel) {
this.errorListModel = errorListModel;
if (errorListModel != null) {
// register the validator in the model list
@@ -137,7 +137,7 @@
}
}
- public void setErrorTableModel(SwingValidatorErrorTableModel errorTableModel) {
+ public void setErrorTableModel(SwingValidatorMessageTableModel errorTableModel) {
this.errorTableModel = errorTableModel;
if (errorTableModel != null) {
// register the validator in the model table
@@ -221,7 +221,7 @@
}
for (Entry<String, JComponent> entry : fieldRepresentation.entrySet()) {
try {
- setErrorRepresentation(entry.getKey(), null, entry.getValue(), uiClass);
+ setMessageRepresentation(entry.getKey(), null, entry.getValue(), uiClass);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -230,7 +230,7 @@
});
}
- protected void setErrorRepresentation(String fieldname, JComponent old, JComponent c, Class<? extends AbstractBeanValidatorUI> uiClass)
+ protected void setMessageRepresentation(String fieldname, JComponent old, JComponent c, Class<? extends AbstractBeanValidatorUI> uiClass)
throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException {
if (old == c) {
// same component, nothing to do
@@ -250,7 +250,6 @@
Object ui = jx.getUI();
if (ui != null && ui instanceof AbstractBeanValidatorUI) {
removeBeanValidatorListener((AbstractBeanValidatorUI)ui);
- //field.removeValidatorErrorListener((AbstractBeanValidatorUI) ui);
}
jx.setUI(null);
@@ -265,7 +264,6 @@
ui.setEnabled(true);
JXLayer<JComponent> jx = (JXLayer<JComponent>) container;
addBeanValidatorListener(ui);
- //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-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListModel.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,231 +0,0 @@
-package jaxx.runtime.validator.swing;
-
-import jaxx.runtime.validator.BeanValidatorEvent;
-
-import javax.swing.DefaultListModel;
-import javax.swing.JComponent;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import jaxx.runtime.validator.BeanValidatorField;
-import jaxx.runtime.validator.BeanValidatorListener;
-import jaxx.runtime.validator.BeanValidatorScope;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * The model of the list of errors
- *
- * @author chemit
- */
-public class SwingValidatorErrorListModel extends DefaultListModel implements BeanValidatorListener {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- private static Log log = LogFactory.getLog(SwingValidatorErrorListModel.class);
- private static final long serialVersionUID = 1L;
- /** list of registred validators */
- protected transient List<SwingValidator<?>> validators;
-
- public SwingValidatorErrorListModel() {
- validators = new ArrayList<SwingValidator<?>>();
- }
-
- public void registerValidator(SwingValidator<?> validator) {
- if (validators.contains(validator)) {
- throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
- }
- validators.add(validator);
- validator.addBeanValidatorListener(this);
- // the model listen on each field of the validator
- /*for (ValidatorField<?> field : validator.getFields()) {
- field.addValidatorErrorListener(this);
- }*/
- }
-
- @Override
- public void onFieldChanged(BeanValidatorEvent event) {
- String[] toDelete = event.getMessagesToDelete();
- String[] toAdd = event.getMessagesToAdd();
- BeanValidatorScope scope = event.getScope();
- SwingValidator validator = (SwingValidator) event.getSource();
- BeanValidatorField field = event.getField();
-
- if (log.isTraceEnabled()) {
- log.trace("----------------------------------------------------------");
- log.trace(field + " - (" + getSize() + ") toAdd " + (toAdd == null ? null : toAdd.length));
- log.trace(field + " - (" + getSize() + ") toDelete " + (toDelete == null ? null : toDelete.length));
- }
-
- if ((toAdd == null || toAdd.length == 0) && (toDelete == null || toDelete.length == 0)) {
- // no data to add nor remove, so nothing to do
- return;
- }
-
- if (toAdd == null || toAdd.length == 0) {
-
- if (log.isTraceEnabled()) {
- log.trace(field + " - toDelete : just delete some datas!");
- }
-
- // no add, no need to resort the datas, can direclty delete
- // messages we do not want any longer
-
- // delete some messages for the given field and given scope
- List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
- List<Integer> indexs = new java.util.ArrayList<Integer>(toDelete.length);
-
- Enumeration enumeration = elements();
- int index = 0;
- while (enumeration.hasMoreElements()) {
- SwingValidatorErrorModel error = (SwingValidatorErrorModel) enumeration.nextElement();
-
- if (error.getValidator() == validator && error.getField() == field && ids.contains(error.getError())) {
- indexs.add(index);
- }
- index++;
- }
-
- java.util.Collections.reverse(indexs);
-
- for (Integer i : indexs) {
- removeElementAt(i);
- }
-
- return;
- }
-
- if (log.isTraceEnabled()) {
- log.trace(field + " - add and delete !");
- }
-
- List<SwingValidatorErrorModel> newMessages = new ArrayList<SwingValidatorErrorModel>();
-
-
-
- // obtain all messages not to delete
-
- List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
-
- Enumeration enumeration = elements();
- while (enumeration.hasMoreElements()) {
- SwingValidatorErrorModel error = (SwingValidatorErrorModel) enumeration.nextElement();
-
- if (error.getValidator() != validator || error.getField() != field || !ids.contains(error.getError())) {
- // keep this row
- newMessages.add(error);
- }
- }
-
- if (toAdd != null && toAdd.length > 0) {
- JComponent editor = validator.getFieldRepresentation(field.getName());
- // add new messages
- for (String error : toAdd) {
- newMessages.add(new SwingValidatorErrorModel(validator, field, error, editor));
- }
- }
-
- // sort datas
-
- java.util.Collections.sort(newMessages);
-
- // clean model and reinject new errors
- removeAllElements();
-
- // reinject in list model, all the errors
- for (SwingValidatorErrorModel error : newMessages) {
- addElement(error);
- }
-
- /*
- List<SwingValidatorErrorModel> newErrors = new ArrayList<SwingValidatorErrorModel>();
-
- JComponent editor = validator.getFieldRepresentation(field.getName());
- // add new errors
- for (String error : toAdd) {
- 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);
- }*/
- }
- /**
- * 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);
- }
- }
- }*/
-}
Deleted: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListMouseListener.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListMouseListener.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListMouseListener.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,61 +0,0 @@
-package jaxx.runtime.validator.swing;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.JComponent;
-import javax.swing.JList;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-
-/**
- * A mouse listener to put on a {@link javax.swing.JList} with a {@link SwingValidatorErrorListModel} as a model.
- * <p/>
- * When a double click occurs, find the selected error in model and then focus to the associated component of error.
- *
- * @author chemit
- */
-public class SwingValidatorErrorListMouseListener extends MouseAdapter {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(SwingValidatorErrorListMouseListener.class);
-
- @Override
- public void mouseClicked(MouseEvent e) {
- super.mouseClicked(e);
- if (e.getClickCount() == 2) {
-
- SwingValidatorErrorModel entry = getSelectedError(e);
- if (entry == null) {
- // no entry found
- return;
- }
- JComponent component = entry.getEditor();
- if (component != null) {
- component.requestFocus();
- }
- }
- }
-
-
- protected SwingValidatorErrorModel getSelectedError(MouseEvent e) {
- JList list = (JList) e.getSource();
- if (!(list.getModel() instanceof SwingValidatorErrorListModel)) {
- log.warn("model must be a " + SwingValidatorErrorListModel.class + ", but was " + list.getModel());
- return null;
- }
-
- SwingValidatorErrorListModel model = (SwingValidatorErrorListModel) list.getModel();
- int index = list.getSelectionModel().getMinSelectionIndex();
- if (index == -1) {
- // nothing is selected
- return null;
- }
- SwingValidatorErrorModel entry = (SwingValidatorErrorModel) model.getElementAt(index);
- if (log.isDebugEnabled()) {
- log.debug("selected index: " + index + " : error: " + entry);
- }
- return entry;
- }
-
-}
\ No newline at end of file
Deleted: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorModel.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorModel.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,58 +0,0 @@
-package jaxx.runtime.validator.swing;
-
-
-import javax.swing.JComponent;
-import jaxx.runtime.validator.BeanValidatorField;
-
-/** @author chemit */
-public class SwingValidatorErrorModel implements Comparable<SwingValidatorErrorModel> {
- protected SwingValidator validator;
- protected BeanValidatorField field;
- protected String error;
- protected JComponent editor;
-
- public SwingValidatorErrorModel(SwingValidator validator, BeanValidatorField field, String error, JComponent editor) {
- this.field = field;
- this.validator = validator;
- this.error = error;
- this.editor = editor;
- }
-
- public JComponent getEditor() {
- return editor;
- }
-
- public SwingValidator getValidator() {
- return validator;
- }
-
- public BeanValidatorField getField() {
- return field;
- }
-
- public String getError() {
- return error;
- }
-
- @Override
- public int compareTo(SwingValidatorErrorModel o) {
- int result = field.getScope().compareTo(o.field.getScope());
- if (result != 0) {
- return result;
- }
- result = field.getName().compareTo(o.field.getName());
- if (result != 0) {
- return result;
- }
- result = error.compareTo(o.error);
- return result;
- }
-
- @Override
- public String toString() {
- if (editor == null) {
- return field.getI18nError(error);
- }
- return editor.getName() + " : " + field.getI18nError(error);
- }
-}
Deleted: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableModel.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableModel.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,158 +0,0 @@
-package jaxx.runtime.validator.swing;
-
-import jaxx.runtime.validator.BeanValidatorEvent;
-
-import javax.swing.JComponent;
-import javax.swing.table.DefaultTableModel;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Vector;
-import jaxx.runtime.validator.BeanValidatorField;
-import jaxx.runtime.validator.BeanValidatorListener;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * The model of the list of errors
- *
- * @author chemit
- */
-public class SwingValidatorErrorTableModel extends DefaultTableModel implements BeanValidatorListener {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- private static Log log = LogFactory.getLog(SwingValidatorErrorTableMouseListener.class);
- private static final long serialVersionUID = 1L;
- public static final String[] columnNames = {"validator.scope", "validator.field", "validator.message"};
- /** list of registred validators */
- protected transient List<SwingValidator<?>> validators;
- /** comporator of errors */
- protected transient Comparator<SwingValidatorErrorModel> comparator;
-
- public SwingValidatorErrorTableModel() {
- super(columnNames, 0);
- validators = new ArrayList<SwingValidator<?>>();
- }
-
- public int getErrorColumn() {
- return findColumn(columnNames[2]);
- }
-
- @Override
- public boolean isCellEditable(int row, int column) {
- // cells are never editable in this model
- return false;
- }
-
- public void registerValidator(SwingValidator<?> validator) {
- if (validators.contains(validator)) {
- throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
- }
- validators.add(validator);
- validator.addBeanValidatorListener(this);
- }
-
- @Override
- public void onFieldChanged(BeanValidatorEvent event) {
- String[] toDelete = event.getMessagesToDelete();
- String[] toAdd = event.getMessagesToAdd();
- BeanValidatorField field = event.getField();
-
- if (log.isTraceEnabled()) {
- log.trace("----------------------------------------------------------");
- log.trace(field + " - (" + getRowCount() + ") toAdd " + (toAdd == null ? null : toAdd.length));
- log.trace(field + " - (" + getRowCount() + ") toDelete " + (toDelete == null ? null : toDelete.length));
- }
- if ((toAdd == null || toAdd.length == 0) && (toDelete == null || toDelete.length == 0)) {
- // no data to add nor remove, so nothing to do
- return;
- }
-
- SwingValidator validator = (SwingValidator) event.getSource();
-
-
- int errorColumn = getErrorColumn();
-
- if (toAdd == null || toAdd.length == 0) {
-
-
- if (log.isTraceEnabled()) {
- log.trace(field + " - toDelete : just delete some datas!");
- }
-
- // no add, no need to resort the datas, can direclty delete
- // messages we do not want any longer
-
- // delete some messages for the given field and given scope
- List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
- List<Integer> indexs = new java.util.ArrayList<Integer>(toDelete.length);
-
- Enumeration enumeration = getDataVector().elements();
-
- int index = 0;
- while (enumeration.hasMoreElements()) {
- Vector row = (Vector) enumeration.nextElement();
- SwingValidatorErrorModel error = (SwingValidatorErrorModel) row.get(errorColumn);
- if (error.getValidator() == validator && error.getField() == field && ids.contains(error.getError())) {
- // remo the message
- indexs.add(index);
- }
- index++;
- }
- java.util.Collections.reverse(indexs);
-
- for (Integer i : indexs) {
- removeRow(i);
- }
-
- return;
- }
-
- if (log.isTraceEnabled()) {
- log.trace(field + " - add and delete !");
- }
-
- // rebuild all the data (since we are some adding data and we ensure
- // an order on datas)
-
- List<SwingValidatorErrorModel> newMessages = new ArrayList<SwingValidatorErrorModel>();
-
- // delete some messages for the given field and given scope
- List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
-
- Enumeration enumeration = getDataVector().elements();
-
- while (enumeration.hasMoreElements()) {
- Vector row = (Vector) enumeration.nextElement();
- SwingValidatorErrorModel error = (SwingValidatorErrorModel) row.get(errorColumn);
- if (error.getValidator() != validator || error.getField() != field || !ids.contains(error.getError())) {
- // keep this row
- newMessages.add(error);
- }
- }
-
- if (toAdd != null && toAdd.length > 0) {
- JComponent editor = validator.getFieldRepresentation(field.getName());
- // add new errors
- for (String error : toAdd) {
- SwingValidatorErrorModel errorModel = new SwingValidatorErrorModel(validator, field, error, editor);
- newMessages.add(errorModel);
- }
- }
-
- // sort datas
-
- java.util.Collections.sort(newMessages);
-
- // clean table model and reinject new messages
- getDataVector().clear();
-
- // reinject in list model, all the errors
- for (SwingValidatorErrorModel error : newMessages) {
- addRow(new Object[]{error.getField().getScope(), error.getField().getName(), error});
- }
-
- fireTableDataChanged();
- }
-}
\ No newline at end of file
Deleted: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableMouseListener.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableMouseListener.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableMouseListener.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,92 +0,0 @@
-package jaxx.runtime.validator.swing;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.JComponent;
-import javax.swing.JTable;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-
-/**
- * A mouse listener to put on a {@link javax.swing.JList} with a {@link SwingValidatorErrorTableModel} as a model.
- * <p/>
- * When a double click occurs, find the selected error in model and then focus to the associated component of error.
- *
- * @author chemit
- */
-public class SwingValidatorErrorTableMouseListener extends MouseAdapter {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- private static Log log = LogFactory.getLog(SwingValidatorErrorTableMouseListener.class);
-
- public static final String HIGHLIGHT_ERROR_PROPERTY = "highlightError";
-
- /** delgate property change support */
- protected PropertyChangeSupport pcs;
-
- public SwingValidatorErrorTableMouseListener() {
- pcs = new PropertyChangeSupport(this);
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {
- super.mouseClicked(e);
- if (e.getClickCount() == 2) {
-
- SwingValidatorErrorModel entry = getSelectedError(e);
- if (entry == null) {
- // no entry found
- return;
- }
- JComponent component = entry.getEditor();
- if (component != null) {
- pcs.firePropertyChange(HIGHLIGHT_ERROR_PROPERTY, null, entry);
- if (component.isVisible()) {
- component.requestFocus();
- }
- }
- }
- }
-
-
- protected SwingValidatorErrorModel getSelectedError(MouseEvent e) {
- JTable table = (JTable) e.getSource();
- if (!(table.getModel() instanceof SwingValidatorErrorTableModel)) {
- log.warn("model must be a " + SwingValidatorErrorTableModel.class + ", but was " + table.getModel());
- return null;
- }
-
- SwingValidatorErrorTableModel model = (SwingValidatorErrorTableModel) table.getModel();
- int index = table.getSelectionModel().getMinSelectionIndex();
- if (index == -1) {
- // nothing is selected
- return null;
- }
- int col = model.getErrorColumn();
- SwingValidatorErrorModel entry = (SwingValidatorErrorModel) model.getValueAt(index, col);
- if (log.isDebugEnabled()) {
- log.debug("selected index: " + index + " : error: " + entry);
- }
- return entry;
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(propertyName, listener);
- }
-
-}
\ No newline at end of file
Deleted: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableRenderer.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableRenderer.java 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableRenderer.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,61 +0,0 @@
-package jaxx.runtime.validator.swing;
-
-import javax.swing.ImageIcon;
-import javax.swing.JLabel;
-import javax.swing.JTable;
-import javax.swing.table.DefaultTableCellRenderer;
-import java.awt.Component;
-import jaxx.runtime.validator.BeanValidatorScope;
-
-/** @author chemit */
-public class SwingValidatorErrorTableRenderer extends DefaultTableCellRenderer {
-
- private static final long serialVersionUID = 1L;
- ImageIcon errorIcon;
- ImageIcon warningIcon;
- ImageIcon infoIcon;
-
- public SwingValidatorErrorTableRenderer() {
- errorIcon = jaxx.runtime.Util.createImageIcon("error.png");
- warningIcon = jaxx.runtime.Util.createImageIcon("warning.png");
- infoIcon = jaxx.runtime.Util.createImageIcon("info.png");
- }
-
- @Override
- public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
- JLabel rendererComponent = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
-
- ImageIcon icon = null;
- String text = null;
- if (value instanceof BeanValidatorScope) {
-
- BeanValidatorScope scope = (BeanValidatorScope) value;
- switch (scope) {
- case ERROR:
- icon = errorIcon;
- break;
- case WARNING:
- icon = warningIcon;
- break;
- case INFO:
- icon = infoIcon;
- break;
- }
- } else if (value instanceof SwingValidatorErrorModel) {
- SwingValidatorErrorModel model = (SwingValidatorErrorModel) value;
- String error = model.getError();
- text = model.getField().getI18nError(error);
- } else {
- // keep text rendered
- text = rendererComponent.getText();
- }
- rendererComponent.setText(text);
- rendererComponent.setIcon(icon);
- return rendererComponent;
- }
-
- @Override
- protected void setValue(Object value) {
- super.setValue(value);
- }
-}
\ No newline at end of file
Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java (from rev 1273, 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/SwingValidatorMessageListModel.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListModel.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -0,0 +1,135 @@
+package jaxx.runtime.validator.swing;
+
+import jaxx.runtime.validator.BeanValidatorEvent;
+
+import javax.swing.DefaultListModel;
+import javax.swing.JComponent;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import jaxx.runtime.validator.BeanValidatorField;
+import jaxx.runtime.validator.BeanValidatorListener;
+import jaxx.runtime.validator.BeanValidatorScope;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The model of the list of validation's messages
+ *
+ * @author chemit
+ */
+public class SwingValidatorMessageListModel extends DefaultListModel implements BeanValidatorListener {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(SwingValidatorMessageListModel.class);
+ private static final long serialVersionUID = 1L;
+ /** list of registred validators */
+ protected transient List<SwingValidator<?>> validators;
+
+ public SwingValidatorMessageListModel() {
+ validators = new ArrayList<SwingValidator<?>>();
+ }
+
+ public void registerValidator(SwingValidator<?> validator) {
+ if (validators.contains(validator)) {
+ throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
+ }
+ validators.add(validator);
+ validator.addBeanValidatorListener(this);
+ }
+
+ @Override
+ public void onFieldChanged(BeanValidatorEvent event) {
+ String[] toDelete = event.getMessagesToDelete();
+ String[] toAdd = event.getMessagesToAdd();
+ BeanValidatorScope scope = event.getScope();
+ SwingValidator validator = (SwingValidator) event.getSource();
+ BeanValidatorField field = event.getField();
+
+ if (log.isTraceEnabled()) {
+ log.trace("----------------------------------------------------------");
+ log.trace(field + " - (" + getSize() + ") toAdd " + (toAdd == null ? null : toAdd.length));
+ log.trace(field + " - (" + getSize() + ") toDelete " + (toDelete == null ? null : toDelete.length));
+ }
+
+ if ((toAdd == null || toAdd.length == 0) && (toDelete == null || toDelete.length == 0)) {
+ // no data to add nor remove, so nothing to do
+ return;
+ }
+
+ if (toAdd == null || toAdd.length == 0) {
+
+ if (log.isTraceEnabled()) {
+ log.trace(field + " - toDelete : just delete some datas!");
+ }
+
+ // no add, no need to resort the datas, can direclty delete
+ // messages we do not want any longer
+
+ // delete some messages for the given field and given scope
+ List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
+ List<Integer> indexs = new java.util.ArrayList<Integer>(toDelete.length);
+
+ Enumeration enumeration = elements();
+ int index = 0;
+ while (enumeration.hasMoreElements()) {
+ SwingValidatorMessageModel error = (SwingValidatorMessageModel) enumeration.nextElement();
+
+ if (error.getValidator() == validator && error.getField() == field && ids.contains(error.getMessage())) {
+ indexs.add(index);
+ }
+ index++;
+ }
+
+ java.util.Collections.reverse(indexs);
+
+ for (Integer i : indexs) {
+ removeElementAt(i);
+ }
+
+ return;
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace(field + " - add and delete !");
+ }
+
+ List<SwingValidatorMessageModel> newMessages = new ArrayList<SwingValidatorMessageModel>();
+
+
+
+ // obtain all messages not to delete
+
+ List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
+
+ Enumeration enumeration = elements();
+ while (enumeration.hasMoreElements()) {
+ SwingValidatorMessageModel error = (SwingValidatorMessageModel) enumeration.nextElement();
+
+ if (error.getValidator() != validator || error.getField() != field || !ids.contains(error.getMessage())) {
+ // keep this row
+ newMessages.add(error);
+ }
+ }
+
+ if (toAdd != null && toAdd.length > 0) {
+ JComponent editor = validator.getFieldRepresentation(field.getName());
+ // add new messages
+ for (String error : toAdd) {
+ newMessages.add(new SwingValidatorMessageModel(validator, field, error, editor));
+ }
+ }
+
+ // sort datas
+
+ java.util.Collections.sort(newMessages);
+
+ // clean model and reinject new errors
+ removeAllElements();
+
+ // reinject in list model, all the errors
+ for (SwingValidatorMessageModel error : newMessages) {
+ addElement(error);
+ }
+ }
+}
Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListMouseListener.java (from rev 1273, jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorListMouseListener.java)
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListMouseListener.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListMouseListener.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -0,0 +1,61 @@
+package jaxx.runtime.validator.swing;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.JComponent;
+import javax.swing.JList;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+/**
+ * A mouse listener to put on a {@link javax.swing.JList} with a {@link SwingValidatorMessageListModel} as a model.
+ * <p/>
+ * When a double click occurs, find the selected error in model and then focus to the associated component of error.
+ *
+ * @author chemit
+ */
+public class SwingValidatorMessageListMouseListener extends MouseAdapter {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(SwingValidatorMessageListMouseListener.class);
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (e.getClickCount() == 2) {
+
+ SwingValidatorMessageModel entry = getSelectedError(e);
+ if (entry == null) {
+ // no entry found
+ return;
+ }
+ JComponent component = entry.getEditor();
+ if (component != null) {
+ component.requestFocus();
+ }
+ }
+ }
+
+
+ protected SwingValidatorMessageModel getSelectedError(MouseEvent e) {
+ JList list = (JList) e.getSource();
+ if (!(list.getModel() instanceof SwingValidatorMessageListModel)) {
+ log.warn("model must be a " + SwingValidatorMessageListModel.class + ", but was " + list.getModel());
+ return null;
+ }
+
+ SwingValidatorMessageListModel model = (SwingValidatorMessageListModel) list.getModel();
+ int index = list.getSelectionModel().getMinSelectionIndex();
+ if (index == -1) {
+ // nothing is selected
+ return null;
+ }
+ SwingValidatorMessageModel entry = (SwingValidatorMessageModel) model.getElementAt(index);
+ if (log.isDebugEnabled()) {
+ log.debug("selected index: " + index + " : error: " + entry);
+ }
+ return entry;
+ }
+
+}
\ No newline at end of file
Property changes on: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageListMouseListener.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageModel.java (from rev 1273, jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorModel.java)
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageModel.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageModel.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -0,0 +1,75 @@
+package jaxx.runtime.validator.swing;
+
+import javax.swing.JComponent;
+import jaxx.runtime.validator.BeanValidatorField;
+
+/**
+ * The object to box a validation message within an u.
+ *
+ * @author chemit
+ * @since 1.3
+ */
+public class SwingValidatorMessageModel implements Comparable<SwingValidatorMessageModel> {
+
+ /**
+ * the validator that produce the message
+ */
+ protected SwingValidator validator;
+ /**
+ * the field thatproduce the message
+ */
+ protected BeanValidatorField field;
+ /**
+ * the label of the message (to be displayed somewhere)
+ */
+ protected String message;
+ /**
+ * the optional field's editor
+ */
+ protected JComponent editor;
+
+ public SwingValidatorMessageModel(SwingValidator validator, BeanValidatorField field, String message, JComponent editor) {
+ this.field = field;
+ this.validator = validator;
+ this.message = message;
+ this.editor = editor;
+ }
+
+ public JComponent getEditor() {
+ return editor;
+ }
+
+ public SwingValidator getValidator() {
+ return validator;
+ }
+
+ public BeanValidatorField getField() {
+ return field;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ @Override
+ public int compareTo(SwingValidatorMessageModel o) {
+ int result = field.getScope().compareTo(o.field.getScope());
+ if (result != 0) {
+ return result;
+ }
+ result = field.getName().compareTo(o.field.getName());
+ if (result != 0) {
+ return result;
+ }
+ result = message.compareTo(o.message);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ if (editor == null) {
+ return field.getI18nError(message);
+ }
+ return editor.getName() + " : " + field.getI18nError(message);
+ }
+}
Property changes on: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageModel.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java (from rev 1273, jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableModel.java)
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableModel.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -0,0 +1,158 @@
+package jaxx.runtime.validator.swing;
+
+import jaxx.runtime.validator.BeanValidatorEvent;
+
+import javax.swing.JComponent;
+import javax.swing.table.DefaultTableModel;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Vector;
+import jaxx.runtime.validator.BeanValidatorField;
+import jaxx.runtime.validator.BeanValidatorListener;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The model of the list of errors
+ *
+ * @author chemit
+ */
+public class SwingValidatorMessageTableModel extends DefaultTableModel implements BeanValidatorListener {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(SwingValidatorMessageTableMouseListener.class);
+ private static final long serialVersionUID = 1L;
+ public static final String[] columnNames = {"validator.scope", "validator.field", "validator.message"};
+ /** list of registred validators */
+ protected transient List<SwingValidator<?>> validators;
+ /** comporator of errors */
+ protected transient Comparator<SwingValidatorMessageModel> comparator;
+
+ public SwingValidatorMessageTableModel() {
+ super(columnNames, 0);
+ validators = new ArrayList<SwingValidator<?>>();
+ }
+
+ public int getErrorColumn() {
+ return findColumn(columnNames[2]);
+ }
+
+ @Override
+ public boolean isCellEditable(int row, int column) {
+ // cells are never editable in this model
+ return false;
+ }
+
+ public void registerValidator(SwingValidator<?> validator) {
+ if (validators.contains(validator)) {
+ throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
+ }
+ validators.add(validator);
+ validator.addBeanValidatorListener(this);
+ }
+
+ @Override
+ public void onFieldChanged(BeanValidatorEvent event) {
+ String[] toDelete = event.getMessagesToDelete();
+ String[] toAdd = event.getMessagesToAdd();
+ BeanValidatorField field = event.getField();
+
+ if (log.isTraceEnabled()) {
+ log.trace("----------------------------------------------------------");
+ log.trace(field + " - (" + getRowCount() + ") toAdd " + (toAdd == null ? null : toAdd.length));
+ log.trace(field + " - (" + getRowCount() + ") toDelete " + (toDelete == null ? null : toDelete.length));
+ }
+ if ((toAdd == null || toAdd.length == 0) && (toDelete == null || toDelete.length == 0)) {
+ // no data to add nor remove, so nothing to do
+ return;
+ }
+
+ SwingValidator validator = (SwingValidator) event.getSource();
+
+
+ int errorColumn = getErrorColumn();
+
+ if (toAdd == null || toAdd.length == 0) {
+
+
+ if (log.isTraceEnabled()) {
+ log.trace(field + " - toDelete : just delete some datas!");
+ }
+
+ // no add, no need to resort the datas, can direclty delete
+ // messages we do not want any longer
+
+ // delete some messages for the given field and given scope
+ List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
+ List<Integer> indexs = new java.util.ArrayList<Integer>(toDelete.length);
+
+ Enumeration enumeration = getDataVector().elements();
+
+ int index = 0;
+ while (enumeration.hasMoreElements()) {
+ Vector row = (Vector) enumeration.nextElement();
+ SwingValidatorMessageModel error = (SwingValidatorMessageModel) row.get(errorColumn);
+ if (error.getValidator() == validator && error.getField() == field && ids.contains(error.getMessage())) {
+ // remo the message
+ indexs.add(index);
+ }
+ index++;
+ }
+ java.util.Collections.reverse(indexs);
+
+ for (Integer i : indexs) {
+ removeRow(i);
+ }
+
+ return;
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace(field + " - add and delete !");
+ }
+
+ // rebuild all the data (since we are some adding data and we ensure
+ // an order on datas)
+
+ List<SwingValidatorMessageModel> newMessages = new ArrayList<SwingValidatorMessageModel>();
+
+ // delete some messages for the given field and given scope
+ List<String> ids = new java.util.ArrayList<String>(java.util.Arrays.asList(toDelete));
+
+ Enumeration enumeration = getDataVector().elements();
+
+ while (enumeration.hasMoreElements()) {
+ Vector row = (Vector) enumeration.nextElement();
+ SwingValidatorMessageModel error = (SwingValidatorMessageModel) row.get(errorColumn);
+ if (error.getValidator() != validator || error.getField() != field || !ids.contains(error.getMessage())) {
+ // keep this row
+ newMessages.add(error);
+ }
+ }
+
+ if (toAdd != null && toAdd.length > 0) {
+ JComponent editor = validator.getFieldRepresentation(field.getName());
+ // add new errors
+ for (String error : toAdd) {
+ SwingValidatorMessageModel errorModel = new SwingValidatorMessageModel(validator, field, error, editor);
+ newMessages.add(errorModel);
+ }
+ }
+
+ // sort datas
+
+ java.util.Collections.sort(newMessages);
+
+ // clean table model and reinject new messages
+ getDataVector().clear();
+
+ // reinject in list model, all the errors
+ for (SwingValidatorMessageModel error : newMessages) {
+ addRow(new Object[]{error.getField().getScope(), error.getField().getName(), error});
+ }
+
+ fireTableDataChanged();
+ }
+}
\ No newline at end of file
Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableMouseListener.java (from rev 1273, jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableMouseListener.java)
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableMouseListener.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableMouseListener.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -0,0 +1,92 @@
+package jaxx.runtime.validator.swing;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.JComponent;
+import javax.swing.JTable;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+/**
+ * A mouse listener to put on a {@link javax.swing.JList} with a {@link SwingValidatorMessageTableModel} as a model.
+ * <p/>
+ * When a double click occurs, find the selected error in model and then focus to the associated component of error.
+ *
+ * @author chemit
+ */
+public class SwingValidatorMessageTableMouseListener extends MouseAdapter {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(SwingValidatorMessageTableMouseListener.class);
+
+ public static final String HIGHLIGHT_ERROR_PROPERTY = "highlightError";
+
+ /** delgate property change support */
+ protected PropertyChangeSupport pcs;
+
+ public SwingValidatorMessageTableMouseListener() {
+ pcs = new PropertyChangeSupport(this);
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ super.mouseClicked(e);
+ if (e.getClickCount() == 2) {
+
+ SwingValidatorMessageModel entry = getSelectedError(e);
+ if (entry == null) {
+ // no entry found
+ return;
+ }
+ JComponent component = entry.getEditor();
+ if (component != null) {
+ pcs.firePropertyChange(HIGHLIGHT_ERROR_PROPERTY, null, entry);
+ if (component.isVisible()) {
+ component.requestFocus();
+ }
+ }
+ }
+ }
+
+
+ protected SwingValidatorMessageModel getSelectedError(MouseEvent e) {
+ JTable table = (JTable) e.getSource();
+ if (!(table.getModel() instanceof SwingValidatorMessageTableModel)) {
+ log.warn("model must be a " + SwingValidatorMessageTableModel.class + ", but was " + table.getModel());
+ return null;
+ }
+
+ SwingValidatorMessageTableModel model = (SwingValidatorMessageTableModel) table.getModel();
+ int index = table.getSelectionModel().getMinSelectionIndex();
+ if (index == -1) {
+ // nothing is selected
+ return null;
+ }
+ int col = model.getErrorColumn();
+ SwingValidatorMessageModel entry = (SwingValidatorMessageModel) model.getValueAt(index, col);
+ if (log.isDebugEnabled()) {
+ log.debug("selected index: " + index + " : error: " + entry);
+ }
+ return entry;
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }
+
+}
\ No newline at end of file
Property changes on: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableMouseListener.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableRenderer.java (from rev 1273, jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorErrorTableRenderer.java)
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableRenderer.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableRenderer.java 2009-03-21 08:22:03 UTC (rev 1274)
@@ -0,0 +1,61 @@
+package jaxx.runtime.validator.swing;
+
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JTable;
+import javax.swing.table.DefaultTableCellRenderer;
+import java.awt.Component;
+import jaxx.runtime.validator.BeanValidatorScope;
+
+/** @author chemit */
+public class SwingValidatorMessageTableRenderer extends DefaultTableCellRenderer {
+
+ private static final long serialVersionUID = 1L;
+ ImageIcon errorIcon;
+ ImageIcon warningIcon;
+ ImageIcon infoIcon;
+
+ public SwingValidatorMessageTableRenderer() {
+ errorIcon = jaxx.runtime.Util.createImageIcon("error.png");
+ warningIcon = jaxx.runtime.Util.createImageIcon("warning.png");
+ infoIcon = jaxx.runtime.Util.createImageIcon("info.png");
+ }
+
+ @Override
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+ JLabel rendererComponent = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
+
+ ImageIcon icon = null;
+ String text = null;
+ if (value instanceof BeanValidatorScope) {
+
+ BeanValidatorScope scope = (BeanValidatorScope) value;
+ switch (scope) {
+ case ERROR:
+ icon = errorIcon;
+ break;
+ case WARNING:
+ icon = warningIcon;
+ break;
+ case INFO:
+ icon = infoIcon;
+ break;
+ }
+ } else if (value instanceof SwingValidatorMessageModel) {
+ SwingValidatorMessageModel model = (SwingValidatorMessageModel) value;
+ String error = model.getMessage();
+ text = model.getField().getI18nError(error);
+ } else {
+ // keep text rendered
+ text = rendererComponent.getText();
+ }
+ rendererComponent.setText(text);
+ rendererComponent.setIcon(icon);
+ return rendererComponent;
+ }
+
+ @Override
+ protected void setValue(Object value) {
+ super.setValue(value);
+ }
+}
\ No newline at end of file
Property changes on: jaxx/trunk/jaxx-runtime-validator-swing/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageTableRenderer.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorListModel.jaxx
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorListModel.jaxx 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorListModel.jaxx 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,4 +1,4 @@
<Application>
- <jaxx.runtime.validator.swing.SwingValidatorErrorListModel id='errors'/>
+ <jaxx.runtime.validator.swing.SwingValidatorMessageListModel id='errors'/>
<BeanValidator beanClass='testcases.validator.errors.Model' errorListModel='errors' errorListModel='fake'/>
</Application>
Modified: jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorTableModel.jaxx
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorTableModel.jaxx 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorTableModel.jaxx 2009-03-21 08:22:03 UTC (rev 1274)
@@ -1,4 +1,4 @@
<Application>
- <jaxx.runtime.validator.swing.SwingValidatorErrorListModel id='errors'/>
+ <jaxx.runtime.validator.swing.SwingValidatorMessageListModel id='errors'/>
<BeanValidator beanClass='testcases.validator.errors.Model' errorTableModel='errors' errorTableModel='fake'/>
</Application>
Modified: jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Validation.jaxx
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Validation.jaxx 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Validation.jaxx 2009-03-21 08:22:03 UTC (rev 1274)
@@ -6,7 +6,7 @@
<Identity id='identity'/>
<!-- errors model -->
- <jaxx.runtime.validator.swing.SwingValidatorErrorListModel id='errors'
+ <jaxx.runtime.validator.swing.SwingValidatorMessageListModel id='errors'
onContentsChanged='ok.setEnabled(errors.size()==0)'/>
<!-- validators -->
Modified: jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/ValidationBeanClass.jaxx
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/ValidationBeanClass.jaxx 2009-03-20 13:02:18 UTC (rev 1273)
+++ jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/ValidationBeanClass.jaxx 2009-03-21 08:22:03 UTC (rev 1274)
@@ -4,7 +4,7 @@
<Identity id='identity'/>
<!-- errors model -->
- <jaxx.runtime.validator.swing.SwingValidatorErrorListModel id='errors'/>
+ <jaxx.runtime.validator.swing.SwingValidatorMessageListModel id='errors'/>
<!-- validators -->
<BeanValidator id='validator3' autoField='true' beanClass='testcases.validator.ok.Identity' errorListModel='errors'>
1
0
[Buix-commits] r1273 - in jaxx/trunk: . jaxx-compiler-api jaxx-compiler-swing jaxx-compiler-validator jaxx-example jaxx-runtime-api jaxx-runtime-swing jaxx-runtime-validator jaxx-runtime-validator-swing jaxx-swing-action jaxx-util maven-jaxx-plugin
by tchemit@users.labs.libre-entreprise.org 20 Mar '09
by tchemit@users.labs.libre-entreprise.org 20 Mar '09
20 Mar '09
Author: tchemit
Date: 2009-03-20 13:02:18 +0000 (Fri, 20 Mar 2009)
New Revision: 1273
Modified:
jaxx/trunk/changelog.txt
jaxx/trunk/jaxx-compiler-api/changelog.txt
jaxx/trunk/jaxx-compiler-swing/changelog.txt
jaxx/trunk/jaxx-compiler-validator/changelog.txt
jaxx/trunk/jaxx-example/changelog.txt
jaxx/trunk/jaxx-runtime-api/changelog.txt
jaxx/trunk/jaxx-runtime-swing/changelog.txt
jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt
jaxx/trunk/jaxx-runtime-validator/changelog.txt
jaxx/trunk/jaxx-swing-action/changelog.txt
jaxx/trunk/jaxx-util/changelog.txt
jaxx/trunk/maven-jaxx-plugin/changelog.txt
Log:
release 1.3
Modified: jaxx/trunk/changelog.txt
===================================================================
--- jaxx/trunk/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,5 +1,6 @@
-1.3
+1.3 chemit 20090320
* 20090313 [chemit] - use i18n 0.10
+
1.2 ??? 2009????
* 20090223 [chemit] - move sources from jaxx-util to jaxx-swing-action module
- delete jaxx-util module
Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,4 +1,4 @@
-1.3 ??? 200902??
+1.3 chemit 20090320
* 20090313 [chemit] - can now use geneticType on javaBean object
- add an extra method $afterCompleteSetup method to be included if find in script at last statement of $completeSetup method
Modified: jaxx/trunk/jaxx-compiler-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-swing/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-compiler-swing/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,3 +1,5 @@
+1.3 chemit 20090320
+
1.1 chemit 20090220
* 20090122 [chemit] - refactor poms (sibling dependencies, pluginsManagment,...)
Modified: jaxx/trunk/jaxx-compiler-validator/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-validator/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-compiler-validator/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,3 +1,5 @@
+1.3 chemit 20090320
+
1.1 chemit 20090220
* 20090202 [chemit] - refactor validators (this module will soon disappear to jaxx-compiler-swing-validator)
* 20090122 [chemit] - refactor poms (sibling dependencies, pluginsManagment,...)
Modified: jaxx/trunk/jaxx-example/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-example/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-example/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,4 +1,4 @@
-1.3
+1.3 chemit 20090320
* 20090319 [chemit] - refactor Validator : now can deal with scopes, improve design
* 20090313 [chemit] - improve demo
Modified: jaxx/trunk/jaxx-runtime-api/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-api/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-runtime-api/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,4 +1,4 @@
-1.3 ??? 200903??
+1.3 chemit 20090320
* 20090302 [chemit] - add pcs in ApplicationContext
- add method in Util to filter JAXX property changed listeners
Modified: jaxx/trunk/jaxx-runtime-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,4 +1,4 @@
-1.3 ?? 200903??
+1.3 chemit 20090320
* 20090318 [chemit] - introduce the BlockingLayerUI2 class (should be merge with BlockingLayerUI)
* 20090318 [chemit] - introduce the CardLayout2Ext class
* 20090312 [chemit] - add some usefull code from ObServe (load Nimbus L&F, load ui configuration)
Modified: jaxx/trunk/jaxx-runtime-validator/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-runtime-validator/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,4 +1,4 @@
-1.3 ??? 200903??
+1.3 chemit 20090320
* 20090319 [chemit] - refactor Validator : now can deal with scopes, improve design
1.1 chemit 20090220
Modified: jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-runtime-validator-swing/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,4 +1,4 @@
-1.3 ??? 200903??
+1.3 chemit 20090320
* 20090319 [chemit] - refactor Validator : now can deal with scopes, improve design
1.1 chemit 20090220
Modified: jaxx/trunk/jaxx-swing-action/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-swing-action/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-swing-action/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,3 +1,5 @@
+1.3 chemit 20090320
+
1.1 chemit 20090220
* 20090122 [chemit] - refactor poms (sibling dependencies, pluginsManagment,...)
- rename i18n bundles according artifactId
Modified: jaxx/trunk/jaxx-util/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-util/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/jaxx-util/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,3 +1,5 @@
+1.3 chemit 20090320
+
1.1 chemit 20090220
* 20090122 [chemit] - refactor poms (sibling dependencies, pluginsManagment,...)
- rename i18n bundles according artifactId
Modified: jaxx/trunk/maven-jaxx-plugin/changelog.txt
===================================================================
--- jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-03-19 22:47:05 UTC (rev 1272)
+++ jaxx/trunk/maven-jaxx-plugin/changelog.txt 2009-03-20 13:02:18 UTC (rev 1273)
@@ -1,4 +1,4 @@
-1.3 ??? 200903??
+1.3 chemit 20090320
* 20090301 [chemit] - add a profile mode (-Djaxx.profile)
1.2 letelier 2009022?
1
0