1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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.Linq;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Core.Views;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Clients.Hive.Views.Administration {
|
---|
30 | [View("ResourcesView")]
|
---|
31 | [Content(typeof(IItemList<Resource>), IsDefaultView = true)]
|
---|
32 | public partial class ResourcesView : ItemView {
|
---|
33 | public new IItemList<Resource> Content {
|
---|
34 | get { return (IItemList<Resource>)base.Content; }
|
---|
35 | set { base.Content = value; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public ResourcesView() {
|
---|
39 | InitializeComponent();
|
---|
40 | treeSlaveGroup.ImageList.Images.Add(HiveImageLibrary.Slave);
|
---|
41 | treeSlaveGroup.ImageList.Images.Add(HiveImageLibrary.SlaveGroup);
|
---|
42 | updateScheduleControl.UpdateAction = new Action(UpdateSchedule);
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void UpdateSchedule() {
|
---|
46 | Guid resourceId = scheduleView.ResourceId;
|
---|
47 | if (resourceId != null) {
|
---|
48 | ServiceLocator.Instance.CallHiveService(service => {
|
---|
49 | var appointments = service.GetScheduleForResource(resourceId);
|
---|
50 | ItemList<Appointment> ias = new ItemList<Appointment>();
|
---|
51 | appointments.ForEach(a => ias.Add(a));
|
---|
52 | scheduleView.Invoke(new Action(() => scheduleView.Content = ias));
|
---|
53 | });
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | #region Register Content Events
|
---|
58 | protected override void DeregisterContentEvents() {
|
---|
59 | // TODO: Deregister your event handlers on the Content here
|
---|
60 | base.DeregisterContentEvents();
|
---|
61 | }
|
---|
62 | protected override void RegisterContentEvents() {
|
---|
63 | base.RegisterContentEvents();
|
---|
64 | // TODO: Register your event handlers on the Content here
|
---|
65 | }
|
---|
66 | #endregion
|
---|
67 |
|
---|
68 | protected override void OnContentChanged() {
|
---|
69 | base.OnContentChanged();
|
---|
70 | if (Content == null) {
|
---|
71 | slaveView.Content = null;
|
---|
72 | treeSlaveGroup.Nodes.Clear();
|
---|
73 | } else {
|
---|
74 |
|
---|
75 | TreeNode ungrp = new TreeNode("UNGROUPED");
|
---|
76 | ungrp.ImageIndex = treeSlaveGroup.ImageList.Images.Count - 1;
|
---|
77 | ungrp.SelectedImageIndex = ungrp.ImageIndex;
|
---|
78 | var newGroup = new SlaveGroup();
|
---|
79 | newGroup.Name = "UNGROUPED";
|
---|
80 | newGroup.Id = Guid.NewGuid();
|
---|
81 | newGroup.Description = "Contains slaves which are in no group";
|
---|
82 | ungrp.Tag = newGroup;
|
---|
83 |
|
---|
84 | foreach (Resource g in Content) {
|
---|
85 | if (g.GetType() == typeof(SlaveGroup)) {
|
---|
86 | TreeNode tn = new TreeNode();
|
---|
87 | tn.ImageIndex = treeSlaveGroup.ImageList.Images.Count - 1;
|
---|
88 | tn.SelectedImageIndex = tn.ImageIndex;
|
---|
89 |
|
---|
90 | tn.Tag = g;
|
---|
91 | tn.Text = g.Name;
|
---|
92 | foreach (Slave s in Content.Where(s => s.ParentResourceId != null && s.ParentResourceId == g.Id)) {
|
---|
93 | var stn = new TreeNode(s.Name);
|
---|
94 | stn.ImageIndex = 0;
|
---|
95 | stn.SelectedImageIndex = stn.ImageIndex;
|
---|
96 | stn.Tag = s;
|
---|
97 | tn.Nodes.Add(stn);
|
---|
98 | }
|
---|
99 | treeSlaveGroup.Nodes.Add(tn);
|
---|
100 |
|
---|
101 |
|
---|
102 | } else if (g.GetType() == typeof(Slave)) {
|
---|
103 | if (g.ParentResourceId == null) {
|
---|
104 | var stn = new TreeNode(g.Name);
|
---|
105 | stn.ImageIndex = 0;
|
---|
106 | stn.SelectedImageIndex = stn.ImageIndex;
|
---|
107 | stn.Tag = g;
|
---|
108 | ungrp.Nodes.Add(stn);
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 | treeSlaveGroup.Nodes.Add(ungrp);
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | protected override void SetEnabledStateOfControls() {
|
---|
117 | base.SetEnabledStateOfControls();
|
---|
118 | // TODO: Put code here to enable or disable controls based on whether the Content is/not null or the view is ReadOnly
|
---|
119 | }
|
---|
120 |
|
---|
121 | private void treeSlaveGroup_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
122 | if (e.Node.Tag.GetType() == typeof(Slave)) {
|
---|
123 | slaveView.Content = (Slave)e.Node.Tag;
|
---|
124 | scheduleView.ResourceId = ((Slave)e.Node.Tag).Id;
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | #region Event Handlers
|
---|
129 | // TODO: Put event handlers here
|
---|
130 | #endregion
|
---|
131 | }
|
---|
132 | }
|
---|