Sha256: 072edf8f7be6bd831d7da12af14aa8d25b6afe62785044b36f40c64017cedf16

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

require File.dirname(__FILE__) + "/observer"

class WidgetBinding
  include Observer

  attr_reader :widget, :property
  @@property_type_converters = {
    :text => Proc.new { |value| value.to_s },
    :items => Proc.new { |value| value.to_java :string},
    :visible => Proc.new { |value| !!value}
  }
  def initialize(model, property, translator = nil)
    @widget = model
    @property = property
    @translator = translator || proc {|value| value}
  end
  def update(value)
    converted_value = translated_value = @translator.call(value)
    converter = @@property_type_converters[@property.to_sym]
    converted_value = converter.call(translated_value) if converter
    @widget.widget.send("set#{@property.camelcase(:upper)}", converted_value) unless evaluate_property == converted_value
  end
  def evaluate_property
    @widget.widget.send(@property)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glimmer-0.2.5 lib/command_handlers/models/widget_binding.rb