- Timestamp:
- 01/20/10 05:04:31 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/ItemViewBase.cs
r2555 r2655 34 34 /// Base class for all visual representations. 35 35 /// </summary> 36 public partial class ItemViewBase : ViewBase, IItemView { 37 private IItem myItem; 38 /// <summary> 39 /// Gets or sets the item to represent visually. 40 /// </summary> 41 /// <remarks>Calls <see cref="OnItemChanged"/>, <see cref="Refresh"/>, 42 /// <see cref="RemoveItemEvents"/> (if the current item is not null) and 43 /// <see cref="AddItemEvents"/> (if the new item is not null) in the setter.</remarks> 36 public partial class ItemViewBase : ObjectViewBase { 44 37 public IItem Item { 45 get { return myItem; } 46 protected set { 47 if (value != myItem) { 48 if (myItem != null) 49 RemoveItemEvents(); 50 myItem = value; 51 if (myItem != null) 52 AddItemEvents(); 53 OnItemChanged(); 54 Refresh(); 55 } 56 } 38 get { return (IItem)base.Object; } 39 set { base.Object = value; } 57 40 } 58 41 … … 65 48 } 66 49 67 /// <summary> 68 /// Removes the eventhandlers from the current instance. 69 /// </summary> 70 protected virtual void RemoveItemEvents() { } 71 /// <summary> 72 /// Adds eventhandlers to the current instance. 73 /// </summary> 74 protected virtual void AddItemEvents() { } 75 76 /// <summary> 77 /// Refreshes the current view. 78 /// </summary> 79 /// <remarks>Creates a new <see cref="MethodInvoker"/> if an invoke is required 80 /// (see <see cref="Control.InvokeRequired"/>.<br/> 81 /// Otherwise calls <see cref="UpdateControls"/> and <see cref="Control.Refresh"/> of base class 82 /// <see cref="System.Windows.Forms.UserControl"/>.</remarks> 83 public override void Refresh() { 84 if (InvokeRequired) { 85 Invoke(new Action(Refresh)); 50 protected override void OnObjectChanged() { 51 if (Item == null) { 52 Caption = "View"; 86 53 } else { 87 UpdateControls(); 88 base.Refresh(); 54 Caption = Item.ItemName; 89 55 } 90 }91 /// <summary>92 /// Updates the controls with the latest values of the model.93 /// </summary>94 protected virtual void UpdateControls() {95 if (Item == null)96 Caption = "View";97 else98 Caption = Item.Name;99 100 }101 102 /// <summary>103 /// Occurs when the current item was changed.104 /// </summary>105 public event EventHandler ItemChanged;106 /// <summary>107 /// Fires a new <c>ItemChanged</c> event.108 /// </summary>109 protected virtual void OnItemChanged() {110 if (ItemChanged != null)111 ItemChanged(this, new EventArgs());112 }113 114 /// <summary>115 /// Asynchron call of GUI updating.116 /// </summary>117 /// <param name="method">The delegate to invoke.</param>118 protected new void Invoke(Delegate method) {119 // enforce context switch to improve GUI response time120 System.Threading.Thread.Sleep(0);121 122 // prevent blocking of worker thread in Invoke, if the control is disposed123 IAsyncResult result = BeginInvoke(method);124 while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }125 if (!IsDisposed) EndInvoke(result);126 }127 /// <summary>128 /// Asynchron call of GUI updating.129 /// </summary>130 /// <param name="method">The delegate to invoke.</param>131 /// <param name="args">The invoke arguments.</param>132 protected new void Invoke(Delegate method, params object[] args) {133 // enforce context switch to improve GUI response time134 System.Threading.Thread.Sleep(0);135 136 // prevent blocking of worker thread in Invoke, if the control is disposed137 IAsyncResult result = BeginInvoke(method, args);138 while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }139 if (!IsDisposed) EndInvoke(result);140 56 } 141 57 }
Note: See TracChangeset
for help on using the changeset viewer.