Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/RunView.cs @ 3423

Last change on this file since 3423 was 3423, checked in by mkommend, 14 years ago

added setting of locked property after the creation of contentviews (ticket #982)

File size: 5.6 KB
RevLine 
[3260]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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;
[3376]24using HeuristicLab.Common;
[3260]25using HeuristicLab.Core;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29namespace HeuristicLab.Optimization.Views {
30  /// <summary>
31  /// The visual representation of a <see cref="Variable"/>.
32  /// </summary>
33  [View("Run View")]
[3280]34  [Content(typeof(IRun), true)]
[3260]35  public sealed partial class RunView : NamedItemView {
36    /// <summary>
37    /// Gets or sets the variable to represent visually.
38    /// </summary>
39    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
40    /// No own data storage present.</remarks>
[3280]41    public new IRun Content {
42      get { return (IRun)base.Content; }
[3260]43      set { base.Content = value; }
44    }
45
[3350]46    public override bool ReadOnly {
47      get { return base.ReadOnly; }
48      set { /*not needed because results are always readonly */}
49    }
50
[3260]51    /// <summary>
52    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
53    /// </summary>
54    public RunView() {
55      InitializeComponent();
56      Caption = "Run";
[3350]57      base.ReadOnly = true;
[3260]58    }
59    /// <summary>
60    /// Initializes a new instance of <see cref="VariableView"/> with the given <paramref name="variable"/>.
61    /// </summary>
62    /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
63    /// <param name="variable">The variable to represent visually.</param>
[3280]64    public RunView(IRun content)
[3260]65      : this() {
66      Content = content;
67    }
68
69    protected override void OnContentChanged() {
70      base.OnContentChanged();
71      FillListView();
72      viewHost.ViewType = null;
73      viewHost.Content = null;
[3350]74      if (Content == null)
75        Caption = "Run";
76      else
77        Caption = Content.Name + " (" + Content.GetType().Name + ")";
[3362]78      SetEnabledStateOfControls();
[3350]79    }
80    protected override void OnReadOnlyChanged() {
81      base.OnReadOnlyChanged();
[3362]82      SetEnabledStateOfControls();
[3350]83    }
[3362]84    private void SetEnabledStateOfControls() {
[3260]85      if (Content == null) {
86        parametersResultsGroupBox.Enabled = false;
[3350]87        viewHost.Enabled = false;
[3260]88      } else {
89        parametersResultsGroupBox.Enabled = true;
[3350]90        viewHost.Enabled = true;
91        viewHost.ReadOnly = ReadOnly;
[3260]92      }
93    }
94
95    private void FillListView() {
96      listView.Items.Clear();
[3341]97      listView.SmallImageList.Images.Clear();
[3260]98      if (Content != null) {
[3341]99        foreach (string key in Content.Parameters.Keys)
100          CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"]);
101        foreach (string key in Content.Results.Keys)
102          CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"]);
[3260]103        if (listView.Items.Count > 0) {
104          for (int i = 0; i < listView.Columns.Count; i++)
105            listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
106        }
107      }
108    }
109
[3341]110    private void CreateListViewItem(string name, IItem value, ListViewGroup group) {
111      ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
112      item.Tag = value;
113      item.Group = group;
114      listView.SmallImageList.Images.Add(value == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : value.ItemImage);
115      item.ImageIndex = listView.SmallImageList.Images.Count - 1;
116      listView.Items.Add(item);
117    }
118
[3260]119    private void listView_SelectedIndexChanged(object sender, EventArgs e) {
120      if (listView.SelectedItems.Count == 1) {
121        viewHost.ViewType = null;
[3416]122        viewHost.Content = (IContent) listView.SelectedItems[0].Tag;
[3260]123      } else {
124        viewHost.Content = null;
125      }
126    }
[3300]127    private void listView_DoubleClick(object sender, EventArgs e) {
128      if (listView.SelectedItems.Count == 1) {
129        IItem item = (IItem)listView.SelectedItems[0].Tag;
[3423]130        IContentView view = MainFormManager.CreateDefaultView(item);
[3416]131        if (view != null) {
132          view.ReadOnly = ReadOnly;
[3423]133          view.Locked = Locked;
[3416]134          view.Show();
135        }
[3300]136      }
137    }
138    private void listView_ItemDrag(object sender, ItemDragEventArgs e) {
139      ListViewItem listViewItem = (ListViewItem)e.Item;
140      IItem item = (IItem)listViewItem.Tag;
141      DataObject data = new DataObject();
142      data.SetData("Type", item.GetType());
143      data.SetData("Value", item);
[3341]144      DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
[3300]145    }
146    private void showAlgorithmButton_Click(object sender, EventArgs e) {
[3416]147      IContentView view = MainFormManager.CreateDefaultView(Content.Algorithm.Clone());
148      if (view != null) {
149        view.ReadOnly = ReadOnly;
[3423]150        view.Locked = Locked;
[3416]151        view.Show();
152      }
[3300]153    }
[3260]154  }
155}
Note: See TracBrowser for help on using the repository browser.