加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

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

发布时间:2020-12-14 18:39:10 所属栏目:资源 来源:网络整理
导读:嗨大家有没有人知道如何将自定义html元素注册为GWT小部件uiBinder并直接使用它们代替在 HTMLPanel中使用. 对于例如如果我在mgwt项目中使用Google Polymer我正在使用自定义html元素 g:HTMLPanel paper-shadow class="{style.card}" mgwt:touch.TouchPanel ui:
嗨大家有没有人知道如何将自定义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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读