Free cookie consent management tool by TermsFeed Policy Generator

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

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

Worked on OKB (#1174)

File size: 7.2 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.Clients.OKB.Authentication;
27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
30using HeuristicLab.Optimization;
31
32namespace HeuristicLab.Clients.OKB.Administration {
33  [View("Algorithm View")]
34  [Content(typeof(Algorithm), true)]
35  public partial class AlgorithmView : NamedOKBItemView {
36    private List<Platform> platformComboBoxValues;
37    private List<AlgorithmClass> algorithmClassComboBoxValues;
38    private TypeSelectorDialog typeSelectorDialog;
39
40    public new Algorithm Content {
41      get { return (Algorithm)base.Content; }
42      set { base.Content = value; }
43    }
44
45    public AlgorithmView() {
46      InitializeComponent();
47    }
48
49    protected override void Dispose(bool disposing) {
50      if (disposing) {
51        if (components != null) components.Dispose();
52        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
53      }
54      base.Dispose(disposing);
55    }
56
57    protected override void OnContentChanged() {
58      base.OnContentChanged();
59
60      platformComboBoxValues = AdministrationClient.Instance.Platforms.ToList();
61      platformComboBox.DataSource = platformComboBoxValues;
62      algorithmClassComboBoxValues = AdministrationClient.Instance.AlgorithmClasses.ToList();
63      algorithmClassComboBox.DataSource = algorithmClassComboBoxValues;
64
65      if (Content == null) {
66        platformComboBox.SelectedIndex = -1;
67        algorithmClassComboBox.SelectedIndex = -1;
68        dataTypeNameTextBox.Text = string.Empty;
69        dataTypeTypeNameTextBox.Text = string.Empty;
70      } else {
71        platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
72        algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
73        dataTypeNameTextBox.Text = Content.DataTypeName;
74        dataTypeTypeNameTextBox.Text = Content.DataTypeTypeName;
75      }
76      usersListBox.DataSource = null;
77    }
78
79    protected override void SetEnabledStateOfControls() {
80      base.SetEnabledStateOfControls();
81      platformComboBox.Enabled = (Content != null) && !ReadOnly;
82      algorithmClassComboBox.Enabled = (Content != null) && !ReadOnly;
83      dataTypeGroupBox.Enabled = (Content != null) && !ReadOnly;
84      refreshUsersButton.Enabled = (Content != null) && (Content.Id != 0);
85      storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
86      usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
87
88      bool isHL33Platform = platformComboBox.Text == "HeuristicLab 3.3";
89      setDataTypeButton.Enabled = isHL33Platform && !ReadOnly;
90      dataTypeNameTextBox.ReadOnly = isHL33Platform;
91      dataTypeTypeNameTextBox.ReadOnly = isHL33Platform;
92    }
93
94    protected override void OnContentPropertyChanged(string propertyName) {
95      switch (propertyName) {
96        case "Id":
97          SetEnabledStateOfControls();
98          break;
99        case "PlatformId":
100          platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
101          SetEnabledStateOfControls();
102          break;
103        case "AlgorithmClassId":
104          algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
105          break;
106        case "DataTypeName":
107          dataTypeNameTextBox.Text = Content.DataTypeName;
108          break;
109        case "DataTypeTypeName":
110          dataTypeTypeNameTextBox.Text = Content.DataTypeTypeName;
111          break;
112      }
113    }
114
115    private void platformComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
116      if (Content != null) {
117        Platform selected = platformComboBox.SelectedItem as Platform;
118        if (selected != null) Content.PlatformId = selected.Id;
119      }
120    }
121    private void algorithmClassComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
122      if (Content != null) {
123        AlgorithmClass selected = algorithmClassComboBox.SelectedItem as AlgorithmClass;
124        if (selected != null) Content.AlgorithmClassId = selected.Id;
125      }
126    }
127
128    private void setDataTypeButton_Click(object sender, EventArgs e) {
129      if (typeSelectorDialog == null) {
130        typeSelectorDialog = new TypeSelectorDialog();
131        typeSelectorDialog.Caption = "Select Algorithm";
132        typeSelectorDialog.TypeSelector.Caption = "Available Algorithms";
133        typeSelectorDialog.TypeSelector.Configure(typeof(IAlgorithm), false, true);
134      }
135      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
136        Content.DataTypeName = typeSelectorDialog.TypeSelector.SelectedType.Name;
137        Content.DataTypeTypeName = typeSelectorDialog.TypeSelector.SelectedType.AssemblyQualifiedName;
138      }
139    }
140    private void dataTypeNameTextBox_TextChanged(object sender, EventArgs e) {
141      if (dataTypeNameTextBox.Text != Content.DataTypeName)
142        Content.DataTypeName = dataTypeNameTextBox.Text;
143    }
144    private void dataTypeTypeNameTextBox_TextChanged(object sender, EventArgs e) {
145      if (dataTypeTypeNameTextBox.Text != Content.DataTypeTypeName)
146        Content.DataTypeTypeName = dataTypeTypeNameTextBox.Text;
147    }
148
149    private void refreshUsersButton_Click(object sender, System.EventArgs e) {
150      List<Guid> ids = AdministrationClient.GetAlgorithmUsers(Content.Id);
151      if (ids != null) {
152        if (AuthenticationClient.Instance.Users == null) AuthenticationClient.Instance.Refresh();
153        List<User> users = AuthenticationClient.Instance.Users.ToList();
154        usersListBox.DataSource = users;
155        usersListBox.DisplayMember = "Name";
156        for (int i = 0; i < users.Count; i++)
157          usersListBox.SetItemChecked(i, ids.Contains(users[i].Id));
158        usersListBox.Enabled = !ReadOnly;
159        storeUsersButton.Enabled = false;
160      }
161    }
162    private void storeUsersButton_Click(object sender, System.EventArgs e) {
163      AdministrationClient.UpdateAlgorithmUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToList());
164      storeUsersButton.Enabled = false;
165    }
166    private void usersListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
167      storeUsersButton.Enabled = !ReadOnly;
168    }
169  }
170}
Note: See TracBrowser for help on using the repository browser.