Adobe 65007312 Programming Guide - Page 173

Transforming data, Create multiple bindings to one key

Page 173 highlights

CHAPTER 9: Getting Started: A Tutorial Example Transforming data 173 Transforming data The very simple binding we created for the checkbox allows you to set and clear a data value by selected or deselecting the checkbox button. To show a more complex relationship between the UI and the data, we will add two radio buttons and a static text field. All three are bound to the same data key, but with transformations such that when you select one radio button, it deselects the other, and updates the text to show which is selected. Create multiple bindings to one key Use these step to populate a custom dialog with this new set of controls and create the data transformation. 1. Edit the LibraryMenuItem.lua file to create a new function, showCustomDialogWithTranform(): function MyHWLibraryItem.showCustomDialogWithTransform() -- body of function end 2. Within this function, make the function-context call you need for the property table: LrFunctionContext.callWithContext( "showCustomDialogWithTransform", function( context ) -- body of function end ) 3. In this context, create the observable table, and add a property named selectedButton, with an initial value: -- body of function local props = LrBinding.makePropertyTable( context ) props.selectedButton = "one" -- new property with initial value -- create view hierarchy 4. Now we will create a new view hierarchy for the dialog, whose controls are bound to this table. This is a slightly more complex hierarchy, where the root node is a column container, which has two rows. The rows contain the controls, two radio buttons and a text box: -- create view hierarchy local f = LrView.osFactory() -- get the view factory object local c = f:column { bind_to_object = props, -- all controls bound to our table spacing = f:control_spacing(), -- default spacing for the child rows f:row { -- first row contains radio buttons spacing = f:control_spacing(), -- use default spacing f:column { f:radio_button { title = "Button one", checked_value = "one", -- when control value matches this, -- the button is checked -- add value binding in next step },

  • 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

C
HAPTER
9: Getting Started: A Tutorial Example
Transforming data
173
Transforming data
The very simple binding we created for the checkbox allows you to set and clear a data value by selected
or deselecting the checkbox button. To show a more complex relationship between the UI and the data,
we will add two radio buttons and a static text field. All three are bound to the same data key, but with
transformations such that when you select one radio button, it deselects the other, and updates the text to
show which is selected.
Create multiple bindings to one key
Use these step to populate a custom dialog with this new set of controls and create the data
transformation.
1.
Edit the
LibraryMenuItem.lua
file to create a new function,
showCustomDialogWithTranform()
:
function MyHWLibraryItem.showCustomDialogWithTransform()
-- body of function
end
2.
Within this function, make the function-context call you need for the property table:
LrFunctionContext.callWithContext( "showCustomDialogWithTransform",
function( context )
-- body of function
end )
3.
In this context, create the observable table, and add a property named
selectedButton
, with an
initial value:
-- body of function
local props = LrBinding.makePropertyTable( context )
props.selectedButton = "one" -- new property with initial value
-- create view hierarchy
4.
Now we will create a new view hierarchy for the dialog, whose controls are bound to this table. This is
a slightly more complex hierarchy, where the root node is a column container, which has two rows.
The rows contain the controls, two radio buttons and a text box:
-- create view hierarchy
local f = LrView.osFactory() -- get the view factory object
local c = f:column {
bind_to_object = props, -- all controls bound to our table
spacing = f:control_spacing(), -- default spacing for the child rows
f:row { -- first row contains radio buttons
spacing = f:control_spacing(), -- use default spacing
f:column {
f:radio_button {
title = "Button one",
checked_value = "one", -- when control value matches this,
-- the button is checked
-- add value binding in next step
},