[8886] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8886] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.ComponentModel;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Encodings.ScheduleEncoding.Views {
|
---|
| 29 | [View("JobView")]
|
---|
| 30 | [Content(typeof(Job))]
|
---|
| 31 | public partial class JobView : ItemView {
|
---|
| 32 | private ItemListView<Task> tasksView;
|
---|
[8887] | 33 | protected bool SuppressEvents = false;
|
---|
[8886] | 34 |
|
---|
| 35 | public new Job Content {
|
---|
| 36 | get { return (Job)base.Content; }
|
---|
| 37 | set { base.Content = value; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public JobView() {
|
---|
| 41 | InitializeComponent();
|
---|
| 42 | tasksView = new ItemListView<Task> { Dock = DockStyle.Fill };
|
---|
| 43 | tasksGroupBox.Controls.Add(tasksView);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | protected override void DeregisterContentEvents() {
|
---|
| 47 | Content.PropertyChanged -= Content_PropertyChanged;
|
---|
| 48 | base.DeregisterContentEvents();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | protected override void RegisterContentEvents() {
|
---|
| 52 | base.RegisterContentEvents();
|
---|
| 53 | Content.PropertyChanged += Content_PropertyChanged;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | protected override void OnContentChanged() {
|
---|
| 57 | base.OnContentChanged();
|
---|
| 58 | if (Content == null) {
|
---|
| 59 | indexTextBox.Text = String.Empty;
|
---|
| 60 | dueDateTextBox.Text = String.Empty;
|
---|
| 61 | tasksView.Content = null;
|
---|
| 62 | } else {
|
---|
| 63 | SuppressEvents = true;
|
---|
| 64 | try {
|
---|
| 65 | indexTextBox.Text = Content.Index.ToString();
|
---|
| 66 | dueDateTextBox.Text = Content.DueDate.ToString("r");
|
---|
| 67 | } finally { SuppressEvents = false; }
|
---|
| 68 | tasksView.Content = Content.Tasks;
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | protected override void SetEnabledStateOfControls() {
|
---|
| 73 | base.SetEnabledStateOfControls();
|
---|
| 74 | indexTextBox.Enabled = !ReadOnly && !Locked && Content != null;
|
---|
| 75 | dueDateTextBox.Enabled = !ReadOnly && !Locked && Content != null;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 79 | SuppressEvents = true;
|
---|
| 80 | try {
|
---|
| 81 | switch (e.PropertyName) {
|
---|
| 82 | case "Index":
|
---|
| 83 | indexTextBox.Text = Content.Index.ToString();
|
---|
| 84 | break;
|
---|
| 85 | case "DueDate":
|
---|
| 86 | dueDateTextBox.Text = Content.DueDate.ToString("r");
|
---|
| 87 | break;
|
---|
| 88 | case "Tasks":
|
---|
| 89 | tasksView.Content = Content.Tasks;
|
---|
| 90 | break;
|
---|
| 91 | default:
|
---|
| 92 | break;
|
---|
| 93 | }
|
---|
| 94 | } finally {
|
---|
| 95 | SuppressEvents = false;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | private void indexTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 100 | if (!SuppressEvents && Content != null && indexTextBox.Enabled) {
|
---|
| 101 | int value;
|
---|
| 102 | if (int.TryParse(indexTextBox.Text, out value)) {
|
---|
| 103 | Content.Index = value;
|
---|
| 104 | errorProvider.SetError(indexTextBox, String.Empty);
|
---|
| 105 | } else {
|
---|
| 106 | e.Cancel = true;
|
---|
| 107 | errorProvider.SetError(indexTextBox, "Please provide a valid integer.");
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | private void dueDateTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 113 | if (!SuppressEvents && Content != null && dueDateTextBox.Enabled) {
|
---|
| 114 | double value;
|
---|
| 115 | if (double.TryParse(dueDateTextBox.Text, out value)) {
|
---|
| 116 | Content.DueDate = value;
|
---|
| 117 | errorProvider.SetError(dueDateTextBox, String.Empty);
|
---|
| 118 | } else {
|
---|
| 119 | e.Cancel = true;
|
---|
| 120 | errorProvider.SetError(dueDateTextBox, "Please provide a valid double.");
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|