|
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using MVCSharp.Core;
using MVCSharp.Core.Views;
using MVCSharp.Core.Configuration.Views;
using MVCSharp.Core.Configuration;
namespace MVCSharp.Examples.SimpleFormsViewsManagerExample
{
public class SimpleFormsViewsManager : IViewsManager
{
private Navigator navigator;
private ViewInfoCollection viewInfos;
private Dictionary<string, Form> forms = new Dictionary<string, Form>();
public void ActivateView(string viewName)
{
Form f = FindOrCreateView(viewName);
f.Show();
f.Activate();
}
public IView GetView(string viewName)
{
return (IView)FindOrCreateView(viewName);
}
private Form FindOrCreateView(string viewName)
{
Form result = null;
forms.TryGetValue(viewName, out result);
if ((result == null) || result.IsDisposed)
{
result = CreateHelper.Create(ViewInfos[viewName].ViewType) as Form;
result.Activated += new EventHandler(view_Activated);
forms[viewName] = result;
(result as IView).ViewName = viewName;
InitializeView(result as IView);
}
return result;
}
void view_Activated(object sender, EventArgs e)
{
Navigator.TryNavigateToView((sender as IView).ViewName);
}
private void InitializeView(IView view)
{
view.Controller = Navigator.GetController(view.ViewName);
view.Controller.View = view;
}
public Navigator Navigator
{
get { return navigator; }
set { navigator = value; }
}
public ViewInfoCollection ViewInfos
{
get { return viewInfos; }
set { viewInfos = value; }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Oleg Zhukov, born and living in Russia is Lead Engineer and Project Manager in a company which provides business software solutions. He has graduated from Moscow Institute of Physics and Technology (MIPT) (department of system programming) and has got a M.S. degree in applied physics and mathematics. His research and development work concerns architectural patterns, domain-driven development and systems analysis. Being the adherent of agile methods he applies them extensively in the projects managed by him.