2 using System.Reflection;
3 using System.Collections;
4 using System.Collections.Generic;
6 namespace Tizen.NUI.Binding
8 internal abstract class TriggerBase : BindableObject, IAttachedObject
12 internal TriggerBase(Type targetType)
14 if (targetType == null)
15 throw new ArgumentNullException("targetType");
16 TargetType = targetType;
18 EnterActions = new SealedList<TriggerAction>();
19 ExitActions = new SealedList<TriggerAction>();
22 internal TriggerBase(Condition condition, Type targetType) : this(targetType)
24 Setters = new SealedList<Setter>();
25 Condition = condition;
26 Condition.ConditionChanged = OnConditionChanged;
29 public IList<TriggerAction> EnterActions { get; }
31 public IList<TriggerAction> ExitActions { get; }
35 get { return _isSealed; }
38 if (_isSealed == value)
41 throw new InvalidOperationException("What is sealed can not be unsealed.");
47 public Type TargetType { get; }
49 internal Condition Condition { get; }
51 //Setters and Condition are used by Trigger, DataTrigger and MultiTrigger
52 internal IList<Setter> Setters { get; }
54 void IAttachedObject.AttachTo(BindableObject bindable)
59 throw new ArgumentNullException("bindable");
60 if (!TargetType.IsInstanceOfType(bindable))
61 throw new InvalidOperationException("bindable not an instance of AssociatedType");
62 OnAttachedTo(bindable);
65 void IAttachedObject.DetachFrom(BindableObject bindable)
68 throw new ArgumentNullException("bindable");
69 OnDetachingFrom(bindable);
72 internal virtual void OnAttachedTo(BindableObject bindable)
74 if (Condition != null)
75 Condition.SetUp(bindable);
78 internal virtual void OnDetachingFrom(BindableObject bindable)
80 if (Condition != null)
81 Condition.TearDown(bindable);
84 internal virtual void OnSeal()
86 ((SealedList<TriggerAction>)EnterActions).IsReadOnly = true;
87 ((SealedList<TriggerAction>)ExitActions).IsReadOnly = true;
89 ((SealedList<Setter>)Setters).IsReadOnly = true;
90 if (Condition != null)
91 Condition.IsSealed = true;
94 void OnConditionChanged(BindableObject bindable, bool oldValue, bool newValue)
98 foreach (TriggerAction action in EnterActions)
99 action.DoInvoke(bindable);
100 foreach (Setter setter in Setters)
101 setter.Apply(bindable);
105 foreach (Setter setter in Setters)
106 setter.UnApply(bindable);
107 foreach (TriggerAction action in ExitActions)
108 action.DoInvoke(bindable);
112 internal class SealedList<T> : IList<T>
114 readonly IList<T> _actual;
120 _actual = new List<T>();
123 public void Add(T item)
126 throw new InvalidOperationException("This list is ReadOnly");
133 throw new InvalidOperationException("This list is ReadOnly");
137 public bool Contains(T item)
139 return _actual.Contains(item);
142 public void CopyTo(T[] array, int arrayIndex)
144 _actual.CopyTo(array, arrayIndex);
149 get { return _actual.Count; }
152 public bool IsReadOnly
154 get { return _isReadOnly; }
157 if (_isReadOnly == value)
160 throw new InvalidOperationException("Can't change this back to non readonly");
165 public bool Remove(T item)
168 throw new InvalidOperationException("This list is ReadOnly");
169 return _actual.Remove(item);
172 IEnumerator IEnumerable.GetEnumerator()
174 return ((IEnumerable)_actual).GetEnumerator();
177 public IEnumerator<T> GetEnumerator()
179 return _actual.GetEnumerator();
182 public int IndexOf(T item)
184 return _actual.IndexOf(item);
187 public void Insert(int index, T item)
190 throw new InvalidOperationException("This list is ReadOnly");
191 _actual.Insert(index, item);
194 public T this[int index]
196 get { return _actual[index]; }
200 throw new InvalidOperationException("This list is ReadOnly");
201 _actual[index] = value;
205 public void RemoveAt(int index)
208 throw new InvalidOperationException("This list is ReadOnly");
209 _actual.RemoveAt(index);