Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/ResultValueView.cs @ 7235

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

Added information icon in VariableValueView and ResultValueView, corrected tooltip update in NamedItemCollectionView and reverted changes of r6631 (#1054).

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Core.Views;
25using HeuristicLab.MainForm;
26
27namespace HeuristicLab.Optimization.Views {
28  [View("Result Value View")]
29  [Content(typeof(Result), true)]
30  [Content(typeof(IResult), false)]
31  public sealed partial class ResultValueView : ItemView {
32    private const string infoLabelToolTipSuffix = "Double-click to open description editor.";
33
34    public new IResult Content {
35      get { return (IResult)base.Content; }
36      set { base.Content = value; }
37    }
38
39    public override bool ReadOnly {
40      get { return true; }
41      set { /*not needed because results are always readonly */}
42    }
43
44    public ResultValueView() {
45      InitializeComponent();
46    }
47
48    protected override void DeregisterContentEvents() {
49      Content.NameChanged -= new EventHandler(Content_NameChanged);
50      Content.DescriptionChanged -= new EventHandler(Content_DescriptionChanged);
51      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
52      base.DeregisterContentEvents();
53    }
54    protected override void RegisterContentEvents() {
55      base.RegisterContentEvents();
56      Content.NameChanged += new EventHandler(Content_NameChanged);
57      Content.DescriptionChanged += new EventHandler(Content_DescriptionChanged);
58      Content.ValueChanged += new EventHandler(Content_ValueChanged);
59    }
60
61    protected override void OnContentChanged() {
62      base.OnContentChanged();
63      if (Content == null) {
64        viewHost.Content = null;
65        toolTip.SetToolTip(infoLabel, string.Empty);
66        if (ViewAttribute.HasViewAttribute(this.GetType()))
67          this.Caption = ViewAttribute.GetViewName(this.GetType());
68        else
69          this.Caption = "ResultValue View";
70      } else {
71        viewHost.ViewType = null;
72        viewHost.Content = Content.Value;
73        toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
74        Caption = Content.Name;
75      }
76    }
77
78    protected override void SetEnabledStateOfControls() {
79      base.SetEnabledStateOfControls();
80      viewHost.Enabled = Content != null;
81      viewHost.ReadOnly = this.ReadOnly;
82      infoLabel.Enabled = Content != null;
83    }
84
85    private void Content_NameChanged(object sender, EventArgs e) {
86      if (InvokeRequired)
87        Invoke(new EventHandler(Content_NameChanged), sender, e);
88      else
89        Caption = Content.Name;
90    }
91    private void Content_DescriptionChanged(object sender, EventArgs e) {
92      if (InvokeRequired)
93        Invoke(new EventHandler(Content_DescriptionChanged), sender, e);
94      else
95        toolTip.SetToolTip(infoLabel, string.IsNullOrEmpty(Content.Description) ? infoLabelToolTipSuffix : Content.Description + Environment.NewLine + Environment.NewLine + infoLabelToolTipSuffix);
96    }
97    private void Content_ValueChanged(object sender, EventArgs e) {
98      if (InvokeRequired)
99        Invoke(new EventHandler(Content_ValueChanged), sender, e);
100      else {
101        viewHost.Content = Content.Value;
102      }
103    }
104
105    private void infoLabel_DoubleClick(object sender, System.EventArgs e) {
106      using (TextDialog dialog = new TextDialog("Description of " + Content.Name, Content.Description, ReadOnly || !Content.CanChangeDescription)) {
107        if (dialog.ShowDialog(this) == DialogResult.OK)
108          Content.Description = dialog.Content;
109      }
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.