Ignore:
Timestamp:
02/01/21 14:37:18 (4 months ago)
Author:
dpiringe
Message:

#3026

  • removed the option to set the value for JsonItems via exporter
    • reworked some base controls
    • added new controls for JsonItem specific properties (e.g. ArrayResizable)
    • deleted a lot of obsolet controls
  • removed the Enable checkbox in the detail view of JsonItems
  • exporter now clones the IOptimizer object
  • added a check + message for unsupported exports
  • list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
  • refactored the converter type check
    • now every converter has to specify its supported type(s)
File:
1 edited

Legend:

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

    r17601 r17828  
    4040
    4141        Optimizer = content as IOptimizer;
    42         Root = JsonItemConverter.Extract(Optimizer);
    43         TreeNode parent = new TreeNode(Root.Name);
    44         treeView.AfterCheck += TreeView_AfterCheck;
    45         BuildTreeNode(parent, Root);
    46         treeView.Nodes.Add(parent);
    47         treeView.ExpandAll();
    48         panelParameterDetails.Controls.Clear();
    49         panelResultDetails.Controls.Clear();
    50 
     42        if(Optimizer != null) {
     43          Optimizer = (IOptimizer)Optimizer.Clone(); // clone the optimizer
     44          Root = JsonItemConverter.Extract(Optimizer);
     45          TreeNode parent = new TreeNode(Root.Name);
     46          treeView.AfterCheck += TreeView_AfterCheck;
     47          BuildTreeNode(parent, Root);
     48          treeView.Nodes.Add(parent);
     49          treeView.ExpandAll();
     50          panelParameterDetails.Controls.Clear();
     51          panelResultDetails.Controls.Clear();
     52        }
    5153      }
    5254    }
     
    6264    public ExportJsonDialog() {
    6365      InitializeComponent();
     66      this.Icon = HeuristicLab.Common.Resources.HeuristicLab.Icon;
    6467      InitCache();
    6568    }
    6669
    6770    private void exportButton_Click(object sender, EventArgs e) {
    68       // to set default value for disabled items
    69       JsonItemConverter.Inject(Optimizer, Root);
     71      if (FolderBrowserDialog == null) {
     72        FolderBrowserDialog = new FolderBrowserDialog();
     73        FolderBrowserDialog.Description = "Select .json-Template Directory";
     74      }
    7075
    71       // clear all runs
    72       Optimizer.Runs.Clear();
    73 
    74       var validationResult = Root.GetValidator().Validate();
    75       if (!validationResult.Success) {
    76         IList<Exception> list = new List<Exception>();
    77         //print faultyItems
    78         foreach (var x in validationResult.Errors) {
    79           list.Add(new Exception(x));
    80         }
    81         ErrorHandling.ShowErrorDialog(this, new AggregateException(list));
    82       } else {
    83         if (FolderBrowserDialog == null) {
    84           FolderBrowserDialog = new FolderBrowserDialog();
    85           FolderBrowserDialog.Description = "Select .json-Template Dictionary";
    86         }
    87 
    88         if (FolderBrowserDialog.ShowDialog() == DialogResult.OK) {
    89           JsonTemplateGenerator.GenerateTemplate(FolderBrowserDialog.SelectedPath, textBoxTemplateName.Text, Optimizer, Root);
     76      if (FolderBrowserDialog.ShowDialog() == DialogResult.OK) {
     77        try {
     78          JsonTemplateGenerator.GenerateTemplate(
     79            Path.Combine(FolderBrowserDialog.SelectedPath, textBoxTemplateName.Text),
     80            Optimizer, Root);
    9081          Close();
     82        } catch (Exception ex) {
     83          ErrorHandling.ShowErrorDialog(this, ex);
    9184        }
    9285      }
     
    9891        foreach (var c in item.Children) {
    9992          if (IsDrawableItem(c)) {
     93            TreeNode childNode = new TreeNode(c.Name);
    10094            if (c is IResultJsonItem) {
    101               TreeNode childNode = new TreeNode(c.Name);
    10295              treeViewResults.Nodes.Add(childNode);
    103               RegisterItem(childNode, c, treeViewResults);
    104               if(Node2VM.TryGetValue(childNode, out IJsonItemVM vm))
    105                 vm.Selected = true;
    106              
     96              IJsonItemVM vm = RegisterItem(childNode, c, treeViewResults);
     97              if (vm != null) vm.Selected = true;             
    10798            } else {
    108               TreeNode childNode = new TreeNode(c.Name);
    10999              node.Nodes.Add(childNode);
    110100              BuildTreeNode(childNode, c);
     
    115105    }
    116106
    117     private void RegisterItem(TreeNode node, IJsonItem item, TreeView tv) {
    118       if (JI2VM.TryGetValue(item.GetType(), out Type vmType)) { // TODO: enhance for interfaces?
     107    private IJsonItemVM RegisterItem(TreeNode node, IJsonItem item, TreeView tv) {
     108      if (JI2VM.TryGetValue(item.GetType(), out Type vmType)) {
    119109        IJsonItemVM vm = (IJsonItemVM)Activator.CreateInstance(vmType);
    120110
     
    128118        UserControl control = new JsonItemBaseControl(vm, vm.Control);
    129119        Node2Control.Add(node, control);
     120        return vm;
    130121      } else {
    131122        node.ForeColor = Color.LightGray;
    132123        node.NodeFont = new Font(SystemFonts.DialogFont, FontStyle.Italic);
    133124      }
     125      return null;
    134126    }
    135127
     
    142134      }
    143135     
    144       return b || !(item is EmptyJsonItem);
     136      return b || !(item is EmptyJsonItem) || !(item is UnsupportedJsonItem);
    145137    }
    146138   
Note: See TracChangeset for help on using the changeset viewer.