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

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

Constructor Details

#initialize(*pages) ⇒ Pager

Returns a new instance of Pager

Parameters:



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

def initialize(*pages)
  @pages = pages
  @current_page = nil
  self.handle_all_events = true
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:



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

abstract_method :contents

#handle(event) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'library/cwm/src/lib/cwm/pager.rb', line 29

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

  return nil unless page

  return nil if @current_page.widget_id == new_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



24
25
26
27
# File 'library/cwm/src/lib/cwm/pager.rb', line 24

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



84
85
86
87
88
# File 'library/cwm/src/lib/cwm/pager.rb', line 84

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:



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

abstract_method :mark_page

#page_for_id(id) ⇒ Object (protected)



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

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



53
54
55
# File 'library/cwm/src/lib/cwm/pager.rb', line 53

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

#replace_pointObject (protected)



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

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

#store_pageObject (protected)

stores page with given id



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

def store_page
  replace_point.store
end

#switch_page(page) ⇒ Object (protected)

switch to target page



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

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