using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using Eina;
#if EFL_BETA
namespace Efl {
/// Generic implementation for MVVM models based on
public class GenericModel : Efl.Object, Efl.IModel, IDisposable
{
private Efl.IModel model;
/// Creates a new model wrapping model.
public GenericModel (Efl.IModel model, Efl.Object parent = null) : base(parent)
{
this.model = model;
}
/// The list of properties available in the wrapped model.
public Eina.Iterator< System.String> Properties
{
get { return GetProperties(); }
}
/// The number of children in the wrapped model.
public uint ChildrenCount
{
get { return GetChildrenCount(); }
}
/// The list of properties available in the wrapped model.
public Eina.Iterator GetProperties()
{
return model.GetProperties();
}
/// Gets the value of the given property in the wrapped model.
public Eina.Value GetProperty( System.String property)
{
return model.GetProperty(property);
}
/// Sets the value of the given property in the given model.
public Eina.Future SetProperty( System.String property, Eina.Value value)
{
return model.SetProperty(property, value);
}
/// Returns the number of children in the wrapped model.
public uint GetChildrenCount()
{
return model.GetChildrenCount();
}
/// Returns an that will resolve when the property is ready to be read.
public Eina.Future GetPropertyReady( System.String property)
{
return model.GetPropertyReady(property);
}
/// Gets a number of children from the wrapped model.
public Eina.Future GetChildrenSlice( uint start, uint count)
{
return model.GetChildrenSlice(start, count);
}
/// Adds a new object to the wrapper model.
public void Add(T o)
{
Efl.IModel child = (Efl.IModel)this.AddChild();
ModelHelper.SetProperties(o, child);
}
/// Adds a new childs to the model and returns it.
public Efl.Object AddChild()
{
return model.AddChild();
}
/// Deletes the given child from the wrapped model.
public void DelChild( Efl.Object child)
{
model.DelChild(child);
}
/// Gets the element at the specified index.
async public System.Threading.Tasks.Task 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");
}
}
}
/// Async wrapper around .
public System.Threading.Tasks.Task SetPropertyAsync( System.String property, Eina.Value value, System.Threading.CancellationToken token=default(System.Threading.CancellationToken))
{
return model.SetPropertyAsync(property, value, token);
}
/// Async wrapper around .
public System.Threading.Tasks.Task GetPropertyReadyAsync( System.String property, System.Threading.CancellationToken token=default(System.Threading.CancellationToken))
{
return model.GetPropertyReadyAsync(property, token);
}
/// Async wrapper around .
public System.Threading.Tasks.Task GetChildrenSliceAsync( uint start, uint count, System.Threading.CancellationToken token=default(System.Threading.CancellationToken))
{
return model.GetChildrenSliceAsync(start, count, token);
}
/// Event triggered when properties on the wrapped model changes.
public event EventHandler PropertiesChangedEvt
{
add {
model.PropertiesChangedEvt += value;
}
remove {
model.PropertiesChangedEvt -= value;
}
}
/// Event triggered when a child is added from the wrapped model.
public event EventHandler ChildAddedEvt
{
add {
model.ChildAddedEvt += value;
}
remove {
model.ChildAddedEvt -= value;
}
}
/// Event triggered when a child is removed from the wrapped model.
public event EventHandler ChildRemovedEvt
{
add {
model.ChildRemovedEvt += value;
}
remove {
model.ChildRemovedEvt -= value;
}
}
/// Event triggered when the number of children changes.
public event EventHandler ChildrenCountChangedEvt
{
add {
model.ChildrenCountChangedEvt += value;
}
remove {
model.ChildrenCountChangedEvt -= value;
}
}
}
}
#endif