how can I register custom element parsers in UiBinder?
Sofar I use a patched UiBinderWriter.
Maybe you want to have a look at the demos:
http://69.20.122.77/gwt-mosaic/Showcase.html#CwUiBinderFillLayout
http://69.20.122.77/gwt-mosaic/Showcase.html#CwUiBinderBoxLayout
http://69.20.122.77/gwt-mosaic/Showcase.html#CwUiBinderBorderLayout
http://69.20.122.77/gwt-mosaic/Showcase.html#CwUiBinderGridLayout
http://69.20.122.77/gwt-mosaic/Showcase.html#CwUiBinderColumnLayout
http://69.20.122.77/gwt-mosaic/Showcase.html#CwUiBinderRowLayout
http://69.20.122.77/gwt-mosaic/Showcase.html#CwUiBinderFlowLayout
http://69.20.122.77/gwt-mosaic/Showcase.html#CwUiBinderAbsoluteLayout
Thanks,
George.
thanks for the reply.
> A nit: we've tried to keep a convention of using lower case names for XML
> elements that don't correspond to runtime objects, so <l:BoxLayoutData> should
> probably be <l:boxLayoutData>.
OK, I will do the required changes to keep the same convention.
> If you want to get this out the door in the meantime, I'm afraid you'll have
> to copy and paste UiBinderGenerator and UiBinderWriter, and provide some
> gwt.xml magic to let your generator run instead of ours for GWT.create calls
> on UiBinder.class.
I tried to rename UiBinderGenerator and UiBinderWriter but there is a
problem with the
ElementParser.parse(XMLElement elem, String fieldName, JClassType
type, UiBinderWriter writer)
it requires a UiBinderWriter.
Extending UiBinderWriter is also not possible since all register
methods are private.
> Another alternative is to do some classpath cheating. Patch UiBinderWriter
> to register your parsers, and put your version in the Mosaic jar. If your
> users put your jar in the classpath before gwt's, you should be good to go.
Maybe I keep this for simplicity. This is what I do so far.
Can I post a patch for GWT-2.1 as a temporary solution, that allows
registration of custom handlers, until you provide a final API for
UiBinder generator?
Thanks,
George.
How could I stop you? :-)Would you making an issue tracker entry about this and putting the patch there?
yes I still use the ScrollTable and PagingScrollTable. I am thing
about forking them if they do not appear in the main GWT trunk very
soon.
George.
Please have a look at:
http://code.google.com/p/google-web-toolkit/issues/detail?id=4461
the attached patch is the simplest patch I could make. It adds support
for adding custom ElementParser(s) to UiBinder by tagging each widgets
that is using a custom parser with the @ElementParserToUse annotation,
e.g.: for GWT Mosaic's LayoutPanel the code is:
@ElementParserToUse(className =
"org.gwt.mosaic.ui.elementparsers.LayoutPanelParser")
public class LayoutPanel extends AbsolutePanel implements
HasLayoutManager,
HasAnimation {
...
}
----
After applying the patch, the UiBinderWriter.registerParsers() looks
like this:
private void registerParsers() {
// TODO(rjrjr): Allow third-party parsers to register themselves
// automagically
addElementParser("com.google.gwt.dom.client.Element",
"com.google.gwt.uibinder.elementparsers.DomElementParser");
// Register widget parsers.
addWidgetParser("UIObject");
addWidgetParser("HasText");
addWidgetParser("HasHTML");
addWidgetParser("HasWidgets");
addWidgetParser("HTMLPanel");
addWidgetParser("DockPanel");
addWidgetParser("StackPanel");
addWidgetParser("DisclosurePanel");
addWidgetParser("TabPanel");
addWidgetParser("MenuItem");
addWidgetParser("MenuBar");
addWidgetParser("RadioButton");
addWidgetParser("CellPanel");
addWidgetParser("CustomButton");
addWidgetParser("DialogBox");
addWidgetParser("LayoutPanel");
addWidgetParser("DockLayoutPanel");
addWidgetParser("StackLayoutPanel");
addWidgetParser("TabLayoutPanel");
// Register custom widget parsers... (almost automagically)
Collection<OwnerField> uiFields = ownerClass.getUiFields();
if (uiFields == null) {
return;
}
for (OwnerField uiField : uiFields) {
JClassType fieldType = uiField.getType().getRawType().isClass();
String uiClassName = fieldType.getQualifiedSourceName();
if (elementParsers.containsKey(uiClassName)) {
continue;
}
if (fieldType != null
&& fieldType.isAnnotationPresent(ElementParserToUse.class))
{
String parserClassName = fieldType.getAnnotation
(ElementParserToUse.class).className();
if (parserClassName != null && parserClassName.length() > 0) {
addElementParser(uiClassName, parserClassName);
}
}
}
}
Kind Regards,
George.
On Jan 7, 12:04 am, Ray Ryan <rj...@google.com> wrote:
On 09/01/2010, at 3:30 AM, ggeorg <georgopoul...@gmail.com>
wrote:
> --
> http://groups.google.com/group/Google-Web-Toolkit-Contributors
On Jan 8, 11:09 pm, Miroslav Pokorny <miroslav.poko...@gmail.com>
wrote:
> In your ElementParserToUse annontation why not pass the class instead
> of classname which enforces some typesafety.
>
> On 09/01/2010, at 3:30 AM, ggeorg <georgopoulos.georg...@gmail.com>
in your solution parsing of an annotated widget will not be custom
if the widget is not injected into a field, right?
Here's a different idea:
http://cafebab3.blogspot.com/2010/01/non-intrusive-gwt-2-mod-2nd-part.html
Perhaps it is useful for you...
Kind regards
Daniel
I think if you do not inject it into a field, you don't need the custom
parser to be registered at all, but I am not sure about that.
I will check your code later today.
Thanks,
George.
>> if (parserClassName != null&& parserClassName.length()> 0) {