Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/JobItemView.cs @ 4144

Last change on this file since 4144 was 4144, checked in by cneumuel, 14 years ago

improved HiveExperiment GUI (HL3.3 look&feel, RunCollectionView, JobItem.ToString) (#1115)

File size: 4.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Core.Views;
10using HeuristicLab.MainForm;
11using HeuristicLab.Hive.JobBase;
12using HeuristicLab.Persistence.Default.Xml;
13using System.IO;
14
15namespace HeuristicLab.Hive.Experiment.Views {
16  [View("JobItem View")]
17  [Content(typeof(JobItem), true)]
18  public partial class JobItemView : ItemView {
19    public new JobItem Content {
20      get { return (JobItem)base.Content; }
21      set {
22        if (base.Content != value) {
23          base.Content = value;
24        }
25      }
26    }
27
28    public JobItemView() {
29      InitializeComponent();
30      this.ReadOnly = true;
31    }
32
33    protected override void OnContentChanged() {
34      base.OnContentChanged();
35      if (Content != null) {
36        logView.Content = Content.Log;
37        Content_JobDtoChanged(this, EventArgs.Empty);
38        if (Content.LatestSnapshot != null) {
39          snapshotStatusText.InvokeIfRequired(c => c.Text = Content.LatestSnapshot.StatusMessage);
40          snapshotTimeText.InvokeIfRequired(c => { c.Text = Content.LatestSnapshotTime.ToString(); });
41        }
42      }
43    }
44
45    protected override void RegisterContentEvents() {
46      base.RegisterContentEvents();
47      Content.LatestSnapshotChanged += new EventHandler(Content_LatestSnapshotChanged);
48      Content.JobDtoChanged += new EventHandler(Content_JobDtoChanged);
49    }
50
51    protected override void DeregisterContentEvents() {
52      Content.LatestSnapshotChanged -= new EventHandler(Content_LatestSnapshotChanged);
53      Content.JobDtoChanged -= new EventHandler(Content_JobDtoChanged);
54      base.DeregisterContentEvents();
55    }
56
57    void Content_JobDtoChanged(object sender, EventArgs e) {
58      if (InvokeRequired) {
59        Invoke(new EventHandler(Content_JobDtoChanged), sender, e);
60      } else {
61        this.jobIdTextBox.Text = Content.JobDto.Id.ToString();
62        this.stateTextBox.Text = Content.JobDto.State.ToString();
63        this.userIdTextBox.Text = Content.JobDto.UserId.ToString();
64        this.percentageTextBox.Text = (Content.JobDto.Percentage*100).ToString() + "%";
65        this.percentageProgressBar.Value = Convert.ToInt32(Content.JobDto.Percentage * percentageProgressBar.Maximum);
66        this.dateCreatedTextBox.Text = Content.JobDto.DateCreated.ToString();
67        this.dateCalculatedText.Text = Content.JobDto.DateCalculated.ToString();
68        this.dateFinishedTextBox.Text = Content.JobDto.DateFinished.ToString();
69        this.priorityTextBox.Text = Content.JobDto.Priority.ToString();
70        this.coresNeededTextBox.Text = Content.JobDto.CoresNeeded.ToString();
71        this.memoryNeededTextBox.Text = Content.JobDto.MemoryNeeded.ToString();
72        this.exceptionTextBox.Text = Content.JobDto.Exception;
73        this.projectTextBox.Text = Content.JobDto.Project != null ? Content.JobDto.Project.Name : "-";
74      }
75    }
76
77    void Content_LatestSnapshotChanged(object sender, EventArgs e) {
78      if (InvokeRequired) {
79        Invoke(new EventHandler(Content_LatestSnapshotChanged), sender, e);
80      } else {
81        if (Content.LatestSnapshot != null) {
82          snapshotStatusText.Text = Content.LatestSnapshot.StatusMessage;
83          snapshotTimeText.Text = Content.LatestSnapshotTime.ToString();
84        } else {
85          snapshotStatusText.Text = "";
86          snapshotTimeText.Text = "";
87        }
88        SetEnabledStateOfControls();
89      }
90    }
91
92    protected override void SetEnabledStateOfControls() {
93      base.SetEnabledStateOfControls();
94      openSnapshotButton.Enabled = Content != null && Content.LatestSnapshot != null;
95      this.jobIdTextBox.ReadOnly = this.ReadOnly;
96      this.stateTextBox.ReadOnly = this.ReadOnly;
97      this.userIdTextBox.ReadOnly = this.ReadOnly;
98      this.percentageTextBox.ReadOnly = this.ReadOnly;
99      this.dateCreatedTextBox.ReadOnly = this.ReadOnly;
100      this.dateCalculatedText.ReadOnly = this.ReadOnly;
101      this.dateFinishedTextBox.ReadOnly = this.ReadOnly;
102      this.priorityTextBox.ReadOnly = this.ReadOnly;
103      this.coresNeededTextBox.ReadOnly = this.ReadOnly;
104      this.memoryNeededTextBox.ReadOnly = this.ReadOnly;
105      this.exceptionTextBox.ReadOnly = this.ReadOnly;
106      this.projectTextBox.ReadOnly = this.ReadOnly;
107      this.snapshotStatusText.ReadOnly = this.ReadOnly;
108      this.snapshotTimeText.ReadOnly = this.ReadOnly;
109    }
110
111    private void openSnapshotButton_Click(object sender, EventArgs e) {
112      OptimizerJob job = XmlParser.Deserialize<OptimizerJob>(new MemoryStream(Content.LatestSnapshot.Obj.SerializedJobData));
113      MainFormManager.MainForm.ShowContent(job.Optimizer);
114    }
115
116    private void requestSnapshotButton_Click(object sender, EventArgs e) {
117     
118    }
119  }
120}
Note: See TracBrowser for help on using the repository browser.