1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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;
|
---|
24 | using HeuristicLab.MainForm;
|
---|
25 | using HeuristicLab.MainForm.WindowsForms;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Clients.OKB.Query {
|
---|
28 | [View("OrdinalComparisonTimeSpanFilterView View")]
|
---|
29 | [Content(typeof(OrdinalComparisonTimeSpanFilter), true)]
|
---|
30 | public partial class OrdinalComparisonTimeSpanFilterView : OrdinalComparisonFilterView {
|
---|
31 | public new OrdinalComparisonTimeSpanFilter Content {
|
---|
32 | get { return (OrdinalComparisonTimeSpanFilter)base.Content; }
|
---|
33 | set { base.Content = value; }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public OrdinalComparisonTimeSpanFilterView() {
|
---|
37 | InitializeComponent();
|
---|
38 | errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
39 | errorProvider.SetIconPadding(valueTextBox, 2);
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected override void OnContentChanged() {
|
---|
43 | base.OnContentChanged();
|
---|
44 |
|
---|
45 | if (Content == null) {
|
---|
46 | valueTextBox.Text = string.Empty;
|
---|
47 | } else if (Content.Value == 0) {
|
---|
48 | valueTextBox.Text = "00:00:00";
|
---|
49 | } else {
|
---|
50 | valueTextBox.Text = TimeSpan.FromSeconds(Content.Value).ToString();
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | protected override void SetEnabledStateOfControls() {
|
---|
55 | base.SetEnabledStateOfControls();
|
---|
56 | valueTextBox.Enabled = Content != null;
|
---|
57 | valueTextBox.ReadOnly = ReadOnly;
|
---|
58 | }
|
---|
59 |
|
---|
60 | private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
61 | if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
|
---|
62 | label.Focus(); // set focus on label to validate data
|
---|
63 | if (e.KeyCode == Keys.Escape) {
|
---|
64 | valueTextBox.Text = Content.Value.ToString();
|
---|
65 | label.Focus(); // set focus on label to validate data
|
---|
66 | }
|
---|
67 | }
|
---|
68 | private void valueTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
69 | HeuristicLab.Data.IStringConvertibleValue tsv = new HeuristicLab.Data.TimeSpanValue();
|
---|
70 |
|
---|
71 | string errorMessage;
|
---|
72 | if (!tsv.Validate(valueTextBox.Text, out errorMessage)) {
|
---|
73 | e.Cancel = true;
|
---|
74 | errorProvider.SetError(valueTextBox, "Invalid TimeSpan Value");
|
---|
75 | valueTextBox.SelectAll();
|
---|
76 | }
|
---|
77 | }
|
---|
78 | private void valueTextBox_Validated(object sender, System.EventArgs e) {
|
---|
79 | if (Content != null) {
|
---|
80 | HeuristicLab.Data.IStringConvertibleValue tsv = new HeuristicLab.Data.TimeSpanValue();
|
---|
81 |
|
---|
82 | tsv.SetValue(valueTextBox.Text);
|
---|
83 | Content.Value = (long)((HeuristicLab.Data.TimeSpanValue)tsv).Value.TotalSeconds;
|
---|
84 | errorProvider.SetError(valueTextBox, string.Empty);
|
---|
85 | valueTextBox.Text = tsv.GetValue();
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|