Class: Yast::TablePopupClass

Inherits:
Module
  • Object
show all
Defined in:
library/cwm/src/modules/TablePopup.rb

Instance Method Summary collapse

Instance Method Details

#askForNewOption(possible, editable, descr) ⇒ String

Displaye popup for option to edit choosing

Parameters:

  • possible (Array)

    a list of strings or items of all possible options to provide

  • editable (Boolean)

    boolean true means that it is possible to add non-listed options

  • descr (Hash{String => Object})

    a map table description map

Returns:

  • (String)

    option identifies, nil if canceled



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
505
506
507
508
509
510
511
512
513
514
515
516
# File 'library/cwm/src/modules/TablePopup.rb', line 457

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
  widget = 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(widget)
  begin
    UI.SetFocus(Id(:optname))
    ret = nil
    option = nil
    while ret != :_tp_ok && ret != :_tp_cancel
      ret = UI.UserInput
      if ret == :_tp_ok
        option = Convert.to_string(UI.QueryWidget(Id(:optname), :Value))
      end
    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

Parameters:

  • attrib (Hash{String => Object})

    map table attributes

  • widget_descr (Hash{String => Object})

    map widget description map of the table, will be unioned with the generated map

Returns:

  • (Hash)

    table widget



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
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
# File 'library/cwm/src/modules/TablePopup.rb', line 856

def CreateTableDescr(attrib, widget_descr)
  attrib = deep_copy(attrib)
  widget_descr = deep_copy(widget_descr)
  ValidateTableAttr(attrib)

  add_button = if Ops.get_boolean(attrib, "add_delete_buttons", true)
    PushButton(Id(:_tp_add), Opt(:key_F3), Label.AddButton)
  else
    HSpacing(0)
  end

  edit_button = if Ops.get_boolean(attrib, "edit_button", true)
    PushButton(Id(:_tp_edit), Opt(:key_F4), Label.EditButton)
  else
    HSpacing(0)
  end

  delete_button = 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(
              add_button,
              edit_button,
              delete_button,
              HStretch(),
              replace_point
            )
          ),
          HSpacing(2)
        ),
        "_cwm_attrib"      => attrib,
        "widget"           => :custom,
        "help"             => help,
        "_cwm_do_validate" => fun_ref(
          method(:ValidateTableDescr),
          "boolean (string, map <string, any>)"
        )
      },
      widget_descr
    ),
    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

Parameters:

  • opt_id (Object)

    any option id

  • descr (Hash{String => Object})

    map table description map

Returns:

  • (Boolean)

    true if was really deleted



338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'library/cwm/src/modules/TablePopup.rb', line 338

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

Parameters:

  • descr (Hash{String => Object})

    map table widget description map



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'library/cwm/src/modules/TablePopup.rb', line 620

def DisableTable(descr)
  descr = deep_copy(descr)
  UI.ChangeWidget(Id(:_tp_table), :Enabled, false)
  if Ops.get_boolean(descr, ["_cwm_attrib", "edit_button"], true)
    UI.ChangeWidget(Id(:_tp_edit), :Enabled, false)
  end
  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

Parameters:

  • descr (Hash{String => Object})

    map table widget description map



641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'library/cwm/src/modules/TablePopup.rb', line 641

def EnableTable(descr)
  descr = deep_copy(descr)
  UI.ChangeWidget(Id(:_tp_table), :Enabled, true)
  if Ops.get_boolean(descr, ["_cwm_attrib", "edit_button"], true)
    UI.ChangeWidget(Id(:_tp_edit), :Enabled, true)
  end
  if Ops.get_boolean(descr, ["_cwm_attrib", "add_delete_buttons"], true)
    UI.ChangeWidget(Id(:_tp_add), :Enabled, false)
  end

  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

Parameters:

  • descr (Hash{String => Object})

    map table description map

Returns:

  • (Array)

    of IDs of the table



58
59
60
61
62
63
64
65
66
67
# File 'library/cwm/src/modules/TablePopup.rb', line 58

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

Parameters:

  • descr (Hash{String => Object})

    map description of the table

  • opt_id (Object)

    any id of the option

Returns:



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'library/cwm/src/modules/TablePopup.rb', line 185

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

Parameters:

  • descr (Hash{String => Object})

    map description of the table

  • opt_key (String)

    string option key

Returns:

  • (Hash)

    option description map



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
# File 'library/cwm/src/modules/TablePopup.rb', line 207

def key2descr(descr, opt_key)
  descr = deep_copy(descr)
  options = Ops.get_map(descr, "options", {})
  opt_descr = Ops.get_map(options, 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

#mainObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'library/cwm/src/modules/TablePopup.rb', line 35

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

Parameters:

  • opt_id (Object)

    any option id

  • descr (Hash{String => Object})

    map table description map

  • dir (Symbol)

    symbol `up or `down (according to the button user pressed)

Returns:

  • (Object)

    new id of selected option, nil if wasn't reordered



395
396
397
398
399
400
401
402
403
404
405
# File 'library/cwm/src/modules/TablePopup.rb', line 395

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

Parameters:

  • option (Hash{String => Object})

    map one option description map that is modified in order to contain the option name and more percise option identification

Returns:

  • (Symbol)

    `_tp_ok or `_tp_cancel



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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
# File 'library/cwm/src/modules/TablePopup.rb', line 522

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", {}))
  widget = 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), widget)),
      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)"
        )
        if !toEval.nil?
          ret = nil if !toEval.call(opt_id, opt_key, event_descr2)
        end
      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

Parameters:

  • opt_id (Object)

    any option id

  • opt_descr (Hash{String => Object})

    map option description map

Returns:

  • (Boolean)

    true if was changed



320
321
322
323
324
325
326
327
328
329
330
331
# File 'library/cwm/src/modules/TablePopup.rb', line 320

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

Parameters:

  • opt_id (Object)

    any option id

  • opt_descr (Hash{String => Object})

    map option description map

Returns:

  • (String)

    text to the table



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'library/cwm/src/modules/TablePopup.rb', line 279

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

Parameters:

  • opt_id (Object)

    any option id

  • opt_descr (Hash{String => Object})

    map option description map

Returns:

  • (String)

    text to the table



303
304
305
306
307
308
309
310
311
312
313
314
# File 'library/cwm/src/modules/TablePopup.rb', line 303

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

Parameters:

  • descr (Hash{String => Object})

    map description of the table

  • key (String)

    table widget key

  • event_descr (Hash)

    map event to handle

Returns:

  • (Symbol)

    modified event if needed



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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
# File 'library/cwm/src/modules/TablePopup.rb', line 676

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
    if Ops.get_string(event_descr, "EventReason", "") == "Activated" &&
        Ops.get_string(event_descr, "EventType", "") == "WidgetEvent" &&
        UI.WidgetExists(Id(:_tp_edit))
      event_id = :_tp_edit
    end
  end
  if event_id == :_tp_edit || event_id == :_tp_add
    opt_key = nil
    opt_id = nil

    if event_id == :_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?
    elsif event_id == :_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)")
        ret2 = Convert.to_symbol(toEval)
        return ret2
      else
        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
      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
      if event_id == :_tp_add
        TableInit(descr, key)
      elsif event_id == :_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
  elsif event_id == :_tp_delete
    opt_id = UI.QueryWidget(Id(:_tp_table), :CurrentItem)
    TableInit(descr, key) if deleteTableItem(opt_id, descr)
  elsif event_id == :_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
      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
      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)
  elsif event_id == :_tp_up || event_id == :_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

Parameters:

  • key (String)

    any widget key

  • event_descr (Hash)

    map event description map

Returns:

  • (Symbol)

    return value for wizard sequencer or nil



846
847
848
849
# File 'library/cwm/src/modules/TablePopup.rb', line 846

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

Parameters:

  • descr (Hash{String => Object})

    map description map of the whole table

  • key (String)

    table widget key



662
663
664
665
666
667
668
669
# File 'library/cwm/src/modules/TablePopup.rb', line 662

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

Parameters:

  • key (String)

    any widget key



835
836
837
838
839
# File 'library/cwm/src/modules/TablePopup.rb', line 835

def TableInitWrapper(key)
  TableInit(CWM.GetProcessedWidget, key)

  nil
end

#TableRedraw(descr, update_buttons) ⇒ Object

Redraw completely the table

Parameters:

  • descr (Hash{String => Object})

    map description map of the whole table

  • update_buttons (Boolean)

    boolean true if buttons status (enabled/disabled) should be updated according to currently selected item



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
437
438
439
440
441
442
443
444
445
446
447
448
# File 'library/cwm/src/modules/TablePopup.rb', line 411

def TableRedraw(descr, update_buttons)
  descr = deep_copy(descr)
  id_list = getIdList(descr)
  if @previous_selected_item.nil?
    @previous_selected_item = Ops.get(id_list, 0)
  end
  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
    if update_buttons && opt_id == @previous_selected_item
      updateButtons(descr, opt_descr)
    end
    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

Parameters:

  • descr (Hash{String => Object})

    map table description map

  • opt_descr (Hash{String => Object})

    map selected option description map



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
# File 'library/cwm/src/modules/TablePopup.rb', line 356

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

Parameters:

  • opt_descr (Hash{String => Object})

    map option description map

  • fallbacks (Hash)

    map of fallback handlers

Returns:

  • (Hash)

    updated option description map



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'library/cwm/src/modules/TablePopup.rb', line 240

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

Parameters:

  • attr (Hash{String => Object})

    a map of table attributes

Returns:

  • (Boolean)

    true if validation succeeded



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'library/cwm/src/modules/TablePopup.rb', line 72

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

Parameters:

  • descr (Hash{String => Object})

    a map containing the table description

Returns:

  • (Boolean)

    true if validation succeeded



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'library/cwm/src/modules/TablePopup.rb', line 155

def ValidateTableDescr(key, descr)
  descr = deep_copy(descr)
  ret = true
  Builtins.foreach(descr) do |k, v|
    ret = ValidateValueType(k, v, key, false) && ret
  end
  options = Ops.get_map(descr, "options", {})
  Builtins.foreach(options) do |w_key, v|
    des = Convert.convert(
      v,
      from: "any",
      to:   "map <string, map <string, any>>"
    )
    Builtins.foreach(des) do |group, d|
      if group != "table" && group != "popup"
        Builtins.y2error("Unknown entry in option %1: %2", w_key, group)
      end
      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

Parameters:

  • key (String)

    string key of the map entry

  • value (Object)

    any value of the map entry

  • widget (String)

    any name of the widget/option

  • popup (Boolean)

    boolean true if is option of a popup

Returns:

  • (Boolean)

    true if validation succeeded



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
# File 'library/cwm/src/modules/TablePopup.rb', line 101

def ValidateValueType(key, value, widget, popup)
  value = deep_copy(value)
  success = true
  if popup
    if key == "init"
      success = Ops.is(value, "void (any, string)")
    elsif key == "handle"
      success = Ops.is(value, "void (any, string, map)") ||
        Ops.is_symbol?(value)
    elsif key == "store"
      success = Ops.is(value, "void (any, string)")
    elsif key == "cleanup"
      success = Ops.is(value, "void (any, string)")
    elsif key == "validate_function"
      success = Ops.is(value, "boolean (any, string, map)")
    elsif key == "optional"
      success = Ops.is_boolean?(value)
    elsif key == "label_func"
      success = Ops.is(value, "string (any, string)")
    else
      return CWM.ValidateValueType(key, value, widget)
    end
  elsif key == "id2key"
    success = Ops.is(value, "string (map, any)")
  elsif key == "ids"
    success = Ops.is(value, "list (map)")
  elsif key == "option_delete"
    success = Ops.is(value, "boolean (any, string)")
  elsif key == "summary"
    success = Ops.is(value, "string (any, string)")
  elsif key == "label_func"
    success = Ops.is(value, "string (any, string)")
  elsif key == "option_move"
    success = Ops.is(value, "any (any, string, symbol)")
  elsif key == "options"
    success = Ops.is(value, "map <string, any>")
  elsif key == "add_items"
    success = Ops.is_list?(value)
  end

  if !success
    Builtins.y2error(
      "Wrong type of option %1 in description map of %2",
      key,
      widget
    )
  end

  nil
end