Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8145


Ignore:
Timestamp:
06/28/12 12:00:51 (12 years ago)
Author:
ascheibe
Message:

#1762 implemented review comments:

  • removed self disposing. The progress view now reacts if a progress is set and Finish() is now called on the progress object and not the view.
  • Moved Cancel event from ProgressView to Progress
  • throw ArgumentNullException if the parent view is null
Location:
trunk/sources
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.Access.Views/3.3/ClientViews/ClientView.cs

    r8143 r8145  
    3535
    3636    private ProgressView progressView;
     37    IProgress progress;
    3738
    3839    public ClientView() {
    3940      InitializeComponent();
     41      progressView = new ProgressView(this);
    4042    }
    4143
     
    8284        Invoke(new Action(StartProgressView));
    8385      } else {
    84         if (progressView == null) {
    85           IProgress prog = new Progress();
    86           prog.Status = "Downloading client information. Please be patient.";
    87           progressView = new ProgressView(this, prog);
    88         }
     86        progress = new Progress();
     87        progress.Status = "Downloading client information. Please be patient.";
     88        progressView.Progress = progress;
    8989      }
    9090    }
     
    9494        Invoke(new Action(FinishProgressView));
    9595      } else {
    96         if (progressView != null) {
    97           progressView.Finish();
    98           progressView = null;
    99           SetEnabledStateOfControls();
    100         }
     96        progress.Finish();
     97        SetEnabledStateOfControls();
    10198      }
    10299    }
  • trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs

    r7928 r8145  
    4242    private ISet<TreeNode> filteredTreeNodes;
    4343    private ISet<TreeNode> nodeStore;
     44    private IProgress currentProgress;
    4445
    4546    private ISet<Resource> selectedResources;
     
    6869      imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.MonitorLarge);
    6970      imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.NetworkCenterLarge);
     71      progressView = new ProgressView(this);
    7072    }
    7173
     
    7476        Invoke(new Action(StartProgressView));
    7577      } else {
    76         if (progressView == null) {
    77           IProgress prog = new Progress();
    78           prog.Status = "Downloading resources. Please be patient.";
    79           progressView = new ProgressView(this, prog);
    80         }
     78        currentProgress = new Progress();
     79        currentProgress.Status = "Downloading resources. Please be patient.";
     80        progressView.Progress = currentProgress;
    8181      }
    8282    }
     
    8686        Invoke(new Action(FinishProgressView));
    8787      } else {
    88         if (progressView != null) {
    89           progressView.Finish();
    90           progressView = null;
    91           SetEnabledStateOfControls();
    92         }
     88        currentProgress.Finish();
     89        SetEnabledStateOfControls();
    9390      }
    9491    }
  • trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r8109 r8145  
    5555    public RefreshableHiveJobView() {
    5656      InitializeComponent();
     57      progressView = new ProgressView(this);
    5758    }
    5859
     
    475476        Invoke(new Action(SetProgressView));
    476477      } else {
    477         if (progressView == null) {
    478           progressView = new ProgressView(this, Content.Progress);
    479         } else {
    480           progressView.Progress = Content.Progress;
    481         }
     478        progressView.Progress = Content.Progress;
    482479      }
    483480    }
     
    487484        Invoke(new Action<IProgress>(SetProgressView), progress);
    488485      } else {
    489         if (progressView == null) {
    490           progressView = new ProgressView(this, progress);
    491         } else {
    492           progressView.Progress = progress;
    493         }
     486        progressView.Progress = progress;
    494487      }
    495488    }
     
    499492        Invoke(new Action(FinishProgressView));
    500493      } else {
    501         if (progressView != null) {
    502           progressView.Finish();
    503           progressView = null;
    504           SetEnabledStateOfControls();
    505         }
     494        if (Content.Progress != null)
     495          Content.Progress.Finish();
     496        SetEnabledStateOfControls();
    506497      }
    507498    }
  • trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs

    r7582 r8145  
    3232  public partial class OptimizerHiveTaskView : HiveTaskView {
    3333    private ProgressView progressView;
     34    private IProgress progress;
    3435
    3536    public new OptimizerHiveTask Content {
     
    4445    public OptimizerHiveTaskView() {
    4546      InitializeComponent();
     47      progressView = new ProgressView(this);
    4648    }
    4749
     
    9799
    98100    private void PauseTaskAsync() {
    99       IProgress prog = new Progress();
    100       prog.Status = "Pausing task. Please be patient for the command to take effect.";
    101       SetProgressView(prog);
     101      progress = new Progress();
     102      progress.Status = "Pausing task. Please be patient for the command to take effect.";
     103      SetProgressView(progress);
    102104      Content.Pause();
    103105      FinishProgressView();
     
    105107
    106108    private void StopTaskAsync() {
    107       IProgress prog = new Progress();
    108       prog.Status = "Stopping task. Please be patient for the command to take effect.";
    109       SetProgressView(prog);
     109      progress = new Progress();
     110      progress.Status = "Stopping task. Please be patient for the command to take effect.";
     111      SetProgressView(progress);
    110112      Content.Stop();
    111113      FinishProgressView();
     
    113115
    114116    private void ResumeTaskAsync() {
    115       IProgress prog = new Progress();
    116       prog.Status = "Resuming task. Please be patient for the command to take effect.";
    117       SetProgressView(prog);
     117      progress = new Progress();
     118      progress.Status = "Resuming task. Please be patient for the command to take effect.";
     119      SetProgressView(progress);
    118120      Content.Restart();
    119121      FinishProgressView();
     
    124126        Invoke(new Action<IProgress>(SetProgressView), progress);
    125127      } else {
    126         if (progressView == null) {
    127           progressView = new ProgressView(this, progress);
    128         } else {
    129           progressView.Progress = progress;
    130         }
     128        progressView.Progress = progress;
    131129      }
    132130    }
     
    136134        Invoke(new Action(FinishProgressView));
    137135      } else {
    138         if (progressView != null) {
    139           progressView.Finish();
    140           progressView = null;
    141           SetEnabledStateOfControls();
    142         }
     136        progress.Finish();
     137        SetEnabledStateOfControls();
    143138      }
    144139    }
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs

    r8117 r8145  
    5757    Problem selectedProblem = null;
    5858    private ProgressView progressView;
     59    private IProgress progress;
    5960
    6061    public OKBExperimentUploadView() {
    6162      InitializeComponent();
     63      progressView = new ProgressView(this);
    6264    }
    6365
     
    176178        Invoke(new EventHandler(RunCreationClient_Refreshing), sender, e);
    177179      } else {
    178         IProgress prog = new Progress();
    179         prog.Status = "Refreshing algorithms and problems...";
    180         SetProgressView(prog);
     180        progress = new Progress();
     181        progress.Status = "Refreshing algorithms and problems...";
     182        SetProgressView(progress);
    181183      }
    182184    }
     
    200202
    201203    private void UploadAsync() {
    202       IProgress prog = new Progress();
    203       prog.Status = "Uploading runs to OKB...";
    204       prog.ProgressValue = 0;
     204      progress = new Progress();
     205      progress.Status = "Uploading runs to OKB...";
     206      progress.ProgressValue = 0;
    205207      double count = dataGridView.Rows.Count;
    206208      int i = 0;
    207209
    208       SetProgressView(prog);
     210      SetProgressView(progress);
    209211      foreach (DataGridViewRow row in dataGridView.Rows) {
    210212        selectedAlgorithm = algorithms.Where(x => x.Name == row.Cells[algorithmColumnIndex].Value.ToString()).FirstOrDefault();
     
    217219        run.Store();
    218220        i++;
    219         prog.ProgressValue = ((double)i) / count;
     221        progress.ProgressValue = ((double)i) / count;
    220222      }
    221223      FinishProgressView();
     
    226228        Invoke(new Action<IProgress>(SetProgressView), progress);
    227229      } else {
    228         if (progressView == null) {
    229           progressView = new ProgressView(this, progress);
    230         } else {
    231           progressView.Progress = progress;
    232         }
     230        progressView.Progress = progress;
    233231      }
    234232    }
     
    238236        Invoke(new Action(FinishProgressView));
    239237      } else {
    240         if (progressView != null) {
    241           progressView.Finish();
    242           progressView = null;
    243           SetEnabledStateOfControls();
    244           ClearRuns();
    245         }
     238        progress.Finish();
     239        SetEnabledStateOfControls();
     240        ClearRuns();
    246241      }
    247242    }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Views/ProgressView.cs

    r8135 r8145  
    3535        progress = value;
    3636        RegisterProgressEvents();
     37        ShowProgress();
    3738        OnProgressChanged();
    3839      }
     
    4849    }
    4950
    50     /// <param name="parentView">This is the view which will be locked while progress is made.</param>
    51     public ProgressView(ContentView parentView, IProgress progress) {
     51    private void ShowProgress() {
     52      this.Left = (parentView.ClientRectangle.Width / 2) - (this.Width / 2);
     53      this.Top = (parentView.ClientRectangle.Height / 2) - (this.Height / 2);
     54      this.Anchor = AnchorStyles.Left | AnchorStyles.Top;
     55
     56      LockBackground();
     57
     58      if (!parentView.Controls.Contains(this)) {
     59        parentView.Controls.Add(this);
     60      }
     61
     62      BringToFront();
     63      Visible = true;
     64    }
     65
     66    public ProgressView(ContentView parentView) {
    5267      InitializeComponent();
    53       Progress = progress;
    5468      CancelEnabled = false;
    5569
    5670      if (parentView != null) {
    5771        this.parentView = parentView;
    58         this.Left = (parentView.ClientRectangle.Width / 2) - (this.Width / 2);
    59         this.Top = (parentView.ClientRectangle.Height / 2) - (this.Height / 2);
    60         this.Anchor = AnchorStyles.Left | AnchorStyles.Top;
    61 
    62         LockBackground();
    63 
    64         parentView.Controls.Add(this);
    65         BringToFront();
     72      } else {
     73        throw new ArgumentNullException("The parent view is null.");
    6674      }
    6775    }
     
    7280      progress.StatusChanged += new EventHandler(progress_StatusChanged);
    7381      progress.ProgressValueChanged += new EventHandler(progress_ProgressValueChanged);
     82      progress.Canceled += new EventHandler(progress_Canceled);
    7483    }
    7584
     
    7988      progress.StatusChanged -= new EventHandler(progress_StatusChanged);
    8089      progress.ProgressValueChanged -= new EventHandler(progress_ProgressValueChanged);
     90      progress.Canceled -= new EventHandler(progress_Canceled);
    8191    }
    8292
     
    91101    private void progress_ProgressValueChanged(object sender, EventArgs e) {
    92102      UpdateProgressValue();
     103    }
     104
     105    void progress_Canceled(object sender, EventArgs e) {
     106      Finish();
    93107    }
    94108
     
    128142    }
    129143
    130     public void Finish() {
     144    private void Finish() {
    131145      if (InvokeRequired) {
    132146        Invoke(new Action(Finish));
     
    139153          c.Enabled = true;
    140154        DeregisterProgressEvents();
    141         Dispose();
     155        progress = null;
     156        this.Visible = false;
    142157      }
    143158    }
    144159
    145160    private void cancelButton_Click(object sender, EventArgs e) {
    146       OnCanceled();
    147       Finish();
     161      if (progress != null) {
     162        progress.CancelRequested = true;
     163        cancelButton.Enabled = false;
     164      }
    148165    }
    149166
     
    160177      UpdateProgressValue();
    161178    }
    162 
    163     public event EventHandler Canceled;
    164     protected virtual void OnCanceled() {
    165       var handler = Canceled;
    166       if (handler != null) Canceled(this, EventArgs.Empty);
    167     }
    168179  }
    169180}
  • trunk/sources/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs

    r7582 r8145  
    2828
    2929    void Finish();
     30    void SignalSuccessfulCancelation();
    3031
    3132    event EventHandler Finished;
    3233    event EventHandler StatusChanged;
    3334    event EventHandler ProgressValueChanged;
     35
     36    bool CancelRequested { get; set; }
     37    event EventHandler Canceled;
     38
     39
    3440  }
    3541}
  • trunk/sources/HeuristicLab.MainForm/3.3/Progress.cs

    r7582 r8145  
    3737    }
    3838
     39    public bool CancelRequested { get; set; }
     40
    3941    private double progressValue;
    4042    public double ProgressValue {
     
    6062    }
    6163
     64    public void SignalSuccessfulCancelation() {
     65      OnCanceled();
     66    }
     67
    6268    #region Event Handler
     69    public event EventHandler Canceled;
     70    private void OnCanceled() {
     71      var handler = Canceled;
     72      try {
     73        if (handler != null) handler(this, EventArgs.Empty);
     74      }
     75      catch (Exception) { }
     76    }
     77
    6378    public event EventHandler Finished;
    6479    private void OnFinished() {
Note: See TracChangeset for help on using the changeset viewer.