根据模块属性使用不同的UiBinder @UiTemplate文件 [英] Using different UiBinder @UiTemplate files depending on module property

查看:96
本文介绍了根据模块属性使用不同的UiBinder @UiTemplate文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用< replace-with> 标签根据我的GWT模块文件中设置的属性来交换类的不同实现。这很棒 - 我喜欢它。



但是:我的意见与 formfactor =mobile formfactor =desktop是我使用的ui.xml文件 - 即使是java文件也是一样的。所以,类交换是不够的 - 我不想重复Java文件来获得不同的类。



如何使用属性来影响哪些用户界面.xml文件作为UiBinder模板加载?



note :我正在使用一种解决方法来计算模块属性应该在Java中,并在加载相应的ui.xml文件的switch语句中使用该属性。这是不可取的,因为:


  • 代码被复制 - 我必须计算模块文件和Java代码中的属性

  • 每个排列必须编译每个ui.xml文件,以便在运行时选择正确的文件。我希望有一个编译时解决方案。
  • 您自己的生成器,它将提供不同的UI绑定器模板。可能您可以重载 UiBinderGenerator中的deduceTemplateFile()


    I can use <replace-with> tags to swap out different implementations of a class depending on the properties set in my GWT module file. That's great - I love it.

    BUT: all that's different about my views between formfactor="mobile" and formfactor="desktop" are the ui.xml files I use - even the java files are identical. So, class swapping isn't sufficient - I don't want to have to duplicate the Java files to get different classes.

    How can I use properties to affect which ui.xml file is loaded as a UiBinder template?

    note: I'm currently using a workaround that calculates what the module properties should be in Java, and using the property in a switch statement that loads the appropriate ui.xml file. This is undesirable because:

    • Code is duplicated - I have to calculate properties in the module file and in the java code
    • Each permutation must compile every ui.xml file in order for the correct one to be chosen at runtime. I'd prefer a compile-time solution.

    解决方案

    I think, that You must write your own generator which will serve different ui binder templates. Probably you can overload method deduceTemplateFile() in UiBinderGenerator.

    这篇关于根据模块属性使用不同的UiBinder @UiTemplate文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆