Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/Views/AlgorithmView.cs @ 5304

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

Worked on OKB (#1174)

File size: 5.6 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    private List<Platform> platformComboBoxValues;
34    private List<AlgorithmClass> algorithmClassComboBoxValues;
35
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);
47      platformComboBoxValues = OKBClient.Instance.Platforms.ToList();
48      platformComboBox.DataSource = platformComboBoxValues;
49      algorithmClassComboBoxValues = OKBClient.Instance.AlgorithmClasses.ToList();
50      algorithmClassComboBox.DataSource = algorithmClassComboBoxValues;
51    }
52
53    protected override void OnContentChanged() {
54      base.OnContentChanged();
55      if (Content == null) {
56        platformComboBox.SelectedIndex = -1;
57        algorithmClassComboBox.SelectedIndex = -1;
58        algorithmDataView.AlgorithmId = 0;
59      } else {
60        platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
61        algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
62        algorithmDataView.AlgorithmId = Content.Id;
63      }
64      usersListBox.DataSource = null;
65      algorithmDataView.Content = null;
66    }
67
68    protected override void SetEnabledStateOfControls() {
69      base.SetEnabledStateOfControls();
70      platformComboBox.Enabled = (Content != null) && !ReadOnly;
71      algorithmClassComboBox.Enabled = (Content != null) && !ReadOnly;
72      refreshUsersButton.Enabled = Content != null;
73      storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
74      usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
75      algorithmDataView.Enabled = Content != null;
76    }
77
78    protected override void OnContentPropertyChanged(string propertyName) {
79      switch (propertyName) {
80        case "Id":
81          algorithmDataView.AlgorithmId = Content.Id;
82          break;
83        case "PlatformId":
84          platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
85          break;
86        case "AlgorithmClassId":
87          algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
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    }
104
105    private void refreshUsersButton_Click(object sender, System.EventArgs e) {
106      List<Guid> ids = OKBClient.Instance.GetAlgorithmUsers(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.UpdateAlgorithmUsers(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    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) {
135      experimentCollectionView.Content = OKBClient.Instance.GetExperiments(Content.Id, 0);
136    }
137  }
138}
Note: See TracBrowser for help on using the repository browser.