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.Problems.MetaOptimization.Views {
|
---|
10 | [View("ValueConfigurationList View")]
|
---|
11 | [Content(typeof(ICheckedValueConfigurationList), IsDefaultView = true)]
|
---|
12 | public sealed partial class ValueConfigurationCheckedItemCollectionView : CheckedItemListView<IValueConfiguration> {
|
---|
13 | public new ICheckedValueConfigurationList Content {
|
---|
14 | get { return (ICheckedValueConfigurationList)base.Content; }
|
---|
15 | set { base.Content = value; }
|
---|
16 | }
|
---|
17 |
|
---|
18 | public ValueConfigurationCheckedItemCollectionView() {
|
---|
19 | InitializeComponent();
|
---|
20 | this.viewHost.ViewsLabelVisible = false;
|
---|
21 | }
|
---|
22 |
|
---|
23 | #region Event Handlers (Content)
|
---|
24 | #endregion
|
---|
25 |
|
---|
26 | protected override void OnContentChanged() {
|
---|
27 | base.OnContentChanged();
|
---|
28 | if (Content != null) {
|
---|
29 | SetEnabledStateOfControls();
|
---|
30 | } else {
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | protected override void SetEnabledStateOfControls() {
|
---|
35 | base.SetEnabledStateOfControls();
|
---|
36 | if(Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount;
|
---|
37 | }
|
---|
38 |
|
---|
39 | #region Event Handlers (child controls)
|
---|
40 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
41 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
42 | this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount);
|
---|
43 | }
|
---|
44 | #endregion
|
---|
45 |
|
---|
46 | protected override IValueConfiguration CreateItem() {
|
---|
47 | var objectSelectorDialog = new ObjectSelectorDialog<IItem>(Content.ValidValues.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name));
|
---|
48 | if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
49 | try {
|
---|
50 | IItem value = (IItem)objectSelectorDialog.Item.Clone();
|
---|
51 | if (value is NullValue) {
|
---|
52 | return new NullValueConfiguration();
|
---|
53 | } else if(value is IParameterizedItem) {
|
---|
54 | return new ParameterizedValueConfiguration(value, value.GetType(), true);
|
---|
55 | } else {
|
---|
56 | return new RangeValueConfiguration(value, value.GetType());
|
---|
57 | }
|
---|
58 | }
|
---|
59 | catch (Exception ex) {
|
---|
60 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | return null;
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|