Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.Clients.OKB-3.3/Views/AlgorithmView.cs @ 4492

Last change on this file since 4492 was 4492, checked in by swagner, 14 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.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28
29namespace HeuristicLab.Clients.OKB {
30  [View("Algorithm View")]
31  [Content(typeof(Algorithm), true)]
32  public partial class AlgorithmView : NamedOKBItemView {
33    public new Algorithm Content {
34      get { return (Algorithm)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public AlgorithmView() {
39      InitializeComponent();
40    }
41
42    protected override void OnInitialized(System.EventArgs e) {
43      base.OnInitialized(e);
44      platformComboBox.DataSource = Administrator.Instance.Platforms.ToList();
45      algorithmClassComboBox.DataSource = Administrator.Instance.AlgorithmClasses.ToList();
46    }
47
48    protected override void OnContentChanged() {
49      base.OnContentChanged();
50      if (Content == null) {
51        platformComboBox.SelectedIndex = -1;
52        algorithmClassComboBox.SelectedIndex = -1;
53        algorithmDataView.AlgorithmId = 0;
54      } else {
55        platformComboBox.SelectedItem = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId);
56        algorithmClassComboBox.SelectedItem = Administrator.Instance.AlgorithmClasses.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
57        algorithmDataView.AlgorithmId = Content.Id;
58      }
59      usersListBox.DataSource = null;
60      algorithmDataView.Content = null;
61    }
62
63    protected override void SetEnabledStateOfControls() {
64      base.SetEnabledStateOfControls();
65      platformComboBox.Enabled = (Content != null) && !ReadOnly;
66      algorithmClassComboBox.Enabled = (Content != null) && !ReadOnly;
67      refreshUsersButton.Enabled = Content != null;
68      storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
69      usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
70      algorithmDataView.Enabled = Content != null;
71    }
72
73    protected override void OnContentPropertyChanged(string propertyName) {
74      switch (propertyName) {
75        case "Id":
76          algorithmDataView.AlgorithmId = Content.Id;
77          break;
78        case "PlatformId":
79          platformComboBox.SelectedItem = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId);
80          break;
81        case "AlgorithmClassId":
82          algorithmClassComboBox.SelectedItem = Administrator.Instance.AlgorithmClasses.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
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 algorithmClassComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
94      if (Content != null) {
95        AlgorithmClass selected = algorithmClassComboBox.SelectedItem as AlgorithmClass;
96        if (selected != null) Content.AlgorithmClassId = selected.Id;
97      }
98    }
99
100    private void refreshUsersButton_Click(object sender, System.EventArgs e) {
101      Guid[] ids = Administrator.Instance.GetAlgorithmUsers(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.UpdateAlgorithmUsers(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}
Note: See TracBrowser for help on using the repository browser.