1 | using System;
|
---|
2 | using System.Linq;
|
---|
3 | using System.Windows.Forms;
|
---|
4 | using HeuristicLab.Core.Views;
|
---|
5 | using HeuristicLab.MainForm;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Encodings.ParameterConfigurationEncoding.Views {
|
---|
8 | [View("ConstrainedTypeValueView")]
|
---|
9 | [Content(typeof(ConstrainedTypeValue), IsDefaultView = false)]
|
---|
10 | [Content(typeof(ConstrainedTypeValue<>), IsDefaultView = true)]
|
---|
11 | public sealed partial class ConstrainedTypeValueView : ItemView {
|
---|
12 | public new ConstrainedTypeValue Content {
|
---|
13 | get { return (ConstrainedTypeValue)base.Content; }
|
---|
14 | set { base.Content = value; }
|
---|
15 | }
|
---|
16 |
|
---|
17 | public ConstrainedTypeValueView() {
|
---|
18 | InitializeComponent();
|
---|
19 | }
|
---|
20 |
|
---|
21 | protected override void DeregisterContentEvents() {
|
---|
22 | Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
23 | base.DeregisterContentEvents();
|
---|
24 | }
|
---|
25 |
|
---|
26 | protected override void RegisterContentEvents() {
|
---|
27 | base.RegisterContentEvents();
|
---|
28 | Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
29 | }
|
---|
30 |
|
---|
31 | #region Event Handlers (Content)
|
---|
32 | void Content_ValueChanged(object sender, EventArgs e) {
|
---|
33 | if (InvokeRequired) {
|
---|
34 | Invoke(new EventHandler(Content_ValueChanged), sender, e);
|
---|
35 | } else {
|
---|
36 | this.typeComboBox.SelectedItem = Content.Value;
|
---|
37 | }
|
---|
38 | }
|
---|
39 | #endregion
|
---|
40 |
|
---|
41 | protected override void OnContentChanged() {
|
---|
42 | base.OnContentChanged();
|
---|
43 | if (Content == null) {
|
---|
44 | typeComboBox.Items.Clear();
|
---|
45 | } else {
|
---|
46 | typeComboBox.Items.AddRange(Content.ValidTypes.ToArray());
|
---|
47 | Content_ValueChanged(this, EventArgs.Empty);
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override void SetEnabledStateOfControls() {
|
---|
52 | base.SetEnabledStateOfControls();
|
---|
53 | }
|
---|
54 |
|
---|
55 | #region Event Handlers (child controls)
|
---|
56 | private void typeComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
57 | Content.Value = (Type)typeComboBox.SelectedItem;
|
---|
58 | }
|
---|
59 | #endregion
|
---|
60 | }
|
---|
61 | }
|
---|