Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1959 fixed a bug which occurs on systems that don't use german time format

File size: 7.1 KB
RevLine 
[6976]1#region License Information
2/* HeuristicLab
[7259]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6976]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;
[8702]45
[8718]46      this.itemsListView.ListViewItemSorter = new ListViewItemDateComparer(0, SortOrder.Ascending);
[6976]47      this.itemsListView.Sorting = SortOrder.Ascending;
48      this.itemsListView.Sort();
49    }
50
51    protected override RefreshableJob CreateItem() {
[7068]52      var refreshableJob = new RefreshableJob() { IsAllowedPrivileged = HiveClient.Instance.IsAllowedPrivileged };
53      refreshableJob.Job.Name = "New Hive Job";
54      return refreshableJob;
[6976]55    }
56
57    protected override void removeButton_Click(object sender, EventArgs e) {
[7200]58      DialogResult result = MessageBox.Show("This action will permanently delete this job (also on the Hive server). Continue?", "HeuristicLab Hive Job Manager", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
59      if (result == DialogResult.Yes) {
60        System.Windows.Forms.ListView.SelectedListViewItemCollection selectedItems = itemsListView.SelectedItems;
61        bool inProgress = false;
[8702]62        foreach (ListViewItem item in selectedItems) {
[7200]63          RefreshableJob job = item.Tag as RefreshableJob;
64          if (job != null && job.IsProgressing) {
65            inProgress = true;
66            break;
67          }
68        }
69
70        if (inProgress) {
71          MessageBox.Show("You can't delete jobs which are currently uploading or downloading." + Environment.NewLine + "Please wait for the jobs to complete and try again. ", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Warning);
72          return;
73        } else {
74          base.removeButton_Click(sender, e);
75        }
[6976]76      }
77    }
78
79    protected override void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<RefreshableJob> e) {
[7152]80      if (InvokeRequired) {
81        Invoke(new CollectionItemsChangedEventHandler<RefreshableJob>(Content_ItemsAdded), sender, e);
82      } else {
83        base.Content_ItemsAdded(sender, e);
84        foreach (ColumnHeader c in this.itemsListView.Columns) {
85          c.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
86        }
87        foreach (var item in e.Items) {
88          item.ItemImageChanged += new EventHandler(item_ItemImageChanged);
89        }
[6976]90      }
91    }
92
[7059]93    void item_ItemImageChanged(object sender, EventArgs e) {
[7152]94      if (this.itemsListView.InvokeRequired) {
95        Invoke(new EventHandler(item_ItemImageChanged), sender, e);
96      } else {
97        RefreshableJob job = sender as RefreshableJob;
98        if (job != null) {
99          foreach (ListViewItem item in this.itemsListView.Items) {
100            if (item.Tag != null) {
101              RefreshableJob cur = item.Tag as RefreshableJob;
102              if (cur != null && cur == job) {
103                this.UpdateListViewItemImage(item);
104              }
[7059]105            }
[7152]106          }
107        }
[7059]108      }
109    }
110
[6976]111    protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<RefreshableJob> e) {
[7152]112      if (InvokeRequired) {
113        Invoke(new CollectionItemsChangedEventHandler<RefreshableJob>(Content_ItemsRemoved), sender, e);
114      } else {
115        base.Content_ItemsRemoved(sender, e);
116        foreach (var item in e.Items) {
117          item.ItemImageChanged -= new EventHandler(item_ItemImageChanged);
[6976]118        }
[7152]119        if (Content != null && Content.Count == 0) {
120          foreach (ColumnHeader c in this.itemsListView.Columns) {
121            c.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
122          }
123        }
[6976]124      }
125    }
126
127    protected override ListViewItem CreateListViewItem(RefreshableJob item) {
128      ListViewItem listViewItem = base.CreateListViewItem(item);
129      listViewItem.SubItems.Clear();
[8850]130      listViewItem.SubItems.Insert(0, new ListViewItem.ListViewSubItem(listViewItem, item.Job.DateCreated.ToString()));
[6976]131      listViewItem.SubItems.Insert(1, new ListViewItem.ListViewSubItem(listViewItem, item.Job.Name));
132      listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
133      return listViewItem;
134    }
135
136    protected override void UpdateListViewItemText(ListViewItem listViewItem) {
137      if (listViewItem == null) throw new ArgumentNullException();
138      var item = listViewItem.Tag as RefreshableJob;
139      listViewItem.SubItems[0].Text = item == null ? "null" : item.Job.DateCreated.ToString("dd.MM.yyyy HH:mm");
140      listViewItem.SubItems[1].Text = item == null ? "null" : item.Job.Name;
141      listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
142      listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
143    }
144
[7056]145    //drag'n'drop is not supported
146    protected override void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) { }
147    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) { }
148    protected override void itemsListView_DragOver(object sender, DragEventArgs e) { }
149    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) { }
150
[6976]151    private ListViewGroup GetListViewGroup(string groupName) {
152      foreach (ListViewGroup group in itemsListView.Groups) {
153        if (group.Name == groupName)
154          return group;
155      }
156      var newGroup = new ListViewGroup(string.Format("Owner ({0})", groupName), HorizontalAlignment.Left) { Name = groupName };
157      itemsListView.Groups.Add(newGroup);
158      return newGroup;
159    }
160  }
161}
Note: See TracBrowser for help on using the repository browser.