Changeset 17411 for branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views
- Timestamp:
- 01/28/20 16:21:53 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified 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) { -
TabularUnified 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 } -
TabularUnified 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 -
TabularUnified 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.