微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在GWT中将自定义HTML元素注册为窗口小部件

嗨大家有没有人知道如何将自定义html元素注册为GWT小部件uiBinder并直接使用它们代替在 HTMLPanel中使用.

对于例如如果我在mgwt项目中使用Google Polymer我正在使用自定义html元素

<g:HTMLPanel >
                    <paper-shadow class="{style.card}">
                        <mgwt:touch.TouchPanel ui:field="touchPanel">
                            <mgwt:panel.flex.FlexPanel orientation="VERTICAL" alignment="CENTER">
                                <g:Image url="{global.getDirection.getSafeUri.asstring}" />
                                <g:HTMLPanel>Take me to Deal</g:HTMLPanel>
                            </mgwt:panel.flex.FlexPanel>
                        </mgwt:touch.TouchPanel>
                    </paper-shadow>
                </g:HTMLPanel>

我想注册/创建纸质阴影作为自定义小部件,以便我可以编写代码,以便它容易handel事件

<polymer:paper-shadow class="{style.card}">
                    <mgwt:touch.TouchPanel ui:field="touchPanel">
                        <mgwt:panel.flex.FlexPanel orientation="VERTICAL" alignment="CENTER">
                            <g:Image url="{global.getDirection.getSafeUri.asstring}" />
                            <g:HTMLPanel>Take me to Deal</g:HTMLPanel>
                        </mgwt:panel.flex.FlexPanel>
                    </mgwt:touch.TouchPanel>
                <polymer:paper-shadow>

解决方法

据我所知,你不能轻易添加UiBinder会理解的新自定义元素.但是,您可以添加一个your custom widget.

您会注意到GWT允许这些自定义元素的自定义属性,如DockLayoutPanel

<g:DockLayoutPanel unit='EM'>
  <g:north size='5'>
    <g:Label>Top</g:Label>
  </g:north>
  <g:center>
    <g:Label>Body</g:Label>
  </g:center>
  <g:west size='192'>
    <g:HTML>
      <ul>
        <li>Sidebar</li>
        <li>Sidebar</li>
        <li>Sidebar</li>
      </ul>
    </g:HTML>
  </g:west>
</g:DockLayoutPanel>

注意< g:north size ='5'> element – 如果你查看DockLayoutPanel的源代码,你会发现它是由这个方法处理的:

public void addnorth(Widget widget,double size) {
    insert(widget,Direction.norTH,size,null);
}

没有@UiChild注释和额外的参数意味着在场景背后发生了“神奇”的事情.确实如此,有一个DockLayoutPanelParser类来处理这种特殊情况.您会注意到它实现了ElementParser – 不幸的是,it’s not possible to “plug in” your own ElementParser.

一个项目,gwt-customuibinder,试图回避这个限制,但它已被弃用为较新的(2.5?)版本的GWT:

Please note that with the newer releases of GWT,this project is Now deprecated as many of the techniques used to add custom element parsers to UiBinder are Now not possible.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐