Changeset 9894


Ignore:
Timestamp:
08/22/13 11:31:32 (8 years ago)
Author:
ascheibe
Message:

#1042

  • changed Hive views to use MainForm for progress handling
  • removed Cancel timeout
  • setter for ProgressState is now private
  • added Start methods to Progress
  • removed unused methods from RefreshableHiveJobView
Location:
trunk/sources
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs

    r9893 r9894  
    4242    private ISet<TreeNode> filteredTreeNodes;
    4343    private ISet<TreeNode> nodeStore;
    44     private Progress progress;
    45     private ProgressView progressView;
    46 
     44   
    4745    private ISet<Resource> selectedResources;
    4846    public ISet<Resource> SelectedResources {
     
    6462      imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.MonitorLarge);
    6563      imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.NetworkCenterLarge);
    66       progress = new Progress();
    67     }
    68 
    69     protected override void DeregisterContentEvents() {
    70       if (progressView != null) {
    71         progressView.Dispose();
    72         progressView = null;
    73       }
    74       base.DeregisterContentEvents();
    75     }
    76 
    77     protected override void RegisterContentEvents() {
    78       base.RegisterContentEvents();
    79       progressView = new ProgressView(this, progress);
    80     }
    81 
     64    }
     65 
    8266    public void StartProgressView() {
    8367      if (InvokeRequired) {
    8468        Invoke(new Action(StartProgressView));
    8569      } else {
    86         progress.Status = "Downloading resources. Please be patient.";
    87         progress.ProgressState = ProgressState.Started;
     70        var message = "Downloading resources. Please be patient.";
     71        MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message);
    8872      }
    8973    }
     
    9377        Invoke(new Action(FinishProgressView));
    9478      } else {
    95         progress.Finish();
     79        MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    9680      }
    9781    }
  • trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobListView.cs

    r9893 r9894  
    3434  [Content(typeof(ItemCollection<RefreshableJob>), false)]
    3535  public partial class RefreshableHiveJobListView : HeuristicLab.Core.Views.ItemCollectionView<RefreshableJob> {
    36     private Progress progress;
    37     private ProgressView progressView;
    38 
    3936    public RefreshableHiveJobListView() {
    4037      InitializeComponent();
     
    4946
    5047      this.itemsListView.ListViewItemSorter = new ListViewItemDateComparer(0, SortOrder.Ascending);
    51 
    52       progress = new Progress();
    53       progressView = new ProgressView(this, progress);
    5448    }
    5549
     
    115109
    116110        task.ContinueWith((t) => {
    117           progress.Finish();
     111          MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    118112          ErrorHandling.ShowErrorDialog("An error occured while deleting the job. ", t.Exception);
    119113        }, TaskContinuationOptions.OnlyOnFaulted);
     
    126120
    127121    private void DeleteHiveJobsAsync(object items) {
    128       progress.Start("Deleting job...");
     122      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Deleting job...");
    129123      foreach (RefreshableJob item in (List<RefreshableJob>)items) {
    130124        Content.Remove(item);
    131125      }
    132       progress.Finish();
     126      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    133127    }
    134128
     
    222216      if (disposing) {
    223217        if (components != null) components.Dispose();
    224         progressView.Dispose();
    225         progressView = null;
    226218      }
    227219      base.Dispose(disposing);
  • trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r9893 r9894  
    4242  [Content(typeof(RefreshableJob), true)]
    4343  public partial class RefreshableHiveJobView : HeuristicLab.Core.Views.ItemView {
    44     private ProgressView progressView;
    4544    private HiveResourceSelectorDialog hiveResourceSelectorDialog;
    4645    private bool SuppressEvents { get; set; }
     
    7271      Content.Loaded += new EventHandler(Content_Loaded);
    7372      Content.TaskReceived += new EventHandler(Content_TaskReceived);
    74       progressView = new ProgressView(this, Content.Progress);
     73      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, Content.Progress);
    7574    }
    7675
     
    8786      Content.Loaded -= new EventHandler(Content_Loaded);
    8887      Content.TaskReceived -= new EventHandler(Content_TaskReceived);
    89       if (progressView != null) {
    90         progressView.Dispose();
    91         progressView = null;
    92       }
     88      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this, false);
    9389      DeregisterHiveExperimentEvents();
    9490      DeregisterHiveTasksEvents();
     
    251247        SetEnabledStateOfControls();
    252248    }
    253     private void Content_Prepared(object sender, EventArgs e) {
    254       if (InvokeRequired)
    255         Invoke(new EventHandler(Content_Prepared), sender, e);
    256       else {
    257         nameTextBox.Enabled = true;
    258         Locked = false;
    259         SetEnabledStateOfControls();
    260       }
    261     }
    262     private void Content_Started(object sender, EventArgs e) {
    263       if (InvokeRequired)
    264         Invoke(new EventHandler(Content_Started), sender, e);
    265       else {
    266         nameTextBox.Enabled = false;
    267         SetEnabledStateOfControls();
    268       }
    269     }
    270     private void Content_Paused(object sender, EventArgs e) {
    271       if (InvokeRequired)
    272         Invoke(new EventHandler(Content_Paused), sender, e);
    273       else {
    274         nameTextBox.Enabled = true;
    275         SetEnabledStateOfControls();
    276       }
    277     }
    278     private void Content_Stopped(object sender, EventArgs e) {
    279       if (InvokeRequired)
    280         Invoke(new EventHandler(Content_Stopped), sender, e);
    281       else {
    282         nameTextBox.Enabled = true;
    283         Locked = false;
    284         SetEnabledStateOfControls();
    285       }
    286     }
     249
    287250    private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
    288251      if (InvokeRequired)
  • trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs

    r9893 r9894  
    3232  public partial class OptimizerHiveTaskView : HiveTaskView {
    3333    private Progress progress;
    34     private ProgressView progressView;
    35 
     34   
    3635    public new OptimizerHiveTask Content {
    3736      get { return (OptimizerHiveTask)base.Content; }
     
    6160      base.RegisterContentEvents();
    6261      Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged);
    63       progressView = new ProgressView(this, progress);
     62      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, progress);
    6463    }
    6564
    6665    protected override void DeregisterContentEvents() {
    6766      Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged);
    68       if (progressView != null) {
    69         progressView.Dispose();
    70         progressView = null;
    71       }
     67      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this, false);
    7268      base.DeregisterContentEvents();
    7369    }
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs

    r9893 r9894  
    5454    Algorithm selectedAlgorithm = null;
    5555    Problem selectedProblem = null;
    56     private ProgressView progressView;
    57     private Progress progress;
    5856
    5957    public OKBExperimentUploadView() {
    6058      InitializeComponent();
    61       progress = new Progress();
    6259    }
    6360
     
    9390      RunCreationClient.Instance.Refreshing += new EventHandler(RunCreationClient_Refreshing);
    9491      RunCreationClient.Instance.Refreshed += new EventHandler(RunCreationClient_Refreshed);
    95       progressView = new ProgressView(this, progress);
    9692    }
    9793
     
    9995      RunCreationClient.Instance.Refreshing -= new EventHandler(RunCreationClient_Refreshing);
    10096      RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed);
    101       if (progressView != null) {
    102         progressView.Dispose();
    103         progressView = null;
    104       }
     97
    10598      base.DeregisterContentEvents();
    10699    }
     
    194187        Invoke(new EventHandler(RunCreationClient_Refreshing), sender, e);
    195188      } else {
    196         progress.Status = "Refreshing algorithms and problems...";
    197         progress.ProgressState = ProgressState.Started;
     189        var message = "Refreshing algorithms and problems...";
     190        MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message);
    198191      }
    199192    }
     
    203196        Invoke(new EventHandler(RunCreationClient_Refreshed), sender, e);
    204197      } else {
    205         progress.Finish();
     198        MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    206199        SetEnabledStateOfControls();
    207200      }
     
    211204      var task = System.Threading.Tasks.Task.Factory.StartNew(UploadAsync);
    212205      task.ContinueWith((t) => {
    213         progress.Finish();
     206        MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    214207        PluginInfrastructure.ErrorHandling.ShowErrorDialog("An exception occured while uploading the runs to the OKB.", t.Exception);
    215208      }, TaskContinuationOptions.OnlyOnFaulted);
     
    217210
    218211    private void UploadAsync() {
    219       progress.Status = "Uploading runs to OKB...";
    220       progress.ProgressValue = 0;
    221       progress.ProgressState = ProgressState.Started;
     212      var message = "Uploading runs to OKB...";
     213      IProgress progress = MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message);
    222214      double count = dataGridView.Rows.Count;
    223215      int i = 0;
     
    234226        progress.ProgressValue = ((double)i) / count;
    235227      }
    236       progress.Finish();
     228      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    237229      ClearRuns();
    238230    }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs

    r9893 r9894  
    2424
    2525namespace HeuristicLab.MainForm.WindowsForms {
    26   public sealed partial class ProgressView : UserControl {
     26  internal sealed partial class ProgressView : UserControl {
    2727    private readonly Control control;
    2828    public Control Control {
     
    4646        ShowProgress();
    4747      RegisterContentEvents();
     48    }
     49
     50    /// <summary>
     51    /// Clean up any resources being used.
     52    /// </summary>
     53    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
     54    protected override void Dispose(bool disposing) {
     55      DeregisterContentEvents();
     56      HideProgress();
     57
     58      if (disposing && (components != null)) {
     59        components.Dispose();
     60      }
     61      base.Dispose(disposing);
    4862    }
    4963
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.designer.cs

    r9893 r9894  
    2727    private System.ComponentModel.IContainer components = null;
    2828
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       DeregisterContentEvents();
    35       if (disposing && (components != null)) {
    36         components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    40 
     29   
    4130    #region Component Designer generated code
    4231
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs

    r9893 r9894  
    353353    /// Adds a <see cref="ProgressView"/> to the <see cref="ContentView"/>s showing the specified content.
    354354    /// </summary>
    355     public void AddOperationProgressToContent(IContent content, string progressMessage, bool addToObjectGraphObjects = true) {
     355    public IProgress AddOperationProgressToContent(IContent content, string progressMessage, bool addToObjectGraphObjects = true) {
    356356      if (contentProgressLookup.ContainsKey(content))
    357357        throw new ArgumentException("A progress is already registered for the specified content.", "content");
     
    373373
    374374      contentProgressLookup[content] = progress;
     375      return progress;
    375376    }
    376377
     
    378379    /// Adds a <see cref="ProgressView"/> to the specified view.
    379380    /// </summary>
    380     public void AddOperationProgressToView(IView view, string progressMessage) {
    381       if (viewProgressLookup.ContainsKey(view))
    382         throw new ArgumentException("A progress is already registered for the specified view.", "view");
     381    public IProgress AddOperationProgressToView(IView view, string progressMessage) {
     382      var progress = new Progress(progressMessage, ProgressState.Started);
     383      AddOperationProgressToView(view, progress);
     384      return progress;
     385    }
     386
     387    public void AddOperationProgressToView(IView view, IProgress progress) {
     388      if (view == null) throw new ArgumentNullException("view", "The view must not be null.");
     389      if (progress == null) throw new ArgumentNullException("progress", "The progress must not be null.");
    383390
    384391      var control = view as Control;
    385392      if (control == null) throw new ArgumentException("The passed view must be a control.", "view");
    386393
    387       var progress = new Progress(progressMessage, ProgressState.Started);
     394      IProgress oldProgress;
     395      if (viewProgressLookup.TryGetValue(view, out oldProgress)) {
     396        foreach (var progressView in progressViews.Where(v => v.Content == oldProgress).ToList()) {
     397          progressView.Dispose();
     398          progressViews.Remove(progressView);
     399        }
     400        viewProgressLookup.Remove(view);
     401      }
     402
    388403      progressViews.Add(new ProgressView(control, progress));
    389404      viewProgressLookup[view] = progress;
     
    393408    /// Removes an existing <see cref="ProgressView"/> from the <see cref="ContentView"/>s showing the specified content.
    394409    /// </summary>
    395     public void RemoveOperationProgressFromContent(IContent content) {
     410    public void RemoveOperationProgressFromContent(IContent content, bool finishProgress = true) {
    396411      IProgress progress;
    397412      if (!contentProgressLookup.TryGetValue(content, out progress))
    398413        throw new ArgumentException("No progress is registered for the specified content.", "content");
    399414
    400       progress.Finish();
     415      if (finishProgress) progress.Finish();
    401416      foreach (var progressView in progressViews.Where(v => v.Content == progress).ToList()) {
    402417        progressView.Dispose();
     
    409424    /// Removes an existing <see cref="ProgressView"/> from the specified view.
    410425    /// </summary>
    411     public void RemoveOperationProgressFromView(IView view) {
     426    public void RemoveOperationProgressFromView(IView view, bool finishProgress = true) {
    412427      IProgress progress;
    413428      if (!viewProgressLookup.TryGetValue(view, out progress))
    414429        throw new ArgumentException("No progress is registered for the specified view.", "view");
    415430
    416       progress.Finish();
     431      if (finishProgress) progress.Finish();
    417432      foreach (var progressView in progressViews.Where(v => v.Content == progress).ToList()) {
    418433        progressView.Dispose();
  • trunk/sources/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs

    r9893 r9894  
    4141    /// If it is reused it may be Started again.
    4242    /// </summary>
    43     ProgressState ProgressState { get; set; }
     43    ProgressState ProgressState { get; }
    4444    /// <summary>
    4545    /// Returns whether the operation can be canceled or not.
     
    5454    /// </summary>
    5555    /// <exception cref="NotSupportedException">Thrown when cancellation is not supported.</exception>
    56     /// <param name="timeoutMs">The operation is given a certain timeout to cancel. If the operation doesn't cancel in this time it will be forcibly closed.</param>
    57     void Cancel(int timeoutMs = 0);
     56    void Cancel();
    5857    /// <summary>
    5958    /// Sets the ProgressValue to 1 and the ProgressState to Finished.
     
    6160    void Finish();
    6261
     62    /// <summary>
     63    /// Starts or restarts a Progress.
     64    /// </summary>
     65    void Start();
     66
    6367    void Start(string status);
    64 
    65     void Start();
    6668
    6769    /// <summary>
     
    8284    event EventHandler CanBeCanceledChanged;
    8385    /// <summary>
    84     /// A cancelation is requested with a certain timeout (in ms) in which it should occur gracefully. If the timeout is surpassed, it should be forcibly canceled.
     86    /// A cancelation is requested.
    8587    /// </summary>
    86     event EventHandler<EventArgs<int>> CancelRequested;
     88    event EventHandler CancelRequested;
    8789  }
    8890}
  • trunk/sources/HeuristicLab.MainForm/3.3/Progress.cs

    r9893 r9894  
    2121
    2222using System;
    23 using HeuristicLab.Common;
    2423
    2524namespace HeuristicLab.MainForm {
     
    5049    public ProgressState ProgressState {
    5150      get { return progressState; }
    52       set {
     51      private set {
    5352        if (progressState != value) {
    5453          progressState = value;
     
    8382    }
    8483
    85     public void Cancel(int timeoutMs = 0) {
     84    public void Cancel() {
    8685      if (canBeCanceled)
    87         OnCancelRequested(timeoutMs);
     86        OnCancelRequested();
    8887    }
    8988
     
    126125      var handler = CanBeCanceledChanged;
    127126      if (handler != null) handler(this, EventArgs.Empty);
    128 
    129127    }
    130128
    131     public event EventHandler<EventArgs<int>> CancelRequested;
    132     private void OnCancelRequested(int timeoutMs) {
     129    public event EventHandler CancelRequested;
     130    private void OnCancelRequested() {
    133131      var handler = CancelRequested;
    134132      if (handler != null) throw new NotSupportedException("Cancel request was ignored.");
    135       else handler(this, new EventArgs<int>(timeoutMs));
     133      else handler(this, EventArgs.Empty);
    136134    }
    137135    #endregion
Note: See TracChangeset for help on using the changeset viewer.