Class: CWM::Table

Inherits:
CustomWidget show all
Defined in:
library/cwm/src/lib/cwm/table.rb

Overview

Represents Table widget

Instance Attribute Summary

Attributes inherited from AbstractWidget

#handle_all_events, #widget_id

Instance Method Summary collapse

Methods inherited from CustomWidget

#cwm_definition

Methods inherited from AbstractWidget

#cleanup, #cwm_definition, #disable, #enable, #enabled?, #handle, #help, #init, #label, #opt, #store, #validate, widget_type=

Instance Method Details

#change_cell(id, column_number, cell_content) ⇒ Object

Note:

more efficient for bigger tables then changing everything with #change_items

Replaces content of single cell



70
71
72
# File 'library/cwm/src/lib/cwm/table.rb', line 70

def change_cell(id, column_number, cell_content)
  Yast::UI.ChangeWidget(Id(widget_id), Cell(id, column_number), cell_content)
end

#change_items(items_list) ⇒ Object

Note:

items and change_items is consistent with ItemsSelection mixin, just format of items is different due to nature of Table content.

change list on fly with argument. Useful when content of widget is changed.



47
48
49
# File 'library/cwm/src/lib/cwm/table.rb', line 47

def change_items(items_list)
  Yast::UI.ChangeWidget(Id(widget_id), :Items, format_items(items_list))
end

#contentsObject

Note:

used mainly to pass it CWM.

Resulting table as YUI term.



76
77
78
79
80
81
82
83
84
# File 'library/cwm/src/lib/cwm/table.rb', line 76

def contents
  opt_args = respond_to?(:opt, true) ? opt : []
  Table(
    Id(widget_id),
    Opt(*opt_args),
    Header(*header),
    format_items(items)
  )
end

#headerObject

return array of String or Yast::Term which is used as headers for table it can use e.g. align Left/Center/Right



20
# File 'library/cwm/src/lib/cwm/table.rb', line 20

abstract_method :header

#itemsObject

Note:

default value is empty array. It is useful when computation expensive content need to be set. In such case, it is better to keep empty items to quickly show table and then in #init call #change_items method, so it will be filled when all widgets are at place and just filling its content.

gets initial two dimensional array of Table content one element in the first dimension contain as first element id and then rest is data in table, which can be e.g. terms. Then it have to be enclosed in `cell` term.

Examples:

for table with two columns

def items
  [
    [:first_user, "Joe", "Doe"],
    [:best_user, "Chuck", "Norris"]
  ]
end

See Also:

  • more complex example see examples directory


39
40
41
# File 'library/cwm/src/lib/cwm/table.rb', line 39

def items
  []
end

#valueArray<Object>, Object

gets id of selected item in table or array of ids if multiselection option is used



53
54
55
56
# File 'library/cwm/src/lib/cwm/table.rb', line 53

def value
  val = Yast::UI.QueryWidget(Id(widget_id), :SelectedItems)
  multiselection? ? val : val.first
end

#value=(id) ⇒ Object

sets id of selected item(-s) in table



61
62
63
# File 'library/cwm/src/lib/cwm/table.rb', line 61

def value=(id)
  Yast::UI.ChangeWidget(Id(widget_id), :SelectedItems, Array(id))
end