0

I was required to put a "Done" button in a GWT Composite (despite already having the close icon), it should simply close the window upon clicking. Unfortunately, I can't find a .close() method to implement it. How can it be done?

enter image description here

I have a UserDialog class that contains a Composite component, which I named UserComposite. UserDialog extends to CustomDialogBox, which extends to DialogBox class:

public class UserDialog extends CustomDialogBox {    
    private UserComposite c = new UserComposite();
    // more codes here
    private FlowPanel getFlowPanel() {
        if (p instanceof Panel && c instanceof Composite) {
            p.setSize(WIDTH, HEIGHT);
            p.add(c);
        }
        return p;
    } 
}

and then this is my UserComposite

public class UserComposite extends Composite {
   // codes here
   @UiHandler("doneButton")
   void onDoneButtonClick(ClickEvent event) {
      this.removeFromParent();
   }
}

I tried removeFromParent() but the UserComposite was only removed from parent which resulted to an empty DialogBox.

enter image description here

Mr. Xymon
  • 1,053
  • 2
  • 11
  • 16

2 Answers2

4

@Mr. Xymon, By window if you mean instance of PopupPanel or instance of any subclass of PopupPanel, you can use the following :

popupPanel.hide();
RAS
  • 8,100
  • 16
  • 64
  • 86
4

You need to hide the dialog, not the composite. One way to do this is to pass a reference to the dialog box to the UserComposite constructor, and then use that reference to call hide() on the dialog. It could be something along these lines:

public class UserDialog extends CustomDialogBox {
    private UserComposite c = new UserComposite(this);
    ...
}

public class UserComposite extends Composite {
    private DialogBox parentDialog;

    public UserComposite(DialogBox parentDialog) {
        this.parentDialog = parentDialog;
    }

    @UiHandler("doneButton")
    void onDoneButtonClick(ClickEvent event) {
        parentDialog.hide();
    }
}
David Levesque
  • 22,181
  • 8
  • 67
  • 82
  • +1 This is basically how it's done. It can be improved by defining a CloseCallback interface (so the UserComposite doesn't have to know the entire UserDialog class). Or by using MVP. – Chris Lercher Sep 29 '12 at 17:15
  • Thanks a lot David. I found a way with *removeFromParent()* but I now prefer your solution. – Mr. Xymon Oct 05 '12 at 09:31