- Timestamp:
- 01/31/14 17:34:11 (11 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Job.cs
r9456 r10433 20 20 #endregion 21 21 22 using System; 22 23 using System.ComponentModel; 23 24 using System.Text; 25 using HeuristicLab.Collections; 24 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Core; … … 38 40 bool changed = dueDate != value; 39 41 dueDate = value; 40 if (changed) OnPropertyChanged("DueDate"); 42 if (changed) { 43 OnPropertyChanged("DueDate"); 44 OnToStringChanged(); 45 } 41 46 } 42 47 } … … 49 54 bool changed = index != value; 50 55 index = value; 51 if (changed) OnPropertyChanged("Index"); 56 if (changed) { 57 OnPropertyChanged("Index"); 58 OnToStringChanged(); 59 } 52 60 } 53 61 } … … 71 79 this.Index = original.Index; 72 80 this.Tasks = cloner.Clone(original.Tasks); 81 RegisterEventHandlers(); 73 82 } 74 83 public Job() : this(-1, double.MaxValue) { } … … 78 87 Index = index; 79 88 Tasks = new ItemList<Task>(); 89 RegisterEventHandlers(); 80 90 } 81 91 82 92 public override IDeepCloneable Clone(Cloner cloner) { 83 93 return new Job(this, cloner); 94 } 95 96 [StorableHook(HookType.AfterDeserialization)] 97 private void AfterDeserialization() { 98 RegisterEventHandlers(); 99 } 100 101 private void RegisterEventHandlers() { 102 Tasks.ItemsAdded += TasksOnItemsChanged; 103 Tasks.ItemsRemoved += TasksOnItemsChanged; 104 Tasks.ItemsReplaced += TasksOnItemsChanged; 105 Tasks.CollectionReset += TasksOnItemsChanged; 106 foreach (var task in Tasks) { 107 task.PropertyChanged += TaskOnPropertyChanged; 108 task.ToStringChanged += TaskOnToStringChanged; 109 } 110 } 111 112 private void TasksOnItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<Task>> e) { 113 foreach (var task in e.OldItems) { 114 task.Value.PropertyChanged -= TaskOnPropertyChanged; 115 task.Value.ToStringChanged -= TaskOnToStringChanged; 116 } 117 foreach (var task in e.Items) { 118 task.Value.PropertyChanged += TaskOnPropertyChanged; 119 task.Value.ToStringChanged += TaskOnToStringChanged; 120 } 121 OnTasksChanged(); 122 OnToStringChanged(); 123 } 124 125 private void TaskOnPropertyChanged(object sender, EventArgs e) { 126 OnTasksChanged(); 127 } 128 129 private void TaskOnToStringChanged(object sender, EventArgs e) { 130 OnToStringChanged(); 84 131 } 85 132 … … 100 147 } 101 148 149 public event EventHandler TasksChanged; 150 protected virtual void OnTasksChanged() { 151 var handler = TasksChanged; 152 if (handler != null) handler(this, EventArgs.Empty); 153 } 154 102 155 public event PropertyChangedEventHandler PropertyChanged; 103 156 protected virtual void OnPropertyChanged(string propertyName) { -
trunk/sources/HeuristicLab.Encodings.ScheduleEncoding/3.3/ScheduleEncoding/Task.cs
r9456 r10433 38 38 bool changed = taskNr != value; 39 39 taskNr = value; 40 if (changed) OnPropertyChanged("TaskNr"); 40 if (changed) { 41 OnPropertyChanged("TaskNr"); 42 OnToStringChanged(); 43 } 41 44 } 42 45 } … … 48 51 bool changed = resourceNr != value; 49 52 resourceNr = value; 50 if (changed) OnPropertyChanged("ResourceNr"); 53 if (changed) { 54 OnPropertyChanged("ResourceNr"); 55 OnToStringChanged(); 56 } 51 57 } 52 58 } … … 115 121 } 116 122 117 public override bool Equals(object obj) {118 if (obj.GetType() == typeof(Task))119 return AreEqual(this, obj as Task);120 else121 return false;122 }123 124 public override int GetHashCode() {125 return TaskNr ^ JobNr;126 }127 128 public static bool AreEqual(Task task1, Task task2) {129 return (task1.Duration == task2.Duration &&130 task1.IsScheduled == task2.IsScheduled &&131 task1.JobNr == task2.JobNr &&132 task1.ResourceNr == task2.ResourceNr &&133 task1.TaskNr == task2.TaskNr);134 }135 136 123 public event PropertyChangedEventHandler PropertyChanged; 137 124 protected virtual void OnPropertyChanged(string propertyName) {
Note: See TracChangeset
for help on using the changeset viewer.