Class: CWM::CustomWidget

Inherits:
AbstractWidget show all
Defined in:
library/cwm/src/lib/cwm/custom_widget.rb

Overview

A custom widget that has its UI content defined in the method #contents. Useful mainly when a specialized widget including more subwidgets should be reusable at more places.

Examples:

custom widget child

class MyWidget < CWM::CustomWidget
  def contents
    HBox(
      MyPushButton.new,
      PushButton(Id(:undo), _("Undo"))
    )
  end

  def handle(event)
    case event["ID"]
    when :undo then ...
    else
      # handle for MyPushButton lives in that PushButton
    end
    nil
  end
end

Direct Known Subclasses

Page, Pager, ReplacePoint, Table, Tree

Instance Attribute Summary

Attributes inherited from AbstractWidget

#handle_all_events, #widget_id

Instance Method Summary collapse

Methods inherited from AbstractWidget

#cleanup, #disable, #enable, #enabled?, #handle, #help, #init, #label, #opt, #store, #validate, widget_type=

Instance Method Details

#contentsWidgetTerm

Must be defined by subclasses

Returns:

  • (WidgetTerm)

    a UI term that can include another AbstractWidgets

See Also:

  • CWM::CustomWidget.example/object_api_nestedexample/object_api_nested.rb


35
# File 'library/cwm/src/lib/cwm/custom_widget.rb', line 35

abstract_method :contents

#cwm_definitionWidgetHash

Returns:



38
39
40
41
42
43
44
# File 'library/cwm/src/lib/cwm/custom_widget.rb', line 38

def cwm_definition
  res = { "custom_widget" => cwm_contents }

  res["handle_events"] = ids_in_contents unless handle_all_events

  super.merge(res)
end