Friday, March 13, 2015

Extending DialogBox to include a footer w/ ui:binder

I'm looking at extending the DialogBox widget that allows for a <g:footer> child in the ui:binder template, similar to that of the <g:caption>.

I've has success using a @UiChild annotated method, ie:

UiBinder:

<g:DialogBox2>
 
<g:footer>
   
<g:HTML>
     
<button>Okay</button>
      <button>Cancel</button>
   
</g:HTML>
 
</g:footer>
</g:DialogBox2>

Class:

public class DialogBox2 extends DialboxBox {
 
@UiChild
 
public void addFooter(Widget widget) {
   
Element td = getCellElement(2,1); // corresponds to .dialogBottomCenter
    DOM.appendChild(td, widget.getElement());
  }
}

However the DialogBox widget did not implement <g:caption> like this. They seem to pass the Caption as a argument constructor(?) On this assumption, I copied the inner Caption class renaming it Footer and adding a new constructor with all the possible parameter variants. 

Please see my snippet below - I've excluded the <g:caption> in this example, anticipating the my ui:binder template will be invoking the constructor with the single Footer parameter. I'm given a compilation error, hence is my reason for posting.

UiBinder:

<g:DialogBox2>
 
<g:footer>
   
<button>Okay</button>
   
<button>Cancel</button>
 
</g:footer>
</g:DialogBox2>

Class:

public class DialogBox2 extends DialboxBox {
  public interface Footer extends HasAllMouseHandlers, HasHTML, HasSafeHtml, IsWidget { }

  public static class FooterImpl extends HTML implements Footer {
    public FooterImpl() {
     
super();
   
}
 
}

 
private Footer footer;

 
public DialogBox2(Footer footer) {
   
super();
   
this.footer = footer;

   
Element td = getCellElement(2,1); // corresponds to .dialogBottomCenter
    DOM
.appendChild(td, footer.asWidget()..getElement());
 
}

  public DialogBox2() {
    super(new FooterImpl);
 
}

 
public Footer getFooter() {
   
return footer;
 
}
}

Compiler Output:

Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   
Computing all possible rebind results for 'com.example.client.core.ExampleDialogView.Binder'
     
Rebinding com.example.client.core.ExampleDialogView.Binder
         
Invoking generator com.google.gwt.uibinder.rebind.UiBinderGenerator
           
[ERROR] No class matching "footer" in urn:import:com.google.gwt.user.client.ui: <g:footer> (:60)
   
[ERROR] Errors in 'gen/com/example/client/core/com_gwtplatform_mvp_client_DesktopGinjector_DesktopGinjectorGinjector_fragment.java'
     
[ERROR] Line 56: Failed to resolve 'com.example.client.core.ExampleDialogView.Binder' via deferred binding
   
Unification traversed 659 fields and methods and 505 types. 15 are considered part of the current module and 15 had all of their fields and methods traversed.
   
[WARN] Some stale types ([com.example.client.core.ExampleDialogView_BinderImpl, com.example.client.core.ExampleDialogView_BinderImpl$Widgets]) were not reprocessed as was expected. This is either a compiler bug or a Generator has legitimately stopped creating these types.
[ERROR] Compiler returned false

I am using the GWTP/GIN frameworks but should not be an issue.

I prefer the second (broken) solution because I do not need to nest the inner content inside another widget.

Any ideas what I've overlooked here? Much appreciated.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment