JBoss Rich Faces SVN: r17703 - in root/cdk/branches/RF8755/plugins: generator/src/main/java/org/richfaces/cdk and 14 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-07-01 20:31:47 -0400 (Thu, 01 Jul 2010)
New Revision: 17703
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/SwitchStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addConstant.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addImport.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addMethod.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/foo.ftl
Removed:
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/templatecompiler/JavaClassConfiguration.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java
Modified:
root/cdk/branches/RF8755/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java
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/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/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/model/ModelFragment.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.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/IfStatement.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/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/main/resources/META-INF/schema/cdk-template.xsd
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:
Merged revisions 17695 via svnmerge from
https://svn.jboss.org/repos/richfaces/root/cdk/trunk
.......
r17695 | nbelaevski | 2010-07-01 06:15:39 -0700 (Thu, 01 Jul 2010) | 1 line
Added support for cdk:switch/cdk:case/cdk:default elements
.......
tested improved templates
Modified: root/cdk/branches/RF8755/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java
===================================================================
--- root/cdk/branches/RF8755/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java 2010-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -45,6 +45,7 @@
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Provider;
+import com.google.inject.ScopeAnnotation;
import com.google.inject.TypeLiteral;
import com.google.inject.binder.AnnotatedBindingBuilder;
@@ -155,29 +156,11 @@
Class<? extends Annotation> annotationType = annotation.annotationType();
if (/* annotationType.isAnnotationPresent(Qualifier.class)|| */annotationType
.isAnnotationPresent(BindingAnnotation.class)) {
- Implementation implementation = annotationType.getAnnotation(Implementation.class);
- if (null != implementation) {
- try {
- Annotation value =
- implementation.value().getConstructor(annotationType).newInstance(annotation);
- builder.annotatedWith(value);
- } catch (SecurityException e) {
- throw new RuntimeException(e);
- } catch (NoSuchMethodException e) {
- builder.annotatedWith(annotationType);
- } catch (IllegalArgumentException e) {
- throw new RuntimeException(e);
- } catch (InstantiationException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- } else {
- builder.annotatedWith(annotationType);
- }
+ builder.annotatedWith(annotation);
}
+ if (annotationType.isAnnotationPresent(ScopeAnnotation.class)){
+ builder.in(annotationType);
+ }
}
Binding binding = fields.get(field);
if (null != binding.getValue()) {
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -34,7 +34,6 @@
import java.util.Map;
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.taglib.TaglibModule;
import org.richfaces.cdk.model.ModelModule;
@@ -115,7 +114,7 @@
public void init() {
injector =
Guice.createInjector(Stage.PRODUCTION, new CdkConfigurationModule(), new AptModule(), new ModelModule(),
- new FreeMakerModule(),new ClassGeneratorModule(), new TemplateModule(),
+ new ClassGeneratorModule(), new TemplateModule(),
new XmlModule(), new TaglibModule());
if (!log.isDebugEnabled()) {
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -46,6 +46,8 @@
public class CdkConfiguration extends Configuration implements FreeMarkerRenderer {
private static final String TEMPLATES = "/META-INF/templates";
+
+ private String templatesFolder=TEMPLATES;
private Logger log;
@@ -74,6 +76,11 @@
}
}
}
+
+ @Inject(optional=true)
+ public synchronized void setImports(@DefaultImports Map<String,String> map) {
+ super.setAutoImports(map);
+ }
@Override
public void writeTemplate(String templateName, Object object, Writer writer) throws IOException, TemplateException {
@@ -102,9 +109,19 @@
/**
* <p class="changed_added_4_0"></p>
+ * @param templatesFolder the templatesFolder to set
+ */
+ @Inject(optional=true)
+ public void setTemplatesFolder(@TemplatesFolder String templatesFolder) {
+ setClassForTemplateLoading(this.getClass(), templatesFolder);
+ this.templatesFolder = templatesFolder;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
* @return the templates
*/
- public static String getTemplatesFolder() {
- return TEMPLATES;
+ public String getTemplatesFolder() {
+ return templatesFolder;
}
}
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,48 @@
+/*
+ * $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 static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+/**
+ * <p class="changed_added_4_0">
+ * Marks {@link org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer} instance that is targeted to work with JSF
+ * library model
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@Retention(RUNTIME)
+@Target({ FIELD, PARAMETER, METHOD })
+@BindingAnnotation
+public @interface DefaultImports {
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: 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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -1,40 +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.generate.freemarker;
-
-import com.google.inject.AbstractModule;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class FreeMakerModule extends AbstractModule {
-
- @Override
- protected void configure() {
- bind(FreeMarkerRenderer.class).to(CdkConfiguration.class);
- }
-
-}
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,16 @@
+package org.richfaces.cdk.generate.freemarker;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+@Retention(RUNTIME)
+@Target({ FIELD, PARAMETER, METHOD })
+@BindingAnnotation
+public @interface TemplatesFolder {
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -43,7 +43,7 @@
public class BehaviorClassGenerator extends FreeMarkerWriter<BehaviorModel> implements CdkWriter {
@Inject
- public BehaviorClassGenerator(FreeMarkerRenderer configuration,
+ public BehaviorClassGenerator(@LibraryModel 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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -23,15 +23,16 @@
package org.richfaces.cdk.generate.java;
-import java.util.Set;
-
import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.FreeMakerUtils;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
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.PrivateModule;
-import com.google.inject.TypeLiteral;
+import com.google.inject.AbstractModule;
+import com.google.inject.PrivateBinder;
import com.google.inject.multibindings.Multibinder;
import freemarker.template.ObjectWrapper;
@@ -43,7 +44,7 @@
* @author asmirnov(a)exadel.com
*
*/
-public class ClassGeneratorModule extends PrivateModule {
+public class ClassGeneratorModule extends AbstractModule {
/*
* (non-Javadoc)
@@ -60,9 +61,11 @@
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);
+ PrivateBinder privateBinder = binder().newPrivateBinder();
+ privateBinder.bind(FreeMarkerRenderer.class).annotatedWith(LibraryModel.class).to(CdkConfiguration.class);
+ privateBinder.expose(FreeMarkerRenderer.class).annotatedWith(LibraryModel.class);
+ privateBinder.bind(ObjectWrapper.class).to(LibraryModelWrapper.class);
+ privateBinder.bind(FreeMakerUtils.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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -47,7 +47,7 @@
public class ComponentClassGenerator extends FreeMarkerWriter<ComponentModel> implements CdkWriter {
@Inject
- public ComponentClassGenerator(FreeMarkerRenderer configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public ComponentClassGenerator(@LibraryModel 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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -43,7 +43,7 @@
public class ConverterClassGenerator extends FreeMarkerWriter<ConverterModel> implements CdkWriter {
@Inject
- public ConverterClassGenerator(FreeMarkerRenderer configuration,
+ public ConverterClassGenerator(@LibraryModel 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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -44,7 +44,7 @@
public class EventSourceInterfaceGenerator extends FreeMarkerWriter<EventModel> implements CdkWriter {
@Inject
- public EventSourceInterfaceGenerator(FreeMarkerRenderer configuration,
+ public EventSourceInterfaceGenerator(@LibraryModel FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,48 @@
+/*
+ * $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.java;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+/**
+ * <p class="changed_added_4_0">
+ * Marks {@link org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer} instance that is targeted to work with JSF
+ * library model
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@Retention(RUNTIME)
+@Target({ FIELD, PARAMETER, METHOD })
+@BindingAnnotation
+public @interface LibraryModel {
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -43,7 +43,7 @@
public class ValidatorClassGenerator extends FreeMarkerWriter<ValidatorModel> implements CdkWriter {
@Inject
- public ValidatorClassGenerator(FreeMarkerRenderer configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public ValidatorClassGenerator(@LibraryModel 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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -33,6 +33,7 @@
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
+import org.richfaces.cdk.generate.java.LibraryModel;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.TagModel;
@@ -46,7 +47,7 @@
public class ListenerTagHandlerGenerator extends FreeMarkerWriter<TagWithModel<EventModel>> implements CdkWriter {
@Inject
- public ListenerTagHandlerGenerator(FreeMarkerRenderer configuration,
+ public ListenerTagHandlerGenerator(@LibraryModel 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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -31,6 +31,7 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.java.LibraryModel;
import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.TagModel;
import org.richfaces.cdk.model.Trackable;
@@ -52,7 +53,7 @@
private final FreeMarkerRenderer configuration;
@Inject
- public TagHandlerClassGenerator(FreeMarkerRenderer configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public TagHandlerClassGenerator(@LibraryModel FreeMarkerRenderer configuration, @Output(Outputs.JAVA_CLASSES) FileManager output) {
this.configuration = configuration;
this.output = output;
}
Deleted: 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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -1,92 +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;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-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;
-
-/**
- * <p class="changed_added_4_0"></p>
- * TODO: injection.
- * @author asmirnov(a)exadel.com
- */
-public class JavaClassConfiguration extends Configuration implements FreeMarkerRenderer {
- private static final String TEMPLATES = "/META-INF/templates/java";
-
- public JavaClassConfiguration() {
-
- // TODO set proper template loader.
- setClassForTemplateLoading(this.getClass(), TEMPLATES);
-
- // TODO create an object wrapper for library model.
- setObjectWrapper(new JavaClassModelWrapper());
-
- // Add context variables
-// this.setSharedVariable("context", new BeanModel(context, new BeansWrapper()));
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#writeSnippet(java.lang.String, java.lang.Object, java.io.Writer)
- */
- 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);
-
- rootMap.put("facesContextVariable", RendererClassVisitor.FACES_CONTEXT_VARIABLE);
- rootMap.put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE);
- rootMap.put("responseWriterVariable", RendererClassVisitor.RESPONSE_WRITER_VARIABLE);
- rootMap.put("clientIdVariable", RendererClassVisitor.CLIENT_ID_VARIABLE);
-
- t.process(rootMap, writer);
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#renderSnippet(java.lang.String, java.lang.Object)
- */
- public String renderTemplate(String templateName, Object object) {
- StringWriter writer = new StringWriter();
- try {
- writeTemplate(templateName, object, writer);
-
- return writer.toString();
- } catch (IOException e) {
- // TODO: handle exception
- return e.getMessage();
- } catch (TemplateException e) {
- // TODO: handle exception
- return e.getMessage();
- }
- }
-
-}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -70,7 +70,7 @@
*/
@Inject
public RendererClassGenerator((a)Output(Outputs.JAVA_CLASSES) FileManager output, Logger log,
- TemplateVisitorFactory<RendererClassVisitor> visitorFactory, FreeMarkerRenderer renderer) {
+ TemplateVisitorFactory<RendererClassVisitor> visitorFactory, @TemplateModel FreeMarkerRenderer renderer) {
this.output = output;
this.log = log;
this.visitorFactory = visitorFactory;
@@ -102,12 +102,8 @@
attributes.addAll(renderer.getAttributes());
RendererClassVisitor visitor = visitorFactory.createVisitor(template.getInterface(), attributes);
- try {
- // TODO - put real parameters.
- template.getImplementation().visit(visitor);
- } finally {
- RendererClassVisitor.clearCaches();
- }
+ // TODO - put real parameters.
+ template.getImplementation().visit(visitor);
JavaClass javaClass = visitor.getGeneratedClass();
String fullName = javaClass.getName();
@@ -116,7 +112,7 @@
output.createOutput(fullName.replace('.', '/') + ".java", library.lastModified());
if (null != outFile) {
- this.renderer.writeTemplate("class", javaClass, outFile);
+ this.renderer.writeTemplate("class.ftl", 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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -23,33 +23,20 @@
package org.richfaces.cdk.templatecompiler;
-import static org.richfaces.cdk.templatecompiler.QNameComparator.QNAME_COMPARATOR;
-import static org.richfaces.cdk.util.JavaUtils.getEscapedString;
-import static org.richfaces.cdk.util.JavaUtils.getEscapedStringsArray;
-
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumMap;
import java.util.EnumSet;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.TreeMap;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
import javax.xml.namespace.QName;
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.attributes.Attribute;
-import org.richfaces.cdk.attributes.Element;
-import org.richfaces.cdk.attributes.Schema;
-import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.builder.model.Argument;
import org.richfaces.cdk.templatecompiler.builder.model.JavaAnnotation;
@@ -58,52 +45,43 @@
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
-import org.richfaces.cdk.templatecompiler.builder.model.StatementImpl;
-import org.richfaces.cdk.templatecompiler.el.ELParserUtils;
-import org.richfaces.cdk.templatecompiler.el.ELVisitor;
-import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
-import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
import org.richfaces.cdk.templatecompiler.model.AnyElement;
import org.richfaces.cdk.templatecompiler.model.CdkBodyElement;
import org.richfaces.cdk.templatecompiler.model.CdkCallElement;
+import org.richfaces.cdk.templatecompiler.model.CdkCaseElement;
import org.richfaces.cdk.templatecompiler.model.CdkChooseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkDefaultElement;
import org.richfaces.cdk.templatecompiler.model.CdkForEachElement;
import org.richfaces.cdk.templatecompiler.model.CdkIfElement;
import org.richfaces.cdk.templatecompiler.model.CdkObjectElement;
import org.richfaces.cdk.templatecompiler.model.CdkOtherwiseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkSwitchElement;
import org.richfaces.cdk.templatecompiler.model.CdkWhenElement;
import org.richfaces.cdk.templatecompiler.model.CompositeImplementation;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.templatecompiler.model.TemplateVisitor;
import org.richfaces.cdk.templatecompiler.statements.AttributesStatement;
+import org.richfaces.cdk.templatecompiler.statements.CaseStatement;
import org.richfaces.cdk.templatecompiler.statements.ConstantReturnMethodBodyStatement;
-import org.richfaces.cdk.templatecompiler.statements.ConversionToBooleanMethodBodyStatement;
-import org.richfaces.cdk.templatecompiler.statements.ConversionToStringMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.DefineObjectStatement;
-import org.richfaces.cdk.templatecompiler.statements.EmptinessCheckingMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.EncodeMethodPrefaceStatement;
import org.richfaces.cdk.templatecompiler.statements.EndElementStatement;
-import org.richfaces.cdk.templatecompiler.statements.EqualsCheckingMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.ForEachStatement;
-import org.richfaces.cdk.templatecompiler.statements.HelperJavaMethod;
import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
-import org.richfaces.cdk.templatecompiler.statements.HelperMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.IfElseStatement;
import org.richfaces.cdk.templatecompiler.statements.IfStatement;
import org.richfaces.cdk.templatecompiler.statements.StartElementStatement;
import org.richfaces.cdk.templatecompiler.statements.StatementsContainer;
+import org.richfaces.cdk.templatecompiler.statements.SwitchStatement;
import org.richfaces.cdk.templatecompiler.statements.TemplateStatement;
-import org.richfaces.cdk.templatecompiler.statements.WriteAttributeStatement;
-import org.richfaces.cdk.templatecompiler.statements.WriteAttributesSetStatement;
+import org.richfaces.cdk.templatecompiler.statements.TemplateStatementImpl;
import org.richfaces.cdk.templatecompiler.statements.WriteTextStatement;
import org.richfaces.cdk.util.Strings;
-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;
@@ -146,12 +124,11 @@
*/
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();
+ 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();
/**
*
@@ -245,93 +222,6 @@
return typesFactory.getType(type);
}
- private String createPassThroughAttributeCode(String htmlAttributeName, String componentAttributeName) {
-
- generatedClass.addImport("org.richfaces.renderkit.ComponentAttribute");
-
- StringBuilder sb = new StringBuilder();
- sb.append("new ComponentAttribute(");
-
- sb.append(getEscapedString(htmlAttributeName));
-
- sb.append(")");
-
- String attributeName = htmlAttributeName;
- if (!attributeName.equals(componentAttributeName)) {
- attributeName = componentAttributeName;
-
- sb.append(".setComponentAttributeName(");
- sb.append(getEscapedString(componentAttributeName));
- sb.append(")");
- }
-
- // OPTIMIZATION - use ModelSet with lookup method
- for (PropertyBase property : attributes) {
- if (attributeName.equals(property.getName())) {
- Set<EventName> eventNames = property.getEventNames();
- if (eventNames != null && !eventNames.isEmpty()) {
- sb.append(".setEventNames(");
- sb.append("new String[] {");
- Collection<String> eventNamesStrings =
- Collections2.transform(eventNames, new Function<EventName, String>() {
- @Override
- public String apply(EventName from) {
- return from.getName();
- }
- });
- sb.append(getEscapedStringsArray(eventNamesStrings));
- sb.append("})");
- }
- break;
- }
- }
-
- return sb.toString();
- }
-
- private String createPassThroughField(Map<String, Attribute> htmlAttributesMap) {
- String fieldName = PASS_THROUGH_ATTRIBUTES_FIELD_NAME;
- if (passThroughCounter >= 0) {
- fieldName += "_" + passThroughCounter;
- }
- passThroughCounter++;
-
- // TODO generic arguments
- JavaField passThroughField = new JavaField(Map.class, fieldName);
- passThroughField.addModifier(JavaModifier.PRIVATE);
- passThroughField.addModifier(JavaModifier.STATIC);
- passThroughField.addModifier(JavaModifier.FINAL);
-
- generatedClass.addImport("org.richfaces.renderkit.ComponentAttribute");
- addRendererUtilsImport();
- generatedClass.addImport(Collections.class);
-
- // TODO - get rid of FQNs for classes via imports
- passThroughField.setGenericArguments(new JavaClass[] { new JavaClass(String.class),
- new JavaClass("org.richfaces.renderkit.ComponentAttribute") });
-
- StringBuilder fieldValue = new StringBuilder("Collections.unmodifiableMap(ComponentAttribute.createMap(");
- boolean isFirstArgument = true;
- for (Map.Entry<String, Attribute> entry : htmlAttributesMap.entrySet()) {
- if (isFirstArgument) {
- isFirstArgument = false;
- } else {
- fieldValue.append(", ");
- }
-
- String htmlAttributeName = entry.getKey();
- String componentAttributeName = entry.getValue().getComponentAttributeName();
- fieldValue.append(createPassThroughAttributeCode(htmlAttributeName, componentAttributeName));
- }
-
- fieldValue.append("))");
-
- passThroughField.setValue(new StatementImpl(fieldValue.toString()));
- generatedClass.addField(passThroughField);
-
- return fieldName;
- }
-
private void createMethodContext() {
this.currentStatement = new StatementsContainer();
currentStatement.setVariable(FACES_CONTEXT_VARIABLE, getType(FacesContext.class));
@@ -371,11 +261,6 @@
createMethodContext();
}
- private void defineObject(ELType type, String name, String initializationExpression) {
- addStatement(new DefineObjectStatement(type, name, initializationExpression));
- currentStatement.setVariable(name, type);
- }
-
private void createRendersChildrenMethod() {
Boolean rendersChildren = compositeInterface.getRendersChildren();
if (rendersChildren != null) {
@@ -395,6 +280,12 @@
currentStatement = container;
}
+ protected <T extends StatementsContainer> T pushStatement(Class<T> container) {
+ T statement = createStatement(container);
+ pushStatement(container);
+ return statement;
+ }
+
protected void popStatement() {
currentStatement = currentStatement.getParent();
}
@@ -460,59 +351,59 @@
AttributesStatement attributesStatement = createStatement(AttributesStatement.class);
addStatement(attributesStatement);
attributesStatement.setAttributes(elementAttributes);
-// Set<String> writtenAttributes = new HashSet<String>();
-// boolean shouldEncodePassThrough = false;
-// String[] passThroughExclusions = null;
-//
-// Map<QName, Object> sortedElementAttributes = new TreeMap<QName, Object>(QNAME_COMPARATOR);
-// sortedElementAttributes.putAll(elementAttributes);
-//
-// for (Map.Entry<QName, Object> attribute : sortedElementAttributes.entrySet()) {
-// QName attributeName = attribute.getKey();
-// Object attributeValue = attribute.getValue();
-//
-// if (!isDefaultNamespace(attributeName.getNamespaceURI())) {
-// // TODO: add support
-// if (Template.CDK_NAMESPACE.equals(attributeName.getNamespaceURI())
-// && "passThroughWithExclusions".equals(attributeName.getLocalPart())) {
-//
-// shouldEncodePassThrough = true;
-// if (attributeValue != null) {
-// passThroughExclusions = attributeValue.toString().split("\\s+");
-// }
-// }
-// } else {
-// String attributeLocalName = attributeName.getLocalPart();
-// if (writtenAttributes.add(attributeLocalName)) {
-// addStatement(new WriteAttributeStatement(attributeLocalName, compileEl(
-// attributeValue.toString(), Object.class)));
-// }
-// }
-// }
-//
-// if (shouldEncodePassThrough) {
-// Element attributesElement = attributesSchema.getElements().get(elementName.getLocalPart());
-// if (attributesElement != null) {
-// // make a copy of original set
-// TreeMap<String, Attribute> actualAttributesMap =
-// new TreeMap<String, Attribute>(attributesElement.getAttributes());
-//
-// if (passThroughExclusions != null) {
-// for (String passThroughExclusion : passThroughExclusions) {
-// actualAttributesMap.remove(passThroughExclusion);
-// }
-// }
-//
-// for (String writtenAttribute : writtenAttributes) {
-// actualAttributesMap.remove(writtenAttribute);
-// }
-//
-// if (!actualAttributesMap.isEmpty()) {
-// String passThroughFieldName = createPassThroughField(actualAttributesMap);
-// addStatement(new WriteAttributesSetStatement(passThroughFieldName));
-// }
-// }
-// }
+ // Set<String> writtenAttributes = new HashSet<String>();
+ // boolean shouldEncodePassThrough = false;
+ // String[] passThroughExclusions = null;
+ //
+ // Map<QName, Object> sortedElementAttributes = new TreeMap<QName, Object>(QNAME_COMPARATOR);
+ // sortedElementAttributes.putAll(elementAttributes);
+ //
+ // for (Map.Entry<QName, Object> attribute : sortedElementAttributes.entrySet()) {
+ // QName attributeName = attribute.getKey();
+ // Object attributeValue = attribute.getValue();
+ //
+ // if (!isDefaultNamespace(attributeName.getNamespaceURI())) {
+ // // TODO: add support
+ // if (Template.CDK_NAMESPACE.equals(attributeName.getNamespaceURI())
+ // && "passThroughWithExclusions".equals(attributeName.getLocalPart())) {
+ //
+ // shouldEncodePassThrough = true;
+ // if (attributeValue != null) {
+ // passThroughExclusions = attributeValue.toString().split("\\s+");
+ // }
+ // }
+ // } else {
+ // String attributeLocalName = attributeName.getLocalPart();
+ // if (writtenAttributes.add(attributeLocalName)) {
+ // addStatement(new WriteAttributeStatement(attributeLocalName, compileEl(
+ // attributeValue.toString(), Object.class)));
+ // }
+ // }
+ // }
+ //
+ // if (shouldEncodePassThrough) {
+ // Element attributesElement = attributesSchema.getElements().get(elementName.getLocalPart());
+ // if (attributesElement != null) {
+ // // make a copy of original set
+ // TreeMap<String, Attribute> actualAttributesMap =
+ // new TreeMap<String, Attribute>(attributesElement.getAttributes());
+ //
+ // if (passThroughExclusions != null) {
+ // for (String passThroughExclusion : passThroughExclusions) {
+ // actualAttributesMap.remove(passThroughExclusion);
+ // }
+ // }
+ //
+ // for (String writtenAttribute : writtenAttributes) {
+ // actualAttributesMap.remove(writtenAttribute);
+ // }
+ //
+ // if (!actualAttributesMap.isEmpty()) {
+ // String passThroughFieldName = createPassThroughField(actualAttributesMap);
+ // addStatement(new WriteAttributesSetStatement(passThroughFieldName));
+ // }
+ // }
+ // }
}
/*
@@ -526,8 +417,8 @@
public void endElement(AnyElement anyElement) throws CdkException {
QName elementName = anyElement.getName();
EndElementStatement endElementStatement = createStatement(EndElementStatement.class);
- endElementStatement.setElementName(elementName.getLocalPart());
addStatement(endElementStatement);
+ endElementStatement.setElementName(elementName.getLocalPart());
}
/*
@@ -541,7 +432,9 @@
if (text != null) {
String trimmedText = text.trim();
if (!Strings.isEmpty(trimmedText)) {
- addStatement(new WriteTextStatement(compileEl(trimmedText, String.class)));
+ WriteTextStatement statement = createStatement(WriteTextStatement.class);
+ addStatement(statement);
+ statement.setExpression(trimmedText);
}
}
}
@@ -560,7 +453,7 @@
expression = cdkCallElement.getBodyValue();
}
- addStatement(new StatementImpl(expression + ";"));
+ addStatement(new TemplateStatementImpl(expression + ";"));
}
/*
@@ -572,10 +465,10 @@
@Override
public void startElement(CdkIfElement cdkIfElement) {
- String compiledTestExpression = compileEl(cdkIfElement.getTest(), Boolean.TYPE);
-
- pushStatement(new IfElseStatement());
- pushStatement(new IfStatement(compiledTestExpression));
+ pushStatement(createStatement(IfElseStatement.class));
+ IfStatement ifStatement = createStatement(IfStatement.class);
+ pushStatement(ifStatement);
+ ifStatement.setTest(cdkIfElement.getTest());
}
/*
@@ -600,7 +493,7 @@
@Override
public void startElement(CdkChooseElement cdkChooseElement) {
- pushStatement(new IfElseStatement());
+ pushStatement(createStatement(IfElseStatement.class));
}
/*
@@ -624,9 +517,9 @@
@Override
public void startElement(CdkWhenElement cdkWhenElement) {
- String compiledTestExpression = compileEl(cdkWhenElement.getTest(), Boolean.TYPE);
-
- pushStatement(new IfStatement(compiledTestExpression));
+ IfStatement ifStatement = createStatement(IfStatement.class);
+ pushStatement(ifStatement);
+ ifStatement.setTest(cdkWhenElement.getTest());
}
/*
@@ -650,7 +543,8 @@
@Override
public void startElement(CdkOtherwiseElement cdkOtherwiseElement) {
- pushStatement(new IfStatement(""));
+ IfStatement ifStatement = createStatement(IfStatement.class);
+ pushStatement(ifStatement);
}
/*
@@ -688,30 +582,33 @@
typeString += "<" + typeArgumentsString + ">";
}
- ELType type = null;
- if (!Strings.isEmpty(typeString)) {
- type = TypesFactoryImpl.getType(typeString, typesFactory);
- }
-
- if (!Strings.isEmpty(value)) {
- Class<?> valueType;
- if (type != null) {
- valueType = type.getRawType();
- } else {
- valueType = Object.class;
- }
-
- value = compileEl(value, valueType);
- if (type == null) {
- type = lastCompiledExpressionType;
- }
- }
-
- if (type == null) {
- type = TypesFactory.OBJECT_TYPE;
- }
-
- defineObject(type, name, value);
+ // ELType type = null;
+ // if (!Strings.isEmpty(typeString)) {
+ // type = TypesFactoryImpl.getType(typeString, typesFactory);
+ // }
+ //
+ // if (!Strings.isEmpty(value)) {
+ // Class<?> valueType;
+ // if (type != null) {
+ // valueType = type.getRawType();
+ // } else {
+ // valueType = Object.class;
+ // }
+ //
+ // value = compileEl(value, valueType);
+ // if (type == null) {
+ // type = lastCompiledExpressionType;
+ // }
+ // }
+ //
+ // if (type == null) {
+ // type = TypesFactory.OBJECT_TYPE;
+ // }
+ //
+ // defineObject(type, name, value);
+ DefineObjectStatement statement = createStatement(DefineObjectStatement.class);
+ addStatement(statement);
+ // TODO - set parameters.
}
/*
@@ -724,17 +621,16 @@
@Override
public void startElement(CdkForEachElement cdkForEachElement) {
String items = cdkForEachElement.getItems();
- String itemsExpression = compileEl(items, Iterable.class);
+// String itemsExpression = compileEl(items, Iterable.class);
// TODO - review
- Class<?> collectionElementClass = lastCompiledExpressionType.getContainerType().getRawType();
- if (collectionElementClass == null) {
- collectionElementClass = Object.class;
- }
-
- pushStatement(new ForEachStatement(itemsExpression, cdkForEachElement.getVar(),
- collectionElementClass.getName()));
- currentStatement.setVariable(cdkForEachElement.getVar(), lastCompiledExpressionType.getContainerType());
+ // Class<?> collectionElementClass = lastCompiledExpressionType.getContainerType().getRawType();
+ // if (collectionElementClass == null) {
+ // collectionElementClass = Object.class;
+ // }
+ ForEachStatement forEachStatement = pushStatement(ForEachStatement.class);
+ forEachStatement.setItemsExpression(items);
+ // currentStatement.setVariable(cdkForEachElement.getVar(), lastCompiledExpressionType.getContainerType());
}
/*
@@ -749,6 +645,41 @@
popStatement();
}
+ @Override
+ public void startElement(CdkSwitchElement cdkSwitchElement) {
+ String key = cdkSwitchElement.getKey();
+ // String keyExpression = compileEl(key, Object.class);
+ SwitchStatement switchStatement = createStatement(SwitchStatement.class);
+ pushStatement(switchStatement);
+ switchStatement.setKeyExpression(key);
+ }
+
+ @Override
+ public void endElement(CdkSwitchElement cdkSwitchElement) {
+ popStatement();
+ }
+
+ @Override
+ public void startElement(CdkCaseElement cdkCaseElement) {
+ CaseStatement caseStatement = pushStatement(CaseStatement.class);
+ caseStatement.setValues(cdkCaseElement.getValues());
+ }
+
+ @Override
+ public void endElement(CdkCaseElement cdkCaseElement) {
+ popStatement();
+ }
+
+ @Override
+ public void startElement(CdkDefaultElement cdkDefaultElement) {
+ pushStatement(new CaseStatement());
+ }
+
+ @Override
+ public void endElement(CdkDefaultElement cdkDefaultElement) {
+ popStatement();
+ }
+
/**
*
*/
@@ -765,8 +696,4 @@
createRendersChildrenMethod();
}
- public static void clearCaches() {
- TypesFactoryImpl.clearCaches();
- ELParserUtils.clearCaches();
- }
}
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,16 @@
+package org.richfaces.cdk.templatecompiler;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+@Retention(RUNTIME)
+@Target({ FIELD, PARAMETER, METHOD })
+@BindingAnnotation
+public @interface TemplateModel {
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -24,11 +24,15 @@
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;
+import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.DefaultImports;
+import org.richfaces.cdk.generate.freemarker.FreeMakerUtils;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.TemplatesFolder;
import org.richfaces.cdk.templatecompiler.el.ELParserImpl;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
@@ -36,7 +40,9 @@
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactoryImpl;
-import com.google.inject.PrivateModule;
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.AbstractModule;
+import com.google.inject.PrivateBinder;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
@@ -45,32 +51,41 @@
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 TemplateModule extends PrivateModule {
+public class TemplateModule extends AbstractModule {
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.google.inject.AbstractModule#configure()
*/
@Override
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(new TypeLiteral<TemplateVisitorFactory<RendererClassVisitor>>() {
+ }).to(VisitorFactoryImpl.class).in(Singleton.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);
+ bind(Schema.class).annotatedWith(Names.named(Template.XHTML_EL_NAMESPACE))
+ .toProvider(XhtmlElSchemaProvider.class).in(Singleton.class);
+ // Private bindings.
+ PrivateBinder privateBinder = binder().newPrivateBinder();
+ privateBinder.bind(FreeMarkerRenderer.class).annotatedWith(TemplateModel.class).to(CdkConfiguration.class);
+ privateBinder.expose(FreeMarkerRenderer.class).annotatedWith(TemplateModel.class);
+ privateBinder.bind(FreeMakerUtils.class);
+ privateBinder.bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
+ privateBinder.bind(new TypeLiteral<Map<String, Object>>() {
+ }).toInstance(RendererClassVisitor.ENCODE_METHOD_VARIABLES);
+ privateBinder.bind(String.class).annotatedWith(TemplatesFolder.class).toInstance("/META-INF/templates/java");
+ privateBinder.bind(new TypeLiteral<Map<String,String>>(){}).annotatedWith(DefaultImports.class).toInstance(ImmutableMap.of("util","util.ftl"));
}
}
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java (from rev 17695, root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "case", namespace = Template.CDK_NAMESPACE)
+public class CdkCaseElement extends ModelFragment {
+
+ @XmlAttribute
+ private String[] values;
+
+ public String[] getValues() {
+ return values;
+ }
+
+ public void setValues(String[] values) {
+ this.values = values;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java (from rev 17695, root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.model;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "default", namespace = Template.CDK_NAMESPACE)
+public class CdkDefaultElement extends ModelFragment {
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java (from rev 17695, root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "switch", namespace = Template.CDK_NAMESPACE)
+public class CdkSwitchElement extends ModelFragment {
+
+ @XmlAttribute
+ private String key;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -22,7 +22,10 @@
CdkChooseElement.class,
CdkWhenElement.class,
CdkOtherwiseElement.class,
- CdkForEachElement.class
+ CdkForEachElement.class,
+ CdkSwitchElement.class,
+ CdkCaseElement.class,
+ CdkDefaultElement.class
})
public class ModelFragment implements LeafModelElement {
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -66,6 +66,18 @@
void endElement(CdkForEachElement cdkForEachElement);
+ void startElement(CdkSwitchElement cdkSwitchElement);
+
+ void endElement(CdkSwitchElement cdkSwitchElement);
+
+ void startElement(CdkCaseElement cdkCaseElement);
+
+ void endElement(CdkCaseElement cdkCaseElement);
+
+ void startElement(CdkDefaultElement cdkDefaultElement);
+
+ void endElement(CdkDefaultElement cdkDefaultElement);
+
void preProcess(CompositeImplementation compositeImplementation);
void postProcess(CompositeImplementation compositeImplementation);
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java (from rev 17695, root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,60 @@
+/*
+ * 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.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Nick Belaevski
+ */
+public class CaseStatement extends FreeMarkerTemplateStatementBase {
+
+ private String[] values;
+
+ public CaseStatement() {
+ this(null);
+ }
+
+ @Inject
+ public CaseStatement(@TemplateModel FreeMarkerRenderer renderer) {
+ super(renderer,"case");
+ }
+
+ public String[] getValues() {
+ return values;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param values the values to set
+ */
+ public void setValues(String[] values) {
+ this.values = values;
+ }
+
+ public boolean isDefault() {
+ return values == null;
+ }
+}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -22,6 +22,7 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
@@ -29,12 +30,12 @@
* @author Nick Belaevski
*
*/
-public class ConstantReturnMethodBodyStatement extends TemplateStatementBase {
+public class ConstantReturnMethodBodyStatement extends FreeMarkerTemplateStatementBase {
private String returnValue;
@Inject
- public ConstantReturnMethodBodyStatement(FreeMarkerRenderer renderer) {
+ public ConstantReturnMethodBodyStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"constant-return");
}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -23,6 +23,7 @@
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
@@ -32,7 +33,7 @@
/**
* @author Nick Belaevski
*/
-public class DefineObjectStatement extends TemplateStatementBase {
+public class DefineObjectStatement extends FreeMarkerTemplateStatementBase {
private ELType type;
@@ -43,7 +44,7 @@
private TypedTemplateStatement initializationStatement;
@Inject
- public DefineObjectStatement(FreeMarkerRenderer renderer, ELParser parser) {
+ public DefineObjectStatement(@TemplateModel FreeMarkerRenderer renderer, ELParser parser) {
super(renderer, "define-object");
this.parser = parser;
}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -27,15 +27,14 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class ElementStatement extends TemplateStatementBase {
+public class ElementStatement extends FreeMarkerTemplateStatementBase {
private String elementName;
- public ElementStatement(FreeMarkerRenderer renderer,String template) {
- super(renderer,template);
+ public ElementStatement(FreeMarkerRenderer renderer, String template) {
+ super(renderer, template);
}
-
/**
* @return the elementName
*/
@@ -44,8 +43,11 @@
}
/**
- * <p class="changed_added_4_0"></p>
- * @param elementName the elementName to set
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param elementName
+ * the elementName to set
*/
public void setElementName(String elementName) {
this.elementName = elementName;
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -22,19 +22,20 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
/**
* @author Nick Belaevski
*/
-public class EncodeMethodPrefaceStatement extends TemplateStatementBase {
+public class EncodeMethodPrefaceStatement extends FreeMarkerTemplateStatementBase {
/**
* @param templateName
*/
@Inject
- public EncodeMethodPrefaceStatement(FreeMarkerRenderer renderer) {
+ public EncodeMethodPrefaceStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"encode-method-preface");
}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -22,6 +22,7 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
@@ -32,7 +33,7 @@
public class EndElementStatement extends ElementStatement {
@Inject
- public EndElementStatement(FreeMarkerRenderer renderer) {
+ public EndElementStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"end-element");
}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -22,13 +22,14 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
/**
* @author Nick Belaevski
*/
-public class ForEachStatement extends TemplateStatementBase {
+public class ForEachStatement extends FreeMarkerTemplateStatementBase {
private String itemsExpression;
@@ -37,7 +38,7 @@
private String varType;
@Inject
- public ForEachStatement(FreeMarkerRenderer renderer) {
+ public ForEachStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"for-each");
}
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java (from rev 17697, 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/FreeMarkerTemplateStatementBase.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,119 @@
+/*
+ * 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 java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+
+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.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 FreeMarkerTemplateStatementBase 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 FreeMarkerTemplateStatementBase(FreeMarkerRenderer renderer, String templateName) {
+ super();
+ this.renderer = renderer;
+ this.templateName = templateName+".ftl";
+ }
+
+
+ @Override
+ public String getCode() {
+ parse();
+ return code;
+ }
+
+ private void parse() {
+ if(!parsed){
+ code = renderer.renderTemplate(templateName, this);
+ parsed = true;
+ }
+ }
+
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ parse();
+ return Iterables.concat(super.getRequiredImports(),imports);
+ }
+
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ parse();
+ return Iterables.concat(super.getRequiredFields(),fields);
+ }
+
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ parse();
+ return Iterables.concat(super.getRequiredMethods(),requiredMethods);
+ }
+
+ protected void addRequiredMethods(HelperMethod... methods) {
+ for (HelperMethod helperMethod : methods) {
+ 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 TemplateStatementImpl(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
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -28,6 +28,7 @@
import org.richfaces.cdk.Generator;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import org.richfaces.cdk.templatecompiler.builder.model.Argument;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
@@ -73,7 +74,7 @@
* @param typesFactory
*/
@Inject
- public void initHelperMethods(FreeMarkerRenderer renderer, TypesFactory typesFactory) {
+ public void initHelperMethods(@TemplateModel FreeMarkerRenderer renderer, TypesFactory typesFactory) {
this.renderer = renderer;
this.typesFactory = typesFactory;
buildHelperMethod(HelperMethod.EMPTINESS_CHECK, false, "emptiness-check-method", "object");
@@ -98,7 +99,7 @@
helperJavaMethod = new JavaMethod(helperMethod.getName(), returnType, arguments);
helperJavaMethod.addModifier(JavaModifier.PRIVATE);
helperJavaMethod.addModifier(JavaModifier.STATIC);
- helperJavaMethod.setMethodBody(new TemplateStatementBase(renderer, templateName));
+ helperJavaMethod.setMethodBody(new FreeMarkerTemplateStatementBase(renderer, templateName));
}
helperMethods.put(helperMethod, helperJavaMethod);
return helperJavaMethod;
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -22,6 +22,7 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
@@ -29,10 +30,10 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class IfElseStatement extends TemplateStatementBase {
+public class IfElseStatement extends FreeMarkerTemplateStatementBase {
@Inject
- public IfElseStatement(FreeMarkerRenderer renderer) {
+ public IfElseStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"if-else");
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java 2010-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -26,8 +26,15 @@
private String test;
- public IfStatement(String test) {
+ public IfStatement() {
super();
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param test the test to set
+ */
+ public void setTest(String test) {
this.test = test;
}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -22,6 +22,7 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
@@ -32,7 +33,7 @@
public class StartElementStatement extends ElementStatement {
@Inject
- public StartElementStatement(FreeMarkerRenderer renderer) {
+ public StartElementStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"start-element");
}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -67,8 +67,20 @@
}
};
- private final List<TemplateStatement> statements = new ArrayList<TemplateStatement>();
+ @SuppressWarnings("serial")
+ private final List<TemplateStatement> statements = new ArrayList<TemplateStatement>() {
+ public boolean add(TemplateStatement e) {
+ e.setParent(StatementsContainer.this);
+ return super.add(e);
+ };
+
+ public void add(int index, TemplateStatement element) {
+ element.setParent(StatementsContainer.this);
+ super.add(index, element);
+ };
+ };
+
private StatementsContainer parent;
private final Map<String, ELType> localVariablesMap = Maps.newHashMap();
@@ -78,12 +90,10 @@
}
public void addStatement(TemplateStatement statement) {
- statement.setParent(this);
getStatements().add(statement);
}
public void addStatement(int index, TemplateStatement statement) {
- statement.setParent(this);
getStatements().add(index, statement);
}
@@ -173,8 +183,9 @@
return concatStatements(HELPER_METHODS_TRANSFORM);
}
- @Override
- public String toString() {
- return getCode();
- }
+// @Override
+// public String toString() {
+// return getCode();
+// }
+
}
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/SwitchStatement.java (from rev 17695, root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/SwitchStatement.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/SwitchStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,55 @@
+/*
+ * 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.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Nick Belaevski
+ */
+public class SwitchStatement extends FreeMarkerTemplateStatementBase {
+
+ private String keyExpression;
+
+ @Inject
+ public SwitchStatement(@TemplateModel FreeMarkerRenderer renderer) {
+ super(renderer,"switch");
+ }
+
+ /**
+ * @return the keyExpression
+ */
+ public String getKeyExpression() {
+ return keyExpression;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param keyExpression the keyExpression to set
+ */
+ public void setKeyExpression(String keyExpression) {
+ this.keyExpression = keyExpression;
+ }
+}
Deleted: 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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -1,120 +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 java.util.EnumSet;
-import java.util.List;
-import java.util.Set;
-
-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 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();
- this.renderer = renderer;
- this.templateName = templateName;
- }
-
-
- @Override
- public String getCode() {
- parse();
- return code;
- }
-
- private void parse() {
- if(!parsed){
- code = renderer.renderTemplate(templateName, this);
- parsed = true;
- }
- }
-
- @Override
- public Iterable<JavaImport> getRequiredImports() {
- parse();
- return Iterables.concat(super.getRequiredImports(),imports);
- }
-
- @Override
- public Iterable<JavaField> getRequiredFields() {
- parse();
- return Iterables.concat(super.getRequiredFields(),fields);
- }
-
- @Override
- public Iterable<HelperMethod> getRequiredMethods() {
- parse();
- return Iterables.concat(super.getRequiredMethods(),requiredMethods);
- }
-
- protected void addRequiredMethods(HelperMethod... methods) {
- for (HelperMethod helperMethod : methods) {
- 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
Added: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,85 @@
+/*
+ * $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.statements;
+
+import java.util.Collections;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TemplateStatementImpl implements TemplateStatement {
+
+ private final String code;
+ private StatementsContainer parent;
+
+ public TemplateStatementImpl(String code) {
+ this.code = code;
+ // TODO Auto-generated constructor stub
+ }
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.builder.model.JavaStatement#getCode()
+ */
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.builder.model.RequireImports#getRequiredImports()
+ */
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return Collections.emptySet();
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.statements.TemplateStatement#getRequiredFields()
+ */
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ return Collections.emptySet();
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.statements.TemplateStatement#getRequiredMethods()
+ */
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ return Collections.emptySet();
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.statements.TemplateStatement#setParent(org.richfaces.cdk.templatecompiler.statements.StatementsContainer)
+ */
+ @Override
+ public void setParent(StatementsContainer parent) {
+ this.parent = parent;
+ }
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -22,13 +22,14 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
/**
* @author Nick Belaevski
*/
-public class WriteAttributeStatement extends TemplateStatementBase {
+public class WriteAttributeStatement extends FreeMarkerTemplateStatementBase {
private String name;
@@ -36,7 +37,7 @@
@Inject
- public WriteAttributeStatement(FreeMarkerRenderer renderer) {
+ public WriteAttributeStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"write-attribute");
}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -24,13 +24,14 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
/**
* @author Nick Belaevski
*/
-public class WriteAttributesSetStatement extends TemplateStatementBase {
+public class WriteAttributesSetStatement extends FreeMarkerTemplateStatementBase {
/**
*
@@ -42,7 +43,7 @@
private String passThroughFieldName;
@Inject
- public WriteAttributesSetStatement(FreeMarkerRenderer renderer) {
+ public WriteAttributesSetStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer, "write-attributes-set");
passThroughFieldName = PASS_THROUGH_ATTRIBUTES_FIELD_NAME + fieldCounter.getAndIncrement();
}
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -24,8 +24,10 @@
import java.util.Collections;
import java.util.List;
+import org.richfaces.cdk.Logger;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
@@ -34,15 +36,17 @@
/**
* @author Nick Belaevski
*/
-public class WriteTextStatement extends TemplateStatementBase {
+public class WriteTextStatement extends FreeMarkerTemplateStatementBase {
private TemplateStatement textStatement;
private final ELParser parser;
+ private final Logger log;
@Inject
- public WriteTextStatement(FreeMarkerRenderer renderer,ELParser parser) {
+ public WriteTextStatement(@TemplateModel FreeMarkerRenderer renderer,ELParser parser, Logger log) {
super(renderer,"write-text");
this.parser = parser;
+ this.log = log;
}
public TemplateStatement getTextStatement() {
@@ -58,9 +62,13 @@
* @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);
+ public void setExpression(String textExpression) {
+ try {
+ textStatement = parser.parse(textExpression,this,TypesFactory.OBJECT_TYPE);
+ textStatement.setParent(this);
+ } catch (ParsingException e) {
+ log.error("Error parsing EL expression", e);
+ }
}
}
Modified: root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-07-02 00:31:47 UTC (rev 17703)
@@ -518,4 +518,30 @@
</xs:choice>
</xs:sequence>
</xs:complexType>
+
+ <xs:element name="switch">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence>
+ <xs:element name="case" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="c:arbitraryContent">
+ <xs:attribute name="values" form="unqualified" use="required" type="xs:NMTOKENS" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:element name="default" minOccurs="0">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="c:arbitraryContent" />
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="key" use="required" form="unqualified" type="elStrictExpression" />
+ </xs:complexType>
+ </xs:element>
</xs:schema>
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl (from rev 17695, root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,12 @@
+<#if modelItem.default>
+ default:
+<#else>
+ <#list modelItem.values as value>
+ case ${value}:
+ </#list>
+</#if>
+ <#list modelItem.statements as subStatement>
+ ${subStatement.code}
+ </#list>
+
+ break;
\ No newline at end of file
Copied: root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl (from rev 17695, root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl)
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,5 @@
+switch (${modelItem.keyExpression}) {
+ <#list modelItem.statements as subStatement>
+ ${subStatement.code}
+ </#list>
+}
\ No newline at end of file
Added: root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,3 @@
+<#macro constant type name><#assign code><#nested></#assign>${addConstant(type,name,code)}</#macro>
+<#macro require name>${addRequiredMethod(name)}</#macro>
+<#macro import name>${addImport(name)}</#macro>
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -6,15 +6,10 @@
import java.io.File;
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;
-import org.apache.maven.model.FileSet;
import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.util.DirectoryScanner;
import org.junit.Test;
/**
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-07-01 19:58:07 UTC (rev 17702)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -59,6 +59,7 @@
@Inject
@As(CdkConfiguration.class)
+ @LibraryModel
protected FreeMarkerRenderer configuration;
@Inject
Added: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,125 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.MockController;
+import org.richfaces.cdk.Stub;
+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.RuntimeImport;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+(a)RunWith(CdkTestRunner.class)
+public class FreeMarkerTemplateStatementTest {
+
+ private static final String FOO_CODE = "private static final String foo;";
+
+ @Mock
+ private FreeMarkerRenderer renderer;
+
+ @Stub
+ private TemplateStatement statement;
+
+ @Stub
+ @Named("second")
+ private TemplateStatement statement1;
+
+ @Inject
+ private MockController controller;
+
+ private FreeMarkerTemplateStatementBase freeMarkerStatement;
+
+ @Before
+ public void setUp() {
+ freeMarkerStatement = new FreeMarkerTemplateStatementBase(renderer, "foo");
+ }
+
+ public void tearDown() {
+ freeMarkerStatement = null;
+ }
+
+ @Test
+ public void testGetCode() {
+ expect(renderer.renderTemplate("foo.ftl", freeMarkerStatement)).andReturn(FOO_CODE);
+ controller.replay();
+ String code = freeMarkerStatement.getCode();
+ controller.verify();
+ assertEquals(FOO_CODE, code);
+ }
+
+ @Test
+ public void testGetRequiredImports() {
+ freeMarkerStatement.addImport("foo.Bar");
+ expect(statement.getRequiredImports()).andStubReturn(
+ Collections.<JavaImport> singleton(new RuntimeImport("foo.baz")));
+ expect(renderer.renderTemplate("foo.ftl", freeMarkerStatement)).andReturn(FOO_CODE);
+ controller.replay();
+ freeMarkerStatement.addStatement(statement);
+ Iterable<JavaImport> requiredImports = freeMarkerStatement.getRequiredImports();
+ assertEquals(2, Iterables.size(requiredImports));
+ controller.verify();
+ }
+
+ @Test
+ public void testGetRequiredFields() {
+ freeMarkerStatement.addConstant("boolean", "foo", FOO_CODE);
+ expect(statement.getRequiredFields()).andStubReturn(
+ Collections.<JavaField> singleton(new JavaField(TypesFactory.INT_TYPE, "bar")));
+ expect(renderer.renderTemplate("foo.ftl", freeMarkerStatement)).andReturn(FOO_CODE);
+ controller.replay();
+ freeMarkerStatement.addStatement(statement);
+ Iterable<JavaField> requiredFields = freeMarkerStatement.getRequiredFields();
+ assertEquals(2, Iterables.size(requiredFields));
+ controller.verify();
+ }
+
+ @Test
+ public void testGetRequiredMethods() {
+ freeMarkerStatement.addRequiredMethod(HelperMethod.EMPTINESS_CHECK.toString());
+ expect(renderer.renderTemplate("foo.ftl", freeMarkerStatement)).andReturn(FOO_CODE);
+ expect(statement.getRequiredMethods()).andStubReturn(
+ Collections.<HelperMethod> singleton(HelperMethod.EQUALS_CHECK));
+ controller.replay();
+ freeMarkerStatement.addStatement(statement);
+ Iterable<HelperMethod> requiredMethods = freeMarkerStatement.getRequiredMethods();
+ assertEquals(2, Iterables.size(requiredMethods));
+ controller.verify();
+ }
+
+ @Test
+ public void testAddConstant() {
+ freeMarkerStatement.addConstant("java.util.List<java.lang.String>", "foo", FOO_CODE);
+ JavaField javaField = Iterables.getOnlyElement(freeMarkerStatement.getRequiredFields());
+ assertEquals("foo", javaField.getName());
+ assertEquals("java.util.List<java.lang.String>", javaField.getType().getCode());
+ assertEquals(FOO_CODE, javaField.getValue().getCode());
+ }
+
+ @Test
+ public void testAddImport() {
+ freeMarkerStatement.addImport("java.util.List");
+ JavaImport javaImport = Iterables.getOnlyElement(freeMarkerStatement.getRequiredImports());
+ assertEquals("java.util.List",javaImport.getName());
+ }
+
+ @Test
+ public void testAddRequiredMethod() {
+ freeMarkerStatement.addRequiredMethod(HelperMethod.EMPTINESS_CHECK.toString());
+ HelperMethod helperMethod = Iterables.getOnlyElement(freeMarkerStatement.getRequiredMethods());
+ assertEquals(HelperMethod.EMPTINESS_CHECK, helperMethod);
+ }
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,101 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.junit.Assert.*;
+
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestBase;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.MockController;
+import org.richfaces.cdk.Stub;
+import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.DefaultImports;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.TemplatesFolder;
+import org.richfaces.cdk.templatecompiler.JavaClassModelWrapper;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.inject.Binder;
+import com.google.inject.Inject;
+import com.google.inject.TypeLiteral;
+
+import freemarker.template.ObjectWrapper;
+
+(a)RunWith(CdkTestRunner.class)
+public class FreeMarkerTemplateStatementTest1 extends CdkTestBase {
+
+ private static final String FOO_CODE = "private static final String foo;";
+
+ @Stub
+ private Logger log;
+
+ @Inject
+ @TemplateModel
+ private FreeMarkerRenderer renderer;
+
+
+
+ @Inject
+ private MockController controller;
+
+
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+ binder.bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
+ binder.bind(FreeMarkerRenderer.class).annotatedWith(TemplateModel.class).to(CdkConfiguration.class);
+ binder.bind(String.class).annotatedWith(TemplatesFolder.class).toInstance("/META-INF/templates/java");
+ binder.bind(new TypeLiteral<Map<String,String>>(){}).annotatedWith(DefaultImports.class).toInstance(ImmutableMap.of("util","util.ftl"));
+ }
+
+ public FreeMarkerTemplateStatementBase setUpStatement(String template) {
+ FreeMarkerTemplateStatementBase freeMarkerStatement = new FreeMarkerTemplateStatementBase(renderer, template);
+ return freeMarkerStatement;
+ }
+
+
+ @Test
+ public void testGetCode() {
+ FreeMarkerTemplateStatementBase statement = setUpStatement("foo");
+ controller.replay();
+ String code = statement.getCode();
+ controller.verify();
+ assertEquals(FOO_CODE, code);
+ }
+
+ @Test
+ public void testAddConstant() {
+ FreeMarkerTemplateStatementBase statement = setUpStatement("addConstant");
+ JavaField javaField = Iterables.getOnlyElement(statement.getRequiredFields());
+ assertEquals("foo", javaField.getName());
+ assertEquals("List<String>", javaField.getType().getCode());
+ assertNotNull(javaField.getValue());
+ assertEquals(FOO_CODE, javaField.getValue().getCode());
+ assertEquals("",statement.getCode());
+ }
+
+ @Test
+ public void testAddImport() {
+ FreeMarkerTemplateStatementBase statement = setUpStatement("addImport");
+ JavaImport javaImport = Iterables.getOnlyElement(statement.getRequiredImports());
+ assertEquals("java.util.List",javaImport.getName());
+ assertEquals("",statement.getCode());
+ }
+
+ @Test
+ public void testAddRequiredMethod() {
+ FreeMarkerTemplateStatementBase statement = setUpStatement("addMethod");
+ HelperMethod helperMethod = Iterables.getOnlyElement(statement.getRequiredMethods());
+ assertEquals(HelperMethod.EMPTINESS_CHECK, helperMethod);
+ assertEquals("",statement.getCode());
+ }
+
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1,140 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestBase;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.MockController;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.internal.ImmutableSet;
+import com.google.inject.name.Named;
+
+(a)RunWith(CdkTestRunner.class)
+public class StatatementsContainerTest extends CdkTestBase {
+
+ @Mock
+ private TemplateStatement statement;
+
+ @Mock
+ @Named("second")
+ private TemplateStatement statement1;
+
+ @Mock
+ private JavaImport import1;
+ @Mock
+ @Named("second")
+ private JavaImport import2;
+ @Mock
+ @Named("third")
+ private JavaImport import3;
+
+ @Inject
+ private MockController controller;
+
+ @Inject
+ private StatementsContainer container;
+
+ @Test
+ public void addStatement() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+ controller.replay();
+ container.addStatement(statement);
+ controller.verify();
+ assertSame(statement, container.getStatements().get(0));
+ }
+
+ @Test
+ public void addStatement1() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+ controller.replay();
+ container.getStatements().add(statement);
+ controller.verify();
+ assertSame(statement, container.getStatements().get(0));
+ }
+
+ @Test
+ public void addStatement2() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+ statement1.setParent(container);
+ expectLastCall();
+ controller.replay();
+ container.addStatement(statement);
+ container.addStatement(statement1);
+ controller.verify();
+ assertEquals(2, container.getStatements().size());
+ assertSame(statement, container.getStatements().get(0));
+ }
+
+ @Test
+ public void getImports() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+ expect(statement.getRequiredImports()).andReturn(Collections.singleton(import1));
+ statement1.setParent(container);
+ expectLastCall();
+ expect(statement1.getRequiredImports()).andReturn(ImmutableSet.of(import2, import3));
+ controller.replay();
+ container.addStatement(statement);
+ container.addStatement(statement1);
+ JavaImport[] javaImports = Iterables.toArray(container.getRequiredImports(), JavaImport.class);
+ controller.verify();
+ assertEquals(3, javaImports.length);
+ assertSame(import1, javaImports[0]);
+ }
+
+ @Test
+ public void getCode() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+ expect(statement.getCode()).andReturn("first ");
+ statement1.setParent(container);
+ expectLastCall();
+ expect(statement1.getCode()).andReturn("second");
+ controller.replay();
+ container.addStatement(statement);
+ container.addStatement(statement1);
+ String code = container.getCode();
+ controller.verify();
+ assertTrue(code.contains("first"));
+ assertTrue(code.contains("second"));
+ }
+
+ @Test
+ public void testVariables() throws Exception {
+ StatementsContainer parent = new StatementsContainer();
+ parent.addStatement(container);
+ parent.setVariable("foo", TypesFactory.OBJECT_TYPE);
+ assertTrue(container.isDefined("foo"));
+ }
+
+ @Test
+ public void testVariables1() throws Exception {
+ StatementsContainer parent = new StatementsContainer();
+ parent.addStatement(container);
+ container.setVariable("foo", TypesFactory.OBJECT_TYPE);
+ assertFalse(parent.isDefined("foo"));
+ }
+
+ @Test
+ public void testVariables2() throws Exception {
+ StatementsContainer parent = new StatementsContainer();
+ parent.addStatement(container);
+ parent.setVariable("foo", TypesFactory.OBJECT_TYPE);
+ container.setVariable("foo", TypesFactory.INTEGER_TYPE);
+ assertTrue(container.isDefined("foo"));
+ assertEquals(TypesFactory.INTEGER_TYPE, container.getVariable("foo"));
+ }
+}
Property changes on: root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addConstant.ftl
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addConstant.ftl (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addConstant.ftl 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1 @@
+<@util.constant "List<String>" "foo">private static final String foo;</(a)util.constant>
\ No newline at end of file
Added: root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addImport.ftl
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addImport.ftl (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addImport.ftl 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1 @@
+<@util.import "java.util.List" />
\ No newline at end of file
Added: root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addMethod.ftl
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addMethod.ftl (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addMethod.ftl 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1 @@
+<@util.require "EMPTINESS_CHECK"/>
\ No newline at end of file
Added: root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/foo.ftl
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/foo.ftl (rev 0)
+++ root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/foo.ftl 2010-07-02 00:31:47 UTC (rev 17703)
@@ -0,0 +1 @@
+private static final String foo;
\ No newline at end of file
14 years, 6 months
JBoss Rich Faces SVN: r17702 - 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-07-01 15:58:07 -0400 (Thu, 01 Jul 2010)
New Revision: 17702
Modified:
root/commons/trunk/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
root/examples/iteration-demo/trunk/src/main/webapp/extendedtable.xhtml
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/html/HtmlExtendedDataTable.java
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js
Log:
RF-8101
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-07-01 19:24:55 UTC (rev 17701)
+++ root/commons/trunk/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-07-01 19:58:07 UTC (rev 17702)
@@ -255,9 +255,8 @@
}
}
- public static void renderAttributeAndBehaviors(FacesContext facesContext, UIComponent component,
- ComponentAttribute componentAttribute) throws IOException {
-
+ public static Object getAttributeAndBehaviorsValue(FacesContext facesContext, UIComponent component,
+ ComponentAttribute componentAttribute) {
if (facesContext == null) {
throw new NullPointerException("facesContext");
}
@@ -270,7 +269,6 @@
throw new NullPointerException("componentAttribute");
}
- String htmlAttributeName = componentAttribute.getHtmlAttributeName();
String componentAttributeName = componentAttribute.getComponentAttributeName();
Object attributeValue = component.getAttributes().get(componentAttributeName);
@@ -293,8 +291,13 @@
}
}
}
+ return attributeValue;
+ }
- renderAttribute(facesContext, htmlAttributeName, attributeValue);
+ public static void renderAttributeAndBehaviors(FacesContext facesContext, UIComponent component,
+ ComponentAttribute componentAttribute) throws IOException {
+ Object attributeValue = getAttributeAndBehaviorsValue(facesContext, component, componentAttribute);
+ renderAttribute(facesContext, componentAttribute.getHtmlAttributeName(), attributeValue);
}
public static void renderPassThroughAttributesOptimized(FacesContext context, UIComponent component,
Modified: root/examples/iteration-demo/trunk/src/main/webapp/extendedtable.xhtml
===================================================================
--- root/examples/iteration-demo/trunk/src/main/webapp/extendedtable.xhtml 2010-07-01 19:24:55 UTC (rev 17701)
+++ root/examples/iteration-demo/trunk/src/main/webapp/extendedtable.xhtml 2010-07-01 19:58:07 UTC (rev 17702)
@@ -79,8 +79,9 @@
value="#{dataBean.state ? dataBean.employeeList : null}" var="record" noDataLabel="There isn't data."
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">
+ onbeforeselectionchange="if (document.getElementById('selectionLocker').checked) {event.preventDefault(); return false;}">
+ <f:ajax render=":form1:selectionOutput" />
+ <f:facet name="header">
<h:outputText value="Current date: #{dataBean.date}"/>
</f:facet>
<f:facet name="footer">
@@ -100,6 +101,9 @@
</f:facet>
</c:if>
</rich:column>
+ <rich:column>
+ <textarea cols="5" rows="5"/>
+ </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"/>
Modified: root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/html/HtmlExtendedDataTable.java
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/html/HtmlExtendedDataTable.java 2010-07-01 19:24:55 UTC (rev 17701)
+++ root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/component/html/HtmlExtendedDataTable.java 2010-07-01 19:58:07 UTC (rev 17702)
@@ -21,12 +21,21 @@
*/
package org.richfaces.component.html;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.faces.component.behavior.ClientBehaviorHolder;
+
import org.richfaces.component.UIExtendedDataTable;
-public class HtmlExtendedDataTable extends UIExtendedDataTable {
+public class HtmlExtendedDataTable extends UIExtendedDataTable implements ClientBehaviorHolder {
public static final String COMPONENT_TYPE = "org.richfaces.ExtendedDataTable";
+ private static final Collection<String> EVENT_NAMES = Collections.unmodifiableCollection(Arrays.asList(
+ "selectionchange", "beforeselectionchange"));
+
private static enum PropertyKeys {
style, styleClass, frozenColumns
}
@@ -58,4 +67,12 @@
public void setFrozenColumns(Integer frozenColumns) {
getStateHelper().put(PropertyKeys.frozenColumns, frozenColumns);
}
+
+ public Collection<String> getEventNames() {
+ return EVENT_NAMES;
+ }
+
+ public String getDefaultEventName() {
+ return "selectionchange";
+ }
}
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-07-01 19:24:55 UTC (rev 17701)
+++ root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-07-01 19:58:07 UTC (rev 17702)
@@ -28,6 +28,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -205,6 +206,11 @@
}
+ private static final Map<java.lang.String, org.richfaces.renderkit.ComponentAttribute> EVENT_ATTRIBUTES = Collections
+ .unmodifiableMap(ComponentAttribute.createMap(new ComponentAttribute("onselectionchange")
+ .setEventNames(new String[] {"selectionchange"}), new ComponentAttribute("onbeforeselectionchange")
+ .setEventNames(new String[] {"beforeselectionchange"})));
+
private void encodeEmptyFooterCell(FacesContext context, ResponseWriter writer, UIComponent column)
throws IOException {
if (column.isRendered()) {
@@ -643,10 +649,10 @@
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);
+ utils.addToScriptHash(options, "onbeforeselectionchange", RenderKitUtils.getAttributeAndBehaviorsValue(context,
+ component, EVENT_ATTRIBUTES.get("onbeforeselectionchange")), null, ScriptHashVariableWrapper.EVENT_HANDLER);
+ utils.addToScriptHash(options, "onselectionchange", RenderKitUtils.getAttributeAndBehaviorsValue(context,
+ component, EVENT_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(";}");
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-07-01 19:24:55 UTC (rev 17701)
+++ root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js 2010-07-01 19:58:07 UTC (rev 17702)
@@ -498,7 +498,7 @@
}
var onbeforeselectionchange = function (event) {
- return !options.onbeforeselectionchange || options.onbeforeselectionchange(event) !== false;
+ return !options.onbeforeselectionchange || options.onbeforeselectionchange.call(element, event) !== false;
}
var onselectionchange = function (event, index, changed) {
@@ -511,7 +511,7 @@
if (changed) {
writeSelection();
if (options.onselectionchange) {
- options.onselectionchange(event);
+ options.onselectionchange.call(element, event);
}
}
}
@@ -555,7 +555,7 @@
selectRows([0, rows]);
selectionFlag = "a";
onselectionchange(event, activeIndex, true); //TODO Is there a way to know that selection haven't changed?
- return false;
+ event.preventDefault();
}
if (typeof activeIndex == "number") {
var index;
@@ -574,7 +574,7 @@
setActiveRow(index);
//showRow
onselectionchange(event, index, changed);
- return false;
+ event.preventDefault();
}
}
}
14 years, 6 months
JBoss Rich Faces SVN: r17701 - in root: examples/iteration-demo/trunk/src/main/webapp and 20 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-01 15:24:55 -0400 (Thu, 01 Jul 2010)
New Revision: 17701
Added:
root/examples/iteration-demo/trunk/src/main/java/org/richfaces/demo/ListBean.java
root/examples/iteration-demo/trunk/src/main/webapp/list.xhtml
root/ui/iteration/trunk/lists/
root/ui/iteration/trunk/lists/api/
root/ui/iteration/trunk/lists/api/src/
root/ui/iteration/trunk/lists/api/src/main/
root/ui/iteration/trunk/lists/api/src/main/java/
root/ui/iteration/trunk/lists/api/src/main/java/org/
root/ui/iteration/trunk/lists/api/src/main/java/org/richfaces/
root/ui/iteration/trunk/lists/api/src/main/java/org/richfaces/component/
root/ui/iteration/trunk/lists/api/src/main/java/org/richfaces/component/ListType.java
root/ui/iteration/trunk/lists/pom.xml
root/ui/iteration/trunk/lists/ui/
root/ui/iteration/trunk/lists/ui/pom.xml
root/ui/iteration/trunk/lists/ui/src/
root/ui/iteration/trunk/lists/ui/src/main/
root/ui/iteration/trunk/lists/ui/src/main/java/
root/ui/iteration/trunk/lists/ui/src/main/java/org/
root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/
root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/component/
root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/component/AbstractList.java
root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/renderkit/
root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/renderkit/ListRendererBase.java
root/ui/iteration/trunk/lists/ui/src/main/templates/
root/ui/iteration/trunk/lists/ui/src/main/templates/list.template.xml
Modified:
root/examples/iteration-demo/trunk/src/main/webapp/index.xhtml
root/ui/iteration/trunk/dist/richfaces-ui-iteration-api/pom.xml
root/ui/iteration/trunk/dist/richfaces-ui-iteration-ui/pom.xml
root/ui/iteration/trunk/pom.xml
Log:
https://jira.jboss.org/browse/RF-8753
Added: root/examples/iteration-demo/trunk/src/main/java/org/richfaces/demo/ListBean.java
===================================================================
--- root/examples/iteration-demo/trunk/src/main/java/org/richfaces/demo/ListBean.java (rev 0)
+++ root/examples/iteration-demo/trunk/src/main/java/org/richfaces/demo/ListBean.java 2010-07-01 19:24:55 UTC (rev 17701)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.demo;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+
+import org.richfaces.component.ListType;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@ManagedBean
+@SessionScoped
+public class ListBean {
+
+ private String listType = ListType.unordered.name();
+
+ public String getListType() {
+ return listType;
+ }
+
+ public void setListType(String listType) {
+ this.listType = listType;
+ }
+}
Modified: root/examples/iteration-demo/trunk/src/main/webapp/index.xhtml
===================================================================
--- root/examples/iteration-demo/trunk/src/main/webapp/index.xhtml 2010-07-01 19:21:53 UTC (rev 17700)
+++ root/examples/iteration-demo/trunk/src/main/webapp/index.xhtml 2010-07-01 19:24:55 UTC (rev 17701)
@@ -11,6 +11,7 @@
<li><h:link outcome="dataTable">rich:DataTable</h:link></li>
<li><h:link outcome="extendedtable">rich:extendedDataTable</h:link></li>
<li><h:link outcome="filteringAndSorting">filtering and sorting feature</h:link></li>
+ <li><h:link outcome="list">rich:list</h:link></li>
</ul>
<h:form>
Added: root/examples/iteration-demo/trunk/src/main/webapp/list.xhtml
===================================================================
--- root/examples/iteration-demo/trunk/src/main/webapp/list.xhtml (rev 0)
+++ root/examples/iteration-demo/trunk/src/main/webapp/list.xhtml 2010-07-01 19:24:55 UTC (rev 17701)
@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:it="http://richfaces.org/iteration">
+<f:view contentType="text/html" />
+
+<h:head>
+ <title>Richfaces List</title>
+</h:head>
+
+<h:body>
+ <h:form>
+ <h:selectOneListbox value="#{listBean.listType}" onchange="submit()">
+ <f:selectItem itemValue="ordered" />
+ <f:selectItem itemValue="unordered" />
+ <f:selectItem itemValue="definitions" />
+ </h:selectOneListbox>
+ </h:form>
+
+ <h:form id="form1">
+ <it:list id="list" var="item" value="#{dataBean.employeeList}" rows="20" type="#{listBean.listType}">
+ <f:facet name="term">
+ #{item.EMail}
+ </f:facet>
+
+ #{item.name}
+ </it:list>
+ </h:form>
+</h:body>
+</html>
Modified: root/ui/iteration/trunk/dist/richfaces-ui-iteration-api/pom.xml
===================================================================
--- root/ui/iteration/trunk/dist/richfaces-ui-iteration-api/pom.xml 2010-07-01 19:21:53 UTC (rev 17700)
+++ root/ui/iteration/trunk/dist/richfaces-ui-iteration-api/pom.xml 2010-07-01 19:24:55 UTC (rev 17701)
@@ -63,6 +63,11 @@
<artifactId>tables-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${assembly.projects.group}</groupId>
+ <artifactId>lists-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- artifacts for javadoc generation -->
<dependency>
Modified: root/ui/iteration/trunk/dist/richfaces-ui-iteration-ui/pom.xml
===================================================================
--- root/ui/iteration/trunk/dist/richfaces-ui-iteration-ui/pom.xml 2010-07-01 19:21:53 UTC (rev 17700)
+++ root/ui/iteration/trunk/dist/richfaces-ui-iteration-ui/pom.xml 2010-07-01 19:24:55 UTC (rev 17701)
@@ -69,6 +69,11 @@
<artifactId>tables-ui</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${assembly.projects.group}</groupId>
+ <artifactId>lists-ui</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- artifacts for javadoc generation -->
<dependency>
Added: root/ui/iteration/trunk/lists/api/src/main/java/org/richfaces/component/ListType.java
===================================================================
--- root/ui/iteration/trunk/lists/api/src/main/java/org/richfaces/component/ListType.java (rev 0)
+++ root/ui/iteration/trunk/lists/api/src/main/java/org/richfaces/component/ListType.java 2010-07-01 19:24:55 UTC (rev 17701)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.component;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public enum ListType {
+
+ ordered, unordered, definitions
+
+}
Added: root/ui/iteration/trunk/lists/pom.xml
===================================================================
--- root/ui/iteration/trunk/lists/pom.xml (rev 0)
+++ root/ui/iteration/trunk/lists/pom.xml 2010-07-01 19:24:55 UTC (rev 17701)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ JBoss, Home of Professional Open Source Copyright 2010, 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.richfaces.ui.iteration</groupId>
+ <artifactId>richfaces-ui-iteration-parent</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.richfaces.ui.iteration</groupId>
+ <artifactId>lists-aggregator</artifactId>
+ <packaging>pom</packaging>
+ <name>Richfaces UI Components: Lists Aggregator</name>
+
+ <modules>
+ <module>api</module>
+ <module>ui</module>
+ </modules>
+
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/root/ui/iteration/trunk/...</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/root/ui/iteration/trunk/lists</developerConnection>
+ <url>http://fisheye.jboss.org/browse/richfaces</url>
+ </scm>
+</project>
\ No newline at end of file
Added: root/ui/iteration/trunk/lists/ui/pom.xml
===================================================================
--- root/ui/iteration/trunk/lists/ui/pom.xml (rev 0)
+++ root/ui/iteration/trunk/lists/ui/pom.xml 2010-07-01 19:24:55 UTC (rev 17701)
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- JBoss, Home of Professional Open Source Copyright 2010, 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. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.richfaces.ui.iteration</groupId>
+ <artifactId>lists-aggregator</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.richfaces.ui.iteration</groupId>
+ <artifactId>lists-ui</artifactId>
+ <packaging>jar</packaging>
+ <name>Richfaces UI Components: Lists UI</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-cdk-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!-- runtime -->
+ <dependency>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-api</artifactId>
+ </dependency>
+ <dependency>
+ <!-- todo remove this dependency or move to test scope -->
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.richfaces.ui.iteration</groupId>
+ <artifactId>lists-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- JSF with dependencies -->
+ <dependency>
+ <groupId>${jsf2.api.groupid}</groupId>
+ <artifactId>${jsf2.api.artifactid}</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- tests -->
+ <dependency>
+ <groupId>${jsf2.impl.groupid}</groupId>
+ <artifactId>${jsf2.impl.artifactid}</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <!-- todo api? -->
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-test-stage</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>htmlunit-client</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-mock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ </dependencies>
+
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/root/ui/iteration/trunk/...</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/root/ui/iteration/trunk/lis...</developerConnection>
+ <url>http://fisheye.jboss.org/browse/richfaces</url>
+ </scm>
+</project>
\ No newline at end of file
Added: root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/component/AbstractList.java
===================================================================
--- root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/component/AbstractList.java (rev 0)
+++ root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/component/AbstractList.java 2010-07-01 19:24:55 UTC (rev 17701)
@@ -0,0 +1,159 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * 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.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.Facet;
+import org.richfaces.cdk.annotations.JsfComponent;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Maps;
+
+/**
+ * JSF component class
+ *
+ */
+@JsfComponent(type = "org.richfaces.List", family = "org.richfaces.List", facets = @Facet(name = AbstractList.TERM))
+public abstract class AbstractList extends UISequence {
+
+ public static final String TERM = "term";
+
+ private static final Predicate<String> TERM_PREDICATE = new Predicate<String>() {
+
+ public boolean apply(String input) {
+ return TERM.equals(input);
+ }
+ };
+
+ private static final Predicate<String> NON_TERM_PREDICATE = Predicates.not(TERM_PREDICATE);
+
+ private Iterator<UIComponent> getFacetsIterator(Predicate<? super String> namePredicate) {
+ if (getFacetCount() > 0) {
+ return Maps.filterKeys(getFacets(), namePredicate).values().iterator();
+ }
+
+ return Iterators.emptyIterator();
+ }
+
+ protected Iterator<UIComponent> dataChildren() {
+ return Iterators.concat(getChildren().iterator(), getFacetsIterator(TERM_PREDICATE));
+ }
+
+ protected Iterator<UIComponent> fixedChildren() {
+ return getFacetsIterator(NON_TERM_PREDICATE);
+ }
+
+ @Attribute(required = true)
+ public abstract ListType getType();
+
+ public UIComponent getTerm() {
+ return getFacet(TERM);
+ }
+
+ @Attribute(events = @EventName("click"))
+ public abstract String getOnclick();
+
+ @Attribute(events = @EventName("dblclick"))
+ public abstract String getOndblclick();
+
+ @Attribute(events = @EventName("mousedown"))
+ public abstract String getOnmousedown();
+
+ @Attribute(events = @EventName("mouseup"))
+ public abstract String getOnmouseup();
+
+ @Attribute(events = @EventName("mouseover"))
+ public abstract String getOnmouseover();
+
+ @Attribute(events = @EventName("mousemove"))
+ public abstract String getOnmousemove();
+
+ @Attribute(events = @EventName("mouseout"))
+ public abstract String getOnmouseout();
+
+ @Attribute(events = @EventName("keypress"))
+ public abstract String getOnkeypress();
+
+ @Attribute(events = @EventName("keydown"))
+ public abstract String getOnkeydown();
+
+ @Attribute(events = @EventName("keyup"))
+ public abstract String getOnkeyup();
+
+ @Attribute(events = @EventName("rowclick"))
+ public abstract String getOnrowclick();
+
+ @Attribute(events = @EventName("rowdblclick"))
+ public abstract String getOnrowdblclick();
+
+ @Attribute(events = @EventName("rowmousedown"))
+ public abstract String getOnrowmousedown();
+
+ @Attribute(events = @EventName("rowmouseup"))
+ public abstract String getOnrowmouseup();
+
+ @Attribute(events = @EventName("rowmouseover"))
+ public abstract String getOnrowmouseover();
+
+ @Attribute(events = @EventName("rowmousemove"))
+ public abstract String getOnrowmousemove();
+
+ @Attribute(events = @EventName("rowmouseout"))
+ public abstract String getOnrowmouseout();
+
+ @Attribute(events = @EventName("rowkeypress"))
+ public abstract String getOnrowkeypress();
+
+ @Attribute(events = @EventName("rowkeydown"))
+ public abstract String getOnrowkeydown();
+
+ @Attribute(events = @EventName("rowkeyup"))
+ public abstract String getOnrowkeyup();
+
+ @Attribute
+ public abstract String getStyle();
+
+ @Attribute
+ public abstract String getStyleClass();
+
+ @Attribute
+ public abstract String getTitle();
+
+ @Attribute
+ public abstract String getDir();
+
+ @Attribute
+ public abstract String getLang();
+
+ @Attribute
+ public abstract String getRowClasses();
+
+ @Attribute
+ public abstract String getRowClass();
+}
Added: root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/renderkit/ListRendererBase.java
===================================================================
--- root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/renderkit/ListRendererBase.java (rev 0)
+++ root/ui/iteration/trunk/lists/ui/src/main/java/org/richfaces/renderkit/ListRendererBase.java 2010-07-01 19:24:55 UTC (rev 17701)
@@ -0,0 +1,223 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.renderkit;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import org.ajax4jsf.model.DataVisitResult;
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.AbstractList;
+import org.richfaces.component.ListType;
+import org.richfaces.component.UISequence;
+import org.richfaces.component.util.HtmlUtil;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class ListRendererBase extends Renderer {
+
+ private static final Map<String, ComponentAttribute> ROW_HANDLER_ATTRIBUTES = Collections
+ .unmodifiableMap(ComponentAttribute.createMap(
+ new ComponentAttribute(HTML.ONCLICK_ATTRIBUTE).setEventNames("rowclick").
+ setComponentAttributeName("onrowclick"),
+ new ComponentAttribute(HTML.ONDBLCLICK_ATTRIBUTE).setEventNames("rowdblclick").
+ setComponentAttributeName("onrowdblclick"),
+ new ComponentAttribute(HTML.ONMOUSEDOWN_ATTRIBUTE).setEventNames("rowmousedown").
+ setComponentAttributeName("onrowmousedown"),
+ new ComponentAttribute(HTML.ONMOUSEUP_ATTRIBUTE).setEventNames("rowmouseup").
+ setComponentAttributeName("onrowmouseup"),
+ new ComponentAttribute(HTML.ONMOUSEOVER_ATTRIBUTE).setEventNames("rowmouseover").
+ setComponentAttributeName("onrowmouseover"),
+ new ComponentAttribute(HTML.ONMOUSEMOVE_ATTRIBUTE).setEventNames("rowmousemove").
+ setComponentAttributeName("onrowmousemove"),
+ new ComponentAttribute(HTML.ONMOUSEOUT_ATTRIBUTE).setEventNames("rowmouseout").
+ setComponentAttributeName("onrowmouseout"),
+ new ComponentAttribute(HTML.ONKEYPRESS_ATTRIBUTE).setEventNames("rowkeypress").
+ setComponentAttributeName("onrowkeypress"),
+ new ComponentAttribute(HTML.ONKEYDOWN_ATTRIBUTE).setEventNames("rowkeydown").
+ setComponentAttributeName("onrowkeydown"),
+ new ComponentAttribute(HTML.ONKEYUP_ATTRIBUTE).setEventNames("rowkeyup").
+ setComponentAttributeName("onrowkeyup")
+ ));
+
+ private RendererUtils rendererUtils = RendererUtils.getInstance();
+
+ /**
+ * @author Nick Belaevski
+ *
+ */
+ private final class SimpleItemsEncoder extends ItemsEncoder {
+ @Override
+ protected void encodeRow(FacesContext context, UISequence sequence, SequenceRendererHelper helper)
+ throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+
+ writer.startElement(HTML.LI_ELEMENT, sequence);
+
+ if (rendererUtils.hasExplicitId(sequence)) {
+ rendererUtils.writeAttribute(writer, HTML.ID_ATTRIBUTE, sequence.getClientId(context));
+ }
+
+ rendererUtils.writeAttribute(writer, HTML.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses(helper.getRowClass(), helper.getColumnClass(), "rf-ls-i"));
+ renderHandlers(context, sequence);
+ rendererUtils.encodeChildren(context, sequence);
+ writer.endElement(HTML.LI_ELEMENT);
+ }
+
+ public void encodeFakeItem(FacesContext context, UIComponent component) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement(HTML.LI_ELEMENT, component);
+ writer.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none", null);
+ writer.endElement(HTML.LI_ELEMENT);
+ }
+ }
+
+ /**
+ * @author Nick Belaevski
+ *
+ */
+ private final class DefinitionItemsEncoder extends ItemsEncoder {
+ @Override
+ protected void encodeRow(FacesContext context, UISequence sequence, SequenceRendererHelper helper)
+ throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+
+ UIComponent termFacet = sequence.getFacet(AbstractList.TERM);
+ if (termFacet != null && termFacet.isRendered()) {
+ writer.startElement(HTML.DT_ELEMENT, sequence);
+
+ if (rendererUtils.hasExplicitId(sequence)) {
+ rendererUtils.writeAttribute(writer, HTML.ID_ATTRIBUTE, sequence.getClientId(context) + ".dt");
+ }
+
+ rendererUtils.writeAttribute(writer, HTML.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses(helper.getRowClass(), helper.getColumnClass(), "rf-ls-dt"));
+ termFacet.encodeAll(context);
+ writer.endElement(HTML.DT_ELEMENT);
+ }
+
+ writer.startElement(HTML.DD_ELEMENT, sequence);
+
+ if (rendererUtils.hasExplicitId(sequence)) {
+ rendererUtils.writeAttribute(writer, HTML.ID_ATTRIBUTE, sequence.getClientId(context));
+ }
+
+ rendererUtils.writeAttribute(writer, HTML.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses(helper.getRowClass(), helper.getColumnClass(), "rf-ls-dd"));
+ renderHandlers(context, sequence);
+ rendererUtils.encodeChildren(context, sequence);
+ writer.endElement(HTML.DD_ELEMENT);
+ }
+
+ public void encodeFakeItem(FacesContext context, UIComponent component) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement(HTML.DD_ELEMENT, component);
+ writer.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none", null);
+ writer.endElement(HTML.DD_ELEMENT);
+ }
+ }
+
+ private abstract class ItemsEncoder implements DataVisitor {
+
+ protected void renderHandlers(FacesContext context, UISequence sequence) throws IOException {
+ RenderKitUtils.renderPassThroughAttributesOptimized(context, sequence, ROW_HANDLER_ATTRIBUTES);
+ }
+
+ protected abstract void encodeRow(FacesContext context, UISequence sequence, SequenceRendererHelper helper)
+ throws IOException;
+
+ public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
+ SequenceRendererHelper helper = (SequenceRendererHelper) argument;
+ UISequence sequence = helper.getSequence();
+ sequence.setRowKey(context, rowKey);
+ if (sequence.isRowAvailable()) {
+ helper.nextRow();
+
+ try {
+ encodeRow(context, sequence, helper);
+ } catch (IOException e) {
+ throw new FacesException(e.getMessage(), e);
+ }
+
+ return DataVisitResult.CONTINUE;
+ } else {
+ return DataVisitResult.STOP;
+ }
+ }
+
+ public abstract void encodeFakeItem(FacesContext context, UIComponent component) throws IOException;
+
+ }
+
+ private ItemsEncoder simpleItemsEncoder = new SimpleItemsEncoder();
+
+ private ItemsEncoder definitionItemsEncoder = new DefinitionItemsEncoder();
+
+ protected ListType getType(UIComponent component) {
+ ListType type = ((AbstractList) component).getType();
+ if (type == null) {
+ // TODO add component information
+ throw new IllegalArgumentException("Type for rich:list is required!");
+ }
+
+ return type;
+ }
+
+ protected String getStyleClass(UIComponent component) {
+ String styleClass = (String) component.getAttributes().get(HTML.STYLE_CLASS_ATTR);
+ // TODO rf-* classes for different list types
+ return HtmlUtil.concatClasses(styleClass, "rf-ls");
+ }
+
+ protected void encodeListItems(FacesContext context, UIComponent component, boolean isSimpleList)
+ throws IOException {
+ AbstractList list = (AbstractList) component;
+ try {
+ ItemsEncoder itemsEncoder = isSimpleList ? simpleItemsEncoder : definitionItemsEncoder;
+ SequenceRendererHelper rendererHelper = new SequenceRendererHelper(list);
+ list.walk(context, itemsEncoder, rendererHelper);
+
+ if (!rendererHelper.hasWalkedOverRows()) {
+ itemsEncoder.encodeFakeItem(context, component);
+ }
+ } catch (FacesException e) {
+ // TODO nick - review
+ if (e.getCause() instanceof IOException) {
+ throw (IOException) e.getCause();
+ } else {
+ throw e;
+ }
+ }
+ }
+}
Added: root/ui/iteration/trunk/lists/ui/src/main/templates/list.template.xml
===================================================================
--- root/ui/iteration/trunk/lists/ui/src/main/templates/list.template.xml (rev 0)
+++ root/ui/iteration/trunk/lists/ui/src/main/templates/list.template.xml 2010-07-01 19:24:55 UTC (rev 17701)
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root xmlns="http://richfaces.org/cdk/xhtml-el" xmlns:cdk="http://richfaces.org/cdk/core"
+ xmlns:c="http://richfaces.org/cdk/jstl/core" xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+ xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.renderkit.html.ListRenderer</cdk:class>
+ <cdk:superclass>org.richfaces.renderkit.ListRendererBase</cdk:superclass>
+ <cdk:component-family>org.richfaces.List</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.ListRenderer
+ </cdk:renderer-type>
+ <cdk:renders-children>true</cdk:renders-children>
+
+ <!--
+ <cc:attribute name="onclick" type="java.lang.String">
+ <cc:clientBehavior event="click" />
+ </cc:attribute>
+ <cc:attribute name="ondblclick" type="java.lang.String">
+ <cc:clientBehavior event="dblclick" />
+ </cc:attribute>
+ <cc:attribute name="onmousedown" type="java.lang.String">
+ <cc:clientBehavior event="mousedown" />
+ </cc:attribute>
+ <cc:attribute name="onmouseup" type="java.lang.String">
+ <cc:clientBehavior event="mouseup" />
+ </cc:attribute>
+ <cc:attribute name="onmouseover" type="java.lang.String">
+ <cc:clientBehavior event="mouseover" />
+ </cc:attribute>
+ <cc:attribute name="onmousemove" type="java.lang.String">
+ <cc:clientBehavior event="mousemove" />
+ </cc:attribute>
+ <cc:attribute name="onmouseout" type="java.lang.String">
+ <cc:clientBehavior event="mouseout" />
+ </cc:attribute>
+ <cc:attribute name="onkeypress" type="java.lang.String">
+ <cc:clientBehavior event="keypress" />
+ </cc:attribute>
+ <cc:attribute name="onkeydown" type="java.lang.String">
+ <cc:clientBehavior event="keydown" />
+ </cc:attribute>
+ <cc:attribute name="onkeyup" type="java.lang.String">
+ <cc:clientBehavior event="keyup" />
+ </cc:attribute>
+ <cc:attribute name="onrowclick" type="java.lang.String">
+ <cc:clientBehavior event="rowclick" />
+ </cc:attribute>
+ <cc:attribute name="onrowdblclick" type="java.lang.String">
+ <cc:clientBehavior event="rowdblclick" />
+ </cc:attribute>
+ <cc:attribute name="onrowmousedown" type="java.lang.String">
+ <cc:clientBehavior event="rowmousedown" />
+ </cc:attribute>
+ <cc:attribute name="onrowmouseup" type="java.lang.String">
+ <cc:clientBehavior event="rowmouseup" />
+ </cc:attribute>
+ <cc:attribute name="onrowmouseover" type="java.lang.String">
+ <cc:clientBehavior event="rowmouseover" />
+ </cc:attribute>
+ <cc:attribute name="onrowmousemove" type="java.lang.String">
+ <cc:clientBehavior event="rowmousemove" />
+ </cc:attribute>
+ <cc:attribute name="onrowmouseout" type="java.lang.String">
+ <cc:clientBehavior event="rowmouseout" />
+ </cc:attribute>
+ <cc:attribute name="onrowkeypress" type="java.lang.String">
+ <cc:clientBehavior event="rowkeypress" />
+ </cc:attribute>
+ <cc:attribute name="onrowkeydown" type="java.lang.String">
+ <cc:clientBehavior event="rowkeydown" />
+ </cc:attribute>
+ <cc:attribute name="onrowkeyup" type="java.lang.String">
+ <cc:clientBehavior event="rowkeyup" />
+ </cc:attribute>
+ -->
+ </cc:interface>
+
+ <cc:implementation>
+ <cdk:object type="org.richfaces.component.ListType" name="listType" value="#{getType(component)}" />
+ <cdk:object name="styleClass" value="#{getStyleClass(component)}" />
+ <cdk:switch key="#{listType}">
+ <cdk:case values="ordered">
+ <ol id="#{clientId}" class="#{styleClass}" cdk:passThroughWithExclusions="type value">
+ <cdk:call expression="encodeListItems(facesContext, component, true)" />
+ </ol>
+ </cdk:case>
+ <cdk:case values="unordered">
+ <ul id="#{clientId}" class="#{styleClass}" cdk:passThroughWithExclusions="type value">
+ <cdk:call expression="encodeListItems(facesContext, component, true)" />
+ </ul>
+ </cdk:case>
+ <cdk:case values="definitions">
+ <dl id="#{clientId}" class="#{styleClass}" cdk:passThroughWithExclusions="type value">
+ <cdk:call expression="encodeListItems(facesContext, component, false)" />
+ </dl>
+ </cdk:case>
+ </cdk:switch>
+ </cc:implementation>
+
+</cdk:root>
Modified: root/ui/iteration/trunk/pom.xml
===================================================================
--- root/ui/iteration/trunk/pom.xml 2010-07-01 19:21:53 UTC (rev 17700)
+++ root/ui/iteration/trunk/pom.xml 2010-07-01 19:24:55 UTC (rev 17701)
@@ -39,6 +39,7 @@
<module>parent</module>
<module>tables</module>
<module>datascroller</module>
+ <module>lists</module>
<module>dist</module>
</modules>
14 years, 6 months
JBoss Rich Faces SVN: r17700 - in root/core/trunk/impl/src/main/java/org: richfaces/renderkit and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-01 15:21:53 -0400 (Thu, 01 Jul 2010)
New Revision: 17700
Added:
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
Log:
https://jira.jboss.org/browse/RF-8753
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-07-01 19:11:26 UTC (rev 17699)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2010-07-01 19:21:53 UTC (rev 17700)
@@ -44,8 +44,8 @@
import javax.faces.component.UIParameter;
import javax.faces.component.UIViewRoot;
import javax.faces.component.ValueHolder;
+import javax.faces.component.behavior.ClientBehaviorContext.Parameter;
import javax.faces.component.behavior.ClientBehaviorHolder;
-import javax.faces.component.behavior.ClientBehaviorContext.Parameter;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.Converter;
@@ -187,7 +187,7 @@
* @throws IOException
*/
public void encodeCustomId(FacesContext context, UIComponent component) throws IOException {
- if ((component.getId() != null) && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
+ if (hasExplicitId(component)) {
context.getResponseWriter().writeAttribute(HTML.ID_ATTRIBUTE, component.getClientId(context),
HTML.ID_ATTRIBUTE);
}
@@ -1135,6 +1135,18 @@
}
}
+ public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ child.encodeAll(context);
+ }
+ }
+ }
+
+ public boolean hasExplicitId(UIComponent component) {
+ return component.getId() != null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX);
+ }
+
/**
* Common HTML elements and attributes names.
*
@@ -1157,6 +1169,7 @@
public static final String COL_ELEMENT = "col";
public static final String DISABLED_ATTR = "disabled";
public static final String DIV_ELEM = "div";
+ public static final String DD_ELEMENT = "dd";
public static final String DL_ELEMENT = "dl";
public static final String DT_ELEMENT = "dt";
public static final String FORM_ELEMENT = "form";
@@ -1176,7 +1189,10 @@
public static final String TR_ELEMENT = "tr";
public static final String TH_ELEM = "th";
public static final String TITLE_ELEM = "title";
-
+ public static final String UL_ELEMENT = "ul";
+ public static final String OL_ELEMENT = "ol";
+ public static final String LI_ELEMENT = "li";
+
// attributes
public static final String FRAME_ATTRIBUTE = "frame";
public static final String BORDER_ATTRIBUTE = "border";
Added: root/core/trunk/impl/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java (rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/renderkit/SequenceRendererHelper.java 2010-07-01 19:21:53 UTC (rev 17700)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.renderkit;
+
+import org.richfaces.component.UISequence;
+import org.richfaces.component.util.HtmlUtil;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SequenceRendererHelper {
+
+ private UISequence sequence;
+
+ private int rowIndex = -1;
+
+ private int columnIndex = 0;
+
+ private String[] rowClasses = null;
+
+ private String[] columnClasses = null;
+
+ private static String[] splitClassesString(String s) {
+ if (s != null) {
+ return s.split(",");
+ }
+
+ return null;
+ }
+
+ private static String getCorrespondingArrayItem(String[] strings, int idx) {
+ if (strings != null && strings.length > 0) {
+ return strings[idx % strings.length];
+ }
+
+ return null;
+ }
+
+ public SequenceRendererHelper(UISequence sequence) {
+ super();
+ this.sequence = sequence;
+
+ this.rowClasses = splitClassesString((String) sequence.getAttributes().get("rowClasses"));
+ this.columnClasses = splitClassesString((String) sequence.getAttributes().get("columnClasses"));
+ }
+
+ public UISequence getSequence() {
+ return sequence;
+ }
+
+ private void initialize() {
+ rowIndex = sequence.getRowIndex();
+ }
+
+ public void nextRow() {
+ if (rowIndex == -1) {
+ initialize();
+ }
+
+ rowIndex++;
+ columnIndex = 0;
+ }
+
+ public void nextColumn() {
+ columnIndex++;
+ }
+
+ public String getRowClass() {
+ String rowClass = (String) sequence.getAttributes().get("rowClass");
+ return HtmlUtil.concatClasses(getCorrespondingArrayItem(rowClasses, rowIndex), rowClass);
+ }
+
+ public String getColumnClass() {
+ return getCorrespondingArrayItem(columnClasses, columnIndex);
+ }
+
+ public boolean hasWalkedOverRows() {
+ return rowIndex != -1;
+ }
+}
14 years, 6 months
JBoss Rich Faces SVN: r17699 - in root: examples/iteration-demo/trunk and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-01 15:11:26 -0400 (Thu, 01 Jul 2010)
New Revision: 17699
Modified:
root/build/bom/trunk/pom.xml
root/examples/iteration-demo/trunk/pom.xml
Log:
https://jira.jboss.org/browse/RF-8753
Modified: root/build/bom/trunk/pom.xml
===================================================================
--- root/build/bom/trunk/pom.xml 2010-07-01 18:28:45 UTC (rev 17698)
+++ root/build/bom/trunk/pom.xml 2010-07-01 19:11:26 UTC (rev 17699)
@@ -81,7 +81,12 @@
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
-
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>r05</version>
+ </dependency>
+
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
Modified: root/examples/iteration-demo/trunk/pom.xml
===================================================================
--- root/examples/iteration-demo/trunk/pom.xml 2010-07-01 18:28:45 UTC (rev 17698)
+++ root/examples/iteration-demo/trunk/pom.xml 2010-07-01 19:11:26 UTC (rev 17699)
@@ -82,6 +82,12 @@
<groupId>org.richfaces.ui.iteration</groupId>
<artifactId>richfaces-ui-iteration-impl</artifactId>
</dependency>
+
+ <!-- TODO: this should be inherited from richfaces-ui-iteration-ui -->
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
<!-- API implementation for runtime -->
<dependency>
14 years, 6 months
JBoss Rich Faces SVN: r17698 - in root: commons/trunk/api/src/main/java/org/richfaces/renderkit and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-01 14:28:45 -0400 (Thu, 01 Jul 2010)
New Revision: 17698
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/commons/trunk/api/src/main/java/org/richfaces/renderkit/ComponentAttribute.java
Log:
Small commons refactoring
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-01 16:21:37 UTC (rev 17697)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-01 18:28:45 UTC (rev 17698)
@@ -303,7 +303,6 @@
Set<EventName> eventNames = property.getEventNames();
if (eventNames != null && !eventNames.isEmpty()) {
sb.append(".setEventNames(");
- sb.append("new String[] {");
Collection<String> eventNamesStrings = Collections2.transform(eventNames,
new Function<EventName, String>() {
@Override
@@ -312,7 +311,7 @@
}
});
sb.append(getEscapedStringsArray(eventNamesStrings));
- sb.append("})");
+ sb.append(")");
}
break;
}
Modified: root/commons/trunk/api/src/main/java/org/richfaces/renderkit/ComponentAttribute.java
===================================================================
--- root/commons/trunk/api/src/main/java/org/richfaces/renderkit/ComponentAttribute.java 2010-07-01 16:21:37 UTC (rev 17697)
+++ root/commons/trunk/api/src/main/java/org/richfaces/renderkit/ComponentAttribute.java 2010-07-01 18:28:45 UTC (rev 17698)
@@ -88,7 +88,7 @@
* @param eventNames the eventNames to set
* @return
*/
- public ComponentAttribute setEventNames(String[] eventNames) {
+ public ComponentAttribute setEventNames(String... eventNames) {
this.eventNames = eventNames;
return this;
14 years, 6 months
JBoss Rich Faces SVN: r17697 - root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-07-01 12:21:37 -0400 (Thu, 01 Jul 2010)
New Revision: 17697
Modified:
root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js
Log:
RF-8101
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-07-01 16:01:54 UTC (rev 17696)
+++ root/ui/iteration/trunk/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js 2010-07-01 16:21:37 UTC (rev 17697)
@@ -550,12 +550,11 @@
}
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?
- }
+ if (event.ctrlKey && options.selectionMode != "single" && (event.keyCode == 65 || event.keyCode == 97) //Ctrl-A
+ && 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") {
@@ -565,18 +564,16 @@
} 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);
+ if (index != null && 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;
}
}
14 years, 6 months
JBoss Rich Faces SVN: r17696 - root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-07-01 12:01:54 -0400 (Thu, 01 Jul 2010)
New Revision: 17696
Modified:
root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/ClientBehavior.java
Log:
https://jira.jboss.org/browse/RF-8733
Modified: root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2010-07-01 13:15:39 UTC (rev 17695)
+++ root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2010-07-01 16:01:54 UTC (rev 17696)
@@ -22,11 +22,14 @@
package org.ajax4jsf.component.behavior;
+import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
+import java.util.HashSet;
import java.util.Set;
+import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.behavior.ClientBehaviorHint;
import javax.faces.context.FacesContext;
@@ -52,40 +55,30 @@
private static final Set<ClientBehaviorHint> HINTS = Collections.unmodifiableSet(EnumSet
.of(ClientBehaviorHint.SUBMITTING));
-
+
enum PropertyKeys {
data, execute, onbeforedomupdate, onbegin, oncomplete, onerror, onevent, queueId, render,
status, disabled, limitRender, immediate, bypassUpdates
}
-
+
+ private Set<String> execute;
+
+ private Set<String> render;
+
private static final Set<String> ALL_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.ALL);
private static final Set<String> FORM_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.FORM);
private static final Set<String> THIS_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.THIS);
private static final Set<String> REGION_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.REGION);
private static final Set<String> NONE_SINGLETON_SET = Collections.singleton(AjaxRendererUtils.NONE);
-
+
@Override
public void setLiteralAttribute(String name, Object value) {
if (compare(PropertyKeys.data, name)) {
setData(value);
} else if (compare(PropertyKeys.execute, name)) {
- Set<String> set = toSet(name, value);
- if (set != null) {
- setExecute(set);
- } else {
- throw new FacesException(value + " : '" + name
- + "' attribute value must be either a String or a Collection");
- }
-
+ setExecute(toSet(PropertyKeys.execute, value));
} else if (compare(PropertyKeys.render, name)) {
- Set<String> set = toSet(name, value);
- if (set != null) {
- setRender(set);
- } else {
- throw new FacesException(value + " : '" + name
- + "' attribute value must be either a String or a Collection");
- }
-
+ setRender(toSet(PropertyKeys.render, value));
} else if (compare(PropertyKeys.onbeforedomupdate, name)) {
setOnbeforedomupdate((String) value);
} else if (compare(PropertyKeys.onbegin, name)) {
@@ -111,23 +104,38 @@
}
}
- private Set<String> toSet(String propertyName, Object value) {
+ private Set<String> toSet(Serializable propertyName, Object value) {
+
+ Set<String> result = null;
+
if (value instanceof String) {
- String strValue = (String) value;
- if (strValue.indexOf(' ') == -1) {
- return toSingleton(propertyName, strValue);
- }
- return AjaxRendererUtils.asSet(strValue);
+ result = toSingletonSet(propertyName.toString(), (String) value);
}
- return null;
+
+ if (result == null) {
+ result = AjaxRendererUtils.asSet(value);
+ }
+
+ if (result == null) {
+ throw new FacesException(
+ propertyName.toString()
+ + "' attribute value must be Collection, List, array, String, comma-separated String, whitespace-separate String'");
+ }
+
+ return result;
}
-
- private static Set<String> toSingleton(String propertyName, String value) {
- if ((null == value) || (value.length() == 0)) {
+
+ private Set<String> toSingletonSet(String propertyName, String value) {
+
+ if(value == null) {
return null;
}
-
- if (value.charAt(0) == '@') {
+
+ if(value.trim().length() == 0) {
+ return null;
+ }
+
+ if(value.charAt(0) == '@') {
if (AjaxRendererUtils.ALL.equals(value)) {
return ALL_SINGLETON_SET;
} else if (AjaxRendererUtils.FORM.equals(value)) {
@@ -138,9 +146,13 @@
return REGION_SINGLETON_SET;
} else if (AjaxRendererUtils.NONE.equals(value)) {
return NONE_SINGLETON_SET;
+ } else {
+ throw new FacesException(value + " : Invalid id keyword specified for '"
+ + propertyName + "' attribute");
}
}
- return Collections.singleton(value);
+
+ return null;
}
public Object getData() {
@@ -151,21 +163,15 @@
getStateHelper().put(PropertyKeys.data, data);
}
- @SuppressWarnings("unchecked")
public Collection<String> getExecute() {
- Object executeObject = getStateHelper().eval(PropertyKeys.execute);
-
- if (executeObject instanceof Collection<?>) {
- return (Collection<String>) executeObject;
- } else {
- return AjaxRendererUtils.asSet(executeObject);
- }
+ return getCollectionValue(PropertyKeys.execute, execute);
}
public void setExecute(Collection<String> execute) {
- getStateHelper().put(PropertyKeys.execute, execute);
+ this.execute = copyToSet(execute);
+ clearInitialState();
}
-
+
public String getOnbeforedomupdate() {
return (String) getStateHelper().eval(PropertyKeys.onbeforedomupdate);
}
@@ -214,21 +220,15 @@
getStateHelper().put(PropertyKeys.queueId, queueId);
}
- @SuppressWarnings("unchecked")
public Collection<String> getRender() {
- Object renderObject = getStateHelper().eval(PropertyKeys.render);
-
- if (renderObject instanceof Collection<?>) {
- return (Collection<String>) renderObject;
- } else {
- return AjaxRendererUtils.asSet(renderObject);
- }
+ return getCollectionValue(PropertyKeys.render, render);
}
public void setRender(Collection<String> render) {
- getStateHelper().put(PropertyKeys.render, render);
+ this.render = copyToSet(render);
+ clearInitialState();
}
-
+
public String getStatus() {
return (String) getStateHelper().eval(PropertyKeys.status);
}
@@ -295,4 +295,93 @@
super.broadcast(event);
}
+
+ private Object saveSet(Serializable propertyName, Set<String> set) {
+ if ((set == null) || set.isEmpty()) {
+ return null;
+ }
+
+ int size = set.size();
+
+ if (size == 1) {
+ return set.toArray(new String[1])[0];
+ }
+
+ return set.toArray(new String[size]);
+ }
+
+ private Set<String> restoreSet(Serializable propertyName, Object state) {
+ if (state == null) {
+ return null;
+ }
+
+ Set<String> set = toSet(propertyName, state);
+ return set;
+ }
+
+ private Set<String> copyToSet(Collection<String> collection) {
+ return Collections.unmodifiableSet(new HashSet<String>(collection));
+ }
+
+ private Collection<String> getCollectionValue(Serializable propertyName, Collection<String> collection) {
+ if (collection!= null) {
+ return collection;
+ }
+
+ Collection<String> result = null;
+
+ ValueExpression expression = getValueExpression(propertyName.toString());
+ if (expression != null) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Object value = expression.getValue(facesContext.getELContext());
+
+ if (value != null) {
+
+ if (value instanceof Collection) {
+ return (Collection<String>)value;
+ }
+
+ result = toSet(propertyName, value);
+ }
+ }
+ return result == null ? Collections.<String>emptyList() : result;
+ }
+
+ @Override
+ public void restoreState(FacesContext context, Object state) {
+ if (state != null) {
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+
+ if (values.length != 1) {
+ execute = restoreSet(PropertyKeys.execute, values[1]);
+ render = restoreSet(PropertyKeys.render, values[2]);
+
+ clearInitialState();
+ }
+ }
+ }
+
+ @Override
+ public Object saveState(FacesContext context) {
+ Object parentState = super.saveState(context);
+ Object state = null;
+
+ if (initialStateMarked()) {
+
+ if (parentState != null) {
+ state = new Object[] { parentState };
+ }
+
+ } else {
+ Object [] values = new Object[3];
+ values[0] = parentState;
+ values[1] = saveSet(PropertyKeys.execute, execute);
+ values[2] = saveSet(PropertyKeys.render, render);
+
+ state = values;
+ }
+
+ return state;
+ }
}
Modified: root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/ClientBehavior.java
===================================================================
--- root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/ClientBehavior.java 2010-07-01 13:15:39 UTC (rev 17695)
+++ root/ui/core/trunk/ui/src/main/java/org/ajax4jsf/component/behavior/ClientBehavior.java 2010-07-01 16:01:54 UTC (rev 17696)
@@ -45,7 +45,7 @@
private StateHelper behaviorStateHelper = null;
private Map<String, ValueExpression> bindings;
-
+
public StateHelper getStateHelper() {
if (behaviorStateHelper == null) {
behaviorStateHelper = new BehaviorStateHelper(this);
@@ -115,14 +115,15 @@
state = new Object[] { parentState };
}
} else {
+
+ Object savedHelper = null;
+ if(behaviorStateHelper != null) {
+ savedHelper = behaviorStateHelper.saveState(context);
+ }
+
state = new Object[3];
state[0] = parentState;
-
- Object attrs = null;
- if (behaviorStateHelper != null) {
- attrs = behaviorStateHelper.saveState(context);
- }
- state[1] = attrs;
+ state[1] = savedHelper;
state[2] = saveBindings(context, bindings);
}
@@ -134,12 +135,13 @@
if (state != null) {
Object[] stateObject = (Object[]) state;
super.restoreState(context, stateObject[0]);
- if (stateObject.length > 1) {
- if (behaviorStateHelper != null) {
- behaviorStateHelper.restoreState(context, stateObject[1]);
- }
+
+ if (stateObject.length == 3) {
+ getStateHelper().restoreState(context, stateObject[1]);
+ restoreBindings(context, stateObject[2]);
+
+ clearInitialState();
}
- restoreBindings(context, stateObject[2]);
}
}
@@ -188,5 +190,4 @@
}
return retValue;
}
-
}
14 years, 6 months
JBoss Rich Faces SVN: r17695 - in root/cdk/trunk/plugins/generator/src/main: java/org/richfaces/cdk/templatecompiler/model and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-01 09:15:39 -0400 (Thu, 01 Jul 2010)
New Revision: 17695
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
Log:
Added support for cdk:switch/cdk:case/cdk:default elements
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java 2010-07-01 13:15:39 UTC (rev 17695)
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+/**
+ * @author Nick Belaevski
+ */
+public class CaseStatement extends AbstractTemplateMethodBodyStatementsContainer {
+
+ private String[] values;
+
+ public CaseStatement() {
+ this(null);
+ }
+
+ public CaseStatement(String[] values) {
+ super("case");
+ this.values = values;
+ }
+
+ public String[] getValues() {
+ return values;
+ }
+
+ public boolean isDefault() {
+ return values == null;
+ }
+}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-01 07:44:12 UTC (rev 17694)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-01 13:15:39 UTC (rev 17695)
@@ -23,8 +23,9 @@
package org.richfaces.cdk.templatecompiler;
-import static org.richfaces.cdk.templatecompiler.QNameComparator.*;
-import static org.richfaces.cdk.util.JavaUtils.*;
+import static org.richfaces.cdk.templatecompiler.QNameComparator.QNAME_COMPARATOR;
+import static org.richfaces.cdk.util.JavaUtils.getEscapedString;
+import static org.richfaces.cdk.util.JavaUtils.getEscapedStringsArray;
import java.io.IOException;
import java.util.Collection;
@@ -68,11 +69,14 @@
import org.richfaces.cdk.templatecompiler.model.AnyElement;
import org.richfaces.cdk.templatecompiler.model.CdkBodyElement;
import org.richfaces.cdk.templatecompiler.model.CdkCallElement;
+import org.richfaces.cdk.templatecompiler.model.CdkCaseElement;
import org.richfaces.cdk.templatecompiler.model.CdkChooseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkDefaultElement;
import org.richfaces.cdk.templatecompiler.model.CdkForEachElement;
import org.richfaces.cdk.templatecompiler.model.CdkIfElement;
import org.richfaces.cdk.templatecompiler.model.CdkObjectElement;
import org.richfaces.cdk.templatecompiler.model.CdkOtherwiseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkSwitchElement;
import org.richfaces.cdk.templatecompiler.model.CdkWhenElement;
import org.richfaces.cdk.templatecompiler.model.CompositeImplementation;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
@@ -783,6 +787,39 @@
popStatement();
}
+ @Override
+ public void startElement(CdkSwitchElement cdkSwitchElement) {
+ String key = cdkSwitchElement.getKey();
+ String keyExpression = compileEl(key, Object.class);
+
+ pushStatement(new SwitchStatement(keyExpression));
+ }
+
+ @Override
+ public void endElement(CdkSwitchElement cdkSwitchElement) {
+ popStatement();
+ }
+
+ @Override
+ public void startElement(CdkCaseElement cdkCaseElement) {
+ pushStatement(new CaseStatement(cdkCaseElement.getValues()));
+ }
+
+ @Override
+ public void endElement(CdkCaseElement cdkCaseElement) {
+ popStatement();
+ }
+
+ @Override
+ public void startElement(CdkDefaultElement cdkDefaultElement) {
+ pushStatement(new CaseStatement());
+ }
+
+ @Override
+ public void endElement(CdkDefaultElement cdkDefaultElement) {
+ popStatement();
+ }
+
/**
*
*/
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java 2010-07-01 13:15:39 UTC (rev 17695)
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * @author Nick Belaevski
+ */
+public class SwitchStatement extends AbstractTemplateMethodBodyStatementsContainer {
+
+ private String keyExpression;
+
+ public SwitchStatement(String keyExpression) {
+ super("switch");
+ this.keyExpression = keyExpression;
+ }
+
+ /**
+ * @return the keyExpression
+ */
+ public String getKeyExpression() {
+ return keyExpression;
+ }
+}
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java 2010-07-01 13:15:39 UTC (rev 17695)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "case", namespace = Template.CDK_NAMESPACE)
+public class CdkCaseElement extends ModelFragment {
+
+ @XmlAttribute
+ private String[] values;
+
+ public String[] getValues() {
+ return values;
+ }
+
+ public void setValues(String[] values) {
+ this.values = values;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java 2010-07-01 13:15:39 UTC (rev 17695)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.model;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "default", namespace = Template.CDK_NAMESPACE)
+public class CdkDefaultElement extends ModelFragment {
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java 2010-07-01 13:15:39 UTC (rev 17695)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "switch", namespace = Template.CDK_NAMESPACE)
+public class CdkSwitchElement extends ModelFragment {
+
+ @XmlAttribute
+ private String key;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-01 07:44:12 UTC (rev 17694)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-01 13:15:39 UTC (rev 17695)
@@ -22,7 +22,10 @@
CdkChooseElement.class,
CdkWhenElement.class,
CdkOtherwiseElement.class,
- CdkForEachElement.class
+ CdkForEachElement.class,
+ CdkSwitchElement.class,
+ CdkCaseElement.class,
+ CdkDefaultElement.class
})
public class ModelFragment implements LeafModelElement {
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-07-01 07:44:12 UTC (rev 17694)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-07-01 13:15:39 UTC (rev 17695)
@@ -66,6 +66,18 @@
void endElement(CdkForEachElement cdkForEachElement);
+ void startElement(CdkSwitchElement cdkSwitchElement);
+
+ void endElement(CdkSwitchElement cdkSwitchElement);
+
+ void startElement(CdkCaseElement cdkCaseElement);
+
+ void endElement(CdkCaseElement cdkCaseElement);
+
+ void startElement(CdkDefaultElement cdkDefaultElement);
+
+ void endElement(CdkDefaultElement cdkDefaultElement);
+
void preProcess(CompositeImplementation compositeImplementation);
void postProcess(CompositeImplementation compositeImplementation);
Modified: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-07-01 07:44:12 UTC (rev 17694)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-07-01 13:15:39 UTC (rev 17695)
@@ -518,4 +518,30 @@
</xs:choice>
</xs:sequence>
</xs:complexType>
+
+ <xs:element name="switch">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence>
+ <xs:element name="case" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="c:arbitraryContent">
+ <xs:attribute name="values" form="unqualified" use="required" type="xs:NMTOKENS" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:element name="default" minOccurs="0">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="c:arbitraryContent" />
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="key" use="required" form="unqualified" type="elStrictExpression" />
+ </xs:complexType>
+ </xs:element>
</xs:schema>
Added: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl 2010-07-01 13:15:39 UTC (rev 17695)
@@ -0,0 +1,12 @@
+<#if modelItem.default>
+ default:
+<#else>
+ <#list modelItem.values as value>
+ case ${value}:
+ </#list>
+</#if>
+ <#list modelItem.statements as subStatement>
+ ${subStatement.code}
+ </#list>
+
+ break;
\ No newline at end of file
Added: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl 2010-07-01 13:15:39 UTC (rev 17695)
@@ -0,0 +1,5 @@
+switch (${modelItem.keyExpression}) {
+ <#list modelItem.statements as subStatement>
+ ${subStatement.code}
+ </#list>
+}
\ No newline at end of file
14 years, 6 months
JBoss Rich Faces SVN: r17694 - root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-07-01 03:44:12 -0400 (Thu, 01 Jul 2010)
New Revision: 17694
Modified:
root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java
Log:
TODOs for selection renderer commit
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-07-01 03:29:25 UTC (rev 17693)
+++ root/ui/iteration/trunk/tables/ui/src/main/java/org/richfaces/renderkit/SelectionRenderer.java 2010-07-01 07:44:12 UTC (rev 17694)
@@ -45,11 +45,13 @@
private class ClientSelection {
+ //TODO nick - use enum instead of constant
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";
+ //TODO nick - add special class that will express selection range
private int [][] ranges;
private int activeIndex;
private int shiftIndex;
@@ -57,6 +59,7 @@
private int index;
public ClientSelection(String selectionString) {
+ //TODO nick - this code is not readable at all - lacks comments, has lot of arrays operation
String[] strings = selectionString.split("\\|", -1);
String[] rangeStrings = strings[0].split(";");
if (strings[0].length() > 0) {
@@ -122,6 +125,7 @@
protected void encodeSelectionInput(ResponseWriter writer, FacesContext context, UIComponent component)
throws IOException {
writer.startElement(HTML.INPUT_ELEM, component);
+ //TODO nick - selection input id should use constants/be a method
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);
@@ -172,6 +176,7 @@
Collection<Object> selectedRowKeys = table.getSelectedRowKeys();
if (selectedRowKeys == null) {
selectedRowKeys = new HashSet<Object>();
+ //TODO nick - model updates should not happen on the 2nd phase
updateAttribute(context, component, "selectedRowKeys", selectedRowKeys);
}
final Collection<Object> rowKeys = selectedRowKeys;
14 years, 6 months