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 |
|
---|
22 | using System;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using HeuristicLab.Collections;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 |
|
---|
28 | namespace 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 | if (this.itemsListView.InvokeRequired) {
|
---|
74 | Invoke(new EventHandler(item_ItemImageChanged), sender, e);
|
---|
75 | } else {
|
---|
76 | RefreshableJob job = sender as RefreshableJob;
|
---|
77 | if (job != null) {
|
---|
78 | foreach (ListViewItem item in this.itemsListView.Items) {
|
---|
79 | if (item.Tag != null)
|
---|
80 | {
|
---|
81 | RefreshableJob cur = item.Tag as RefreshableJob;
|
---|
82 | if (cur != null && cur == job)
|
---|
83 | {
|
---|
84 | this.UpdateListViewItemImage(item);
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<RefreshableJob> e) {
|
---|
93 | base.Content_ItemsRemoved(sender, e);
|
---|
94 | foreach (var item in e.Items) {
|
---|
95 | item.ItemImageChanged -= new EventHandler(item_ItemImageChanged);
|
---|
96 | }
|
---|
97 | if (Content != null && Content.Count == 0) {
|
---|
98 | foreach (ColumnHeader c in this.itemsListView.Columns) {
|
---|
99 | c.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | protected override ListViewItem CreateListViewItem(RefreshableJob item) {
|
---|
105 | ListViewItem listViewItem = base.CreateListViewItem(item);
|
---|
106 | listViewItem.SubItems.Clear();
|
---|
107 | listViewItem.SubItems.Insert(0, new ListViewItem.ListViewSubItem(listViewItem, item.Job.DateCreated.ToString("dd.MM.yyyy HH:mm")));
|
---|
108 | listViewItem.SubItems.Insert(1, new ListViewItem.ListViewSubItem(listViewItem, item.Job.Name));
|
---|
109 | listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
|
---|
110 | return listViewItem;
|
---|
111 | }
|
---|
112 |
|
---|
113 | protected override void UpdateListViewItemText(ListViewItem listViewItem) {
|
---|
114 | if (listViewItem == null) throw new ArgumentNullException();
|
---|
115 | var item = listViewItem.Tag as RefreshableJob;
|
---|
116 | listViewItem.SubItems[0].Text = item == null ? "null" : item.Job.DateCreated.ToString("dd.MM.yyyy HH:mm");
|
---|
117 | listViewItem.SubItems[1].Text = item == null ? "null" : item.Job.Name;
|
---|
118 | listViewItem.Group = GetListViewGroup(item.Job.OwnerUsername);
|
---|
119 | listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
|
---|
120 | }
|
---|
121 |
|
---|
122 | //drag'n'drop is not supported
|
---|
123 | protected override void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) { }
|
---|
124 | protected override void itemsListView_DragEnter(object sender, DragEventArgs e) { }
|
---|
125 | protected override void itemsListView_DragOver(object sender, DragEventArgs e) { }
|
---|
126 | protected override void itemsListView_DragDrop(object sender, DragEventArgs e) { }
|
---|
127 |
|
---|
128 | private ListViewGroup GetListViewGroup(string groupName) {
|
---|
129 | foreach (ListViewGroup group in itemsListView.Groups) {
|
---|
130 | if (group.Name == groupName)
|
---|
131 | return group;
|
---|
132 | }
|
---|
133 | var newGroup = new ListViewGroup(string.Format("Owner ({0})", groupName), HorizontalAlignment.Left) { Name = groupName };
|
---|
134 | itemsListView.Groups.Add(newGroup);
|
---|
135 | return newGroup;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|