Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/25/10 03:32:18 (14 years ago)
Author:
swagner
Message:

Worked on OKB (#1174)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OKB/HeuristicLab.Clients.OKB-3.3/Views/AlgorithmDataView.cs

    r4481 r4492  
    2121
    2222using System;
     23using System.ComponentModel;
    2324using System.IO;
    2425using System.Linq;
     
    3637  [Content(typeof(AlgorithmData), true)]
    3738  public partial class AlgorithmDataView : AsynchronousContentView {
    38     public long AlgorithmId { get; set; }
     39    private long algorithmId;
     40    public long AlgorithmId {
     41      get { return algorithmId; }
     42      set {
     43        algorithmId = value;
     44        if (Content != null) {
     45          Content.AlgorithmId = value;
     46          SetEnabledStateOfControls();
     47        }
     48      }
     49    }
    3950
    4051    public new AlgorithmData Content {
     
    5162      dataTypeComboBox.DataSource = Administrator.Instance.DataTypes.ToList();
    5263      dataTypeComboBox.SelectedIndex = -1;
     64    }
     65
     66    protected override void DeregisterContentEvents() {
     67      Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
     68      base.DeregisterContentEvents();
     69    }
     70    protected override void RegisterContentEvents() {
     71      base.RegisterContentEvents();
     72      Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
    5373    }
    5474
     
    7999    protected override void SetEnabledStateOfControls() {
    80100      base.SetEnabledStateOfControls();
    81       storeDataButton.Enabled = saveFileButton.Enabled = Content != null;
    82       dataTypeComboBox.Enabled = Content != null && viewHost.Content == null;
     101      newDataButton.Enabled = !ReadOnly;
     102      openFileButton.Enabled = !ReadOnly;
     103      saveFileButton.Enabled = (Content != null) && (((Content.Data != null) && (Content.Data.Length != 0)) || (viewHost.Content != null));
     104      storeDataButton.Enabled = saveFileButton.Enabled && (Content.AlgorithmId != 0) && !ReadOnly;
     105      dataTypeComboBox.Enabled = Content != null && viewHost.Content == null && !ReadOnly;
    83106      fileTextBox.Enabled = Content != null;
    84107      groupBox.Enabled = Content != null;
    85108    }
    86109
     110    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     111      switch (e.PropertyName) {
     112        case "DataTypeId":
     113          dataTypeComboBox.SelectedItem = Administrator.Instance.DataTypes.FirstOrDefault(d => d.Id == Content.DataTypeId);
     114          break;
     115      }
     116    }
     117
    87118    private void refreshDataButton_Click(object sender, EventArgs e) {
    88       AlgorithmData data = Administrator.Instance.GetAlgorithmData(AlgorithmId);
    89       Content = data;
     119      BeginAsyncCall();
     120      var call = new Action(delegate() {
     121        AlgorithmData data = Administrator.Instance.GetAlgorithmData(AlgorithmId);
     122        Content = data;
     123      });
     124      call.BeginInvoke(delegate(IAsyncResult result) {
     125        call.EndInvoke(result);
     126        EndAsyncCall();
     127      }, null);
    90128    }
    91129    private void storeDataButton_Click(object sender, EventArgs e) {
     
    95133            IAlgorithm algorithm = viewHost.Content as IAlgorithm;
    96134            algorithm.Prepare(true);
    97             algorithm.Problem = null;
    98135            XmlGenerator.Serialize(algorithm, stream);
    99136            stream.Close();
     
    114151        if (dialog.ShowDialog(this) == DialogResult.OK) {
    115152          try {
    116             if (Content == null) Content = new AlgorithmData { AlgorithmId = AlgorithmId, Data = new byte[0] };
     153            if (Content == null) Content = new AlgorithmData { AlgorithmId = AlgorithmId };
    117154            viewHost.Content = (IContent)dialog.TypeSelector.CreateInstanceOfSelectedType();
    118155            DataType dataType = Administrator.Instance.DataTypes.FirstOrDefault(d => d.Name == viewHost.Content.GetType().AssemblyQualifiedName);
    119156            if (dataType == null) {
    120               dataType = new DataType { Name = viewHost.Content.GetType().AssemblyQualifiedName, SqlName = "Blob" };
     157              dataType = new DataType { Name = viewHost.Content.GetType().AssemblyQualifiedName, SqlName = "varbinary" };
    121158              dataType.PlatformId = Administrator.Instance.Platforms.FirstOrDefault(p => p.Name == "HeuristicLab 3.3").Id;
    122 
    123               Administrator.Instance.Store(dataType);
     159              dataType.Store();
    124160              Administrator.Instance.DataTypes.Add(dataType);
    125161              dataTypeComboBox.DataSource = Administrator.Instance.DataTypes.OrderBy(d => d.Name).ToList();
    126162            }
    127163            dataTypeComboBox.SelectedItem = dataType;
    128             dataTypeComboBox.Enabled = false;
    129164            fileTextBox.Text = "-";
    130165            noViewAvailableLabel.Visible = false;
     166            SetEnabledStateOfControls();
    131167          }
    132168          catch (Exception ex) {
     
    139175      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
    140176        try {
    141           if (Content == null) Content = new AlgorithmData { AlgorithmId = AlgorithmId, Data = new byte[0] };
     177          if (Content == null) Content = new AlgorithmData { AlgorithmId = AlgorithmId };
    142178          IAlgorithm algorithm = null;
    143179          try {
     
    151187            DataType dataType = Administrator.Instance.DataTypes.FirstOrDefault(d => d.Name == viewHost.Content.GetType().AssemblyQualifiedName);
    152188            if (dataType == null) {
    153               dataType = new DataType { Name = viewHost.Content.GetType().AssemblyQualifiedName, SqlName = "Blob" };
     189              dataType = new DataType { Name = viewHost.Content.GetType().AssemblyQualifiedName, SqlName = "varbinary" };
    154190              dataType.PlatformId = Administrator.Instance.Platforms.FirstOrDefault(p => p.Name == "HeuristicLab 3.3").Id;
    155 
    156               Administrator.Instance.Store(dataType);
     191              dataType.Store();
    157192              Administrator.Instance.DataTypes.Add(dataType);
    158193              dataTypeComboBox.DataSource = Administrator.Instance.DataTypes.OrderBy(d => d.Name).ToList();
     
    169204            }
    170205          }
    171           dataTypeComboBox.Enabled = viewHost.Content == null;
    172206          fileTextBox.Text = openFileDialog.FileName;
     207          SetEnabledStateOfControls();
    173208        }
    174209        catch (Exception ex) {
     
    198233      if (Content != null) Content.DataTypeId = ((DataType)dataTypeComboBox.SelectedItem).Id;
    199234    }
     235
     236    private void BeginAsyncCall() {
     237      if (InvokeRequired)
     238        Invoke(new Action(BeginAsyncCall));
     239      else {
     240        Cursor = Cursors.AppStarting;
     241        Enabled = false;
     242      }
     243    }
     244    private void EndAsyncCall() {
     245      if (InvokeRequired)
     246        Invoke(new Action(EndAsyncCall));
     247      else {
     248        Cursor = Cursors.Default;
     249        Enabled = true;
     250      }
     251    }
    200252  }
    201253}
Note: See TracChangeset for help on using the changeset viewer.