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

Methods inherited from AbstractWidget

#cleanup, #cwm_definition, #disable, #enable, #enabled?, #focus, #fun_ref, #help, #label, #my_event?, #opt, #refresh_help, #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

#contentsWidgetTerm (protected)

The contents will probably include a selector, such as Tabs or Tree and must include #replace_point where CWM::Pages will appear.

Returns:


85
# File 'library/cwm/src/lib/cwm/pager.rb', line 85

abstract_method :contents

#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

#initial_pageObject (protected)

gets initial page This default page which return true for method initial otherwise first page passed to constructor


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

def initial_page
  initial = @pages.find(&:initial)

  initial || @pages.first
end

#mark_pagevoid (protected)

This method returns an undefined value.

Mark the currently active page in the selector. This is needed in case the user has switched to a different page but we need to switch back because the current one failed validation.

Parameters:


80
# File 'library/cwm/src/lib/cwm/pager.rb', line 80

abstract_method :mark_page

#page_for_id(id) ⇒ Object (protected)


96
97
98
# File 'library/cwm/src/lib/cwm/pager.rb', line 96

def page_for_id(id)
  @pages.find { |t| t.widget_id == id }
end

#page_orderObject (protected)

gets visual order of pages This default implementation returns same order as passed to constructor


59
60
61
# File 'library/cwm/src/lib/cwm/pager.rb', line 59

def page_order
  @pages.map(&:widget_id)
end

#replace_pointObject (protected)


100
101
102
# File 'library/cwm/src/lib/cwm/pager.rb', line 100

def replace_point
  @replace_point ||= ReplacePoint.new(id: "replace_point_#{widget_id}", widget: initial_page)
end

#store_pageObject (protected)

stores page with given id


64
65
66
# File 'library/cwm/src/lib/cwm/pager.rb', line 64

def store_page
  replace_point.store
end

#switch_page(page) ⇒ Object (protected)

switch to target page


69
70
71
72
73
# File 'library/cwm/src/lib/cwm/pager.rb', line 69

def switch_page(page)
  mark_page(page)
  @current_page = page
  replace_point.replace(page)
end