[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] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[4441] | 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms;
|
---|
[5533] | 26 | using HeuristicLab.Clients.OKB.Authentication;
|
---|
[5534] | 27 | using HeuristicLab.Core.Views;
|
---|
[4441] | 28 | using HeuristicLab.MainForm;
|
---|
| 29 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[5534] | 30 | using HeuristicLab.Optimization;
|
---|
[4441] | 31 |
|
---|
[5533] | 32 | namespace HeuristicLab.Clients.OKB.Administration {
|
---|
[4441] | 33 | [View("Algorithm View")]
|
---|
| 34 | [Content(typeof(Algorithm), true)]
|
---|
| 35 | public partial class AlgorithmView : NamedOKBItemView {
|
---|
[4558] | 36 | private List<Platform> platformComboBoxValues;
|
---|
| 37 | private List<AlgorithmClass> algorithmClassComboBoxValues;
|
---|
[5534] | 38 | private TypeSelectorDialog typeSelectorDialog;
|
---|
[4558] | 39 |
|
---|
[4441] | 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 |
|
---|
[5534] | 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 |
|
---|
[5550] | 57 | protected override void OnContentChanged() {
|
---|
| 58 | base.OnContentChanged();
|
---|
| 59 |
|
---|
[5533] | 60 | platformComboBoxValues = AdministrationClient.Instance.Platforms.ToList();
|
---|
[4558] | 61 | platformComboBox.DataSource = platformComboBoxValues;
|
---|
[5533] | 62 | algorithmClassComboBoxValues = AdministrationClient.Instance.AlgorithmClasses.ToList();
|
---|
[4558] | 63 | algorithmClassComboBox.DataSource = algorithmClassComboBoxValues;
|
---|
[4441] | 64 |
|
---|
| 65 | if (Content == null) {
|
---|
| 66 | platformComboBox.SelectedIndex = -1;
|
---|
| 67 | algorithmClassComboBox.SelectedIndex = -1;
|
---|
[5550] | 68 | dataTypeNameTextBox.Text = string.Empty;
|
---|
| 69 | dataTypeTypeNameTextBox.Text = string.Empty;
|
---|
[4441] | 70 | } else {
|
---|
[4558] | 71 | platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
|
---|
| 72 | algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
|
---|
[5534] | 73 | dataTypeNameTextBox.Text = Content.DataTypeName;
|
---|
| 74 | dataTypeTypeNameTextBox.Text = Content.DataTypeTypeName;
|
---|
[4441] | 75 | }
|
---|
[4466] | 76 | usersListBox.DataSource = null;
|
---|
[4441] | 77 | }
|
---|
| 78 |
|
---|
| 79 | protected override void SetEnabledStateOfControls() {
|
---|
| 80 | base.SetEnabledStateOfControls();
|
---|
[4492] | 81 | platformComboBox.Enabled = (Content != null) && !ReadOnly;
|
---|
| 82 | algorithmClassComboBox.Enabled = (Content != null) && !ReadOnly;
|
---|
[5534] | 83 | dataTypeGroupBox.Enabled = (Content != null) && !ReadOnly;
|
---|
[5550] | 84 | refreshUsersButton.Enabled = (Content != null) && (Content.Id != 0);
|
---|
[4492] | 85 | storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
|
---|
| 86 | usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
|
---|
[5534] | 87 |
|
---|
| 88 | bool isHL33Platform = platformComboBox.Text == "HeuristicLab 3.3";
|
---|
| 89 | setDataTypeButton.Enabled = isHL33Platform && !ReadOnly;
|
---|
| 90 | dataTypeNameTextBox.ReadOnly = isHL33Platform;
|
---|
| 91 | dataTypeTypeNameTextBox.ReadOnly = isHL33Platform;
|
---|
[4441] | 92 | }
|
---|
| 93 |
|
---|
| 94 | protected override void OnContentPropertyChanged(string propertyName) {
|
---|
| 95 | switch (propertyName) {
|
---|
[5550] | 96 | case "Id":
|
---|
| 97 | SetEnabledStateOfControls();
|
---|
| 98 | break;
|
---|
[4441] | 99 | case "PlatformId":
|
---|
[4558] | 100 | platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
|
---|
[5534] | 101 | SetEnabledStateOfControls();
|
---|
[4441] | 102 | break;
|
---|
| 103 | case "AlgorithmClassId":
|
---|
[4558] | 104 | algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
|
---|
[4441] | 105 | break;
|
---|
[5534] | 106 | case "DataTypeName":
|
---|
| 107 | dataTypeNameTextBox.Text = Content.DataTypeName;
|
---|
| 108 | break;
|
---|
| 109 | case "DataTypeTypeName":
|
---|
| 110 | dataTypeTypeNameTextBox.Text = Content.DataTypeTypeName;
|
---|
| 111 | break;
|
---|
[4441] | 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 | }
|
---|
[4466] | 127 |
|
---|
[5534] | 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 | }
|
---|
[5550] | 140 | private void dataTypeNameTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 141 | if (dataTypeNameTextBox.Text != Content.DataTypeName)
|
---|
| 142 | Content.DataTypeName = dataTypeNameTextBox.Text;
|
---|
[5534] | 143 | }
|
---|
[5550] | 144 | private void dataTypeTypeNameTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 145 | if (dataTypeTypeNameTextBox.Text != Content.DataTypeTypeName)
|
---|
| 146 | Content.DataTypeTypeName = dataTypeTypeNameTextBox.Text;
|
---|
[5534] | 147 | }
|
---|
| 148 |
|
---|
[4466] | 149 | private void refreshUsersButton_Click(object sender, System.EventArgs e) {
|
---|
[5550] | 150 | List<Guid> ids = AdministrationClient.GetAlgorithmUsers(Content.Id);
|
---|
[4466] | 151 | if (ids != null) {
|
---|
[5550] | 152 | if (AuthenticationClient.Instance.Users == null) AuthenticationClient.Instance.Refresh();
|
---|
[5533] | 153 | List<User> users = AuthenticationClient.Instance.Users.ToList();
|
---|
[4466] | 154 | usersListBox.DataSource = users;
|
---|
| 155 | usersListBox.DisplayMember = "Name";
|
---|
[5534] | 156 | for (int i = 0; i < users.Count; i++)
|
---|
| 157 | usersListBox.SetItemChecked(i, ids.Contains(users[i].Id));
|
---|
[4492] | 158 | usersListBox.Enabled = !ReadOnly;
|
---|
[4466] | 159 | storeUsersButton.Enabled = false;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | private void storeUsersButton_Click(object sender, System.EventArgs e) {
|
---|
[5550] | 163 | AdministrationClient.UpdateAlgorithmUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToList());
|
---|
| 164 | storeUsersButton.Enabled = false;
|
---|
[4466] | 165 | }
|
---|
[5550] | 166 | private void usersListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
|
---|
[4492] | 167 | storeUsersButton.Enabled = !ReadOnly;
|
---|
[4466] | 168 | }
|
---|
[4441] | 169 | }
|
---|
| 170 | }
|
---|