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, #displayed?, #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
25
26
# File 'library/cwm/src/lib/cwm/pager.rb', line 20

def initialize(*pages)
  super()

  @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:



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

abstract_method :contents

#handle(event) ⇒ Object



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

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



29
30
31
32
# File 'library/cwm/src/lib/cwm/pager.rb', line 29

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



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

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:



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

abstract_method :mark_page

#page_for_id(id) ⇒ Object (protected)



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

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



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

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

#replace_pointObject (protected)



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

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

#store_pageObject (protected)

stores page with given id



66
67
68
# File 'library/cwm/src/lib/cwm/pager.rb', line 66

def store_page
  replace_point.store
end

#switch_page(page) ⇒ Object (protected)

switch to target page



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

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