Class: CWM::Pager

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

Overview

A Pager contains several Pages and makes only one visible at a time.

TreePager is a Pager.

Tabs is a Pager and a Tab is its Page.

See Also:

  • examples/object_api_tabsexamples/object_api_tabs.rb

Direct Known Subclasses

DumbTabPager, PushButtonTabPager, Tabs, TreePager

Instance Attribute Summary collapse

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?, #help, #label, #opt, #store, #validate, widget_type=

Constructor Details

#initialize(*pages) ⇒ Pager

Returns a new instance of Pager

Parameters:



20
21
22
23
24
# File 'library/cwm/src/lib/cwm/pager.rb', line 20

def initialize(*pages)
  @pages = pages
  @current_page = nil
  self.handle_all_events = true
end

Instance Attribute Details

#current_pageCWM::Page? (readonly)

Returns currently selected page; nil if no page is selected

Returns:

  • (CWM::Page, nil)

    currently selected page; nil if no page is selected



17
18
19
# File 'library/cwm/src/lib/cwm/pager.rb', line 17

def current_page
  @current_page
end

Instance Method Details

#handle(event) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'library/cwm/src/lib/cwm/pager.rb', line 32

def handle(event)
  new_id = event["ID"]
  page = page_for_id(new_id)

  return nil unless page

  # Note: don't rely on new_id being equal to page.widget_id
  # This may not be true for subclasses redefining #page_for_id
  # (see bsc#1078212)
  return nil if @current_page.widget_id == page.widget_id

  unless replace_point.validate
    mark_page(@current_page)
    return nil
  end

  replace_point.store

  switch_page(page)

  nil
end

#initObject

initializes pages, show page which is initial



27
28
29
30
# File 'library/cwm/src/lib/cwm/pager.rb', line 27

def init
  mark_page(initial_page)
  @current_page = initial_page
end