Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobListView.cs @ 7068

Last change on this file since 7068 was 7068, checked in by ascheibe, 12 years ago

#1672

  • added a default job name
  • added check that a job name is set before upload
File size: 5.8 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.JobManager.Views {
29  [View("Refreshable Hive Job List")]
30  [Content(typeof(ItemCollection<RefreshableJob>), false)]
31  public partial class RefreshableHiveJobListView : HeuristicLab.Core.Views.ItemCollectionView<RefreshableJob> {
32
33    public RefreshableHiveJobListView() {
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      var refreshableJob = new RefreshableJob() { IsAllowedPrivileged = HiveClient.Instance.IsAllowedPrivileged };
51      refreshableJob.Job.Name = "New Hive Job";
52      return refreshableJob;
53    }
54
55    protected override void removeButton_Click(object sender, EventArgs e) {
56      DialogResult result = MessageBox.Show("This action will permanently delete this job (also on the hive server). Continue?", "HeuristicLab Hive Job Manager", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
57      if (result == DialogResult.OK) {
58        base.removeButton_Click(sender, e);
59      }
60    }
61
62    protected override void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<RefreshableJob> e) {
63      base.Content_ItemsAdded(sender, e);
64      foreach (ColumnHeader c in this.itemsListView.Columns) {
65        c.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
66      }
67      foreach (var item in e.Items) {
68        item.ItemImageChanged += new EventHandler(item_ItemImageChanged);
69      }
70    }
71
72    void item_ItemImageChanged(object sender, EventArgs e) {
73      RefreshableJob job = sender as RefreshableJob;
74      if (job != null) {
75        foreach (ListViewItem item in this.itemsListView.Items) {
76          if (item.Tag != null) {
77            RefreshableJob cur = item.Tag as RefreshableJob;
78            if (cur != null && cur == job) {
79              this.UpdateListViewItemImage(item);
80            }
81          }
82        }
83      }
84    }
85
86    protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<RefreshableJob> e) {
87      base.Content_ItemsRemoved(sender, e);
88      foreach (var item in e.Items) {
89        item.ItemImageChanged -= new EventHandler(item_ItemImageChanged);
90      }
91      if (Content != null && Content.Count == 0) {
92        foreach (ColumnHeader c in this.itemsListView.Columns) {
93          c.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
94        }
95      }
96    }
97
98    protected override ListViewItem CreateListViewItem(RefreshableJob item) {
99      ListViewItem listViewItem = base.CreateListViewItem(item);
100      listViewItem.SubItems.Clear();
101      listViewItem.SubItems.Insert(0, new ListViewItem.ListViewSubItem(listViewItem, item.Job.DateCreated.ToString("dd.MM.yyyy HH:mm")));
102      listViewItem.SubItems.Insert(1, new ListViewItem.ListViewSubItem(listViewItem, item.Job.Name));
103      listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
104      return listViewItem;
105    }
106
107    protected override void UpdateListViewItemText(ListViewItem listViewItem) {
108      if (listViewItem == null) throw new ArgumentNullException();
109      var item = listViewItem.Tag as RefreshableJob;
110      listViewItem.SubItems[0].Text = item == null ? "null" : item.Job.DateCreated.ToString("dd.MM.yyyy HH:mm");
111      listViewItem.SubItems[1].Text = item == null ? "null" : item.Job.Name;
112      listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
113      listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
114    }
115
116    //drag'n'drop is not supported
117    protected override void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) { }
118    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) { }
119    protected override void itemsListView_DragOver(object sender, DragEventArgs e) { }
120    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) { }
121
122    private ListViewGroup GetListViewGroup(string groupName) {
123      foreach (ListViewGroup group in itemsListView.Groups) {
124        if (group.Name == groupName)
125          return group;
126      }
127      var newGroup = new ListViewGroup(string.Format("Owner ({0})", groupName), HorizontalAlignment.Left) { Name = groupName };
128      itemsListView.Groups.Add(newGroup);
129      return newGroup;
130    }
131  }
132}
Note: See TracBrowser for help on using the repository browser.