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