public class NavigationDispatcher
{
public static void RaiseNavigate(Type type)
{
Navigate(type);
}
public static event NavigateHandler Navigate;
}
NavigationDispatcher allows you to raise the Navigate event from both the MainForm and the UpdateView. The UpdateView button click event changes to:
private void saveButton_Click(object sender, EventArgs e)
{
Save();
NavigationDispatcher.RaiseNavigate(typeof(ReadView));
}
The only other change to make is in MainPresenter.
public class MainPresenter
{
private readonly MainForm form;
private PresenterFactory presenterFactory;
public MainPresenter(MainForm form, PresenterFactory presenterFactory)
{
this.form = form;
NavigationDispatcher.Navigate+=new NavigateHandler(Navigate);
this.presenterFactory = presenterFactory;
}
private void Navigate(System.Type viewType)
{
form.ContentPanel.Controls.Clear();
IView view = presenterFactory.Find(viewType);
form.ContentPanel.Controls.Add((Control) view);
}
}
Subscription to the NavigationDispatcher's Navigate event occurs in the constructor; however, the subscription is no longer necessary in the Navigate event (where we used to subscribe to the Navigate event of the View). Obviously, the Navigate event can be removed from the IView at this point also.
Have you considered posting the source code for download?
ReplyDeleteI wasn't keeping the code completely clean since I wasn't planning on it; however, if you can accept it with it's flaws you can find it at http://jayfields.com/src/samplesmartclient.zip
ReplyDelete