I've never used deferred commands before and your solution does sound
better.  If I were to do what you said is this what the code would somewhat
look like (below)?

public class CallingClass {
  private Command yesCommand;
  private Command noCommand;

  public CallingClass() {
    yesCommand new Command() {
      public void execute() {
        yesButtonAction();
      }
    };

    panel.Add(new AlertClass(yesCommand));
  }

  public void yesButtonAction() {
    // Do yes button action here
  }

    public void noButtonAction() {
    // Do no button action here
  }
}

public class AlertClass extends Composite {
  private Command yesCommand;
  private Command noCommand;
  private final Button yesButton;
  private final Button noButton;

  public AlertClass(Command yesCommand, Command noCommand) {
    this.yesCommand = yesCommand;
    this.noCommand = noCommand;
    ......

    yesButton = new Button("Yes",new ClickListener(){
      public void onClick(Widget sender) {
        DeferredCommand.add(yesCommand);
      }
    });

    noButton = new Button("No",new ClickListener(){
      public void onClick(Widget sender) {
        DeferredCommand.add(noCommand);
      }
    });

    initWidget(...);
  }
}


On Fri, Dec 5, 2008 at 9:48 AM, jhulford <[EMAIL PROTECTED]> wrote:

>
> It might be easier just to pass 2 Command objects.  1 for when the yes
> button is clicked and 1 for when the no button is clicked.  Then in
> your click handler just execute the command via DeferredCommand.
>
> On Dec 4, 3:29 pm, "Pavel Byles" <[EMAIL PROTECTED]> wrote:
> > You can pass a reference to the calling class to Alert class and call a
> > method in the calling class.. here's an example:
> >
> > public class CallingClass {
> >   public CallingClass() {
> >     panel.Add(new AlertClass(this));
> >   }
> >
> >   public void yesButtonAction() {
> >     // Do yes button action here
> >   }
> >
> > }
> >
> > public class AlertClass {
> >   private CallingClass callingClass;
> >
> >   public AlertClass(CallingClass reference) {
> >     this.callingClass = reference;
> >     ......
> >     Yes = new Button("Yes",new ClickListener(){
> >          public void onClick(Widget sender) {
> >              callingClass.yesButtonAction();
> >              result="yes";
> >          }
> >     });
> >   }
> >
> > }
> >
> > This might work.
> >
> > On Thu, Dec 4, 2008 at 8:05 AM, jagadesh <[EMAIL PROTECTED]
> >wrote:
> >
> >
> >
> >
> >
> > >  Hi Guys
> >
> > > iam developing an pageheader type of widget.the real thing i donot
> > > want to user Window.confirm(); to showing the user a window with yes
> > > and no buttons . i want my own widget to show a popuppanel with a
> > > horizontal panel with 2 buttons like yes and no. so when a user click
> > > on yes a action is performed and when on no another action is done.
> > > iam successfull in creating a widget called AlertBox .
> > > here is a sample code ..
> >
> > > public AlertClass() {
> >
> > >                popupPanel=new PopupPanel();
> > >                popupPanel.setTitle("Popup Panel");
> >
> > >                panel = new HorizontalPanel();
> > >                panel.setWidth("100%");
> >
> > >                messageLabel = new HTML();
> > >                //messageLabel.setText(message);
> > >                messageLabel.setText("jagadesh");
> > >                panel.add(messageLabel);
> > >                panel.setCellVerticalAlignment(messageLabel,
> > > HorizontalPanel.ALIGN_MIDDLE);
> >
> > >                Yes=new Button("Yes",new ClickListener(){
> > >                        public void onClick(Widget sender) {
> > >                                result="yes";
> > >                        }
> > >                });
> > >                Yes.setWidth("40px");
> >
> > >                No=new Button("No",new ClickListener(){
> > >                        public void onClick(Widget sender) {
> > >                                result="no";
> > >                        }
> > >                });
> > >        No.setWidth("40px");
> >
> > >                panel.add(Yes);
> > >                panel.setCellHorizontalAlignment(messageLabel,
> > > HorizontalPanel.ALIGN_RIGHT);
> > >                panel.add(No);
> > >                panel.setCellHorizontalAlignment(messageLabel,
> > > HorizontalPanel.ALIGN_RIGHT);
> >
> > >                Image closeIcon = new Image("images/cross.white.png");
> > >                closeIcon.setStyleName("close-icon");
> > >                panel.add(closeIcon);
> > >                panel.setCellHorizontalAlignment(closeIcon,
> > > HorizontalPanel.ALIGN_RIGHT);
> >
> > >                closeIcon.addClickListener(new ClickListener() {
> > >                        public void onClick(Widget sender) {
> > >                                panel.setVisible(false);
> > >                                panel.removeStyleDependentName("Error");
> > >
>  panel.removeStyleDependentName("Success");
> > >                        }
> > >                });
> >
> > >                popupPanel.add(panel);
> > >                popupPanel.show();
> > >                initWidget(popupPanel);
> >
> > >        }
> >
> > > now my requirement is iam creating an object of the AlertClass in
> > > another class and showing the pageheader. but when a user click on the
> > > yes button an action should be done. iam unable to catch which button
> > > is clicked.
> > > how can i catch which button is clicked now.can u tell me what is the
> > > use of hasWidgets interface.
> >
> > > thank in advance for every help.
> >
> > > thank u,.
> > > jagadesh
> >
> > --
> > -Pav
> >
>


-- 
-Pav

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to