This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserEditorsRepository.cs
42 lines (36 loc) · 1.63 KB
/
UserEditorsRepository.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
using System;
using System.Collections.Generic;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
namespace DefaultEditor {
public class UserEditorsRepository : DefaultEditorsRepository {
Dictionary<EditorType, RepositoryItem> EditorsCache = new Dictionary<EditorType, RepositoryItem>();
public override RepositoryItem GetRepositoryItem(Type type) {
if (type.Equals(typeof(DateTime)))
return GetRepositoryItem(EditorType.DateTime);
else if (type.Equals(typeof(bool)))
return GetRepositoryItem(EditorType.Boolean);
else return base.GetRepositoryItem(type);
}
RepositoryItem GetRepositoryItem(EditorType editorType) {
if (EditorsCache.ContainsKey(editorType))
return EditorsCache[editorType];
RepositoryItem result = CreateRepositoryItem(editorType);
EditorsCache.Add(editorType, result);
return result;
}
RepositoryItem CreateRepositoryItem(EditorType editorType) {
switch (editorType) {
case EditorType.DateTime: return new RepositoryItemTextEdit();
case EditorType.Boolean:
RepositoryItemRadioGroup result = new RepositoryItemRadioGroup();
result.Columns = 2;
result.Items.Add(new RadioGroupItem(true, "Yes"));
result.Items.Add(new RadioGroupItem(false, "No"));
return result;
default: return new RepositoryItemTextEdit();
}
}
enum EditorType { DateTime, Boolean }
}
}