Changeset 15477


Ignore:
Timestamp:
11/16/17 10:30:21 (2 years ago)
Author:
pfleck
Message:

#2845

  • Added an explicite method for StartMarquee.
  • Renamed Add/RemoveOperationProgress methods.
  • Moved progress helpers from MainForm into static Progress methods named Show and Hide.
Location:
branches/EnhancedProgress
Files:
28 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/EnhancedProgress/HeuristicLab.Analysis.Statistics.Views/3.3/ChartAnalysisView.cs

    r15446 r15477  
    173173
    174174    private void addLineToChart_Click(object sender, EventArgs e) {
    175       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Adding fitted lines to charts...");
     175      Progress.ShowMarquee(this, "Adding fitted lines to charts...");
    176176
    177177      string resultName = (string)dataTableComboBox.SelectedItem;
     
    181181
    182182      task.ContinueWith((t) => {
    183         MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     183        Progress.Hide(this);
    184184        ErrorHandling.ShowErrorDialog("An error occured while adding lines to charts. ", t.Exception);
    185185      }, TaskContinuationOptions.OnlyOnFaulted);
    186186
    187187      task.ContinueWith((t) => {
    188         MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     188        Progress.Hide(this);
    189189      }, TaskContinuationOptions.OnlyOnRanToCompletion);
    190190    }
     
    273273      var task = Task.Factory.StartNew(() => {
    274274        sem.Wait();
    275         progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values...", 0);
     275        progress = Progress.Show(this, "Calculating values...");
    276276        RebuildDataTable(resultName, rowName);
    277277      });
    278278
    279279      task.ContinueWith((t) => {
    280         MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     280        Progress.Hide(this);
    281281        ErrorHandling.ShowErrorDialog("An error occured while calculating values. ", t.Exception);
    282282        sem.Release();
     
    284284
    285285      task.ContinueWith((t) => {
    286         MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     286        Progress.Hide(this);
    287287        sem.Release();
    288288      }, TaskContinuationOptions.OnlyOnRanToCompletion);
  • branches/EnhancedProgress/HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs

    r14185 r15477  
    356356
    357357      if (data != null && data.All(x => x != null)) {
    358         MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>()
    359           .AddOperationProgressToView(this, "Calculating...");
     358        Progress.ShowMarquee(this, "Calculating...");
    360359
    361360        string curItem = (string)groupCompComboBox.SelectedItem;
     
    369368      CalculatePairwiseTest(groupName);
    370369
    371       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     370      Progress.Hide(this);
    372371    }
    373372
     
    377376        return;
    378377
    379       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");
     378      Progress.ShowMarquee(pairwiseTestGroupBox, "Calculating...");
    380379      Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName));
    381380    }
     
    384383      CalculatePairwiseTest(groupName);
    385384
    386       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);
     385      Progress.Hide(pairwiseTestGroupBox);
    387386    }
    388387
  • branches/EnhancedProgress/HeuristicLab.Clients.Access.Views/3.3/ClientViews/ClientView.cs

    r14185 r15477  
    7777    public void StartProgressView() {
    7878      var message = "Downloading client information. Please be patient.";
    79       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message);
     79      Progress.ShowMarquee(this, message);
    8080    }
    8181
    8282    public void FinishProgressView() {
    83       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     83      Progress.Hide(this);
    8484    }
    8585  }
  • branches/EnhancedProgress/HeuristicLab.Clients.Hive.JobManager/3.3/MenuItems/RunInHiveMenuItem.cs

    r14185 r15477  
    8282      task.ItemTask.ComputeInParallel = content is Experiment || content is BatchRun;
    8383
    84       progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToContent(this.content, "Uploading to Hive...");
     84      progress = Progress.ShowMarquee(this.content, "Uploading to Hive...");
    8585      rJob.Progress = progress;
    8686      progress.ProgressStateChanged += progress_ProgressStateChanged;
     
    9191    private void progress_ProgressStateChanged(object sender, EventArgs e) {
    9292      if (progress.ProgressState != ProgressState.Started) {
    93         MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromContent(content);
     93        Progress.Hide(content);
    9494        progress.ProgressStateChanged -= progress_ProgressStateChanged;
    9595      }
     
    9797
    9898    private void HandleEx(Exception ex) {
    99       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromContent(content);
     99      Progress.Hide(content);
    100100      progress.ProgressStateChanged -= progress_ProgressStateChanged;
    101101      ErrorHandling.ShowErrorDialog("Error uploading tasks", ex);
  • branches/EnhancedProgress/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs

    r14185 r15477  
    6868        Invoke(new Action(StartProgressView));
    6969      } else {
    70         var message = "Downloading resources. Please be patient.";
    71         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message);
     70        Progress.ShowMarquee(this, "Downloading resources. Please be patient.");
    7271      }
    7372    }
     
    7776        Invoke(new Action(FinishProgressView));
    7877      } else {
    79         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     78        Progress.Hide(this);
    8079      }
    8180    }
  • branches/EnhancedProgress/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobListView.cs

    r14185 r15477  
    109109
    110110        task.ContinueWith((t) => {
    111           MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     111          Progress.Hide(this);
    112112          ErrorHandling.ShowErrorDialog("An error occured while deleting the job. ", t.Exception);
    113113        }, TaskContinuationOptions.OnlyOnFaulted);
     
    120120
    121121    private void DeleteHiveJobsAsync(object items) {
    122       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Deleting job...");
     122      Progress.ShowMarquee(this, "Deleting job...");
    123123      foreach (RefreshableJob item in (List<RefreshableJob>)items) {
    124124        Content.Remove(item);
    125125      }
    126       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     126      Progress.Hide(this);
    127127    }
    128128
  • branches/EnhancedProgress/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r14901 r15477  
    7171      Content.Loaded += new EventHandler(Content_Loaded);
    7272      Content.TaskReceived += new EventHandler(Content_TaskReceived);
    73       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, Content.Progress);
     73      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddProgressToView(this, Content.Progress);
    7474    }
    7575
     
    8686      Content.Loaded -= new EventHandler(Content_Loaded);
    8787      Content.TaskReceived -= new EventHandler(Content_TaskReceived);
    88       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this, false);
     88      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveProgressFromView(this, false);
    8989      DeregisterHiveExperimentEvents();
    9090      DeregisterHiveTasksEvents();
     
    137137          }
    138138        }
    139       }
    140       finally {
     139      } finally {
    141140        SuppressEvents = false;
    142141      }
     
    381380
    382381    private void PauseJobAsync(object job) {
    383       Content.Progress.Start("Pausing job...");
     382      Content.Progress.StartMarquee("Pausing job...");
    384383      HiveClient.PauseJob((RefreshableJob)job);
    385384      Content.Progress.Finish();
     
    387386
    388387    private void StopJobAsync(object job) {
    389       Content.Progress.Start("Stopping job...");
     388      Content.Progress.StartMarquee("Stopping job...");
    390389      HiveClient.StopJob((RefreshableJob)job);
    391390      Content.Progress.Finish();
     
    393392
    394393    private void ResumeJobAsync(object job) {
    395       Content.Progress.Start("Resuming job...");
     394      Content.Progress.StartMarquee("Resuming job...");
    396395      HiveClient.ResumeJob((RefreshableJob)job);
    397396      Content.Progress.Finish();
     
    417416        try {
    418417          invoker.EndInvoke(ar);
    419         }
    420         catch (Exception ex) {
    421           ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
     418        } catch (Exception ex) {
     419          ThreadPool.QueueUserWorkItem(delegate (object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
    422420        }
    423421      }, null);
     
    506504          if (subTask is OptimizerHiveTask) {
    507505            OptimizerHiveTask ohTask = subTask as OptimizerHiveTask;
    508             ohTask.ExecuteReadActionOnItemTask(new Action(delegate() {
     506            ohTask.ExecuteReadActionOnItemTask(new Action(delegate () {
    509507              runs.AddRange(ohTask.ItemTask.Item.Runs);
    510508            }));
  • branches/EnhancedProgress/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs

    r15121 r15477  
    4646    protected override void Job_ItemChanged(object sender, EventArgs e) {
    4747      if (Content != null && Content.Task != null && Content.ItemTask.Item != null) {
    48         Content.ExecuteReadActionOnItemTask(new Action(delegate() {
     48        Content.ExecuteReadActionOnItemTask(new Action(delegate () {
    4949          runCollectionViewHost.Content = Content.ItemTask.Item.Runs;
    5050        }));
     
    5858      base.RegisterContentEvents();
    5959      Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged);
    60       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, Content.Progress);
     60      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddProgressToView(this, Content.Progress);
    6161    }
    6262
    6363    protected override void DeregisterContentEvents() {
    6464      Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged);
    65       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this, false);
     65      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveProgressFromView(this, false);
    6666      base.DeregisterContentEvents();
    6767    }
     
    9999
    100100    private void PauseTaskAsync() {
    101       Content.Progress.Start("Pausing task. Please be patient for the command to take effect.");
     101      Content.Progress.StartMarquee("Pausing task. Please be patient for the command to take effect.");
    102102      Content.Pause();
    103103      Content.Progress.Finish();
     
    105105
    106106    private void StopTaskAsync() {
    107       Content.Progress.Start("Stopping task. Please be patient for the command to take effect.");
     107      Content.Progress.StartMarquee("Stopping task. Please be patient for the command to take effect.");
    108108      Content.Stop();
    109109      Content.Progress.Finish();
     
    111111
    112112    private void ResumeTaskAsync() {
    113       Content.Progress.Start("Resuming task. Please be patient for the command to take effect.");
     113      Content.Progress.StartMarquee("Resuming task. Please be patient for the command to take effect.");
    114114      Content.Restart();
    115115      Content.Progress.Finish();
  • branches/EnhancedProgress/HeuristicLab.Clients.Hive/3.3/HeuristicLab.Clients.Hive-3.3.csproj

    r14738 r15477  
    229229      <Private>False</Private>
    230230    </ProjectReference>
     231    <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.3\HeuristicLab.MainForm.WindowsForms-3.3.csproj">
     232      <Project>{AB687BBE-1BFE-476B-906D-44237135431D}</Project>
     233      <Name>HeuristicLab.MainForm.WindowsForms-3.3</Name>
     234      <Private>False</Private>
     235    </ProjectReference>
    231236    <ProjectReference Include="..\..\HeuristicLab.MainForm\3.3\HeuristicLab.MainForm-3.3.csproj">
    232237      <Project>{3BD61258-31DA-4B09-89C0-4F71FEF5F05A}</Project>
  • branches/EnhancedProgress/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r15446 r15477  
    249249      try {
    250250        refreshableJob.IsProgressing = true;
    251         refreshableJob.Progress.Start("Connecting to server...");
     251        refreshableJob.Progress.StartMarquee("Connecting to server...");
    252252        IEnumerable<string> resourceNames = ToResourceNameList(refreshableJob.Job.ResourceNames);
    253253        var resourceIds = new List<Guid>();
     
    414414
    415415        // fetch all task objects to create the full tree of tree of HiveTask objects
    416         refreshableJob.Progress.Start("Downloading list of tasks...");
     416        refreshableJob.Progress.StartMarquee("Downloading list of tasks...");
    417417        allTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(hiveExperiment.Id));
    418418        totalJobCount = allTasks.Count();
  • branches/EnhancedProgress/HeuristicLab.Clients.Hive/3.3/Plugin.cs.frame

    r14195 r15477  
    3636  [PluginDependency("HeuristicLab.Hive", "3.3")] 
    3737  [PluginDependency("HeuristicLab.MainForm", "3.3")]
     38  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
    3839  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3940  [PluginDependency("HeuristicLab.Persistence", "3.3")]
  • branches/EnhancedProgress/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs

    r15446 r15477  
    188188      if (InvokeRequired) { Invoke((Action<object, EventArgs>)RunCreationClient_Refreshing, sender, e); return; }
    189189      var message = "Refreshing algorithms and problems...";
    190       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message);
     190      Progress.ShowMarquee(this, message);
    191191      refreshing = true;
    192192      SetEnabledStateOfControls();
     
    195195    private void RunCreationClient_Refreshed(object sender, EventArgs e) {
    196196      if (InvokeRequired) { Invoke((Action<object, EventArgs>)RunCreationClient_Refreshed, sender, e); return; }
    197       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     197      Progress.Hide(this);
    198198      refreshing = false;
    199199      SetEnabledStateOfControls();
     
    203203      var task = System.Threading.Tasks.Task.Factory.StartNew(UploadAsync);
    204204      task.ContinueWith((t) => {
    205         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     205        Progress.Hide(this);
    206206        PluginInfrastructure.ErrorHandling.ShowErrorDialog("An exception occured while uploading the runs to the OKB.", t.Exception);
    207207      }, TaskContinuationOptions.OnlyOnFaulted);
     
    210210    private void UploadAsync() {
    211211      var message = "Uploading runs to OKB...";
    212       IProgress progress = MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message, 0);
     212      IProgress progress = Progress.Show(this, message);
    213213      double count = dataGridView.Rows.Count;
    214214      int i = 0;
     
    226226        progress.ProgressValue = ((double)i) / count;
    227227      }
    228       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     228      Progress.Hide(this);
    229229      ClearRuns();
    230230    }
  • branches/EnhancedProgress/HeuristicLab.DataPreprocessing.Views/3.4/DataPreprocessingView.cs

    r15446 r15477  
    169169        await Task.Run(() => {
    170170          TProblemData instance;
    171           var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
    172171          // lock active view and show progress bar
    173           var activeView = (IContentView)MainFormManager.MainForm.ActiveView;
    174172
    175173          try {
    176             var progress = mainForm.AddOperationProgressToContent(activeView.Content, "Loading problem instance.", 0);
    177 
     174            var progress = Progress.Show(Content, "Loading problem instance.");
    178175            instanceProvider.ProgressChanged += (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };
    179176
     
    181178          } catch (IOException ex) {
    182179            MessageBox.Show(string.Format("There was an error parsing the file: {0}", Environment.NewLine + ex.Message), "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error);
    183             mainForm.RemoveOperationProgressFromContent(activeView.Content);
     180            Progress.Hide(Content);
    184181            return;
    185182          }
     
    189186            MessageBox.Show(string.Format("This problem does not support loading the instance {0}: {1}", Path.GetFileName(importDialog.Path), Environment.NewLine + ex.Message), "Cannot load instance");
    190187          } finally {
    191             mainForm.RemoveOperationProgressFromContent(activeView.Content);
     188            Progress.Hide(Content);
    192189          }
    193190        });
     
    226223          var storable = itemCreator() as IStorableContent;
    227224          if (storable != null) {
    228             var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
    229             var activeView = (IContentView)MainFormManager.MainForm.ActiveView;
    230225            try {
    231               mainForm.AddOperationProgressToContent(activeView.Content, "Exporting data.");
     226              Progress.ShowMarquee(Content, "Exporting data.");
    232227              ContentManager.Save(storable, saveFileDialog.FileName, compressed);
    233228            } finally {
    234               mainForm.RemoveOperationProgressFromContent(activeView.Content);
     229              Progress.Hide(Content);
    235230            }
    236231          }
     
    248243      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
    249244        Task.Run(() => {
    250           var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
    251           var activeView = (IContentView)MainFormManager.MainForm.ActiveView;
    252245          try {
    253246            var problemData = Content.CreateNewProblemData();
    254             mainForm.AddOperationProgressToContent(activeView.Content, "Exporting data.");
     247            Progress.ShowMarquee(Content, "Exporting data.");
    255248            if (problemData is TimeSeriesPrognosisProblemData)
    256249              Export(new TimeSeriesPrognosisCSVInstanceProvider(), problemData, saveFileDialog.FileName);
     
    260253              Export(new ClassificationCSVInstanceProvider(), problemData, saveFileDialog.FileName);
    261254          } finally {
    262             mainForm.RemoveOperationProgressFromContent(activeView.Content);
     255            Progress.Hide(Content);
    263256          }
    264257        });
  • branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/HeuristicLab.MainForm.WindowsForms-3.3.csproj

    r11623 r15477  
    151151    </Compile>
    152152    <Compile Include="Plugin.cs" />
     153    <Compile Include="Progress.cs" />
    153154    <Compile Include="Views\AsynchronousContentView.cs">
    154155      <SubType>UserControl</SubType>
  • branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs

    r15446 r15477  
    350350    private readonly List<ProgressView> progressViews = new List<ProgressView>();
    351351
    352     public IProgress AddOperationProgressToContent(IContent content, string progressMessage, double? initialProgressValue = null, bool addToObjectGraphObjects = true) {
    353       var progress = new Progress();
    354       if (initialProgressValue.HasValue)
    355         progress.Start(progressMessage, initialProgressValue.Value);
    356       else
    357         progress.Start(progressMessage);
    358       AddOperationProgressToContent(content, progress, addToObjectGraphObjects);
    359       return progress;
    360     }
    361352    /// <summary>
    362353    /// Adds a <see cref="ProgressView"/> to the <see cref="ContentView"/>s showing the specified content.
    363354    /// </summary>
    364     public void AddOperationProgressToContent(IContent content, IProgress progress, bool addToObjectGraphObjects = true) {
     355    public void AddProgressToContent(IContent content, IProgress progress, bool addToObjectGraphObjects = true) {
    365356      if (InvokeRequired) {
    366         Invoke((Action<IContent, IProgress, bool>)AddOperationProgressToContent, content, progress, addToObjectGraphObjects);
     357        Invoke((Action<IContent, IProgress, bool>)AddProgressToContent, content, progress, addToObjectGraphObjects);
    367358        return;
    368359      }
     
    387378    }
    388379
    389     public IProgress AddOperationProgressToView(Control control, string progressMessage, double? initialProgressValue = null) {
    390       var progress = new Progress();
    391       if (initialProgressValue.HasValue)
    392         progress.Start(progressMessage, initialProgressValue.Value);
    393       else
    394         progress.Start(progressMessage);
    395       AddOperationProgressToView(control, progress);
    396       return progress;
    397     }
    398380    /// <summary>
    399381    /// Adds a <see cref="ProgressView"/> to the specified view.
    400382    /// </summary>
    401     public void AddOperationProgressToView(Control control, IProgress progress) {
     383    public void AddProgressToView(Control control, IProgress progress) {
    402384      if (InvokeRequired) {
    403         Invoke((Action<Control, IProgress>)AddOperationProgressToView, control, progress);
     385        Invoke((Action<Control, IProgress>)AddProgressToView, control, progress);
    404386        return;
    405387      }
     
    423405    /// Removes an existing <see cref="ProgressView"/> from the <see cref="ContentView"/>s showing the specified content.
    424406    /// </summary>
    425     public void RemoveOperationProgressFromContent(IContent content, bool finishProgress = true) {
     407    public void RemoveProgressFromContent(IContent content, bool finishProgress = true) {
    426408      if (InvokeRequired) {
    427         Invoke((Action<IContent, bool>)RemoveOperationProgressFromContent, content, finishProgress);
     409        Invoke((Action<IContent, bool>)RemoveProgressFromContent, content, finishProgress);
    428410        return;
    429411      }
     
    439421      }
    440422      contentProgressLookup.Remove(content);
    441 
    442423    }
    443424
     
    445426    /// Removes an existing <see cref="ProgressView"/> from the specified view.
    446427    /// </summary>
    447     public void RemoveOperationProgressFromView(Control control, bool finishProgress = true) {
     428    public void RemoveProgressFromView(Control control, bool finishProgress = true) {
    448429      if (InvokeRequired) {
    449         Invoke((Action<Control, bool>)RemoveOperationProgressFromView, control, finishProgress);
     430        Invoke((Action<Control, bool>)RemoveProgressFromView, control, finishProgress);
    450431        return;
    451432      }
  • branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Progress.cs

    r15466 r15477  
    2121
    2222using System;
     23using System.Windows.Forms;
     24using HeuristicLab.Common;
    2325
    2426namespace HeuristicLab.MainForm {
     
    100102    }
    101103
    102     /// <summary>
    103     /// Starts or restarts an "undefined" progress in marquee-mode
    104     /// </summary>
    105     public void Start(string message) {
    106       ProgressState = ProgressState.Started;
    107       ProgressBarMode = ProgressBarMode.Marquee;
    108       Message = message;
    109     }
    110     /// <summary>
    111     /// Starts or restarts a progress in continuous-mode
    112     /// </summary>
    113     public void Start(string message, double progressValue) {
     104    public void Start(string message, double progressValue = 0) {
    114105      ProgressState = ProgressState.Started;
    115106      ProgressBarMode = ProgressBarMode.Continuous;
    116107      ProgressValue = progressValue;
     108      Message = message;
     109    }
     110    public void StartMarquee(string message) {
     111      ProgressState = ProgressState.Started;
     112      ProgressBarMode = ProgressBarMode.Marquee;
    117113      Message = message;
    118114    }
     
    137133    }
    138134
     135    #region Show/Hide Progress
     136    /// <summary>
     137    /// Shows a started Progress in Continuous-mode on all Views of the specified content.
     138    /// </summary>
     139    public static IProgress Show(IContent content, string progressMessage, double initialProgressValue = 0, bool addToObjectGraphObjects = true) {
     140      var progress = new Progress();
     141      progress.Start(progressMessage, initialProgressValue);
     142      MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToContent(content, progress, addToObjectGraphObjects);
     143      return progress;
     144    }
     145    /// <summary>
     146    /// Shows a started Progress in Marquee-mode on all Views of the specified content.
     147    /// </summary>
     148    public static IProgress ShowMarquee(IContent content, string progressMessage, bool addToObjectGraphObjects = true) {
     149      var progress = new Progress();
     150      progress.StartMarquee(progressMessage);
     151      MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToContent(content, progress, addToObjectGraphObjects);
     152      return progress;
     153    }
     154
     155    /// <summary>
     156    /// Shows a started Progress in Continuous-mode on the specified view.
     157    /// </summary>
     158    public static IProgress Show(Control control, string progressMessage, double initialProgressValue = 0) {
     159      var progress = new Progress();
     160      progress.Start(progressMessage, initialProgressValue);
     161      MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToView(control, progress);
     162      return progress;
     163    }
     164    /// <summary>
     165    /// Shows a started Progress in Marquee-mode on the specified view.
     166    /// </summary>
     167    public static IProgress ShowMarquee(Control control, string progressMessage) {
     168      var progress = new Progress();
     169      progress.StartMarquee(progressMessage);
     170      MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToView(control, progress);
     171      return progress;
     172    }
     173
     174    /// <summary>
     175    /// Hides the Progress fom all Views of the specified content.
     176    /// </summary>
     177    public static void Hide(IContent content) {
     178      MainFormManager.GetMainForm<WindowsForms.MainForm>().RemoveProgressFromContent(content);
     179    }
     180    /// <summary>
     181    /// Hides the Progress fom the specified view.
     182    /// </summary>
     183    public static void Hide(Control control) {
     184      MainFormManager.GetMainForm<WindowsForms.MainForm>().RemoveProgressFromView(control);
     185    }
     186    #endregion
     187
    139188    #region Event Handler
    140189    public event EventHandler ProgressStateChanged;
  • branches/EnhancedProgress/HeuristicLab.MainForm/3.3/HeuristicLab.MainForm-3.3.csproj

    r11623 r15477  
    124124    <Compile Include="Interfaces\IProgress.cs" />
    125125    <Compile Include="Plugin.cs" />
    126     <Compile Include="Progress.cs" />
    127126    <Compile Include="ViewAttribute.cs" />
    128127    <Compile Include="Interfaces\IContentView.cs" />
  • branches/EnhancedProgress/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs

    r15417 r15477  
    3535    /// Changing the ProgressValue when ProgressBarMode is Marquee raises an Exception.
    3636    /// </summary>
     37    /// <exception cref="InvalidOperationException">Setting the ProgressValue-property while in the Marquee state is invalid.</exception>
    3738    double ProgressValue { get; set; }
    3839    bool CanBeStopped { get; }
     
    4041
    4142    /// <summary>
    42     /// Start (or Restart) a progress with ProgressBarMode Marquee
     43    /// Start (or Restart) a progress in ProgressBarMode Continues to display specific progress values (from 0 to 1).
     44    /// A new progress value is reported by setting the ProgressValue-property.
    4345    /// </summary>
    44     void Start(string message);
     46    void Start(string message, double progressValue = 0);
     47
    4548    /// <summary>
    46     /// Start (or Restart) a progress with ProgressBarMode Continues
     49    /// Start (or Restart) a progress in ProgressBarMode Marquee to define an "unknown" progress state.
     50    /// Consider using marquee when the progress is not measurable but the user should be notified that something is still happening.
     51    /// Setting the ProgressValue-property in the Marquee state throws an exception.
    4752    /// </summary>
    48     void Start(string message, double progressValue);
     53    void StartMarquee(string message);
     54
    4955    void Finish();
    5056    void Stop();
  • branches/EnhancedProgress/HeuristicLab.Optimizer/3.3/FileManager.cs

    r14185 r15477  
    161161      mainForm.Invoke((Action)delegate {
    162162        if (showProgress) {
    163           mainForm.AddOperationProgressToContent(content, string.Format("Saving to file \"{0}\"...", Path.GetFileName(fileName ?? content.Filename)));
     163          Progress.ShowMarquee(content, string.Format("Saving to file \"{0}\"...", Path.GetFileName(fileName ?? content.Filename)));
    164164        } else
    165           mainForm.RemoveOperationProgressFromContent(content);
     165          Progress.Hide(content);
    166166      });
    167167      #endregion
  • branches/EnhancedProgress/HeuristicLab.Optimizer/3.3/StartPage.cs

    r15446 r15477  
    8888
    8989    private void LoadSamples(object state) {
    90       progress = MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(samplesListView, "Loading...", 0);
     90      progress = Progress.Show(samplesListView, "Loading...");
    9191      try {
    9292        var assembly = Assembly.GetExecutingAssembly();
     
    112112        OnAllSamplesLoaded();
    113113      } finally {
    114         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(samplesListView);
     114        Progress.Hide(samplesListView);
    115115      }
    116116    }
  • branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicClassificationSolutionView.cs

    r14185 r15477  
    6060        var name = exportFileDialog.FileName;
    6161        using (BackgroundWorker bg = new BackgroundWorker()) {
    62           MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Exportion solution to " + name + ".");
     62          Progress.ShowMarquee(this, "Exportion solution to " + name + ".");
    6363          bg.DoWork += (o, a) => exporter.Export(Content, name);
    64           bg.RunWorkerCompleted += (o, a) => MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     64          bg.RunWorkerCompleted += (o, a) => Progress.Hide(this);
    6565          bg.RunWorkerAsync();
    6666        }
  • branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicDiscriminantFunctionClassificationSolutionView.cs

    r14185 r15477  
    5959        var name = exportFileDialog.FileName;
    6060        using (BackgroundWorker bg = new BackgroundWorker()) {
    61           MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Exportion solution to " + name + ".");
     61          Progress.ShowMarquee(this, "Exportion solution to " + name + ".");
    6262          bg.DoWork += (o, a) => exporter.Export(Content, name);
    63           bg.RunWorkerCompleted += (o, a) => MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     63          bg.RunWorkerCompleted += (o, a) => Progress.Hide(this);
    6464          bg.RunWorkerAsync();
    6565        }
  • branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.cs

    r15371 r15477  
    6161        var name = exportFileDialog.FileName;
    6262        using (BackgroundWorker bg = new BackgroundWorker()) {
    63           MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Exporting solution to " + name + ".");
     63          Progress.ShowMarquee(this, "Exporting solution to " + name + ".");
    6464          bg.DoWork += (o, a) => exporter.Export(Content, name);
    65           bg.RunWorkerCompleted += (o, a) => MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     65          bg.RunWorkerCompleted += (o, a) => Progress.Hide(this);
    6666          bg.RunWorkerAsync();
    6767        }
  • branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r15444 r15477  
    154154      Content.ProblemDataChanged += Content_Changed;
    155155      treeChart.Repainted += treeChart_Repainted;
    156       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress);
     156      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddProgressToView(grpSimplify, progress);
    157157      progress.StopRequested += progress_StopRequested;
    158158    }
     
    162162      Content.ProblemDataChanged -= Content_Changed;
    163163      treeChart.Repainted -= treeChart_Repainted;
    164       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false);
     164      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveProgressFromView(grpSimplify, false);
    165165      progress.StopRequested -= progress_StopRequested;
    166166    }
     
    191191      treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
    192192
    193       progress.Start("Calculate Impact and Replacement Values ...", 0);
     193      progress.Start("Calculate Impact and Replacement Values ...");
    194194      progress.CanBeStopped = true;
    195195      cancellationTokenSource = new CancellationTokenSource();
     
    312312
    313313    private async void btnOptimizeConstants_Click(object sender, EventArgs e) {
    314       progress.Start("Optimizing Constants ...", 0);
     314      progress.Start("Optimizing Constants ...");
    315315      var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone();
    316316      var newTree = await Task.Run(() => OptimizeConstants(tree, progress));
  • branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs

    r14185 r15477  
    7676    public override void Execute() {
    7777      IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
    78       var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
    79       mainForm.AddOperationProgressToContent(activeView.Content, "Removing duplicate datasets.");
     78      var content = activeView.Content;
     79      Progress.ShowMarquee(content, "Removing duplicate datasets.");
    8080
    8181      Action<IContentView> action = (view) => {
     
    9090      };
    9191
    92       action.BeginInvoke(activeView, delegate(IAsyncResult result) {
     92      action.BeginInvoke(activeView, delegate (IAsyncResult result) {
    9393        action.EndInvoke(result);
    94         mainForm.RemoveOperationProgressFromContent(activeView.Content);
     94        Progress.Hide(content);
    9595      }, null);
    9696    }
  • branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r14826 r15477  
    2424using HeuristicLab.Data;
    2525using HeuristicLab.MainForm;
    26 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    2726
    2827namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    8079        || factorVarReplComboBox.SelectedIndex < 0
    8180        || dataPartitionComboBox.SelectedIndex < 0) return;
    82       var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
    8381      variableImactsArrayView.Caption = Content.Name + " Variable Impacts";
    8482      var replMethod =
     
    9391      Task.Factory.StartNew(() => {
    9492        try {
    95           mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
     93          Progress.ShowMarquee(this, "Calculating variable impacts for " + Content.Name);
    9694
    9795          var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod);
     
    10098          variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
    10199        } finally {
    102           mainForm.RemoveOperationProgressFromView(this);
     100          Progress.Hide(this);
    103101        }
    104102      });
  • branches/EnhancedProgress/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/RegressionInstanceProviderView.cs

    r15446 r15477  
    4646
    4747        Task.Factory.StartNew(() => {
    48           var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
     48          var activeView = (IContentView)MainFormManager.MainForm.ActiveView;
     49          var content = activeView.Content;
    4950          // lock active view and show progress bar
    50           IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
     51          try {
     52            var progress = Progress.Show(content, "Loading problem instance.");
    5153
    52           try {
    53             var progress = mainForm.AddOperationProgressToContent(activeView.Content,
    54               "Loading problem instance.", 0);
     54            Content.ProgressChanged += (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };
    5555
    56             Content.ProgressChanged +=
    57               (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };
    58 
    59             instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType,
    60               importTypeDialog.CSVFormat);
     56            instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType, importTypeDialog.CSVFormat);
    6157          } catch (Exception ex) {
    6258            ErrorWhileParsing(ex);
    6359            return;
    6460          } finally {
    65             mainForm.RemoveOperationProgressFromContent(activeView.Content);
     61            Progress.Hide(content);
    6662          }
    6763
  • branches/EnhancedProgress/HeuristicLab.Problems.Instances.Views/3.3/ProblemInstanceProviderViewGeneric.cs

    r14185 r15477  
    121121
    122122        IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
    123         var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
     123        var content = activeView.Content;
    124124        // lock active view and show progress bar
    125         mainForm.AddOperationProgressToContent(activeView.Content, "Loading problem instance.");
     125        Progress.ShowMarquee(content, "Loading problem instance.");
    126126
    127127        Task.Factory.StartNew(() => {
     
    131131          } catch (Exception ex) {
    132132            ErrorHandling.ShowErrorDialog(String.Format("Could not load the problem instance {0}", descriptor.Name), ex);
    133             mainForm.RemoveOperationProgressFromContent(activeView.Content);
     133            Progress.Hide(content);
    134134            return;
    135135          }
     
    139139            ErrorHandling.ShowErrorDialog(String.Format("This problem does not support loading the instance {0}", descriptor.Name), ex);
    140140          } finally {
    141             mainForm.RemoveOperationProgressFromContent(activeView.Content);
     141            Progress.Hide(content);
    142142          }
    143143        });
  • branches/EnhancedProgress/HeuristicLab.Scripting.Views/3.3/ScriptView.cs

    r14185 r15477  
    178178
    179179    private void AddProgressView(string progressMessage) {
    180       var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
    181       mainForm.AddOperationProgressToView(this, progressMessage);
     180      Progress.ShowMarquee(this, progressMessage);
    182181      progressViewCreated = true;
    183182    }
     
    185184    private void RemoveProgressView() {
    186185      if (!progressViewCreated) return;
    187       var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
    188       mainForm.RemoveOperationProgressFromView(this);
     186      Progress.Hide(this);
    189187      progressViewCreated = false;
    190188    }
Note: See TracChangeset for help on using the changeset viewer.