1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Windows.Forms;
|
---|
5 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
6 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
9 | public class JobListView : ListView {
|
---|
10 | private ContextMenuStrip contextMenuJob;
|
---|
11 | private System.ComponentModel.IContainer components;
|
---|
12 | private ToolStripMenuItem menuItemAbortJob;
|
---|
13 | private ToolStripMenuItem menuItemGetSnapshot;
|
---|
14 | private ImageList ilLargeImgJob;
|
---|
15 | private ImageList ilSmallImgJob;
|
---|
16 |
|
---|
17 | public int NrOfEntriesOnPage {
|
---|
18 | get {
|
---|
19 | return jdf.NrOfEntriesOnPage;
|
---|
20 | }
|
---|
21 | set {
|
---|
22 | jdf.NrOfEntriesOnPage = value;
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | private JobDataFetcher jdf;
|
---|
28 |
|
---|
29 | public JobListView(IEnumerable<JobState> states, int nrOfEntries)
|
---|
30 | : base() {
|
---|
31 | InitializeComponent();
|
---|
32 | InitializeCustomControls();
|
---|
33 | jdf = new JobDataFetcher(states, nrOfEntries);
|
---|
34 | jdf.NewDataAvailable += new EventHandler(JdfNewDataAvailable);
|
---|
35 | jdf.Start();
|
---|
36 | }
|
---|
37 |
|
---|
38 | private void JdfNewDataAvailable(object sender, EventArgs e) {
|
---|
39 | JobDataFetcher datafetcher = (JobDataFetcher)sender;
|
---|
40 | this.BeginUpdate();
|
---|
41 | if (datafetcher.PollStates.Contains(JobState.Finished)) {
|
---|
42 | this.Items.Clear();
|
---|
43 | ListViewItem lviDummy = new ListViewItem("blahr", 0);
|
---|
44 | this.Items.Add(lviDummy);
|
---|
45 | foreach (JobDto job in datafetcher.CachedJobs) {
|
---|
46 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0);
|
---|
47 | lvi.Tag = job;
|
---|
48 | this.Items.Add(lvi);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | this.EndUpdate();
|
---|
52 | }
|
---|
53 |
|
---|
54 | public void Forward() {
|
---|
55 | jdf.Forward();
|
---|
56 | }
|
---|
57 |
|
---|
58 | public void Backward() {
|
---|
59 | jdf.Backward();
|
---|
60 | }
|
---|
61 |
|
---|
62 | private void InitializeComponent() {
|
---|
63 | this.components = new System.ComponentModel.Container();
|
---|
64 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(JobListView));
|
---|
65 | this.contextMenuJob = new System.Windows.Forms.ContextMenuStrip(this.components);
|
---|
66 | this.menuItemAbortJob = new System.Windows.Forms.ToolStripMenuItem();
|
---|
67 | this.menuItemGetSnapshot = new System.Windows.Forms.ToolStripMenuItem();
|
---|
68 | this.ilLargeImgJob = new System.Windows.Forms.ImageList(this.components);
|
---|
69 | this.ilSmallImgJob = new System.Windows.Forms.ImageList(this.components);
|
---|
70 | this.contextMenuJob.SuspendLayout();
|
---|
71 | this.SuspendLayout();
|
---|
72 | //
|
---|
73 | // contextMenuJob
|
---|
74 | //
|
---|
75 | this.contextMenuJob.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
---|
76 | this.menuItemAbortJob,
|
---|
77 | this.menuItemGetSnapshot});
|
---|
78 | this.contextMenuJob.Name = "contextMenuJob";
|
---|
79 | this.contextMenuJob.Size = new System.Drawing.Size(145, 48);
|
---|
80 | //
|
---|
81 | // menuItemAbortJob
|
---|
82 | //
|
---|
83 | this.menuItemAbortJob.Name = "menuItemAbortJob";
|
---|
84 | this.menuItemAbortJob.Size = new System.Drawing.Size(144, 22);
|
---|
85 | this.menuItemAbortJob.Text = "Abort";
|
---|
86 | //
|
---|
87 | // menuItemGetSnapshot
|
---|
88 | //
|
---|
89 | this.menuItemGetSnapshot.Name = "menuItemGetSnapshot";
|
---|
90 | this.menuItemGetSnapshot.Size = new System.Drawing.Size(144, 22);
|
---|
91 | this.menuItemGetSnapshot.Text = "Get Snapshot";
|
---|
92 | //
|
---|
93 | // ilLargeImgJob
|
---|
94 | //
|
---|
95 | this.ilLargeImgJob.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilLargeImgJob.ImageStream")));
|
---|
96 | this.ilLargeImgJob.TransparentColor = System.Drawing.Color.Transparent;
|
---|
97 | this.ilLargeImgJob.Images.SetKeyName(0, "ok.png");
|
---|
98 | this.ilLargeImgJob.Images.SetKeyName(1, "Forward.png");
|
---|
99 | this.ilLargeImgJob.Images.SetKeyName(2, "pause.png");
|
---|
100 | //
|
---|
101 | // ilSmallImgJob
|
---|
102 | //
|
---|
103 | this.ilSmallImgJob.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilSmallImgJob.ImageStream")));
|
---|
104 | this.ilSmallImgJob.TransparentColor = System.Drawing.Color.Transparent;
|
---|
105 | this.ilSmallImgJob.Images.SetKeyName(0, "ok.png");
|
---|
106 | this.ilSmallImgJob.Images.SetKeyName(1, "Forward.png");
|
---|
107 | this.ilSmallImgJob.Images.SetKeyName(2, "pause.png");
|
---|
108 | //
|
---|
109 | // JobListView
|
---|
110 | //
|
---|
111 | this.LargeImageList = this.ilLargeImgJob;
|
---|
112 | this.SmallImageList = this.ilSmallImgJob;
|
---|
113 | this.contextMenuJob.ResumeLayout(false);
|
---|
114 | this.ResumeLayout(false);
|
---|
115 |
|
---|
116 | }
|
---|
117 |
|
---|
118 | private void InitializeCustomControls() {
|
---|
119 | menuItemAbortJob.Click += (s, e) => {
|
---|
120 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
121 | if (this.SelectedItems.Count == 1) {
|
---|
122 | jobManager.AbortJob(((JobDto)(this.SelectedItems[0].Tag)).Id);
|
---|
123 | }
|
---|
124 | };
|
---|
125 |
|
---|
126 | //adding context menu items for jobs
|
---|
127 | menuItemGetSnapshot.Click += (s, e) => {
|
---|
128 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
129 | if (this.SelectedItems.Count == 1) {
|
---|
130 | jobManager.RequestSnapshot(((JobDto)(this.SelectedItems[0].Tag)).Id);
|
---|
131 | }
|
---|
132 | };
|
---|
133 | }
|
---|
134 | }
|
---|
135 | } |
---|