On Tue, Oct 6, 2009 at 5:47 PM, Ray Ryan <rj...@google.com> wrote:
>
> On Tue, Oct 6, 2009 at 8:43 AM, Thomas Broyer <t.bro...@gmail.com> wrote:
>>
>> If I understand correctly how UiBinder works, for widgets, I'd still
>> have to "inject" the ID myself using
>> theWidget.getElement().setId(bundle.a().toString()) ?
>
> That's a very bad idea. You're relying on the widget not to be using id for
> its own purposes, now and in the future.

Is it really different from ensureDebugId?


That being said, I've thought a bit more about it and started reading
the UiBinder code to (try to) understand how it works. An IdResource
as implemented by Bob isn't what I want/need; actually, as I said in
the second part of my second message, the "id resource" would need to
be a distinct instance for each call to createAndBindUi.
It loks like I could do something similar using an <ui:with> and
providing my own IdResource implementation; but one of the goal of my
original proposal was also to reuse the IDs that are created by
UiBinder for its internal HTMLPanel "implementation detail" (UiBinder
mints IDs, but even if I use @UiField InputElement for instance, I
won't have the ID, as UiBinder also generates code that removes the
id="" attribute when injecting a DOM element field; so I'd have to
generate new IDs in my own code; that's just wasted computations...)

I'll try to write a clear and detailed proposal *and* provide a patch.

In the mean time, here's another use case (hopefully self-explanatory,
yet not totally realistic wrt the markup; imagine how many times this
could be instantiated within the same app, IDs need to be unique for
each instance; note that in this case, I could very well use
SpanElement but that'd mean doing getElementById and comparing
element's identity where I could just compare IDs):
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>
  <ui:id-generator type='com.my.app.PanelButtons.MyIdentifiers' />
  <span>
    <span aria-role="button" id="{id.minimize}'
class="{style.minimizeSprite}" />
    <span aria-role="button" id="{id.maximize}'
class="{style.maximizeSprite}" />
    <span aria-role="button" id="{id.close}' class="{style.closeSprite}" />
  </span>
</ui:UiBinder>

class PanelButtons extends Widget {

   interface MyIdentifiers extends IdGenerator {
      String minimize();
      String maximize();
      String close();
   }
   interface MyUiBinder extends UiBinder<SpanElement,PanelButton> { }
   private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

   @UiField MyIdentifiers id;

   public PanelButtons() {
     setElement(uiBinder.createAndBindUi(this));
     sinkEvents(Event.ONCLICK);
   }

   public void onBrowserEvent(Event event) {
      super.onBrowserevent(event);
      if (event.getTypeInt() == Event.ONCLICK) {
         Element target = event.getEventTarget();
         if (target != getElement()) {
            // TODO: check parent nodes until getElement(), à laisOrHasChild()
            String id = target.getId();
            if (this.id.minimize().equals(id)) {
               // minimize clicked
            } else if (this.id.maximize().equals(id)) {
               // maximize clicked
            } else if (this.id.close().equals(id)) {
               // close clicked
            }
         }
      }
   }

   ...
}


-- 
Thomas Broyer
/tɔ.ma.bʁwa.je/

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to