Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5532 was 5286, checked in by swagner, 14 years ago

Worked on OKB (#1174)

File size: 5.6 KB
RevLine 
[4441]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
[4466]22using System;
23using System.Collections.Generic;
[4441]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 {
[4558]33    private List<Platform> platformComboBoxValues;
34    private List<AlgorithmClass> algorithmClassComboBoxValues;
35
[4441]36    public new Algorithm Content {
37      get { return (Algorithm)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public AlgorithmView() {
42      InitializeComponent();
43    }
44
45    protected override void OnInitialized(System.EventArgs e) {
46      base.OnInitialized(e);
[4558]47      platformComboBoxValues = OKBClient.Instance.Platforms.ToList();
48      platformComboBox.DataSource = platformComboBoxValues;
49      algorithmClassComboBoxValues = OKBClient.Instance.AlgorithmClasses.ToList();
50      algorithmClassComboBox.DataSource = algorithmClassComboBoxValues;
[4441]51    }
52
53    protected override void OnContentChanged() {
54      base.OnContentChanged();
55      if (Content == null) {
56        platformComboBox.SelectedIndex = -1;
57        algorithmClassComboBox.SelectedIndex = -1;
[4481]58        algorithmDataView.AlgorithmId = 0;
[4441]59      } else {
[4558]60        platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
61        algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
[4481]62        algorithmDataView.AlgorithmId = Content.Id;
[4441]63      }
[4466]64      usersListBox.DataSource = null;
[4481]65      algorithmDataView.Content = null;
[4441]66    }
67
68    protected override void SetEnabledStateOfControls() {
69      base.SetEnabledStateOfControls();
[4492]70      platformComboBox.Enabled = (Content != null) && !ReadOnly;
71      algorithmClassComboBox.Enabled = (Content != null) && !ReadOnly;
[4466]72      refreshUsersButton.Enabled = Content != null;
[4492]73      storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
74      usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
[4481]75      algorithmDataView.Enabled = Content != null;
[4441]76    }
77
78    protected override void OnContentPropertyChanged(string propertyName) {
79      switch (propertyName) {
[4492]80        case "Id":
81          algorithmDataView.AlgorithmId = Content.Id;
82          break;
[4441]83        case "PlatformId":
[4558]84          platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
[4441]85          break;
86        case "AlgorithmClassId":
[4558]87          algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
[4441]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 algorithmClassComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
99      if (Content != null) {
100        AlgorithmClass selected = algorithmClassComboBox.SelectedItem as AlgorithmClass;
101        if (selected != null) Content.AlgorithmClassId = selected.Id;
102      }
103    }
[4466]104
105    private void refreshUsersButton_Click(object sender, System.EventArgs e) {
[5286]106      List<Guid> ids = OKBClient.Instance.GetAlgorithmUsers(Content.Id);
[4466]107      if (ids != null) {
[4549]108        List<User> users = OKBClient.Instance.Users.ToList();
[4466]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));
[4492]114        usersListBox.Enabled = !ReadOnly;
[4466]115        storeUsersButton.Enabled = false;
116      }
117    }
118    private void storeUsersButton_Click(object sender, System.EventArgs e) {
[5286]119      if (OKBClient.Instance.UpdateAlgorithmUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToList()))
[4466]120        storeUsersButton.Enabled = false;
121    }
122    private void usersListBox_SelectedIndexChanged(object sender, EventArgs e) {
[4492]123      storeUsersButton.Enabled = !ReadOnly;
[4466]124    }
[4929]125
126    private void refreshParametersButton_Click(object sender, EventArgs e) {
127      algorithmParameterCollectionView.Content = OKBClient.Instance.GetAlgorithmParameters(Content.Id);
128    }
129
130    private void refreshResultsButton_Click(object sender, EventArgs e) {
131      resultCollectionView.Content = OKBClient.Instance.GetResults(Content.Id);
132    }
133
134    private void refreshExperimentsButton_Click(object sender, EventArgs e) {
[4943]135      experimentCollectionView.Content = OKBClient.Instance.GetExperiments(Content.Id, 0);
[4929]136    }
[4441]137  }
138}
Note: See TracBrowser for help on using the repository browser.