Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.ExperimentManager/3.3/Views/RefreshableHiveExperimentListView.cs @ 6791

Last change on this file since 6791 was 6791, checked in by ascheibe, 13 years ago

#1233 implemented Experiment Manager review comments

File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Windows.Forms;
24using HeuristicLab.Collections;
25using HeuristicLab.Core;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Clients.Hive.ExperimentManager.Views {
29  [View("HiveExperimentList View")]
30  [Content(typeof(ItemCollection<RefreshableJob>), false)]
31  public partial class RefreshableHiveExperimentListView : HeuristicLab.Core.Views.ItemCollectionView<RefreshableJob> {
32
33    public RefreshableHiveExperimentListView() {
34      InitializeComponent();
35      itemsGroupBox.Text = "Jobs";
36      this.itemsListView.View = View.Details;
37      this.itemsListView.Columns.Clear();
38      this.itemsListView.Columns.Add(new ColumnHeader("Date") { Text = "Date" });
39      this.itemsListView.Columns.Add(new ColumnHeader("Name") { Text = "Name" });
40      foreach (ColumnHeader c in this.itemsListView.Columns) {
41        c.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
42      }
43      this.itemsListView.HeaderStyle = ColumnHeaderStyle.Clickable;
44      this.itemsListView.FullRowSelect = true;
45      this.itemsListView.Sorting = SortOrder.Ascending;
46      this.itemsListView.Sort();
47    }
48
49    protected override RefreshableJob CreateItem() {
50      return new RefreshableJob() { IsAllowedPrivileged = HiveClient.Instance.IsAllowedPrivileged };
51    }
52
53    protected override void removeButton_Click(object sender, EventArgs e) {
54      DialogResult result = MessageBox.Show("This action will permanently delete this experiment (also on the hive server). Continue?", "Delete Experiment", MessageBoxButtons.OKCancel);
55      if (result == DialogResult.OK) {
56        base.removeButton_Click(sender, e);
57      }
58    }
59
60    protected override void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<RefreshableJob> e) {
61      base.Content_ItemsAdded(sender, e);
62      foreach (ColumnHeader c in this.itemsListView.Columns) {
63        c.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
64      }
65    }
66
67    protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<RefreshableJob> e) {
68      base.Content_ItemsRemoved(sender, e);
69      if (Content != null && Content.Count == 0) {
70        foreach (ColumnHeader c in this.itemsListView.Columns) {
71          c.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
72        }
73      }
74    }
75
76    protected override ListViewItem CreateListViewItem(RefreshableJob item) {
77      ListViewItem listViewItem = base.CreateListViewItem(item);
78      listViewItem.SubItems.Clear();
79      listViewItem.SubItems.Insert(0, new ListViewItem.ListViewSubItem(listViewItem, item.Job.DateCreated.ToString("dd.MM.yyyy HH:mm")));
80      listViewItem.SubItems.Insert(1, new ListViewItem.ListViewSubItem(listViewItem, item.Job.Name));
81      listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
82      return listViewItem;
83    }
84
85    protected override void UpdateListViewItemText(ListViewItem listViewItem) {
86      if (listViewItem == null) throw new ArgumentNullException();
87      var item = listViewItem.Tag as RefreshableJob;
88      listViewItem.SubItems[0].Text = item == null ? "null" : item.Job.DateCreated.ToString("dd.MM.yyyy HH:mm");
89      listViewItem.SubItems[1].Text = item == null ? "null" : item.Job.Name;
90      listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
91      listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
92    }
93
94    private ListViewGroup GetListViewGroup(string groupName) {
95      foreach (ListViewGroup group in itemsListView.Groups) {
96        if (group.Name == groupName)
97          return group;
98      }
99      var newGroup = new ListViewGroup(string.Format("Owner ({0})", groupName), HorizontalAlignment.Left) { Name = groupName };
100      itemsListView.Groups.Add(newGroup);
101      return newGroup;
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.