| 1 | = Views in HL3 = |
| 2 | |
| 3 | == Attributes == |
| 4 | * View |
| 5 | * Content |
| 6 | |
| 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 | } |
| 31 | }}} |
| 32 | |
| 33 | Events happen asynchronous --> Invoke required. |
| 34 | |
| 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(); |
| 43 | } |
| 44 | } |
| 45 | }}} |
| 46 | |
| 47 | === SetEnabledStateOfControls: === |
| 48 | |
| 49 | In principle all Views have 2 possible states: |
| 50 | * Locked: |
| 51 | * ReadOnly: cf. Results --> those can't be changed; this is not configured in the object graph but in the views |
| 52 | |
| 53 | * Either via ViewHost or manually |
| 54 | |
| 55 | OnContentChanged --> update content here |
| 56 | SetEnabledStateOfControls --> only update enabled and readonly here |
| 57 | |
| 58 | === Default Views: === |
| 59 | * The most specific default view is used for inherited classes. |
| 60 | |
| 61 | |
| 62 | protected override void SetEnabledStateOfControls() { |
| 63 | |
| 64 | } |
| 65 | |
| 66 | === NamedItems: === |
| 67 | You should make sure that if CanChangeName is false --> ReadOnly |
| 68 | |
| 69 | private void Content_NameChanged(object sender, EventArgs e) { |
| 70 | if (InvokeRequired) { |
| 71 | Invoke(...); |
| 72 | } else { |
| 73 | |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | AsynchronosContentView, ItemView --> derive from those, not from ContentView or other views in MainForm.WindowsForm (uses Invoke synchronous --> can get messy). |
| 78 | |
| 79 | Andreas has prepared a useful snippet that you may use to easily create a template for your view. |
| 80 | |
| 81 | |
| 82 | == General advice: == |
| 83 | If you program views that are not sealed --> make everything protected to allow inheritance. |