Thursday, February 7, 2013

Re: UiBinder and abstract class



How do we do that?

On Tuesday, 2 February 2010 04:55:17 UTC+5:30, matttai wrote:
You are probably setting setWidget(uiBinder.createAndBindUi(this)); in
the extended class. I don't see your bind statement for the second
class so i cannot tell so it is just a guess.

Bind the loginbox content for the LoginDialogBox as a widget and pass
it in for your bind in the setContent(content); statement

On Feb 1, 10:22 pm, damians <dsu...@o2.pl> wrote:
> Hello,
>
> I've got a problem and i googled lots of pages to see if anyone got
> the same problem but i didn't find anything.
>
> I've got class AbstractDialog that extends DialogBox with some
> standart buttons like OK CANCEL that are bound by UiBinder. I've got
> another class that extends AbstractDialog with another declarative xml
> file, that contains only the main content of that DialogBox.
>
> When am trying to lunch application i got this error:
> Rebinding <package>.<class>UiBinder
>   Invoking com.google.gwt.dev.javac.StandardGeneratorContext@a51c3c
>     Method 'ok' can not be bound. You probably missed
> ui:field='okButton' in the template.
>
> Method ok and UiHandler for button okVutton is declared in
> AbstractDialog. From class that extends AbstractDialog the UiField is
> not visible. Am i doing something wrong or i just didnt saw any
> information that you can not extends an object tha got his own
> UiBinder and extended class got their own UiBinder as well.
>
> My code:
>
> AbstractDialogBox.java
>
> public abstract class AbstractDialogBox extends DialogBox
> {
>         private static AbstractDialogBoxUiBinder uiBinder = GWT.create
> (AbstractDialogBoxUiBinder.class);
>
>         interface AbstractDialogBoxUiBinder extends UiBinder<Widget,
> AbstractDialogBox>
>         {
>         }
>
>         @UiField Button okButton;
>         @UiField Button cancelButton;
>         @UiField Label emptyLabel;
>         @UiField VerticalPanel main;
>
>         public AbstractDialogBox()
>         {
>                 setWidget(uiBinder.createAndBindUi(this));
>                 setStyleName("oe-DialogBox");
>
>                 okButton.setText("OK");
>                 cancelButton.setText("CANCEL");
>         }
>
>         public void setContent(Widget content)
>         {
>                 main.add(content);
>         }
>
>         @UiHandler("okButton")
>         void ok(ClickEvent e)
>         {
>                 onOK();
>         }
>
>         @UiHandler("cancelButton")
>         void cancel(ClickEvent e)
>         {
>                 onCancel();
>         }
>
>         public void keyPress(KeyPressEvent event)
>         {
>                 if (event.getCharCode() == 13)
>                         onOK();
>                 else if (event.getCharCode() == 27)
>                         onCancel();
>         }
>
>         public abstract void onOK();
>         public abstract void onCancel();
>
> }
>
> AbstractDialog.ui.xml
>
> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
> <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
>         xmlns:g="urn:import:com.google.gwt.user.client.ui">
>
>         <g:HTMLPanel>
>         <table width="320px" cellspacing="0" cellpadding="3">
>                 <tr>
>                         <td colspan="3"><g:VerticalPanel ui:field="main" width="100%"/></
> td>
>                 </tr>
>                 <tr>
>                         <td><g:Label ui:field="emptyLabel" width="140px"/></td>
>                         <td><g:Button ui:field="okButton" styleName="dialogButton"/></td>
>                         <td><g:Button ui:field="cancelButton" styleName="dialogButton"/></
> td>
>                 </tr>
>         </table>
>         </g:HTMLPanel>
> </ui:UiBinder>
>
> LoginOptionDialog.java that extends AbstractDialog
>
> public class LoginOptionDialog extends AbstractDialogBox
> {
>         private static LoginOptionDialogUiBinder uiBinder = GWT.create
> (LoginOptionDialogUiBinder.class);
>         interface LoginOptionDialogUiBinder extends UiBinder<Widget,
> LoginOptionDialog>   {}
>
>         @UiField Image icon;
>         @UiField Label descIp;
>         @UiField TextBox ip;
>         @UiField HTMLPanel content;
>
>         public LoginOptionDialog()
>         {
>                 super();
>
>                 setText("Login options");
>
>                 descIp.setText("Server IP:");
>                                 ip.setText("Enter ip");
>
>                                 setContent(content);
>         }
>
>         @UiHandler("ip")
>         public void press(KeyPressEvent event)
>         {
>                 keyPress(event);
>         }
>
>         public void onCancel()
>         {
>                 // restore ip text from application context
>                 hide();
>         }
>
>         public void onOK()
>         {
>                 // set ip in application context
>                 hide();
>         }
>
> }
>
> LoginOptionDialog.ui.xml
>
> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
> <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
>         xmlns:g="urn:import:com.google.gwt.user.client.ui">
>
>  <g:HTMLPanel ui:field="content">
>   <table width="100%" cellspacing="0" cellpadding="3">
>    <tr>
>     <td><g:Image ui:field="icon" url="gfx/ServerIp.png" width="23px"
> height="23px"/></td>
>     <td align="center"><g:Label ui:field="descIp"
> styleName="dialogText" wordWrap="false" width="126px"/></td>
>     <td><g:TextBox ui:field="ip" styleName="dialogText" width="165px"/></td>
>
>    </tr>
>   </table>
>  </g:HTMLPanel>
>
> </ui:UiBinder>
>
> Enviroment that am using to launch it:
>
> public class Application implement EntryPoint
> {
>     private LoginOptionDialog loginOptionDialog;
>     private Button optionButton;
>
>     public void onModuleLoad()
>     {
>        optionButton = new Button("Options");
>        optionButton.addClickHandler(new ClickHandler()
>           {
>                public void onClick(ClickEvent event)
>                {
>            loginOptionDialog.setPopupPosition(optionButton.getAbsoluteLeft()
> - 100,
>
> optionButton.getAbsoluteTop() - 60);
>
>            loginOptionDialog.show();
>                }
>           });
>        loginOptionDialog = new LoginOptionDialog();
>
>         RootPanel.get("optionButton").add(optionButton);
>     }}

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment