[5955] | 1 | using System;
|
---|
| 2 | using System.ComponentModel;
|
---|
| 3 | using System.Windows.Forms;
|
---|
| 4 | using HeuristicLab.Core.Views;
|
---|
| 5 | using HeuristicLab.MainForm;
|
---|
| 6 | using HeuristicLab.PluginInfrastructure;
|
---|
| 7 |
|
---|
| 8 | namespace HeuristicLab.Clients.Hive.Views {
|
---|
| 9 | [View("HiveItem View")]
|
---|
| 10 | [Content(typeof(HiveItem), IsDefaultView = false)]
|
---|
| 11 | [Content(typeof(IHiveItem), IsDefaultView = false)]
|
---|
| 12 | public partial class HiveItemView : ItemView {
|
---|
| 13 | public new IHiveItem Content {
|
---|
| 14 | get { return (IHiveItem)base.Content; }
|
---|
| 15 | set { base.Content = value; }
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | public HiveItemView() {
|
---|
| 19 | InitializeComponent();
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | protected override void DeregisterContentEvents() {
|
---|
| 23 | Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
|
---|
| 24 | Content.ModifiedChanged -= new EventHandler(Content_ModifiedChanged);
|
---|
| 25 | base.DeregisterContentEvents();
|
---|
| 26 | }
|
---|
| 27 | protected override void RegisterContentEvents() {
|
---|
| 28 | base.RegisterContentEvents();
|
---|
| 29 | Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
|
---|
| 30 | Content.ModifiedChanged += new EventHandler(Content_ModifiedChanged);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | protected override void SetEnabledStateOfControls() {
|
---|
| 34 | base.SetEnabledStateOfControls();
|
---|
| 35 | storeButton.Enabled = (Content != null) && !ReadOnly && Content.Modified;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 39 | if (InvokeRequired)
|
---|
| 40 | Invoke(new PropertyChangedEventHandler(Content_PropertyChanged), sender, e);
|
---|
| 41 | else {
|
---|
| 42 | OnContentPropertyChanged(e.PropertyName);
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | protected virtual void OnContentPropertyChanged(string propertyName) { }
|
---|
| 46 | protected virtual void Content_ModifiedChanged(object sender, EventArgs e) {
|
---|
| 47 | if (InvokeRequired)
|
---|
| 48 | Invoke(new EventHandler(Content_ModifiedChanged), sender, e);
|
---|
| 49 | else
|
---|
| 50 | SetEnabledStateOfControls();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | protected virtual void storeButton_Click(object sender, EventArgs e) {
|
---|
| 54 | try {
|
---|
| 55 | Content.Store();
|
---|
| 56 | }
|
---|
| 57 | catch (Exception ex) {
|
---|
| 58 | ErrorHandling.ShowErrorDialog(this, "Store failed.", ex);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | } |
---|