client/src/Iri.Modernisation.Controls/ViewModel/AnnotationMaker/AnnotationMakerVM.cs
changeset 0 249d70e7b32d
child 25 a9c815025a1b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/Iri.Modernisation.Controls/ViewModel/AnnotationMaker/AnnotationMakerVM.cs	Wed Nov 18 15:30:31 2009 +0100
@@ -0,0 +1,361 @@
+using System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using System.Windows.Data;
+using SLExtensions.Input;
+using Iri.Modernisation.BaseMVVM.Commands;
+using Iri.Modernisation.Data.Models;
+using System.Collections.Generic;
+using System.Linq;
+using Iri.Modernisation.Controls.View;
+namespace Iri.Modernisation.Controls.ViewModel
+{
+
+    /// <summary>
+    /// ViewModel du module d'annotation
+    /// </summary>
+    public class AnnotationMakerVM : BaseMVVM.ViewModel.ViewModel
+    {
+        /// <summary>
+        /// Element référent
+        /// </summary>
+        private PolemicElement _refElement;
+        public PolemicElement RefElement
+        {
+            get
+            {
+                return _refElement;
+            }
+            set
+            {
+                _refElement = value;
+
+                _newAnnotation = new Annotation(((PolemicElement)value).Chapter);
+                Begin = ((PolemicElement)value).TimerIn.TotalMilliseconds;
+                End = ((PolemicElement)value).TimerOut.TotalMilliseconds;
+                BasicRelation = new PolemicLink() { FromElement = ((PolemicElement)value), ToElement = _newAnnotation, Type = PolemicElementType.Basic };
+                PolemicRelation = new PolemicLink();
+                PolemicRelation.FromElement = _newAnnotation;
+               
+                OnPropertyChanged(String.Empty);
+                //OnPropertyChanged("RefElement");
+                //OnPropertyChanged("IsControlEnable");
+                
+            }
+        }
+
+        /// <summary>
+        /// Savoir si le module de liens est activé
+        /// </summary>
+        public bool IsBinderActive { get; set; }
+        public List<String> RefTags
+        {
+            get
+            {
+                if (_refElement != null)
+                {
+                    return _refElement.Tags;
+                }
+                else
+                {
+                    return new List<String>();
+                }
+            }
+        }
+
+        /// <summary>
+        /// Annotation créé
+        /// </summary>
+        private Annotation _newAnnotation;
+
+        /// <summary>
+        /// Temps de début de l'annotation
+        /// </summary>
+        private TimeSpan _begin;
+        public double Begin 
+        {
+            get
+            {
+                return _begin.TotalMilliseconds;
+            }
+            set
+            {
+                _begin = TimeSpan.FromMilliseconds(value);
+                _newAnnotation.TimerIn = TimeSpan.FromMilliseconds(value);
+                OnPropertyChanged("Begin");
+            }
+        }
+
+        /// <summary>
+        /// Temps de fin de l'annotation
+        /// </summary>
+        private TimeSpan _end;
+        public double End
+        {
+            get
+            {
+                return _end.TotalMilliseconds;
+            }
+            set
+            {
+                _end = TimeSpan.FromMilliseconds(value);
+                _newAnnotation.TimerOut = TimeSpan.FromMilliseconds(value);
+                OnPropertyChanged("End");
+            }
+        }
+
+        /// <summary>
+        /// Type de l'annotation
+        /// </summary>
+        private PolemicElementType _type;
+        public PolemicElementType Type 
+        {
+            get
+            {
+                return _type;
+            }
+            set
+            {
+                _type = value;
+                _newAnnotation.Type = value;
+                OnPropertyChanged("Type");
+            }
+        }
+
+        /// <summary>
+        /// Convertion Rectange
+        /// </summary>
+        private Rectangle _selectedType;
+        public Rectangle SelectedType
+        {
+            get
+            {
+                return _selectedType;
+            }
+            set
+            {
+                _selectedType = value;
+               
+                Type = (PolemicElementType)((Rectangle)_selectedType).Resources["PolemicType"];
+            }
+        }
+
+        /// <summary>
+        /// Titre de l'annotation
+        /// </summary>
+        private String _title;
+        public String Title
+        {
+            get
+            { return _title; }
+            set
+            {
+                _title = value;
+                _newAnnotation.Title = value;
+                OnPropertyChanged("Title");
+            }
+        }
+
+        /// <summary>
+        /// Description de l'annotation
+        /// </summary>
+        private String _description;
+        public String Description
+        {
+            get
+            {
+                return _description;
+            }
+            set
+            {
+                _description = value;
+                _newAnnotation.Description = value;
+                OnPropertyChanged("Description");
+            }
+
+        }
+
+        /// <summary>
+        /// Tags de l'annotation
+        /// </summary>
+        public List<String> _tags =new List<String>();
+        public String Tags
+        {
+            get
+            {
+                try
+                {
+                    return String.Join(",", _tags.ToArray());
+                }
+                catch 
+                {
+                    return String.Empty;
+                }
+            }
+            set
+            {
+                String val = (String)value;
+                _tags = val.Split(',').ToList();
+                _newAnnotation.Tags = val.Split(',').ToList();
+                OnPropertyChanged("Tags");
+               
+                
+            }
+        }
+
+        /// <summary>
+        /// Relation basique
+        /// </summary>
+        private PolemicLink _basicRelation;
+        public PolemicLink BasicRelation
+        {
+            get
+            {
+                return _basicRelation;
+            }
+            set
+            {
+                _basicRelation = value;
+                OnPropertyChanged("BasicRelation");
+            }
+
+
+        }
+
+        /// <summary>
+        /// Relation polémique
+        /// </summary>
+        private PolemicLink _polemicRelation;
+        public PolemicLink PolemicRelation
+        {
+            get
+            {
+
+                return _polemicRelation;
+            }
+            set
+            {
+                _polemicRelation = value;
+                OnPropertyChanged("PolemicRelation");
+            }
+
+
+        }
+
+        /// <summary>
+        /// Détermine si le control est activé ou non
+        /// </summary>
+        public bool IsControlEnable
+        {
+            get
+            {
+                return _refElement != null;
+            }
+        }
+
+        /// <summary>
+        /// Permet d'initialiser les commands;
+        /// </summary>
+        private void InitializeCommands()
+        {
+            Commands.ContextualBinderLayer.BeginBind.Executed += new EventHandler<ExecutedEventArgs>(BeginBind_Executed);
+            Commands.ContextualBinderLayer.SelectBind.Executed += new EventHandler<ExecutedEventArgs>(SelectBind_Executed);
+            Commands.ContextualBinderLayer.ActiveBind.Executed += new EventHandler<ExecutedEventArgs>(ActiveBind_Executed);
+            Commands.ContextualBinderLayer.DesactiveBind.Executed += new EventHandler<ExecutedEventArgs>(DesactiveBind_Executed);
+            Commands.AnnotationMaker.OkClick.Executed += new EventHandler<ExecutedEventArgs>(OkClickAnnotationMaker_Executed);
+        }
+
+        void DesactiveBind_Executed(object sender, ExecutedEventArgs e)
+        {
+            IsBinderActive = false;
+        }
+
+        void ActiveBind_Executed(object sender, ExecutedEventArgs e)
+        {
+            IsBinderActive = true;
+        }
+
+      
+
+        void SelectBind_Executed(object sender, ExecutedEventArgs e)
+        {
+            if (IsControlEnable && IsBinderActive )
+            {
+                PolemicRelation.ToElement = (PolemicElement)e.Source;
+                OnPropertyChanged("PolemicRelation");
+            }
+                
+        }
+
+        void BeginBind_Executed(object sender, ExecutedEventArgs e)
+        {
+            if (IsControlEnable)
+            {
+                PolemicRelation.Type = ((ContextualLinkBinder)e.Parameter).PolemicType;
+                PolemicRelation.ToElement = null;
+                OnPropertyChanged("PolemicRelation");
+                
+            }
+
+        }
+
+      
+
+        void OkClickAnnotationMaker_Executed(object sender, ExecutedEventArgs e)
+        {
+            String message = "Ok clicked "+Type+" \n";
+            message += _begin + "-->" + _end;
+            message += "\n" + Title;
+            message += "\n" + Description;
+            
+                foreach (string tag in _tags)
+                {
+                    message += "\n|-" + tag;
+                }
+
+                message += "PolemicLink "+PolemicRelation.Type;
+            MessageBox.Show(message);
+        }
+
+        /// <summary>
+        /// Constructeur par défaut
+        /// </summary>
+        public AnnotationMakerVM()
+        {
+
+            InitializeCommands();
+
+        }
+
+        /// <summary>
+        /// Constructeur par référence
+        /// </summary>
+        /// <param name="refAParam">Element référant</param>
+        public AnnotationMakerVM(PolemicElement refAParam)
+        {
+
+
+            RefElement = refAParam;
+
+
+
+            _newAnnotation = new Annotation(RefElement.Chapter);
+            _begin = RefElement.TimerIn;
+            _end = RefElement.TimerOut;
+            _basicRelation = new PolemicLink() { FromElement = RefElement, ToElement = _newAnnotation, Type = PolemicElementType.Basic };
+            _polemicRelation = new PolemicLink();
+            PolemicRelation.FromElement = _newAnnotation;
+            InitializeCommands();
+        }
+
+
+    }
+   
+}