1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using HeuristicLab.Core.Views;
|
---|
9 | using HeuristicLab.MainForm;
|
---|
10 | using HeuristicLab.Core;
|
---|
11 | using System.Windows.Forms;
|
---|
12 | using HeuristicLab.PluginInfrastructure;
|
---|
13 | using HeuristicLab.Collections;
|
---|
14 |
|
---|
15 | namespace HeuristicLab.Problems.MetaOptimization.Views {
|
---|
16 | [View("ValueConfigurationList View")]
|
---|
17 | [Content(typeof(ICheckedValueConfigurationCollection), IsDefaultView = true)]
|
---|
18 | public sealed partial class ValueConfigurationCheckedItemCollectionView : CheckedItemCollectionView<IValueConfiguration> {
|
---|
19 | public new ICheckedValueConfigurationCollection Content {
|
---|
20 | get { return (ICheckedValueConfigurationCollection)base.Content; }
|
---|
21 | set { base.Content = value; }
|
---|
22 | }
|
---|
23 |
|
---|
24 | public ValueConfigurationCheckedItemCollectionView() {
|
---|
25 | InitializeComponent();
|
---|
26 | this.viewHost.ViewsLabelVisible = false;
|
---|
27 | }
|
---|
28 |
|
---|
29 | protected override void DeregisterContentEvents() {
|
---|
30 | Content.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(Content_ItemsRemoved);
|
---|
31 | base.DeregisterContentEvents();
|
---|
32 | }
|
---|
33 |
|
---|
34 | protected override void RegisterContentEvents() {
|
---|
35 | base.RegisterContentEvents();
|
---|
36 | Content.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(Content_ItemsRemoved);
|
---|
37 | }
|
---|
38 |
|
---|
39 | #region Event Handlers (Content)
|
---|
40 | private new void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IValueConfiguration> e) {
|
---|
41 | if (InvokeRequired) {
|
---|
42 | Invoke(new EventHandler<CollectionItemsChangedEventArgs<IValueConfiguration>>(Content_ItemsRemoved), sender, e);
|
---|
43 | } else {
|
---|
44 | base.Content_ItemsRemoved(sender, e);
|
---|
45 | SetEnabledStateOfControls();
|
---|
46 | }
|
---|
47 | }
|
---|
48 | #endregion
|
---|
49 |
|
---|
50 | protected override void OnContentChanged() {
|
---|
51 | base.OnContentChanged();
|
---|
52 | if (Content != null) {
|
---|
53 | SetEnabledStateOfControls();
|
---|
54 | } else {
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override void SetEnabledStateOfControls() {
|
---|
59 | base.SetEnabledStateOfControls();
|
---|
60 | if(Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount;
|
---|
61 | }
|
---|
62 |
|
---|
63 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
64 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
65 | this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount);
|
---|
66 | }
|
---|
67 |
|
---|
68 | #region Event Handlers (child controls)
|
---|
69 | #endregion
|
---|
70 |
|
---|
71 | protected override IValueConfiguration CreateItem() {
|
---|
72 | var objectSelectorDialog = new ObjectSelectorDialog<IItem>(Content.ValidValues.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name));
|
---|
73 | if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
74 | try {
|
---|
75 | IItem value = (IItem)objectSelectorDialog.Item.Clone();
|
---|
76 | if (value is NullValue) {
|
---|
77 | return new NullValueConfiguration();
|
---|
78 | } else {
|
---|
79 | return new ValueConfiguration(value, value.GetType());
|
---|
80 | }
|
---|
81 | }
|
---|
82 | catch (Exception ex) {
|
---|
83 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
84 | }
|
---|
85 | }
|
---|
86 | return null;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|