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