[Buix-commits] r1248 - in jaxx/trunk: jaxx-compiler-api jaxx-compiler-api/src/main/java/jaxx/tags jaxx-example/src/main/java/jaxx/demo maven-jaxx-plugin/src/test/java/org/codelutin/jaxx maven-jaxx-plugin/src/test/resources/testcases maven-jaxx-plugin/src/test/resources/testcases/clientProperty
Author: tchemit Date: 2009-02-25 14:17:29 +0000 (Wed, 25 Feb 2009) New Revision: 1248 Added: jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ClientProperty.xml jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/clientProperty/ jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/clientProperty/TestOne.jaxx Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx jaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java Log: add a mecanism to make possible injection of client properties Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt =================================================================== --- jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-02-25 09:55:48 UTC (rev 1247) +++ jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-02-25 14:17:29 UTC (rev 1248) @@ -1,3 +1,8 @@ +1.3 ??? 200902?? + * 20090225 [chemit] - add a mecanism to make possible injection of client properties + +1.2 letellier 20090225 (release for isis) + 1.1 chemit 20090220 * 20090202 [chemit] - can now generate abstract and generic classes * 20090202 [chemit] - introduce a property validatorFQN in CompilerOptions to specify the validator implementation Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java =================================================================== --- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java 2009-02-25 09:55:48 UTC (rev 1247) +++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultComponentHandler.java 2009-02-25 14:17:29 UTC (rev 1248) @@ -23,11 +23,13 @@ import java.beans.IntrospectionException; import java.io.IOException; import java.lang.reflect.Field; +import org.w3c.dom.Attr; +import org.w3c.dom.NamedNodeMap; public class DefaultComponentHandler extends DefaultObjectHandler { + /** log */ protected static final Log log = LogFactory.getLog(DefaultComponentHandler.class); - private String containerDelegate; public DefaultComponentHandler(ClassDescriptor beanClass) { @@ -83,7 +85,6 @@ closeComponent(compiler.getOpenComponent(), tag, compiler); } - protected void openComponent(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException { String constraints = tag.getAttribute("constraints"); if (constraints != null && constraints.length() > 0) { @@ -197,6 +198,15 @@ @Override public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) { + + if (propertyName.startsWith("_")) { + // client property + if (stringValue.startsWith("{")) { + stringValue = stringValue.substring(1, stringValue.length() - 1); + } + object.appendAdditionCode(object.getJavaCode() + ".putClientProperty(\"" + propertyName.substring(1) + "\", " + stringValue + ");"); + return; + } if ("icon".equals(propertyName)) { if (!(stringValue.startsWith("{") || stringValue.endsWith("}"))) { // this is a customized icon, add the icon creation code @@ -223,6 +233,27 @@ super.setAttribute(object, propertyName, stringValue, inline, compiler); } + @Override + protected void scanAttributesForDependencies(Element tag, JAXXCompiler compiler) { + super.scanAttributesForDependencies(tag, compiler); + // check for clientProperty attributes + //FIXME make this works,... it seems jaxx compiler does not come here ? + //FIXME see the the firstPassHandler in JAXXCompiler ? + NamedNodeMap children = tag.getAttributes(); + for (int i = 0, max = children.getLength(); i < max; i++) { + Attr attr = (Attr) children.item(i); + String name = attr.getName(); + if (!name.startsWith("_")) { + continue; + } + String value = attr.getValue(); + if (value.startsWith("{")) { + compiler.reportWarning(tag, "an clientProperty attribute " + name.substring(1) + " does not required curly value but was : " + value, 0); + } + } + + } + /** * Maps string values onto integers, so that int-valued enumeration properties can be specified by strings. For * example, when passed a key of 'alignment', this method should normally map the values 'left', 'center', and @@ -254,7 +285,6 @@ return super.constantValue(key, value); } - /** * Returns <code>true</code> if this component can contain other components. For children to be * allowed, the component must be a subclass of <code>Container</code> and its <code>JAXXBeanInfo</code> @@ -277,7 +307,6 @@ return container; } - public String getContainerDelegate() { try { init(); Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx =================================================================== --- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx 2009-02-25 09:55:48 UTC (rev 1247) +++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx 2009-02-25 14:17:29 UTC (rev 1248) @@ -21,7 +21,8 @@ protected void accept(ActionEvent e, String suffix) { JButton source = (JButton) e.getSource(); - String msg = "'" + source.getText() + "' clicked - " + suffix; + String clickedMessage = (String) source.getClientProperty("clickedText"); + String msg = "'" + source.getText() + "' clicked - " + suffix + " : " + clickedMessage; ((DefaultListModel)messages.getModel()).addElement(msg); }]]> </script> @@ -36,11 +37,11 @@ <row> <cell weighty='0.5'> <JPanel layout='{new GridLayout(1,3,3,3)}'> - <JButton text='button A' decorator='boxed' + <JButton text='button A' decorator='boxed' _clickedText='"button A was clicked"' onActionPerformed='accept(event, "from button (no layer)")'/> - <JButton text='button B' decorator='boxed' + <JButton text='button B' decorator='boxed' _clickedText='"button B was clicked"' onActionPerformed='accept(event, "from button (no layer)")'/> - <JButton text='button C' decorator='boxed' + <JButton text='button C' decorator='boxed' _clickedText='"button C was clicked"' onActionPerformed='accept(event, "from button (no layer)");'/> </JPanel> </cell> Modified: jaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java =================================================================== --- jaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2009-02-25 09:55:48 UTC (rev 1247) +++ jaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2009-02-25 14:17:29 UTC (rev 1248) @@ -33,6 +33,12 @@ checkPattern(mojo, ".getUIManagerActionIcon(\"myActionIcon.png\")", true); } + public void testClientProperty() throws Exception { + mojo.execute(); + checkPattern(mojo, ".putClientProperty(\"testOne\", \"oneTest\")", true); + checkPattern(mojo, ".putClientProperty(\"testTwo\", \"anotherTest\")", true); + } + public void testSpecialSubclassing() throws Exception { mojo.execute(); assertNumberJaxxFiles(7); @@ -81,6 +87,7 @@ assertNumberJaxxFiles(34); mojo.setLog(new SystemStreamLog() { + @Override public boolean isErrorEnabled() { return false; Added: jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ClientProperty.xml =================================================================== --- jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ClientProperty.xml (rev 0) +++ jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ClientProperty.xml 2009-02-25 14:17:29 UTC (rev 1248) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <build> + <plugins> + <plugin> + <groupId>org.codelutin</groupId> + <artifactId>maven-jaxx-plugin</artifactId> + <configuration> + <src>${basedir}/src/test/resources</src> + <outJava>${basedir}/target/it-generated-sources/java</outJava> + <outResource>${basedir}/target/it-generated-sources/resources</outResource> + <force>true</force> + <addLogger>false</addLogger> + <includes> + <value>**/clientProperty/*.jaxx</value> + </includes> + </configuration> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Added: jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/clientProperty/TestOne.jaxx =================================================================== --- jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/clientProperty/TestOne.jaxx (rev 0) +++ jaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/clientProperty/TestOne.jaxx 2009-02-25 14:17:29 UTC (rev 1248) @@ -0,0 +1,3 @@ +<JPanel id='root'> + <JButton id='boxedButton' _testOne='"oneTest"' _testTwo='{"anotherTest"}'/> +</JPanel>
participants (1)
-
tchemit@users.labs.libre-entreprise.org