client/src/Iri.Modernisation.Controls/View/HeaderProduction/HeaderProductionPartControler.xaml.cs
author Matthieu Totet
Mon, 04 Jan 2010 10:29:39 +0100
changeset 27 f292db96b050
parent 16 dde0338cb539
child 38 bd33267300aa
permissions -rw-r--r--
Generalization of Book Structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
     1
using System;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
     2
using System.Windows;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
     3
using System.Windows.Controls;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
     4
using System.Windows.Documents;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
     5
using System.Windows.Ink;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
     6
using System.Windows.Input;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
     7
using System.Windows.Media;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
     8
using System.Windows.Media.Animation;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
     9
using System.Windows.Shapes;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    10
using System.Windows.Data;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    11
namespace Iri.Modernisation.Controls.View
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    12
{
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    13
	public partial class HeaderProductionPartControler : UserControl
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    14
	{
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    15
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    16
		public bool HighLighted
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    17
        {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    18
            get { return (bool)GetValue(HighLightProperty); }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    19
            set { 
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    20
                
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    21
                SetValue(HighLightProperty, value); 
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    22
            }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    23
        }
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    24
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    25
        // Using a DependencyProperty as the backing store for HighLight.  This enables animation, styling, binding, etc...
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    26
        public static readonly DependencyProperty HighLightProperty =
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    27
            DependencyProperty.Register("HighLighted", typeof(bool), typeof(HeaderProductionPartControler), new PropertyMetadata(new PropertyChangedCallback(HighLightChange)));
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    28
        private static void HighLightChange(DependencyObject sender, DependencyPropertyChangedEventArgs e)
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    29
        {
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    30
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    31
            if((bool)e.NewValue)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    32
            {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    33
                ((HeaderProductionPartControler)sender).Select();
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    34
            }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    35
            else
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    36
            {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    37
                ((HeaderProductionPartControler)sender).UnSelect();
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    38
            }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    39
        }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    40
        public bool Active
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    41
        {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    42
            get { return (bool)GetValue(ActiveProperty); }
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    43
            set 
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    44
            { 
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    45
                
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    46
               
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    47
                SetValue(ActiveProperty, value);
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    48
                if (value)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    49
                {
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    50
                    Activate();
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    51
                    if (HighLighted)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    52
                    {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    53
                        Select();
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    54
                    }
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    55
                }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    56
                else
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    57
                {
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    58
                }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    59
            }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    60
        }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    61
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    62
        // Using a DependencyProperty as the backing store for IsActive.  This enables animation, styling, binding, etc...
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    63
        public  static readonly DependencyProperty ActiveProperty =
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    64
            DependencyProperty.Register("Active", typeof(bool), typeof(HeaderProductionPartControler), new PropertyMetadata(new PropertyChangedCallback(ItemsSourceChanged)));
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    65
        private static void ItemsSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    66
        {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    67
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    68
            ((HeaderProductionPartControler)sender).Active =(bool)e.NewValue;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    69
        }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    70
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    71
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    72
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    73
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    74
        public String Text
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    75
        {
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    76
            get { return (String)GetValue(TextProperty); }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    77
            set 
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    78
            { SetValue(TextProperty, value); 
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    79
                textBlock.Text = value; 
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    80
            }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    81
        }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    82
            
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    83
        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    84
        public static readonly DependencyProperty TextProperty =
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    85
            DependencyProperty.Register("Text", typeof(String), typeof(HeaderProductionPartControler), new PropertyMetadata(""));
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    86
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    87
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    88
		
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    89
		public HeaderProductionPartControler()
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    90
		{
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    91
			// Required to initialize variables
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    92
			InitializeComponent();
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
    93
           
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    94
			_activated = false;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    95
			_finished= false;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    96
          
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    97
            
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    98
           
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
    99
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   100
		}
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   101
		
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   102
        private bool _activated;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   103
		private bool _finished;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   104
		
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
   105
		public void Activate()
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   106
		{
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   107
			if(!_activated && !_finished)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   108
			{
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   109
				VisualStateManager.GoToState(this,"Available",true);
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   110
				_activated=true;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   111
			}
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   112
            
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   113
		}
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   114
		
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   115
		public void UnSelect()
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   116
		{
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
   117
            if (_activated && !_finished)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
   118
            {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
   119
                VisualStateManager.GoToState(this, "Available", true);
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents: 16
diff changeset
   120
            }
16
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   121
		}
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   122
		private void Button_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   123
		{
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   124
           
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   125
		
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   126
		}
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   127
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   128
		private void but_Click(object sender, System.Windows.RoutedEventArgs e)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   129
		{
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   130
		     	
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   131
				if(_activated)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   132
				{
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   133
					VisualStateManager.GoToState(this,"Finished",true);
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   134
                    if (HeaderProductionPartFinished!=null)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   135
                    {
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   136
                      HeaderProductionPartFinished(this, new HeaderProductionPartControlerEventArgs(sender));
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   137
                    }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   138
					_finished=true;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   139
                    
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   140
				}
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   141
		}
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   142
        public void Select()
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   143
        {
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   144
            if (_activated && !_finished)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   145
            {
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   146
                VisualStateManager.GoToState(this, "Selected", true);
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   147
            }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   148
        }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   149
		private void textBlock_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   150
		{
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   151
            if (_activated && !_finished)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   152
            {
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   153
                if (HeaderProductionPartSelected != null)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   154
                    HeaderProductionPartSelected(this, new HeaderProductionPartControlerEventArgs(this));
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   155
            }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   156
        }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   157
        public event EventHandler<HeaderProductionPartControlerEventArgs> HeaderProductionPartFinished;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   158
        public event EventHandler<HeaderProductionPartControlerEventArgs> HeaderProductionPartSelected;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   159
	}
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   160
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   161
    public class HeaderProductionPartControlerEventArgs : EventArgs
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   162
    {
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   163
        public object sender { get; set; }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   164
        public HeaderProductionPartControlerEventArgs(object psender)
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   165
        {
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   166
            sender = psender;
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   167
        }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   168
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   169
    }
dde0338cb539 Update ProductionView and Components
Matthieu Totet
parents:
diff changeset
   170
}