Changeset 18017


Ignore:
Timestamp:
07/17/21 18:18:41 (2 weeks ago)
Author:
gkronber
Message:

#3024: merged r17223,r17268,r17273,r17274 from trunk to stable

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Clients.Hive.Administrator

  • stable/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectView.Designer.cs

    r17063 r18017  
    3939      this.endLabel = new System.Windows.Forms.Label();
    4040      this.indefiniteCheckBox = new System.Windows.Forms.CheckBox();
    41       this.createdTextBox = new System.Windows.Forms.TextBox();     
     41      this.createdTextBox = new System.Windows.Forms.TextBox();
    4242      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
     43      this.refreshButton = new System.Windows.Forms.Button();
    4344      this.SuspendLayout();
    4445      //
     
    6869      this.nameLabel.Name = "nameLabel";
    6970      this.nameLabel.Size = new System.Drawing.Size(38, 13);
    70       this.nameLabel.TabIndex = 0;
     71      this.nameLabel.TabIndex = 2;
    7172      this.nameLabel.Text = "Name:";
    7273      //
     
    7879      this.nameTextBox.Name = "nameTextBox";
    7980      this.nameTextBox.Size = new System.Drawing.Size(464, 20);
    80       this.nameTextBox.TabIndex = 2;
     81      this.nameTextBox.TabIndex = 3;
    8182      this.nameTextBox.TextChanged += new System.EventHandler(this.nameTextBox_TextChanged);
    8283      this.nameTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.nameTextBox_Validating);
     
    8889      this.descriptionLabel.Name = "descriptionLabel";
    8990      this.descriptionLabel.Size = new System.Drawing.Size(63, 13);
    90       this.descriptionLabel.TabIndex = 0;
     91      this.descriptionLabel.TabIndex = 4;
    9192      this.descriptionLabel.Text = "Description:";
    9293      //
     
    99100      this.descriptionTextBox.Name = "descriptionTextBox";
    100101      this.descriptionTextBox.Size = new System.Drawing.Size(464, 98);
    101       this.descriptionTextBox.TabIndex = 3;
     102      this.descriptionTextBox.TabIndex = 5;
    102103      this.descriptionTextBox.TextChanged += new System.EventHandler(this.descriptionTextBox_TextChanged);
    103104      //
    104       // ownerLabel
    105       //
    106       this.ownerLabel.AutoSize = true;
    107       this.ownerLabel.Location = new System.Drawing.Point(3, 167);
    108       this.ownerLabel.Name = "ownerLabel";
    109       this.ownerLabel.Size = new System.Drawing.Size(41, 13);
    110       this.ownerLabel.TabIndex = 0;
    111       this.ownerLabel.Text = "Owner:";
    112       //
    113105      // ownerComboBox
    114106      //
    115       //this.ownerComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    116       //      | System.Windows.Forms.AnchorStyles.Right)));
    117107      this.ownerComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    118108      this.ownerComboBox.FormattingEnabled = true;
     
    120110      this.ownerComboBox.Name = "ownerComboBox";
    121111      this.ownerComboBox.Size = new System.Drawing.Size(200, 21);
    122       this.ownerComboBox.TabIndex = 4;
     112      this.ownerComboBox.TabIndex = 7;
    123113      this.ownerComboBox.SelectedIndexChanged += new System.EventHandler(this.ownerComboBox_SelectedIndexChanged);
     114      //
     115      // ownerLabel
     116      //
     117      this.ownerLabel.AutoSize = true;
     118      this.ownerLabel.Location = new System.Drawing.Point(3, 167);
     119      this.ownerLabel.Name = "ownerLabel";
     120      this.ownerLabel.Size = new System.Drawing.Size(41, 13);
     121      this.ownerLabel.TabIndex = 6;
     122      this.ownerLabel.Text = "Owner:";
    124123      //
    125124      // createdLabel
     
    129128      this.createdLabel.Name = "createdLabel";
    130129      this.createdLabel.Size = new System.Drawing.Size(47, 13);
    131       this.createdLabel.TabIndex = 8;
     130      this.createdLabel.TabIndex = 9;
    132131      this.createdLabel.Text = "Created:";
    133132      //
     
    135134      //
    136135      this.startDateTimePicker.CustomFormat = "ddd, dd.MM.yyyy, HH:mm:ss";
    137       this.startDateTimePicker.Enabled = false;
    138136      this.startDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
    139137      this.startDateTimePicker.Location = new System.Drawing.Point(72, 216);
    140138      this.startDateTimePicker.Name = "startDateTimePicker";
    141139      this.startDateTimePicker.Size = new System.Drawing.Size(200, 20);
    142       this.startDateTimePicker.TabIndex = 9;
    143       this.startDateTimePicker.ValueChanged += new System.EventHandler(this.startDateTimePicker_ValueChanged);     
     140      this.startDateTimePicker.TabIndex = 12;
     141      this.startDateTimePicker.ValueChanged += new System.EventHandler(this.startDateTimePicker_ValueChanged);
    144142      //
    145143      // startLabel
     
    149147      this.startLabel.Name = "startLabel";
    150148      this.startLabel.Size = new System.Drawing.Size(32, 13);
    151       this.startLabel.TabIndex = 10;
     149      this.startLabel.TabIndex = 11;
    152150      this.startLabel.Text = "Start:";
    153151      //
     
    155153      //
    156154      this.endDateTimePicker.CustomFormat = "ddd, dd.MM.yyyy, HH:mm:ss";
    157       this.endDateTimePicker.Enabled = false;
    158155      this.endDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
    159156      this.endDateTimePicker.Location = new System.Drawing.Point(72, 243);
    160157      this.endDateTimePicker.Name = "endDateTimePicker";
    161158      this.endDateTimePicker.Size = new System.Drawing.Size(200, 20);
    162       this.endDateTimePicker.TabIndex = 11;
     159      this.endDateTimePicker.TabIndex = 14;
    163160      this.endDateTimePicker.ValueChanged += new System.EventHandler(this.endDateTimePicker_ValueChanged);
    164161      //
     
    169166      this.endLabel.Name = "endLabel";
    170167      this.endLabel.Size = new System.Drawing.Size(29, 13);
    171       this.endLabel.TabIndex = 10;
     168      this.endLabel.TabIndex = 13;
    172169      this.endLabel.Text = "End:";
    173170      //
     
    178175      this.indefiniteCheckBox.Name = "indefiniteCheckBox";
    179176      this.indefiniteCheckBox.Size = new System.Drawing.Size(69, 17);
    180       this.indefiniteCheckBox.TabIndex = 13;
     177      this.indefiniteCheckBox.TabIndex = 15;
    181178      this.indefiniteCheckBox.Text = "Indefinite";
    182179      this.indefiniteCheckBox.UseVisualStyleBackColor = true;
     
    189186      this.createdTextBox.ReadOnly = true;
    190187      this.createdTextBox.Size = new System.Drawing.Size(200, 20);
    191       this.createdTextBox.TabIndex = 14;
     188      this.createdTextBox.TabIndex = 10;
     189      //
     190      // refreshButton
     191      //
     192      this.refreshButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Refresh;
     193      this.refreshButton.Location = new System.Drawing.Point(278, 162);
     194      this.refreshButton.Name = "refreshButton";
     195      this.refreshButton.Size = new System.Drawing.Size(24, 24);
     196      this.refreshButton.TabIndex = 8;
     197      this.refreshButton.UseVisualStyleBackColor = true;
     198      this.refreshButton.Click += new System.EventHandler(this.refreshButton_Click);
    192199      //
    193200      // ProjectView
     
    195202      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    196203      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     204      this.Controls.Add(this.refreshButton);
    197205      this.Controls.Add(this.createdTextBox);
    198206      this.Controls.Add(this.indefiniteCheckBox);
     
    213221      this.Size = new System.Drawing.Size(539, 271);
    214222      this.Load += new System.EventHandler(this.ProjectView_Load);
    215       this.Disposed += new System.EventHandler(this.ProjectView_Disposed);
    216223      this.ResumeLayout(false);
    217224      this.PerformLayout();
     
    235242    private System.Windows.Forms.Label endLabel;
    236243    private System.Windows.Forms.CheckBox indefiniteCheckBox;
    237     private System.Windows.Forms.TextBox createdTextBox;   
     244    private System.Windows.Forms.TextBox createdTextBox;
    238245    private System.Windows.Forms.ToolTip toolTip;
     246    private System.Windows.Forms.Button refreshButton;
    239247  }
    240248}
  • stable/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectView.cs

    r17181 r18017  
    2828using HeuristicLab.Core.Views;
    2929using HeuristicLab.MainForm;
     30using Tpl = System.Threading.Tasks;
    3031
    3132namespace HeuristicLab.Clients.Hive.Administrator.Views {
     
    3334  [Content(typeof(Project), IsDefaultView = true)]
    3435  public partial class ProjectView : ItemView {
    35     private readonly object locker = new object();
    36 
    3736    public new Project Content {
    3837      get { return (Project)base.Content; }
     
    5857    }
    5958
    60     protected void RegisterControlEvents() {
    61       nameTextBox.TextChanged += nameTextBox_TextChanged;
    62       nameTextBox.Validating += nameTextBox_Validating;
    63       descriptionTextBox.TextChanged += descriptionTextBox_TextChanged;
    64       ownerComboBox.SelectedIndexChanged += ownerComboBox_SelectedIndexChanged;
    65       startDateTimePicker.ValueChanged += startDateTimePicker_ValueChanged;
    66       endDateTimePicker.ValueChanged += endDateTimePicker_ValueChanged;
    67       indefiniteCheckBox.CheckedChanged += indefiniteCheckBox_CheckedChanged;
    68     }
    69 
    70     protected void DeregisterControlEvents() {
    71       nameTextBox.TextChanged -= nameTextBox_TextChanged;
    72       nameTextBox.Validating -= nameTextBox_Validating;
    73       descriptionTextBox.TextChanged -= descriptionTextBox_TextChanged;
    74       ownerComboBox.SelectedIndexChanged -= ownerComboBox_SelectedIndexChanged;
    75       startDateTimePicker.ValueChanged -= startDateTimePicker_ValueChanged;
    76       endDateTimePicker.ValueChanged -= endDateTimePicker_ValueChanged;
    77       indefiniteCheckBox.CheckedChanged -= indefiniteCheckBox_CheckedChanged;
    78     }
    79 
    8059    protected override void OnContentChanged() {
    8160      base.OnContentChanged();
    82       DeregisterControlEvents();
     61      UpdateView();
     62    }
     63
     64    private void UpdateView() {
    8365      if (Content == null) {
    8466        idTextBox.Clear();
     
    9476        nameTextBox.Text = Content.Name;
    9577        descriptionTextBox.Text = Content.Description;
    96 
    97         ownerComboBox.SelectedIndexChanged -= ownerComboBox_SelectedIndexChanged;
    98         if (AccessClient.Instance.UsersAndGroups != null) {
    99           var users = AccessClient.Instance.UsersAndGroups.OfType<LightweightUser>();
    100           if (!Content.ParentProjectId.HasValue) users = users.Where(x => x.Roles.Select(y => y.Name).Contains(HiveRoles.Administrator));
    101           var projectOwnerId = Content.OwnerUserId;
    102           ownerComboBox.DataSource = users.OrderBy(x => x.UserName).ToList();
    103           ownerComboBox.SelectedItem = users.FirstOrDefault(x => x.Id == projectOwnerId);
    104         }
    105         ownerComboBox.SelectedIndexChanged += ownerComboBox_SelectedIndexChanged;
    106 
     78        ownerComboBox.SelectedItem = AccessClient.Instance.UsersAndGroups?.OfType<LightweightUser>().SingleOrDefault(x => x.Id == Content.OwnerUserId);
    10779        createdTextBox.Text = Content.DateCreated.ToString("ddd, dd.MM.yyyy, HH:mm:ss");
    10880        startDateTimePicker.Value = Content.StartDate;
    109 
     81        endDateTimePicker.Value = Content.EndDate.GetValueOrDefault(Content.StartDate);
    11082        indefiniteCheckBox.Checked = !Content.EndDate.HasValue;
    111         if (!indefiniteCheckBox.Checked) endDateTimePicker.Value = Content.EndDate.Value;
    112         else endDateTimePicker.Value = Content.StartDate;
    113         endDateTimePicker.Enabled = !indefiniteCheckBox.Checked;
    114       }
    115       SetEnabledStateOfControls();
    116       RegisterControlEvents();
    117     }
    118 
    119     protected override void SetEnabledStateOfControls() {
    120       base.SetEnabledStateOfControls();
    121       bool enabled = Content != null && !Locked && !ReadOnly;
    122       nameTextBox.Enabled = enabled;
    123       descriptionTextBox.Enabled = enabled;
    124       ownerComboBox.Enabled = enabled;
    125       createdTextBox.Enabled = enabled;
    126       startDateTimePicker.Enabled = enabled;
    127       endDateTimePicker.Enabled = enabled && Content.EndDate.HasValue;
    128       indefiniteCheckBox.Enabled = enabled;
    129 
    130       if (Content != null) {
    131         //var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault();
    132         var parentProject = HiveAdminClient.Instance.Projects.FirstOrDefault(x => x.Id == Content.ParentProjectId);
    133         if ((!IsAdmin() && (parentProject == null || parentProject.EndDate.HasValue))
    134            || (IsAdmin() && parentProject != null && parentProject.EndDate.HasValue)) {
    135           indefiniteCheckBox.Enabled = false;
    136         }
    137 
    138         if (Content.Id != Guid.Empty && !IsAdmin() && !HiveAdminClient.Instance.CheckOwnershipOfParentProject(Content, UserInformation.Instance.User.Id)) {
    139           ownerComboBox.Enabled = false;
    140           startDateTimePicker.Enabled = false;
    141           endDateTimePicker.Enabled = false;
    142           indefiniteCheckBox.Enabled = false;
    143         }
    144       }
    145     }
    146     #endregion
    147 
    148     #region Event Handlers
    149     private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    150       if (InvokeRequired) Invoke((Action<object, PropertyChangedEventArgs>)Content_PropertyChanged, sender, e);
    151       else OnContentChanged();
    152     }
    153 
    154     private void AccessClient_Instance_Refreshing(object sender, EventArgs e) {
    155       if (InvokeRequired) Invoke((Action<object, EventArgs>)AccessClient_Instance_Refreshing, sender, e);
    156       else {
    157         Progress.Show(this, "Refreshing ...", ProgressMode.Indeterminate);
    158         SetEnabledStateOfControls();
    159       }
    160     }
    161 
    162     private void AccessClient_Instance_Refreshed(object sender, EventArgs e) {
    163       if (InvokeRequired) Invoke((Action<object, EventArgs>)AccessClient_Instance_Refreshed, sender, e);
    164       else {
    165         Progress.Hide(this);
    166         SetEnabledStateOfControls();
    167       }
    168     }
    169 
    170     private async void ProjectView_Load(object sender, EventArgs e) {
    171       await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
    172         action: () => UpdateUsers(),
    173         finallyCallback: () => {
    174           ownerComboBox.SelectedIndexChanged -= ownerComboBox_SelectedIndexChanged;
    175           var users = AccessClient.Instance.UsersAndGroups.OfType<LightweightUser>();
    176           if (Content != null && !Content.ParentProjectId.HasValue) users = users.Where(x => x.Roles.Select(y => y.Name).Contains(HiveRoles.Administrator));
    177           ownerComboBox.DataSource = users.OrderBy(x => x.UserName).ToList();
    178           ownerComboBox.SelectedIndexChanged += ownerComboBox_SelectedIndexChanged;
    179         });
    180     }
    181 
    182     private void ProjectView_Disposed(object sender, EventArgs e) {
    183       AccessClient.Instance.Refreshed -= AccessClient_Instance_Refreshed;
    184       AccessClient.Instance.Refreshing -= AccessClient_Instance_Refreshing;
    185     }
    186 
    187     private void nameTextBox_Validating(object sender, CancelEventArgs e) {
    188       if (string.IsNullOrEmpty(nameTextBox.Text)) {
    189         MessageBox.Show(
    190           "Project must have a name.",
    191           "HeuristicLab Hive Administrator",
    192           MessageBoxButtons.OK,
    193           MessageBoxIcon.Error);
    194         e.Cancel = true;
    195       }
    196     }
    197 
    198     private void nameTextBox_TextChanged(object sender, EventArgs e) {
    199       if (Content != null && Content.Name != nameTextBox.Text) {
    200         DeregisterContentEvents();
    201         Content.Name = nameTextBox.Text;
    202         RegisterContentEvents();
    203       }
    204     }
    205 
    206     private void descriptionTextBox_TextChanged(object sender, EventArgs e) {
    207       if (Content != null && Content.Description != descriptionTextBox.Text) {
    208         DeregisterContentEvents();
    209         Content.Description = descriptionTextBox.Text;
    210         RegisterContentEvents();
    211       }
    212     }
    213 
    214     private void ownerComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    215       var selectedItem = (LightweightUser)ownerComboBox.SelectedItem;
    216       var selectedOwnerUserId = selectedItem != null ? selectedItem.Id : Guid.Empty;
    217       if (Content != null && Content.OwnerUserId != selectedOwnerUserId) {
    218         DeregisterContentEvents();
    219         Content.OwnerUserId = selectedOwnerUserId;
    220         RegisterContentEvents();
    221       }
    222     }
    223 
    224     private void startDateTimePicker_ValueChanged(object sender, EventArgs e) {
    225       if (Content == null) return;
    226       startDateTimePicker.ValueChanged -= startDateTimePicker_ValueChanged;
    227 
    228       if (!IsAdmin()) {
    229         var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault();
    230         if (parentProject != null) {
    231           if (startDateTimePicker.Value < parentProject.StartDate)
    232             startDateTimePicker.Value = parentProject.StartDate;
    233         } else {
    234           startDateTimePicker.Value = Content.StartDate;
    235         }
    236       }
    237 
    238       if (!Content.EndDate.HasValue || startDateTimePicker.Value > Content.EndDate)
    239         endDateTimePicker.Value = startDateTimePicker.Value;
    240       if (Content.StartDate != startDateTimePicker.Value) {
    241         DeregisterContentEvents();
    242         Content.StartDate = startDateTimePicker.Value;
    243         RegisterContentEvents();
    244       }
    245 
    246       startDateTimePicker.ValueChanged += startDateTimePicker_ValueChanged;
    247     }
    248 
    249     private void endDateTimePicker_ValueChanged(object sender, EventArgs e) {
    250       if (Content == null) return;
    251       endDateTimePicker.ValueChanged -= endDateTimePicker_ValueChanged;
    252 
    253       if (!IsAdmin()) {
    254         var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault();
    255         if (parentProject != null) {
    256           if (parentProject.EndDate.HasValue && endDateTimePicker.Value > parentProject.EndDate.Value) {
    257             endDateTimePicker.Value = parentProject.EndDate.Value;
    258           }
    259         } else if (Content.EndDate.HasValue) {
    260           endDateTimePicker.Value = Content.EndDate.Value;
    261         }
    262       }
    263 
    264       if (endDateTimePicker.Value < startDateTimePicker.Value)
    265         endDateTimePicker.Value = startDateTimePicker.Value;
    266       if (Content.EndDate != endDateTimePicker.Value) {
    267         DeregisterContentEvents();
    268         Content.EndDate = endDateTimePicker.Value;
    269         RegisterContentEvents();
    270       }
    271 
    272       endDateTimePicker.ValueChanged += endDateTimePicker_ValueChanged;
    273     }
    274 
    275     private void indefiniteCheckBox_CheckedChanged(object sender, EventArgs e) {
    276       if (Content == null) return;
    277 
    278       var newEndDate = indefiniteCheckBox.Checked ? (DateTime?)null : endDateTimePicker.Value;
    279       endDateTimePicker.Enabled = !indefiniteCheckBox.Checked;
    280       if (Content.EndDate != newEndDate) {
    281         DeregisterContentEvents();
    282         Content.EndDate = newEndDate;
    283         RegisterContentEvents();
    284       }
    285     }
    286     #endregion
    287 
    288     #region Helpers
     83      }
     84    }
     85
     86    private async Tpl.Task UpdateUsersAsync() {
     87      await Tpl.Task.Run(() => UpdateUsers());
     88    }
     89
    28990    private void UpdateUsers() {
     91      // deregister handler to avoid change of content's owner when data source is updated
     92      ownerComboBox.SelectedIndexChanged -= ownerComboBox_SelectedIndexChanged;
    29093      try {
    291         AccessClient.Instance.Refresh();
     94        ownerComboBox.DataSource = null;
     95        SecurityExceptionUtil.TryAndReportSecurityExceptions(AccessClient.Instance.Refresh);
     96        ownerComboBox.DataSource = AccessClient.Instance.UsersAndGroups.OfType<LightweightUser>().OrderBy(x => x.UserName).ToList();
    29297      } catch (AnonymousUserException) {
    29398        ShowHiveInformationDialog();
    294       }
    295     }
    296 
    297     private bool IsAdmin() {
    298       return HiveRoles.CheckAdminUserPermissions();
     99      } finally {
     100        ownerComboBox.SelectedIndexChanged += ownerComboBox_SelectedIndexChanged;
     101      }
    299102    }
    300103
     
    307110      }
    308111    }
     112
     113    protected override void SetEnabledStateOfControls() {
     114      base.SetEnabledStateOfControls();
     115
     116      bool enabled = Content != null && !Locked && !ReadOnly;
     117
     118      nameTextBox.Enabled = enabled;
     119      descriptionTextBox.Enabled = enabled;
     120      ownerComboBox.Enabled = enabled;
     121      refreshButton.Enabled = enabled;
     122      createdTextBox.Enabled = enabled;
     123      startDateTimePicker.Enabled = enabled;
     124      endDateTimePicker.Enabled = enabled && Content.EndDate.HasValue && Content.EndDate > Content.StartDate;
     125      indefiniteCheckBox.Enabled = enabled;
     126
     127      if (Content == null) return;
     128
     129      var parentProject = HiveAdminClient.Instance.Projects.SingleOrDefault(x => x.Id == Content.ParentProjectId);
     130      if (parentProject != null && parentProject.EndDate.HasValue)
     131        indefiniteCheckBox.Enabled = false;
     132
     133      if (Content.Id == Guid.Empty) return; // newly created project
     134      if (HiveRoles.CheckAdminUserPermissions()) return; // admins can edit any project
     135      if (HiveAdminClient.Instance.CheckOwnershipOfParentProject(Content, UserInformation.Instance.User.Id)) return; // owner can edit project
     136
     137      // project was already created and user is neither admin nor owner
     138      ownerComboBox.Enabled = false;
     139      startDateTimePicker.Enabled = false;
     140      endDateTimePicker.Enabled = false;
     141      indefiniteCheckBox.Enabled = false;
     142    }
     143    #endregion
     144
     145    #region Event Handlers
     146    private void ProjectView_Load(object sender, EventArgs e) {
     147      Locked = true;
     148      try {
     149        UpdateUsers();
     150        UpdateView();
     151      } finally {
     152        Locked = false;
     153      }
     154    }
     155
     156    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     157      UpdateView();
     158    }
     159
     160    private void nameTextBox_TextChanged(object sender, EventArgs e) {
     161      if (Content == null || Content.Name == nameTextBox.Text) return;
     162      Content.Name = nameTextBox.Text;
     163    }
     164
     165    private void nameTextBox_Validating(object sender, CancelEventArgs e) {
     166      if (!string.IsNullOrEmpty(nameTextBox.Text)) return;
     167
     168      MessageBox.Show("Project must have a name.", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
     169      e.Cancel = true;
     170    }
     171
     172    private void descriptionTextBox_TextChanged(object sender, EventArgs e) {
     173      if (Content == null || Content.Description == descriptionTextBox.Text) return;
     174      Content.Description = descriptionTextBox.Text;
     175    }
     176
     177    private void ownerComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     178      if (Content == null) return;
     179
     180      var selectedItem = (LightweightUser)ownerComboBox.SelectedItem;
     181      var selectedOwnerUserId = selectedItem != null ? selectedItem.Id : Guid.Empty;
     182      if (Content.OwnerUserId == selectedOwnerUserId) return;
     183
     184      Content.OwnerUserId = selectedOwnerUserId;
     185    }
     186
     187    private async void refreshButton_Click(object sender, EventArgs e) {
     188      Locked = true;
     189      try {
     190        await UpdateUsersAsync();
     191        UpdateView();
     192      } finally {
     193        Locked = false;
     194      }
     195    }
     196
     197    private void startDateTimePicker_ValueChanged(object sender, EventArgs e) {
     198      if (Content == null || Content.StartDate == startDateTimePicker.Value) return;
     199
     200      string errorMessage = string.Empty;
     201
     202      var parentProject = HiveAdminClient.Instance.Projects.SingleOrDefault(x => x.Id == Content.ParentProjectId);
     203      if (parentProject != null) {
     204        if (startDateTimePicker.Value < parentProject.StartDate) {
     205          errorMessage = "Project cannot start before its parent project has started.";
     206        } else if (startDateTimePicker.Value > parentProject.EndDate) {
     207          errorMessage = "Project cannot start after its parent project has ended.";
     208        }
     209      }
     210
     211      if (startDateTimePicker.Value > endDateTimePicker.Value) {
     212        errorMessage = "Project cannot start after it ends.";
     213      }
     214
     215      if (!string.IsNullOrEmpty(errorMessage)) {
     216        MessageBox.Show(errorMessage, "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
     217        startDateTimePicker.Value = Content.StartDate;
     218      }
     219
     220      Content.StartDate = startDateTimePicker.Value;
     221    }
     222
     223    private void endDateTimePicker_ValueChanged(object sender, EventArgs e) {
     224      if (Content == null || Content.EndDate == endDateTimePicker.Value || Content.StartDate == endDateTimePicker.Value) return;
     225
     226      string errorMessage = string.Empty;
     227
     228      var parentProject = HiveAdminClient.Instance.Projects.SingleOrDefault(x => x.Id == Content.ParentProjectId);
     229      if (parentProject != null) {
     230        if (endDateTimePicker.Value > parentProject.EndDate) {
     231          errorMessage = "Project cannot end after its parent project has ended.";
     232        } else if (endDateTimePicker.Value < parentProject.StartDate) {
     233          errorMessage = "Project cannot end before its parent project has started.";
     234        }
     235      }
     236
     237      if (endDateTimePicker.Value < startDateTimePicker.Value) {
     238        errorMessage = "Project cannot end after it starts.";
     239      }
     240
     241      if (!string.IsNullOrEmpty(errorMessage)) {
     242        MessageBox.Show(errorMessage, "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
     243        endDateTimePicker.Value = Content.EndDate.GetValueOrDefault(Content.StartDate);
     244      }
     245
     246      Content.EndDate = endDateTimePicker.Value;
     247    }
     248
     249    private void indefiniteCheckBox_CheckedChanged(object sender, EventArgs e) {
     250      if (Content == null) return;
     251
     252      var newEndDate = indefiniteCheckBox.Checked ? (DateTime?)null : endDateTimePicker.Value;
     253
     254      if (Content.EndDate == newEndDate) return;
     255      Content.EndDate = newEndDate;
     256
     257      endDateTimePicker.Enabled = !indefiniteCheckBox.Checked;
     258    }
     259
     260    private void AccessClient_Instance_Refreshing(object sender, EventArgs e) {
     261      if (InvokeRequired) {
     262        Invoke((Action<object, EventArgs>)AccessClient_Instance_Refreshing, sender, e);
     263        return;
     264      }
     265
     266      Progress.Show(this, "Refreshing ...", ProgressMode.Indeterminate);
     267      SetEnabledStateOfControls();
     268    }
     269
     270    private void AccessClient_Instance_Refreshed(object sender, EventArgs e) {
     271      if (InvokeRequired) {
     272        Invoke((Action<object, EventArgs>)AccessClient_Instance_Refreshed, sender, e);
     273        return;
     274      }
     275
     276      Progress.Hide(this);
     277      SetEnabledStateOfControls();
     278    }
    309279    #endregion
    310280  }
Note: See TracChangeset for help on using the changeset viewer.