Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/02/13 17:04:43 (11 years ago)
Author:
gkronber
Message:

#1508: merged r9804:9805,r9808:9809,r9811:9812,r9822,r9824:9825,r9897,r9928,r9938:9941,r9964:9965,r9989,r9991:9992,r9995,r9997,r10004:10015 from trunk into stable branch.

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.Instances.Views/3.3/ProblemInstanceProviderViewGeneric.cs

    r9456 r10020  
    2121
    2222using System;
     23using System.ComponentModel;
    2324using System.Linq;
     25using System.Threading.Tasks;
    2426using System.Windows.Forms;
    2527using HeuristicLab.MainForm;
     
    8890
    8991    private void instancesComboBox_SelectionChangeCommitted(object sender, System.EventArgs e) {
     92      toolTip.SetToolTip(instancesComboBox, String.Empty);
    9093      if (instancesComboBox.SelectedIndex >= 0) {
    9194        var descriptor = (IDataDescriptor)instancesComboBox.SelectedItem;
    92         T instance = Content.LoadData(descriptor);
    93         try {
    94           GenericConsumer.Load(instance);
    95         } catch (Exception ex) {
    96           ErrorHandling.ShowErrorDialog(String.Format("This problem does not support loading the instance {0}", descriptor.Name), ex);
    97         }
    98         toolTip.SetToolTip(instancesComboBox, descriptor.Description);
    99       } else toolTip.SetToolTip(instancesComboBox, String.Empty);
     95
     96        IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
     97        var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
     98        // lock active view and show progress bar
     99        mainForm.AddOperationProgressToContent(activeView.Content, "Loading problem instance.");
     100        // continuation for removing the progess bar from the active view
     101        Action<Task> removeProgressFromContent = (_) => mainForm.RemoveOperationProgressFromContent(activeView.Content);
     102
     103        // task structure:
     104        // loadFromProvider
     105        // |
     106        // +-> on fault -> show error dialog -> remove progress bar
     107        // |
     108        // `-> success  -> loadToProblem
     109        //                 |
     110        //                 +-> on fault -> show error dialog -> remove progress bar
     111        //                 |
     112        //                 `-> success -> set tool tip -> remove progress bar
     113        var loadFromProvider = new Task<T>(() => Content.LoadData(descriptor));
     114
     115        // success
     116        var loadToProblem = loadFromProvider
     117          .ContinueWith(task => GenericConsumer.Load(task.Result), TaskContinuationOptions.OnlyOnRanToCompletion);
     118        // on error
     119        loadFromProvider
     120          .ContinueWith(task => { ErrorHandling.ShowErrorDialog(String.Format("Could not load the problem instance {0}", descriptor.Name), task.Exception); }, TaskContinuationOptions.OnlyOnFaulted)
     121          .ContinueWith(removeProgressFromContent);
     122
     123        // success
     124        loadToProblem
     125          .ContinueWith(task => toolTip.SetToolTip(instancesComboBox, descriptor.Description), TaskContinuationOptions.OnlyOnRanToCompletion)
     126          .ContinueWith(removeProgressFromContent);
     127        // on error
     128        loadToProblem.ContinueWith(task => { ErrorHandling.ShowErrorDialog(String.Format("This problem does not support loading the instance {0}", descriptor.Name), task.Exception); }, TaskContinuationOptions.OnlyOnFaulted)
     129        .ContinueWith(removeProgressFromContent);
     130
     131        // start async loading task
     132        loadFromProvider.Start();
     133      }
    100134    }
    101135  }
Note: See TracChangeset for help on using the changeset viewer.