-
Notifications
You must be signed in to change notification settings - Fork 4
/
CustomGanttEditor.cs
134 lines (130 loc) · 5.78 KB
/
CustomGanttEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Model;
using DevExpress.XtraGantt;
using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using GanttSolution.Module.BusinessObjects;
using DevExpress.ExpressApp.EFCore;
using System.Windows.Controls;
namespace GanttSolution.Module.Win.Editors {
[ListEditor(typeof(IMyTask), false)]
public class CustomGanttEditor : ListEditor {
private GanttControl control;
private object controlDataSource;
public CustomGanttEditor(IModelListView info) : base(info) { }
public override SelectionType SelectionType {
get { return SelectionType.Full; }
}
public override IList GetSelectedObjects() {
if (control == null) {
return new object[0] { };
}
object[] result = new object[1];
result[0] = control.GetFocusedRow();
return result;
}
private void Control_SelectedIndexChanged(object sender, EventArgs e) {
OnSelectionChanged();
OnFocusedObjectChanged();
}
private void Control_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) {
OnSelectionChanged();
}
public override void Refresh() {
if (control == null)
return;
try {
control.BeginUpdate();
var lst = ((ProxyCollection)controlDataSource).OriginalCollection as EFCoreCollection;
var lst2 = lst.Cast<object>().ToList();
control.DataSource = lst2;
// control.DataSource = controlDataSource;
control.RefreshDataSource();
}
finally {
control.EndUpdate();
}
}
private void DataSource_ListChanged(object sender, ListChangedEventArgs e) {
Refresh();
}
protected override void AssignDataSourceToControl(object dataSource) {
if (controlDataSource != dataSource) {
IBindingList oldBindable = controlDataSource as IBindingList;
if (oldBindable != null) {
oldBindable.ListChanged -= new ListChangedEventHandler(DataSource_ListChanged);
}
controlDataSource = dataSource;
IBindingList bindable = controlDataSource as IBindingList;
if (bindable != null) {
bindable.ListChanged += DataSource_ListChanged;
}
Refresh();
}
}
protected override object CreateControlsCore() {
control = new GanttControl();
foreach (IModelColumn column in Model.Columns) {
if(!(column.Caption=="Name" || column.Caption == "Start Date" || column.Caption == "End Date")) {
continue;
}
var ganttColumn = new DevExpress.XtraTreeList.Columns.TreeListColumn();
ganttColumn.Caption = column.Caption;
ganttColumn.FieldName = column.PropertyName;
ganttColumn.Name = column.PropertyName + "Column";
ganttColumn.Visible = true;
ganttColumn.SortIndex = column.SortIndex;
ganttColumn.Format.FormatString = column.DisplayFormat;
ganttColumn.Format.FormatType = DevExpress.Utils.FormatType.Custom;
control.Columns.Add(ganttColumn);
}
control.KeyFieldName = nameof(IMyTask.TaskId);
control.ParentFieldName = nameof(IMyTask.Parent);
control.ChartMappings.TextFieldName = nameof(IMyTask.Name);
control.ChartMappings.StartDateFieldName = nameof(IMyTask.StartDate);
control.ChartMappings.FinishDateFieldName = nameof(IMyTask.EndDate);
control.ChartMappings.ProgressFieldName = nameof(IMyTask.Progress);
control.ChartMappings.PredecessorsFieldName = nameof(IMyTask.PredecessorTasks);
control.AllowTouchGestures = DevExpress.Utils.DefaultBoolean.True;
control.OptionsBehavior.ScheduleMode = DevExpress.XtraGantt.Options.ScheduleMode.Auto;
control.OptionsCustomization.AllowModifyTasks = DevExpress.Utils.DefaultBoolean.True;
control.OptionsCustomization.AllowModifyDependencies = DevExpress.Utils.DefaultBoolean.True;
control.OptionsCustomization.AllowModifyProgress = DevExpress.Utils.DefaultBoolean.True;
control.SelectionChanged += Control_SelectedIndexChanged;
control.FocusedNodeChanged += Control_FocusedNodeChanged;
control.MouseDoubleClick += Control_MouseDoubleClick;
control.KeyDown += Control_KeyDown;
Refresh();
return control;
}
private void Control_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) {
OnSelectionChanged();
OnFocusedObjectChanged();
}
private void Control_MouseDoubleClick(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left) {
GanttControlHitInfo hitInfo = control.CalcHitInfo(e.Location);
if (hitInfo.ChartHitTest?.ItemInfo != null) {
OnProcessSelectedItem();
}
}
}
private void Control_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Enter) {
OnProcessSelectedItem();
}
}
public override object FocusedObject {
get {
return control?.GetFocusedRow();
}
}
public override void Dispose() {
controlDataSource = null;
base.Dispose();
}
}
}