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, #displayed?, #enable, #enabled?, #focus, #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



145
146
147
# File 'library/cwm/src/lib/cwm/table.rb', line 145

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



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

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)

    same format as #items



84
85
86
# File 'library/cwm/src/lib/cwm/table.rb', line 84

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.



113
114
115
116
117
118
119
120
121
# File 'library/cwm/src/lib/cwm/table.rb', line 113

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



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

abstract_method :header

#icon(path) ⇒ Object (protected)

helper to create icon term

Parameters:

  • path (String)

    path to icon



127
128
129
# File 'library/cwm/src/lib/cwm/table.rb', line 127

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

#item(*args) ⇒ Object (protected)

Note:

Not to be confused with the UI shortcut Item

helper to create a CWM::TableItem

Examples:

item(:joe, ["Joe", "Doe"], children: [[:joeson, "Joeson", "Doe"]], open: false)

Parameters:



155
156
157
# File 'library/cwm/src/lib/cwm/table.rb', line 155

def item(*args)
  TableItem.new(*args)
end

#itemsArray<TableItem, Array>

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.

Array with the table content

Each element can be a CWM::TableItem or an Array. The helper #item can be used to easily create CWM::TableItem objects.

If it's an array, the row contains no nested elements. The first element represents the id of the row and the rest is used as data for its cells. Those can be e.g. terms. Then it has to be enclosed in cell term.

Examples:

for table with two columns

def items
  [
    item(:first_user, ["Joe", "Doe"], children: first_children),
    [:best_user, "Chuck", "Norris"]
  ]
end

def first_children
  [
    [:first_sub1, "SubJoe1", "Doe"],
    [:first_sub2, "SubJoe2", "Doe"]
  ]
end

Returns:

See Also:

  • more complex example see examples directory


76
77
78
# File 'library/cwm/src/lib/cwm/table.rb', line 76

def items
  []
end

#multiselection?Boolean (protected)

helper to say if table have multiselection

Returns:

  • (Boolean)


160
161
162
163
164
# File 'library/cwm/src/lib/cwm/table.rb', line 160

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

  opt.include?(:multiSelection)
end

#sort_key(value) ⇒ Object (protected)

helper to create sort-key term

Parameters:

  • value (String)

    sort-key



133
134
135
# File 'library/cwm/src/lib/cwm/table.rb', line 133

def sort_key(value)
  Yast::Term.new(:sortKey, value)
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



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

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



98
99
100
# File 'library/cwm/src/lib/cwm/table.rb', line 98

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