Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/Administration/Views/ProblemView.cs @ 5550

Last change on this file since 5550 was 5550, checked in by swagner, 13 years ago

Worked on OKB (#1174)

File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Clients.OKB.Authentication;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29
30namespace HeuristicLab.Clients.OKB.Administration {
31  [View("Problem View")]
32  [Content(typeof(Problem), true)]
33  public partial class ProblemView : NamedOKBItemView {
34    private List<Platform> platformComboBoxValues;
35    private List<ProblemClass> problemClassComboBoxValues;
36
37    public new Problem Content {
38      get { return (Problem)base.Content; }
39      set { base.Content = value; }
40    }
41
42    public ProblemView() {
43      InitializeComponent();
44    }
45
46    protected override void OnInitialized(System.EventArgs e) {
47      base.OnInitialized(e);
48      platformComboBoxValues = AdministrationClient.Instance.Platforms.ToList();
49      platformComboBox.DataSource = platformComboBoxValues;
50      problemClassComboBoxValues = AdministrationClient.Instance.ProblemClasses.ToList();
51      problemClassComboBox.DataSource = problemClassComboBoxValues;
52    }
53
54    protected override void OnContentChanged() {
55      base.OnContentChanged();
56      if (Content == null) {
57        platformComboBox.SelectedIndex = -1;
58        problemClassComboBox.SelectedIndex = -1;
59      } else {
60        platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
61        problemClassComboBox.SelectedItem = problemClassComboBoxValues.FirstOrDefault(a => a.Id == Content.ProblemClassId);
62      }
63      usersListBox.DataSource = null;
64    }
65
66    protected override void SetEnabledStateOfControls() {
67      base.SetEnabledStateOfControls();
68      platformComboBox.Enabled = (Content != null) && !ReadOnly;
69      problemClassComboBox.Enabled = (Content != null) && !ReadOnly;
70      refreshUsersButton.Enabled = Content != null;
71      storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
72      usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
73    }
74
75    protected override void OnContentPropertyChanged(string propertyName) {
76      switch (propertyName) {
77        case "PlatformId":
78          platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
79          break;
80        case "ProblemClassId":
81          problemClassComboBox.SelectedItem = problemClassComboBoxValues.FirstOrDefault(a => a.Id == Content.ProblemClassId);
82          break;
83      }
84    }
85
86    private void platformComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
87      if (Content != null) {
88        Platform selected = platformComboBox.SelectedItem as Platform;
89        if (selected != null) Content.PlatformId = selected.Id;
90      }
91    }
92    private void problemClassComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
93      if (Content != null) {
94        ProblemClass selected = problemClassComboBox.SelectedItem as ProblemClass;
95        if (selected != null) Content.ProblemClassId = selected.Id;
96      }
97    }
98
99    private void refreshUsersButton_Click(object sender, System.EventArgs e) {
100      List<Guid> ids = AdministrationClient.GetProblemUsers(Content.Id);
101      if (ids != null) {
102        List<User> users = AuthenticationClient.Instance.Users.ToList();
103        usersListBox.DataSource = users;
104        usersListBox.DisplayMember = "Name";
105        usersListBox.SelectedItems.Clear();
106        foreach (Guid id in ids)
107          usersListBox.SelectedItems.Add(users.First(u => u.Id == id));
108        usersListBox.Enabled = !ReadOnly;
109        storeUsersButton.Enabled = false;
110      }
111    }
112    private void storeUsersButton_Click(object sender, System.EventArgs e) {
113      AdministrationClient.UpdateProblemUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToList());
114      storeUsersButton.Enabled = false;
115    }
116    private void usersListBox_SelectedIndexChanged(object sender, EventArgs e) {
117      storeUsersButton.Enabled = !ReadOnly;
118    }
119  }
120}
Note: See TracBrowser for help on using the repository browser.