Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/26/15 23:00:51 (9 years ago)
Author:
abeham
Message:

#2477:

  • Changed OKBExperimentUploadView to not be a ContentView anymore
  • Make automatic suggestion on OKBAlgorithm and OKBProblem based on equality of name and data type
  • Add an upload checkbox column in order to deselect individual runs from upload
Location:
trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.Designer.cs

    r12012 r12971  
    3535        components.Dispose();
    3636      }
     37      DisposeSpecific();
    3738      base.Dispose(disposing);
    3839    }
     
    4849      this.btnUpload = new System.Windows.Forms.Button();
    4950      this.dataGridView = new System.Windows.Forms.DataGridView();
     51      this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
     52      this.setColumnToThisValueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     53      this.clearButton = new System.Windows.Forms.Button();
    5054      this.RunNameColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
    5155      this.AlgorithmNameColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
     
    5559      this.ProblemTypeColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
    5660      this.OKBProblemColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
    57       this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
    58       this.setColumnToThisValueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    59       this.clearButton = new System.Windows.Forms.Button();
     61      this.UploadColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
    6062      ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
    6163      this.contextMenu.SuspendLayout();
     
    8082      this.dataGridView.AllowUserToOrderColumns = true;
    8183      this.dataGridView.AllowUserToResizeRows = false;
    82       this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    83                   | System.Windows.Forms.AnchorStyles.Left)
    84                   | System.Windows.Forms.AnchorStyles.Right)));
     84      this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     85            | System.Windows.Forms.AnchorStyles.Left)
     86            | System.Windows.Forms.AnchorStyles.Right)));
    8587      this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
    8688      this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
     
    9294            this.ProblemNameColumn,
    9395            this.ProblemTypeColumn,
    94             this.OKBProblemColumn});
     96            this.OKBProblemColumn,
     97            this.UploadColumn});
    9598      this.dataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
    9699      this.dataGridView.Location = new System.Drawing.Point(3, 3);
     
    102105      this.dataGridView.DragEnter += new System.Windows.Forms.DragEventHandler(this.dataGridView_DragEnter);
    103106      //
    104       // RunNameColumn
    105       //
    106       this.RunNameColumn.HeaderText = "Run Name";
    107       this.RunNameColumn.Name = "RunNameColumn";
    108       this.RunNameColumn.ReadOnly = true;
    109       //
    110       // AlgorithmNameColumn
    111       //
    112       this.AlgorithmNameColumn.HeaderText = "Algorithm Name";
    113       this.AlgorithmNameColumn.Name = "AlgorithmNameColumn";
    114       this.AlgorithmNameColumn.ReadOnly = true;
    115       //
    116       // AlgorithmTypeColumn
    117       //
    118       this.AlgorithmTypeColumn.HeaderText = "Algorithm Type";
    119       this.AlgorithmTypeColumn.Name = "AlgorithmTypeColumn";
    120       this.AlgorithmTypeColumn.ReadOnly = true;
    121       //
    122       // OKBAlgorithmColumn
    123       //
    124       this.OKBAlgorithmColumn.HeaderText = "OKB Algorithm";
    125       this.OKBAlgorithmColumn.Name = "OKBAlgorithmColumn";
    126       //
    127       // ProblemNameColumn
    128       //
    129       this.ProblemNameColumn.HeaderText = "Problem Name";
    130       this.ProblemNameColumn.Name = "ProblemNameColumn";
    131       this.ProblemNameColumn.ReadOnly = true;
    132       this.ProblemNameColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
    133       this.ProblemNameColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
    134       //
    135       // ProblemTypeColumn
    136       //
    137       this.ProblemTypeColumn.HeaderText = "Problem Type";
    138       this.ProblemTypeColumn.Name = "ProblemTypeColumn";
    139       this.ProblemTypeColumn.ReadOnly = true;
    140       this.ProblemTypeColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
    141       this.ProblemTypeColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
    142       //
    143       // OKBProblemColumn
    144       //
    145       this.OKBProblemColumn.HeaderText = "OKB Problem";
    146       this.OKBProblemColumn.Name = "OKBProblemColumn";
    147       //
    148107      // contextMenu
    149108      //
     
    170129      this.clearButton.UseVisualStyleBackColor = true;
    171130      this.clearButton.Click += new System.EventHandler(this.clearButton_Click);
     131      //
     132      // RunNameColumn
     133      //
     134      this.RunNameColumn.HeaderText = "Run Name";
     135      this.RunNameColumn.Name = "RunNameColumn";
     136      this.RunNameColumn.ReadOnly = true;
     137      //
     138      // AlgorithmNameColumn
     139      //
     140      this.AlgorithmNameColumn.HeaderText = "Algorithm Name";
     141      this.AlgorithmNameColumn.Name = "AlgorithmNameColumn";
     142      this.AlgorithmNameColumn.ReadOnly = true;
     143      //
     144      // AlgorithmTypeColumn
     145      //
     146      this.AlgorithmTypeColumn.HeaderText = "Algorithm Type";
     147      this.AlgorithmTypeColumn.Name = "AlgorithmTypeColumn";
     148      this.AlgorithmTypeColumn.ReadOnly = true;
     149      //
     150      // OKBAlgorithmColumn
     151      //
     152      this.OKBAlgorithmColumn.HeaderText = "OKB Algorithm";
     153      this.OKBAlgorithmColumn.Name = "OKBAlgorithmColumn";
     154      //
     155      // ProblemNameColumn
     156      //
     157      this.ProblemNameColumn.HeaderText = "Problem Name";
     158      this.ProblemNameColumn.Name = "ProblemNameColumn";
     159      this.ProblemNameColumn.ReadOnly = true;
     160      this.ProblemNameColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
     161      this.ProblemNameColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
     162      //
     163      // ProblemTypeColumn
     164      //
     165      this.ProblemTypeColumn.HeaderText = "Problem Type";
     166      this.ProblemTypeColumn.Name = "ProblemTypeColumn";
     167      this.ProblemTypeColumn.ReadOnly = true;
     168      this.ProblemTypeColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
     169      this.ProblemTypeColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
     170      //
     171      // OKBProblemColumn
     172      //
     173      this.OKBProblemColumn.HeaderText = "OKB Problem";
     174      this.OKBProblemColumn.Name = "OKBProblemColumn";
     175      //
     176      // UploadColumn
     177      //
     178      this.UploadColumn.HeaderText = "Upload?";
     179      this.UploadColumn.Name = "UploadColumn";
     180      this.UploadColumn.ToolTipText = "Whether the run should be uploaded or not.";
    172181      //
    173182      // OKBExperimentUploadView
     
    191200    private System.Windows.Forms.Button btnUpload;
    192201    private System.Windows.Forms.DataGridView dataGridView;
     202    private System.Windows.Forms.ContextMenuStrip contextMenu;
     203    private System.Windows.Forms.ToolStripMenuItem setColumnToThisValueToolStripMenuItem;
     204    private System.Windows.Forms.Button clearButton;
    193205    private System.Windows.Forms.DataGridViewTextBoxColumn RunNameColumn;
    194206    private System.Windows.Forms.DataGridViewTextBoxColumn AlgorithmNameColumn;
     
    198210    private System.Windows.Forms.DataGridViewTextBoxColumn ProblemTypeColumn;
    199211    private System.Windows.Forms.DataGridViewComboBoxColumn OKBProblemColumn;
    200     private System.Windows.Forms.ContextMenuStrip contextMenu;
    201     private System.Windows.Forms.ToolStripMenuItem setColumnToThisValueToolStripMenuItem;
    202     private System.Windows.Forms.Button clearButton;
     212    private System.Windows.Forms.DataGridViewCheckBoxColumn UploadColumn;
    203213  }
    204214}
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs

    r12012 r12971  
    2828using HeuristicLab.Clients.Access;
    2929using HeuristicLab.Core;
    30 using HeuristicLab.Core.Views;
    3130using HeuristicLab.MainForm;
    32 using HeuristicLab.MainForm.WindowsForms;
    3331using HeuristicLab.Optimization;
     32using View = HeuristicLab.MainForm.WindowsForms.View;
    3433
    3534namespace HeuristicLab.Clients.OKB.RunCreation {
    3635  [View("OKBExperimentUpload View")]
    37   [Content(typeof(IOptimizer), false)]
    38   public partial class OKBExperimentUploadView : ItemView {
    39     public new IOptimizer Content {
    40       get { return (IOptimizer)base.Content; }
    41       set { base.Content = value; }
    42     }
    43 
    44     private const string algorithmTypeParameterName = "Algorithm Type";
    45     private const string problemTypeParameterName = "Problem Type";
    46     private const string algorithmNameParameterName = "Algorithm Name";
    47     private const string problemNameParameterName = "Problem Name";
    48     private const int algorithmColumnIndex = 3;
    49     private const int problemColumnIndex = 6;
     36  public partial class OKBExperimentUploadView : View {
     37
     38    private const string AlgorithmTypeParameterName = "Algorithm Type";
     39    private const string ProblemTypeParameterName = "Problem Type";
     40    private const string AlgorithmNameParameterName = "Algorithm Name";
     41    private const string ProblemNameParameterName = "Problem Name";
    5042
    5143    private List<IRun> runs = new List<IRun>();
     
    5749    public OKBExperimentUploadView() {
    5850      InitializeComponent();
    59     }
    60 
    61     protected override void OnContentChanged() {
    62       base.OnContentChanged();
    63       if (Content == null) {
    64         ClearRuns();
    65       } else {
    66         AddRuns(Content);
    67       }
    68     }
    69 
    70     private void AddRuns(IItem item) {
     51      OKBAlgorithmColumn.ValueType = typeof(Algorithm);
     52      OKBAlgorithmColumn.ValueMember = "Name";
     53      OKBAlgorithmColumn.DisplayMember = "Name";
     54      OKBProblemColumn.ValueType = typeof(Problem);
     55      OKBProblemColumn.ValueMember = "Name";
     56      OKBProblemColumn.DisplayMember = "Name";
     57      RunCreationClient.Instance.Refreshing += RunCreationClient_Refreshing;
     58      RunCreationClient.Instance.Refreshed += RunCreationClient_Refreshed;
     59    }
     60
     61    private void DisposeSpecific() {
     62      RunCreationClient.Instance.Refreshing -= RunCreationClient_Refreshing;
     63      RunCreationClient.Instance.Refreshed -= RunCreationClient_Refreshed;
     64    }
     65
     66    private bool refreshing;
     67
     68    protected override void SetEnabledStateOfControls() {
     69      if (InvokeRequired) { Invoke((Action)SetEnabledStateOfControls); return; }
     70      base.SetEnabledStateOfControls();
     71      btnUpload.Enabled = runs.Count > 0 && !refreshing;
     72    }
     73
     74    public void AddRuns(IItem item) {
     75      if (InvokeRequired) { Invoke((Action<IItem>)AddRuns, item); return; }
    7176      if (item is Experiment) {
    7277        runs.AddRange((item as Experiment).Runs);
     
    8489        DisplayRuns(tmp);
    8590      }
    86     }
    87 
    88     protected override void RegisterContentEvents() {
    89       base.RegisterContentEvents();
    90       RunCreationClient.Instance.Refreshing += new EventHandler(RunCreationClient_Refreshing);
    91       RunCreationClient.Instance.Refreshed += new EventHandler(RunCreationClient_Refreshed);
    92     }
    93 
    94     protected override void DeregisterContentEvents() {
    95       RunCreationClient.Instance.Refreshing -= new EventHandler(RunCreationClient_Refreshing);
    96       RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed);
    97 
    98       base.DeregisterContentEvents();
     91      SetEnabledStateOfControls();
    9992    }
    10093
     
    117110
    118111    private void CreateUI(RunCollection runs) {
    119       if (InvokeRequired) {
    120         Invoke(new Action<RunCollection>(CreateUI), runs);
    121       } else {
    122         if (problems.Count == 0)
    123           problems.AddRange(RunCreationClient.Instance.Problems);
    124         if (algorithms.Count == 0)
    125           algorithms.AddRange(RunCreationClient.Instance.Algorithms);
    126 
    127         IItem algorithmType;
    128         IItem problemType;
    129         IItem algorithmName;
    130         IItem problemName;
    131 
    132         DataGridViewComboBoxColumn cmbAlgorithm = dataGridView.Columns[algorithmColumnIndex] as DataGridViewComboBoxColumn;
    133         cmbAlgorithm.DataSource = algorithms;
    134         cmbAlgorithm.DisplayMember = "Name";
    135 
    136         DataGridViewComboBoxColumn cmbProblem = dataGridView.Columns[problemColumnIndex] as DataGridViewComboBoxColumn;
    137         cmbProblem.DataSource = problems;
    138         cmbProblem.DisplayMember = "Name";
    139 
    140         foreach (IRun run in runs) {
    141           int idx = dataGridView.Rows.Add(run.Name);
    142           DataGridViewRow curRow = dataGridView.Rows[idx];
    143           curRow.Tag = run;
    144 
    145           if (run.Parameters.TryGetValue(algorithmTypeParameterName, out algorithmType)) {
    146             HeuristicLab.Data.StringValue algStr = algorithmType as HeuristicLab.Data.StringValue;
    147             if (algStr != null) {
    148               curRow.Cells[1].Value = algStr;
    149             }
    150           }
    151 
    152           if (run.Parameters.TryGetValue(algorithmNameParameterName, out algorithmName)) {
    153             HeuristicLab.Data.StringValue algStr = algorithmName as HeuristicLab.Data.StringValue;
    154             if (algStr != null) {
    155               curRow.Cells[2].Value = algStr;
    156             }
    157           }
    158 
    159           if (run.Parameters.TryGetValue(problemTypeParameterName, out problemType)) {
    160             HeuristicLab.Data.StringValue prbStr = problemType as HeuristicLab.Data.StringValue;
    161             if (prbStr != null) {
    162               curRow.Cells[4].Value = prbStr;
    163             }
    164           }
    165 
    166           if (run.Parameters.TryGetValue(problemNameParameterName, out problemName)) {
    167             HeuristicLab.Data.StringValue prbStr = problemName as HeuristicLab.Data.StringValue;
    168             if (prbStr != null) {
    169               curRow.Cells[5].Value = prbStr;
    170             }
    171           }
    172         }
    173       }
    174     }
    175 
    176     private void ClearRuns() {
    177       if (InvokeRequired) {
    178         Invoke(new Action(ClearRuns));
    179       } else {
    180         dataGridView.Rows.Clear();
    181         runs.Clear();
    182       }
     112      if (InvokeRequired) { Invoke((Action<RunCollection>)CreateUI, runs); return; }
     113      if (problems.Count == 0)
     114        problems.AddRange(RunCreationClient.Instance.Problems);
     115      if (algorithms.Count == 0)
     116        algorithms.AddRange(RunCreationClient.Instance.Algorithms);
     117
     118      IItem algorithmType;
     119      IItem problemType;
     120      IItem algorithmName;
     121      IItem problemName;
     122
     123      OKBAlgorithmColumn.DataSource = algorithms;
     124      OKBProblemColumn.DataSource = problems;
     125
     126      foreach (IRun run in runs) {
     127        int idx = dataGridView.Rows.Add(run.Name);
     128        DataGridViewRow curRow = dataGridView.Rows[idx];
     129        curRow.Tag = run;
     130
     131        HeuristicLab.Data.StringValue algStr = null, algTypeStr = null, prbStr = null, prbTypeStr = null;
     132        if (run.Parameters.TryGetValue(AlgorithmNameParameterName, out algorithmName)) {
     133          algStr = algorithmName as HeuristicLab.Data.StringValue;
     134          if (algStr != null) {
     135            curRow.Cells[AlgorithmNameColumn.Name].Value = algStr;
     136          }
     137        }
     138
     139        if (run.Parameters.TryGetValue(AlgorithmTypeParameterName, out algorithmType)) {
     140          algTypeStr = algorithmType as HeuristicLab.Data.StringValue;
     141          if (algTypeStr != null) {
     142            curRow.Cells[AlgorithmTypeColumn.Name].Value = algTypeStr;
     143          }
     144        }
     145
     146        var uploadOk = false;
     147        if (algStr != null && algTypeStr != null) {
     148          var alg = algorithms.FirstOrDefault(x => x.DataType.Name == algTypeStr.Value && x.Name == algStr.Value);
     149          if (alg != null) {
     150            curRow.Cells[OKBAlgorithmColumn.Name].Value = alg.Name;
     151            uploadOk = true;
     152          }
     153        }
     154
     155        if (run.Parameters.TryGetValue(ProblemNameParameterName, out problemName)) {
     156          prbStr = problemName as HeuristicLab.Data.StringValue;
     157          if (prbStr != null) {
     158            curRow.Cells[ProblemNameColumn.Name].Value = prbStr;
     159          }
     160        }
     161
     162        if (run.Parameters.TryGetValue(ProblemTypeParameterName, out problemType)) {
     163          prbTypeStr = problemType as HeuristicLab.Data.StringValue;
     164          if (prbTypeStr != null) {
     165            curRow.Cells[ProblemTypeColumn.Name].Value = prbTypeStr;
     166          }
     167        }
     168
     169        if (prbStr != null && prbTypeStr != null) {
     170          var prb = problems.FirstOrDefault(x => x.DataType.Name == prbTypeStr.Value && x.Name == prbStr.Value);
     171          if (prb != null) {
     172            curRow.Cells[OKBProblemColumn.Name].Value = prb.Name;
     173          } else uploadOk = false;
     174        }
     175
     176        curRow.Cells[UploadColumn.Name].Value = uploadOk;
     177      }
     178    }
     179
     180    public void ClearRuns() {
     181      if (InvokeRequired) { Invoke((Action)ClearRuns); return; }
     182      dataGridView.Rows.Clear();
     183      runs.Clear();
     184      SetEnabledStateOfControls();
    183185    }
    184186
    185187    private void RunCreationClient_Refreshing(object sender, EventArgs e) {
    186       if (InvokeRequired) {
    187         Invoke(new EventHandler(RunCreationClient_Refreshing), sender, e);
    188       } else {
    189         var message = "Refreshing algorithms and problems...";
    190         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message);
    191       }
     188      if (InvokeRequired) { Invoke((Action<object, EventArgs>)RunCreationClient_Refreshing, sender, e); return; }
     189      var message = "Refreshing algorithms and problems...";
     190      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message);
     191      refreshing = true;
     192      SetEnabledStateOfControls();
    192193    }
    193194
    194195    private void RunCreationClient_Refreshed(object sender, EventArgs e) {
    195       if (InvokeRequired) {
    196         Invoke(new EventHandler(RunCreationClient_Refreshed), sender, e);
    197       } else {
    198         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    199         SetEnabledStateOfControls();
    200       }
     196      if (InvokeRequired) { Invoke((Action<object, EventArgs>)RunCreationClient_Refreshed, sender, e); return; }
     197      MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     198      refreshing = false;
     199      SetEnabledStateOfControls();
    201200    }
    202201
     
    215214      int i = 0;
    216215      foreach (DataGridViewRow row in dataGridView.Rows) {
    217         selectedAlgorithm = algorithms.Where(x => x.Name == row.Cells[algorithmColumnIndex].Value.ToString()).FirstOrDefault();
    218         selectedProblem = problems.Where(x => x.Name == row.Cells[problemColumnIndex].Value.ToString()).FirstOrDefault();
     216        i++;
     217        if (!Convert.ToBoolean(row.Cells[UploadColumn.Name].Value)) continue;
     218        selectedAlgorithm = algorithms.FirstOrDefault(x => x.Name == row.Cells[OKBAlgorithmColumn.Name].Value.ToString());
     219        selectedProblem = problems.FirstOrDefault(x => x.Name == row.Cells[OKBProblemColumn.Name].Value.ToString());
    219220        if (selectedAlgorithm == null || selectedProblem == null) {
    220221          throw new ArgumentException("Can't retrieve the algorithm/problem to upload");
     
    223224        OKBRun run = new OKBRun(selectedAlgorithm.Id, selectedProblem.Id, row.Tag as IRun, UserInformation.Instance.User.Id);
    224225        run.Store();
    225         i++;
    226226        progress.ProgressValue = ((double)i) / count;
    227227      }
     
    233233      if (e.Button == System.Windows.Forms.MouseButtons.Right && dataGridView[e.ColumnIndex, e.RowIndex].Value != null) {
    234234        string curVal = dataGridView[e.ColumnIndex, e.RowIndex].Value.ToString();
    235         selectedAlgorithm = algorithms.Where(x => x.Name == curVal).FirstOrDefault();
    236         selectedProblem = problems.Where(x => x.Name == curVal).FirstOrDefault();
     235        selectedAlgorithm = algorithms.FirstOrDefault(x => x.Name == curVal);
     236        selectedProblem = problems.FirstOrDefault(x => x.Name == curVal);
    237237
    238238        if (selectedAlgorithm != null || selectedProblem != null) {
     
    247247        for (int i = 0; i < dataGridView.Rows.Count; i++) {
    248248          var row = dataGridView.Rows[i];
    249           row.Cells[algorithmColumnIndex].Value = selectedAlgorithm.Name;
     249          row.Cells[OKBAlgorithmColumn.Name].Value = selectedAlgorithm.Name;
    250250        }
    251251      } else if (selectedProblem != null) {
    252252        for (int i = 0; i < dataGridView.Rows.Count; i++) {
    253253          var row = dataGridView.Rows[i];
    254           row.Cells[problemColumnIndex].Value = selectedProblem.Name;
     254          row.Cells[OKBProblemColumn.Name].Value = selectedProblem.Name;
    255255        }
    256256      }
Note: See TracChangeset for help on using the changeset viewer.