Search code examples
gwtpopupgwt-editors

GWT Popup with Editor Framework


In a simple inventory management app i have an activity to handle assigning equipment types to employees (if a user checks something out). What i am wondering is this:

Currently i have drag and drop up to where equipment can be dragged over to an employee. What i want to have is, as soon as the equipment is dragged, a popup opens asking the user for confirmation as well as the amount he wishes to assign. This will basically act as an Editor around two entities (equipmentCheckin and equipmentCheckout).

Here's the issues i'm running into:
1. should the popup be initialized in the view and then set visible on the drop event (this is what i planned on doing) - in doing this how do you actually initialize the editor properly (should there be a separate activity called on the drop - i don't imagine there would but the editor part is confusing me)

2. should each popup have its own class and ui.xml file - this is the way i was going to go originally and then just call the set visible to true on the drop event (i think this is the right way to go)

i guess what i'm asking here is mostly just validation on how to do some of this, i can't find a decent example for this stuff.

for anybody that's used google music before i want to do exactly what they're doing when you go to edit album or song info - i imagine behind the scenes they're using an editor with a popup - i just want to know what the correct way to actually do this is before i go hack up a solution


Solution

  • I think you are on the right track, making the popup self-contained, and keeping just a single instance of it if you can help it.

    As far as the editor details, what isn't making sense? The general idea is that you can create the driver once, initialize it with the popup (implementing Editor), then call edit on the driver each time you are ready to display it with a new model.

    I usually end up with something like (assuming the class extends Popup, implements Editor, and has the driver defined internally)

    public MyPopup() {
      //uibinder or other layout
      this.driver = GWT.create(Driver.class);
      driver.initialize(this);
    }
    public void edit(MyModel model) {
      driver.edit(model);
      show();
    }
    

    To flavor this answer with my own approach/biases, I like a MVP setup where the view and presenter are both interfaces, and where the presenter impl doesn't know how the view will end up drawing. Generally looks about like this for me

    public interface MyModelEditorView extends Editor<MyModel> {
      // this param is used in a mobile/table situation, where popups aren't as friendly
      void show(AcceptsOneWidget parent);
    
      // exposes the driver for the presenter * 
      SimpleBeanEditorDriver<MyModel, ?> getDriver();
    
      void setPresenter(Presenter presenter);
    
      public interface Presenter {
        // this is the only method that is called externally
        void show(AcceptsOneWidget parent, MyModel model);
    
        // called by click handlers in the view impl, probably by @UiHandler methods
        void onSaveClicked();
        void onCancelClicked();
      }
    }
    

    * Presenter probably should control the driver so it can check for errors, pass in errors from the server if needed, edit new models, and flush out the results.