Reputation: 390
Using GWT 2.4 with MVP, I have a presenter where the top portion can swap between a read-only presenter of a set of data or an editor for that data, depending on how you arrived at the page.
Without using GWTP, how can I swap between those two presenters and the underlying views?
Currently, the classes looks like this:
public class MainPagePresenter implements Presenter, MainPageView.Presenter, ParentPresenter {
private MainPageViewview;
private final ClientFactory clientFactory;
private StaticDataPresenter staticPresenter;
private SomeOtherPresenter otherPresenter;
}
I'd like for StaticDataPresenter to become some structure that can either hold a StaticDataPresenter or a DynamicDataPresenter that lets you edit.
Thanks for your input.
Upvotes: 0
Views: 388
Reputation: 390
What I ended up doing was putting both editors on the page, and then turning on and off the visibility in the presenter.
Thanks for your suggestions. They helped.
Upvotes: 0
Reputation: 39307
public interface DataPresenter {
void handleEdit();
}
public class StaticDataPresenter implements DataPresenter {
@Override
public void handleEdit() {
// Do nothing.
}
}
public class DynamicDataPresenter implements DataPresenter {
@Override
public void handleEdit() {
// Do something.
}
}
public class MainPagePresenter implements Presenter, MainPageView.Presenter, ParentPresenter {
private MainPageView view;
private final ClientFactory clientFactory;
private DataPresenter dataPresenter;
private SomeOtherPresenter otherPresenter;
...
public void switchDataPresenter(DataPresenter dataPresenter) {
this.dataPresenter = dataPresenter;
DataPresenterView dataPresenterView = view.dataPresenterView();
dataPresenterView.setPresenter(dataPresenter);
}
}
Upvotes: 1
Reputation: 411
Your MainPageView can have a DeckPanel with both the StaticDataPresenter's view, and the SomeOtherPresenter's view.
MainPagePresenter can then tell the MainPageView to switch what is being displayed based on your needs.
Upvotes: 1