Changeset 17410 for branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration
- Timestamp:
- 01/28/20 14:53:45 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration
- Files:
-
- 5 added
- 5 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/HeuristicLab.JsonInterface.OptimizerIntegration.csproj
r17405 r17410 78 78 </ItemGroup> 79 79 <ItemGroup> 80 <Compile Include="Interfaces\IJsonItemValueParser.cs" /> 81 <Compile Include="Parser\JsonItemDoubleValueParser.cs" /> 82 <Compile Include="Parser\JsonItemIntValueParser.cs" /> 80 83 <Compile Include="Properties\Resources.Designer.cs"> 81 84 <AutoGen>True</AutoGen> … … 95 98 <DependentUpon>NumericRangeControl.cs</DependentUpon> 96 99 </Compile> 100 <Compile Include="ViewModels\JsonItemVMBase.cs" /> 101 <Compile Include="ViewModels\RangeVM.cs" /> 102 <Compile Include="ViewModels\SingleValueVM.cs" /> 103 <Compile Include="ViewModels\StringValueVM.cs" /> 97 104 <Compile Include="Views\ExportJsonDialog.cs"> 98 105 <SubType>Form</SubType> … … 102 109 </Compile> 103 110 <Compile Include="FileManager.cs" /> 104 <Compile Include="Views\JsonItemArrayControl.cs">105 <SubType>UserControl</SubType>106 </Compile>107 <Compile Include="Views\JsonItemArrayControl.Designer.cs">108 <DependentUpon>JsonItemArrayControl.cs</DependentUpon>109 </Compile>110 111 <Compile Include="Views\JsonItemBoolControl.cs"> 111 112 <SubType>UserControl</SubType> … … 113 114 <Compile Include="Views\JsonItemBoolControl.Designer.cs"> 114 115 <DependentUpon>JsonItemBoolControl.cs</DependentUpon> 115 </Compile>116 <Compile Include="Views\JsonItemDefaultControl.cs">117 <SubType>UserControl</SubType>118 </Compile>119 <Compile Include="Views\JsonItemDefaultControl.Designer.cs">120 <DependentUpon>JsonItemDefaultControl.cs</DependentUpon>121 116 </Compile> 122 117 <Compile Include="Views\JsonItemRangeControl.cs"> … … 199 194 <EmbeddedResource Include="Views\ExportJsonDialog.resx"> 200 195 <DependentUpon>ExportJsonDialog.cs</DependentUpon> 201 </EmbeddedResource>202 <EmbeddedResource Include="Views\JsonItemArrayControl.resx">203 <DependentUpon>JsonItemArrayControl.cs</DependentUpon>204 196 </EmbeddedResource> 205 197 <EmbeddedResource Include="Views\JsonItemBoolControl.resx"> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/JsonItemBaseControl.Designer.cs
r17405 r17410 51 51 this.checkBoxActive.TabIndex = 2; 52 52 this.checkBoxActive.UseVisualStyleBackColor = true; 53 this.checkBoxActive.CheckedChanged += new System.EventHandler(this.checkBoxActive_CheckedChanged);54 53 // 55 54 // textBoxActualName … … 61 60 this.textBoxActualName.Size = new System.Drawing.Size(404, 20); 62 61 this.textBoxActualName.TabIndex = 12; 63 this.textBoxActualName.TextChanged += new System.EventHandler(this.textBoxActualName_TextChanged);64 62 // 65 63 // labelActualName … … 82 80 this.textBoxName.Size = new System.Drawing.Size(404, 20); 83 81 this.textBoxName.TabIndex = 10; 84 this.textBoxName.TextChanged += new System.EventHandler(this.textBoxName_TextChanged);85 82 // 86 83 // label1 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/JsonItemBaseControl.cs
r17405 r17410 11 11 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 12 12 public partial class JsonItemBaseControl : UserControl { 13 p ublic JsonItemVMVM { get; set; }13 private JsonItemVMBase VM { get; set; } 14 14 15 15 private JsonItemBaseControl() { … … 17 17 } 18 18 19 public JsonItemBaseControl(JsonItemVM vm) {19 public JsonItemBaseControl(JsonItemVMBase vm) { 20 20 InitializeComponent(); 21 21 VM = vm; 22 checkBoxActive.Checked = VM.Selected; 23 textBoxName.Text = VM.Item.Name; 22 23 checkBoxActive.DataBindings.Add("Checked", VM, nameof(JsonItemVMBase.Selected)); 24 textBoxName.DataBindings.Add("Text", VM, nameof(JsonItemVMBase.Name)); 25 textBoxActualName.DataBindings.Add("Text", VM, nameof(JsonItemVMBase.ActualName)); 26 27 //checkBoxActive.Checked = VM.Selected; 28 //textBoxName.Text = VM.Item.Name; 24 29 if (string.IsNullOrWhiteSpace(VM.Item.ActualName)) 25 30 textBoxActualName.ReadOnly = true; … … 27 32 textBoxActualName.Text = VM.Item.ActualName; 28 33 } 29 30 private void checkBoxActive_CheckedChanged(object sender, EventArgs e) {31 VM.Selected = checkBoxActive.Checked;32 }33 34 private void textBoxName_TextChanged(object sender, EventArgs e) {35 VM.Item.Name = textBoxName.Text;36 }37 38 private void textBoxActualName_TextChanged(object sender, EventArgs e) {39 VM.Item.ActualName = textBoxActualName.Text;40 }41 34 } 42 35 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/NumericRangeControl.Designer.cs
r17405 r17410 1 namespace HeuristicLab.JsonInterface.OptimizerIntegration .Shared{1 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 2 2 partial class NumericRangeControl { 3 3 /// <summary> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/NumericRangeControl.cs
r17405 r17410 10 10 using System.Globalization; 11 11 12 namespace HeuristicLab.JsonInterface.OptimizerIntegration .Shared{12 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 13 13 public partial class NumericRangeControl : UserControl { 14 14 … … 22 22 } 23 23 public bool IsDouble { get; set; } 24 25 26 24 27 25 public NumericRangeControl() { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVM.cs
r17406 r17410 2 2 using System.Collections; 3 3 using System.Collections.Generic; 4 using System.ComponentModel; 4 5 using System.Linq; 5 6 using System.Text; 6 7 using System.Threading.Tasks; 8 using System.Windows.Forms; 7 9 8 10 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 9 public delegate void OnSelectionChangeHandler(JsonItemVM sender, bool selection);10 public delegate void OnChildAddedHandler(JsonItemVM sender, JsonItemVM child);11 11 12 public class JsonItemVM { 13 public IJsonItem Item { get; set; } 12 //TODO: controls/views only initcomponents and delegate events to this, this has parsers and other actions? 13 // maybe different VMs? 14 public class JsonItemVM : JsonItemVMBase { 14 15 15 private IList<JsonItemVM> children = new List<JsonItemVM>(); 16 public IEnumerable<JsonItemVM> Children { 17 get => children; 18 } 16 public override Type JsonItemType => typeof(JsonItem); 19 17 20 public JsonItemVM Parent { get; set; } 18 //protected IJsonItemValueParser Parser { get; set; } 19 //child tree 20 //private IList<JsonItemVM> nodes = new List<JsonItemVM>(); 21 22 //public IEnumerable<JsonItemVM> Nodes { get => nodes; } 23 //public JsonItemVM Parent { get; private set; } 24 21 25 22 26 private bool selected = true; 23 27 public bool Selected { 24 get => selected; 28 get => selected; 25 29 set { 26 30 selected = value; 27 On SelectionChange?.Invoke(this, Selected);28 } 31 OnPropertyChange(this, nameof(Selected)); 32 } 29 33 } 30 34 31 public event OnSelectionChangeHandler OnSelectionChange; 32 public event OnChildAddedHandler OnChildAdded; 33 34 public JsonItemVM(IJsonItem item) { 35 this.Item = item; 35 public string Name { 36 get => Item.Name; 37 set { 38 Item.Name = value; 39 OnPropertyChange(this, nameof(Name)); 40 } 36 41 } 37 42 38 public void AddChild(JsonItemVM vm) { 39 children.Add(vm); 40 vm.Parent = this; 41 OnChildAdded?.Invoke(this, vm); 43 public string ActualName { 44 get => Item.ActualName; 45 set { 46 Item.ActualName = value; 47 OnPropertyChange(this, nameof(ActualName)); 48 } 42 49 } 50 public override JsonItemBaseControl GetControl() { 51 return new JsonItemBaseControl(this); 52 } 53 54 55 /* 56 public abstract UserControl Control { get; } 57 58 public void OnSelectChange(object sender, EventArgs e) { 59 CheckBox checkBox = sender as CheckBox; 60 Selected = checkBox.Checked; 61 } 62 63 public void OnNameChange(object sender, EventArgs e) { 64 TextBox textBox = sender as TextBox; 65 Item.Name = textBox.Text; 66 } 67 68 public void OnActualNameChange(object sender, EventArgs e) { 69 TextBox textBox = sender as TextBox; 70 Item.ActualName = textBox.Text; 71 } 72 73 public abstract void OnValueChange(object sender, EventArgs e); 74 75 public abstract void OnRangeChange(object sender, EventArgs e); 76 */ 43 77 } 44 78 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs
r17406 r17410 12 12 using HeuristicLab.Common; 13 13 using HeuristicLab.Optimization; 14 using HeuristicLab.PluginInfrastructure; 14 15 15 16 namespace HeuristicLab.JsonInterface.OptimizerIntegration { … … 30 31 vms = new List<JsonItemVM>(); 31 32 treeView.Nodes.Clear(); 32 33 33 34 optimizer = content as IOptimizer; 34 35 root = JsonItemConverter.Extract(optimizer); 35 36 TreeNode parent = new TreeNode(root.Name); 37 36 38 BuildTreeNode(parent, root); 37 39 treeView.Nodes.Add(parent); … … 39 41 } 40 42 43 private IDictionary<Type, JsonItemVMBase> VMs { get; set; } 44 45 46 private void InitCache() { 47 VMs = new Dictionary<Type, JsonItemVMBase>(); 48 foreach (var vm in ApplicationManager.Manager.GetInstances<JsonItemVMBase>()) { 49 VMs.Add(vm.JsonItemType, vm); 50 } 51 } 52 41 53 public ExportJsonDialog() { 42 54 InitializeComponent(); 55 InitCache(); 43 56 } 44 57 … … 67 80 } 68 81 69 private JsonItemVM BuildTreeNode(TreeNode node, IJsonItem item) { 70 JsonItemVM vm = new JsonItemVM(item); 82 private void BuildTreeNode(TreeNode node, IJsonItem item) { 71 83 72 vms.Add(vm); 73 ctrlCollection.Add(node.GetHashCode(), GenerateControl(vm)); 74 if (item.Children != null) { 75 foreach (var c in item.Children) { 76 if (IsDrawableItem(c)) { 77 if (c is ResultItem) { 84 if (VMs.TryGetValue(item.GetType(), out JsonItemVMBase vm)) { 85 //vm.Item = item; 86 //UserControl control = vm.GetControl(); 87 //if (control != null) { 88 // control.Dock = DockStyle.Fill; 89 // control.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; 90 //} 91 //ctrlCollection.Add(node.GetHashCode(), control); 92 if (item.Children != null) { 93 foreach (var c in item.Children) { 94 if (IsDrawableItem(c)) { 95 if (c is ResultItem) { 78 96 79 } else { 80 TreeNode childNode = new TreeNode(c.Name); 81 node.Nodes.Add(childNode); 82 vm.AddChild(BuildTreeNode(childNode, c)); 97 } else { 98 TreeNode childNode = new TreeNode(c.Name); 99 node.Nodes.Add(childNode); 100 BuildTreeNode(childNode, c); 101 //vm.AddChild(BuildTreeNode(childNode, c)); 102 } 83 103 } 84 104 } 85 105 } 106 } else { 107 Console.WriteLine(); 86 108 } 87 88 return vm;89 109 } 90 110 … … 109 129 } 110 130 } 111 112 private UserControl GenerateControl(JsonItemVM vm) {113 IJsonItem item = vm.Item;114 UserControl control = null;115 if (!(item is UnsupportedJsonItem)) {116 if (item.Value is string && item.Range != null) {117 control = new JsonItemValidValuesControl(vm);118 } else if (item.Value is bool && item.Range != null) {119 control = new JsonItemBoolControl(vm);120 } else if (item.Value is int && item.Range != null) {121 control = new JsonItemValueControl(vm, false);122 } else if (item.Value is double && item.Range != null) {123 control = new JsonItemValueControl(vm, true);124 } else if (item.Value is Array) {125 Array arr = (Array)item.Value;126 if (arr.Length == 2 && arr.GetValue(0) is int && item.Range != null)127 control = new JsonItemRangeControl(vm, false);128 else if (arr.Length == 2 && arr.GetValue(0) is double && item.Range != null)129 control = new JsonItemRangeControl(vm, true);130 else if (arr.Rank == 1 && arr.GetValue(0) is double) {131 control = new JsonItemArrayControl(vm);132 }133 } else {134 control = new JsonItemBaseControl(vm);135 }136 if (control != null) {137 control.Dock = DockStyle.Fill;138 control.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;139 }140 }141 return control;142 }143 131 } 144 132 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemBoolControl.Designer.cs
r17405 r17410 38 38 this.checkBoxValue.TabIndex = 19; 39 39 this.checkBoxValue.UseVisualStyleBackColor = true; 40 this.checkBoxValue.CheckStateChanged += new System.EventHandler(this.checkBoxValue_CheckStateChanged);41 40 // 42 41 // label2 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemBoolControl.cs
r17404 r17410 11 11 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 12 12 public partial class JsonItemBoolControl : JsonItemBaseControl { 13 public JsonItemBoolControl(JsonItemVM vm) : base(vm) { 13 14 public JsonItemBoolControl(BoolValueVM vm) : base(vm) { 14 15 InitializeComponent(); 15 checkBoxValue.Checked = (bool)vm.Item.Value;16 //checkBoxValue.Checked = (bool)vm.Item.Value; 16 17 } 17 18 /* 18 19 private void checkBoxValue_CheckStateChanged(object sender, EventArgs e) { 19 20 VM.Item.Value = checkBoxValue.Checked; 20 21 } 22 */ 21 23 } 22 24 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemRangeControl.Designer.cs
r17405 r17410 29 29 this.label4 = new System.Windows.Forms.Label(); 30 30 this.label2 = new System.Windows.Forms.Label(); 31 this.numericRangeControl1 = new HeuristicLab.JsonInterface.OptimizerIntegration. Shared.NumericRangeControl();31 this.numericRangeControl1 = new HeuristicLab.JsonInterface.OptimizerIntegration.NumericRangeControl(); 32 32 this.groupBox1.SuspendLayout(); 33 33 this.SuspendLayout(); … … 56 56 this.textBoxValueTo.Size = new System.Drawing.Size(230, 20); 57 57 this.textBoxValueTo.TabIndex = 3; 58 this.textBoxValueTo.Leave += new System.EventHandler(this.textBoxValueTo_Leave);59 58 // 60 59 // textBoxValueFrom … … 64 63 this.textBoxValueFrom.Size = new System.Drawing.Size(230, 20); 65 64 this.textBoxValueFrom.TabIndex = 2; 66 this.textBoxValueFrom.Leave += new System.EventHandler(this.textBoxValueFrom_Leave);67 65 // 68 66 // label4 … … 94 92 this.numericRangeControl1.Size = new System.Drawing.Size(487, 112); 95 93 this.numericRangeControl1.TabIndex = 18; 96 this.numericRangeControl1.Load += new System.EventHandler(this.numericRangeControl1_Load);97 94 // 98 95 // JsonItemRangeControl … … 120 117 private System.Windows.Forms.Label label4; 121 118 private System.Windows.Forms.Label label2; 122 private Shared.NumericRangeControl numericRangeControl1;119 private NumericRangeControl numericRangeControl1; 123 120 } 124 121 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemRangeControl.cs
r17405 r17410 12 12 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 13 13 public partial class JsonItemRangeControl : JsonItemBaseControl { 14 bool isDouble = false;15 object[] range = new object[2];16 object[] value = new object[2];17 14 18 public JsonItemRangeControl( JsonItemVM vm, bool isDouble) : base(vm) {15 public JsonItemRangeControl(DoubleRangeVM vm) : base(vm) { 19 16 InitializeComponent(); 17 /* 20 18 this.isDouble = isDouble; 21 19 textBoxValueFrom.Text = ((Array)VM.Item.Value).GetValue(0).ToString(); … … 23 21 textBoxValueFrom.Text = VM.Item.Range.First().ToString(); 24 22 textBoxValueTo.Text = VM.Item.Range.Last().ToString(); 23 */ 25 24 } 26 27 private object Parse(string s) { 28 if (isDouble) { 29 if (s == "-1,79769313486232E+308") return double.MinValue; 30 if (s == "1,79769313486232E+308") return double.MaxValue; 31 return double.Parse(s.Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture); 32 } 33 return int.Parse(s); 34 } 25 /* 26 protected abstract object Parse(string s); 35 27 36 28 private void SetValue() { … … 59 51 numericRangeControl1.VM = VM; 60 52 } 53 */ 61 54 } 62 55 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValidValuesControl.Designer.cs
r17405 r17410 92 92 this.Name = "JsonItemValidValuesControl"; 93 93 this.Size = new System.Drawing.Size(500, 290); 94 this.Load += new System.EventHandler(this.JsonItemValidValuesControl_Load);95 94 this.Controls.SetChildIndex(this.groupBoxRange, 0); 96 95 this.Controls.SetChildIndex(this.comboBoxValues, 0); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValidValuesControl.cs
r17405 r17410 11 11 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 12 12 public partial class JsonItemValidValuesControl : JsonItemBaseControl { 13 14 13 15 public JsonItemValidValuesControl( JsonItemVM vm) : base(vm) {14 public JsonItemValidValuesControl(StringValueVM vm) : base(vm) { 16 15 InitializeComponent(); 16 /* 17 17 foreach (var i in VM.Item.Range) { 18 18 AddOption((string)i); … … 20 20 comboBoxValues.SelectedItem = (string)i; 21 21 } 22 } 23 22 }*/ 24 23 } 25 24 /* 26 25 private void AddOption(string opt) { 27 26 AddComboOption(opt); … … 72 71 73 72 } 73 */ 74 74 } 75 75 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValueControl.Designer.cs
r17405 r17410 26 26 this.textBoxValue = new System.Windows.Forms.TextBox(); 27 27 this.label2 = new System.Windows.Forms.Label(); 28 this.numericRangeControl1 = new HeuristicLab.JsonInterface.OptimizerIntegration. Shared.NumericRangeControl();28 this.numericRangeControl1 = new HeuristicLab.JsonInterface.OptimizerIntegration.NumericRangeControl(); 29 29 this.SuspendLayout(); 30 30 // … … 37 37 this.textBoxValue.Size = new System.Drawing.Size(404, 20); 38 38 this.textBoxValue.TabIndex = 14; 39 this.textBoxValue.Leave += new System.EventHandler(this.textBoxValue_Leave);40 39 // 41 40 // label2 … … 56 55 this.numericRangeControl1.TabIndex = 16; 57 56 this.numericRangeControl1.VM = null; 58 this.numericRangeControl1.Load += new System.EventHandler(this.numericRangeControl1_Load);59 57 // 60 58 // JsonItemValueControl … … 79 77 private System.Windows.Forms.TextBox textBoxValue; 80 78 private System.Windows.Forms.Label label2; 81 private Shared.NumericRangeControl numericRangeControl1;79 private NumericRangeControl numericRangeControl1; 82 80 } 83 81 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValueControl.cs
r17405 r17410 11 11 12 12 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 13 public partial class JsonItemValueControl : JsonItemBaseControl {14 bool isDouble = false;15 object[] range = new object[2];16 13 17 public JsonItemValueControl(JsonItemVM vm, bool isDouble) : base(vm) { 18 InitializeComponent(); 19 this.isDouble = isDouble; 20 textBoxValue.Text = VM.Item.Value.ToString(); 21 range[0] = VM.Item.Range.First(); 22 range[1] = VM.Item.Range.Last(); 14 public class JsonItemIntValueControl : JsonItemValueControl { 15 16 public JsonItemIntValueControl(SingleValueVM<int> vm) : base(vm) { } 17 18 } 19 20 public class JsonItemDoubleValueControl : JsonItemValueControl { 21 private SingleValueVM<double> VM { get; set; } 22 23 public JsonItemDoubleValueControl(SingleValueVM<double> vm) : base(vm) { 24 VM = vm; 23 25 } 24 26 25 private object Parse(string s) { 26 if (isDouble) { 27 return double.Parse(s.Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture); 28 } 29 return int.Parse(s); 27 } 28 29 public abstract partial class JsonItemValueControl : JsonItemBaseControl { 30 31 public JsonItemValueControl(JsonItemVMBase vm) : base(vm) { 32 InitializeComponent(); 30 33 } 31 34 32 33 private void textBoxValue_Leave(object sender, EventArgs e) {34 if (!string.IsNullOrWhiteSpace(textBoxValue.Text))35 VM.Item.Value = Parse(textBoxValue.Text);36 }37 38 private void numericRangeControl1_Load(object sender, EventArgs e) {39 numericRangeControl1.IsDouble = isDouble;40 numericRangeControl1.VM = VM;41 }42 35 } 43 36 }
Note: See TracChangeset
for help on using the changeset viewer.