using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using HeuristicLab.Hive.Contracts.BusinessObjects; using HeuristicLab.Hive.Contracts.Interfaces; namespace HeuristicLab.Hive.Server.ServerConsole { public class JobListView : ListView { private ContextMenuStrip contextMenuJob; private System.ComponentModel.IContainer components; private ToolStripMenuItem menuItemAbortJob; private ToolStripMenuItem menuItemGetSnapshot; private ImageList ilLargeImgJob; private ImageList ilSmallImgJob; public int NrOfEntriesOnPage { get { return jdf.NrOfEntriesOnPage; } set { jdf.NrOfEntriesOnPage = value; } } private JobDataFetcher jdf; public JobListView(IEnumerable states, int nrOfEntries) : base() { InitializeComponent(); InitializeCustomControls(); jdf = new JobDataFetcher(states, nrOfEntries); jdf.NewDataAvailable += new EventHandler(JdfNewDataAvailable); jdf.Start(); } private void JdfNewDataAvailable(object sender, EventArgs e) { JobDataFetcher datafetcher = (JobDataFetcher) sender; this.BeginUpdate(); if (datafetcher.PollStates.Contains(State.finished)) { this.Items.Clear(); ListViewItem lviDummy = new ListViewItem("blahr", 0); this.Items.Add(lviDummy); foreach (JobDto job in datafetcher.CachedJobs) { ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0); lvi.Tag = job; this.Items.Add(lvi); } } this.EndUpdate(); } public void Forward() { jdf.Forward(); } public void Backward() { jdf.Backward(); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(JobListView)); this.contextMenuJob = new System.Windows.Forms.ContextMenuStrip(this.components); this.menuItemAbortJob = new System.Windows.Forms.ToolStripMenuItem(); this.menuItemGetSnapshot = new System.Windows.Forms.ToolStripMenuItem(); this.ilLargeImgJob = new System.Windows.Forms.ImageList(this.components); this.ilSmallImgJob = new System.Windows.Forms.ImageList(this.components); this.contextMenuJob.SuspendLayout(); this.SuspendLayout(); // // contextMenuJob // this.contextMenuJob.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuItemAbortJob, this.menuItemGetSnapshot}); this.contextMenuJob.Name = "contextMenuJob"; this.contextMenuJob.Size = new System.Drawing.Size(145, 48); // // menuItemAbortJob // this.menuItemAbortJob.Name = "menuItemAbortJob"; this.menuItemAbortJob.Size = new System.Drawing.Size(144, 22); this.menuItemAbortJob.Text = "Abort"; // // menuItemGetSnapshot // this.menuItemGetSnapshot.Name = "menuItemGetSnapshot"; this.menuItemGetSnapshot.Size = new System.Drawing.Size(144, 22); this.menuItemGetSnapshot.Text = "Get Snapshot"; // // ilLargeImgJob // this.ilLargeImgJob.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilLargeImgJob.ImageStream"))); this.ilLargeImgJob.TransparentColor = System.Drawing.Color.Transparent; this.ilLargeImgJob.Images.SetKeyName(0, "ok.png"); this.ilLargeImgJob.Images.SetKeyName(1, "Forward.png"); this.ilLargeImgJob.Images.SetKeyName(2, "pause.png"); // // ilSmallImgJob // this.ilSmallImgJob.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilSmallImgJob.ImageStream"))); this.ilSmallImgJob.TransparentColor = System.Drawing.Color.Transparent; this.ilSmallImgJob.Images.SetKeyName(0, "ok.png"); this.ilSmallImgJob.Images.SetKeyName(1, "Forward.png"); this.ilSmallImgJob.Images.SetKeyName(2, "pause.png"); // // JobListView // this.LargeImageList = this.ilLargeImgJob; this.SmallImageList = this.ilSmallImgJob; this.contextMenuJob.ResumeLayout(false); this.ResumeLayout(false); } private void InitializeCustomControls() { menuItemAbortJob.Click += (s, e) => { IJobManager jobManager = ServiceLocator.GetJobManager(); if (this.SelectedItems.Count == 1) { jobManager.AbortJob(((JobDto) (this.SelectedItems[0].Tag)).Id); } }; //adding context menu items for jobs menuItemGetSnapshot.Click += (s, e) => { IJobManager jobManager = ServiceLocator.GetJobManager(); if (this.SelectedItems.Count == 1) { jobManager.RequestSnapshot(((JobDto) (this.SelectedItems[0].Tag)).Id); } }; } } }