[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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Windows.Forms;
|
---|
[3376] | 24 | using HeuristicLab.Common;
|
---|
[3260] | 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Core.Views;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 |
|
---|
| 29 | namespace 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 |
|
---|
| 60 | protected override void OnContentChanged() {
|
---|
| 61 | base.OnContentChanged();
|
---|
| 62 | FillListView();
|
---|
| 63 | viewHost.ViewType = null;
|
---|
| 64 | viewHost.Content = null;
|
---|
[3350] | 65 | if (Content == null)
|
---|
| 66 | Caption = "Run";
|
---|
| 67 | else
|
---|
| 68 | Caption = Content.Name + " (" + Content.GetType().Name + ")";
|
---|
[3362] | 69 | SetEnabledStateOfControls();
|
---|
[3350] | 70 | }
|
---|
| 71 | protected override void OnReadOnlyChanged() {
|
---|
| 72 | base.OnReadOnlyChanged();
|
---|
[3362] | 73 | SetEnabledStateOfControls();
|
---|
[3350] | 74 | }
|
---|
[3454] | 75 | protected override void OnLockedChanged() {
|
---|
| 76 | base.OnLockedChanged();
|
---|
| 77 | SetEnabledStateOfControls();
|
---|
| 78 | }
|
---|
[3362] | 79 | private void SetEnabledStateOfControls() {
|
---|
[3454] | 80 | listView.Enabled = Content != null;
|
---|
| 81 | viewHost.Enabled = Content != null;
|
---|
| 82 | showAlgorithmButton.Enabled = Content != null && !Locked;
|
---|
[3260] | 83 | }
|
---|
| 84 |
|
---|
| 85 | private void FillListView() {
|
---|
| 86 | listView.Items.Clear();
|
---|
[3341] | 87 | listView.SmallImageList.Images.Clear();
|
---|
[3260] | 88 | if (Content != null) {
|
---|
[3341] | 89 | foreach (string key in Content.Parameters.Keys)
|
---|
| 90 | CreateListViewItem(key, Content.Parameters[key], listView.Groups["parametersGroup"]);
|
---|
| 91 | foreach (string key in Content.Results.Keys)
|
---|
| 92 | CreateListViewItem(key, Content.Results[key], listView.Groups["resultsGroup"]);
|
---|
[3260] | 93 | if (listView.Items.Count > 0) {
|
---|
| 94 | for (int i = 0; i < listView.Columns.Count; i++)
|
---|
| 95 | listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[3341] | 100 | private void CreateListViewItem(string name, IItem value, ListViewGroup group) {
|
---|
| 101 | ListViewItem item = new ListViewItem(new string[] { name, value != null ? value.ToString() : "-" });
|
---|
| 102 | item.Tag = value;
|
---|
| 103 | item.Group = group;
|
---|
| 104 | listView.SmallImageList.Images.Add(value == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : value.ItemImage);
|
---|
| 105 | item.ImageIndex = listView.SmallImageList.Images.Count - 1;
|
---|
| 106 | listView.Items.Add(item);
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[3260] | 109 | private void listView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 110 | if (listView.SelectedItems.Count == 1) {
|
---|
| 111 | viewHost.ViewType = null;
|
---|
[3557] | 112 | viewHost.Content = (IContent)listView.SelectedItems[0].Tag;
|
---|
[3260] | 113 | } else {
|
---|
| 114 | viewHost.Content = null;
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
[3300] | 117 | private void listView_DoubleClick(object sender, EventArgs e) {
|
---|
| 118 | if (listView.SelectedItems.Count == 1) {
|
---|
| 119 | IItem item = (IItem)listView.SelectedItems[0].Tag;
|
---|
[3557] | 120 | IContentView view = MainFormManager.MainForm.ShowContent(item);
|
---|
[3416] | 121 | if (view != null) {
|
---|
| 122 | view.ReadOnly = ReadOnly;
|
---|
[3423] | 123 | view.Locked = Locked;
|
---|
[3416] | 124 | }
|
---|
[3300] | 125 | }
|
---|
| 126 | }
|
---|
| 127 | private void listView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
[3432] | 128 | if (!Locked) {
|
---|
| 129 | ListViewItem listViewItem = (ListViewItem)e.Item;
|
---|
| 130 | IItem item = (IItem)listViewItem.Tag;
|
---|
| 131 | DataObject data = new DataObject();
|
---|
| 132 | data.SetData("Type", item.GetType());
|
---|
| 133 | data.SetData("Value", item);
|
---|
| 134 | DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
|
---|
| 135 | }
|
---|
[3300] | 136 | }
|
---|
| 137 | private void showAlgorithmButton_Click(object sender, EventArgs e) {
|
---|
[3454] | 138 | if (!Locked) {
|
---|
[3557] | 139 | MainFormManager.MainForm.ShowContent((IContent)Content.Algorithm.Clone());
|
---|
[3416] | 140 | }
|
---|
[3300] | 141 | }
|
---|
[3260] | 142 | }
|
---|
| 143 | }
|
---|