1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 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.ComponentModel;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Core.Views;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
28 | using HeuristicLab.PluginInfrastructure;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Clients.OKB.Administration {
|
---|
31 | [View("OKBItem View")]
|
---|
32 | [Content(typeof(OKBItem), true)]
|
---|
33 | [Content(typeof(IOKBItem), false)]
|
---|
34 | public partial class OKBItemView : ItemView {
|
---|
35 | public new IOKBItem Content {
|
---|
36 | get { return (IOKBItem)base.Content; }
|
---|
37 | set { base.Content = value; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public OKBItemView() {
|
---|
41 | InitializeComponent();
|
---|
42 | }
|
---|
43 |
|
---|
44 | protected override void DeregisterContentEvents() {
|
---|
45 | Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
|
---|
46 | Content.ModifiedChanged -= new EventHandler(Content_ModifiedChanged);
|
---|
47 | base.DeregisterContentEvents();
|
---|
48 | }
|
---|
49 | protected override void RegisterContentEvents() {
|
---|
50 | base.RegisterContentEvents();
|
---|
51 | Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
|
---|
52 | Content.ModifiedChanged += new EventHandler(Content_ModifiedChanged);
|
---|
53 | }
|
---|
54 |
|
---|
55 | protected override void SetEnabledStateOfControls() {
|
---|
56 | base.SetEnabledStateOfControls();
|
---|
57 | storeButton.Enabled = (Content != null) && !ReadOnly && Content.Modified;
|
---|
58 | }
|
---|
59 |
|
---|
60 | private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
61 | if (InvokeRequired)
|
---|
62 | Invoke(new PropertyChangedEventHandler(Content_PropertyChanged), sender, e);
|
---|
63 | else {
|
---|
64 | OnContentPropertyChanged(e.PropertyName);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | protected virtual void OnContentPropertyChanged(string propertyName) { }
|
---|
68 | protected virtual void Content_ModifiedChanged(object sender, EventArgs e) {
|
---|
69 | if (InvokeRequired)
|
---|
70 | Invoke(new EventHandler(Content_ModifiedChanged), sender, e);
|
---|
71 | else
|
---|
72 | SetEnabledStateOfControls();
|
---|
73 | }
|
---|
74 |
|
---|
75 | protected virtual void storeButton_Click(object sender, EventArgs e) {
|
---|
76 | try {
|
---|
77 | Content.Store();
|
---|
78 | }
|
---|
79 | catch (Exception ex) {
|
---|
80 | ErrorHandling.ShowErrorDialog(this, "Store failed.", ex);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|