Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/18/20 16:28:53 (5 years ago)
Author:
dpiringe
Message:

#3026:

  • added two new methods in IJsonItem -> FixatePath and LoosenPath to fixate/loosen the path (to enable name changing without effects on path)
  • set IsInRange to virtual and made overrides for IntMatrixJsonItem and DoubleMatrixJsonItem (IsInRange is a bad name and needs to be renamed in future versions)
  • implemented basic validation feedback with ErrorProvider for some inputs (templateName, Name, Range)
  • now all items gets validated before export (validation errors are shown with ErrorHandling.ShowErrorDialog)
  • added a check in AlgorithmConverter to prevent an exception for accessing the first element of an empty IEnumerable
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs

    r17443 r17444  
    1616namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    1717  public partial class ExportJsonDialog : Form {
    18     private static SaveFileDialog SaveFileDialog { get; set; }
     18    private static FolderBrowserDialog FolderBrowserDialog { get; set; }
    1919    private IDictionary<int, UserControl> Hash2Control { get; set; } = new Dictionary<int, UserControl>();
    2020    private IDictionary<TreeNode, JsonItemVMBase> Node2VM { get; set; } = new Dictionary<TreeNode, JsonItemVMBase>();
     
    7171
    7272    private void exportButton_Click(object sender, EventArgs e) {
    73       foreach(var x in VMs) {
     73      foreach (var x in VMs) {
    7474        if (!x.Selected) {
    7575          x.Item.Parent.Children.Remove(x.Item);
     
    7777      }
    7878
    79       foreach(var x in ResultItems.Values) {
     79      foreach (var x in ResultItems.Values) {
    8080        x.Parent.Children.Remove(x);
    8181      }
    8282
    83       foreach(var x in resultItems.CheckedItems) {
    84         if(ResultItems.TryGetValue((string)x, out IJsonItem item)) {
     83      foreach (var x in resultItems.CheckedItems) {
     84        if (ResultItems.TryGetValue((string)x, out IJsonItem item)) {
    8585          Root.AddChildren(item);
    8686        }
     
    8888
    8989      IList<IJsonItem> faultyItems = new List<IJsonItem>();
    90       if(!Root.GetValidator().Validate(ref faultyItems)) {
     90     
     91      if (!Root.GetValidator().Validate(ref faultyItems)) {
     92        IList<Exception> list = new List<Exception>();
    9193        //print faultyItems
     94        foreach (var x in faultyItems) {
     95          list.Add(new Exception($"Combination of value and range is not valid for {x.Name}"));
     96        }
     97        ErrorHandling.ShowErrorDialog(this, new AggregateException(list));
     98      } else {
     99        if (FolderBrowserDialog == null) {
     100          FolderBrowserDialog = new FolderBrowserDialog();
     101          FolderBrowserDialog.Description = "Select .json-Template Dictionary";
     102        }
     103
     104        if (FolderBrowserDialog.ShowDialog() == DialogResult.OK) {
     105          Generator.GenerateTemplate(FolderBrowserDialog.SelectedPath, textBoxTemplateName.Text, Optimizer, Root);
     106        }
     107
     108        Close();
    92109      }
    93 
    94       if (SaveFileDialog == null) {
    95         SaveFileDialog = new SaveFileDialog();
    96         SaveFileDialog.Title = "Export .json-Template";
    97         SaveFileDialog.DefaultExt = "json";
    98         SaveFileDialog.Filter = ".json-Template|*.json|All Files|*.*";
    99         SaveFileDialog.FilterIndex = 1;
    100       }
    101      
    102       SaveFileDialog.FileName = "template";
    103 
    104       if (SaveFileDialog.ShowDialog() == DialogResult.OK) {
    105         Generator.GenerateTemplate(@"C:\Users\p41997\Desktop", "template", Optimizer, Root);
    106       }
    107 
    108       Close();
    109110    }
    110111
     
    162163      }
    163164    }
     165
     166    private void textBoxTemplateName_Validating(object sender, CancelEventArgs e) {
     167      if (string.IsNullOrWhiteSpace(textBoxTemplateName.Text)) {
     168        errorProvider.SetError(textBoxTemplateName, "Template name must not be empty.");
     169        e.Cancel = true;
     170      } else {
     171        errorProvider.SetError(textBoxTemplateName, null);
     172      }
     173    }
    164174  }
    165175}
Note: See TracChangeset for help on using the changeset viewer.