-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCsvToLrMapRow.cs
111 lines (90 loc) · 3.24 KB
/
CsvToLrMapRow.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
using System;
using System.Collections;
using System.Linq;
using Gtk;
[System.ComponentModel.ToolboxItem(true)]
public partial class CsvToLrMapRow : Gtk.Bin
{
public const string NO_VAL_TEXT = "Select Column...";
public const string CONSTANT_VAL_TEXT = "<Constant Value>";
public const string ROW_AS_CSV_TEXT = "<Entire Row (as JSON)>";
public readonly string [] RESOURCE_DATA_TYPES = {"resource", "paradata", "metadata", "assertion"};
public readonly string [] IDENTITY_SUBMITTER_TYPES = {"anonymous", "user", "agent"};
public readonly string [] PAYLOAD_PLACEMENTS = {"inline", "linked", "attached"};
public string Key
{
get { return this.lbl_ResourceDataField.Text; }
}
private bool _isConstant;
public bool IsConstant { get { return _isConstant; } }
private bool _hasConstantValues;
public bool HasConstantValues { get { return _hasConstantValues; } }
private bool _isSerializeToRow;
public bool IsSerializeToRow { get { return _isSerializeToRow; } }
private IEnumerable _options;
public string DropDownValue
{
get
{
if (ColumnOptionsComboBox.Active == 0)
return null;
return ColumnOptionsComboBox.ActiveText;
}
}
public string ConstantValue
{
get { return this.CustomValueEntry.Text; }
}
public CsvToLrMapRow (IEnumerable options, string resourceDataDescriptionField)
{
this.Build ();
ColumnOptionsComboBox.AppendText(NO_VAL_TEXT);
//Add static options for fields that only have certain inputs
if (resourceDataDescriptionField.Equals("*resource_data_type")){
foreach(string type in RESOURCE_DATA_TYPES)
this.ColumnOptionsComboBox.AppendText(type);
_options = RESOURCE_DATA_TYPES;
}
else if(resourceDataDescriptionField.Equals("*identity.submitter_type")){
foreach(string type in IDENTITY_SUBMITTER_TYPES)
this.ColumnOptionsComboBox.AppendText(type);
_options = IDENTITY_SUBMITTER_TYPES;
}
else if(resourceDataDescriptionField.Equals("*payload_placement")){
foreach(string placement in PAYLOAD_PLACEMENTS)
this.ColumnOptionsComboBox.AppendText(placement);
_options = PAYLOAD_PLACEMENTS;
}
else{
foreach(string option in options)
this.ColumnOptionsComboBox.AppendText(option);
_options = options;
ColumnOptionsComboBox.AppendText(CONSTANT_VAL_TEXT);
ColumnOptionsComboBox.AppendText(ROW_AS_CSV_TEXT);
}
ColumnOptionsComboBox.Active = 0;
this.lbl_ResourceDataField.Text = resourceDataDescriptionField;
CustomValueEntry.Shown += OnColumnSelectionChanged;
}
protected void OnColumnSelectionChanged (object sender, System.EventArgs e)
{
if (ColumnOptionsComboBox.ActiveText == CONSTANT_VAL_TEXT)
{
CustomValueEntry.Visible = true;
_isConstant = true;
}
else if(Key.Equals("*resource_data_type") || Key.Equals("*identity.submitter_type") || Key.Equals("*payload_placement"))
{
if (CustomValueEntry.Visible)
CustomValueEntry.Visible = false;
_hasConstantValues = true;
}
else
{
_isSerializeToRow = ColumnOptionsComboBox.ActiveText == ROW_AS_CSV_TEXT;
if (CustomValueEntry.Visible)
CustomValueEntry.Visible = false;
_isConstant = false;
}
}
}