diff -r 000000000000 -r 249d70e7b32d client/src/Iri.Modernisation.Controls/ViewModel/AnnotationMaker/AnnotationMakerVM.cs --- /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 +{ + + /// + /// ViewModel du module d'annotation + /// + public class AnnotationMakerVM : BaseMVVM.ViewModel.ViewModel + { + /// + /// Element référent + /// + 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"); + + } + } + + /// + /// Savoir si le module de liens est activé + /// + public bool IsBinderActive { get; set; } + public List RefTags + { + get + { + if (_refElement != null) + { + return _refElement.Tags; + } + else + { + return new List(); + } + } + } + + /// + /// Annotation créé + /// + private Annotation _newAnnotation; + + /// + /// Temps de début de l'annotation + /// + private TimeSpan _begin; + public double Begin + { + get + { + return _begin.TotalMilliseconds; + } + set + { + _begin = TimeSpan.FromMilliseconds(value); + _newAnnotation.TimerIn = TimeSpan.FromMilliseconds(value); + OnPropertyChanged("Begin"); + } + } + + /// + /// Temps de fin de l'annotation + /// + private TimeSpan _end; + public double End + { + get + { + return _end.TotalMilliseconds; + } + set + { + _end = TimeSpan.FromMilliseconds(value); + _newAnnotation.TimerOut = TimeSpan.FromMilliseconds(value); + OnPropertyChanged("End"); + } + } + + /// + /// Type de l'annotation + /// + private PolemicElementType _type; + public PolemicElementType Type + { + get + { + return _type; + } + set + { + _type = value; + _newAnnotation.Type = value; + OnPropertyChanged("Type"); + } + } + + /// + /// Convertion Rectange + /// + private Rectangle _selectedType; + public Rectangle SelectedType + { + get + { + return _selectedType; + } + set + { + _selectedType = value; + + Type = (PolemicElementType)((Rectangle)_selectedType).Resources["PolemicType"]; + } + } + + /// + /// Titre de l'annotation + /// + private String _title; + public String Title + { + get + { return _title; } + set + { + _title = value; + _newAnnotation.Title = value; + OnPropertyChanged("Title"); + } + } + + /// + /// Description de l'annotation + /// + private String _description; + public String Description + { + get + { + return _description; + } + set + { + _description = value; + _newAnnotation.Description = value; + OnPropertyChanged("Description"); + } + + } + + /// + /// Tags de l'annotation + /// + public List _tags =new List(); + 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"); + + + } + } + + /// + /// Relation basique + /// + private PolemicLink _basicRelation; + public PolemicLink BasicRelation + { + get + { + return _basicRelation; + } + set + { + _basicRelation = value; + OnPropertyChanged("BasicRelation"); + } + + + } + + /// + /// Relation polémique + /// + private PolemicLink _polemicRelation; + public PolemicLink PolemicRelation + { + get + { + + return _polemicRelation; + } + set + { + _polemicRelation = value; + OnPropertyChanged("PolemicRelation"); + } + + + } + + /// + /// Détermine si le control est activé ou non + /// + public bool IsControlEnable + { + get + { + return _refElement != null; + } + } + + /// + /// Permet d'initialiser les commands; + /// + private void InitializeCommands() + { + Commands.ContextualBinderLayer.BeginBind.Executed += new EventHandler(BeginBind_Executed); + Commands.ContextualBinderLayer.SelectBind.Executed += new EventHandler(SelectBind_Executed); + Commands.ContextualBinderLayer.ActiveBind.Executed += new EventHandler(ActiveBind_Executed); + Commands.ContextualBinderLayer.DesactiveBind.Executed += new EventHandler(DesactiveBind_Executed); + Commands.AnnotationMaker.OkClick.Executed += new EventHandler(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); + } + + /// + /// Constructeur par défaut + /// + public AnnotationMakerVM() + { + + InitializeCommands(); + + } + + /// + /// Constructeur par référence + /// + /// Element référant + 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(); + } + + + } + +}