7 | | == Methods to override: == |
8 | | |
9 | | {{{#!java |
10 | | public new Algorithm Content { |
11 | | get { return (T)base.Content; } |
12 | | set { base.Content = value; } |
13 | | } |
14 | | |
15 | | protected override void OnContentChanged() { |
16 | | base.OnContentChanged(); |
17 | | if (Content != null) { |
18 | | // set controls to Content values |
19 | | } else { |
20 | | // set default values in controls |
21 | | } |
22 | | } |
23 | | |
24 | | protected override void RegisterContentEvents() { |
25 | | |
26 | | } |
27 | | |
28 | | protected override void DeRegisterContentEvents() { |
29 | | |
30 | | } |
| 5 | {{{#!csharp |
| 6 | MainFormManager.MainForm.ShowContent(IContent content); //displays the content with its default view |
| 7 | MainFormManager.MainForm.ShowContent(IContent content, Type viewType); //displays the content with the specified view type |
35 | | Views must still work if content is NULL. |
36 | | {{{#!java |
37 | | private void Content_XYZChanged(object sender, System.EventArgs e) { |
38 | | if (InvokeRequired) { |
39 | | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); |
40 | | } else { |
41 | | // set controls |
42 | | SetEnabledStateControls(); |
| 12 | |
| 13 | The `StringConvertibleValueView` is located in HeuristicLab.Data.View and consists of a label and a textbox. |
| 14 | |
| 15 | TODO insert image of !StringConvertibleValueView |
| 16 | |
| 17 | == Frame of HeuristicLab views == |
| 18 | |
| 19 | {{{#!csharp |
| 20 | [View("StringConvertibleValue View")] |
| 21 | [Content(typeof(IStringConvertibleValue), true)] |
| 22 | public partial class StringConvertibleValueView : AsynchronousContentView { |
| 23 | public new IStringConvertibleValue Content { |
| 24 | get { return (IStringConvertibleValue)base.Content; } |
| 25 | set { base.Content = value; } |
| 26 | } |
58 | | === Default Views: === |
59 | | * The most specific default view is used for inherited classes. |
| 48 | protected override void RegisterContentEvents() { |
| 49 | base.RegisterContentEvents(); |
| 50 | Content.ValueChanged += new EventHandler(Content_ValueChanged); |
| 51 | } |
| 52 | |
| 53 | private void Content_ValueChanged(object sender, EventArgs e) { |
| 54 | if (InvokeRequired) |
| 55 | Invoke(new EventHandler(Content_ValueChanged), sender, e); |
| 56 | else |
| 57 | valueTextBox.Text = Content.GetValue(); |
| 58 | } |
| 59 | }}} |
| 60 | |
| 61 | If a new content is set in a view, first the `DeregisterContentEvents` method is called, afterwards `OnContentChanged` and at last `RegisterContentEvents`. `DeregisterContentEvents` is responsible for deregistering events from the "old" content, and is only called if the old content is not null. `OnContentChanged` the controls in the view must be filled with the properties of the content, in this case the valueTextBox is either populated with the result of `Content.GetValue()` or displays nothing (`String.Empty`) if the content is null. `RegisterContentEvents` is the equivalent to `DeregisterContentEvents` for registering necessary events on the new content object. If the `Content` changes its value the previously registered `Content_ValueChanged` method is called and the value of the `TextBox` is updated. Please keep in mind, that these events are often called asynchronous and therefore, an `InvokeRequired` check with according `Invoke` call is necessary (more information on [http://msdn.microsoft.com/en-us/library/ms171728.aspx thread-safe calls to controls]). |
| 62 | |
| 63 | == Enabling & Disabling of Controls == |
| 64 | Every HeuristicLab view has the two states `Locked` and `ReadOnly` that are used to indicate if an operation is in progress and contents should not be altered, e.g. saving to a file or a running algorithm. Changes to these two properties, as well as content changes, trigger to following overriden method. |
| 65 | |
| 66 | {{{#!csharp |
| 67 | protected override void SetEnabledStateOfControls() { |
| 68 | base.SetEnabledStateOfControls(); |
| 69 | valueTextBox.Enabled = !Locked && Content != null; |
| 70 | valueTextBox.ReadOnly = ReadOnly; |
| 71 | } |
| 72 | }}} |
| 73 | |
| 74 | In `SetEnabledStateOfControls` used controls must be adapted according to the current state of the view. If other HeuristicLab views are nested in the current view, no additional handling is necessary, as state changes are automatically propagated by the base class. |
| 75 | |
| 76 | The Locked state of a view is set if a operation is in progress and !ReadOnly is used if the content object itself indicates that it must not be changed. Most times the enabled property corresponds to the Locked state and additionally to !ReadOnly if not separates handling is provided by the control. |