[longomatch/redesign: 96/120] Add type to ITemplate



commit ae5eb74e43cfac7b2da14b70d168c3e386d3ca14
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Mar 30 22:07:51 2011 +0200

    Add type to ITemplate

 LongoMatch/Gui/Component/ProjectDetailsWidget.cs  |    4 +-
 LongoMatch/Interfaces/ITemplates.cs               |    8 +++--
 LongoMatch/Services/TemplatesService.cs           |   36 +++++++++++++--------
 LongoMatch/Store/SubCategory.cs                   |    2 +-
 LongoMatch/Store/Templates/CategoriesTemplate.cs  |    2 +-
 LongoMatch/Store/Templates/SubCategoryTemplate.cs |    2 +-
 LongoMatch/Store/Templates/TeamTemplate.cs        |    2 +-
 7 files changed, 33 insertions(+), 23 deletions(-)
---
diff --git a/LongoMatch/Gui/Component/ProjectDetailsWidget.cs b/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
index 4c6fe27..7bba332 100644
--- a/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
+++ b/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
@@ -53,8 +53,8 @@ namespace LongoMatch.Gui.Component
 		private Categories actualCategory;
 		private TeamTemplate actualVisitorTeam;
 		private TeamTemplate actualLocalTeam;
-		private ITemplateProvider<Categories> tpc;
-		private ITemplateProvider<TeamTemplate> tpt;
+		private ITemplateProvider<Categories, Category> tpc;
+		private ITemplateProvider<TeamTemplate, Player> tpt;
 		private ProjectType useType;
 		private List<Device> videoDevices;
 		private const string PAL_FORMAT = "720x576 (4:3)";
diff --git a/LongoMatch/Interfaces/ITemplates.cs b/LongoMatch/Interfaces/ITemplates.cs
index 80f8e0c..2eee58d 100644
--- a/LongoMatch/Interfaces/ITemplates.cs
+++ b/LongoMatch/Interfaces/ITemplates.cs
@@ -26,6 +26,8 @@ namespace LongoMatch.Interfaces
 		string Name {get; set;}
 	}
 	
+	public interface ITemplate<T>: ITemplate, IList<T> {}
+	
 	public interface ITemplateProvider
 	{
 		void CheckDefaultTemplate();
@@ -36,14 +38,14 @@ namespace LongoMatch.Interfaces
 		void Create (string templateName, params object [] list);
 	}
 	
-	public interface ITemplateProvider<T>: ITemplateProvider where T: ITemplate
+	public interface ITemplateProvider<T, U>: ITemplateProvider where T: ITemplate<U>
 	{
 		List<T> Templates {get;}
 		T Load (string name);
-		void Save (ITemplate template);
+		void Save (ITemplate<U> template);
 	}
 	
-	public interface ITemplateWidget<T>
+	public interface ITemplateWidget<T, U> where T: ITemplate<U>
 	{
 		T Template {get; set;}
 	}
diff --git a/LongoMatch/Services/TemplatesService.cs b/LongoMatch/Services/TemplatesService.cs
index bf17d56..03fedf2 100644
--- a/LongoMatch/Services/TemplatesService.cs
+++ b/LongoMatch/Services/TemplatesService.cs
@@ -38,13 +38,13 @@ namespace LongoMatch.Services
 		{
 			dict = new Dictionary<Type, ITemplateProvider>();
 			dict.Add(typeof(SubCategoryTemplate),
-			         new TemplatesProvider<SubCategoryTemplate> (basePath,
+			         new TemplatesProvider<SubCategoryTemplate, string> (basePath,
 			                                                 Constants.SUBCAT_TEMPLATE_EXT));
 			dict.Add(typeof(TeamTemplate),
-			         new TemplatesProvider<TeamTemplate> (basePath,
+			         new TemplatesProvider<TeamTemplate, Player> (basePath,
 			                                                 Constants.TEAMS_TEMPLATE_EXT));
 			dict.Add(typeof(Categories),
-			         new TemplatesProvider<Categories> (basePath,
+			         new TemplatesProvider<Categories, Category> (basePath,
 			                                                 Constants.CAT_TEMPLATE_EXT));
 			CheckDefaultTemplates();
 		}
@@ -54,32 +54,40 @@ namespace LongoMatch.Services
 				t.CheckDefaultTemplate();
 		}
 		
-		public ITemplateProvider<T> GetTemplateProvider<T>() where T: ITemplate {
+		public ITemplateProvider<T, U> GetTemplateProvider<T, U>() where T: ITemplate<U> {
 			if (dict.ContainsKey(typeof(T)))
-				return (ITemplateProvider<T>)dict[typeof(T)];
+				return (ITemplateProvider<T, U>)dict[typeof(T)];
 			return null;
 		}
 		
-		public ITemplateProvider<SubCategoryTemplate> SubCategoriesTemplateProvider {
+		public ITemplateWidget<T, U> GetTemplateEditor<T, U>() where T: ITemplate<U>{
+			if (typeof(T) == typeof(Categories))
+				return (ITemplateWidget<T, U>) new CategoriesTemplateEditorWidget ();
+			if (typeof(T) == typeof(TeamTemplate))
+				return (ITemplateWidget<T, U>) new TeamTemplateEditorWidget();
+			return null;
+		}
+		
+		public ITemplateProvider<SubCategoryTemplate, string> SubCategoriesTemplateProvider {
 			get {
-				return (ITemplateProvider<SubCategoryTemplate>) dict[typeof(SubCategoryTemplate)]; 
+				return (ITemplateProvider<SubCategoryTemplate, string>) dict[typeof(SubCategoryTemplate)]; 
 			}
 		}
 		
-		public ITemplateProvider<TeamTemplate> TeamTemplateProvider {
+		public ITemplateProvider<TeamTemplate, Player> TeamTemplateProvider {
 			get {
-				return (ITemplateProvider<TeamTemplate>) dict[typeof(TeamTemplate)]; 
+				return (ITemplateProvider<TeamTemplate, Player>) dict[typeof(TeamTemplate)]; 
 			}
 		}
 
-		public ITemplateProvider<Categories> CategoriesTemplateProvider {
+		public ITemplateProvider<Categories, Category> CategoriesTemplateProvider {
 			get {
-				return (ITemplateProvider<Categories>) dict[typeof(Categories)]; 
+				return (ITemplateProvider<Categories, Category>) dict[typeof(Categories)]; 
 			}
 		}
 	}
 	
-	public class TemplatesProvider<T>: ITemplateProvider<T> where T: ITemplate
+	public class TemplatesProvider<T, U>: ITemplateProvider<T, U> where T: ITemplate<U>
 	{
 		private readonly string basePath;
 		private readonly string extension;
@@ -141,7 +149,7 @@ namespace LongoMatch.Services
 			return (T)methodLoad.Invoke(null, new object[] {GetPath(name)});
 		}
 		
-		public void Save (ITemplate template) {
+		public void Save (ITemplate<U> template) {
 			string filename =  GetPath(template.Name);
 			
 			Log.Information("Saving template " + filename);
@@ -180,7 +188,7 @@ namespace LongoMatch.Services
 			if (list.Length == 0)
 				list = new object[] {0};
 			Log.Information(String.Format("Creating default {0} template", typeof(T)));
-			ITemplate t =(ITemplate)methodDefaultTemplate.Invoke(null, list);
+			ITemplate<U> t =(ITemplate<U>)methodDefaultTemplate.Invoke(null, list);
 			t.Name = templateName;
 			Save(t);
 		}
diff --git a/LongoMatch/Store/SubCategory.cs b/LongoMatch/Store/SubCategory.cs
index 5c02fda..bf55c99 100644
--- a/LongoMatch/Store/SubCategory.cs
+++ b/LongoMatch/Store/SubCategory.cs
@@ -71,7 +71,7 @@ namespace LongoMatch.Store
 	}
 
 	[Serializable]
-	public class TagSubCategory: SubCategory<string> {}
+	public class TagSubCategory: SubCategory<string>, IList<string> {}
 
 	/// <summary>
 	/// SubCategory to tag Players
diff --git a/LongoMatch/Store/Templates/CategoriesTemplate.cs b/LongoMatch/Store/Templates/CategoriesTemplate.cs
index 510d1cf..efabd74 100644
--- a/LongoMatch/Store/Templates/CategoriesTemplate.cs
+++ b/LongoMatch/Store/Templates/CategoriesTemplate.cs
@@ -37,7 +37,7 @@ namespace LongoMatch.Store.Templates
 	/// The <see cref="LongoMatch.DB.Project"/> must handle all the changes
 	/// </summary>
 	[Serializable]
-	public class Categories: List<Category>, ITemplate
+	public class Categories: List<Category>, ITemplate, ITemplate<Category>
 	{
 
 		/// <summary>
diff --git a/LongoMatch/Store/Templates/SubCategoryTemplate.cs b/LongoMatch/Store/Templates/SubCategoryTemplate.cs
index 770dda8..c627b35 100644
--- a/LongoMatch/Store/Templates/SubCategoryTemplate.cs
+++ b/LongoMatch/Store/Templates/SubCategoryTemplate.cs
@@ -26,7 +26,7 @@ namespace LongoMatch.Store.Templates
 {
 
 	[Serializable]
-	public class SubCategoryTemplate: TagSubCategory, ITemplate
+	public class SubCategoryTemplate: TagSubCategory, ITemplate<string>
 	{
 
 		public SubCategoryTemplate() {}
diff --git a/LongoMatch/Store/Templates/TeamTemplate.cs b/LongoMatch/Store/Templates/TeamTemplate.cs
index 9d7caa6..dcc0cbc 100644
--- a/LongoMatch/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch/Store/Templates/TeamTemplate.cs
@@ -27,7 +27,7 @@ namespace LongoMatch.Store.Templates
 {
 	[Serializable]
 
-	public class TeamTemplate: List<Player>, ITemplate
+	public class TeamTemplate: List<Player>, ITemplate<Player>
 	{
 		public TeamTemplate() {}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]