Free cookie consent management tool by TermsFeed Policy Generator

source: branches/crossvalidation-2434/HeuristicLab.Core.Views/3.3/VariableValueView.cs @ 14895

Last change on this file since 14895 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 5.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Windows.Forms;
24using HeuristicLab.MainForm;
25
26namespace HeuristicLab.Core.Views {
27  [View("Variable Value View")]
28  [Content(typeof(Variable), false)]
29  [Content(typeof(IVariable), false)]
30  public partial class VariableValueView : ItemView {
31    private const string infoLabelToolTipSuffix = "Double-click to open description editor.";
32
33    public new IVariable Content {
34      get { return (IVariable)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public VariableValueView() {
39      InitializeComponent();
40    }
41
42    protected override void DeregisterContentEvents() {
43      Content.NameChanged -= new EventHandler(Content_NameChanged);
44      Content.DescriptionChanged -= new EventHandler(Content_DescriptionChanged);
45      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
46      base.DeregisterContentEvents();
47    }
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
50      Content.NameChanged += new EventHandler(Content_NameChanged);
51      Content.DescriptionChanged += new EventHandler(Content_DescriptionChanged);
52      Content.ValueChanged += new EventHandler(Content_ValueChanged);
53    }
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      if (Content == null) {
58        viewHost.Content = null;
59        toolTip.SetToolTip(infoLabel, string.Empty);
60        if (ViewAttribute.HasViewAttribute(this.GetType()))
61          this.Caption = ViewAttribute.GetViewName(this.GetType());
62        else
63          this.Caption = "VariableValue View";
64      } else {
65        viewHost.ViewType = null;
66        viewHost.Content = Content.Value;
67        toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
68        Caption = Content.Name;
69      }
70    }
71
72    protected override void SetEnabledStateOfControls() {
73      base.SetEnabledStateOfControls();
74      viewHost.Enabled = Content != null;
75      viewHost.ReadOnly = this.ReadOnly;
76      infoLabel.Enabled = Content != null;
77    }
78
79    protected virtual void Content_NameChanged(object sender, EventArgs e) {
80      if (InvokeRequired)
81        Invoke(new EventHandler(Content_NameChanged), sender, e);
82      else
83        Caption = Content.Name;
84    }
85    protected virtual void Content_DescriptionChanged(object sender, EventArgs e) {
86      if (InvokeRequired)
87        Invoke(new EventHandler(Content_DescriptionChanged), sender, e);
88      else
89        toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
90    }
91    protected virtual void Content_ValueChanged(object sender, EventArgs e) {
92      if (InvokeRequired)
93        Invoke(new EventHandler(Content_ValueChanged), sender, e);
94      else {
95        viewHost.ViewType = null;
96        viewHost.Content = Content.Value;
97      }
98    }
99
100    protected virtual void VariableValueView_DragEnterOver(object sender, DragEventArgs e) {
101      e.Effect = DragDropEffects.None;
102      if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IItem)) {
103        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
104        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
105        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
106        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
107        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
108      }
109    }
110    protected virtual void VariableValueView_DragDrop(object sender, DragEventArgs e) {
111      if (e.Effect != DragDropEffects.None) {
112        IItem item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IItem;
113        if (e.Effect.HasFlag(DragDropEffects.Copy)) item = (IItem)item.Clone();
114        Content.Value = item;
115      }
116    }
117    protected virtual void infoLabel_DoubleClick(object sender, EventArgs e) {
118      using (TextDialog dialog = new TextDialog("Description of " + Content.Name, Content.Description, ReadOnly || !Content.CanChangeDescription)) {
119        if (dialog.ShowDialog(this) == DialogResult.OK)
120          Content.Description = dialog.Content;
121      }
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.