0

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.

Brett Slocum
  • 390
  • 1
  • 5
  • 21

3 Answers3

1
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);
  }    
}
dting
  • 38,604
  • 10
  • 95
  • 114
1

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.

trevorism
  • 411
  • 2
  • 7
0

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.

Brett Slocum
  • 390
  • 1
  • 5
  • 21