forked from adlnet-archive/LR-Publisher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CsvToLrMapRow.cs
77 lines (62 loc) · 1.95 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
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 string Key
{
get { return this.lbl_ResourceDataField.Text; }
}
private bool _isConstant;
public bool IsConstant { get { return _isConstant; } }
private bool _isSerializeToRow;
public bool IsSerializeToRow { get { return _isSerializeToRow; } }
private IEnumerable _options;
public string DropDownValue
{
get
{
//TODO: improve exception throwing/handling for empty columns
if(ColumnOptionsComboBox.Active == 0 || ColumnOptionsComboBox.Active > _options.Cast<string>().Count() - 3)
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);
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
{
_isSerializeToRow = ColumnOptionsComboBox.ActiveText == ROW_AS_CSV_TEXT;
if (CustomValueEntry.Visible)
CustomValueEntry.Visible = false;
_isConstant = false;
}
}
}