I am designing a GUI that has the following basic idea (similarly modeled after Visual Studio\'s basic look-and-feel):
I know this question is nearly 2 years old but I find myself in a very similar situation. Like you, I have scoured the internet for DAYS and not found a concrete example that fits my needs - the more I searched the more I kept coming back to the same sites over and over again to the point where I had about 10 pages of purple links in Google!
Anyway, I was wondering if you ever came up with a satisfactory solution to the problem? I'll outline how I have gone about it so far, based on what I have read over the last week:
My aims were: Passive form, presenter first (the presenter instantiates the form so the form has no knowledge of it's presenter) Call methods in the presenter by raising events in the form (view)
The application has a single FormMain which contains 2 user controls:
ControlsView (has 3 buttons) DocumentView (A 3rd party image thumbnail viewer)
The "Main Form" holds a toolbar for the usual file save stuff etc. and little else. The "ControlsView" user control allows the user to click "Scan Documents" It also contains a treeview control to display a hierarchy of documents and pages The "DocumentView" shows thumbnails of the scanned documents
It really felt to me that each control should have it's own MVP triad, as well as the main form, but I wanted them all to reference the same model. I just could not work out how to co-ordinate the communication between the controls.
For example, when the user clicks "Scan", the ControlsPresenter takes charge of acquiring the images from the scanner and I wanted it to add the page to the treeview as each page returned from the scanner - no problem - but I also wanted the thumbnail to appear in the DocumentsView at the same time (problem as the presenters don't know about each other).
My solution was for the ControlsPresenter to call a method in the model to add the new page into the business object, and then in the model I raise a "PageAdded" event.
I then have both the ControlsPresenter and the DocumentPresenter "listening" to this event so that the ControlsPesenter tells it's view to add the new page to the treeview, and the DocumentPresenter tells it's view to add the new thumbnail.
To summarise:
Controls View - raises event "ScanButtonClicked"
Controls Presenter - hears the event, calls Scanner class to AcquireImages as follows:
GDPictureScanning scanner = new GDPictureScanning();
IEnumerable pages = scanner.AquireImages();
foreach (Page page in pages)
{
m_DocumentModel.AddPage(page);
//The view gets notified of new pages via events raised by the model
//The events are subscribed to by the various presenters so they can
//update views accordingly
}
As each page is scanned, the scanning loop calls a "yield return new Page(PageID)". The above method calls m_DocumentModel.AddPage(page). The new page is added to the model, which raises an event. Both controls presenter and document presenter "hear" the event and add items accordingly.
The bit I'm not "sure" about is the initialisation of all the presenters - I'm doing this within Program.cs as follows:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
IDocumotiveCaptureView view = new DocumotiveCaptureView();
IDocumentModel model = new DocumentModel();
IDocumotiveCapturePresenter Presenter = new DocumotiveCapturePresenter(view, model);
IControlsPresenter ControlsPresenter = new ControlsPresenter(view.ControlsView, model);
IDocumentPresenter DocumentPresenter = new DocumentPresenter(view.DocumentView, model);
Application.Run((Form)view);
}
Not sure if this is good, bad or indifferent!
Anyway, what a huge post on a two year old question - be good to get some feedback though...