GWT Activities and places: Reusing modal dialogs?

328 views Asked by At

I am trying to get my head around GWT Activities and Places. And I am not sure how to implement a specific functionnality.

Let's assume here that I am also using MVP, and that my Activities are my Presenters.

Say I have an activity (let's call it activity A) (and its corresponding view) that is displaying a list of customers. The user can click on a "create customer" button in the view.

What I want to do is this: I want a "create customer" dialog to pop up on top of the current activity when the user clicks on the button. I also want all logic related to said dialog to be separated, so it can be reused later.

For example, the same dialog could be reused in a "create invoice" activity. So the user could click a similar "create customer" button in the "create invoice" activity, and be presented with the same dialog as used earlier.

Now, if I understand it correctly, I do not want to goTo() a new place, since it would terminate the current activity "list customers" or "create invoice".

I have thought about defining a "CreateCustomerPresenter" and a "CreateCustomerDialog" (which would be the corresponding view", and having my "list customers"/"create invoice" Activities (reminder: they also are my Presenters) extend the "CreateCustomerPresenter", but I don't know if it would be a wise idea...

What is the recommended way of reusing logic+view associated with a dialog in the context of an activity?

2

There are 2 answers

0
Chris Lercher On BEST ANSWER

There are several valid approaches, but the one I usually prefer is this: Not to treat dialogs as places (activities) at all.

Reasoning: A place means, that you can reach it via bookmarks/browser history. Let's say I'm on the customer list, and I click "edit customer", a dialog opens. Do I want to "go back" to the list when I click the browser back button? And will the dialog open again when I click the browser forward button? I doubt it, and believe that a user wants to use the browser buttons to go back/forward entire 'pages' within the app (i.e. a concept that feels to the user like a page), but not open/close dialogs within the page.

0
pillingworth On

I have done exactly this very recently.

The approach I took was to create an activity/view in the usual way for the content of the dialog. To launch, create the activity/view to embed in the dialog - I termed this a sub activity. Create the modal dialog and then call start on the sub-activity passing in the dialog content as the panel. In the main activity I then redirected the mayStop, stop etc to the sub-activity.

The tricky part was handling the dialog closing and passing control back to the main activity. I ended up adding a listener to the dialog and firing events on the event bus which were picked up my main activity. I am not 100% happy with this but it does work.

I have not used it but I think that GWTP supports this and other ways of creating sub-activities out-of-the box.