3 using System.Reflection;
4 using System.Collections;
10 public class ABMGenerico
17 public ABMGenerico (Type objectType)
19 widgets = new Hashtable ();
21 PropertyInfo[] properties = objectType.GetProperties ();
24 xml = new Glade.XML (null, "abm_generico.glade", "abm_one", null);
25 xml.Autoconnect (this);
28 foreach( PropertyInfo mf in properties ) {
29 Widget l = GetWidget (mf);
31 tabla.Attach (l, 0, 1, i, i+1);
32 Entry e = new Entry ();
33 tabla.Attach (e, 1, 2, i, i+1);
42 private Widget GetWidget (PropertyInfo mf)
45 if (mf.PropertyType.Equals (typeof(string))
46 || mf.PropertyType.Equals (typeof(int))
47 || mf.PropertyType.Equals (typeof(float))) {
48 Label l = new Label (GetLabel (mf.Name) + " : ");
49 l.Justify = Justification.Left;
57 private string GetLabel (string name)
60 string s = (string)name.Clone ();
61 while (i < s.Length) {
62 if (Char.IsUpper(s[i]) && (i>0)) {
63 s = s.Insert (i, " ");
71 public void OnDialogResponse (object o, ResponseArgs args)
73 if (args.ResponseId == ResponseType.Cancel)
76 PropertyInfo[] properties = current.GetProperties ();
78 System.Object output = Activator.CreateInstance (current);
80 foreach (string key in widgets.Keys) {
81 PropertyInfo p = current.GetProperty (key);
82 Entry e = (Entry)widgets[key];
83 Console.WriteLine ("{0} = {1}", key, e.Text);
84 if (p.PropertyType.Equals (typeof(string)))
85 p.SetValue (output, e.Text, null);
86 if (p.PropertyType.Equals (typeof(int)))
87 p.SetValue (output, Int32.Parse (e.Text), null);
88 if (p.PropertyType.Equals (typeof(float))) {
89 p.SetValue (output, (float)Double.Parse (e.Text), null);
93 Controller c = new Controller ();
95 c.GenericSave (output);
100 public void Run (string title)
102 Dialog w = (Dialog)xml.GetWidget ("abm_one");