JBoss Rich Faces SVN: r17692 - in root/cdk/branches/RF8755/plugins/generator/src: main/java/org/richfaces/cdk/generate/freemarker and 10 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-30 19:15:43 -0400 (Wed, 30 Jun 2010)
New Revision: 17692
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
Removed:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
Log:
improve template-based statements
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -36,7 +36,6 @@
import org.richfaces.cdk.apt.AptModule;
import org.richfaces.cdk.generate.freemarker.FreeMakerModule;
import org.richfaces.cdk.generate.java.ClassGeneratorModule;
-import org.richfaces.cdk.generate.java.taghandler.TagHandlerModule;
import org.richfaces.cdk.generate.taglib.TaglibModule;
import org.richfaces.cdk.model.ModelModule;
import org.richfaces.cdk.model.validator.ValidatorImpl;
@@ -48,9 +47,7 @@
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
-import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
-import com.google.inject.util.Providers;
/**
* @author asmirnov
@@ -118,7 +115,7 @@
public void init() {
injector =
Guice.createInjector(Stage.PRODUCTION, new CdkConfigurationModule(), new AptModule(), new ModelModule(),
- new ClassGeneratorModule(), new TagHandlerModule(), new FreeMakerModule(), new TemplateModule(),
+ new FreeMakerModule(),new ClassGeneratorModule(), new TemplateModule(),
new XmlModule(), new TaglibModule());
if (!log.isDebugEnabled()) {
@@ -179,16 +176,9 @@
}
bind(NamingConventions.class).to(RichFacesConventions.class);
bind(ModelValidator.class).to(ValidatorImpl.class);
-
- bind(new TypeLiteral<Map<String, String>>() {
- }).annotatedWith(Names.named(OPTIONS)).toInstance(options);
- bindOption(RENDERER_UTILS_CLASS);
+ Names.bindProperties(binder(), options);
}
- private void bindOption(String name) {
- bind(String.class).annotatedWith(Names.named(name)).toProvider(
- Providers.of(options.get(name)));
- }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -23,22 +23,30 @@
package org.richfaces.cdk.generate.freemarker;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Map;
+
import org.richfaces.cdk.Logger;
import com.google.inject.Inject;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateModelException;
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
*/
-public class CdkConfiguration extends Configuration {
-
+public class CdkConfiguration extends Configuration implements FreeMarkerRenderer {
+
private static final String TEMPLATES = "/META-INF/templates";
-
+
private Logger log;
@Inject
@@ -47,12 +55,56 @@
this.log = log;
// load templates from plugin classloader.
- setClassForTemplateLoading(this.getClass(), TEMPLATES);
+ setClassForTemplateLoading(this.getClass(), getTemplatesFolder());
setTemplateUpdateDelay(10000);// Forever...
setSharedVariable("utils", utils);
setObjectWrapper(wrapper);
-
// Add context variables
-// this.setSharedVariable("context", new BeanModel(context, new BeansWrapper()));
+ // this.setSharedVariable("context", new BeanModel(context, new BeansWrapper()));
}
+
+ @Inject(optional=true)
+ protected void setSharedVariables(Map<String,Object> variables) {
+ // template method for subclasses.
+ for (Map.Entry<String,Object> entry : variables.entrySet()) {
+ try {
+ setSharedVariable(entry.getKey(), entry.getValue());
+ } catch (TemplateModelException e) {
+ log.error("Error to set shared variable "+entry.getKey(), e);
+ }
+ }
+ }
+
+ @Override
+ public void writeTemplate(String templateName, Object object, Writer writer) throws IOException, TemplateException {
+ getTemplate(templateName).process(object, writer);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#renderSnippet(java.lang.String, java.lang.Object)
+ */
+ @Override
+ public String renderTemplate(String templateName, Object object) {
+ StringWriter writer = new StringWriter();
+ try {
+ writeTemplate(templateName, object, writer);
+ return writer.toString();
+ } catch (IOException e) {
+ log.error("Error rendering template", e);
+ return e.getMessage();
+ } catch (TemplateException e) {
+ log.error("Error rendering template", e);
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the templates
+ */
+ public static String getTemplatesFolder() {
+ return TEMPLATES;
+ }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -25,9 +25,6 @@
import com.google.inject.AbstractModule;
-import freemarker.template.Configuration;
-import freemarker.template.ObjectWrapper;
-
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
@@ -37,8 +34,7 @@
@Override
protected void configure() {
- bind(Configuration.class).to(CdkConfiguration.class);
- bind(ObjectWrapper.class).to(LibraryModelWrapper.class);
+ bind(FreeMarkerRenderer.class).to(CdkConfiguration.class);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -1,104 +1,15 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-
package org.richfaces.cdk.generate.freemarker;
-import java.io.File;
import java.io.IOException;
import java.io.Writer;
-import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.CdkWriter;
-import org.richfaces.cdk.FileManager;
-import org.richfaces.cdk.model.ClassName;
-import org.richfaces.cdk.model.ComponentLibrary;
-import org.richfaces.cdk.model.ModelElementBase;
-import org.richfaces.cdk.model.Trackable;
-
-import freemarker.template.Configuration;
import freemarker.template.TemplateException;
-/**
- * <p class="changed_added_4_0">Base class for all output file buildes that use FreeMarker as template engine.</p>
- * @author asmirnov(a)exadel.com
- *
- */
-public abstract class FreeMarkerRenderer<C> implements CdkWriter {
+public interface FreeMarkerRenderer {
+ public void writeTemplate(String templateName, Object object, Writer writer)
+ throws IOException, TemplateException;
- private final Configuration configuration;
+ public String renderTemplate(String templateName, Object object);
- private final FileManager output;
-
- public FreeMarkerRenderer(Configuration configuration, FileManager output) {
- this.configuration = configuration;
- this.output = output;
- }
-
- public void generate(ComponentLibrary library,C c) throws CdkException {
- try {
- Writer out = getOutput(library, c);
- if(null != out){
- configuration.getTemplate(getTemplateName()).process(c, out);
- out.close();
- }
- } catch (IOException e) {
- throw new CdkException(e);
- } catch (TemplateException e) {
- throw new CdkException(e);
- }
- }
-
- protected Writer getOutput(ComponentLibrary library, C c) throws CdkException {
- long lastModified = Long.MIN_VALUE;
-
- if (c instanceof Trackable) {
- Trackable trackuble = (Trackable) c;
- lastModified = trackuble.lastModified();
- }
-
- try {
- return output.createOutput(getOutputFileName(c), lastModified);
- } catch (IOException e) {
- throw new CdkException(e);
- }
- }
-
- protected String getOutputFileName(C c) throws CdkException {
- if (c instanceof ModelElementBase) {
- ModelElementBase modelElement = (ModelElementBase) c;
- return modelElement.getTargetClass().getName().replace('.', File.separatorChar) + ".java";
- } else {
- throw new CdkException("Unknown model object " + c);
- }
- }
-
- protected String getJavaFileName(ClassName targetClass){
- return targetClass.getName().replace('.', File.separatorChar) + ".java";
- }
-
- protected abstract String getTemplateName();
-
-}
+}
\ No newline at end of file
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java (from rev 17685, root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -0,0 +1,103 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.richfaces.cdk.generate.freemarker;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.ModelElementBase;
+import org.richfaces.cdk.model.Trackable;
+
+import freemarker.template.TemplateException;
+
+/**
+ * <p class="changed_added_4_0">Base class for all output file buildes that use FreeMarker as template engine.</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public abstract class FreeMarkerWriter<C> implements CdkWriter {
+
+
+ private final FreeMarkerRenderer configuration;
+
+ private final FileManager output;
+
+ public FreeMarkerWriter(FreeMarkerRenderer configuration, FileManager output) {
+ this.configuration = configuration;
+ this.output = output;
+ }
+
+ public void generate(ComponentLibrary library,C c) throws CdkException {
+ try {
+ Writer out = getOutput(library, c);
+ if(null != out){
+ configuration.writeTemplate(getTemplateName(),c, out);
+ out.close();
+ }
+ } catch (IOException e) {
+ throw new CdkException(e);
+ } catch (TemplateException e) {
+ throw new CdkException(e);
+ }
+ }
+
+ protected Writer getOutput(ComponentLibrary library, C c) throws CdkException {
+ long lastModified = Long.MIN_VALUE;
+
+ if (c instanceof Trackable) {
+ Trackable trackuble = (Trackable) c;
+ lastModified = trackuble.lastModified();
+ }
+
+ try {
+ return output.createOutput(getOutputFileName(c), lastModified);
+ } catch (IOException e) {
+ throw new CdkException(e);
+ }
+ }
+
+ protected String getOutputFileName(C c) throws CdkException {
+ if (c instanceof ModelElementBase) {
+ ModelElementBase modelElement = (ModelElementBase) c;
+ return modelElement.getTargetClass().getName().replace('.', File.separatorChar) + ".java";
+ } else {
+ throw new CdkException("Unknown model object " + c);
+ }
+ }
+
+ protected String getJavaFileName(ClassName targetClass){
+ return targetClass.getName().replace('.', File.separatorChar) + ".java";
+ }
+
+ protected abstract String getTemplateName();
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -30,21 +30,20 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.BehaviorModel;
import org.richfaces.cdk.model.ComponentLibrary;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author akolonitsky
* @since Jan 21, 2010
*/
-public class BehaviorClassGenerator extends FreeMarkerRenderer<BehaviorModel> implements CdkWriter {
+public class BehaviorClassGenerator extends FreeMarkerWriter<BehaviorModel> implements CdkWriter {
@Inject
- public BehaviorClassGenerator(Configuration configuration,
+ public BehaviorClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -23,19 +23,31 @@
package org.richfaces.cdk.generate.java;
+import java.util.Set;
+
import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.generate.freemarker.LibraryModelWrapper;
+import org.richfaces.cdk.generate.java.taghandler.ListenerTagHandlerGenerator;
+import org.richfaces.cdk.generate.java.taghandler.TagHandlerWriter;
-import com.google.inject.AbstractModule;
+import com.google.inject.PrivateModule;
+import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
+import freemarker.template.ObjectWrapper;
+
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
-public class ClassGeneratorModule extends AbstractModule {
+public class ClassGeneratorModule extends PrivateModule {
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.google.inject.AbstractModule#configure()
*/
@Override
@@ -46,6 +58,11 @@
setBinder.addBinding().to(ValidatorClassGenerator.class);
setBinder.addBinding().to(BehaviorClassGenerator.class);
setBinder.addBinding().to(EventSourceInterfaceGenerator.class);
+ setBinder.addBinding().to(TagHandlerWriter.class);
+ setBinder.addBinding().to(ListenerTagHandlerGenerator.class);
+ TypeLiteral<Set<CdkWriter>> writersType = new TypeLiteral<Set<CdkWriter>>(){};
+ expose(writersType);
+ bind(ObjectWrapper.class).to(LibraryModelWrapper.class);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -33,22 +33,21 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
*
*/
-public class ComponentClassGenerator extends FreeMarkerRenderer<ComponentModel> implements CdkWriter {
+public class ComponentClassGenerator extends FreeMarkerWriter<ComponentModel> implements CdkWriter {
@Inject
- public ComponentClassGenerator(Configuration configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public ComponentClassGenerator(FreeMarkerRenderer configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -30,21 +30,20 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ConverterModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author akolonitsky
* @since Jan 20, 2010
*/
-public class ConverterClassGenerator extends FreeMarkerRenderer<ConverterModel> implements CdkWriter {
+public class ConverterClassGenerator extends FreeMarkerWriter<ConverterModel> implements CdkWriter {
@Inject
- public ConverterClassGenerator(Configuration configuration,
+ public ConverterClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -31,21 +31,20 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author asmirnov
* @since Jan 20, 2010
*/
-public class EventSourceInterfaceGenerator extends FreeMarkerRenderer<EventModel> implements CdkWriter {
+public class EventSourceInterfaceGenerator extends FreeMarkerWriter<EventModel> implements CdkWriter {
@Inject
- public EventSourceInterfaceGenerator(Configuration configuration,
+ public EventSourceInterfaceGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -30,21 +30,20 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ValidatorModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author akolonitsky
* @since Jan 15, 2010
*/
-public class ValidatorClassGenerator extends FreeMarkerRenderer<ValidatorModel> implements CdkWriter {
+public class ValidatorClassGenerator extends FreeMarkerWriter<ValidatorModel> implements CdkWriter {
@Inject
- public ValidatorClassGenerator(Configuration configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public ValidatorClassGenerator(FreeMarkerRenderer configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -32,22 +32,21 @@
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.TagModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author akolonitsky
* @since Jan 20, 2010
*/
-public class ListenerTagHandlerGenerator extends FreeMarkerRenderer<TagWithModel<EventModel>> implements CdkWriter {
+public class ListenerTagHandlerGenerator extends FreeMarkerWriter<TagWithModel<EventModel>> implements CdkWriter {
@Inject
- public ListenerTagHandlerGenerator(Configuration configuration,
+ public ListenerTagHandlerGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -30,13 +30,13 @@
import org.richfaces.cdk.FileManager;
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.TagModel;
import org.richfaces.cdk.model.Trackable;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
import freemarker.template.TemplateException;
/**
@@ -49,10 +49,10 @@
private final FileManager output;
- private final Configuration configuration;
+ private final FreeMarkerRenderer configuration;
@Inject
- public TagHandlerClassGenerator(Configuration configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public TagHandlerClassGenerator(FreeMarkerRenderer configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
this.configuration = configuration;
this.output = output;
}
@@ -60,7 +60,7 @@
public boolean process(ModelElementBase model, TagModel tag) throws CdkException {
try {
Writer writer = getOutput(tag);
- configuration.getTemplate(TAGHANDLER_TEMPLATE).process(new TagWithModel<ModelElementBase>(tag, model),
+ configuration.writeTemplate(TAGHANDLER_TEMPLATE,new TagWithModel<ModelElementBase>(tag, model),
writer);
writer.close();
} catch (IOException e) {
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerModule.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerModule.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerModule.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright , Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.richfaces.cdk.generate.java.taghandler;
-
-import org.richfaces.cdk.CdkWriter;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.multibindings.Multibinder;
-
-/**
- * @author akolonitsky
- * @since Feb 22, 2010
- */
-public class TagHandlerModule extends AbstractModule {
-
- @Override
- protected void configure() {
- Multibinder<CdkWriter> multibinder = Multibinder.newSetBinder(binder(), CdkWriter.class);
- multibinder
- .addBinding().to(TagHandlerWriter.class);
- multibinder
- .addBinding().to(ListenerTagHandlerGenerator.class);
- }
-}
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -1,15 +0,0 @@
-package org.richfaces.cdk.templatecompiler;
-
-import java.io.IOException;
-import java.io.Writer;
-
-import freemarker.template.TemplateException;
-
-public interface FreeMarkerRenderer {
-
- public void writeSnippet(String templateName, Object object, Writer writer)
- throws IOException, TemplateException;
-
- public String renderSnippet(String templateName, Object object);
-
-}
\ No newline at end of file
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -29,6 +29,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
@@ -47,7 +49,7 @@
setClassForTemplateLoading(this.getClass(), TEMPLATES);
// TODO create an object wrapper for library model.
- setObjectWrapper(new JavaClassModelWrapper(this));
+ setObjectWrapper(new JavaClassModelWrapper());
// Add context variables
// this.setSharedVariable("context", new BeanModel(context, new BeansWrapper()));
@@ -56,7 +58,7 @@
/* (non-Javadoc)
* @see org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#writeSnippet(java.lang.String, java.lang.Object, java.io.Writer)
*/
- public void writeSnippet(String templateName, Object object, Writer writer) throws IOException, TemplateException {
+ public void writeTemplate(String templateName, Object object, Writer writer) throws IOException, TemplateException {
Template t = getTemplate(templateName + ".ftl");
Map<String, Object> rootMap = new HashMap<String, Object>();
rootMap.put("modelItem", object);
@@ -72,10 +74,10 @@
/* (non-Javadoc)
* @see org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#renderSnippet(java.lang.String, java.lang.Object)
*/
- public String renderSnippet(String templateName, Object object) {
+ public String renderTemplate(String templateName, Object object) {
StringWriter writer = new StringWriter();
try {
- writeSnippet(templateName, object, writer);
+ writeTemplate(templateName, object, writer);
return writer.toString();
} catch (IOException e) {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -9,10 +9,8 @@
public class JavaClassModelWrapper extends BeansWrapper implements ObjectWrapper {
- private final JavaClassConfiguration configuration;
- public JavaClassModelWrapper(JavaClassConfiguration configuration) {
- this.configuration = configuration;
+ public JavaClassModelWrapper() {
}
@Override
@@ -30,13 +28,5 @@
return templateModel;
}
- /**
- * <p class="changed_added_4_0"></p>
- *
- * @return the configuration
- */
- public JavaClassConfiguration getConfiguration() {
- return configuration;
- }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -33,6 +33,7 @@
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.ModelSet;
@@ -115,7 +116,7 @@
output.createOutput(fullName.replace('.', '/') + ".java", library.lastModified());
if (null != outFile) {
- this.renderer.writeSnippet("class", javaClass, outFile);
+ this.renderer.writeTemplate("class", javaClass, outFile);
outFile.close();
}
} catch (IOException e) {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -104,6 +104,7 @@
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
@@ -145,6 +146,13 @@
*/
static final String CLIENT_ID_VARIABLE = "clientId";
+ static final ImmutableMap<String, Object> ENCODE_METHOD_VARIABLES = ImmutableMap.<String, Object>builder()
+ .put("facesContextVariable", RendererClassVisitor.FACES_CONTEXT_VARIABLE)
+ .put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE)
+ .put("responseWriterVariable", RendererClassVisitor.RESPONSE_WRITER_VARIABLE)
+ .put("clientIdVariable", RendererClassVisitor.CLIENT_ID_VARIABLE)
+ .build();
+
/**
*
*/
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -23,6 +23,9 @@
package org.richfaces.cdk.templatecompiler;
+import java.util.Map;
+import java.util.Set;
+
import org.richfaces.cdk.CdkWriter;
import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.attributes.Schema;
@@ -33,18 +36,20 @@
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactoryImpl;
-import com.google.inject.AbstractModule;
+import com.google.inject.PrivateModule;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;
+import freemarker.template.ObjectWrapper;
+
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
*
*/
-public class TemplateModule extends AbstractModule {
+public class TemplateModule extends PrivateModule {
/* (non-Javadoc)
* @see com.google.inject.AbstractModule#configure()
@@ -53,13 +58,19 @@
protected void configure() {
Multibinder<ModelBuilder> modelBinder = Multibinder.newSetBinder(binder(), ModelBuilder.class);
modelBinder.addBinding().to(RendererTemplateParser.class);
+ TypeLiteral<Set<ModelBuilder>> buildersType = new TypeLiteral<Set<ModelBuilder>>(){};
+ expose(buildersType);
Multibinder.newSetBinder(binder(), CdkWriter.class).addBinding().to(RendererClassGenerator.class);
+ TypeLiteral<Set<CdkWriter>> writersType = new TypeLiteral<Set<CdkWriter>>(){};
+ expose(writersType);
+ // Private bindings.
bind(new TypeLiteral<TemplateVisitorFactory<RendererClassVisitor>>(){}).to(VisitorFactoryImpl.class).in(Singleton.class);
- bind(FreeMarkerRenderer.class).to(JavaClassConfiguration.class);
bind(TypesFactory.class).to(TypesFactoryImpl.class);
bind(ELParser.class).to(ELParserImpl.class);
bind(HelperMethodFactory.class).to(HelperMethodFactoryImpl.class).in(Singleton.class);
bind(Schema.class).annotatedWith(Names.named(Template.XHTML_EL_NAMESPACE)).toProvider(XhtmlElSchemaProvider.class).in(Singleton.class);
+ bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
+ bind(new TypeLiteral<Map<String,Object>>(){}).toInstance(RendererClassVisitor.ENCODE_METHOD_VARIABLES);
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -22,7 +22,6 @@
package org.richfaces.cdk.templatecompiler.builder.model;
import java.util.ArrayList;
-import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
@@ -40,11 +39,7 @@
private static final ClassName DEFAULT_SUPERCLASS = ClassName.get(Renderer.class);
private List<JavaField> fields = new ArrayList<JavaField>();
private List<JavaMethod> methods = new ArrayList<JavaMethod>();
- private Set<JavaImport> imports = new TreeSet<JavaImport>(new Comparator<JavaImport>() {
- public int compare(JavaImport o1, JavaImport o2) {
- return o1.getName().compareTo(o2.getName());
- }
- });
+ private Set<JavaImport> imports = new TreeSet<JavaImport>(JavaImport.COMPARATOR);
private ClassName superClass = DEFAULT_SUPERCLASS;
private final JavaPackage pakg;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,10 +21,18 @@
package org.richfaces.cdk.templatecompiler.builder.model;
+import java.util.Comparator;
+
/**
* @author Maksim Kaszynski
*/
public interface JavaImport {
- public String getName();
- public boolean isDefault();
+ public Comparator<? super JavaImport> COMPARATOR = new Comparator<JavaImport>() {
+ public int compare(JavaImport o1, JavaImport o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ };
+ String getName();
+
+ boolean isDefault();
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -94,6 +94,7 @@
import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
+import org.richfaces.cdk.templatecompiler.statements.StatementsContainer;
import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
/**
* Entry point for parsing EL expressions. @see parse() method.
@@ -117,6 +118,8 @@
private boolean mixedExpression;
private boolean literal = true;
+
+ private StatementsContainer parent;
public ELVisitor(Logger log, TypesFactory typesFactory) {
@@ -364,4 +367,10 @@
return treeNode;
}
+
+ @Override
+ public void setParent(StatementsContainer parent) {
+ this.parent = parent;
+ }
+
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -85,7 +85,7 @@
*/
@Override
public String toString() {
- return getClass().getName();
+ return "null";
}
/* (non-Javadoc)
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,8 +21,14 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*/
@@ -32,17 +38,52 @@
private String name;
- private String initializationExpression;
+ private final ELParser parser;
- public DefineObjectStatement(ELType type, String name, String initializationExpression) {
- super("define-object");
+ private TypedTemplateStatement initializationStatement;
+ @Inject
+ public DefineObjectStatement(FreeMarkerRenderer renderer, ELParser parser) {
+ super(renderer, "define-object");
+ this.parser = parser;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param type
+ * the type to set
+ */
+ public void setType(ELType type) {
this.type = type;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param name
+ * the name to set
+ */
+ public void setName(String name) {
this.name = name;
- this.initializationExpression = initializationExpression != null ? initializationExpression : "";
}
/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param initializationExpression
+ * the initializationExpression to set
+ * @throws ParsingException
+ */
+ public void setInitializationExpression(String initializationExpression) throws ParsingException {
+ initializationStatement = parser.parse(initializationExpression, this, TypesFactory.OBJECT_TYPE);
+ initializationStatement.setParent(this);
+ }
+
+ /**
* @return the type
*/
public ELType getType() {
@@ -59,8 +100,8 @@
/**
* @return the initializationExpression
*/
- public String getInitializationExpression() {
- return initializationExpression;
+ public TemplateStatement getInitializationExpression() {
+ return initializationStatement;
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
/**
* @author Nick Belaevski
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,10 +21,14 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*/
-public class ForEachStatement extends TemplateStatementsContainerBase {
+public class ForEachStatement extends TemplateStatementBase {
private String itemsExpression;
@@ -32,12 +36,9 @@
private String varType;
- public ForEachStatement(String itemsExpression,
- String var, String varType) {
- super("for-each");
- this.itemsExpression = itemsExpression;
- this.var = var;
- this.varType = varType;
+ @Inject
+ public ForEachStatement(FreeMarkerRenderer renderer) {
+ super(renderer,"for-each");
}
/**
@@ -61,4 +62,28 @@
return varType;
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param itemsExpression the itemsExpression to set
+ */
+ public void setItemsExpression(String itemsExpression) {
+ this.itemsExpression = itemsExpression;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param var the var to set
+ */
+ public void setVar(String var) {
+ this.var = var;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param varType the varType to set
+ */
+ public void setVarType(String varType) {
+ this.varType = varType;
+ }
+
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -26,7 +26,8 @@
import java.util.EnumMap;
import org.richfaces.cdk.Generator;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.builder.model.Argument;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
@@ -35,7 +36,6 @@
import com.google.common.collect.Maps;
import com.google.inject.Inject;
-import com.google.inject.internal.Nullable;
import com.google.inject.name.Named;
/**
@@ -47,30 +47,43 @@
*/
public class HelperMethodFactoryImpl implements HelperMethodFactory {
- private final FreeMarkerRenderer renderer;
- private final TypesFactory typesFactory;
- private final String rendererUtilsClass;
- private final EnumMap<HelperMethod, JavaMethod> helperMethods =
- Maps.newEnumMap(HelperMethod.class);
+ private TypesFactory typesFactory;
+ @Inject(optional = true)
+ @Named(Generator.RENDERER_UTILS_CLASS)
+ private String rendererUtilsClass = "org.richfaces.renderkit.RenderKitUtils";
+ private FreeMarkerRenderer renderer;
+ private final EnumMap<HelperMethod, JavaMethod> helperMethods = Maps.newEnumMap(HelperMethod.class);
+
+ private final Logger log;
+
@Inject
- public HelperMethodFactoryImpl(FreeMarkerRenderer renderer, TypesFactory typesFactory,
- @Named(Generator.RENDERER_UTILS_CLASS) @Nullable String rendererUtilsClass) {
+ public HelperMethodFactoryImpl(Logger log) {
+ this.log = log;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * Initialization code. It should be called after field injection, so render kit utils class name should have proper
+ * value here.
+ * </p>
+ *
+ * @param renderer
+ * @param typesFactory
+ */
+ @Inject
+ public void initHelperMethods(FreeMarkerRenderer renderer, TypesFactory typesFactory) {
this.renderer = renderer;
this.typesFactory = typesFactory;
- this.rendererUtilsClass = rendererUtilsClass;
- initHelperMethods();
- }
-
- protected void initHelperMethods() {
buildHelperMethod(HelperMethod.EMPTINESS_CHECK, false, "emptiness-check-method", "object");
buildHelperMethod(HelperMethod.EQUALS_CHECK, false, "equals-check-method", "o1", "o2");
- buildHelperMethod(HelperMethod.TO_BOOLEAN_CONVERSION, false,"conversion-to-boolean-method", "object");
+ buildHelperMethod(HelperMethod.TO_BOOLEAN_CONVERSION, false, "conversion-to-boolean-method", "object");
buildHelperMethod(HelperMethod.TO_STRING_CONVERSION, false, "conversion-to-string-method", "object");
}
- private JavaMethod buildHelperMethod(HelperMethod helperMethod, boolean utilsMethod, String templateName, String... argumentNames) {
+ private JavaMethod buildHelperMethod(HelperMethod helperMethod, boolean utilsMethod, String templateName,
+ String... argumentNames) {
JavaMethod helperJavaMethod;
if (utilsMethod && null != rendererUtilsClass) {
helperJavaMethod = new RendererUtilsMethod(helperMethod, rendererUtilsClass);
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,14 +21,19 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
* @since 4.0
*/
-public class IfElseStatement extends TemplateStatementsContainerBase {
+public class IfElseStatement extends TemplateStatementBase {
- public IfElseStatement() {
- super("if-else");
+ @Inject
+ public IfElseStatement(FreeMarkerRenderer renderer) {
+ super(renderer,"if-else");
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -67,7 +67,7 @@
}
};
- private List<TemplateStatement> statements = new ArrayList<TemplateStatement>();
+ private final List<TemplateStatement> statements = new ArrayList<TemplateStatement>();
private StatementsContainer parent;
@@ -79,12 +79,12 @@
public void addStatement(TemplateStatement statement) {
statement.setParent(this);
- statements.add(statement);
+ getStatements().add(statement);
}
public void addStatement(int index, TemplateStatement statement) {
statement.setParent(this);
- statements.add(index, statement);
+ getStatements().add(index, statement);
}
/**
@@ -109,7 +109,7 @@
}
public boolean isEmpty() {
- return statements.isEmpty();
+ return getStatements().isEmpty();
}
/*
@@ -120,7 +120,7 @@
@Override
public String getCode() {
StringBuilder sb = new StringBuilder();
- for (TemplateStatement statement : statements) {
+ for (TemplateStatement statement : getStatements()) {
sb.append(statement.getCode());
sb.append('\n');
}
@@ -154,7 +154,7 @@
}
private <T> Iterable<T> concatStatements(Function<TemplateStatement, Iterable<T>> transform) {
- Iterable<T> imports = Iterables.concat(Iterables.transform(statements, transform));
+ Iterable<T> imports = Iterables.concat(Iterables.transform(getStatements(), transform));
return imports;
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,23 +21,38 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import java.util.Collections;
import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
+import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
+import org.richfaces.cdk.templatecompiler.builder.model.StatementImpl;
+import org.richfaces.cdk.templatecompiler.el.types.ReferencedType;
+import org.richfaces.cdk.util.Strings;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
/**
* @author Nick Belaevski
*
*/
-public class TemplateStatementBase implements TemplateStatement {
+public class TemplateStatementBase extends StatementsContainer {
protected StatementsContainer parent;
private final String templateName;
private final FreeMarkerRenderer renderer;
+ private final Set<JavaImport> imports = Sets.newTreeSet(JavaImport.COMPARATOR);
private final EnumSet<HelperMethod> requiredMethods = EnumSet.noneOf(HelperMethod.class);
+ private final List<JavaField> fields = Lists.newArrayList();
+
+ private boolean parsed = false;
+ private String code;
protected TemplateStatementBase(FreeMarkerRenderer renderer, String templateName) {
super();
@@ -45,29 +60,36 @@
this.templateName = templateName;
}
- @Override
- public void setParent(StatementsContainer parent) {
- this.parent = parent;
- }
@Override
public String getCode() {
- return renderer.renderSnippet(templateName, this);
+ parse();
+ return code;
}
+ private void parse() {
+ if(!parsed){
+ code = renderer.renderTemplate(templateName, this);
+ parsed = true;
+ }
+ }
+
@Override
public Iterable<JavaImport> getRequiredImports() {
- return Collections.emptySet();
+ parse();
+ return Iterables.concat(super.getRequiredImports(),imports);
}
@Override
public Iterable<JavaField> getRequiredFields() {
- return Collections.emptySet();
+ parse();
+ return Iterables.concat(super.getRequiredFields(),fields);
}
@Override
public Iterable<HelperMethod> getRequiredMethods() {
- return requiredMethods;
+ parse();
+ return Iterables.concat(super.getRequiredMethods(),requiredMethods);
}
protected void addRequiredMethods(HelperMethod... methods) {
@@ -75,4 +97,24 @@
requiredMethods.add(helperMethod);
}
}
+
+ public void addConstant(String type, String name, String code) {
+ JavaField field = new JavaField(new ReferencedType(type),name);
+ field.addModifier(JavaModifier.PRIVATE);
+ field.addModifier(JavaModifier.STATIC);
+ field.addModifier(JavaModifier.FINAL);
+ if(!Strings.isEmpty(code)){
+ field.setValue(new StatementImpl(code));
+ }
+ fields.add(field);
+ }
+
+ public void addImport(String name) {
+ imports.add(new RuntimeImport(name));
+ }
+
+ public void addRequiredMethod(String helperMethodName) {
+ HelperMethod helperMethod = HelperMethod.valueOf(helperMethodName);
+ requiredMethods.add(helperMethod);
+ }
}
\ No newline at end of file
Deleted: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -1,46 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.cdk.templatecompiler.statements;
-
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
-
-
-/**
- * @author Nick Belaevski
- */
-public class TemplateStatementsContainerBase extends StatementsContainer {
-
- private final String templateName;
- private final FreeMarkerRenderer renderer;
-
- protected TemplateStatementsContainerBase(FreeMarkerRenderer renderer,String templateName) {
- super();
- this.renderer = renderer;
- this.templateName = templateName;
- }
-
- @Override
- public String getCode() {
- return renderer.renderSnippet(templateName, this);
- }
-
-}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,17 +21,30 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*/
public class WriteAttributesSetStatement extends TemplateStatementBase {
+ /**
+ *
+ */
+ private static final String PASS_THROUGH_ATTRIBUTES_FIELD_NAME = "PASS_THROUGH_ATTRIBUTES";
+
+ private static AtomicInteger fieldCounter = new AtomicInteger(0);
+
private String passThroughFieldName;
- public WriteAttributesSetStatement(String passThroughFieldName) {
- super("write-attributes-set");
- this.passThroughFieldName = passThroughFieldName;
+ @Inject
+ public WriteAttributesSetStatement(FreeMarkerRenderer renderer) {
+ super(renderer, "write-attributes-set");
+ passThroughFieldName = PASS_THROUGH_ATTRIBUTES_FIELD_NAME + fieldCounter.getAndIncrement();
}
/**
@@ -40,5 +53,5 @@
public String getPassThroughFieldName() {
return passThroughFieldName;
}
-
+
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -21,20 +21,46 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.Collections;
+import java.util.List;
+
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*/
public class WriteTextStatement extends TemplateStatementBase {
- private String textExpression;
+ private TemplateStatement textStatement;
+ private final ELParser parser;
- public WriteTextStatement(String textExpression) {
- super("write-text");
- this.textExpression = textExpression;
+ @Inject
+ public WriteTextStatement(FreeMarkerRenderer renderer,ELParser parser) {
+ super(renderer,"write-text");
+ this.parser = parser;
}
- public String getTextExpression() {
- return textExpression;
+ public TemplateStatement getTextStatement() {
+ return textStatement;
}
+ @Override
+ public List<TemplateStatement> getStatements() {
+ return Collections.singletonList(textStatement);
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param textExpression the textExpression to set
+ * @throws ParsingException
+ */
+ public void setExpression(String textExpression) throws ParsingException {
+ textStatement = parser.parse(textExpression,this,TypesFactory.OBJECT_TYPE);
+ textStatement.setParent(this);
+ }
+
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -14,7 +15,6 @@
import org.apache.maven.model.FileSet;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.DirectoryScanner;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -25,7 +25,7 @@
private static final String[] JAVA_INCLUDES = new String[] { "**/*.java" };
private static final String MAIN_CONFIG = "src/main/config";
private static final String MAIN_TEMPLATES = "src/main/templates";
- private static final String PROJECT_BASE = "E:\\_richfaces\\svn\\richfaces_root\\ui\\components\\core\\";
+ private static final String PROJECT_BASE = "";
private static final String[] STRINGS_ARRAY = new String[0];
private static final String XML_INCLUDES = "**/*.xml";
@@ -45,15 +45,11 @@
* @param type
*/
private static void setOutput(Generator generator, File directory, Outputs type) {
- if (!directory.exists()) {
- directory.mkdirs();
- }
generator.addOutputFolder(type, directory);
}
@Test
- @Ignore
public void createInstance() throws Exception {
List<String> compileSourceRoots = Arrays.asList("");
@@ -89,7 +85,6 @@
// Build JSF library.
// LibraryBuilder builder = LibraryBuilder.createInstance(context);
generator.init();
- generator.execute();
} catch (CdkException e) {
throw new MojoExecutionException("CDK build error", e);
}
@@ -110,102 +105,16 @@
return new CdkClassLoader(this.getClass().getClassLoader());
}
- /**
- * Skan Array of filesets for selected resources.
- *
- * @param filesets
- * @return
- * @throws MojoExecutionException
- */
- @SuppressWarnings("unchecked")
- protected Collection<File> doScan(FileSet[] filesets) throws MojoExecutionException {
- List<File> files = new ArrayList<File>();
-
- if (null != filesets) {
- for (FileSet fileSet : filesets) {
- String[] includes = (String[]) fileSet.getIncludes().toArray(STRINGS_ARRAY);
- String[] excludes = (String[]) fileSet.getExcludes().toArray(STRINGS_ARRAY);
- File fileSetDirectory = resolveRelativePath(new File(fileSet.getDirectory()));
- String[] scan = doScan(includes, excludes, fileSetDirectory);
-
- for (String filename : scan) {
- files.add(resolveRelativePath(new File(fileSetDirectory, filename)));
- }
- }
- }
-
- return files;
- }
-
- protected String[] doScan(String[] includes, String[] excludes, File rootFolder) throws MojoExecutionException {
- try {
- DirectoryScanner directoryScanner = new DirectoryScanner();
-
- directoryScanner.setFollowSymlinks(true);
- directoryScanner.setBasedir(rootFolder);
- directoryScanner.setExcludes(excludes);
- directoryScanner.setIncludes(includes);
- directoryScanner.addDefaultExcludes();
- directoryScanner.scan();
-
- return directoryScanner.getIncludedFiles();
- } catch (IllegalStateException e) {
- throw new MojoExecutionException("Error scanning source root: \'" + rootFolder + "\'", e);
- }
- }
-
private Iterable<File> findFacesConfigFiles() throws MojoExecutionException {
- FileSet[] facesConfigs = null;
- File defaultDirectory = resolveRelativePath(new File(MAIN_CONFIG));
- if (defaultDirectory.exists() && defaultDirectory.isDirectory()) {
- FileSet fileSet = new FileSet();
-
- fileSet.setDirectory(MAIN_CONFIG);
- fileSet.addInclude(XML_INCLUDES);
- facesConfigs = new FileSet[] { fileSet };
- }
-
- return doScan(facesConfigs);
+ return Collections.emptySet();
}
private Iterable<File> findJavaFiles() throws MojoExecutionException {
- Set<File> javaSources = new HashSet<File>();
- String[] includes = JAVA_INCLUDES;
- String[] compileSourceRoots = new String[] { PROJECT_BASE + "\\src\\main\\java" };
- for (String compileRoot : compileSourceRoots) {
- File rootFolder = new File(compileRoot);
- String[] sources = doScan(includes, null, rootFolder);
-
- for (String src : sources) {
- javaSources.add(new File(rootFolder, src));
- }
- }
-
- return javaSources;
+ return Collections.emptySet();
}
private Iterable<File> findTemplateFiles() throws MojoExecutionException {
- FileSet[] templates = null;
- File defaultDirectory = resolveRelativePath(new File(MAIN_TEMPLATES));
-
- if (defaultDirectory.exists() && defaultDirectory.isDirectory()) {
- FileSet fileSet = new FileSet();
-
- fileSet.setDirectory(MAIN_TEMPLATES);
- fileSet.addInclude(XML_INCLUDES);
- templates = new FileSet[] { fileSet };
- }
-
- return doScan(templates);
+ return Collections.emptySet();
}
-
- private File resolveRelativePath(File file) {
- File result = file;
- if (!result.isAbsolute()) {
- result = new File(PROJECT_BASE, result.getPath());
- }
-
- return result;
- }
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -1,5 +1,5 @@
/*
- * JBoss, Home of Professional Open Source
+Fr * JBoss, Home of Professional Open Source
* Copyright , Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
@@ -39,6 +39,7 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.generate.freemarker.LibraryModelWrapper;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
@@ -48,7 +49,6 @@
import com.google.inject.Inject;
-import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
/**
@@ -59,7 +59,7 @@
@Inject
@As(CdkConfiguration.class)
- protected Configuration configuration;
+ protected FreeMarkerRenderer configuration;
@Inject
protected ComponentLibrary library;
Copied: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java (from rev 17685, root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -0,0 +1,400 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.model;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.FacesId;
+import org.richfaces.cdk.xmlconfig.JaxbTestBase;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TemplateParserTest extends JaxbTestBase {
+
+ public static final String TEMPLATE_PROLOG =
+ "<cdk:root xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:cdk=\"http://richfaces.org/cdk/core\" xmlns:c=\"http://richfaces.org/cdk/jstl/core\" xmlns:cc=\"http://richfaces.org/cdk/jsf/composite\"><cc:interface>";
+ private static final Object DEFAULT_ATTRIBUTE_TYPE = new ClassName(Object.class);
+ private static final String TEMPLATE_EPILOG = "</cc:implementation></cdk:root>";
+ private static final String TEMPLATE_MIDDLE = "</cc:interface><cc:implementation>";
+
+ @Test
+ public void testAttributes() throws Exception {
+ Template template =
+ unmarshal(
+ Template.class,
+ TEMPLATE_PROLOG
+ + "<cdk:renders-children>true</cdk:renders-children>"
+ + "<cc:attribute name=\"onclick\" />"
+ + "<cc:attribute name=\"mode\" default=\"ajax\" />"
+ + "<cc:attribute name=\"action\" method-signature=\"void action()\" />"
+ + "<cc:attribute name=\"changeListener\" method-signature=\"void changeListener(ValueChangeEvent)\" targets=\"changes changes1\" />"
+ + "<cc:attribute name=\"disabled\" type=\"boolean\" />"
+ + "<cc:attribute name=\"delay\" type=\"java.lang.Integer\" />"
+ + "<cc:attribute name=\"id\" required=\"true\" />"
+ + "<cc:attribute name=\"experts\" shortDescription=\"For use by experts\" displayName=\"Expert attribute\" expert=\"true\" />"
+ + "<cc:attribute name=\"preferred\" shortDescription=\"It's a preferred attribute\" displayName=\"Preferred attribute\" preferred=\"true\" />"
+ + "<cc:attribute name=\"onchange\">" + "<cc:clientBehavior event=\"change\" />"
+ + "<cc:clientBehavior event=\"valueChange\" default=\"true\" />" + "</cc:attribute>"
+ + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+
+ CompositeInterface interfaceSection = template.getInterface();
+ assertNotNull(interfaceSection);
+
+ List<Attribute> attributes = interfaceSection.getAttributes();
+ assertNotNull(attributes);
+ assertEquals(10, attributes.size());
+
+ Attribute attribute;
+
+ attribute = attributes.get(0);
+ assertNotNull(attribute);
+ assertEquals("onclick", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(1);
+ assertNotNull(attribute);
+ assertEquals("mode", attribute.getName());
+ assertEquals("ajax", attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(2);
+ assertNotNull(attribute);
+ assertEquals("action", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertEquals("void action()", attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(3);
+ assertNotNull(attribute);
+ assertEquals("changeListener", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertEquals("void changeListener(ValueChangeEvent)", attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertEquals("changes changes1", attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(4);
+ assertNotNull(attribute);
+ assertEquals("disabled", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(ClassName.parseName("boolean"), attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(5);
+ assertNotNull(attribute);
+ assertEquals("delay", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(ClassName.parseName("java.lang.Integer"), attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(6);
+ assertNotNull(attribute);
+ assertEquals("id", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertTrue(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(7);
+ assertNotNull(attribute);
+ assertFalse(attribute.isRequired());
+ assertEquals("experts", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertEquals("For use by experts", attribute.getShortDescription());
+ assertEquals("Expert attribute", attribute.getDisplayName());
+ assertTrue(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(8);
+ assertNotNull(attribute);
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertEquals("preferred", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertEquals("It's a preferred attribute", attribute.getShortDescription());
+ assertEquals("Preferred attribute", attribute.getDisplayName());
+ assertTrue(attribute.isPreferred());
+
+ attribute = attributes.get(9);
+ assertNotNull(attribute);
+ assertEquals("onchange", attribute.getName());
+
+ List<ClientBehavior> clientBehaviors = attribute.getClientBehaviors();
+ assertNotNull(clientBehaviors);
+ assertEquals(2, clientBehaviors.size());
+
+ ClientBehavior clientBehavior;
+
+ clientBehavior = clientBehaviors.get(0);
+ assertNotNull(clientBehavior);
+ assertEquals("change", clientBehavior.getEvent());
+ assertFalse(clientBehavior.isDefaultEvent());
+
+ clientBehavior = clientBehaviors.get(1);
+ assertNotNull(clientBehavior);
+ assertEquals("valueChange", clientBehavior.getEvent());
+ assertTrue(clientBehavior.isDefaultEvent());
+
+ assertEquals(Boolean.TRUE, interfaceSection.getRendersChildren());
+ }
+
+ @Test
+ public void testImpl() throws Exception {
+ Template template =
+ unmarshal(
+ Template.class,
+ TEMPLATE_PROLOG
+ + TEMPLATE_MIDDLE
+ + "<cdk:call expression=\"#{cc.clientId}\"/><table width=\"200\"><tbody><cdk:call expression=\"#{cc.fooMethod(clientId)}\"/></tbody></table>Header<div class='bar'>foo</div>"
+ + TEMPLATE_EPILOG);
+
+ CompositeImplementation implementation = template.getImplementation();
+ assertNotNull(implementation);
+ List<Object> children = implementation.getChildren();
+ assertNotNull(children);
+ assertEquals(4, children.size());
+ assertEquals(CdkCallElement.class, children.get(0).getClass());
+ assertEquals(AnyElement.class, children.get(1).getClass());
+ assertEquals(String.class, children.get(2).getClass());
+ }
+
+ @Test
+ public void testInterface() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG
+ + "<cdk:class>org.richfaces.renderkit.html.TreeRenderer</cdk:class>"
+ + "<cdk:superclass>org.richfaces.renderkit.TreeRendererBase</cdk:superclass>"
+ + "<cdk:component-family>org.richfaces.TreeFamily</cdk:component-family>"
+ + "<cdk:renderer-type>org.richfaces.TreeRenderer</cdk:renderer-type>"
+ + "<cdk:renderkit-id>RF4_XHTML</cdk:renderkit-id>"
+ + "<cdk:renders-children>false</cdk:renders-children>" + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+
+ CompositeInterface interfaceSection = template.getInterface();
+ assertNotNull(interfaceSection);
+
+ assertEquals(ClassName.parseName("org.richfaces.renderkit.html.TreeRenderer"), interfaceSection.getJavaClass());
+ assertEquals(ClassName.parseName("org.richfaces.renderkit.TreeRendererBase"), interfaceSection.getBaseClass());
+ assertEquals(FacesId.parseId("org.richfaces.TreeFamily"), interfaceSection.getComponentFamily());
+ assertEquals(FacesId.parseId("org.richfaces.TreeRenderer"), interfaceSection.getRendererType());
+ assertEquals("RF4_XHTML", interfaceSection.getRenderKitId());
+ assertEquals(Boolean.FALSE, interfaceSection.getRendersChildren());
+
+ }
+
+ @Test
+ public void testJstlCoreElements() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE + "start"
+ + "<c:if test=\"#{someTest}\">if content</c:if>" + "<c:choose>"
+ + "<c:when test=\"#{anotherTest}\">when content</c:when>" + "<c:when test=\"#{coolTest}\">"
+ + "<c:if test=\"#{nestedIfTest}\">nested if content</c:if>" + "</c:when>"
+ + "<c:otherwise>otherwise content</c:otherwise>" + "</c:choose>"
+ + "<c:forEach items=\"#{someCollection}\" var=\"iterationVar\">" + "forEach content" + "</c:forEach>"
+ + "finish" + TEMPLATE_EPILOG);
+
+ CompositeImplementation implementation = template.getImplementation();
+ assertNotNull(implementation);
+
+ List<Object> children = implementation.getChildren();
+ assertNotNull(children);
+ assertEquals(5, children.size());
+ assertEquals("start", children.get(0));
+ assertEquals(CdkIfElement.class, children.get(1).getClass());
+ CdkIfElement ifElement = (CdkIfElement) children.get(1);
+ assertEquals("#{someTest}", ifElement.getTest());
+ List<Object> ifChildren = ifElement.getChildren();
+ assertNotNull(ifChildren);
+ assertEquals(1, ifChildren.size());
+ assertEquals("if content", ifChildren.get(0));
+
+ assertEquals(CdkChooseElement.class, children.get(2).getClass());
+ CdkChooseElement chooseElement = (CdkChooseElement) children.get(2);
+ List<Object> chooseChildren = chooseElement.getChildren();
+ assertNotNull(chooseChildren);
+ assertEquals(3, chooseChildren.size());
+
+ assertEquals(CdkWhenElement.class, chooseChildren.get(0).getClass());
+ CdkWhenElement firstWhen = (CdkWhenElement) chooseChildren.get(0);
+ assertEquals("#{anotherTest}", firstWhen.getTest());
+ List<Object> childrenOfFirstWhen = firstWhen.getChildren();
+ assertNotNull(childrenOfFirstWhen);
+ assertEquals(1, childrenOfFirstWhen.size());
+ assertEquals("when content", childrenOfFirstWhen.get(0));
+
+ assertEquals(CdkWhenElement.class, chooseChildren.get(1).getClass());
+ CdkWhenElement secondWhen = (CdkWhenElement) chooseChildren.get(1);
+ assertEquals("#{coolTest}", secondWhen.getTest());
+
+ List<Object> childrenOfSecondWhen = secondWhen.getChildren();
+ assertNotNull(childrenOfSecondWhen);
+ assertEquals(1, childrenOfSecondWhen.size());
+
+ assertEquals(CdkIfElement.class, childrenOfSecondWhen.get(0).getClass());
+ CdkIfElement nestedIf = (CdkIfElement) childrenOfSecondWhen.get(0);
+ assertEquals("#{nestedIfTest}", nestedIf.getTest());
+ List<Object> childrenOfNestedIf = nestedIf.getChildren();
+ assertNotNull(childrenOfNestedIf);
+ assertEquals(1, childrenOfNestedIf.size());
+ assertEquals("nested if content", childrenOfNestedIf.get(0));
+
+ assertEquals(CdkOtherwiseElement.class, chooseChildren.get(2).getClass());
+ CdkOtherwiseElement otherwiseElement = (CdkOtherwiseElement) chooseChildren.get(2);
+ List<Object> childrenOfOtherwiseElement = otherwiseElement.getChildren();
+ assertNotNull(childrenOfOtherwiseElement);
+ assertEquals(1, childrenOfOtherwiseElement.size());
+ assertEquals("otherwise content", childrenOfOtherwiseElement.get(0));
+
+ assertEquals(CdkForEachElement.class, children.get(3).getClass());
+ CdkForEachElement forEachElement = (CdkForEachElement) children.get(3);
+ assertEquals("#{someCollection}", forEachElement.getItems());
+ assertEquals("iterationVar", forEachElement.getVar());
+
+ List<Object> forEachChildren = forEachElement.getChildren();
+ assertNotNull(forEachChildren);
+ assertEquals(1, forEachChildren.size());
+ assertEquals("forEach content", forEachChildren.get(0));
+
+ assertEquals("finish", children.get(4));
+ }
+
+ @Test
+ public void testObject() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE
+ + "<cdk:object name=\"rowCount\" type=\"int\" value=\"#{getRowCount(context)}\" />"
+ + "<cdk:object name=\"bodyExpression\" type=\"java.lang.String\">"
+ + "\"test expression\" +\n\"second line\"" + "</cdk:object>" +
+
+ TEMPLATE_EPILOG);
+
+ CompositeImplementation implementation = template.getImplementation();
+ assertNotNull(implementation);
+
+ List<Object> children = implementation.getChildren();
+ assertNotNull(children);
+ assertEquals(2, children.size());
+
+ assertEquals(CdkObjectElement.class, children.get(0).getClass());
+ CdkObjectElement firstObject = (CdkObjectElement) children.get(0);
+ assertNotNull(firstObject);
+ assertEquals("rowCount", firstObject.getName());
+ assertEquals("int", firstObject.getType());
+ assertEquals("#{getRowCount(context)}", firstObject.getValue());
+
+ assertEquals(CdkObjectElement.class, children.get(1).getClass());
+ CdkObjectElement secondObject = (CdkObjectElement) children.get(1);
+ assertNotNull(secondObject);
+ assertEquals("bodyExpression", secondObject.getName());
+ assertEquals("java.lang.String", secondObject.getType());
+ assertEquals("\"test expression\" +\n\"second line\"", secondObject.getBodyValue());
+ }
+
+ @Test
+ public void testResourceDependencies() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG + "<cdk:resource-dependency name=\"jquery.js\" />"
+ + "<cdk:resource-dependency name=\"richfaces.css\" library=\"org.richfaces\" />"
+ + "<cdk:resource-dependency name=\"richfaces.js\" library=\"org.richfaces\" target=\"body\" /> "
+
+ + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+
+ CompositeInterface interfaceSection = template.getInterface();
+ assertNotNull(interfaceSection);
+
+ assertNull(interfaceSection.getRendersChildren());
+
+ List<ResourceDependency> resourceDependencies = interfaceSection.getResourceDependencies();
+ assertNotNull(resourceDependencies);
+ assertEquals(3, resourceDependencies.size());
+
+ ResourceDependency resourceDependency;
+
+ resourceDependency = resourceDependencies.get(0);
+ assertNotNull(resourceDependency);
+ assertEquals("jquery.js", resourceDependency.getName());
+ assertNull(resourceDependency.getLibrary());
+ assertEquals("head", resourceDependency.getTarget());
+
+ resourceDependency = resourceDependencies.get(1);
+ assertNotNull(resourceDependency);
+ assertEquals("richfaces.css", resourceDependency.getName());
+ assertEquals("org.richfaces", resourceDependency.getLibrary());
+ assertEquals("head", resourceDependency.getTarget());
+
+ resourceDependency = resourceDependencies.get(2);
+ assertNotNull(resourceDependency);
+ assertEquals("richfaces.js", resourceDependency.getName());
+ assertEquals("org.richfaces", resourceDependency.getLibrary());
+ assertEquals("body", resourceDependency.getTarget());
+ }
+
+ @Test
+ public void testTemplate() throws Exception {
+ Template template = unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+ assertNotNull(template.getInterface());
+ assertNotNull(template.getImplementation());
+ }
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Deleted: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java 2010-06-30 19:46:12 UTC (rev 17691)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java 2010-06-30 23:15:43 UTC (rev 17692)
@@ -1,400 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.templatecompiler.model;
-
-import static org.junit.Assert.*;
-
-import java.util.List;
-
-import org.junit.Test;
-import org.richfaces.cdk.model.ClassName;
-import org.richfaces.cdk.model.FacesId;
-import org.richfaces.cdk.xmlconfig.JaxbTestBase;
-
-/**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public class TemplateTest extends JaxbTestBase {
-
- public static final String TEMPLATE_PROLOG =
- "<cdk:root xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:cdk=\"http://richfaces.org/cdk/core\" xmlns:c=\"http://richfaces.org/cdk/jstl/core\" xmlns:cc=\"http://richfaces.org/cdk/jsf/composite\"><cc:interface>";
- private static final Object DEFAULT_ATTRIBUTE_TYPE = new ClassName(Object.class);
- private static final String TEMPLATE_EPILOG = "</cc:implementation></cdk:root>";
- private static final String TEMPLATE_MIDDLE = "</cc:interface><cc:implementation>";
-
- @Test
- public void testAttributes() throws Exception {
- Template template =
- unmarshal(
- Template.class,
- TEMPLATE_PROLOG
- + "<cdk:renders-children>true</cdk:renders-children>"
- + "<cc:attribute name=\"onclick\" />"
- + "<cc:attribute name=\"mode\" default=\"ajax\" />"
- + "<cc:attribute name=\"action\" method-signature=\"void action()\" />"
- + "<cc:attribute name=\"changeListener\" method-signature=\"void changeListener(ValueChangeEvent)\" targets=\"changes changes1\" />"
- + "<cc:attribute name=\"disabled\" type=\"boolean\" />"
- + "<cc:attribute name=\"delay\" type=\"java.lang.Integer\" />"
- + "<cc:attribute name=\"id\" required=\"true\" />"
- + "<cc:attribute name=\"experts\" shortDescription=\"For use by experts\" displayName=\"Expert attribute\" expert=\"true\" />"
- + "<cc:attribute name=\"preferred\" shortDescription=\"It's a preferred attribute\" displayName=\"Preferred attribute\" preferred=\"true\" />"
- + "<cc:attribute name=\"onchange\">" + "<cc:clientBehavior event=\"change\" />"
- + "<cc:clientBehavior event=\"valueChange\" default=\"true\" />" + "</cc:attribute>"
- + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
-
- CompositeInterface interfaceSection = template.getInterface();
- assertNotNull(interfaceSection);
-
- List<Attribute> attributes = interfaceSection.getAttributes();
- assertNotNull(attributes);
- assertEquals(10, attributes.size());
-
- Attribute attribute;
-
- attribute = attributes.get(0);
- assertNotNull(attribute);
- assertEquals("onclick", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(1);
- assertNotNull(attribute);
- assertEquals("mode", attribute.getName());
- assertEquals("ajax", attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(2);
- assertNotNull(attribute);
- assertEquals("action", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertEquals("void action()", attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(3);
- assertNotNull(attribute);
- assertEquals("changeListener", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertEquals("void changeListener(ValueChangeEvent)", attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertEquals("changes changes1", attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(4);
- assertNotNull(attribute);
- assertEquals("disabled", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(ClassName.parseName("boolean"), attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(5);
- assertNotNull(attribute);
- assertEquals("delay", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(ClassName.parseName("java.lang.Integer"), attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(6);
- assertNotNull(attribute);
- assertEquals("id", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertTrue(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(7);
- assertNotNull(attribute);
- assertFalse(attribute.isRequired());
- assertEquals("experts", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertEquals("For use by experts", attribute.getShortDescription());
- assertEquals("Expert attribute", attribute.getDisplayName());
- assertTrue(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(8);
- assertNotNull(attribute);
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertEquals("preferred", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertEquals("It's a preferred attribute", attribute.getShortDescription());
- assertEquals("Preferred attribute", attribute.getDisplayName());
- assertTrue(attribute.isPreferred());
-
- attribute = attributes.get(9);
- assertNotNull(attribute);
- assertEquals("onchange", attribute.getName());
-
- List<ClientBehavior> clientBehaviors = attribute.getClientBehaviors();
- assertNotNull(clientBehaviors);
- assertEquals(2, clientBehaviors.size());
-
- ClientBehavior clientBehavior;
-
- clientBehavior = clientBehaviors.get(0);
- assertNotNull(clientBehavior);
- assertEquals("change", clientBehavior.getEvent());
- assertFalse(clientBehavior.isDefaultEvent());
-
- clientBehavior = clientBehaviors.get(1);
- assertNotNull(clientBehavior);
- assertEquals("valueChange", clientBehavior.getEvent());
- assertTrue(clientBehavior.isDefaultEvent());
-
- assertEquals(Boolean.TRUE, interfaceSection.getRendersChildren());
- }
-
- @Test
- public void testImpl() throws Exception {
- Template template =
- unmarshal(
- Template.class,
- TEMPLATE_PROLOG
- + TEMPLATE_MIDDLE
- + "<cdk:call expression=\"#{cc.clientId}\"/><table width=\"200\"><tbody><cdk:call expression=\"#{cc.fooMethod(clientId)}\"/></tbody></table>Header<div class='bar'>foo</div>"
- + TEMPLATE_EPILOG);
-
- CompositeImplementation implementation = template.getImplementation();
- assertNotNull(implementation);
- List<Object> children = implementation.getChildren();
- assertNotNull(children);
- assertEquals(4, children.size());
- assertEquals(CdkCallElement.class, children.get(0).getClass());
- assertEquals(AnyElement.class, children.get(1).getClass());
- assertEquals(String.class, children.get(2).getClass());
- }
-
- @Test
- public void testInterface() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG
- + "<cdk:class>org.richfaces.renderkit.html.TreeRenderer</cdk:class>"
- + "<cdk:superclass>org.richfaces.renderkit.TreeRendererBase</cdk:superclass>"
- + "<cdk:component-family>org.richfaces.TreeFamily</cdk:component-family>"
- + "<cdk:renderer-type>org.richfaces.TreeRenderer</cdk:renderer-type>"
- + "<cdk:renderkit-id>RF4_XHTML</cdk:renderkit-id>"
- + "<cdk:renders-children>false</cdk:renders-children>" + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
-
- CompositeInterface interfaceSection = template.getInterface();
- assertNotNull(interfaceSection);
-
- assertEquals(ClassName.parseName("org.richfaces.renderkit.html.TreeRenderer"), interfaceSection.getJavaClass());
- assertEquals(ClassName.parseName("org.richfaces.renderkit.TreeRendererBase"), interfaceSection.getBaseClass());
- assertEquals(FacesId.parseId("org.richfaces.TreeFamily"), interfaceSection.getComponentFamily());
- assertEquals(FacesId.parseId("org.richfaces.TreeRenderer"), interfaceSection.getRendererType());
- assertEquals("RF4_XHTML", interfaceSection.getRenderKitId());
- assertEquals(Boolean.FALSE, interfaceSection.getRendersChildren());
-
- }
-
- @Test
- public void testJstlCoreElements() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE + "start"
- + "<c:if test=\"#{someTest}\">if content</c:if>" + "<c:choose>"
- + "<c:when test=\"#{anotherTest}\">when content</c:when>" + "<c:when test=\"#{coolTest}\">"
- + "<c:if test=\"#{nestedIfTest}\">nested if content</c:if>" + "</c:when>"
- + "<c:otherwise>otherwise content</c:otherwise>" + "</c:choose>"
- + "<c:forEach items=\"#{someCollection}\" var=\"iterationVar\">" + "forEach content" + "</c:forEach>"
- + "finish" + TEMPLATE_EPILOG);
-
- CompositeImplementation implementation = template.getImplementation();
- assertNotNull(implementation);
-
- List<Object> children = implementation.getChildren();
- assertNotNull(children);
- assertEquals(5, children.size());
- assertEquals("start", children.get(0));
- assertEquals(CdkIfElement.class, children.get(1).getClass());
- CdkIfElement ifElement = (CdkIfElement) children.get(1);
- assertEquals("#{someTest}", ifElement.getTest());
- List<Object> ifChildren = ifElement.getChildren();
- assertNotNull(ifChildren);
- assertEquals(1, ifChildren.size());
- assertEquals("if content", ifChildren.get(0));
-
- assertEquals(CdkChooseElement.class, children.get(2).getClass());
- CdkChooseElement chooseElement = (CdkChooseElement) children.get(2);
- List<Object> chooseChildren = chooseElement.getChildren();
- assertNotNull(chooseChildren);
- assertEquals(3, chooseChildren.size());
-
- assertEquals(CdkWhenElement.class, chooseChildren.get(0).getClass());
- CdkWhenElement firstWhen = (CdkWhenElement) chooseChildren.get(0);
- assertEquals("#{anotherTest}", firstWhen.getTest());
- List<Object> childrenOfFirstWhen = firstWhen.getChildren();
- assertNotNull(childrenOfFirstWhen);
- assertEquals(1, childrenOfFirstWhen.size());
- assertEquals("when content", childrenOfFirstWhen.get(0));
-
- assertEquals(CdkWhenElement.class, chooseChildren.get(1).getClass());
- CdkWhenElement secondWhen = (CdkWhenElement) chooseChildren.get(1);
- assertEquals("#{coolTest}", secondWhen.getTest());
-
- List<Object> childrenOfSecondWhen = secondWhen.getChildren();
- assertNotNull(childrenOfSecondWhen);
- assertEquals(1, childrenOfSecondWhen.size());
-
- assertEquals(CdkIfElement.class, childrenOfSecondWhen.get(0).getClass());
- CdkIfElement nestedIf = (CdkIfElement) childrenOfSecondWhen.get(0);
- assertEquals("#{nestedIfTest}", nestedIf.getTest());
- List<Object> childrenOfNestedIf = nestedIf.getChildren();
- assertNotNull(childrenOfNestedIf);
- assertEquals(1, childrenOfNestedIf.size());
- assertEquals("nested if content", childrenOfNestedIf.get(0));
-
- assertEquals(CdkOtherwiseElement.class, chooseChildren.get(2).getClass());
- CdkOtherwiseElement otherwiseElement = (CdkOtherwiseElement) chooseChildren.get(2);
- List<Object> childrenOfOtherwiseElement = otherwiseElement.getChildren();
- assertNotNull(childrenOfOtherwiseElement);
- assertEquals(1, childrenOfOtherwiseElement.size());
- assertEquals("otherwise content", childrenOfOtherwiseElement.get(0));
-
- assertEquals(CdkForEachElement.class, children.get(3).getClass());
- CdkForEachElement forEachElement = (CdkForEachElement) children.get(3);
- assertEquals("#{someCollection}", forEachElement.getItems());
- assertEquals("iterationVar", forEachElement.getVar());
-
- List<Object> forEachChildren = forEachElement.getChildren();
- assertNotNull(forEachChildren);
- assertEquals(1, forEachChildren.size());
- assertEquals("forEach content", forEachChildren.get(0));
-
- assertEquals("finish", children.get(4));
- }
-
- @Test
- public void testObject() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE
- + "<cdk:object name=\"rowCount\" type=\"int\" value=\"#{getRowCount(context)}\" />"
- + "<cdk:object name=\"bodyExpression\" type=\"java.lang.String\">"
- + "\"test expression\" +\n\"second line\"" + "</cdk:object>" +
-
- TEMPLATE_EPILOG);
-
- CompositeImplementation implementation = template.getImplementation();
- assertNotNull(implementation);
-
- List<Object> children = implementation.getChildren();
- assertNotNull(children);
- assertEquals(2, children.size());
-
- assertEquals(CdkObjectElement.class, children.get(0).getClass());
- CdkObjectElement firstObject = (CdkObjectElement) children.get(0);
- assertNotNull(firstObject);
- assertEquals("rowCount", firstObject.getName());
- assertEquals("int", firstObject.getType());
- assertEquals("#{getRowCount(context)}", firstObject.getValue());
-
- assertEquals(CdkObjectElement.class, children.get(1).getClass());
- CdkObjectElement secondObject = (CdkObjectElement) children.get(1);
- assertNotNull(secondObject);
- assertEquals("bodyExpression", secondObject.getName());
- assertEquals("java.lang.String", secondObject.getType());
- assertEquals("\"test expression\" +\n\"second line\"", secondObject.getBodyValue());
- }
-
- @Test
- public void testResourceDependencies() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG + "<cdk:resource-dependency name=\"jquery.js\" />"
- + "<cdk:resource-dependency name=\"richfaces.css\" library=\"org.richfaces\" />"
- + "<cdk:resource-dependency name=\"richfaces.js\" library=\"org.richfaces\" target=\"body\" /> "
-
- + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
-
- CompositeInterface interfaceSection = template.getInterface();
- assertNotNull(interfaceSection);
-
- assertNull(interfaceSection.getRendersChildren());
-
- List<ResourceDependency> resourceDependencies = interfaceSection.getResourceDependencies();
- assertNotNull(resourceDependencies);
- assertEquals(3, resourceDependencies.size());
-
- ResourceDependency resourceDependency;
-
- resourceDependency = resourceDependencies.get(0);
- assertNotNull(resourceDependency);
- assertEquals("jquery.js", resourceDependency.getName());
- assertNull(resourceDependency.getLibrary());
- assertEquals("head", resourceDependency.getTarget());
-
- resourceDependency = resourceDependencies.get(1);
- assertNotNull(resourceDependency);
- assertEquals("richfaces.css", resourceDependency.getName());
- assertEquals("org.richfaces", resourceDependency.getLibrary());
- assertEquals("head", resourceDependency.getTarget());
-
- resourceDependency = resourceDependencies.get(2);
- assertNotNull(resourceDependency);
- assertEquals("richfaces.js", resourceDependency.getName());
- assertEquals("org.richfaces", resourceDependency.getLibrary());
- assertEquals("body", resourceDependency.getTarget());
- }
-
- @Test
- public void testTemplate() throws Exception {
- Template template = unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
- assertNotNull(template.getInterface());
- assertNotNull(template.getImplementation());
- }
-}
14 years, 6 months
JBoss Rich Faces SVN: r17691 - in root: core/trunk/impl/src/main/resources/META-INF/resources and 4 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-06-30 15:46:12 -0400 (Wed, 30 Jun 2010)
New Revision: 17691
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
root/core/trunk/impl/src/test/resources/javascript/4_0_0.html
root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractPush.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
Log:
https://jira.jboss.org/browse/RF-8744
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2010-06-30 19:32:51 UTC (rev 17690)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2010-06-30 19:46:12 UTC (rev 17691)
@@ -360,6 +360,8 @@
ajaxEventOptions.set(behaviorName, handlerScript);
}
}
+
+ ajaxEventOptions.set("incId", "1");
}
// public static AjaxEventOptions buildEventOptions(FacesContext facesContext,
@@ -779,6 +781,7 @@
* @param component for wich calculate function name
* @return name of JavaScript function or <code>null</code>
*/
+ //TODO nick - refactor - remove this method?
public static String getAjaxOncomplete(UIComponent component) {
if (component instanceof AjaxComponent) {
return ((AjaxComponent) component).getOncomplete();
@@ -793,6 +796,7 @@
* @param component for wich calculate function name
* @return name of JavaScript function or <code>null</code>
*/
+ //TODO nick - refactor - remove this method?
public static String getAjaxOnBeforeDomUpdate(UIComponent component) {
if (component instanceof AjaxComponent) {
return ((AjaxComponent) component).getOnbeforedomupdate();
@@ -801,6 +805,7 @@
return (String) component.getAttributes().get(ONBEFOREDOMUPDATE_ATTR_NAME);
}
+ //TODO nick - refactor - remove this method?
public static String getAjaxOnBegin(UIComponent component) {
if (component instanceof AjaxComponent) {
return ((AjaxComponent) component).getOnbegin();
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2010-06-30 19:32:51 UTC (rev 17690)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2010-06-30 19:46:12 UTC (rev 17691)
@@ -45,11 +45,6 @@
*/
public abstract class RendererBase extends Renderer {
- /**
- * logger for common cases.
- */
- protected static final String JAVASCRIPT_NAMESPACE = "Exadel";
-
private static final Logger LOG = RichfacesLogger.RENDERKIT.getLogger();
private static final RendererUtils UTILS = RendererUtils.getInstance();
@@ -79,11 +74,19 @@
// TODO - create set od common decoders ( UIInput, ActionSource etc. ) for process decoding.
if (component.isRendered()) {
- RenderKitUtils.decodeBehaviors(context, component);
+ String behaviorEventName = RenderKitUtils.decodeBehaviors(context, component);
+ if (behaviorEventName != null) {
+ queueComponentEventForBehaviorEvent(context, component, behaviorEventName);
+ }
+
doDecode(context, component);
}
}
+ protected void queueComponentEventForBehaviorEvent(FacesContext context, UIComponent component, String eventName) {
+
+ }
+
protected void preDecode(FacesContext context, UIComponent component) {
}
Modified: root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-06-30 19:32:51 UTC (rev 17690)
+++ root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-06-30 19:46:12 UTC (rev 17691)
@@ -560,7 +560,6 @@
richfaces.ajax = function(source, event, options) {
var sourceId = (typeof source == 'object' && source.id) ? source.id : source;
- var sourceElt = (typeof source == 'object') ? source : document.getElementById(sourceId);
options = options || {};
@@ -600,7 +599,7 @@
}
}
- if (!jQuery(sourceElt).is(":input:not(:submit, :button, :image, :reset)")) {
+ if (options.incId) {
parameters[sourceId] = sourceId;
}
Modified: root/core/trunk/impl/src/test/resources/javascript/4_0_0.html
===================================================================
--- root/core/trunk/impl/src/test/resources/javascript/4_0_0.html 2010-06-30 19:32:51 UTC (rev 17690)
+++ root/core/trunk/impl/src/test/resources/javascript/4_0_0.html 2010-06-30 19:46:12 UTC (rev 17691)
@@ -137,13 +137,27 @@
adapter(eventData);
});
- test("RichFaces.ajax test", function() {
- expect(7);
+ test("RichFaces.ajax behavior test", function() {
+ expect(1);
+
var ajaxSource = "source";
var ajaxEvent = "event";
var ajaxOptions = {parameters: {'param': 'value'}};
jsf.ajax = {
request : function(source, event, options) {
+ ok(!options['source']);
+ }
+ }
+ RichFaces.ajax(ajaxSource, ajaxEvent, ajaxOptions);
+ });
+
+ test("RichFaces.ajax component test", function() {
+ expect(7);
+ var ajaxSource = "source";
+ var ajaxEvent = "event";
+ var ajaxOptions = {parameters: {'param': 'value'}, incId: 1};
+ jsf.ajax = {
+ request : function(source, event, options) {
equals(source, ajaxSource);
equals(event, ajaxEvent);
equals(options['execute'], '@component');
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractPush.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractPush.java 2010-06-30 19:32:51 UTC (rev 17690)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/component/AbstractPush.java 2010-06-30 19:46:12 UTC (rev 17691)
@@ -29,8 +29,6 @@
import javax.el.MethodExpression;
import javax.faces.component.NamingContainer;
import javax.faces.context.FacesContext;
-import javax.faces.event.BehaviorEvent;
-import javax.faces.event.FacesEvent;
import javax.servlet.http.HttpSession;
import org.richfaces.cdk.annotations.Attribute;
@@ -58,8 +56,6 @@
public static final String ON_DATA_AVAILABLE = "ondataavailable";
- private transient boolean hasActiveBehavior = false;
-
@Override
public void encodeBegin(FacesContext context) throws IOException {
MethodExpression producer = getEventProducer();
@@ -95,22 +91,6 @@
return id.toString();
}
- @Override
- public void queueEvent(FacesEvent e) {
- if (e instanceof BehaviorEvent) {
- hasActiveBehavior = true;
- }
-
- super.queueEvent(e);
- }
-
- /**
- * @return the hasActiveBehavior
- */
- public boolean isHasActiveBehavior() {
- return hasActiveBehavior;
- }
-
// ---------------------------------------
@Attribute(signature = @Signature(parameters = EventListener.class))
public abstract MethodExpression getEventProducer();
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2010-06-30 19:32:51 UTC (rev 17690)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/AjaxCommandRendererBase.java 2010-06-30 19:46:12 UTC (rev 17691)
@@ -53,6 +53,15 @@
private static final Logger LOG = RichfacesLogger.RENDERKIT.getLogger();
@Override
+ protected void queueComponentEventForBehaviorEvent(FacesContext context, UIComponent component, String eventName) {
+ super.queueComponentEventForBehaviorEvent(context, component, eventName);
+
+ if ("action".equals(eventName) || "click".equals(eventName)) {
+ new ActionEvent(component).queue();
+ }
+ }
+
+ @Override
protected void doDecode(FacesContext facesContext, UIComponent uiComponent) {
if (isSubmitted(facesContext, uiComponent)) {
new ActionEvent(uiComponent).queue();
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-06-30 19:32:51 UTC (rev 17690)
+++ root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-06-30 19:46:12 UTC (rev 17691)
@@ -21,6 +21,17 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.event.ActionEvent;
+
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
@@ -29,28 +40,15 @@
import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractPush;
import org.richfaces.resource.PushResource;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.event.ActionEvent;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* @author shura
*/
-@ResourceDependencies(value = {
- @ResourceDependency(library = "javax.faces", name = "jsf.js"),
- @ResourceDependency(name = "jquery.js"),
- @ResourceDependency(name = "richfaces.js")
- })
+@ResourceDependencies({@ResourceDependency(library = "javax.faces", name = "jsf.js") ,
+ @ResourceDependency(name = "jquery.js") , @ResourceDependency(name = "richfaces.js")})
@JsfRenderer
public class AjaxPushRenderer extends RendererBase {
@@ -64,6 +62,15 @@
public static final int DEFAULT_PUSH_WAIT = Integer.MIN_VALUE;
+ @Override
+ protected void queueComponentEventForBehaviorEvent(FacesContext context, UIComponent component, String eventName) {
+ super.queueComponentEventForBehaviorEvent(context, component, eventName);
+
+ if (AbstractPush.DATA_AVAILABLE.equals(eventName) || AbstractPush.ON_DATA_AVAILABLE.equals(eventName)) {
+ new ActionEvent(component).queue();
+ }
+ }
+
/* (non-Javadoc)
* @see org.ajax4jsf.renderkit.RendererBase#doEncodeEnd(javax.faces.context.ResponseWriter,
* javax.faces.context.FacesContext, javax.faces.component.UIComponent)
@@ -148,7 +155,7 @@
AbstractPush push = (AbstractPush) component;
if (push.isEnabled()) {
Map<String, String> requestParameterMap = context.getExternalContext().getRequestParameterMap();
- if (requestParameterMap.get(push.getClientId(context)) != null || push.isHasActiveBehavior()) {
+ if (requestParameterMap.get(push.getClientId(context)) != null) {
new ActionEvent(push).queue();
}
}
14 years, 6 months
JBoss Rich Faces SVN: r17690 - in root/commons/trunk/api/src: test/java/org/richfaces/renderkit and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-06-30 15:32:51 -0400 (Wed, 30 Jun 2010)
New Revision: 17690
Modified:
root/commons/trunk/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
root/commons/trunk/api/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
Log:
https://jira.jboss.org/browse/RF-8744
Modified: root/commons/trunk/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
--- root/commons/trunk/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-06-30 19:18:06 UTC (rev 17689)
+++ root/commons/trunk/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-06-30 19:32:51 UTC (rev 17690)
@@ -353,16 +353,16 @@
}
}
- public static void decodeBehaviors(FacesContext context, UIComponent component) {
+ public static String decodeBehaviors(FacesContext context, UIComponent component) {
if (!(component instanceof ClientBehaviorHolder)) {
- return;
+ return null;
}
ClientBehaviorHolder holder = (ClientBehaviorHolder) component;
Map<String, List<ClientBehavior>> behaviors = holder.getClientBehaviors();
if (behaviors == null || behaviors.isEmpty()) {
- return;
+ return null;
}
ExternalContext externalContext = context.getExternalContext();
@@ -370,7 +370,7 @@
String behaviorEvent = parametersMap.get(BEHAVIOR_EVENT_NAME);
if (behaviorEvent == null) {
- return;
+ return null;
}
List<ClientBehavior> behaviorsForEvent = behaviors.get(behaviorEvent);
@@ -378,12 +378,16 @@
String clientId = component.getClientId(context);
if (behaviorSource != null && behaviorSource.equals(clientId)) {
- if (behaviorsForEvent != null) {
+ if (behaviorsForEvent != null && !behaviorsForEvent.isEmpty()) {
for (ClientBehavior behavior : behaviorsForEvent) {
behavior.decode(context, component);
}
+
+ return behaviorEvent;
}
}
+
+ return null;
}
}
Modified: root/commons/trunk/api/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
===================================================================
--- root/commons/trunk/api/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java 2010-06-30 19:18:06 UTC (rev 17689)
+++ root/commons/trunk/api/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java 2010-06-30 19:32:51 UTC (rev 17690)
@@ -25,6 +25,8 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.same;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
@@ -322,7 +324,7 @@
facesEnvironment.replay();
- RenderKitUtils.decodeBehaviors(facesContext, component);
+ assertEquals("action", RenderKitUtils.decodeBehaviors(facesContext, component));
}
@Test
@@ -337,7 +339,7 @@
facesEnvironment.replay();
- RenderKitUtils.decodeBehaviors(facesContext, component);
+ assertEquals("blur", RenderKitUtils.decodeBehaviors(facesContext, component));
}
@Test
@@ -348,7 +350,7 @@
facesEnvironment.replay();
- RenderKitUtils.decodeBehaviors(facesContext, component);
+ assertNull(RenderKitUtils.decodeBehaviors(facesContext, component));
}
@Test
@@ -359,7 +361,7 @@
facesEnvironment.replay();
- RenderKitUtils.decodeBehaviors(facesContext, component);
+ assertNull(RenderKitUtils.decodeBehaviors(facesContext, component));
}
@Test
@@ -370,6 +372,6 @@
facesEnvironment.replay();
- RenderKitUtils.decodeBehaviors(facesContext, component);
+ assertNull(RenderKitUtils.decodeBehaviors(facesContext, component));
}
}
\ No newline at end of file
14 years, 6 months
JBoss Rich Faces SVN: r17689 - root/ui-sandbox/panels/trunk/docs.
by richfaces-svn-commits@lists.jboss.org
Author: Alex.Kolonitsky
Date: 2010-06-30 15:18:06 -0400 (Wed, 30 Jun 2010)
New Revision: 17689
Added:
root/ui-sandbox/panels/trunk/docs/legend.png
Modified:
root/ui-sandbox/panels/trunk/docs/client_side_api-dev.png
root/ui-sandbox/panels/trunk/docs/client_side_api.png
root/ui-sandbox/panels/trunk/docs/taglib-dev.png
root/ui-sandbox/panels/trunk/docs/taglib.png
Log:
RF-8745 TogglePanel component
update diagrams
Modified: root/ui-sandbox/panels/trunk/docs/client_side_api-dev.png
===================================================================
(Binary files differ)
Modified: root/ui-sandbox/panels/trunk/docs/client_side_api.png
===================================================================
(Binary files differ)
Added: root/ui-sandbox/panels/trunk/docs/legend.png
===================================================================
(Binary files differ)
Property changes on: root/ui-sandbox/panels/trunk/docs/legend.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: root/ui-sandbox/panels/trunk/docs/taglib-dev.png
===================================================================
(Binary files differ)
Modified: root/ui-sandbox/panels/trunk/docs/taglib.png
===================================================================
(Binary files differ)
14 years, 6 months
JBoss Rich Faces SVN: r17687 - root/commons/branches.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-30 14:46:51 -0400 (Wed, 30 Jun 2010)
New Revision: 17687
Added:
root/commons/branches/RF8755/
Log:
development branch
Copied: root/commons/branches/RF8755 (from rev 17685, root/commons/trunk)
14 years, 6 months
JBoss Rich Faces SVN: r17686 - in root: examples/iteration-demo/trunk/src/main/webapp and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-06-30 14:07:32 -0400 (Wed, 30 Jun 2010)
New Revision: 17686
Added:
root/ui/iteration/trunk/tables/api/src/main/java/org/richfaces/model/SelectionMode.java
Modified:
root/examples/iteration-demo/trunk/src/main/java/org/richfaces/demo/DataBean.java
root/examples/iteration-demo/trunk/src/main/webapp/extendedtable.xhtml
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java
root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js
Log:
RF-8101
Modified: root/examples/iteration-demo/trunk/src/main/java/org/richfaces/demo/DataBean.java
===================================================================
--- root/examples/iteration-demo/trunk/src/main/java/org/richfaces/demo/DataBean.java 2010-06-30 15:52:20 UTC (rev 17685)
+++ root/examples/iteration-demo/trunk/src/main/java/org/richfaces/demo/DataBean.java 2010-06-30 18:07:32 UTC (rev 17686)
@@ -1,5 +1,6 @@
package org.richfaces.demo;
+import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -12,6 +13,7 @@
import org.richfaces.demo.model.Employee;
import org.richfaces.demo.utils.EmployeeUtils;
import org.richfaces.event.SortingEvent;
+import org.richfaces.model.SelectionMode;
@ManagedBean(name="dataBean")
@SessionScoped
@@ -36,6 +38,10 @@
private List<Employee> employeeList;
private boolean state = true;
+ private SelectionMode selectionMode = SelectionMode.multiple;
+
+ private Collection<Object> selectedRowKeys;
+
public String getTarget() {
return target;
}
@@ -126,4 +132,24 @@
public boolean isRendered() {
return rendered;
}
+
+ public void setSelectionMode(SelectionMode selectionMode) {
+ this.selectionMode = selectionMode;
+ }
+
+ public SelectionMode getSelectionMode() {
+ return selectionMode;
+ }
+
+ public SelectionMode[] getSelectionModes() {
+ return SelectionMode.values();
+ }
+
+ public void setSelectedRowKeys(Collection<Object> selectedRowKeys) {
+ this.selectedRowKeys = selectedRowKeys;
+ }
+
+ public Collection<Object> getSelectedRowKeys() {
+ return selectedRowKeys;
+ }
}
Modified: root/examples/iteration-demo/trunk/src/main/webapp/extendedtable.xhtml
===================================================================
--- root/examples/iteration-demo/trunk/src/main/webapp/extendedtable.xhtml 2010-06-30 15:52:20 UTC (rev 17685)
+++ root/examples/iteration-demo/trunk/src/main/webapp/extendedtable.xhtml 2010-06-30 18:07:32 UTC (rev 17686)
@@ -6,7 +6,7 @@
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:it="http://richfaces.org/iteration">
+ xmlns:rich="http://richfaces.org/rich">
<!--
JBoss, Home of Professional Open Source
Copyright ${year}, Red Hat, Inc. and individual contributors
@@ -34,7 +34,6 @@
<h:head>
<title>Richfaces ExtendedDataTable</title>
<style type="text/css">
- @charset "utf-8";
.extendedDataTable{
width:500px;
height: 500px;
@@ -48,13 +47,12 @@
<h:selectBooleanCheckbox value="#{dataBean.state}">
<f:ajax render="extendedDataTable" />
</h:selectBooleanCheckbox>
- <br />
- <h:outputText value="Render footer" />
+ <h:outputText value="Render footer" style="padding-left: 30px;"/>
<h:selectBooleanCheckbox value="#{dataBean.rendered}">
<f:ajax render="extendedDataTable" />
</h:selectBooleanCheckbox>
<br />
- JS API
+ <h:outputText value="JS API" />
<script type="text/javascript">
<!--
function invokeJSAPI() {
@@ -67,9 +65,21 @@
<input id="js_api_function_string_input" type="text" value="sort('column_title')" size="60"/>
<input type="button" value="Run" onclick="invokeJSAPI()" />
<input id="js_api_result" type="text" readonly="readonly" size="60"/>
- <it:extendedDataTable id="extendedDataTable" clientRows="40" rows="100" frozenColumns="2"
+ <br />
+ <h:outputText value="Selection mode" />
+ <h:selectOneMenu value="#{dataBean.selectionMode}">
+ <f:selectItems value="#{dataBean.selectionModes}"/>
+ <f:ajax render="extendedDataTable" />
+ </h:selectOneMenu>
+ <h:outputText value="Lock selection" style="padding-left: 30px;"/>
+ <input id="selectionLocker" type="checkbox"/>
+ <h:outputText value="Selected rowKeys" style="padding-left: 30px;"/>
+ <h:outputText id="selectionOutput" value="#{dataBean.selectedRowKeys}"/>
+ <rich:extendedDataTable id="extendedDataTable" clientRows="40" rows="100" frozenColumns="2"
value="#{dataBean.state ? dataBean.employeeList : null}" var="record" noDataLabel="There isn't data."
- styleClass="extendedDataTable" rowKeyVar="rkv" filterVar="fv" sortMode="multi">
+ styleClass="extendedDataTable" rowKeyVar="rkv" filterVar="fv" sortMode="multi"
+ selectionMode="#{dataBean.selectionMode}" selectedRowKeys="#{dataBean.selectedRowKeys}"
+ onselectionchange="document.getElementById('submit').click();" onbeforeselectionchange="if (document.getElementById('selectionLocker').checked) return false;">
<f:facet name="header">
<h:outputText value="Current date: #{dataBean.date}"/>
</f:facet>
@@ -79,7 +89,7 @@
<f:facet name="noData">
<h:outputText value="There isn't data." style="border: solid black 1px;"/>
</f:facet>
- <it:column id="rkv">
+ <rich:column id="rkv">
<f:facet name="header">
<h:outputText value="Index"/>
</f:facet>
@@ -89,8 +99,8 @@
<h:outputText id="footerFacet" value="index"/>
</f:facet>
</c:if>
- </it:column>
- <it:column id="column_name" filterExpression="#{fn:containsIgnoreCase(record.name, fv)}" sortBy="#{record.name}">
+ </rich:column>
+ <rich:column id="column_name" filterExpression="#{fn:containsIgnoreCase(record.name, fv)}" sortBy="#{record.name}">
<f:facet name="header">
<h:outputText id="columnHeader1" value="Column Header Facet"/>
</f:facet>
@@ -100,31 +110,31 @@
<h:outputText id="columnFooter1" value="Column Footer Facet"/>
</f:facet>
</c:if>
- </it:column>
+ </rich:column>
- <it:column id="column_title" width="200px" sortBy="#{record.title}">
+ <rich:column id="column_title" width="200px" sortBy="#{record.title}">
<h:outputText value="#{record.title}" />
<c:if test="#{dataBean.rendered}">
<f:facet name="footer">
<h:outputText id="columnFooter2" value="Column Footer Facet2"/>
</f:facet>
</c:if>
- </it:column>
+ </rich:column>
- <it:column id="column_email" width="300px">
+ <rich:column id="column_email" width="300px">
<h:outputText value="#{record.EMail}" />
- </it:column>
- <it:column id="column_company_name" width="300px">
+ </rich:column>
+ <rich:column id="column_company_name" width="300px">
<h:outputText value="#{record.companies[0].name}" />
- </it:column>
- <it:column id="column_company_state">
+ </rich:column>
+ <rich:column id="column_company_state">
<h:outputText value="#{record.companies[0].state}" />
- </it:column>
- <it:column id="column_company_phone">
+ </rich:column>
+ <rich:column id="column_company_phone">
<h:outputText value="#{record.companies[0].phone}" />
- </it:column>
- </it:extendedDataTable>
- <input type="submit" />
+ </rich:column>
+ </rich:extendedDataTable>
+ <input id="submit" type="submit" />
</h:form>
</h:body>
</html>
Added: root/ui/iteration/trunk/tables/api/src/main/java/org/richfaces/model/SelectionMode.java
===================================================================
--- root/ui/iteration/trunk/tables/api/src/main/java/org/richfaces/model/SelectionMode.java (rev 0)
+++ root/ui/iteration/trunk/tables/api/src/main/java/org/richfaces/model/SelectionMode.java 2010-06-30 18:07:32 UTC (rev 17686)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.richfaces.model;
+
+public enum SelectionMode {
+ none,
+ single,
+ multiple,
+ multipleKeyboardFree
+}
Modified: root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-06-30 15:52:20 UTC (rev 17685)
+++ root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-06-30 18:07:32 UTC (rev 17686)
@@ -50,11 +50,14 @@
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.SequenceRange;
import org.ajax4jsf.renderkit.AjaxEventOptions;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.ajax4jsf.renderkit.RendererUtils.ScriptHashVariableWrapper;
import org.richfaces.component.UIDataTableBase;
import org.richfaces.component.UIExtendedDataTable;
import org.richfaces.component.util.HtmlUtil;
import org.richfaces.context.OnOffResponseWriter;
+import org.richfaces.model.SelectionMode;
/**
* @author Konstantin Mishin
@@ -292,7 +295,7 @@
writer.startElement(HTML.TBODY_ELEMENT, table);
writer.startElement(HTML.TR_ELEMENT, table);
while (columns.hasNext()) {
- if(columnFacetPresent) {
+ if (columnFacetPresent) {
encodeHeaderOrFooterCell(context, writer, columns.next(), name);
} else {
encodeEmptyFooterCell(context, writer, columns.next());
@@ -515,6 +518,9 @@
+ "; i++ ) richTBody.appendChild(richTBody.removeChild(richRows[0]));");
writer.endEval();
}
+ writer.startUpdate(component.getClientId(context) + ":si");
+ encodeSelectionInput(writer, context, component);
+ writer.endUpdate();
writer.startEval();
writer.write("jQuery('#" + component.getClientId(context).replace(":", "\\\\:")
+ "').triggerHandler('rich:onajaxcomplete', {first: " + table.getClientFirst() + "});");
@@ -545,9 +551,13 @@
encodeFooter(state);
} else if (UIDataTableBase.BODY.equals(metaComponentId)) {
encodeBody(state);
+ writer.startUpdate(component.getClientId(context) + ":si");
+ encodeSelectionInput(writer, context, component);
+ writer.endUpdate();
writer.startEval();
writer.write("jQuery('#" + component.getClientId(context).replace(":", "\\\\:")
- + "').triggerHandler('rich:onajaxcomplete', {first: " + table.getClientFirst() + ", rowCount: " + getRowCount(component)+ ", reinitializeBody: true});");
+ + "').triggerHandler('rich:onajaxcomplete', {first: " + table.getClientFirst() + ", rowCount: "
+ + getRowCount(component) + ", reinitializeBody: true});");
writer.endEval();
} else {
throw new IllegalArgumentException("Unsupported metaComponentIdentifier: " + metaComponentId);
@@ -627,9 +637,24 @@
Map<String, Object> parameters = eventOptions.getParameters();
eventOptions.set(AjaxEventOptions.PARAMETERS, new JSReference("parameters"));
ajaxFunction.addParameter(eventOptions);
- writer.write("new RichFaces.ExtendedDataTable('" + component.getClientId(context) + "', "
- + getRowCount(component) + ", function(event, parameters) {" + ajaxFunction.toScript() + ";},"
- + ScriptUtils.toScript(parameters) + ");");
+ Map<String, Object> attributes = component.getAttributes();
+ Map<String, Object> options = new HashMap<String, Object>();
+ RendererUtils utils = getUtils();
+ utils.addToScriptHash(options, "parameters", parameters);
+ utils.addToScriptHash(options, "selectionMode", attributes.get("selectionMode"),
+ SelectionMode.multiple.toString());
+ utils.addToScriptHash(options, "onbeforeselectionchange", attributes.get("onbeforeselectionchange"), null,
+ ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onselectionchange", attributes.get("onselectionchange"), null,
+ ScriptHashVariableWrapper.EVENT_HANDLER);
+ StringBuilder builder = new StringBuilder("new RichFaces.ExtendedDataTable('");
+ builder.append(component.getClientId(context)).append("', ").append(getRowCount(component))
+ .append(", function(event, parameters) {").append(ajaxFunction.toScript()).append(";}");
+ if (!options.isEmpty()) {
+ builder.append(",").append(ScriptUtils.toScript(options));
+ }
+ builder.append(");");
+ writer.write(builder.toString());
writer.endElement(HTML.SCRIPT_ELEM);
writer.endElement(HTML.DIV_ELEM);
}
@@ -687,6 +712,12 @@
}
builder.append("rf-edt-r-a");
}
+ if (table.getRowKey().equals(table.getAttributes().get("shiftRowKey"))) {
+ if (builder.length() > 0) {
+ builder.append(' ');
+ }
+ builder.append("rf-edt-r-t");
+ }
if (builder.length() > 0) {
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, builder.toString(), null);
}
Modified: root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java 2010-06-30 15:52:20 UTC (rev 17685)
+++ root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java 2010-06-30 18:07:32 UTC (rev 17686)
@@ -32,8 +32,10 @@
import org.ajax4jsf.model.DataVisitResult;
import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.SequenceRange;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.UIDataTableBase;
+import org.richfaces.component.UIExtendedDataTable;
/**
* @author Konstantin Mishin
@@ -44,7 +46,10 @@
private class ClientSelection {
public static final String FLAG_RESET = "x";
-
+ public static final String FLAG_ALL = "a";
+ public static final String FLAG_AFTER_RANGE = "d";
+ public static final String FLAG_BEFORE_RANGE = "u";
+
private int [][] ranges;
private int activeIndex;
private int shiftIndex;
@@ -64,15 +69,17 @@
} else {
ranges = new int[0][0];
}
- if (strings[1].length() > 0) {
+ if (strings[1].matches("\\d+")) {
activeIndex = Integer.parseInt(strings[1]);
} else {
activeIndex = -1;
}
- if (strings[2].length() > 0) {
+ if (strings[2].matches("\\d+")) {
shiftIndex = Integer.parseInt(strings[2]);
+ } else if (strings[2].length() > 0) {
+ shiftIndex = -1;
} else {
- shiftIndex = -1;
+ shiftIndex = -2;
}
if (strings[3].length() > 0) {
selectionFlag = strings[3];
@@ -99,6 +106,10 @@
return shiftIndex == index;
}
+ public boolean isCleanShiftIndex() {
+ return shiftIndex == -2;
+ }
+
public String getSelectionFlag() {
return selectionFlag;
}
@@ -114,6 +125,37 @@
writer.writeAttribute(HTML.ID_ATTRIBUTE, component.getClientId(context) + ":si", null);
writer.writeAttribute(HTML.NAME_ATTRIBUTE, component.getClientId(context) + ":si", null);
writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
+ UIDataTableBase table = (UIDataTableBase) component;
+ StringBuilder builder = new StringBuilder("|");
+ Object key = table.getRowKey();
+ table.captureOrigValue(context);
+ SequenceRange range = (SequenceRange) table.getComponentState().getRange();
+ int first = range.getFirstRow();
+ int last = first + range.getRows() - 1;
+ Map<String, Object> attributes = component.getAttributes();
+ table.setRowKey(attributes.get("activeRowKey"));
+ int activeIndex = table.getRowIndex();
+ if (activeIndex > 0) {
+ if (activeIndex < first) {
+ builder.append(ClientSelection.FLAG_BEFORE_RANGE);
+ } else if (activeIndex > last) {
+ builder.append(ClientSelection.FLAG_AFTER_RANGE);
+ }
+ }
+ builder.append("|");
+ table.setRowKey(attributes.get("shiftRowKey"));
+ int shiftIndex = table.getRowIndex();
+ if (shiftIndex > 0) {
+ if (shiftIndex < first) {
+ builder.append(ClientSelection.FLAG_BEFORE_RANGE);
+ } else if (shiftIndex > last) {
+ builder.append(ClientSelection.FLAG_AFTER_RANGE);
+ }
+ }
+ builder.append("|");
+ table.setRowKey(context, key);
+ table.restoreOrigValue(context);
+ writer.writeAttribute(HTML.VALUE_ATTRIBUTE, builder.toString(), null);
writer.endElement(HTML.INPUT_ELEM);
}
@@ -132,15 +174,53 @@
selectedRowKeys = new HashSet<Object>();
updateAttribute(context, component, "selectedRowKeys", selectedRowKeys);
}
- if (ClientSelection.FLAG_RESET.equals(clientSelection.getSelectionFlag())) {
+ final Collection<Object> rowKeys = selectedRowKeys;
+ if (clientSelection.getSelectionFlag() != null) {
selectedRowKeys.clear();
+ if (!ClientSelection.FLAG_RESET.equals(clientSelection.getSelectionFlag())) {
+ Object key = table.getRowKey();
+ table.captureOrigValue(context);
+ SequenceRange range = (SequenceRange) table.getComponentState().getRange();
+ SequenceRange newRange = null;
+ Object rowKey = attributes.get("shiftRowKey");
+ if (rowKey == null) {
+ rowKey = attributes.get("activeRowKey");
+ attributes.put("shiftRowKey", rowKey);
+ }
+ table.setRowKey(rowKey);
+ int shiftIndex = table.getRowIndex();
+ if (ClientSelection.FLAG_ALL.equals(clientSelection.getSelectionFlag())) {
+ newRange = new SequenceRange(0, 0);
+ } else if (shiftIndex > 0) {
+ if (ClientSelection.FLAG_BEFORE_RANGE.equals(clientSelection.getSelectionFlag())) {
+ newRange = new SequenceRange(shiftIndex, range.getFirstRow() - shiftIndex);
+ } else {
+ int last = range.getFirstRow() + range.getRows();
+ newRange = new SequenceRange(last, shiftIndex - last + 1);
+ }
+ }
+ table.setRowKey(context, key);
+ table.restoreOrigValue(context);
+ if (newRange != null) {
+ ((UIExtendedDataTable) table).walk(context, new DataVisitor() { //TODO Don't use cast here.
+ public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
+ rowKeys.add(rowKey);
+ return DataVisitResult.CONTINUE;
+ }
+ }, newRange, null);
+ }
+ }
}
- final Collection<Object> rowKeys = selectedRowKeys;
+ if (clientSelection.isCleanShiftIndex()) {
+ attributes.remove("shiftRowKey");
+ }
table.walk(context, new DataVisitor() {
public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
int index = clientSelection.nextIndex();
if (clientSelection.isSelected(index)) {
rowKeys.add(rowKey);
+ } else {
+ rowKeys.remove(rowKey);
}
if (clientSelection.isActiveIndex(index)) {
attributes.put("activeRowKey", rowKey);
Modified: root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js 2010-06-30 15:52:20 UTC (rev 17685)
+++ root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js 2010-06-30 18:07:32 UTC (rev 17686)
@@ -96,28 +96,6 @@
}
},
- remove: function(index) {
- var i = 0;
- while(i < this.ranges.length && index > this.ranges[i++][1]);
- i--;
- if(this.ranges[i]) {
- if(index==(this.ranges[i][1]) ) {
- if(index==(this.ranges[i][0])){
- this.ranges.splice(i, 1);
- } else {
- this.ranges[i][1]--;
- }
- } else {
- if(index==(this.ranges[i][0])){
- this.ranges[i][0]++;
- } else {
- this.ranges.splice(i+1, 0, [index+1, this.ranges[i][1]]);
- this.ranges[i][1] = index-1;
- }
- }
- }
- },
-
clear: function() {
this.ranges = [];
},
@@ -143,10 +121,11 @@
}
};
- richfaces.ExtendedDataTable = function(id, rowCount, ajaxFunction, ajaxParameters) {
+ richfaces.ExtendedDataTable = function(id, rowCount, ajaxFunction, options) {
var WIDTH_CLASS_NAME_BASE = "rf-edt-cw-";
var MIN_WIDTH = 20;
+ options = options || {};
var ranges = new richfaces.utils.Ranges();
var element = document.getElementById(id);
var bodyElement, contentElement, spacerElement, dataTableElement, rows, rowHeight, parts, tbodies, shiftIndex,
@@ -172,15 +151,16 @@
var timeoutId = null;
var sendAjax = function(event, map) {
- for (key in ajaxParameters) {
+ for (key in options.parameters) {
if(!map[key]) {
- map[key] = ajaxParameters[key];
+ map[key] = options.parameters[key];
}
}
ajaxFunction(event, map);
};
var updateLayout = function() {
+ normalPartStyle.width = "auto";
var offsetWidth = frozenHeaderPartElement ? frozenHeaderPartElement.offsetWidth : 0;
var width = Math.max(0, element.clientWidth - offsetWidth);
if (width) {
@@ -263,7 +243,9 @@
var initialize = function() {
bodyElement = document.getElementById(id + ":b");
- contentElement = jQuery(bodyElement).children("div:first")[0];
+ bodyElement.tabIndex = -1; //TODO don't use tabIndex.
+ var bodyJQuery = jQuery(bodyElement);
+ contentElement = bodyJQuery.children("div:first")[0];
if (contentElement) {
spacerElement = contentElement.firstChild;//TODO this.marginElement = Richfaces.firstDescendant(this.contentElement);
dataTableElement = contentElement.lastChild;//TODO this.dataTableElement = Richfaces.lastDescendant(this.contentElement);
@@ -273,9 +255,12 @@
if (rowCount != rows) {
contentElement.style.height = (rowCount * rowHeight) + "px";
}
- jQuery(bodyElement).bind("scroll", bodyScrollListener)
- tbodies.bind("click", selectionClickListener);
- initializeSelection();
+ bodyJQuery.bind("scroll", bodyScrollListener);
+ if (options.selectionMode != "none") {
+ tbodies.bind("click", selectionClickListener);
+ bodyJQuery.bind("keydown", selectionKeyDownListener);
+ initializeSelection();
+ }
} else {
spacerElement = null;
dataTableElement = null;
@@ -404,17 +389,15 @@
}
}
- var deselectRow = function (index, skipUpdateModel) {
- if (!skipUpdateModel) {
- ranges.remove(index);
- }
+ var deselectRow = function (index) {
+ ranges.remove(index);
for ( var i = 0; i < tbodies.length; i++) {
jQuery(tbodies[i].rows[index]).removeClass("rf-edt-r-s");
}
}
var setActiveRow = function (index) {
- if(activeIndex != null) {
+ if(typeof activeIndex == "number") {
for ( var i = 0; i < tbodies.length; i++) {
jQuery(tbodies[i].rows[activeIndex]).removeClass("rf-edt-r-a");
}
@@ -426,10 +409,31 @@
}
}
+ var resetShiftRow = function () {
+ if(typeof shiftIndex == "number") {
+ for ( var i = 0; i < tbodies.length; i++) {
+ jQuery(tbodies[i].rows[shiftIndex]).removeClass("rf-edt-r-t");
+ }
+
+ }
+ shiftIndex = null;
+ }
+
+ var setShiftRow = function (index) {
+ resetShiftRow();
+ shiftIndex = index;
+ if(typeof index == "number") {
+ for ( var i = 0; i < tbodies.length; i++) {
+ jQuery(tbodies[i].rows[shiftIndex]).addClass("rf-edt-r-t");
+ }
+ }
+ }
+
var initializeSelection = function() {
ranges.clear();
- activeIndex = null;
- shiftIndex = null;
+ var strings = selectionInput.value.split("|");
+ activeIndex = strings[1] || null;
+ shiftIndex = strings[2] || null;
selectionFlag = null;
var rows = tbodies[0].rows;
for (var i = 0; i < rows.length; i++) {
@@ -440,87 +444,153 @@
if (row.hasClass("rf-edt-r-a")) {
activeIndex = row[0].rowIndex;
}
+ if (row.hasClass("rf-edt-r-t")) {
+ shiftIndex = row[0].rowIndex;
+ }
}
- wtiteSelection();
+ writeSelection();
}
- var wtiteSelection = function() {
+ var writeSelection = function() {
selectionInput.value = [ranges, activeIndex, shiftIndex, selectionFlag].join("|");
}
+
+ var selectRows = function(range) {
+ var changed;
+ var i = 0;
+ for (; i < range[0]; i++) {
+ if (ranges.contains(i)) {
+ deselectRow(i);
+ changed = true;
+ }
+ }
+ for (; i <= range[1]; i++) {
+ if (!ranges.contains(i)) {
+ selectRow(i);
+ changed = true;
+ }
+ }
+ for (; i < rows; i++) {
+ if (ranges.contains(i)) {
+ deselectRow(i);
+ changed = true;
+ }
+ }
+ selectionFlag = typeof shiftIndex == "string" ? shiftIndex : "x";
+ return changed;
+ }
+
+ var processSlectionWithShiftKey = function(index) {
+ if(shiftIndex == null) {
+ setShiftRow(activeIndex != null ? activeIndex : index);
+ }
+ var range;
+ if ("u" == shiftIndex) {
+ range = [0, index];
+ } else if ("d" == shiftIndex) {
+ range = [index, rows - 1];
+ } else if (index >= shiftIndex) {
+ range = [shiftIndex, index];
+ } else {
+ range = [index, shiftIndex];
+ }
+ return selectRows(range);
+ }
+
+ var onbeforeselectionchange = function (event) {
+ return !options.onbeforeselectionchange || options.onbeforeselectionchange(event) !== false;
+ }
+
+ var onselectionchange = function (event, index, changed) {
+ if(!event.shiftKey) {
+ resetShiftRow();
+ }
+ if (activeIndex != index) {
+ setActiveRow(index);
+ }
+ if (changed) {
+ writeSelection();
+ if (options.onselectionchange) {
+ options.onselectionchange(event);
+ }
+ }
+ }
+
var selectionClickListener = function (event) {
+ if (!onbeforeselectionchange(event)) {
+ return;
+ }
+ var changed;
if (event.shiftKey || event.ctrlKey) {
- if (window.getSelection) {
- window.getSelection().removeAllRanges(); //TODO
+ if (window.getSelection) { //TODO Try to find other way.
+ window.getSelection().removeAllRanges();
} else if (document.selection) {
document.selection.empty();
}
}
-
var tr = event.target;
while (tbodies.index(tr.parentNode) == -1) {
tr = tr.parentNode;
}
var index = tr.rowIndex;
-
- if(!event.shiftKey) {
- shiftIndex = null;
- }
- if (event.shiftKey && !event.ctrlKey) {
- if(shiftIndex == null) {
- shiftIndex = activeIndex != null ? activeIndex : index;
- }
- var range;
- if (index >= shiftIndex) {
- range = [shiftIndex, index];
- } else {
- range = [index, shiftIndex];
- }
- var i = 0;
- for (; i < range[0]; i++) {
- if (ranges.contains(i)) {
- deselectRow(i);
- }
- }
- for (; i <= range[1]; i++) {
- if (!ranges.contains(i)) {
- selectRow(i);
- }
- }
- for (; i < rows; i++) {
- if (ranges.contains(i)) {
- deselectRow(i);
- }
- }
- selectionFlag = "x";
- } else if (!event.shiftKey && event.ctrlKey) {
+ if (options.selectionMode == "single" || (options.selectionMode != "multipleKeyboardFree"
+ && !event.shiftKey && !event.ctrlKey)) {
+ changed = selectRows([index, index]);
+ } else if (options.selectionMode == "multipleKeyboardFree" || (!event.shiftKey && event.ctrlKey)) {
if (ranges.contains(index)) {
deselectRow(index);
} else {
selectRow(index);
}
- } else if (!event.shiftKey && !event.ctrlKey) {
- ranges.clear();
- for (var i = 0; i < rows; i++) {
- if (i == index) {
- selectRow(i);
- } else {
- deselectRow(i, true);
+ changed = true;
+ } else {
+ changed = processSlectionWithShiftKey(index);
+ }
+ onselectionchange(event, index, changed);
+ }
+
+ var selectionKeyDownListener = function(event) {
+ if (event.ctrlKey && options.selectionMode != "single" && (event.keyCode == 65 || event.keyCode == 97)) { //Ctrl-A
+ if(onbeforeselectionchange(event)) {
+ selectRows([0, rows]);
+ selectionFlag = "a";
+ onselectionchange(event, activeIndex, true); //TODO Is there a way to know that selection haven't changed?
+ }
+ return false;
+ }
+ if (typeof activeIndex == "number") {
+ var index;
+ if (event.keyCode == 38 && activeIndex) { //UP
+ index = activeIndex - 1;
+ } else if (event.keyCode == 40 && activeIndex < rows - 1) { //DOWN
+ index = activeIndex + 1;
+ }
+ if (index != null) {
+ if(onbeforeselectionchange(event)) {
+ var changed;
+ if (options.selectionMode == "single" || (!event.shiftKey && !event.ctrlKey)) {
+ changed = selectRows([index, index]);
+ } else if (event.shiftKey) {
+ changed = processSlectionWithShiftKey(index);
+ }
+ setActiveRow(index);
+ //showRow
+ onselectionchange(event, index, changed);
}
+ return false;
}
- selectionFlag = "x";
}
- setActiveRow(index);
- wtiteSelection();
}
var ajaxComplete = function (event, data) {
if (data.reinitializeHeader) {
bindHeaderHandlers();
} else {
+ selectionInput = document.getElementById(id + ":si");
if (data.reinitializeBody) {
rowCount = data.rowCount;
initialize();
- } else {
+ } else if (options.selectionMode != "none") {
initializeSelection();
}
if (spacerElement) {
14 years, 6 months
JBoss Rich Faces SVN: r17685 - root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2010-06-30 11:52:20 -0400 (Wed, 30 Jun 2010)
New Revision: 17685
Modified:
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/richfaces-selection.js
Log:
https://jira.jboss.org/browse/RF-8875
Modified: root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js
===================================================================
--- root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js 2010-06-30 11:42:30 UTC (rev 17684)
+++ root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js 2010-06-30 15:52:20 UTC (rev 17685)
@@ -24,7 +24,7 @@
}
if ((!this.lastKey || key.indexOf(this.lastKey)!=0) && newCache.length > 0) {
- console && console.log && console.log("added key:"+key+" length:" + newCache.length)
+ //console && console.log && console.log("added key:"+key+" length:" + newCache.length)
this.cache[key] = newCache;
if (newCache.length==1) {
this.lastKey = key;
@@ -132,7 +132,7 @@
var autoFill = function (inputValue, value) {
if( this.options.autoFill) {
var field = rf.getDomElement(this.fieldId);
- field.value = field.value + value.substring(inputValue.length);
+ field.value = inputValue + value.substring(inputValue.length);
rf.Selection.set(field, inputValue.length, field.value.length);
}
};
@@ -149,7 +149,7 @@
return this.namespace;
},
- selectItem: function(index, isOffset) {
+ selectItem: function(index, isOffset, noAutoFill) {
if (this.items.length==0) return;
if (this.index!=-1) {
@@ -176,9 +176,11 @@
}
this.index = index;
}
- this.items.eq(this.index).addClass(this.options.selectedItemClass);
+ var item = this.items.eq(this.index);
+ item.addClass(this.options.selectedItemClass);
scrollToSelectedItem.call(this);
+ !noAutoFill && autoFill.call(this, this.newValue, item.text());
},
selectPrevItem: function () {
@@ -196,24 +198,19 @@
onBeforeShow: function (event) {
},
- onChange: function (event, value) {
+ changeValue: function (event, value) {
// TODO: ajax call here if needed
-
this.selectItem();
var newItems = this.cache.getItems(value);
this.items = $(newItems);
$(rf.getDomElement(this.componentId+ID.ITEMS)).empty().append(newItems);
this.index = -1;
- this.selectItem(0);
- // getFirstValue
- $(this.items).first().text();
- if (event.which != rf.KEYS.BACKSPACE) {
- autoFill.call(this, value, $(this.items).first().text());
- }
+ this.newValue = value;
+ this.selectItem(0, false, event.which == rf.KEYS.BACKSPACE);
},
- onShow: function () {
+ onShow: function (event) {
if (this.items && this.items.length>0) {
//??TODO it's nessesary only if not changed value
this.selectItem(0);
Modified: root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js
===================================================================
--- root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js 2010-06-30 11:42:30 UTC (rev 17684)
+++ root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js 2010-06-30 15:52:20 UTC (rev 17685)
@@ -48,7 +48,7 @@
this.fieldId = fieldId;
this.options = $.extend({}, defaultOptions, options);
this.namespace = this.namespace || "."+rf.Event.createNamespace(this.name, this.selectId);
- this.currentValue = this.getCurrentValue();
+ this.currentValue = this.getInputValue();
bindEventHandlers.call(this);
};
@@ -133,16 +133,15 @@
};
var onChange = function (event) {
- var value = this.getCurrentValue();
+ var value = this.getInputValue();
var flag = value != this.currentValue;
if (event.which == rf.KEYS.LEFT || event.which == rf.KEYS.RIGHT || flag) {
- // TODO: call onchange
- if (flag && !this.isVisible) {
- this.show();
- }
if (flag) {
- this.onChange(event, value);
+ this.changeValue(event, value);
this.currentValue = value;
+ if (!this.isVisible) {
+ this.show();
+ }
}
}
}
@@ -247,7 +246,7 @@
},
onBeforeShow: function () {
},
- getCurrentValue: function () {
+ getInputValue: function () {
var value = this.fieldId ? rf.getDomElement(this.fieldId).value : undefined;
return value;
}
Modified: root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/richfaces-selection.js
===================================================================
--- root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/richfaces-selection.js 2010-06-30 11:42:30 UTC (rev 17684)
+++ root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/richfaces-selection.js 2010-06-30 15:52:20 UTC (rev 17685)
@@ -9,8 +9,8 @@
} else if (field.createTextRange){
var range = field.createTextRange();
range.collapse(true);
- range.moveEnd('character', pos);
- range.moveStart('character', pos);
+ range.moveEnd('character', end);
+ range.moveStart('character', start);
range.select();
}
}
14 years, 6 months
JBoss Rich Faces SVN: r17684 - root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2010-06-30 07:42:30 -0400 (Wed, 30 Jun 2010)
New Revision: 17684
Modified:
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js
Log:
https://jira.jboss.org/browse/RF-8875 working cache was added + some changes
Modified: root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js
===================================================================
--- root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js 2010-06-30 06:27:53 UTC (rev 17683)
+++ root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js 2010-06-30 11:42:30 UTC (rev 17684)
@@ -2,22 +2,37 @@
rf.utils = rf.utils || {};
rf.utils.Cache = function (data, options) {
- this.data = data || [];
- this.values = options.parse && options.parse(this.data) || this.data;
+ this.key = options.key;
+ this.cache = {}
+ this.cache[this.key] = data || [];
+ this.values = options.parse && options.parse(data) || this.cache[this.key];
};
- var getItems = function (str) {
- if (!str || str.length==0) {
- return this.data;
+ var getItems = function (key) {
+ var newCache = [];
+
+ if (this.cache[key]) {
+ newCache = this.cache[key];
+ } else {
+ var itemsCache = this.cache[this.key];
+ for (var i = 0; i<this.values.length; i++) {
+ var value = this.values[i].toLowerCase();
+ var p = value.indexOf(key.toLowerCase());
+ if (p == 0) {
+ newCache.push(itemsCache[i]);
+ }
+ }
+
+ if ((!this.lastKey || key.indexOf(this.lastKey)!=0) && newCache.length > 0) {
+ console && console.log && console.log("added key:"+key+" length:" + newCache.length)
+ this.cache[key] = newCache;
+ if (newCache.length==1) {
+ this.lastKey = key;
+ }
+ }
}
- var newData = [];
- for (var i = 0; i<this.values.length; i++) {
- var value = this.values[i].toLowerCase();
- var p = value.indexOf(str.toLowerCase());
- p == 0 && newData.push(this.data[i]);
- }
-
- return newData;
+
+ return newCache;
};
$.extend(rf.utils.Cache.prototype, (function () {
@@ -42,8 +57,8 @@
this.options = $.extend(this.options, defaultOptions, options);
//this.currentValue = rf.getDomElement(this.fieldId).value;
this.index = -1;
- updateItemsList.call(this);
bindEventHandlers.call(this);
+ updateItemsList.call(this, "");
};
var $p ={};
@@ -82,10 +97,11 @@
}
};
- var updateItemsList = function () {
+ var updateItemsList = function (value) {
this.items = $(rf.getDomElement(this.componentId+ID.ITEMS)).children();
this.cache = new rf.utils.Cache(this.items, {
- parse: getData
+ parse: getData,
+ key: value
});
};
@@ -126,6 +142,7 @@
return {
name:"CompoBox",
destroy: function () {
+ //TODO: add all unbind
$super.destroy.call(this);
},
getNamespace: function () {
@@ -176,11 +193,13 @@
selectPageDown: function () {
},
- prepareToShow: function (event) {
-
+ onBeforeShow: function (event) {
},
onChange: function (event, value) {
+ // TODO: ajax call here if needed
+
+
this.selectItem();
var newItems = this.cache.getItems(value);
this.items = $(newItems);
@@ -195,7 +214,7 @@
},
onShow: function () {
- if (this.items.length>0) {
+ if (this.items && this.items.length>0) {
//??TODO it's nessesary only if not changed value
this.selectItem(0);
}
Modified: root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js
===================================================================
--- root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js 2010-06-30 06:27:53 UTC (rev 17683)
+++ root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js 2010-06-30 11:42:30 UTC (rev 17684)
@@ -48,7 +48,7 @@
this.fieldId = fieldId;
this.options = $.extend({}, defaultOptions, options);
this.namespace = this.namespace || "."+rf.Event.createNamespace(this.name, this.selectId);
- this.currentValue = rf.getDomElement(this.fieldId).value;
+ this.currentValue = this.getCurrentValue();
bindEventHandlers.call(this);
};
@@ -133,7 +133,7 @@
};
var onChange = function (event) {
- var value = rf.getDomElement(this.fieldId).value;
+ var value = this.getCurrentValue();
var flag = value != this.currentValue;
if (event.which == rf.KEYS.LEFT || event.which == rf.KEYS.RIGHT || flag) {
// TODO: call onchange
@@ -184,10 +184,10 @@
case rf.KEYS.TAB:
case rf.KEYS.RETURN:
event.preventDefault();
- /*if( selectCurrent() ) {
+ /*if( selectCurrentItem() ) {
event.preventDefault();
//TODO: bind form submit event handler to cancel form submit under the opera
- cancelSubmit = true;
+ //cancelSubmit = true;
return false;
}*/
this.hide();
@@ -210,7 +210,7 @@
return {
name:"SelectBase",
show: function (event) {
- if (this.prepareToShow(event)!=false) {
+ if (this.onBeforeShow(event)!=false) {
$(rf.getDomElement(this.selectId)).show();
this.isVisible = true;
this.scrollElements = rf.Event.bindScrollEventHandlers(this.selectId, this.hide, this, this.namespace);
@@ -245,8 +245,13 @@
},
selectPageDown: function () {
},
- prepareToShow: function () {
+ onBeforeShow: function () {
+ },
+ getCurrentValue: function () {
+ var value = this.fieldId ? rf.getDomElement(this.fieldId).value : undefined;
+ return value;
}
+
};
})());
})(jQuery, RichFaces);
\ No newline at end of file
14 years, 6 months
JBoss Rich Faces SVN: r17683 - in root/docs/trunk/Component_Reference/en-US: extras and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: SeanRogers
Date: 2010-06-30 02:27:53 -0400 (Wed, 30 Jun 2010)
New Revision: 17683
Added:
root/docs/trunk/Component_Reference/en-US/extras/exam-Component_Reference-Tables_and_grids-richdataOrderedList_example.xml_sample
root/docs/trunk/Component_Reference/en-US/images/figu-Component_Reference-Tables_and_grids-richdataOrderedList_example.png
Modified:
root/docs/trunk/Component_Reference/en-US/chap-Component_Reference-Tables_and_grids.xml
Log:
Added rich:dataOrderedList to docs
Modified: root/docs/trunk/Component_Reference/en-US/chap-Component_Reference-Tables_and_grids.xml
===================================================================
--- root/docs/trunk/Component_Reference/en-US/chap-Component_Reference-Tables_and_grids.xml 2010-06-30 00:47:26 UTC (rev 17682)
+++ root/docs/trunk/Component_Reference/en-US/chap-Component_Reference-Tables_and_grids.xml 2010-06-30 06:27:53 UTC (rev 17683)
@@ -661,8 +661,75 @@
</listitem>
</itemizedlist>
<para>
- Incomplete
+ The <sgmltag><rich:dataOrderedList></sgmltag> component renders an ordered list of items from a data model. Specific rows can be updated dynamically without updating the entire list.
</para>
+ <para>
+ The <varname>type</varname> attribute defines the appearance of the numerating list markers for the list. The possible values for the <varname>type</varname> attribute are as follows:
+ </para>
+ <variablelist>
+ <varlistentry>
+ <term><literal>A</literal></term>
+ <listitem>
+ <para>
+ Numerates the list items as <wordasword>A</wordasword>, <wordasword>B</wordasword>, <wordasword>C</wordasword>, etc.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><literal>a</literal></term>
+ <listitem>
+ <para>
+ Numerates the list items as <wordasword>a</wordasword>, <wordasword>b</wordasword>, <wordasword>c</wordasword>, etc.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><literal>I</literal></term>
+ <listitem>
+ <para>
+ Numerates the list items as <wordasword>I</wordasword>, <wordasword>II</wordasword>, <wordasword>III</wordasword>, etc.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><literal>i</literal></term>
+ <listitem>
+ <para>
+ Numerates the list items as <wordasword>i</wordasword>, <wordasword>ii</wordasword>, <wordasword>iii</wordasword>, etc.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><literal>1</literal></term>
+ <listitem>
+ <para>
+ Numerates the list items as <wordasword>1</wordasword>, <wordasword>2</wordasword>, <wordasword>3</wordasword>, etc.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ <para>
+ The <varname>rows</varname> attribute limits the number of items in the list. The <varname>first</varname> attribute specifies the first item to start from when populating the list. The <varname>title</varname> attribute defines a pop-up title. To only update a sub-set of the rows in the list, use the <varname>ajaxKeys</varname> attribute, which points to an object that contains the specified rows.
+ </para>
+ <example id="exam-Component_Reference-Tables_and_grids-richdataOrderedList_example">
+ <title><sgmltag><rich:dataOrderedList></sgmltag> example</title>
+<programlisting language="XML" role="XML"><xi:include parse="text" href="extras/exam-Component_Reference-Tables_and_grids-richdataOrderedList_example.xml_sample" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ <blockquote>
+ <figure id="figu-Component_Reference-Tables_and_grids-richdataOrderedList_example">
+ <title><sgmltag><rich:dataOrderedList></sgmltag> example</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/figu-Component_Reference-Tables_and_grids-richdataOrderedList_example.png" format="PNG" />
+ </imageobject>
+ <textobject>
+ <para>
+ A list of cars displayed in a numbered list.
+ </para>
+ </textobject>
+ </mediaobject>
+ </figure>
+ </blockquote>
+ </example>
</section>
<section id="sect-Component_Reference-Tables_and_grids-richdataScroller">
Added: root/docs/trunk/Component_Reference/en-US/extras/exam-Component_Reference-Tables_and_grids-richdataOrderedList_example.xml_sample
===================================================================
--- root/docs/trunk/Component_Reference/en-US/extras/exam-Component_Reference-Tables_and_grids-richdataOrderedList_example.xml_sample (rev 0)
+++ root/docs/trunk/Component_Reference/en-US/extras/exam-Component_Reference-Tables_and_grids-richdataOrderedList_example.xml_sample 2010-06-30 06:27:53 UTC (rev 17683)
@@ -0,0 +1,9 @@
+<h:form>
+ <rich:dataOrderedList var="car" value="#{dataTableScrollerBean.allCars}" rows="5" type="1" title="Car Store">
+ <h:outputText value="#{car.make} #{car.model}"/><br/>
+ <h:outputText value="Price:" styleClass="label"></h:outputText>
+ <h:outputText value="#{car.price}" /><br/>
+ <h:outputText value="Mileage:" styleClass="label"></h:outputText>
+ <h:outputText value="#{car.mileage}" /><br/>
+ </rich:dataOrderedList>
+</h:form>
Added: root/docs/trunk/Component_Reference/en-US/images/figu-Component_Reference-Tables_and_grids-richdataOrderedList_example.png
===================================================================
(Binary files differ)
Property changes on: root/docs/trunk/Component_Reference/en-US/images/figu-Component_Reference-Tables_and_grids-richdataOrderedList_example.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
14 years, 6 months