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_contents, #cwm_definition, #find_ids, #ids_in_contents

Methods inherited from AbstractWidget

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

Instance Method Details

#cell(*args) ⇒ Object (protected)

Note:

Please see difference between Cell and cell. The first one is used in queries to pick exact cell, but later is used for content of cell. For reasons ask libyui authors.

helper to create icon term

Examples:

cell(icon("/tmp/cool_icon.png"), "Really cool!!!")

Parameters:

  • args

    content of cell, often used to combine icon and string



102
103
104
# File 'library/cwm/src/lib/cwm/table.rb', line 102

def cell(*args)
  Yast::Term.new(:cell, *args)
end

#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

Parameters:

  • id (Object)

    id of row ( the first element in #items )

  • column_number (Integer)

    index of cell in row. Index start with 0 for first cell.

  • cell_content (String, Yast::Term, Object)

    Content of cell. Support same stuff as #items



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.

Parameters:

  • items_list (Array<Array<Object>>)

    same format as #items



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

#icon(path) ⇒ Object (protected)

helper to create icon term

Parameters:

  • path (String)

    path to icon



90
91
92
# File 'library/cwm/src/lib/cwm/table.rb', line 90

def icon(path)
  Yast::Term.new(:icon, path)
end

#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

#multiselection?Boolean (protected)

helper to say if table have multiselection

Returns:

  • (Boolean)


107
108
109
110
111
# File 'library/cwm/src/lib/cwm/table.rb', line 107

def multiselection?
  return false unless respond_to?(:opt, true)

  opt.include?(:multiSelection)
end

#valueArray<Object>, Object

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

Returns:

  • (Array<Object>, Object)

    array if multiselection? return true



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

Parameters:

  • id (Object, Array<Object>)

    selected id, if multiselection? is true it require array of ids to select



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