Class: Yast::CWMTableClass
- Inherits:
-
Module
- Object
- Module
- Yast::CWMTableClass
- Defined in:
- library/cwm/src/modules/CWMTable.rb
Instance Method Summary collapse
-
#CreateTableDescr(attrib, widget_descr) ⇒ Hash
Get the map with the table widget.
-
#DisableTable(descr) ⇒ Object
Disable whole table.
-
#EnableTable(descr) ⇒ Object
Enable whole table (except buttons that should be grayed according to currently selected table row.
- #getItemId(ter) ⇒ Object
- #main ⇒ Object
-
#TableHandle(descr, key, event_descr) ⇒ Symbol
Handle the event that happened on the table.
-
#TableHandleWrapper(key, event_descr) ⇒ Symbol
Wrapper for TableHandle using CWM::GetProcessedWidget () for getting widget description map.
-
#TableInit(descr, key) ⇒ Object
Initialize the displayed table.
-
#TableInitWrapper(key) ⇒ Object
Wrapper for TableInit using CWM::GetProcessedWidget () for getting widget description map.
-
#updateButtons(descr) ⇒ Object
Enable or disable the Delete and up/down buttons.
-
#ValidateTableAttr(attr) ⇒ Boolean
Validate table options specifyign attributesA.
-
#ValidateTableDescr(key, descr) ⇒ Boolean
Validate the table description.
-
#ValidateValueType(key, value, widget) ⇒ Boolean
Validate type of entry of the option description map Also checks option description maps if present.
Instance Method Details
#CreateTableDescr(attrib, widget_descr) ⇒ Hash
Get the map with the table widget
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 |
# File 'library/cwm/src/modules/CWMTable.rb', line 320 def CreateTableDescr(attrib, ) attrib = deep_copy(attrib) = deep_copy() ValidateTableAttr(attrib) = if Ops.get_boolean(attrib, "add_delete_buttons", true) PushButton(Id(:_tw_add), Opt(:key_F3, :notify), Label.AddButton) else HSpacing(0) end = if Ops.get_boolean(attrib, "edit_button", true) PushButton(Id(:_tw_edit), Opt(:key_F4, :notify), Label.EditButton) else HSpacing(0) end = if Ops.get_boolean(attrib, "add_delete_buttons", true) PushButton(Id(:_tw_delete), Opt(:key_F5, :notify), Label.DeleteButton) else HSpacing(0) end table_header = Ops.get_term(attrib, "header") = if Ops.get_boolean(attrib, "custom_button", false) PushButton( Id(:_tw_custom), Opt(:notify), Ops.get_string(attrib, "custom_button_name", "Custom button") ) else HSpacing(0) end up_down = if Ops.get_boolean(attrib, "up_down_buttons", false) VBox( VStretch(), # push button PushButton(Id(:_tw_up), Opt(:notify), _("&Up")), # push button PushButton(Id(:_tw_down), Opt(:notify), _("&Down")), VStretch() ) else HSpacing(0) end ret = Convert.convert( Builtins.union( { "custom_widget" => HBox( HSpacing(2), VBox( HBox( Table( Id(:_tw_table), Opt(:immediate, :notify, :keepSorting), table_header, [] ), up_down ), HBox( , , , HStretch(), ) ), HSpacing(2) ), "_cwm_attrib" => attrib, "widget" => :custom, "_cwm_do_validate" => fun_ref( method(:ValidateTableDescr), "boolean (string, map <string, any>)" ) }, ), from: "map", to: "map <string, any>" ) if !Builtins.haskey(ret, "init") Ops.set( ret, "init", fun_ref(method(:TableInitWrapper), "void (string)") ) end if !Builtins.haskey(ret, "handle") Ops.set( ret, "handle", fun_ref(method(:TableHandleWrapper), "symbol (string, map)") ) end deep_copy(ret) end |
#DisableTable(descr) ⇒ Object
Disable whole table
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'library/cwm/src/modules/CWMTable.rb', line 265 def DisableTable(descr) descr = deep_copy(descr) UI.ChangeWidget(Id(:_tw_table), :Enabled, false) UI.ChangeWidget(Id(:_tw_edit), :Enabled, false) if Ops.get_boolean(descr, ["_cwm_attrib", "edit_button"], true) if Ops.get_boolean(descr, ["_cwm_attrib", "add_delete_buttons"], true) UI.ChangeWidget(Id(:_tw_delete), :Enabled, false) UI.ChangeWidget(Id(:_tw_add), :Enabled, false) end if Ops.get_boolean(descr, ["_cwm_attrib", "up_down_buttons"], false) UI.ChangeWidget(Id(:_tw_up), :Enabled, false) UI.ChangeWidget(Id(:_tw_down), :Enabled, false) end UI.ChangeWidget(Id(:_tw_custom), :Enabled, false) if Ops.get_boolean(descr, ["_cwm_attrib", "custom_button"], false) nil end |
#EnableTable(descr) ⇒ Object
Enable whole table (except buttons that should be grayed according to currently selected table row
285 286 287 288 289 290 291 292 293 294 |
# File 'library/cwm/src/modules/CWMTable.rb', line 285 def EnableTable(descr) descr = deep_copy(descr) UI.ChangeWidget(Id(:_tw_table), :Enabled, true) UI.ChangeWidget(Id(:_tw_edit), :Enabled, true) if Ops.get_boolean(descr, ["_cwm_attrib", "edit_button"], true) UI.ChangeWidget(Id(:_tw_add), :Enabled, true) if Ops.get_boolean(descr, ["_cwm_attrib", "add_delete_buttons"], true) UI.ChangeWidget(Id(:_tw_custom), :Enabled, true) if Ops.get_boolean(descr, ["_cwm_attrib", "custom_button"], false) TableHandle(descr, "", {}) nil end |
#getItemId(ter) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'library/cwm/src/modules/CWMTable.rb', line 111 def getItemId(ter) ter = deep_copy(ter) args = Builtins.argsof(ter) args = Builtins.filter(args) do |t| next true if Ops.is_term?(t) && Builtins.symbolof(Convert.to_term(t)) == :id false end targs = Convert.convert(args, from: "list", to: "list <term>") if Builtins.size(targs) == 1 return Ops.get( Convert.convert( Builtins.argsof(Ops.get(targs, 0)), from: "list", to: "list <string>" ), 0 ) end nil end |
#main ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'library/cwm/src/modules/CWMTable.rb', line 33 def main Yast.import "UI" textdomain "base" Yast.import "CWM" Yast.import "Label" Yast.import "Mode" Yast.import "Report" end |
#TableHandle(descr, key, event_descr) ⇒ Symbol
Handle the event that happened on the table
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 |
# File 'library/cwm/src/modules/CWMTable.rb', line 194 def TableHandle(descr, key, event_descr) descr = deep_copy(descr) event_descr = deep_copy(event_descr) event_id = Ops.get(event_descr, "ID") attrib = Ops.get_map(descr, "_cwm_attrib", {}) ret = nil id = Convert.to_string(UI.QueryWidget(Id(:_tw_table), :CurrentItem)) item_list = Convert.convert( UI.QueryWidget(Id(:_tw_table), :Items), from: "any", to: "list <term>" ) index = -1 counter = 0 Builtins.foreach(item_list) do |t| index = counter if getItemId(t) == id counter = Ops.add(counter, 1) end if event_id == :_tw_table && (Ops.get_string(event_descr, "EventReason", "") == "Activated" && Ops.get_string(event_descr, "EventType", "") == "WidgetEvent" && UI.WidgetExists(Id(:_tw_edit))) event_id = :_tw_edit end case event_id when :_tw_edit edit_handle = Convert.convert( Ops.get(attrib, "edit"), from: "any", to: "symbol (string, map, integer)" ) ret = edit_handle.call(key, event_descr, index) if !edit_handle.nil? when :_tw_add add_handle = Convert.convert( Ops.get(attrib, "add"), from: "any", to: "symbol (string, map, integer)" ) ret = add_handle.call(key, event_descr, index) if !add_handle.nil? when :_tw_delete delete_handle = Convert.convert( Ops.get(attrib, "delete"), from: "any", to: "symbol (string, map, integer)" ) ret = delete_handle.call(key, event_descr, index) if delete_handle when :_tw_custom custom_handle = Convert.convert( Ops.get(attrib, "custom_handle"), from: "any", to: "symbol (string, map, integer)" ) ret = custom_handle.call(key, event_descr, index) if custom_handle when :_tw_up, :_tw_down up = event_id == :_tw_up updown_handle = Convert.convert( Ops.get(attrib, "updown"), from: "any", to: "symbol (string, map, boolean, integer)" ) if !updown_handle.nil? && !(index == 0 && up) && !(index == Ops.subtract(Builtins.size(item_list), 1) && !up) ret = updown_handle.call(key, event_descr, up, index) UI.ChangeWidget(Id(:_tw_table), :CurrentItem, id) if ret.nil? end end updateButtons(descr) ret end |
#TableHandleWrapper(key, event_descr) ⇒ Symbol
Wrapper for TableHandle using CWM::GetProcessedWidget () for getting widget description map
310 311 312 313 |
# File 'library/cwm/src/modules/CWMTable.rb', line 310 def TableHandleWrapper(key, event_descr) event_descr = deep_copy(event_descr) TableHandle(CWM.GetProcessedWidget, key, event_descr) end |
#TableInit(descr, key) ⇒ Object
Initialize the displayed table
182 183 184 185 186 187 |
# File 'library/cwm/src/modules/CWMTable.rb', line 182 def TableInit(descr, key) descr = deep_copy(descr) Ops.set(descr, "_cwm_key", key) nil end |
#TableInitWrapper(key) ⇒ Object
Wrapper for TableInit using CWM::GetProcessedWidget () for getting widget description map
299 300 301 302 303 |
# File 'library/cwm/src/modules/CWMTable.rb', line 299 def TableInitWrapper(key) TableInit(CWM.GetProcessedWidget, key) nil end |
#updateButtons(descr) ⇒ Object
Enable or disable the Delete and up/down buttons
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 |
# File 'library/cwm/src/modules/CWMTable.rb', line 136 def updateButtons(descr) descr = deep_copy(descr) Builtins.y2milestone("update buttons") id = Convert.to_string(UI.QueryWidget(Id(:_tw_table), :CurrentItem)) item_list = Convert.convert( UI.QueryWidget(Id(:_tw_table), :Items), from: "any", to: "list <term>" ) index = -1 counter = 0 max = Ops.subtract(item_list.nil? ? 0 : Builtins.size(item_list), 1) Builtins.foreach(item_list) do |t| index = counter if getItemId(t) == id counter = Ops.add(counter, 1) end if Ops.get_boolean(descr, ["_cwm_attrib", "up_down_buttons"], false) if Ops.less_than(max, 1) || index == -1 Builtins.y2milestone("short list") UI.ChangeWidget(Id(:_tw_up), :Enabled, false) UI.ChangeWidget(Id(:_tw_down), :Enabled, false) elsif index == 0 Builtins.y2milestone("first item") UI.ChangeWidget(Id(:_tw_up), :Enabled, false) UI.ChangeWidget(Id(:_tw_down), :Enabled, true) elsif index == max Builtins.y2milestone("last item") UI.ChangeWidget(Id(:_tw_up), :Enabled, true) UI.ChangeWidget(Id(:_tw_down), :Enabled, false) else UI.ChangeWidget(Id(:_tw_up), :Enabled, true) UI.ChangeWidget(Id(:_tw_down), :Enabled, true) end else UI.ChangeWidget(Id(:_tw_up), :Enabled, false) UI.ChangeWidget(Id(:_tw_down), :Enabled, false) end nil end |
#ValidateTableAttr(attr) ⇒ Boolean
Validate table options specifyign attributesA
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 |
# File 'library/cwm/src/modules/CWMTable.rb', line 48 def ValidateTableAttr(attr) attr = deep_copy(attr) types = { "add_delete_buttons" => "boolean", "edit_button" => "boolean", "up_down_buttons" => "boolean", "custom_button" => "boolean", "custom_button_name" => "string", "custom_handle" => "symbol(string,map)", "header" => "term", "add" => "symbol(string,map,integer)", "edit" => "symbol(string,map,integer)", "delete" => "symbol(string,map,integer)", "updown" => "symbol(string,map,boolean,integer)" } ret = true Builtins.foreach(attr) do |k, v| type = Ops.get(types, k) if type.nil? Builtins.y2error("Unknown attribute %1", k) ret = false else ret = CWM.ValidateBasicType(v, type) && ret end end ret end |
#ValidateTableDescr(key, descr) ⇒ Boolean
Validate the table description
102 103 104 105 106 107 108 109 |
# File 'library/cwm/src/modules/CWMTable.rb', line 102 def ValidateTableDescr(key, descr) descr = deep_copy(descr) ret = true Builtins.foreach(descr) do |k, v| ret = ValidateValueType(k, v, key) && ret end ret end |
#ValidateValueType(key, value, widget) ⇒ Boolean
Validate type of entry of the option description map Also checks option description maps if present
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'library/cwm/src/modules/CWMTable.rb', line 83 def ValidateValueType(key, value, ) value = deep_copy(value) success = true success = Ops.is_string?(value) if key == "help" if !success Builtins.y2error( "Wrong type of option %1 in description map of %2", key, ) end success end |