1 | using System;
|
---|
2 | using System.Linq;
|
---|
3 | using System.Windows.Forms;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Core.Views;
|
---|
6 | using HeuristicLab.MainForm;
|
---|
7 | using HeuristicLab.PluginInfrastructure;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Encodings.ParameterConfigurationEncoding.Views {
|
---|
10 | [View("ValueConfigurationList View")]
|
---|
11 | [Content(typeof(ICheckedValueConfigurationList), IsDefaultView = true)]
|
---|
12 | public sealed partial class ValueConfigurationCheckedItemListView : CheckedItemListView<IValueConfiguration> {
|
---|
13 | public new ICheckedValueConfigurationList Content {
|
---|
14 | get { return (ICheckedValueConfigurationList)base.Content; }
|
---|
15 | set { base.Content = value; }
|
---|
16 | }
|
---|
17 |
|
---|
18 | public ValueConfigurationCheckedItemListView() {
|
---|
19 | InitializeComponent();
|
---|
20 | this.viewHost.ViewsLabelVisible = false;
|
---|
21 | this.typeSelectorDialog = new TypeSelectorDialog();
|
---|
22 | }
|
---|
23 |
|
---|
24 | #region Event Handlers (Content)
|
---|
25 | #endregion
|
---|
26 |
|
---|
27 | protected override void OnContentChanged() {
|
---|
28 | base.OnContentChanged();
|
---|
29 | if (Content != null) {
|
---|
30 | SetEnabledStateOfControls();
|
---|
31 | } else {
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | protected override void SetEnabledStateOfControls() {
|
---|
36 | base.SetEnabledStateOfControls();
|
---|
37 | if (Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount;
|
---|
38 | }
|
---|
39 |
|
---|
40 | #region Event Handlers (child controls)
|
---|
41 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
42 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
43 | this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount);
|
---|
44 | }
|
---|
45 | #endregion
|
---|
46 |
|
---|
47 | protected override IValueConfiguration CreateItem() {
|
---|
48 | typeSelectorDialog.Caption = "Select Item";
|
---|
49 | typeSelectorDialog.TypeSelector.Caption = "Available Items";
|
---|
50 | typeSelectorDialog.TypeSelector.Configure(Content.ValidValues.Select(x => x.GetType()), false, false, false);
|
---|
51 | if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
52 | try {
|
---|
53 | IItem value = (IItem)Content.ValidValues.Single(x => x.GetType() == typeSelectorDialog.TypeSelector.SelectedType).Clone();
|
---|
54 | if (value is NullValue) {
|
---|
55 | return new NullValueConfiguration();
|
---|
56 | } else if (value is IParameterizedItem) {
|
---|
57 | return new ParameterizedValueConfiguration(value, value.GetType(), true);
|
---|
58 | } else {
|
---|
59 | return new RangeValueConfiguration(value, value.GetType());
|
---|
60 | }
|
---|
61 | }
|
---|
62 | catch (Exception ex) {
|
---|
63 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | return null;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|