[Buix-commits] r879 - in lutinjaxx/trunk: jaxx-core/src/main/java/jaxx/tags jaxx-core/src/main/java/jaxx/tags/swing maven-jaxx-plugin/src/test/java/org/codelutin/jaxx
Author: tchemit Date: 2008-10-02 17:55:51 +0000 (Thu, 02 Oct 2008) New Revision: 879 Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultComponentHandler.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/TabHandler.java lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/I18nTest.java Log: makes i18n work with tabs :) Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultComponentHandler.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultComponentHandler.java 2008-10-02 17:49:08 UTC (rev 878) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultComponentHandler.java 2008-10-02 17:55:51 UTC (rev 879) @@ -203,14 +203,31 @@ } } // ajout du support i18n - if (I18N_ATTRIBUTES.contains(name)) { - if (valueCode.contains("_(") || valueCode.contains(")")) { - compiler.reportWarning("\n\tjaxx supports i18n, no need to add explicit call to I18n._ for attribute '" + name + "' in component '" + id + "'"); + valueCode = addI18nInvocation(id, name, valueCode, compiler); + + return super.getSetPropertyCode(id, name, valueCode, compiler); + } + + /** + * + * @param widgetId the id of the widget + * @param attributeName the name of the attribute + * @param attributeValueCode the value code of the attribute value + * @param compiler the current used compile + * @return the surrender i18n call if attribute name is matchrf the attributeValueCode otherwise + */ + public static String addI18nInvocation(String widgetId, String attributeName, String attributeValueCode, JAXXCompiler compiler) { + if (I18N_ATTRIBUTES.contains(attributeName)) { + if (log.isDebugEnabled()) { + log.debug(" try i18n support for [" + widgetId + ":" + attributeName + "] : " + attributeValueCode); + } + if (attributeValueCode.contains("_(") || attributeValueCode.contains(")")) { + compiler.reportWarning("\n\tjaxx supports i18n, no need to add explicit call to I18n._ for attribute '" + attributeName + "' in component '" + widgetId + "'"); } else { - valueCode = "_(" + valueCode + ")"; + attributeValueCode = "_(" + attributeValueCode + ")"; } } - return super.getSetPropertyCode(id, name, valueCode, compiler); + return attributeValueCode; } Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/TabHandler.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/TabHandler.java 2008-10-02 17:49:08 UTC (rev 878) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/TabHandler.java 2008-10-02 17:55:51 UTC (rev 879) @@ -10,6 +10,7 @@ import jaxx.reflect.ClassDescriptorLoader; import jaxx.runtime.swing.TabInfo; import jaxx.tags.TagHandler; +import jaxx.tags.DefaultComponentHandler; import jaxx.types.TypeManager; import org.w3c.dom.Attr; import org.w3c.dom.Element; @@ -24,6 +25,7 @@ import java.io.IOException; public class TabHandler implements TagHandler { + public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException { compileChildrenFirstPass(tag, compiler); } @@ -56,14 +58,22 @@ TabInfo tabInfo = tabs.tabInfo; String id = tabInfo.getId(); String binding = compiler.processDataBindings(value, ClassDescriptorLoader.getClassDescriptor(Object.class)); - if (binding != null) + if (binding != null) { compiler.registerDataBinding(binding, id + "." + name, id + ".set" + JAXXCompiler.capitalize(name) + "(" + binding + ");"); - else if (name.equals("title")) { - tabInfo.setTitle(value); - compiledTabInfo.appendInitializationCode(id + ".setTitle(" + TypeManager.getJavaCode(value) + ");"); + return; + } + + // add i18n support + String i18nvalue = DefaultComponentHandler.addI18nInvocation(id,name,TypeManager.getJavaCode(value),compiler); + + if (name.equals("title")) { + tabInfo.setTitle(i18nvalue); + compiledTabInfo.appendInitializationCode(id + ".setTitle(" + i18nvalue + ");"); + //compiledTabInfo.appendInitializationCode(id + ".setTitle(" + TypeManager.getJavaCode(value) + ");"); } else if (name.equals("toolTipText")) { - tabInfo.setToolTipText(value); - compiledTabInfo.appendInitializationCode(id + ".setToolTipText(" + TypeManager.getJavaCode(value) + ");"); + tabInfo.setToolTipText(i18nvalue); + compiledTabInfo.appendInitializationCode(id + ".setToolTipText(" + i18nvalue + ");"); + //compiledTabInfo.appendInitializationCode(id + ".setToolTipText(" + TypeManager.getJavaCode(value) + ");"); } else if (name.equals("icon")) { Icon icon = (Icon) TypeManager.convertFromString(value, Icon.class); tabInfo.setIcon(icon); @@ -94,8 +104,9 @@ compiledTabInfo.appendInitializationCode(id + ".setBackground(" + TypeManager.getJavaCode(background) + ");"); } else if (name.equals("id")) { // ignore, already handled - } else + } else { compiler.reportError("The <tab> tag does not support the attribute '" + name + "'"); + } } @@ -105,8 +116,9 @@ Attr attribute = (Attr) children.item(i); String name = attribute.getName(); String value = attribute.getValue(); - if (!name.startsWith("xmlns") && !JAXXCompiler.JAXX_INTERNAL_NAMESPACE.equals(attribute.getNamespaceURI())) + if (!name.startsWith("xmlns") && !JAXXCompiler.JAXX_INTERNAL_NAMESPACE.equals(attribute.getNamespaceURI())) { setAttribute(compiledTabInfo, tabs, name, value, compiler); + } } } @@ -122,8 +134,9 @@ } else if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { String text = ((Text) node).getData().trim(); - if (text.length() > 0) + if (text.length() > 0) { compiler.reportError("tag '" + tag.getLocalName() + "' may not contain text ('" + ((Text) node).getData().trim() + "')"); + } } } } @@ -145,8 +158,9 @@ } else if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) { String text = ((Text) node).getData().trim(); - if (text.length() > 0) + if (text.length() > 0) { compiler.reportError("tag '" + tag.getLocalName() + "' may not contain text ('" + ((Text) node).getData().trim() + "')"); + } } } } Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/I18nTest.java =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/I18nTest.java 2008-10-02 17:49:08 UTC (rev 878) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/I18nTest.java 2008-10-02 17:55:51 UTC (rev 879) @@ -9,21 +9,21 @@ public class I18nTest extends AbstractCompilerTest { - @CompileConfig(packageName = "i18n.text", verbose = true) + @CompileConfig(packageName = "i18n.text", verbose = false) public void testI18nText() throws MojoExecutionException, MojoFailureException, IOException { goal.execute(); assertTrue(true); checkPattern("testId.setText(_(\"test.text\"));"); } - @CompileConfig(packageName = "i18n.title", verbose = true) + @CompileConfig(packageName = "i18n.title", verbose = false) public void testI18nTitle() throws MojoExecutionException, MojoFailureException, IOException { goal.execute(); assertTrue(true); checkPattern("testId.setTitle(_(\"test.title\"));"); } - @CompileConfig(packageName = "i18n.tooltiptext", verbose = true) + @CompileConfig(packageName = "i18n.tooltiptext", verbose = false) public void testI18nToolTipText() throws MojoExecutionException, MojoFailureException, IOException { goal.execute(); assertTrue(true);
participants (1)
-
tchemit@users.labs.libre-entreprise.org