Class: Yast::TablePopupClass
- Inherits:
-
Module
- Object
- Module
- Yast::TablePopupClass
- Defined in:
- library/cwm/src/modules/TablePopup.rb
Instance Method Summary collapse
-
#askForNewOption(possible, editable, descr) ⇒ String
Displaye popup for option to edit choosing.
-
#CreateTableDescr(attrib, widget_descr) ⇒ Hash
Get the map with the table widget.
-
#deleteTableItem(opt_id, descr) ⇒ Boolean
Delete an item from the table Just a wrapper for module-specific function.
-
#DisableTable(descr) ⇒ Object
Disable whole table.
-
#EnableTable(descr) ⇒ Object
Enable whole table (except buttons that should be grayed according to currently selected table row.
-
#getIdList(descr) ⇒ Array
Get list of IDs of entries of the table.
-
#id2key(descr, opt_id) ⇒ String
Get option key from the option id global only because of testsuites.
-
#key2descr(descr, opt_key) ⇒ Hash
Get option description map from the key global only because of testsuites.
- #main ⇒ Object
-
#moveTableItem(opt_id, descr, dir) ⇒ Object
Move table item up or down Just a wrapper for module-specific function.
-
#singleOptionEditPopup(option) ⇒ Symbol
Display and handle the popup for option.
-
#tableEntryChanged(opt_id, opt_descr) ⇒ Boolean
Realize if table entry was changed.
-
#tableEntryKey(opt_id, opt_descr) ⇒ String
Get the left column of the table.
-
#tableEntryValue(opt_id, opt_descr) ⇒ String
Get value to the table entry.
-
#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.
-
#TableRedraw(descr, update_buttons) ⇒ Object
Redraw completely the table.
-
#updateButtons(descr, opt_descr) ⇒ Object
Enable or disable the Delete and up/down buttons.
-
#updateOptionMap(opt_descr, fallbacks) ⇒ Hash
Update the option description map in order to contain handlers of all needed functions global only because of testsuites.
-
#ValidateTableAttr(attr) ⇒ Boolean
Validate table options specifyign attributesA.
-
#ValidateTableDescr(key, descr) ⇒ Boolean
Validate the table description.
-
#ValidateValueType(key, value, widget, popup) ⇒ Boolean
Validate type of entry of the option description map Also checks option description maps if present.
Instance Method Details
#askForNewOption(possible, editable, descr) ⇒ String
Displaye popup for option to edit choosing
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'library/cwm/src/modules/TablePopup.rb', line 445 def askForNewOption(possible, editable, descr) possible = deep_copy(possible) descr = deep_copy(descr) do_sort = !Ops.get_boolean(descr, "add_items_keep_order", false) possible = Builtins.sort(possible) if do_sort val2key = {} known_keys = {} possible = Builtins.maplist(possible) do |p| next if !Ops.is_string?(p) opt_descr = key2descr(descr, Convert.to_string(p)) label = Ops.get_string( opt_descr, ["table", "label"], Builtins.sformat("%1", p) ) Ops.set(known_keys, Convert.to_string(p), true) Ops.set(val2key, label, Convert.to_string(p)) Item(Id(p), label) end = HBox( HSpacing(1), VBox( VSpacing(1), ComboBox( Id(:optname), editable ? Opt(:editable) : Opt(), # combobox header _("&Selected Option"), possible ), VSpacing(1), HBox( HStretch(), PushButton(Id(:_tp_ok), Opt(:key_F10, :default), Label.OKButton), HSpacing(1), PushButton(Id(:_tp_cancel), Opt(:key_F9), Label.CancelButton), HStretch() ), VSpacing(1) ), HSpacing(1) ) UI.OpenDialog() begin UI.SetFocus(Id(:optname)) ret = nil option = nil while ret != :_tp_ok && ret != :_tp_cancel ret = UI.UserInput option = Convert.to_string(UI.QueryWidget(Id(:optname), :Value)) if ret == :_tp_ok end ensure UI.CloseDialog end return nil if ret == :_tp_cancel return option if Ops.get(known_keys, option, false) Ops.get(val2key, option, option) end |
#CreateTableDescr(attrib, widget_descr) ⇒ Hash
Get the map with the table widget
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 |
# File 'library/cwm/src/modules/TablePopup.rb', line 841 def CreateTableDescr(attrib, ) attrib = deep_copy(attrib) = deep_copy() ValidateTableAttr(attrib) = if Ops.get_boolean(attrib, "add_delete_buttons", true) PushButton(Id(:_tp_add), Opt(:key_F3), Label.AddButton) else HSpacing(0) end = if Ops.get_boolean(attrib, "edit_button", true) PushButton(Id(:_tp_edit), Opt(:key_F4), Label.EditButton) else HSpacing(0) end = if Ops.get_boolean(attrib, "add_delete_buttons", true) PushButton(Id(:_tp_delete), Opt(:key_F5), Label.DeleteButton) else HSpacing(0) end table_header = if Ops.get_boolean(attrib, "changed_column", false) Header( # table header, shortcut for changed, keep very short _("Ch."), # table header _("Option"), # table header _("Value") ) else Header( # table header _("Option"), # table header _("Value") ) end replace_point = ReplacePoint(Id(:_tp_table_repl), HSpacing(0)) # help 1/4 help = _( "<p><b><big>Editing the Settings</big></b><br>\n" \ "To edit the settings, choose the appropriate\n" \ "entry of the table then click <b>Edit</b>.</p>" ) if Ops.get_boolean(attrib, "add_delete_buttons", true) # help 2/4, optional help = Ops.add( help, _( "<p>To add a new option, click <b>Add</b>. To remove\nan option, select it and click <b>Delete</b>.</p>" ) ) end if Ops.get_boolean(attrib, "changed_column", false) # help 3/4, optional help = Ops.add( help, _( "<P>The <B>Ch.</B> column of the table shows \nwhether the option was changed.</P>" ) ) end if Ops.get_boolean(attrib, "up_down_buttons", false) # help 4/4, optional help = Ops.add( help, _( "<p>To reorder the options, select an option\n" \ "and use <b>Up</b> and <b>Down</b> to move it up or down\n" \ "in the list.</p>" ) ) end up_down = if Ops.get_boolean(attrib, "up_down_buttons", false) VBox( VStretch(), # push button PushButton(Id(:_tp_up), _("&Up")), # push button PushButton(Id(:_tp_down), _("&Down")), VStretch() ) else HSpacing(0) end ret = Convert.convert( Builtins.union( { "custom_widget" => HBox( HSpacing(2), VBox( HBox( Table( Id(:_tp_table), Opt(:immediate, :notify, :keepSorting), table_header, [] ), up_down ), HBox( , , , HStretch(), replace_point ) ), HSpacing(2) ), "_cwm_attrib" => attrib, "widget" => :custom, "help" => help, "_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 |
#deleteTableItem(opt_id, descr) ⇒ Boolean
Delete an item from the table Just a wrapper for module-specific function
329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'library/cwm/src/modules/TablePopup.rb', line 329 def deleteTableItem(opt_id, descr) opt_id = deep_copy(opt_id) descr = deep_copy(descr) toEval = Convert.convert( Ops.get(descr, "option_delete"), from: "any", to: "boolean (any, string)" ) if nil != toEval opt_key = id2key(descr, opt_id) return toEval.call(opt_id, opt_key) end false end |
#DisableTable(descr) ⇒ Object
Disable whole table
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
# File 'library/cwm/src/modules/TablePopup.rb', line 606 def DisableTable(descr) descr = deep_copy(descr) UI.ChangeWidget(Id(:_tp_table), :Enabled, false) UI.ChangeWidget(Id(:_tp_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(:_tp_delete), :Enabled, false) UI.ChangeWidget(Id(:_tp_add), :Enabled, false) end if Ops.get_boolean(descr, ["_cwm_attrib", "up_down_buttons"], false) UI.ChangeWidget(Id(:_tp_up), :Enabled, false) UI.ChangeWidget(Id(:_tp_down), :Enabled, false) end nil end |
#EnableTable(descr) ⇒ Object
Enable whole table (except buttons that should be grayed according to currently selected table row
625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'library/cwm/src/modules/TablePopup.rb', line 625 def EnableTable(descr) descr = deep_copy(descr) UI.ChangeWidget(Id(:_tp_table), :Enabled, true) UI.ChangeWidget(Id(:_tp_edit), :Enabled, true) if Ops.get_boolean(descr, ["_cwm_attrib", "edit_button"], true) UI.ChangeWidget(Id(:_tp_add), :Enabled, false) if Ops.get_boolean(descr, ["_cwm_attrib", "add_delete_buttons"], true) opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) opt_key = id2key(descr, opt_id) option_map = key2descr(descr, opt_key) updateButtons(descr, option_map) nil end |
#getIdList(descr) ⇒ Array
Get list of IDs of entries of the table
56 57 58 59 60 61 62 63 64 65 66 |
# File 'library/cwm/src/modules/TablePopup.rb', line 56 def getIdList(descr) descr = deep_copy(descr) toEval = Convert.convert( Ops.get(descr, "ids"), from: "any", to: "list (map)" ) return toEval.call(descr) if !toEval.nil? [] end |
#id2key(descr, opt_id) ⇒ String
Get option key from the option id global only because of testsuites
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'library/cwm/src/modules/TablePopup.rb', line 173 def id2key(descr, opt_id) descr = deep_copy(descr) opt_id = deep_copy(opt_id) if !opt_id.nil? && Ops.is_string?(opt_id) && Ops.greater_or_equal(Builtins.size(Convert.to_string(opt_id)), 7) && Builtins.substring(Convert.to_string(opt_id), 0, 7) == "____sep" return "____sep" end toEval = Convert.convert( Ops.get(descr, "id2key"), from: "any", to: "string (map, any)" ) toEval.nil? ? Convert.to_string(opt_id) : toEval.call(descr, opt_id) end |
#key2descr(descr, opt_key) ⇒ Hash
Get option description map from the key global only because of testsuites
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 |
# File 'library/cwm/src/modules/TablePopup.rb', line 196 def key2descr(descr, opt_key) descr = deep_copy(descr) = Ops.get_map(descr, "options", {}) opt_descr = Ops.get_map(, opt_key, {}) # a copy wanted here opt_descr = Builtins.add(opt_descr, "_cwm_key", opt_key) # a deep copy Ops.set( opt_descr, "table", Builtins.add(Ops.get_map(opt_descr, "table", {}), "_cwm_key", opt_key) ) Ops.set( opt_descr, "popup", Builtins.add(Ops.get_map(opt_descr, "popup", {}), "_cwm_key", opt_key) ) if Ops.get(opt_descr, ["popup", "label"]).nil? Ops.set( opt_descr, ["popup", "label"], Ops.get_string(opt_descr, ["table", "label"], opt_key) ) end deep_copy(opt_descr) end |
#main ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'library/cwm/src/modules/TablePopup.rb', line 33 def main Yast.import "UI" textdomain "base" Yast.import "CWM" Yast.import "Label" Yast.import "Mode" Yast.import "Report" # variables # Item, that is the last selected # Used to decide if selected item should be moved up or down if separator # clicked # Loss of contents is no problem @previous_selected_item = nil end |
#moveTableItem(opt_id, descr, dir) ⇒ Object
Move table item up or down Just a wrapper for module-specific function
386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'library/cwm/src/modules/TablePopup.rb', line 386 def moveTableItem(opt_id, descr, dir) opt_id = deep_copy(opt_id) descr = deep_copy(descr) toEval = Convert.convert( Ops.get(descr, "option_move"), from: "any", to: "any (any, string, symbol)" ) return toEval.call(opt_id, id2key(descr, opt_id), dir) if nil != toEval nil end |
#singleOptionEditPopup(option) ⇒ Symbol
Display and handle the popup for option
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
# File 'library/cwm/src/modules/TablePopup.rb', line 510 def singleOptionEditPopup(option) option = deep_copy(option) opt_key = Ops.get_string(option, "_cwm_key", "") opt_id = Ops.get(option, "_cwm_id") label = Builtins.sformat( "%1", Ops.get_string(option, ["table", "label"], opt_key) ) header = HBox( # heading / label Heading(_("Current Option: ")), Label(label), HStretch() ) popup_descr = CWM.prepareWidget(Ops.get_map(option, "popup", {})) = Ops.get_term(popup_descr, "widget", VBox()) help = Ops.get_string(popup_descr, "help", "") help = "" if help.nil? contents = HBox( HSpacing(1), VBox( VSpacing(1), Left(header), VSpacing(1), (help == "") ? VSpacing(0) : Left(Label(help)), VSpacing((help == "") ? 0 : 1), Left(ReplacePoint(Id(:value_rp), )), VSpacing(1), HBox( HStretch(), PushButton(Id(:_tp_ok), Opt(:key_F10, :default), Label.OKButton), HSpacing(1), PushButton(Id(:_tp_cancel), Opt(:key_F9), Label.CancelButton), HStretch() ), VSpacing(1) ), HSpacing(1) ) UI.OpenDialog(contents) begin if Ops.get(popup_descr, "init") toEval = Convert.convert( Ops.get(popup_descr, "init"), from: "any", to: "void (any, string)" ) toEval.call(opt_id, opt_key) end ret = nil while ret != :_tp_ok && ret != :_tp_cancel event_descr2 = UI.WaitForEvent event_descr2 = { "ID" => :_tp_ok } if Mode.test ret = Ops.get(event_descr2, "ID") if Ops.get(popup_descr, "handle") toEval = Convert.convert( Ops.get(popup_descr, "handle"), from: "any", to: "void (any, string, map)" ) toEval.call(opt_id, opt_key, event_descr2) end next if ret != :_tp_ok val_type = Ops.get_symbol(popup_descr, "validate_type") if val_type == :function toEval = Convert.convert( Ops.get(popup_descr, "validate_function"), from: "any", to: "boolean (any, string, map)" ) ret = nil if !toEval.nil? && !toEval.call(opt_id, opt_key, event_descr2) elsif !CWM.validateWidget(popup_descr, event_descr2, opt_key) ret = nil end end if ret == :_tp_ok && Ops.get(popup_descr, "store") toEval = Convert.convert( Ops.get(popup_descr, "store"), from: "any", to: "void (any, string)" ) toEval.call(opt_id, opt_key) end ensure UI.CloseDialog end Convert.to_symbol(ret) end |
#tableEntryChanged(opt_id, opt_descr) ⇒ Boolean
Realize if table entry was changed
310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'library/cwm/src/modules/TablePopup.rb', line 310 def tableEntryChanged(opt_id, opt_descr) opt_id = deep_copy(opt_id) opt_descr = deep_copy(opt_descr) opt_key = Ops.get_string(opt_descr, "_cwm_key", "") toEval = Convert.convert( Ops.get(opt_descr, ["table", "changed"]), from: "any", to: "boolean (any, string)" ) return toEval.call(opt_id, opt_key) if !toEval.nil? false end |
#tableEntryKey(opt_id, opt_descr) ⇒ String
Get the left column of the table
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'library/cwm/src/modules/TablePopup.rb', line 268 def tableEntryKey(opt_id, opt_descr) opt_id = deep_copy(opt_id) opt_descr = deep_copy(opt_descr) opt_key = Ops.get_string(opt_descr, "_cwm_key", "") label = Ops.get_string( opt_descr, ["table", "label"], Builtins.sformat("%1", opt_key) ) if Builtins.haskey(Ops.get_map(opt_descr, "table", {}), "label_func") label_func = Convert.convert( Ops.get(opt_descr, ["table", "label_func"]), from: "any", to: "string (any, string)" ) label = label_func.call(opt_id, opt_key) end label end |
#tableEntryValue(opt_id, opt_descr) ⇒ String
Get value to the table entry
292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'library/cwm/src/modules/TablePopup.rb', line 292 def tableEntryValue(opt_id, opt_descr) opt_id = deep_copy(opt_id) opt_descr = deep_copy(opt_descr) opt_key = Ops.get_string(opt_descr, "_cwm_key", "") toEval = Convert.convert( Ops.get(opt_descr, ["table", "summary"]), from: "any", to: "string (any, string)" ) return toEval.call(opt_id, opt_key) if !toEval.nil? "" end |
#TableHandle(descr, key, event_descr) ⇒ Symbol
Handle the event that happened on the table
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 |
# File 'library/cwm/src/modules/TablePopup.rb', line 656 def TableHandle(descr, key, event_descr) descr = deep_copy(descr) event_descr = deep_copy(event_descr) event_id = Ops.get(event_descr, "ID") UI.SetFocus(Id(:_tp_table)) if event_id == :_tp_table && (Ops.get_string(event_descr, "EventReason", "") == "Activated" && Ops.get_string(event_descr, "EventType", "") == "WidgetEvent" && UI.WidgetExists(Id(:_tp_edit))) event_id = :_tp_edit end case event_id when :_tp_edit, :_tp_add opt_key = nil opt_id = nil case event_id when :_tp_add add_unlisted = Ops.get_boolean(descr, "add_unlisted", true) if !add_unlisted && Builtins.size(Ops.get_list(descr, "add_items", [])) == 1 opt_key = Ops.get_string(descr, ["add_items", 0], "") else add_opts = Ops.get_list(descr, "add_items", []) ids = getIdList(descr) present = Builtins.maplist(ids) { |i| id2key(descr, i) } if !Ops.get_boolean(descr, ["_cwm_attrib", "unique_keys"], false) present = Builtins.filter(present) do |i| opt_descr = key2descr(descr, i) !Ops.get_boolean(opt_descr, ["table", "optional"], true) end end add_opts = Builtins.filter(add_opts) do |o| !Builtins.contains(present, o) end selected = false until selected opt_key = askForNewOption(add_opts, add_unlisted, descr) return nil if opt_key.nil? if Builtins.contains(present, opt_key) Report.Error( # error report _("The selected option is already present.") ) else selected = true end end end return nil if opt_key.nil? when :_tp_edit opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) opt_key = id2key(descr, opt_id) end option_map = key2descr(descr, opt_key) toEval = Ops.get(option_map, ["table", "handle"]) if !toEval.nil? # if (is (toEval, symbol)) if Ops.is(toEval, "symbol (any, string, map)") toEval_c = Convert.convert( Ops.get(option_map, ["table", "handle"]), from: "any", to: "symbol (any, string, map)" ) ret2 = toEval_c.call(opt_id, opt_key, event_descr) return ret2 if ret2 != :_tp_normal else ret2 = Convert.to_symbol(toEval) return ret2 end end Ops.set(option_map, "_cwm_id", opt_id) Ops.set(option_map, "_cwm_key", opt_key) # add generic handlers if needed option_map = updateOptionMap( option_map, Ops.get_map(descr, "fallback", {}) ) ret = singleOptionEditPopup(option_map) if ret == :_tp_ok case event_id when :_tp_add TableInit(descr, key) when :_tp_edit column = descr.fetch("_cwm_attrib", {}).fetch("changed_column", false) ? 2 : 1 UI.ChangeWidget( Id(:_tp_table), term(:Item, opt_id, column), tableEntryValue(opt_id, option_map) ) # also redraw the key field as it can be changed column = Ops.subtract(column, 1) UI.ChangeWidget( Id(:_tp_table), term(:Item, opt_id, column), tableEntryKey(opt_id, option_map) ) if Ops.get_boolean(descr, ["_cwm_attrib", "changed_column"], false) UI.ChangeWidget( Id(:_tp_table), term(:Item, opt_id, 0), tableEntryChanged(opt_id, option_map) ? "*" : "" ) end end end when :_tp_delete opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) TableInit(descr, key) if deleteTableItem(opt_id, descr) when :_tp_table opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) key2 = id2key(descr, opt_id) if key2 == "____sep" id_list = getIdList(descr) previous_index = 0 if !@previous_selected_item.nil? previous_index = -1 Builtins.find(id_list) do |e| previous_index = Ops.add(previous_index, 1) e == @previous_selected_item end end current_index = -1 Builtins.find(id_list) do |e| current_index = Ops.add(current_index, 1) e == opt_id end # rubocop:disable Lint/DuplicateBranch # rubocop here wrongly detect logic in if conditions to decide step direction step = if current_index == 0 1 elsif Ops.add(current_index, 1) == Builtins.size(id_list) -1 elsif Ops.greater_or_equal(current_index, previous_index) 1 else -1 end # rubocop:enable Lint/DuplicateBranch new_index = Ops.add(current_index, step) opt_id = Ops.get(id_list, new_index) UI.ChangeWidget(Id(:_tp_table), :CurrentItem, opt_id) end @previous_selected_item = deep_copy(opt_id) opt_descr = key2descr(descr, id2key(descr, opt_id)) updateButtons(descr, opt_descr) when :_tp_up, :_tp_down opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem) opt_id = moveTableItem(opt_id, descr, (event_id == :_tp_up) ? :up : :down) if nil != opt_id TableRedraw(descr, false) UI.ChangeWidget(Id(:_tp_table), :CurrentItem, opt_id) opt_descr = key2descr(descr, id2key(descr, opt_id)) updateButtons(descr, opt_descr) end end nil end |
#TableHandleWrapper(key, event_descr) ⇒ Symbol
Wrapper for TableHandle using CWM::GetProcessedWidget () for getting widget description map
831 832 833 834 |
# File 'library/cwm/src/modules/TablePopup.rb', line 831 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
642 643 644 645 646 647 648 649 |
# File 'library/cwm/src/modules/TablePopup.rb', line 642 def TableInit(descr, key) descr = deep_copy(descr) @previous_selected_item = nil Ops.set(descr, "_cwm_key", key) TableRedraw(descr, true) nil end |
#TableInitWrapper(key) ⇒ Object
Wrapper for TableInit using CWM::GetProcessedWidget () for getting widget description map
820 821 822 823 824 |
# File 'library/cwm/src/modules/TablePopup.rb', line 820 def TableInitWrapper(key) TableInit(CWM.GetProcessedWidget, key) nil end |
#TableRedraw(descr, update_buttons) ⇒ Object
Redraw completely the table
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'library/cwm/src/modules/TablePopup.rb', line 403 def TableRedraw(descr, ) descr = deep_copy(descr) id_list = getIdList(descr) @previous_selected_item = Ops.get(id_list, 0) if @previous_selected_item.nil? entries = Builtins.maplist(id_list) do |opt_id| opt_val = "" opt_changed = false opt_key = id2key(descr, opt_id) opt_descr = key2descr(descr, opt_key) opt_descr = updateOptionMap( opt_descr, Ops.get_map(descr, "fallback", {}) ) label = tableEntryKey(opt_id, opt_descr) if opt_key != "____sep" opt_val = tableEntryValue(opt_id, opt_descr) opt_changed = tableEntryChanged(opt_id, opt_descr) end updateButtons(descr, opt_descr) if && opt_id == @previous_selected_item if Ops.get_boolean(descr, ["_cwm_attrib", "changed_column"], false) next Item( Id(opt_id), opt_changed ? "*" : "", label, Builtins.sformat("%1", opt_val) ) end Item(Id(opt_id), label, Builtins.sformat("%1", opt_val)) end UI.ChangeWidget(Id(:_tp_table), :Items, entries) UI.SetFocus(Id(:_tp_table)) nil end |
#updateButtons(descr, opt_descr) ⇒ Object
Enable or disable the Delete and up/down buttons
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 |
# File 'library/cwm/src/modules/TablePopup.rb', line 347 def updateButtons(descr, opt_descr) descr = deep_copy(descr) opt_descr = deep_copy(opt_descr) if Ops.get_boolean(descr, ["_cwm_attrib", "add_delete_buttons"], true) UI.ChangeWidget( Id(:_tp_delete), :Enabled, Ops.get_boolean(opt_descr, ["table", "optional"], true) ) end if Ops.get_boolean(descr, ["_cwm_attrib", "edit_button"], true) UI.ChangeWidget( Id(:_tp_edit), :Enabled, !Ops.get_boolean(opt_descr, ["table", "immutable"], false) ) end if Ops.get_boolean(descr, ["_cwm_attrib", "up_down_buttons"], false) UI.ChangeWidget( Id(:_tp_up), :Enabled, Ops.get_boolean(opt_descr, ["table", "ordering"], true) ) UI.ChangeWidget( Id(:_tp_down), :Enabled, Ops.get_boolean(opt_descr, ["table", "ordering"], true) ) end nil end |
#updateOptionMap(opt_descr, fallbacks) ⇒ Hash
Update the option description map in order to contain handlers of all needed functions global only because of testsuites
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 262 |
# File 'library/cwm/src/modules/TablePopup.rb', line 229 def updateOptionMap(opt_descr, fallbacks) opt_descr = deep_copy(opt_descr) fallbacks = deep_copy(fallbacks) # ensure that the submaps exist Ops.set(opt_descr, "table", Ops.get_map(opt_descr, "table", {})) Ops.set(opt_descr, "popup", Ops.get_map(opt_descr, "popup", {})) Builtins.foreach(["init", "store"]) do |k| if !Builtins.haskey(Ops.get_map(opt_descr, "popup", {}), k) && Builtins.haskey(fallbacks, k) Ops.set(opt_descr, ["popup", k], Ops.get(fallbacks, k)) end end if !Builtins.haskey(Ops.get_map(opt_descr, "table", {}), "summary") && Builtins.haskey(fallbacks, "summary") Ops.set(opt_descr, ["table", "summary"], Ops.get(fallbacks, "summary")) end if !Builtins.haskey(Ops.get_map(opt_descr, "table", {}), "label_func") && Builtins.haskey(fallbacks, "label_func") Ops.set( opt_descr, ["table", "label_func"], Ops.get(fallbacks, "label_func") ) end if !Builtins.haskey(Ops.get_map(opt_descr, "table", {}), "changed") && Builtins.haskey(fallbacks, "changed") Ops.set(opt_descr, ["table", "changed"], Ops.get(fallbacks, "changed")) end if Ops.get_string(opt_descr, "_cwm_key", "") == "____sep" && Ops.get_string(opt_descr, ["table", "label"], "") == "" Ops.set(opt_descr, ["table", "label"], "--------------------") end deep_copy(opt_descr) end |
#ValidateTableAttr(attr) ⇒ Boolean
Validate table options specifyign attributesA
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'library/cwm/src/modules/TablePopup.rb', line 71 def ValidateTableAttr(attr) attr = deep_copy(attr) types = { "add_delete_buttons" => "boolean", "edit_button" => "boolean", "changed_column" => "boolean", "up_down_buttons" => "boolean", "unique_keys" => "boolean" } 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
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'library/cwm/src/modules/TablePopup.rb', line 145 def ValidateTableDescr(key, descr) descr = deep_copy(descr) ret = true Builtins.foreach(descr) do |k, v| ret = ValidateValueType(k, v, key, false) && ret end = Ops.get_map(descr, "options", {}) Builtins.foreach() do |w_key, v| des = Convert.convert( v, from: "any", to: "map <string, map <string, any>>" ) Builtins.foreach(des) do |group, d| Builtins.y2error("Unknown entry in option %1: %2", w_key, group) if group != "table" && group != "popup" Builtins.foreach(d) do |key2, value| ValidateValueType(key2, value, w_key, true) end end end ret end |
#ValidateValueType(key, value, widget, popup) ⇒ Boolean
Validate type of entry of the option description map Also checks option description maps if present
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 |
# File 'library/cwm/src/modules/TablePopup.rb', line 100 def ValidateValueType(key, value, , popup) value = deep_copy(value) success = true if popup case key when "init", "store", "cleanup" success = Ops.is(value, "void (any, string)") when "handle" success = Ops.is(value, "void (any, string, map)") || Ops.is_symbol?(value) when "validate_function" success = Ops.is(value, "boolean (any, string, map)") when "optional" success = Ops.is_boolean?(value) when "label_func" success = Ops.is(value, "string (any, string)") else return CWM.ValidateValueType(key, value, ) end else success = case key when "id2key" then Ops.is(value, "string (map, any)") when "ids" then Ops.is(value, "list (map)") when "option_delete" then Ops.is(value, "boolean (any, string)") when "summary", "label_func" then Ops.is(value, "string (any, string)") when "option_move" then Ops.is(value, "any (any, string, symbol)") when "options" then Ops.is(value, "map <string, any>") when "add_items" then Ops.is_list?(value) end end if !success Builtins.y2error( "Wrong type of option %1 in description map of %2", key, ) end nil end |