Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HLScript/HeuristicLab.Optimization.Views/3.3/RunCollectionConstraintViews/RunCollectionContentConstraintView.cs @ 12338

Last change on this file since 12338 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Common;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29namespace HeuristicLab.Optimization.Views {
30  [Content(typeof(RunCollectionContentConstraint), true)]
31  public partial class RunCollectionContentConstraintView : ItemView {
32    public RunCollectionContentConstraintView() {
33      InitializeComponent();
34      runsView.ShowDetails = false;
35    }
36
37    public new RunCollectionContentConstraint Content {
38      get { return (RunCollectionContentConstraint)base.Content; }
39      set { base.Content = value; }
40    }
41
42    protected override void OnContentChanged() {
43      base.OnContentChanged();
44      if (Content != null) {
45        chbActive.Checked = Content.Active;
46        ReadOnly = Content.Active;
47        runsView.RunCollection = Content.ConstrainedValue;
48        runsView.Content = Content.ConstraintData;
49      } else {
50        chbActive.Checked = false;
51        runsView.RunCollection = null;
52        runsView.Content = null;
53      }
54    }
55
56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58      Content.ActiveChanged += new EventHandler(Content_ActiveChanged);
59    }
60
61    protected override void DeregisterContentEvents() {
62      base.DeregisterContentEvents();
63      Content.ActiveChanged -= new EventHandler(Content_ActiveChanged);
64    }
65
66    protected override void SetEnabledStateOfControls() {
67      base.SetEnabledStateOfControls();
68      chbActive.Enabled = !Locked && Content != null;
69      runsView.Enabled = !Locked && Content != null;
70    }
71
72    protected virtual void Content_ActiveChanged(object sender, EventArgs e) {
73      chbActive.Checked = Content.Active;
74      ReadOnly = Content.Active;
75    }
76    protected virtual void chbActive_CheckedChanged(object sender, EventArgs e) {
77      if (Content != null)
78        Content.Active = chbActive.Checked;
79    }
80
81    private class RunSetView : ItemSetView<IRun> {
82      public RunCollection RunCollection { get; set; }
83
84      public RunSetView()
85        : base() {
86        addButton.Enabled = false;
87      }
88
89      protected override void SetEnabledStateOfControls() {
90        base.SetEnabledStateOfControls();
91        addButton.Enabled = false;
92      }
93
94      protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
95        base.itemsListView_DragEnter(sender, e);
96        if (RunCollection != null) {
97          var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
98          foreach (var run in dropData.GetObjectGraphObjects().OfType<IRun>())
99            validDragOperation = validDragOperation && RunCollection.Contains(run);
100        }
101      }
102
103      protected override void itemsListView_DragOver(object sender, DragEventArgs e) {
104        e.Effect = DragDropEffects.None;
105        if (validDragOperation && !draggedItemsAlreadyContained) {
106          e.Effect = DragDropEffects.Link;
107        }
108      }
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.