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 | }
|
---|
27 |
|
---|
28 | protected override void DeregisterContentEvents() {
|
---|
29 | Content.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(Content_ItemsRemoved);
|
---|
30 | base.DeregisterContentEvents();
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected override void RegisterContentEvents() {
|
---|
34 | base.RegisterContentEvents();
|
---|
35 | Content.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(Content_ItemsRemoved);
|
---|
36 | }
|
---|
37 |
|
---|
38 | #region Event Handlers (Content)
|
---|
39 | private new void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IValueConfiguration> e) {
|
---|
40 | if (InvokeRequired) {
|
---|
41 | Invoke(new EventHandler<CollectionItemsChangedEventArgs<IValueConfiguration>>(Content_ItemsRemoved), sender, e);
|
---|
42 | } else {
|
---|
43 | base.Content_ItemsRemoved(sender, e);
|
---|
44 | SetEnabledStateOfControls();
|
---|
45 | }
|
---|
46 | }
|
---|
47 | #endregion
|
---|
48 |
|
---|
49 | protected override void OnContentChanged() {
|
---|
50 | base.OnContentChanged();
|
---|
51 | if (Content != null) {
|
---|
52 | SetEnabledStateOfControls();
|
---|
53 | } else {
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | protected override void SetEnabledStateOfControls() {
|
---|
58 | base.SetEnabledStateOfControls();
|
---|
59 | if(Content != null) this.removeButton.Enabled = Content.Count > Content.MinItemCount;
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
63 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
64 | this.removeButton.Enabled = removeButton.Enabled && (Content.Count > Content.MinItemCount);
|
---|
65 | }
|
---|
66 |
|
---|
67 | #region Event Handlers (child controls)
|
---|
68 | #endregion
|
---|
69 |
|
---|
70 | protected override IValueConfiguration CreateItem() {
|
---|
71 | if (typeSelectorDialog == null) {
|
---|
72 | typeSelectorDialog = new TypeSelectorDialog();
|
---|
73 | typeSelectorDialog.Caption = "Select Item";
|
---|
74 | typeSelectorDialog.TypeSelector.Caption = "Available Items";
|
---|
75 | typeSelectorDialog.TypeSelector.Configure(Content.ValueDataType, false, true);
|
---|
76 | }
|
---|
77 |
|
---|
78 | if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
79 | try {
|
---|
80 | IItem value = (IItem)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
|
---|
81 | return new ValueConfiguration(value, value.GetType());
|
---|
82 | }
|
---|
83 | catch (Exception ex) {
|
---|
84 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
85 | }
|
---|
86 | }
|
---|
87 | return null;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|