00001
00002 using System;
00003 using Foodolini.Activities;
00004 using Foodolini.BusinessLogic;
00005 using Gtk;
00006 using System.Collections.Generic;
00007
00008 namespace Foodolini.Activities.Cookbook
00009 {
00013 [FoodoliniActivity("Select users", true)]
00014 public partial class UserSelector : Gtk.Dialog, IActivity
00015 {
00016
00017 protected NodeStore userStorage = new NodeStore(typeof(PersonAdapter));
00018 protected NodeStore userSelectedStorage = new NodeStore(typeof(PersonAdapter));
00019 private Dictionary<Person, double> users = new Dictionary<Person, double>();
00020
00021 public UserSelector()
00022 {
00023 this.Build();
00024
00025
00026 this.nvUsers.NodeStore = userStorage;
00027 this.nvUsers.AppendColumn("Users", new CellRendererText(), (tree_colum, cell, node)=>{
00028 PersonAdapter n = (PersonAdapter)node;
00029 CellRendererText c = (CellRendererText)cell;
00030 c.Text = n.Name;
00031 });
00032
00033 this.nvSelectedUsers.NodeStore = userSelectedStorage;
00034 this.nvSelectedUsers.AppendColumn("Users", new CellRendererText(), (tree_colum, cell, node)=>{
00035 PersonAdapter n = (PersonAdapter)node;
00036 CellRendererText c = (CellRendererText)cell;
00037 c.Text = n.Name;
00038 });
00039 this.nvSelectedUsers.AppendColumn("Percentage eaten", new CellRendererText(), (tree_colum, cell, node)=>{
00040 PersonAdapter n = (PersonAdapter)node;
00041 CellRendererText c = (CellRendererText)cell;
00042 c.Text = n.PercentageEaten.ToString();
00043 });
00044
00045 bxUnselected.ShowAll();
00046 bxSelected.ShowAll();
00047
00048
00049 foreach (var person in Person.ListUsers())
00050 userStorage.AddNode(new PersonAdapter(person));
00051
00052 this.buttonOk.Sensitive = false;
00053
00054 }
00055
00059 private void checkSelectedPeople()
00060 {
00061 this.buttonOk.Sensitive = false;
00062 if(this.userSelectedStorage.GetEnumerator().MoveNext())
00063 this.buttonOk.Sensitive = true;
00064 }
00065
00072 public Dictionary<Person, double> GetUsers ()
00073 {
00074 foreach (PersonAdapter user in userSelectedStorage)
00075 users.Add(user.Person, user.PercentageEaten);
00076 return users;
00077 }
00078
00082 protected virtual void OnAddUserClick (object sender, System.EventArgs e)
00083 {
00084 if(nvUsers.NodeSelection.SelectedNode != null)
00085 {
00086 PersonAdapter pa = ((PersonAdapter)nvUsers.NodeSelection.SelectedNode);
00087 pa.PercentageEaten = sbProcentageEaten.Value;
00088
00089 userSelectedStorage.AddNode(pa);
00090 checkSelectedPeople();
00091 }
00092 }
00093
00097 protected virtual void OnBtnRemoveUserClicked (object sender, System.EventArgs e)
00098 {
00099 if(nvSelectedUsers.NodeSelection.SelectedNode != null)
00100 {
00101 userSelectedStorage.RemoveNode((PersonAdapter)nvSelectedUsers.NodeSelection.SelectedNode);
00102 checkSelectedPeople();
00103 }
00104 }
00105
00106 #region IActivity
00107 public void Register(IOwner owner){
00108
00109 }
00110
00111 public void Unregister(){
00112
00113 }
00114
00115 public Widget Widget{
00116 get{
00117 return this;
00118 }
00119 }
00120 #endregion
00121 }
00122 }