summaryrefslogtreecommitdiff
path: root/src/bindings/mono/efl_mono/GenericModel.cs
blob: 1bfa91e53ddce8a30fa8dfe03b1f4e0e47c528ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using Eina;

#if EFL_BETA

namespace Efl {

/// <summary>Generic <see cref="Efl.IModel" /> implementation for MVVM models based on <see cref="Efl.UserModel&lt;T&gt;" /></summary>
public class GenericModel<T> : Efl.Object, Efl.IModel, IDisposable
{
   private Efl.IModel model;

   /// <summary>Creates a new model wrapping <c>model</c>.</summary>
   public GenericModel (Efl.IModel model, Efl.Object parent = null) : base(parent)
   {
       this.model = model;
   }

   /// <summary>The list of properties available in the wrapped model.</summary>
   public Eina.Iterator< System.String> Properties
   {
      get { return GetProperties(); }
   }

   /// <summary>The number of children in the wrapped model.</summary>
   public  uint ChildrenCount
   {
      get { return GetChildrenCount(); }
   }

   /// <summary>The list of properties available in the wrapped model.</summary>
   public Eina.Iterator<System.String> GetProperties()
   {
       return model.GetProperties();
   }

   /// <summary>Gets the value of the given property in the wrapped model.</summary>
   public Eina.Value GetProperty(  System.String property)
   {
       return model.GetProperty(property);
   }

   /// <summary>Sets the value of the given property in the given model.</summary>
   public Eina.Future SetProperty(  System.String property,   Eina.Value value)
   {
       return model.SetProperty(property, value);
   }

   /// <summary>Returns the number of children in the wrapped model.</summary>
   public uint GetChildrenCount()
   {
       return model.GetChildrenCount();
   }

   /// <summary>Returns an <see cref="Eina.Future" /> that will resolve when the property is ready to be read.</summary>
   public Eina.Future GetPropertyReady(  System.String property)
   {
       return model.GetPropertyReady(property);
   }

   /// <summary>Gets a number of children from the wrapped model.</summary>
   public Eina.Future GetChildrenSlice(  uint start,   uint count)
   {
       return model.GetChildrenSlice(start, count);
   }

   /// <summary>Adds a new object to the wrapper model.</summary>
   public void Add(T o)
   {
      Efl.IModel child = (Efl.IModel)this.AddChild();
      ModelHelper.SetProperties(o, child);
   }

   /// <summary>Adds a new childs to the model and returns it.</summary>
   public Efl.Object AddChild()
   {
       return model.AddChild();
   }

   /// <summary>Deletes the given <c>child</c> from the wrapped model.</summary>
   public void DelChild( Efl.Object child)
   {
       model.DelChild(child);
   }

   /// <summary>Gets the element at the specified <c>index</c>.</summary>
   async public System.Threading.Tasks.Task<T> GetAtAsync(uint index)
   {
       using (Eina.Value v = await GetChildrenSliceAsync(index, 1))
       {
           if (v.GetValueType().IsContainer())
           {
               var child = (Efl.IModel)v[0];
               T obj = (T)Activator.CreateInstance(typeof(T), new System.Object[] {});
               ModelHelper.GetProperties(obj, child);
               return obj;
           }
           else
           {
               throw new System.InvalidOperationException("GetChildrenSlice must have returned a container");
           }
       }
   }

   /// <summary>Async wrapper around <see cref="SetProperty(System.String, Eina.Value)" />.</summary>
   public System.Threading.Tasks.Task<Eina.Value> SetPropertyAsync(  System.String property,  Eina.Value value, System.Threading.CancellationToken token=default(System.Threading.CancellationToken))
   {
       return model.SetPropertyAsync(property, value, token);
   }

   /// <summary>Async wrapper around <see cref="GetPropertyReady(System.String)" />.</summary>
   public System.Threading.Tasks.Task<Eina.Value> GetPropertyReadyAsync(  System.String property, System.Threading.CancellationToken token=default(System.Threading.CancellationToken))
   {
       return model.GetPropertyReadyAsync(property, token);
   }

   /// <summary>Async wrapper around <see cref="GetChildrenSlice(uint, uint)" />.</summary>
   public System.Threading.Tasks.Task<Eina.Value> GetChildrenSliceAsync(  uint start,  uint count, System.Threading.CancellationToken token=default(System.Threading.CancellationToken))
   {
       return model.GetChildrenSliceAsync(start, count, token);
   }

   /// <summary>Event triggered when properties on the wrapped model changes.</summary>
   public event EventHandler<Efl.IModelPropertiesChangedEvt_Args> PropertiesChangedEvt
   {
      add {
          model.PropertiesChangedEvt += value;
      }
      remove {
          model.PropertiesChangedEvt -= value;
      }
   }

   /// <summary>Event triggered when a child is added from the wrapped model.</summary>
   public event EventHandler<Efl.IModelChildAddedEvt_Args> ChildAddedEvt
   {
      add {
          model.ChildAddedEvt += value;
      }
      remove {
          model.ChildAddedEvt -= value;
      }
   }

   /// <summary>Event triggered when a child is removed from the wrapped model.</summary>
   public event EventHandler<Efl.IModelChildRemovedEvt_Args> ChildRemovedEvt
   {
      add {
          model.ChildRemovedEvt += value;
      }
      remove {
          model.ChildRemovedEvt -= value;
      }
   }

   /// <summary>Event triggered when the number of children changes.</summary>
   public event EventHandler ChildrenCountChangedEvt
   {
      add {
          model.ChildrenCountChangedEvt += value;
      }
      remove {
          model.ChildrenCountChangedEvt -= value;
      }
   }
}

}

#endif