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
/
MyTokenEdit.vb
238 lines (204 loc) · 7.81 KB
/
MyTokenEdit.vb
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Drawing
Imports DevExpress.XtraEditors.Registrator
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraEditors.ViewInfo
Imports DevExpress.XtraEditors.Popup
Imports System.Collections
Namespace T328505
<UserRepositoryItem("RegisterMyTokenEdit")> _
Public Class RepositoryItemMyTokenEdit
Inherits RepositoryItemTokenEdit
Shared Sub New()
RegisterMyTokenEdit()
End Sub
Private customFilterHandler As EventHandler(Of MyFilterEventArgs)
Private _UseCustomFilter As Boolean
Public Property UseCustomFilter() As Boolean
Get
Return _UseCustomFilter
End Get
Set(ByVal value As Boolean)
_UseCustomFilter = value
End Set
End Property
Public Property CustomFilterTokens() As EventHandler(Of MyFilterEventArgs)
Get
Return customFilterHandler
End Get
Set(ByVal value As EventHandler(Of MyFilterEventArgs))
customFilterHandler = value
End Set
End Property
Public Const CustomEditName As String = "MyTokenEdit"
Public Sub New()
End Sub
Public Overrides ReadOnly Property EditorTypeName() As String
Get
Return CustomEditName
End Get
End Property
Public Shared Sub RegisterMyTokenEdit()
Dim img As Image = Nothing
EditorRegistrationInfo.Default.Editors.Add(New EditorClassInfo(CustomEditName, GetType(MyTokenEdit), GetType(RepositoryItemMyTokenEdit), GetType(MyTokenEditViewInfo), New TokenEditPainter(), True, img))
End Sub
Public Overrides Sub Assign(ByVal item As RepositoryItem)
BeginUpdate()
Try
MyBase.Assign(item)
Dim source As RepositoryItemMyTokenEdit = TryCast(item, RepositoryItemMyTokenEdit)
If source Is Nothing Then
Return
End If
Me.UseCustomFilter = source.UseCustomFilter
Me.CustomFilterTokens = source.CustomFilterTokens
'
Finally
EndUpdate()
End Try
End Sub
Friend Sub OnCustomFilterText(ByVal args As MyFilterEventArgs)
If customFilterHandler IsNot Nothing Then
customFilterHandler(Me, args)
End If
End Sub
End Class
<ToolboxItem(True)> _
Public Class MyTokenEdit
Inherits TokenEdit
Friend Sub OnCustomFilterText(ByVal args As MyFilterEventArgs)
Me.Properties.OnCustomFilterText(args)
End Sub
Shared Sub New()
RepositoryItemMyTokenEdit.RegisterMyTokenEdit()
End Sub
Public Sub New()
End Sub
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Shadows ReadOnly Property Properties() As RepositoryItemMyTokenEdit
Get
Return TryCast(MyBase.Properties, RepositoryItemMyTokenEdit)
End Get
End Property
Public Overrides ReadOnly Property EditorTypeName() As String
Get
Return RepositoryItemMyTokenEdit.CustomEditName
End Get
End Property
Protected Overrides Function CreatePopupForm() As TokenEditPopupForm
Return New MyTokenEditPopupForm(Me)
End Function
Protected Overrides Function CreatePopupController() As BaseTokenEditPopupController
If Properties.EditMode = TokenEditMode.TokenList OrElse Properties.EditMode = TokenEditMode.Default Then
Return New MyTokenEditTokenListPopupController(Me)
End If
Return New TokenEditManualModePopupController(Me)
End Function
End Class
Public Class MyTokenEditViewInfo
Inherits TokenEditViewInfo
Public Sub New(ByVal item As RepositoryItem)
MyBase.New(item)
End Sub
End Class
Public Class MyTokenEditPopupForm
Inherits TokenEditPopupForm
Public Sub New(ByVal edit As TokenEdit)
MyBase.New(edit)
End Sub
Protected Overrides Function CreateDropDownControl() As ITokenEditDropDownControl
Dim control As New MyDefaultTokenEditDropDownControl()
Return control
End Function
End Class
Public Class MyDefaultTokenEditDropDownControl
Inherits DefaultTokenEditDropDownControl
Public Sub New()
MyBase.New()
End Sub
Private Function GetCustomFilterSourceCore() As IList
Dim tokCol As TokenEditTokenCollection = Properties.Tokens
Dim selCol As TokenEditSelectedItemCollection = Properties.SelectedItems
If selCol.Count = 0 Then
Return tokCol
End If
Dim indices As New HashSet(Of Integer)()
For i As Integer = 0 To selCol.Count - 1
Dim tok As TokenEditToken = selCol(i)
indices.Add(Properties.Tokens.IndexOf(tok))
Next i
Dim list As New List(Of TokenEditToken)(tokCol.Count)
For i As Integer = 0 To tokCol.Count - 1
If indices.Contains(i) Then
Continue For
End If
list.Add(tokCol(i))
Next i
Return list
End Function
Private Function GetCustomFilterSource() As IList
Dim list As IList = GetCustomFilterSourceCore()
Dim newList As New List(Of TokenEditToken)()
Dim edit As MyTokenEdit = TryCast(Me.OwnerEdit, MyTokenEdit)
For i As Integer = 0 To list.Count - 1
Dim args As New MyFilterEventArgs(TryCast(list(i), TokenEditToken))
edit.OnCustomFilterText(args)
If args.IsValidToken Then
newList.Add(TryCast(list(i), TokenEditToken))
End If
Next i
Return newList
End Function
Public Overrides Sub SetDataSource(ByVal obj As Object)
If (TryCast((TryCast(OwnerEdit, MyTokenEdit)).Properties, RepositoryItemMyTokenEdit)).UseCustomFilter Then
MyBase.SetDataSource(GetCustomFilterSource())
Else
MyBase.SetDataSource(obj)
End If
End Sub
End Class
Public Class MyTokenEditTokenListPopupController
Inherits TokenEditTokenListPopupController
Public Sub New(ByVal edit As TokenEdit)
MyBase.New(edit)
End Sub
Public Overrides Sub UpdateFilter(ByVal filter As String)
If (TryCast((TryCast(OwnerEdit, MyTokenEdit)).Properties, RepositoryItemMyTokenEdit)).UseCustomFilter Then
filter = String.Empty
End If
MyBase.UpdateFilter(filter)
End Sub
End Class
Public Class MyFilterEventArgs
Inherits EventArgs
' Fields...
Private _IsValidToken As Boolean
Private _Token As TokenEditToken
Public Property Token() As TokenEditToken
Get
Return _Token
End Get
Set(ByVal value As TokenEditToken)
_Token = value
End Set
End Property
Public Property IsValidToken() As Boolean
Get
Return _IsValidToken
End Get
Set(ByVal value As Boolean)
_IsValidToken = value
End Set
End Property
Public Sub New(ByVal token As TokenEditToken)
Me.Token = token
IsValidToken = True
End Sub
End Class
End Namespace