- Timestamp:
- 01/28/20 16:21:53 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration
- Files:
-
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/HeuristicLab.JsonInterface.OptimizerIntegration.csproj
r17410 r17411 133 133 <DependentUpon>JsonItemValidValuesControl.cs</DependentUpon> 134 134 </Compile> 135 <Compile Include="ViewModels\JsonItemVM.cs" />136 135 <Compile Include="MenuItems\ImportJsonTemplateMenuItem.cs" /> 137 136 <Compile Include="MenuItems\ExportJsonTemplateMenuItem.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/NumericRangeControl.Designer.cs
r17410 r17411 43 43 this.textBoxFrom.Size = new System.Drawing.Size(164, 20); 44 44 this.textBoxFrom.TabIndex = 2; 45 this.textBoxFrom.Leave += new System.EventHandler(this.textBoxFrom_Leave);46 45 // 47 46 // label6 … … 81 80 this.checkBoxFrom.TabIndex = 4; 82 81 this.checkBoxFrom.UseVisualStyleBackColor = true; 83 this.checkBoxFrom.CheckStateChanged += new System.EventHandler(this.checkBoxFrom_CheckStateChanged);84 82 // 85 83 // checkBoxTo … … 91 89 this.checkBoxTo.TabIndex = 7; 92 90 this.checkBoxTo.UseVisualStyleBackColor = true; 93 this.checkBoxTo.CheckStateChanged += new System.EventHandler(this.checkBoxTo_CheckStateChanged);94 91 // 95 92 // textBoxTo … … 102 99 this.textBoxTo.Size = new System.Drawing.Size(164, 20); 103 100 this.textBoxTo.TabIndex = 6; 104 this.textBoxTo.Leave += new System.EventHandler(this.textBoxTo_Leave);105 101 // 106 102 // label1 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/NumericRangeControl.cs
r17410 r17411 12 12 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 13 13 public partial class NumericRangeControl : UserControl { 14 15 private JsonItemVM vm; 16 public JsonItemVM VM { 17 get => vm; 18 set { 19 vm = value; 20 Init(); 21 } 22 } 23 public bool IsDouble { get; set; } 24 14 public TextBox TBMinRange { get; set; } 15 public TextBox TBMaxRange { get; set; } 16 public CheckBox EnableMinRange { get; set; } 17 public CheckBox EnableMaxRange { get; set; } 25 18 public NumericRangeControl() { 26 19 InitializeComponent(); 27 Init(); 20 TBMinRange = textBoxFrom; 21 TBMaxRange = textBoxTo; 22 EnableMinRange = checkBoxFrom; 23 EnableMaxRange = checkBoxTo; 24 checkBoxFrom.CheckedChanged += ToggleFromInput; 25 checkBoxTo.CheckedChanged += ToggleToInput; 28 26 } 29 27 30 private void Init() { 31 textBoxFrom.Text = ""; 32 textBoxTo.Text = ""; 33 textBoxFrom.ReadOnly = true; 34 textBoxTo.ReadOnly = true; 35 checkBoxFrom.Checked = false; 36 checkBoxFrom.Checked = false; 37 } 38 39 private void checkBoxFrom_CheckStateChanged(object sender, EventArgs e) { 40 textBoxFrom.ReadOnly = !checkBoxFrom.Checked; 41 textBoxFrom.Text = ""; 42 if(!checkBoxFrom.Checked) 43 SetRange(); 28 private void ToggleToInput(object sender, EventArgs e) { 29 textBoxTo.ReadOnly = !checkBoxTo.Checked; 44 30 } 45 31 46 private void checkBoxTo_CheckStateChanged(object sender, EventArgs e) { 47 textBoxTo.ReadOnly = !checkBoxTo.Checked; 48 textBoxTo.Text = ""; 49 if (!checkBoxTo.Checked) 50 SetRange(); 51 } 52 53 private void textBoxFrom_Leave(object sender, EventArgs e) { 54 if (checkBoxFrom.Checked) 55 SetRange(); 56 } 57 58 private void textBoxTo_Leave(object sender, EventArgs e) { 59 if (checkBoxTo.Checked) 60 SetRange(); 61 } 62 63 private void SetRange() { 64 object[] range = new object[2]; 65 if (checkBoxFrom.Checked && !string.IsNullOrWhiteSpace(textBoxFrom.Text)) 66 range[0] = Parse(textBoxFrom.Text); 67 else 68 range[0] = IsDouble ? double.MinValue : int.MinValue; 69 70 if (checkBoxTo.Checked && !string.IsNullOrWhiteSpace(textBoxTo.Text)) 71 range[1] = Parse(textBoxTo.Text); 72 else 73 range[1] = IsDouble ? double.MinValue : int.MinValue; 74 VM.Item.Range = range; 75 } 76 77 private object Parse(string s) { 78 if (IsDouble) { 79 return double.Parse(s.Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture); 80 } 81 return int.Parse(s); 32 private void ToggleFromInput(object sender, EventArgs e) { 33 textBoxFrom.ReadOnly = !checkBoxFrom.Checked; 82 34 } 83 35 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVMBase.cs
r17410 r17411 7 7 8 8 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 9 public abstractclass JsonItemVMBase : INotifyPropertyChanged {9 public class JsonItemVMBase : INotifyPropertyChanged { 10 10 public event PropertyChangedEventHandler PropertyChanged; 11 11 public IJsonItem Item { get; set; } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/RangeVM.cs
r17410 r17411 18 18 } 19 19 20 public abstract class RangeVM<T> : JsonItemVM {20 public abstract class RangeVM<T> : JsonItemVMBase { 21 21 22 22 public T MinValue { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/SingleValueVM.cs
r17410 r17411 10 10 public class IntValueVM : SingleValueVM<int> { 11 11 public override Type JsonItemType => typeof(IntJsonItem); 12 13 protected override int MinTypeValue => int.MinValue; 14 protected override int MaxTypeValue => int.MaxValue; 15 12 16 public override JsonItemBaseControl GetControl() => 13 17 new JsonItemIntValueControl(this); … … 15 19 16 20 public class DoubleValueVM : SingleValueVM<double> { 17 public override Type JsonItemType => typeof(DoubleJsonItem); 21 public override Type JsonItemType => typeof(DoubleJsonItem); 22 23 protected override double MinTypeValue => double.MinValue; 24 protected override double MaxTypeValue => double.MaxValue; 25 18 26 public override JsonItemBaseControl GetControl() => 19 27 new JsonItemDoubleValueControl(this); … … 22 30 public class BoolValueVM : SingleValueVM<bool> { 23 31 public override Type JsonItemType => typeof(BoolJsonItem); 32 33 protected override bool MinTypeValue => false; 34 protected override bool MaxTypeValue => true; 35 24 36 public override JsonItemBaseControl GetControl() => 25 37 new JsonItemBoolControl(this); 26 38 } 27 39 28 public abstract class SingleValueVM<T> : JsonItemVM {40 public abstract class SingleValueVM<T> : JsonItemVMBase { 29 41 30 42 public T Value { … … 52 64 } 53 65 66 private bool enableMinRange = false; 67 public bool EnableMinRange { 68 get => enableMinRange; 69 set { 70 enableMinRange = value; 71 if (!enableMinRange) 72 MinRange = MinTypeValue; 73 OnPropertyChange(this, nameof(EnableMinRange)); 74 } 75 } 76 77 private bool enableMaxRange = false; 78 public bool EnableMaxRange { 79 get => enableMaxRange; 80 set { 81 enableMaxRange = value; 82 if (!enableMaxRange) 83 MaxRange = MaxTypeValue; 84 OnPropertyChange(this, nameof(EnableMaxRange)); 85 } 86 } 87 54 88 private T Cast(object obj) => (T)Convert.ChangeType(obj, typeof(T)); 55 89 … … 59 93 } 60 94 95 protected abstract T MinTypeValue { get; } 96 protected abstract T MaxTypeValue { get; } 61 97 } 62 98 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/StringValueVM.cs
r17410 r17411 6 6 7 7 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 8 public class StringValueVM : JsonItemVM {8 public class StringValueVM : JsonItemVMBase { 9 9 public override Type JsonItemType => typeof(StringJsonItem); 10 10 public override JsonItemBaseControl GetControl() => -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs
r17410 r17411 16 16 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 17 17 public partial class ExportJsonDialog : Form { 18 private static SaveFileDialog SaveFileDialog { get; set; } 19 private IDictionary<int, UserControl> Hash2Control { get; set; } = new Dictionary<int, UserControl>(); 20 private IJsonItem Root { get; set; } 21 private IOptimizer Optimizer { get; set; } 22 private IList<JsonItemVMBase> VMs { get; set; } 23 private JCGenerator Generator { get; set; } = new JCGenerator(); 24 18 25 private IContent content; 19 private static SaveFileDialog saveFileDialog;20 private IDictionary<int, UserControl> ctrlCollection = new Dictionary<int, UserControl>();21 private IJsonItem root;22 private IOptimizer optimizer;23 private IList<JsonItemVM> vms;24 private JCGenerator generator = new JCGenerator();25 26 public IContent Content { 26 27 get => content; … … 28 29 content = value; 29 30 30 //IEnumerable<JsonItem> items = generator.FetchJsonItems(content as IOptimizer); 31 vms = new List<JsonItemVM>(); 31 VMs = new List<JsonItemVMBase>(); 32 32 treeView.Nodes.Clear(); 33 33 34 optimizer = content as IOptimizer;35 root = JsonItemConverter.Extract(optimizer);36 TreeNode parent = new TreeNode( root.Name);34 Optimizer = content as IOptimizer; 35 Root = JsonItemConverter.Extract(Optimizer); 36 TreeNode parent = new TreeNode(Root.Name); 37 37 38 BuildTreeNode(parent, root);38 BuildTreeNode(parent, Root); 39 39 treeView.Nodes.Add(parent); 40 40 } 41 41 } 42 42 43 private IDictionary<Type, JsonItemVMBase> VMs{ get; set; }43 private IDictionary<Type, Type> JI2VM { get; set; } 44 44 45 45 46 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); 47 JI2VM = new Dictionary<Type, Type>(); 48 foreach (var vmType in ApplicationManager.Manager.GetTypes(typeof(JsonItemVMBase))) { 49 JsonItemVMBase vm = (JsonItemVMBase)Activator.CreateInstance(vmType); 50 JI2VM.Add(vm.JsonItemType, vmType); 50 51 } 51 52 } … … 57 58 58 59 private void exportButton_Click(object sender, EventArgs e) { 59 foreach(var x in vms) {60 foreach(var x in VMs) { 60 61 if (!x.Selected) { 61 62 x.Item.Parent.Children.Remove(x.Item); … … 63 64 } 64 65 65 if ( saveFileDialog == null) {66 saveFileDialog = new SaveFileDialog();67 saveFileDialog.Title = "Export .json-Template";68 saveFileDialog.DefaultExt = "json";69 saveFileDialog.Filter = ".json-Template|*.json|All Files|*.*";70 saveFileDialog.FilterIndex = 1;66 if (SaveFileDialog == null) { 67 SaveFileDialog = new SaveFileDialog(); 68 SaveFileDialog.Title = "Export .json-Template"; 69 SaveFileDialog.DefaultExt = "json"; 70 SaveFileDialog.Filter = ".json-Template|*.json|All Files|*.*"; 71 SaveFileDialog.FilterIndex = 1; 71 72 } 72 73 73 saveFileDialog.FileName = "template";74 SaveFileDialog.FileName = "template"; 74 75 75 if ( saveFileDialog.ShowDialog() == DialogResult.OK) {76 File.WriteAllText( saveFileDialog.FileName, generator.GenerateTemplate(root, optimizer));76 if (SaveFileDialog.ShowDialog() == DialogResult.OK) { 77 File.WriteAllText(SaveFileDialog.FileName, Generator.GenerateTemplate(Root, Optimizer)); 77 78 } 78 79 … … 81 82 82 83 private void BuildTreeNode(TreeNode node, IJsonItem item) { 83 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); 84 if (JI2VM.TryGetValue(item.GetType(), out Type vmType)) { 85 JsonItemVMBase vm = (JsonItemVMBase)Activator.CreateInstance(vmType); 86 VMs.Add(vm); 87 vm.Item = item; 88 UserControl control = vm.GetControl(); 89 if (control != null) { 90 control.Dock = DockStyle.Fill; 91 control.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; 92 } 93 Hash2Control.Add(node.GetHashCode(), control); 92 94 if (item.Children != null) { 93 95 foreach (var c in item.Children) { … … 99 101 node.Nodes.Add(childNode); 100 102 BuildTreeNode(childNode, c); 101 //vm.AddChild(BuildTreeNode(childNode, c));102 103 } 103 104 } 104 105 } 105 106 } 106 } else {107 Console.WriteLine();108 107 } 109 108 } … … 121 120 122 121 private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { 123 if( ctrlCollection.TryGetValue(treeView.SelectedNode.GetHashCode(), out UserControl ctrl)) {122 if(Hash2Control.TryGetValue(treeView.SelectedNode.GetHashCode(), out UserControl ctrl)) { 124 123 panel.Controls.Clear(); 125 124 if (ctrl != null) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemBoolControl.cs
r17410 r17411 11 11 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 12 12 public partial class JsonItemBoolControl : JsonItemBaseControl { 13 private BoolValueVM VM { get; set; } 13 14 14 15 public JsonItemBoolControl(BoolValueVM vm) : base(vm) { 15 16 InitializeComponent(); 17 VM = vm; 18 checkBoxValue.DataBindings.Add("Checked", VM, nameof(BoolValueVM.Value)); 16 19 //checkBoxValue.Checked = (bool)vm.Item.Value; 17 20 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValueControl.Designer.cs
r17410 r17411 49 49 // numericRangeControl1 50 50 // 51 this.numericRangeControl1.IsDouble = false;52 51 this.numericRangeControl1.Location = new System.Drawing.Point(9, 101); 53 52 this.numericRangeControl1.Name = "numericRangeControl1"; 54 53 this.numericRangeControl1.Size = new System.Drawing.Size(487, 112); 55 54 this.numericRangeControl1.TabIndex = 16; 56 this.numericRangeControl1.VM = null;57 55 // 58 56 // JsonItemValueControl -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValueControl.cs
r17410 r17411 13 13 14 14 public class JsonItemIntValueControl : JsonItemValueControl { 15 private readonly IntValueVM vm; 15 16 16 public JsonItemIntValueControl(SingleValueVM<int> vm) : base(vm) { } 17 #region Overriden Properties 18 protected override object VM => vm; 19 protected override string ValuePropertyId => nameof(IntValueVM.Value); 20 protected override string MinRangePropertyId => nameof(IntValueVM.MinRange); 21 protected override string MaxRangePropertyId => nameof(IntValueVM.MaxRange); 22 protected override string EnableMinRangePropertyId => nameof(IntValueVM.EnableMinRange); 23 protected override string EnableMaxRangePropertyId => nameof(IntValueVM.EnableMaxRange); 24 #endregion 25 26 public JsonItemIntValueControl(IntValueVM vm) : base(vm) { 27 this.vm = vm; 28 Init(); 29 } 17 30 18 31 } 19 32 20 33 public class JsonItemDoubleValueControl : JsonItemValueControl { 21 private SingleValueVM<double> VM { get; set; }34 private readonly DoubleValueVM vm; 22 35 23 public JsonItemDoubleValueControl(SingleValueVM<double> vm) : base(vm) { 24 VM = vm; 36 #region Overriden Properties 37 protected override object VM => vm; 38 protected override string ValuePropertyId => nameof(DoubleValueVM.Value); 39 protected override string MinRangePropertyId => nameof(DoubleValueVM.MinRange); 40 protected override string MaxRangePropertyId => nameof(DoubleValueVM.MaxRange); 41 protected override string EnableMinRangePropertyId => nameof(DoubleValueVM.EnableMinRange); 42 protected override string EnableMaxRangePropertyId => nameof(DoubleValueVM.EnableMaxRange); 43 #endregion 44 45 public JsonItemDoubleValueControl(DoubleValueVM vm) : base(vm) { 46 this.vm = vm; 47 Init(); 25 48 } 26 49 … … 28 51 29 52 public abstract partial class JsonItemValueControl : JsonItemBaseControl { 53 #region Protected Properties 54 protected TextBox TBValue { get; set; } 55 protected NumericRangeControl NumericRangeControl { get; set; } 56 #endregion 57 58 #region Abstract Properties 59 protected abstract object VM { get; } 60 protected abstract string ValuePropertyId { get; } 61 protected abstract string MinRangePropertyId { get; } 62 protected abstract string MaxRangePropertyId { get; } 63 protected abstract string EnableMinRangePropertyId { get; } 64 protected abstract string EnableMaxRangePropertyId { get; } 65 #endregion 30 66 31 67 public JsonItemValueControl(JsonItemVMBase vm) : base(vm) { 32 68 InitializeComponent(); 69 TBValue = textBoxValue; 70 NumericRangeControl = numericRangeControl1; 71 } 72 73 protected void Init() { 74 TBValue.DataBindings.Add("Text", VM, ValuePropertyId); 75 NumericRangeControl.TBMinRange.DataBindings.Add("Text", VM, MinRangePropertyId); 76 NumericRangeControl.TBMaxRange.DataBindings.Add("Text", VM, MaxRangePropertyId); 77 NumericRangeControl.EnableMinRange.DataBindings.Add("Checked", VM, EnableMinRangePropertyId, 78 false, DataSourceUpdateMode.OnPropertyChanged); 79 NumericRangeControl.EnableMaxRange.DataBindings.Add("Checked", VM, EnableMaxRangePropertyId, 80 false, DataSourceUpdateMode.OnPropertyChanged); 33 81 } 34 82
Note: See TracChangeset
for help on using the changeset viewer.