Sha256: 37a0d7025f11c25e9ff4012300b0282c6b4bef671552395dc8f38db0913502be

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

# Glimmer - a JRuby DSL that enables easy and efficient authoring of user
# interfaces using the robust platform-independent Eclipse SWT library. Glimmer
# comes with built-in data-binding support to greatly facilitate synchronizing
# UI with domain models.

require "rubygems"
require "facets"
require "logger"
require "java"
require_relative "glimmer/parent"
require_relative "glimmer/swt_packages"

module Glimmer
   #TODO make it configurable to include or not include
  include SwtPackages
  def self.included(klass)
    klass.include SwtPackages
  end
  def self.extended(klass)
    klass.include SwtPackages
  end

  @@parent_stack = []
  @@logger = Logger.new(STDOUT).tap {|logger| logger.level = Logger::WARN}

  def self.logger
    @@logger
  end

  def self.method_missing(method_symbol, *args, &block)
    Glimmer.logger.debug "method: " + method_symbol.to_s + " and args: " + args.to_s
    command_handler_chain = CommandHandlerChainFactory.chain
    return_value = command_handler_chain.handle(@@parent_stack.last, method_symbol, *args, &block)
    add_contents(return_value, &block)
    return return_value
  end

  # TODO come up with a better public name for this and put on gwidgets directly
  def self.add_contents(parent, &block)
    @@parent_stack.push(parent) if parent.is_a?(Parent)
    @@parent_stack.last.process_block(block) if block and @@parent_stack.last
    @@parent_stack.pop if parent.is_a?(Parent)
  end

  def self.dsl(dsl)
    CommandHandlerChainFactory.select_dsl(dsl)
  end

  #added for convenience

  def method_missing(method_symbol, *args, &block)
    Glimmer.method_missing(method_symbol, *args, &block)
  end

  def add_contents(parent, &block)
    Glimmer.add_contents(parent, &block)
  end

  def dsl(dsl)
    CommandHandlerChainFactory.select_dsl(dsl)
  end
end

# Command handlers may rely on Glimmer, so this is put here to avoid an infinite loop.
require File.dirname(__FILE__) + "/glimmer/xml_command_handlers"
require File.dirname(__FILE__) + "/glimmer/command_handlers"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
glimmer-0.4.3 lib/glimmer.rb
glimmer-0.4.2 lib/glimmer.rb