Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobListView.cs @ 9070

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

Updated year of copyrights to 2012 (#1716)

File size: 7.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.YesNo, MessageBoxIcon.Question);
57      if (result == DialogResult.Yes) {
58        System.Windows.Forms.ListView.SelectedListViewItemCollection selectedItems = itemsListView.SelectedItems;
59        bool inProgress = false;
60        foreach (ListViewItem item in selectedItems) {                                 
61          RefreshableJob job = item.Tag as RefreshableJob;
62          if (job != null && job.IsProgressing) {
63            inProgress = true;
64            break;
65          }
66        }
67
68        if (inProgress) {
69          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);
70          return;
71        } else {
72          base.removeButton_Click(sender, e);
73        }
74      }
75    }
76
77    protected override void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<RefreshableJob> e) {
78      if (InvokeRequired) {
79        Invoke(new CollectionItemsChangedEventHandler<RefreshableJob>(Content_ItemsAdded), sender, e);
80      } else {
81        base.Content_ItemsAdded(sender, e);
82        foreach (ColumnHeader c in this.itemsListView.Columns) {
83          c.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
84        }
85        foreach (var item in e.Items) {
86          item.ItemImageChanged += new EventHandler(item_ItemImageChanged);
87        }
88      }
89    }
90
91    void item_ItemImageChanged(object sender, EventArgs e) {
92      if (this.itemsListView.InvokeRequired) {
93        Invoke(new EventHandler(item_ItemImageChanged), sender, e);
94      } else {
95        RefreshableJob job = sender as RefreshableJob;
96        if (job != null) {
97          foreach (ListViewItem item in this.itemsListView.Items) {
98            if (item.Tag != null) {
99              RefreshableJob cur = item.Tag as RefreshableJob;
100              if (cur != null && cur == job) {
101                this.UpdateListViewItemImage(item);
102              }
103            }
104          }
105        }
106      }
107    }
108
109    protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<RefreshableJob> e) {
110      if (InvokeRequired) {
111        Invoke(new CollectionItemsChangedEventHandler<RefreshableJob>(Content_ItemsRemoved), sender, e);
112      } else {
113        base.Content_ItemsRemoved(sender, e);
114        foreach (var item in e.Items) {
115          item.ItemImageChanged -= new EventHandler(item_ItemImageChanged);
116        }
117        if (Content != null && Content.Count == 0) {
118          foreach (ColumnHeader c in this.itemsListView.Columns) {
119            c.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
120          }
121        }
122      }
123    }
124
125    protected override ListViewItem CreateListViewItem(RefreshableJob item) {
126      ListViewItem listViewItem = base.CreateListViewItem(item);
127      listViewItem.SubItems.Clear();
128      listViewItem.SubItems.Insert(0, new ListViewItem.ListViewSubItem(listViewItem, item.Job.DateCreated.ToString("dd.MM.yyyy HH:mm")));
129      listViewItem.SubItems.Insert(1, new ListViewItem.ListViewSubItem(listViewItem, item.Job.Name));
130      listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
131      return listViewItem;
132    }
133
134    protected override void UpdateListViewItemText(ListViewItem listViewItem) {
135      if (listViewItem == null) throw new ArgumentNullException();
136      var item = listViewItem.Tag as RefreshableJob;
137      listViewItem.SubItems[0].Text = item == null ? "null" : item.Job.DateCreated.ToString("dd.MM.yyyy HH:mm");
138      listViewItem.SubItems[1].Text = item == null ? "null" : item.Job.Name;
139      listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
140      listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
141    }
142
143    //drag'n'drop is not supported
144    protected override void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) { }
145    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) { }
146    protected override void itemsListView_DragOver(object sender, DragEventArgs e) { }
147    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) { }
148
149    private ListViewGroup GetListViewGroup(string groupName) {
150      foreach (ListViewGroup group in itemsListView.Groups) {
151        if (group.Name == groupName)
152          return group;
153      }
154      var newGroup = new ListViewGroup(string.Format("Owner ({0})", groupName), HorizontalAlignment.Left) { Name = groupName };
155      itemsListView.Groups.Add(newGroup);
156      return newGroup;
157    }
158  }
159}
Note: See TracBrowser for help on using the repository browser.