1 | using System.Windows.Forms;
|
---|
2 | using HeuristicLab.Core.Views;
|
---|
3 | using HeuristicLab.MainForm;
|
---|
4 |
|
---|
5 |
|
---|
6 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Views {
|
---|
7 | using System;
|
---|
8 | using System.Collections.Generic;
|
---|
9 | using System.Linq;
|
---|
10 | using Expressions;
|
---|
11 |
|
---|
12 | using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
|
---|
13 |
|
---|
14 | using Stack;
|
---|
15 |
|
---|
16 | [View("Push Expression Selection Editor")]
|
---|
17 | [Content(typeof(IEnabledExpressionsConfiguration), true)]
|
---|
18 | public partial class ExpressionSelectionView : NamedItemView {
|
---|
19 | public ExpressionSelectionView() {
|
---|
20 | InitializeComponent();
|
---|
21 | InitEvents();
|
---|
22 | Name = "Push Expression Selection Editor";
|
---|
23 | }
|
---|
24 |
|
---|
25 | public new IEnabledExpressionsConfiguration Content
|
---|
26 | {
|
---|
27 | get { return (IEnabledExpressionsConfiguration)base.Content; }
|
---|
28 | set
|
---|
29 | {
|
---|
30 | base.Content = value;
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | protected override void OnReadOnlyChanged() {
|
---|
35 | base.OnReadOnlyChanged();
|
---|
36 |
|
---|
37 | this.expressionsTreeView.Enabled = !ReadOnly;
|
---|
38 | }
|
---|
39 |
|
---|
40 | private void InitEvents() {
|
---|
41 | this.expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck;
|
---|
42 | }
|
---|
43 |
|
---|
44 | private void ExpressionsTreeViewAfterCheck(object sender, TreeViewEventArgs e) {
|
---|
45 | var isStackNode = e.Node.Tag is StackType;
|
---|
46 |
|
---|
47 | if (isStackNode) {
|
---|
48 | if (e.Node.Checked) {
|
---|
49 | Content.EnableStack((StackType)e.Node.Tag);
|
---|
50 | foreach (var subNode in e.Node.Nodes.Cast<TreeNode>())
|
---|
51 | subNode.Checked = true;
|
---|
52 | } else {
|
---|
53 | Content.DisableStack((StackType)e.Node.Tag);
|
---|
54 | foreach (var subNode in e.Node.Nodes.Cast<TreeNode>())
|
---|
55 | subNode.Checked = false;
|
---|
56 | }
|
---|
57 | } else {
|
---|
58 | if (e.Node.Checked) {
|
---|
59 | Content.EnableExpression(e.Node.Name);
|
---|
60 | } else {
|
---|
61 | Content.DisableExpression(e.Node.Name);
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | protected override void OnContentChanged() {
|
---|
67 | expressionsTreeView.Nodes.Clear();
|
---|
68 |
|
---|
69 | if (Content == null) {
|
---|
70 | return;
|
---|
71 | }
|
---|
72 |
|
---|
73 | var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray();
|
---|
74 | expressionsTreeView.Nodes.AddRange(treeNodes);
|
---|
75 | }
|
---|
76 |
|
---|
77 | private IEnumerable<TreeNode> GetTreeNodes(IList<string> enabledExpressions) {
|
---|
78 | foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) {
|
---|
79 | var stackTreeNode = new TreeNode {
|
---|
80 | Tag = stackType,
|
---|
81 | Text = Enum.GetName(typeof(StackType), stackType),
|
---|
82 | };
|
---|
83 |
|
---|
84 | var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType];
|
---|
85 | var enabledStackExpressions = enabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]);
|
---|
86 |
|
---|
87 | stackTreeNode.Checked = enabledStackExpressions.Any();
|
---|
88 |
|
---|
89 | var expressionNodes = stackExpressions
|
---|
90 | .OrderBy(name => name)
|
---|
91 | .Select(name => new TreeNode {
|
---|
92 | Text = name,
|
---|
93 | Checked = enabledStackExpressions.Contains(name),
|
---|
94 | }).ToArray();
|
---|
95 |
|
---|
96 | stackTreeNode.Nodes.AddRange(expressionNodes);
|
---|
97 |
|
---|
98 | yield return stackTreeNode;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|