forked from IDEMSInternational/R-Instat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucrReceiver.vb
714 lines (607 loc) · 32.6 KB
/
ucrReceiver.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
' R- Instat
' Copyright (C) 2015-2017
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
Imports System.Windows.Documents
Imports instat
Imports instat.Translations
Imports RDotNet
Public Class ucrReceiver
Public WithEvents ucrSelector As ucrSelector
Public lstIncludedMetadataProperties As List(Of KeyValuePair(Of String, String()))
Public lstExcludedMetadataProperties As List(Of KeyValuePair(Of String, String()))
Public bFirstLoad As Boolean
Public bFirstShown As Boolean
Public strSelectorHeading As String
Public bUseFilteredData As Boolean = True
Public bDropUnusedFilterLevels As Boolean = False
Public bTypeSet As Boolean
Protected strType As String
Public bExcludeFromSelector As Boolean = False
Public Event SelectionChanged(sender As Object, e As EventArgs)
Public WithEvents frmParent As Form
Public bRemoveLabels As Boolean = False
Public bAsReceiver As Boolean = True
Public strDatabaseQuery As String = ""
Private strPrvNcFilePath As String = ""
'Should the receiver attempt to autofill items based on lstIncludedAutoFillProperties?
Public bAutoFill As Boolean = False
Public lstIncludedAutoFillProperties As Dictionary(Of String, String())
Public bAddParameterIfEmpty As Boolean = False
'If the control is used to set a parameter that is a string i.e. column = "ID"
Protected bParameterIsString As Boolean = False
'If the control is used to set a parameter that is an RFunction i.e. x = InstatDataObject$get_columns_from_data()
Protected bParameterIsRFunction As Boolean = False
'The name of the parameter which contains the items in the get instat object method (depends on the type of items in the receiver)
Protected strItemsParameterNameInRFunction As String = "col_names"
'Name of the data name parameter in the get instat object method (depends on the type of items in the receiver)
Protected strDataFrameParameterNameInRFunction As String = "data_name"
'Should quotes be used when bParameterIsString = False
Public bWithQuotes As Boolean = True
'Should columns be forced as a data frame object when bParameterIsRFunction = True
Public bForceAsDataFrame As Boolean = False
' If True then this receiver can only contain a column from the selector's primary data frame
' and this receiver can set the selector's primary data frame (when current receiver), resetting all other receivers
Public bAttachedToPrimaryDataFrame As Boolean = True
' If not attached to primary data frame, should only data frames linked to the primary data frame be shown.
Public bOnlyLinkedToPrimaryDataFrames As Boolean = True
' When calling GetVariableNames() this is the R package & function name the variables will be inside
' Only currently used in Multiple receiver but defined here as needed in general method SetControlValue()
' for ExtractItemsFromRList()
Protected strVariablesListPackageName As String = ""
Protected strVariablesListFunctionName As String = "c"
' Set to True if GetVariableNames() should always return an R list (using function above)
' Even when only one variable.
' Currently only implemented for multiple receiver.
Public bForceVariablesAsList As Boolean = False
'used by the selector to autoswitch from the current receiver
Public bAutoSwitchFromReceiver As Boolean = False
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
lstIncludedMetadataProperties = New List(Of KeyValuePair(Of String, String()))
lstExcludedMetadataProperties = New List(Of KeyValuePair(Of String, String()))
bFirstLoad = True
lstIncludedAutoFillProperties = New Dictionary(Of String, String())
bFirstShown = True
bTypeSet = False
strSelectorHeading = "Variables"
strType = "column"
bUpdateRCodeFromControl = True
End Sub
Public Overridable Sub AddSelectedSelectorVariables()
End Sub
Public Overridable Sub RemoveSelected()
If IsCurrentReceiver() Then
Selector.LoadList()
End If
End Sub
Private Function IsCurrentReceiver() As Boolean
Return Selector IsNot Nothing AndAlso Selector.CurrentReceiver IsNot Nothing AndAlso Selector.CurrentReceiver.Equals(Me)
End Function
Public Overridable Sub Remove(strItems As String())
End Sub
Public Overridable Sub Clear()
End Sub
Public Overridable Function IsEmpty() As Boolean
Return True
End Function
Public Overridable Sub SetColor()
End Sub
Public Overridable Sub RemoveColor()
End Sub
'This refers to the selector list of columns
Public Overridable Sub RemoveAnyVariablesNotInSelector()
End Sub
Public Property strNcFilePath As String
Get
Return strPrvNcFilePath
End Get
Set(strFilePath As String)
strPrvNcFilePath = strFilePath
If IsCurrentReceiver() Then
Selector.LoadList()
End If
End Set
End Property
Public Overridable Function GetVariables(Optional bForceAsDataFrame As Boolean = False) As RFunction
Return New RFunction
End Function
Public Overridable Function GetVariableNames(Optional bWithQuotes As Boolean = True) As String
Return ""
End Function
Public Overridable Function GetVariableNamesList(Optional bWithQuotes As Boolean = True, Optional strQuotes As String = Chr(34)) As String()
Return Nothing
End Function
Public Overridable Sub SetMeAsReceiver()
If Selector IsNot Nothing Then
Selector.SetCurrentReceiver(Me)
End If
End Sub
Private Sub ucrReceiver_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstLoad Then
frmParent = ParentForm
'Remove this line so that single/multiple code can run things on first load as well
'We never have a receiver not as a single or multiple
'bFirstLoad = False
End If
End Sub
'TODO make this function available throughout project
Public Function GetListAsRString(lstStrings As List(Of String), Optional bWithQuotes As Boolean = True) As String
Dim strTemp As String = ""
Dim i As Integer
If lstStrings.Count = 1 Then
If bWithQuotes Then
strTemp = Chr(34) & lstStrings.Item(0) & Chr(34)
Else
strTemp = lstStrings.Item(0)
End If
ElseIf lstStrings.Count > 1 Then
strTemp = "c" & "("
For i = 0 To lstStrings.Count - 1
If i > 0 Then
strTemp = strTemp & ","
End If
If lstStrings.Item(i) <> "" Then
If bWithQuotes Then
strTemp = strTemp & Chr(34) & lstStrings.Item(i) & Chr(34)
Else
strTemp = strTemp & lstStrings.Item(i)
End If
End If
Next
strTemp = strTemp & ")"
End If
Return strTemp
End Function
Private Sub ucrReceiver_Enter(sender As Object, e As EventArgs) Handles Me.Enter
SetMeAsReceiver()
End Sub
Public Event ValueChanged(ByVal sender As Object, ByVal e As EventArgs)
Public Sub OnValueChanged(ByVal sender As Object, ByVal e As EventArgs)
RaiseEvent ValueChanged(sender, e)
OnControlContentsChanged()
OnControlValueChanged()
End Sub
' If bStrict = True then only columns of the type specific will be included
' If bStict = False then a less strict condition will be made for which columns are included, depending on the type
' as specified below.
' SetDataType("numeric", False) will exclude factor and character columns (so numeric, logical, Date etc. will be included)
' SetDataType("factor", False) will include factor and logical columns
Public Sub SetDataType(strTemp As String, Optional bStrict As Boolean = False)
If Not bStrict Then
If strTemp = "numeric" Then
AddExcludedMetadataProperty("class", {Chr(34) & "factor" & Chr(34), Chr(34) & "character" & Chr(34)})
ElseIf strTemp = "factor" Then
AddIncludedMetadataProperty("class", {Chr(34) & "factor" & Chr(34), Chr(34) & "logical" & Chr(34)})
Else
AddIncludedMetadataProperty("class", {Chr(34) & strTemp & Chr(34)})
End If
Else
AddIncludedMetadataProperty("class", {Chr(34) & strTemp & Chr(34)})
End If
End Sub
'bStrict used as described in SetDataType.
'Currently only checks if strInclude has exactly one item.
Public Overridable Sub SetIncludedDataTypes(strInclude As String(), Optional bStrict As Boolean = False)
Dim strTypes(strInclude.Count - 1) As String
Array.Copy(strInclude, strTypes, strInclude.Length)
'If the two previous lines where not added, the modification of value performed on strTypes was immediately performed on strInclude, then the argument passed into the function such as clsCurrGeom.clsAesParameters(i).strIncludedDataTypes in ucrGeomListWithAes.SetParameters would have been edited (i.e. quotes would have been added to the types names in the strIncludedDataTypes of the i'th AesParameter of the current Geom...), which we don't want !
For i = 0 To strInclude.Count - 1
strTypes(i) = Chr(34) & strInclude(i) & Chr(34)
Next
If Not bStrict Then
If strTypes.Count = 1 Then
If strTypes(0) = Chr(34) & "numeric" & Chr(34) Then
AddExcludedMetadataProperty("class", {Chr(34) & "factor" & Chr(34), Chr(34) & "character" & Chr(34)})
ElseIf strTypes(0) = Chr(34) & "factor" & Chr(34) Then
AddIncludedMetadataProperty("class", {Chr(34) & "factor" & Chr(34), Chr(34) & "logical" & Chr(34)})
Else
AddIncludedMetadataProperty("class", strTypes)
End If
Else
AddIncludedMetadataProperty("class", strTypes)
End If
Else
AddIncludedMetadataProperty("class", strTypes)
End If
End Sub
Public Overridable Sub SetExcludedDataTypes(strExclude As String())
Dim strTypes(strExclude.Count - 1) As String
Array.Copy(strExclude, strTypes, strExclude.Length)
'If the two previous lines where not added, the modification of value performed on strTypes was immediately performed on strInclude, then the argument passed into the function such as clsCurrGeom.clsAesParameters(i).strExcludedDataTypes in ucrGeomListWithAes.SetParameters would have been edited (i.e. quotes would have been added to the types names in the strExcludedDataTypes of the i'th AesParameter of the current Geom...), which we don't want !
For i = 0 To strExclude.Count - 1
strTypes(i) = Chr(34) & strTypes(i) & Chr(34)
Next
AddExcludedMetadataProperty("class", strTypes)
End Sub
Public Sub AddIncludedMetadataProperty(strProperty As String, strInclude As String())
Dim iIncludeIndex As Integer
'Dim iExcludeIndex As Integer
Dim kvpIncludeProperty As KeyValuePair(Of String, String())
If strProperty = "class" AndAlso strInclude.Contains(Chr(34) & "factor" & Chr(34)) Then
Array.Resize(strInclude, strInclude.Length + 1)
' WARNING: This is dependent on the way the metadata is displayed by the Instat object
' If this changes in Instat object, ordered factors will not be displayed
' TODO: Make this solid - should somehow use is.factor() in R
strInclude(strInclude.Length - 1) = Chr(34) & "ordered,factor" & Chr(34)
End If
kvpIncludeProperty = New KeyValuePair(Of String, String())(strProperty, strInclude)
iIncludeIndex = lstIncludedMetadataProperties.FindIndex(Function(x) x.Key = strProperty)
If iIncludeIndex <> -1 Then
lstIncludedMetadataProperties(iIncludeIndex) = kvpIncludeProperty
Else
lstIncludedMetadataProperties.Add(kvpIncludeProperty)
End If
'Removes from other list
'iExcludeIndex = lstExcludedMetadataProperties.FindIndex(Function(x) x.Key = strProperty)
'If iExcludeIndex <> -1 Then
' lstExcludedMetadataProperties.RemoveAt(iExcludeIndex)
'End If
If IsCurrentReceiver() Then
Selector.LoadList()
End If
End Sub
Public Sub RemoveIncludedMetadataProperty(strProperty As String)
Dim iIncludeIndex As Integer
iIncludeIndex = lstIncludedMetadataProperties.FindIndex(Function(x) x.Key = strProperty)
If iIncludeIndex <> -1 Then
lstIncludedMetadataProperties.RemoveAt(iIncludeIndex)
End If
If IsCurrentReceiver() Then
Selector.LoadList()
End If
End Sub
Public Sub RemoveExcludedMetadataProperty(strProperty As String)
Dim iIncludeIndex As Integer
iIncludeIndex = lstExcludedMetadataProperties.FindIndex(Function(x) x.Key = strProperty)
If iIncludeIndex <> -1 Then
lstExcludedMetadataProperties.RemoveAt(iIncludeIndex)
End If
If IsCurrentReceiver() Then
Selector.LoadList()
End If
End Sub
Public Sub AddExcludedMetadataProperty(strProperty As String, strExclude As String())
'Dim iIncludeIndex As Integer
Dim iExcludeIndex As Integer
Dim kvpExcludeProperty As KeyValuePair(Of String, String())
If strProperty = "class" AndAlso strExclude.Contains(Chr(34) & "factor" & Chr(34)) Then
Array.Resize(strExclude, strExclude.Length + 1)
' WARNING: This is dependent on the way the metadata is displayed by the Instat object
' If this changes in Instat object, ordered factors will not be displayed
' TODO: Make this solid - should somehow use is.factor() in R
strExclude(strExclude.Length - 1) = Chr(34) & "ordered,factor" & Chr(34)
End If
kvpExcludeProperty = New KeyValuePair(Of String, String())(strProperty, strExclude)
iExcludeIndex = lstExcludedMetadataProperties.FindIndex(Function(x) x.Key = strProperty)
If iExcludeIndex <> -1 Then
lstExcludedMetadataProperties(iExcludeIndex) = kvpExcludeProperty
Else
lstExcludedMetadataProperties.Add(kvpExcludeProperty)
End If
'Removes from other list
'iIncludeIndex = lstIncludedMetadataProperties.FindIndex(Function(x) x.Key = strProperty)
'If iIncludeIndex <> -1 Then
' lstIncludedMetadataProperties.RemoveAt(iIncludeIndex)
'End If
If IsCurrentReceiver() Then
Selector.LoadList()
End If
End Sub
'TODO if needed create SetExcludedAutoFillProperties
Public Sub SetIncludedAutoFillProperties(lstNewIncludedAutoFillProperties As Dictionary(Of String, String()))
lstIncludedAutoFillProperties = lstNewIncludedAutoFillProperties
End Sub
Protected Overridable Sub Selector_ResetAll() Handles ucrSelector.ResetReceivers
Clear()
CheckAutoFill()
End Sub
Private Sub ucrSelector_DataFrameChanged() Handles ucrSelector.DataFrameChanged
'TODO This is possibly an expensive check, there may be more efficient ways of checking if this is the current receiver
If ucrSelector IsNot Nothing AndAlso ucrSelector.CurrentReceiver IsNot Nothing AndAlso (ucrSelector.CurrentReceiver.bAttachedToPrimaryDataFrame OrElse ucrSelector.CurrentReceiver.Equals(Me)) Then
Selector_ResetAll()
End If
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
If keyData = (Keys.Shift + Keys.Tab) Then
Selector.Focus()
Return True
Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End Function
Public Function GetItemType() As String
Return strType
End Function
Public Sub SetItemType(strNewType As String)
strType = strNewType
Select Case strType
Case "column"
strItemsParameterNameInRFunction = "col_names"
Case "dataframe"
strItemsParameterNameInRFunction = "data_name"
Case "metadata"
'TODO what should this be?
strItemsParameterNameInRFunction = ""
Case "object",
RObjectTypeLabel.Graph,
RObjectTypeLabel.Model,
RObjectTypeLabel.Table,
RObjectTypeLabel.Summary,
RObjectTypeLabel.StructureLabel
strItemsParameterNameInRFunction = "object_name"
Case "filter"
strItemsParameterNameInRFunction = "filter_name"
Case "column_selection"
strItemsParameterNameInRFunction = "column_selection_name"
Case "link"
strItemsParameterNameInRFunction = "link_name"
Case "calculation"
strItemsParameterNameInRFunction = "calculation_name"
Case "scalar"
strItemsParameterNameInRFunction = "scalar_name"
End Select
If IsCurrentReceiver() Then
Selector.LoadList()
End If
bTypeSet = True
End Sub
Public Overridable Sub Add(strItem As String, Optional strDataFrame As String = "", Optional bFixReceiver As Boolean = False)
'SetMeAsReceiver()
'For i = 0 To Selector.lstAvailableVariable.Items.Count - 1
' If Selector.lstAvailableVariable.Items(i).Text = strItem Then
' Selector.lstAvailableVariable.SelectedItems.Clear()
' Selector.lstAvailableVariable.Items(i).Selected = True
' AddSelected()
' Selector.lstAvailableVariable.SelectedItems.Clear()
' Exit For
' End If
'Next
End Sub
Public Sub OnSelectionChanged()
Dim sender As New Object
Dim e As New EventArgs
RaiseEvent SelectionChanged(sender, e)
OnControlValueChanged()
End Sub
Protected Overrides Sub SetControlValue()
Dim clsTempDataParameter As RParameter
Dim lstCurrentVariables As String() = Nothing
Dim clsTempParameter As RParameter
Dim strTempDataName As String = ""
clsTempParameter = GetParameter()
If clsTempParameter IsNot Nothing Then
If bChangeParameterValue Then
If bParameterIsString AndAlso clsTempParameter.bIsString Then
If (strValuesToIgnore IsNot Nothing AndAlso strValuesToIgnore.Contains(clsTempParameter.strArgumentValue)) OrElse Not String.IsNullOrEmpty(clsTempParameter.strArgumentValue) Then
lstCurrentVariables = ExtractItemsFromRList(clsTempParameter.strArgumentValue, strPackageName:=strVariablesListPackageName, strFunctionName:=strVariablesListFunctionName)
End If
'TODO how to recover the data frame name in this case
ElseIf bParameterIsRFunction AndAlso clsTempParameter.bIsFunction Then
clsTempDataParameter = clsTempParameter.clsArgumentCodeStructure.GetParameter(strItemsParameterNameInRFunction)
If clsTempDataParameter IsNot Nothing Then
lstCurrentVariables = ExtractItemsFromRList(clsTempParameter.clsArgumentCodeStructure.GetParameter(strItemsParameterNameInRFunction).strArgumentValue, strPackageName:="", strFunctionName:="c")
End If
'TODO Should this the same for other item types?
If strType = "column" Then
clsTempDataParameter = clsTempParameter.clsArgumentCodeStructure.GetParameter(strDataFrameParameterNameInRFunction)
If clsTempDataParameter IsNot Nothing Then
strTempDataName = clsTempParameter.clsArgumentCodeStructure.GetParameter(strDataFrameParameterNameInRFunction).strArgumentValue.Trim(Chr(34))
End If
End If
End If
Clear()
If lstCurrentVariables IsNot Nothing Then
strTempDataName = If(Selector?.strCurrentDataFrame?.Trim() <> "", Selector.strCurrentDataFrame, "data_names")
If TypeOf Me Is ucrReceiverMultiple Then
'TODO This only works if the selector is updated before receivers and dialog only uses one data frame!
' Needs to change eventually.
Dim lstItems As New List(Of KeyValuePair(Of String, String))
For Each strTemp As String In lstCurrentVariables
lstItems.Add(New KeyValuePair(Of String, String)(strTempDataName, strTemp))
Next
DirectCast(Me, ucrReceiverMultiple).AddMultiple(lstItems)
'TODO. In PR #8605, this subroutine was found to also be called in the selector control when LoadList is called (CurrentReceiver.RemoveAnyVariablesNotInSelector()).
'This can lead to slow perfomance in dialogs when it comes to wide datasets
RemoveAnyVariablesNotInSelector() 'needed due to the Autofill option
Else
For Each strTemp As String In lstCurrentVariables
'TODO This only works if the selector is updated before receivers and dialog only uses one data frame!
' Needs to change eventually.
'TODO. This subroutine call also makes the single receiver automatically clear deleted columns when dialogs are reopened
'However, it does not clear output objects and other data objects. What causes clearing of such objects is
'when CurrentReceiver.RemoveAnyVariablesNotInSelector() is called in the LoadList() of selector control
Add(strTemp, strTempDataName)
Next
End If
End If
End If
End If
End Sub
Public Overrides Sub UpdateParameter(clsTempParam As RParameter)
If clsTempParam Is Nothing Then
clsTempParam = New RParameter
End If
'Could need bParameterIsString and bParameterIsRFunction to be properties of RParameter if two functions need string/function
If bParameterIsString Then
'TODO this currently only works with one value to ignore. Also may need option not to set parameter value to strValuesToIgnore
' although this currently can be done with bAddParameterIfEmpty = True
If IsEmpty() AndAlso strValuesToIgnore IsNot Nothing AndAlso strValuesToIgnore.Count = 1 Then
clsTempParam.SetArgumentValue(strValuesToIgnore(0))
Else
clsTempParam.SetArgumentValue(GetVariableNames(bWithQuotes))
End If
ElseIf bParameterIsRFunction Then
clsTempParam.SetArgument(GetVariables(bForceAsDataFrame))
End If
End Sub
Public Overridable Sub SetParameterIsString()
bParameterIsString = True
bParameterIsRFunction = False
UpdateAllParameters()
End Sub
Public Overridable Sub SetParameterIsRFunction()
bParameterIsRFunction = True
bParameterIsString = False
UpdateAllParameters()
End Sub
Public Overrides Function IsRDefault() As Boolean
If bAddParameterIfEmpty Then
Return False
Else
Return IsEmpty()
End If
End Function
Public Sub SetClimaticType(strTemp As String)
Dim dctTemp As New Dictionary(Of String, String())
' "element" is a special case since it is a different metadata property.
If strTemp = "element" Then
dctTemp.Add("Is_Element", {"TRUE"})
SetIncludedAutoFillProperties(dctTemp)
Else
SetClimaticType({strTemp})
End If
End Sub
Public Sub SetClimaticType(enumTypes As IEnumerable(Of String))
Dim dctTemp As New Dictionary(Of String, String())
Dim arrTypes() As String = enumTypes.ToArray
For i As Integer = 0 To arrTypes.Count - 1
arrTypes(i) = Chr(34) & arrTypes(i) & Chr(34)
Next
dctTemp.Add("Climatic_Type", arrTypes)
SetIncludedAutoFillProperties(dctTemp)
End Sub
Public Sub SetOptionsByContextType(strSingleType As String, Optional strQuotes As String = Chr(34))
AddIncludedMetadataProperty("O_by_C_Type", {strQuotes & strSingleType & strQuotes})
End Sub
Public Sub SetOptionsByContextTypes(strTemp() As String)
AddIncludedMetadataProperty("O_by_C_Type", strTemp)
End Sub
Public Sub SetOptionsByContextTypesAllMeasurements()
AddIncludedMetadataProperty("O_by_C_Type", {Chr(34) & "measurement_1" & Chr(34), Chr(34) & "measurement_other" & Chr(34)})
End Sub
Public Sub SetOptionsByContextTypesAllIDs()
AddIncludedMetadataProperty("O_by_C_Type", {Chr(34) & "id_1" & Chr(34), Chr(34) & "id_other" & Chr(34)})
End Sub
Public Sub SetOptionsByContextTypesAllContexts()
AddIncludedMetadataProperty("O_by_C_Type", {Chr(34) & "context_1" & Chr(34), Chr(34) & "context_2" & Chr(34), Chr(34) & "context_3" & Chr(34), Chr(34) & "context_4" & Chr(34), Chr(34) & "context_other" & Chr(34)})
End Sub
Public Sub SetOptionsByContextTypesAllOptions()
AddIncludedMetadataProperty("O_by_C_Type", {Chr(34) & "option_1" & Chr(34), Chr(34) & "option_other" & Chr(34)})
End Sub
Public Sub SetOptionsByContextTypesAllBlockings()
AddIncludedMetadataProperty("O_by_C_Type", {Chr(34) & "blocking_1" & Chr(34), Chr(34) & "blocking_other" & Chr(34)})
End Sub
Public Sub SetOptionsByContextTypesAllOptionsContextsBlockings()
AddIncludedMetadataProperty("O_by_C_Type", {Chr(34) & "option_1" & Chr(34), Chr(34) & "option_other" & Chr(34), Chr(34) & "context_1" & Chr(34), Chr(34) & "context_2" & Chr(34), Chr(34) & "context_3" & Chr(34), Chr(34) & "context_4" & Chr(34), Chr(34) & "context_other" & Chr(34), Chr(34) & "blocking_1" & Chr(34), Chr(34) & "blocking_other" & Chr(34)})
End Sub
Public Overridable Property Selector As ucrSelector
Get
Return ucrSelector
End Get
Set(ucrNewSelector As ucrSelector)
'remove the receiver from the former selector
If ucrSelector IsNot Nothing Then
ucrSelector.RemoveReceiver(Me)
End If
ucrSelector = ucrNewSelector
'add the receiver to the new selector
If ucrSelector IsNot Nothing Then
ucrSelector.AddReceiver(Me)
End If
End Set
End Property
Protected Overrides Sub ResetControlValue()
Clear()
End Sub
Public Overridable Sub SetTextColour(clrNew As Color)
End Sub
Public Overridable Function GetItemsDataFrames() As List(Of String)
Return New List(Of String)
End Function
Public Sub AddItemsWithMetadataProperty(strCurrentDataFrame As String, strProperty As String, strValues As String())
If Selector IsNot Nothing Then
SetMeAsReceiver()
frmMain.clsRLink.SelectColumnsWithMetadataProperty(Me, strCurrentDataFrame, strProperty, strValues)
End If
End Sub
Public Sub SetVariablesListPackageName(strNewVariablesListPackageName As String)
strVariablesListPackageName = strNewVariablesListPackageName
End Sub
Public Sub SetVariablesListFunctionName(strNewVariablesListFunctionName As String)
strVariablesListFunctionName = strNewVariablesListFunctionName
End Sub
Public Overridable Sub SetSelectorHeading(strNewHeading As String)
strSelectorHeading = strNewHeading
End Sub
Private Sub Selector_DataFrameChanged() Handles ucrSelector.DataFrameChanged
CheckAutoFill()
End Sub
Public Overridable Sub CheckAutoFill()
Dim clsGetItems As New RFunction
Dim clsIncludeList As New RFunction
Dim expItems As SymbolicExpression
Dim chrColumns As CharacterVector
'TODO When there are receivers with bAttachedToPrimaryDataFrame = False
' don't always want to autofill when dataframe is changed.
' Something like AndAlso Selector.CurrentReceiver.bAttachedToPrimaryDataFrame
' except always want to autofill when resetting regardless of current receiver
If bAutoFill AndAlso Selector IsNot Nothing AndAlso (Selector.CurrentReceiver Is Nothing OrElse Selector.CurrentReceiver.bAttachedToPrimaryDataFrame) Then
' If no autofill properties then simply check if one item is in the selector
' (may need to modify behaviour for multiple receivers)
If lstIncludedAutoFillProperties.Count = 0 Then
SetMeAsReceiver()
If Selector.lstAvailableVariable.Items.Count = 1 Then
Add(Selector.lstAvailableVariable.Items(0).Text, Selector.strCurrentDataFrame)
End If
ElseIf lstIncludedAutoFillProperties.Count > 0 AndAlso ((bTypeSet AndAlso GetItemType() = "column") OrElse Selector.GetItemType() = "column") Then
SetMeAsReceiver()
clsGetItems.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_column_names")
clsIncludeList.SetRCommand("list")
For Each kvpInclude In lstIncludedAutoFillProperties
clsIncludeList.AddParameter(kvpInclude.Key, GetListAsRString(kvpInclude.Value.ToList(), bWithQuotes:=False))
Next
clsGetItems.AddParameter("include", clsRFunctionParameter:=clsIncludeList)
clsGetItems.AddParameter("data_name", Chr(34) & Selector.strCurrentDataFrame & Chr(34))
expItems = frmMain.clsRLink.RunInternalScriptGetValue(clsGetItems.ToScript(), bSilent:=True)
If expItems IsNot Nothing AndAlso Not expItems.Type = Internals.SymbolicExpressionType.Null Then
chrColumns = expItems.AsCharacter
' ucrReceiverSingle only autofills if there is exactly one valid item.
If TypeOf Me Is ucrReceiverSingle Then
If chrColumns.Count = 1 Then
For Each lviTempVariable As ListViewItem In Selector.lstAvailableVariable.Items
If lviTempVariable.Text = chrColumns(0) Then
Add(lviTempVariable.Text, Selector.strCurrentDataFrame)
Exit For
End If
Next
End If
' ucrReceiverMultipe autofills all valid items.
ElseIf TypeOf Me Is ucrReceiverMultiple Then
For Each lviTempVariable As ListViewItem In Selector.lstAvailableVariable.Items
For Each chrCol As String In chrColumns
If lviTempVariable.Text = chrCol Then
Add(lviTempVariable.Text, Selector.strCurrentDataFrame)
Exit For
End If
Next
Next
End If
End If
End If
End If
End Sub
End Class