Newer
Older
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
from java.text import DecimalFormat
from ch.systemsx.cisd.common.geometry import ConversionUtils
def parseLines(value):
lines = []
if value:
lines = value.strip().split("\n")
return [ line.split("\t") for line in lines ]
def getMaxWidth(lines):
maxWidth = 0
for line in lines:
maxWidth = max(maxWidth, len(line))
return maxWidth
def isControlWell(value):
return value in ["H", "L"]
def isCompoundWell(value):
try:
numberParser = DecimalFormat()
numberParser.parse(value)
return True
except:
return False
def validate(lines):
for line in lines:
for value in line:
normalizedValue = value.strip().upper()
if normalizedValue:
if isControlWell(normalizedValue):
pass
elif isCompoundWell(normalizedValue):
pass
else:
raise ValidationException("Invalid value found in template : " + normalizedValue)
def configureUI():
propValue = ""
if not property.isSpecialValue():
propValue = property.getValue()
lines = parseLines(propValue)
tableBuilder = createTableBuilder()
if lines:
width = getMaxWidth(lines)
header = [ str(item) for item in range(1, width + 1) ]
header.insert(0, " ")
tableBuilder.addFullHeader(header)
for i in range(0, len(lines)):
rowLetterCode = ConversionUtils.translateRowNumberIntoLetterCode(i+1)
row = [ rowLetterCode ] + lines[i]
tableBuilder.addFullRow(row)
property.setOwnTab(True)
uiDesc = property.getUiDescription()
uiDesc.useTableOutput(tableBuilder.getTableModel())
factory = inputWidgetFactory()
editAction = uiDesc.addTableAction("Edit").setDescription("Edit the library template. "
"Copy the template from Excel and paste it in the text are below.")
textArea = factory.createMultilineTextInputField("Text")
textArea.setValue(propValue)
editAction.addInputWidgets([ textArea ])
def updateFromUI(action):
"""in the "Edit" action we simply replace the entire property content"""
if action.getName() == "Edit":
newValue = action.getInputWidgetDescriptions()[0].getValue()
lines = parseLines(newValue)
validate(lines)
if not newValue:
property.setValue("")
else:
property.setValue(newValue)