Free cookie consent management tool by TermsFeed Policy Generator

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

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

Worked on OKB (#1174)

File size: 5.0 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 DeregisterContentEvents() {
49      // ...
50      base.DeregisterContentEvents();
51    }
52    protected override void RegisterContentEvents() {
53      base.RegisterContentEvents();
54      // ...
55    }
56
57    protected override void OnContentChanged() {
58      base.OnContentChanged();
59      if (Content == null) {
60        platformComboBox.SelectedIndex = -1;
61        algorithmClassComboBox.SelectedIndex = -1;
62        algorithmDataView.AlgorithmId = 0;
63      } else {
64        platformComboBox.SelectedItem = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId);
65        algorithmClassComboBox.SelectedItem = Administrator.Instance.AlgorithmClasses.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
66        algorithmDataView.AlgorithmId = Content.Id;
67      }
68      usersListBox.DataSource = null;
69      algorithmDataView.Content = null;
70    }
71
72    protected override void SetEnabledStateOfControls() {
73      base.SetEnabledStateOfControls();
74      platformComboBox.Enabled = Content != null;
75      algorithmClassComboBox.Enabled = Content != null;
76      refreshUsersButton.Enabled = Content != null;
77      storeUsersButton.Enabled = usersListBox.DataSource != null;
78      usersListBox.Enabled = usersListBox.DataSource != null;
79      algorithmDataView.Enabled = Content != null;
80    }
81
82    protected override void OnContentPropertyChanged(string propertyName) {
83      switch (propertyName) {
84        case "PlatformId":
85          platformComboBox.SelectedItem = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId);
86          break;
87        case "AlgorithmClassId":
88          algorithmClassComboBox.SelectedItem = Administrator.Instance.AlgorithmClasses.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
89          break;
90      }
91    }
92
93    private void platformComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
94      if (Content != null) {
95        Platform selected = platformComboBox.SelectedItem as Platform;
96        if (selected != null) Content.PlatformId = selected.Id;
97      }
98    }
99    private void algorithmClassComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
100      if (Content != null) {
101        AlgorithmClass selected = algorithmClassComboBox.SelectedItem as AlgorithmClass;
102        if (selected != null) Content.AlgorithmClassId = selected.Id;
103      }
104    }
105
106    private void refreshUsersButton_Click(object sender, System.EventArgs e) {
107      Guid[] ids = Administrator.Instance.GetAlgorithmUsers(Content.Id);
108      if (ids != null) {
109        List<User> users = Administrator.Instance.Users.ToList();
110        usersListBox.DataSource = users;
111        usersListBox.DisplayMember = "Name";
112        usersListBox.SelectedItems.Clear();
113        foreach (Guid id in ids)
114          usersListBox.SelectedItems.Add(users.First(u => u.Id == id));
115        usersListBox.Enabled = true;
116        storeUsersButton.Enabled = false;
117      }
118    }
119    private void storeUsersButton_Click(object sender, System.EventArgs e) {
120      if (Administrator.Instance.UpdateAlgorithmUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToArray()))
121        storeUsersButton.Enabled = false;
122    }
123    private void usersListBox_SelectedIndexChanged(object sender, EventArgs e) {
124      storeUsersButton.Enabled = true;
125    }
126  }
127}
Note: See TracBrowser for help on using the repository browser.