As far as I know, you cannot easily add a new custom element that UiBinder will understand. However, you can add it to your custom widget .
You will notice that GWT allows you to configure attributes for these custom elements, for example, 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>
Pay attention to the <g:north size='5'> element - if you look at the source code of the DockLayoutPanel , you will see that it is processed using this method:
public void addNorth(Widget widget, double size) { insert(widget, Direction.NORTH, size, null); }
There is no @UiChild annotation, and an additional parameter means that something “magic” is happening behind the scene. And indeed, there is a DockLayoutPanelParser class that handles this special case. You will notice that it implements ElementParser - unfortunately, it is not possible to “plug in” your own ElementParser .
There was a gwt-customuibinder project that tried to circumvent this limitation, but it was deprecated for newer versions (2.5+?) Of GWT:
Please note that with the new versions of GWT this project is now deprecated, since many of the methods used to add custom item parsers to UiBinder are no longer possible.
Igor Klimer
source share