repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 7 values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/bin/girb_runner.rb | bin/girb_runner.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'puts_debuggerer'
require_relative '../lib/glimmer-dsl-swt'
trap "SIGINT" do
# No Op for irb
end
include Glimmer
# Hijack Shell#start_event_loop default behavior to ensure disposing a display upon closing a shell inside girb
Glimmer::SWT::ShellProxy.class_eval do
alias start_event_loop_original start_event_loop
def start_event_loop
start_event_loop_original
Glimmer::SWT::DisplayProxy.instance.dispose
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/spec_helper.rb | spec/spec_helper.rb | ENV['APP_ENV'] = 'test'
require 'simplecov'
require 'simplecov-lcov'
require 'coveralls' if ENV['TRAVIS']
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
formatters = []
formatters << SimpleCov::Formatter::LcovFormatter
formatters << Coveralls::SimpleCov::Formatter if ENV['TRAVIS']
SimpleCov.formatters = formatters
SimpleCov.start do
add_filter(/^\/spec\//)
end
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'samples'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'puts_debuggerer' unless ENV['puts_debuggerer'] == 'false'
require 'glimmer-dsl-swt'
module GlimmerSpec
include Glimmer::SWT::Packages # makes SWT packages available to namespace containing specs
end
FIXTURES_PATH = File.expand_path('../fixtures', __FILE__)
ROOT_PATH = File.expand_path('../..', __FILE__)
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
# have no way to turn it off -- the option exists only for backwards
# compatibility in RSpec 3). It causes shared context metadata to be
# inherited by the metadata hash of host groups and examples, rather than
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups
config.after do
process_event_loop if @process_event_loop_before_target_dispose
@target.dispose if @target && @target.respond_to?(:dispose)
Glimmer::DSL::Engine.reset
end
# config.profile_examples = 20
# config.fail_fast = true
# config.formatter = 'documentation'
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# This allows you to limit a spec run to individual examples or groups
# you care about by tagging them with `:focus` metadata. When nothing
# is tagged with `:focus`, all examples get run. RSpec also provides
# aliases for `it`, `describe`, and `context` that include `:focus`
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
config.filter_run_when_matching :focus
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
config.disable_monkey_patching!
# This setting enables warnings. It's recommended, but in some cases may
# be too noisy due to issues in dependencies.
config.warnings = true
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
end
RSpec::Matchers.define :have_style do |style|
match do |widget|
begin
style_value = Glimmer::SWT::SWTProxy[style]
rescue
style_value = Glimmer::SWT::DNDProxy[style]
end
widget = widget.swt_widget if widget.respond_to?(:swt_widget)
expect(widget.getStyle & style_value).to eq(style_value)
end
end
# Enable when testing logging manually
# Glimmer::Config.logging_devices = [:stdout, :file, :syslog]
# Glimmer::Config.logger.level = :debug
def wait_until_table_data_binding_done(table)
process_event_loop
sleep(0.001) until table.table_items_binding.data_binding_done
end
def process_event_loop
sleep(0.01) while Glimmer::SWT::DisplayProxy.instance.swt_display.readAndDispatch
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/samples/elaborate/snake/model/game_spec.rb | spec/samples/elaborate/snake/model/game_spec.rb | require 'spec_helper'
require File.join(ROOT_PATH, 'samples/elaborate/snake/model/game')
RSpec.describe Snake::Model::Game do
it 'has a grid of vertebrae of width of 20 and height of 20' do
expect(subject).to be_a(Snake::Model::Game)
expect(subject.width).to eq(20)
expect(subject.height).to eq(20)
end
it 'starts game by generating snake and apple in random locations' do
subject.start
expect(subject).to_not be_over
expect(subject.score).to eq(0)
expect(subject.snake).to be_a(Snake::Model::Snake)
expect(subject.snake.length).to eq(1)
expect(subject.snake.head).to be_a(Snake::Model::Vertebra)
expect(subject.snake.head).to eq(subject.snake.vertebrae.last)
expect(subject.snake.head.row).to be_between(0, subject.height)
expect(subject.snake.head.column).to be_between(0, subject.width)
expect(Snake::Model::Vertebra::ORIENTATIONS).to include(subject.snake.head.orientation)
expect(subject.snake.length).to eq(1)
expect(subject.apple).to be_a(Snake::Model::Apple)
expect(subject.snake.vertebrae.map {|v| [v.row, v.column]}).to_not include([subject.apple.row, subject.apple.column])
expect(subject.apple.row).to be_between(0, subject.height)
expect(subject.apple.column).to be_between(0, subject.width)
end
it 'moves snake of length 1 east without going through a wall' do
direction = :east
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(0)
expect(subject.snake.head.orientation).to eq(direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
expect(subject.apple.row).to eq(10)
expect(subject.apple.column).to eq(10)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(1)
end
it 'moves snake of length 1 east going through a wall' do
direction = :east
subject.start
subject.snake.generate(initial_row: 0, initial_column: 19, initial_orientation: direction)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(19)
expect(subject.snake.head.orientation).to eq(direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
expect(subject.apple.row).to eq(10)
expect(subject.apple.column).to eq(10)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(0)
end
it 'moves snake of length 1 west without going through a wall' do
direction = :west
subject.start
subject.snake.generate(initial_row: 0, initial_column: 19, initial_orientation: direction)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(19)
expect(subject.snake.head.orientation).to eq(direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
expect(subject.apple.row).to eq(10)
expect(subject.apple.column).to eq(10)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(18)
end
it 'moves snake of length 1 west going through a wall' do
direction = :west
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(0)
expect(subject.snake.head.orientation).to eq(direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
expect(subject.apple.row).to eq(10)
expect(subject.apple.column).to eq(10)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(19)
end
it 'moves snake of length 1 south without going through a wall' do
direction = :south
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(0)
expect(subject.snake.head.orientation).to eq(direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
expect(subject.apple.row).to eq(10)
expect(subject.apple.column).to eq(10)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(1)
expect(subject.snake.head.column).to eq(0)
end
it 'moves snake of length 1 south going through a wall' do
direction = :south
subject.start
subject.snake.generate(initial_row: 19, initial_column: 0, initial_orientation: direction)
expect(subject.snake.head.row).to eq(19)
expect(subject.snake.head.column).to eq(0)
expect(subject.snake.head.orientation).to eq(direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
expect(subject.apple.row).to eq(10)
expect(subject.apple.column).to eq(10)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(0)
end
it 'moves snake of length 1 north without going through a wall' do
direction = :north
subject.start
subject.snake.generate(initial_row: 19, initial_column: 0, initial_orientation: direction)
expect(subject.snake.head.row).to eq(19)
expect(subject.snake.head.column).to eq(0)
expect(subject.snake.head.orientation).to eq(direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
expect(subject.apple.row).to eq(10)
expect(subject.apple.column).to eq(10)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(18)
expect(subject.snake.head.column).to eq(0)
end
it 'moves snake of length 1 north going through a wall' do
direction = :north
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
expect(subject.snake.head.row).to eq(0)
expect(subject.snake.head.column).to eq(0)
expect(subject.snake.head.orientation).to eq(direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
expect(subject.apple.row).to eq(10)
expect(subject.apple.column).to eq(10)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(19)
expect(subject.snake.head.column).to eq(0)
end
it 'starts snake going east, moves, turns right south, and moves south' do
direction = :east
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
new_direction = :south
subject.snake.move
subject.snake.turn_right
expect(subject.snake.head.orientation).to eq(new_direction)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(1)
expect(subject.snake.head.column).to eq(1)
expect(subject.snake.head.orientation).to eq(new_direction)
end
it 'starts snake going west, moves, turns right north, and moves south' do
direction = :west
subject.start
subject.snake.generate(initial_row: 19, initial_column: 19, initial_orientation: direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
new_direction = :north
subject.snake.move
subject.snake.turn_right
expect(subject.snake.head.orientation).to eq(new_direction)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(18)
expect(subject.snake.head.column).to eq(18)
expect(subject.snake.head.orientation).to eq(new_direction)
end
it 'starts snake going south, moves, turns right west, and moves south' do
direction = :south
subject.start
subject.snake.generate(initial_row: 0, initial_column: 19, initial_orientation: direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
new_direction = :west
subject.snake.move
subject.snake.turn_right
expect(subject.snake.head.orientation).to eq(new_direction)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(1)
expect(subject.snake.head.column).to eq(18)
expect(subject.snake.head.orientation).to eq(new_direction)
end
it 'starts snake going north, moves, turns right east, and moves south' do
direction = :north
subject.start
subject.snake.generate(initial_row: 19, initial_column: 0, initial_orientation: direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
new_direction = :east
subject.snake.move
subject.snake.turn_right
expect(subject.snake.head.orientation).to eq(new_direction)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(18)
expect(subject.snake.head.column).to eq(1)
expect(subject.snake.head.orientation).to eq(new_direction)
end
it 'starts snake going east, moves, turns left north, and moves south' do
direction = :east
subject.start
subject.snake.generate(initial_row: 19, initial_column: 0, initial_orientation: direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
new_direction = :north
subject.snake.move
subject.snake.turn_left
expect(subject.snake.head.orientation).to eq(new_direction)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(18)
expect(subject.snake.head.column).to eq(1)
expect(subject.snake.head.orientation).to eq(new_direction)
end
it 'starts snake going west, moves, turns left south, and moves south' do
direction = :west
subject.start
subject.snake.generate(initial_row: 0, initial_column: 19, initial_orientation: direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
new_direction = :south
subject.snake.move
subject.snake.turn_left
expect(subject.snake.head.orientation).to eq(new_direction)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(1)
expect(subject.snake.head.column).to eq(18)
expect(subject.snake.head.orientation).to eq(new_direction)
end
it 'starts snake going south, moves, turns left east, and moves south' do
direction = :south
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
new_direction = :east
subject.snake.move
subject.snake.turn_left
expect(subject.snake.head.orientation).to eq(new_direction)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(1)
expect(subject.snake.head.column).to eq(1)
expect(subject.snake.head.orientation).to eq(new_direction)
end
it 'starts snake going north, moves, turns left west, and moves south' do
direction = :north
subject.start
subject.snake.generate(initial_row: 19, initial_column: 19, initial_orientation: direction)
subject.apple.generate(initial_row: 10, initial_column: 10)
new_direction = :west
subject.snake.move
subject.snake.turn_left
expect(subject.snake.head.orientation).to eq(new_direction)
subject.snake.move
expect(subject.snake.length).to eq(1)
expect(subject.snake.head.row).to eq(18)
expect(subject.snake.head.column).to eq(18)
expect(subject.snake.head.orientation).to eq(new_direction)
end
it 'starts snake going east, moves, turns right south, and eats apple while moving south' do
direction = :east
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
subject.apple.generate(initial_row: 1, initial_column: 1)
new_direction = :south
subject.snake.move
subject.snake.turn_right
subject.snake.move
expect(subject.snake.length).to eq(2)
expect(subject.snake.vertebrae[0].row).to eq(0)
expect(subject.snake.vertebrae[0].column).to eq(1)
expect(subject.snake.vertebrae[0].orientation).to eq(new_direction)
expect(subject.snake.vertebrae[1].row).to eq(1)
expect(subject.snake.vertebrae[1].column).to eq(1)
expect(subject.snake.vertebrae[1].orientation).to eq(new_direction)
end
it 'starts snake going east, moves, turns right south, eats apple while moving south, turns left, eats apple while moving east' do
direction = :east
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
subject.apple.generate(initial_row: 1, initial_column: 1)
subject.snake.move
subject.snake.turn_right
subject.snake.move # eats apple
subject.apple.generate(initial_row: 1, initial_column: 2)
subject.snake.turn_left
subject.snake.move # eats apple
expect(subject.snake.length).to eq(3)
expect(subject.snake.vertebrae[0].row).to eq(0)
expect(subject.snake.vertebrae[0].column).to eq(1)
expect(subject.snake.vertebrae[0].orientation).to eq(:south)
expect(subject.snake.vertebrae[1].row).to eq(1)
expect(subject.snake.vertebrae[1].column).to eq(1)
expect(subject.snake.vertebrae[1].orientation).to eq(:east)
expect(subject.snake.vertebrae[2].row).to eq(1)
expect(subject.snake.vertebrae[2].column).to eq(2)
expect(subject.snake.vertebrae[2].orientation).to eq(:east)
end
it 'starts snake going east, moves, turns right south, eats apple while moving south, turns left, eats apple while moving east, turns right, moves south' do
direction = :east
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
subject.apple.generate(initial_row: 1, initial_column: 1)
subject.snake.move
subject.snake.turn_right
subject.snake.move # eats apple
subject.apple.generate(initial_row: 1, initial_column: 2)
subject.snake.turn_left
subject.snake.move # eats apple
subject.apple.generate(initial_row: 10, initial_column: 10)
subject.snake.turn_right
subject.snake.move
expect(subject.snake.length).to eq(3)
expect(subject.snake.vertebrae[0].row).to eq(1)
expect(subject.snake.vertebrae[0].column).to eq(1)
expect(subject.snake.vertebrae[0].orientation).to eq(:east)
expect(subject.snake.vertebrae[1].row).to eq(1)
expect(subject.snake.vertebrae[1].column).to eq(2)
expect(subject.snake.vertebrae[1].orientation).to eq(:south)
expect(subject.snake.vertebrae[2].row).to eq(2)
expect(subject.snake.vertebrae[2].column).to eq(2)
expect(subject.snake.vertebrae[2].orientation).to eq(:south)
end
it 'starts snake going east, moves, turns right south, eats apple while moving south, turns left, eats apple while moving east, turns left, eats apple while moving north, turns left, collides while moving west and game is over' do
direction = :east
subject.start
subject.snake.generate(initial_row: 0, initial_column: 0, initial_orientation: direction)
subject.apple.generate(initial_row: 1, initial_column: 1)
subject.snake.move # 0, 1
subject.snake.turn_right
subject.snake.move # 1, 1 eats apple
subject.apple.generate(initial_row: 1, initial_column: 2)
subject.snake.turn_left
subject.snake.move # 1, 2 eats apple
subject.apple.generate(initial_row: 1, initial_column: 3)
subject.snake.move # 1, 3 eats apple
subject.apple.generate(initial_row: 1, initial_column: 4)
subject.snake.move # 1, 4 eats apple
subject.snake.turn_left
subject.snake.move # 0, 4
subject.snake.turn_left
subject.snake.move # 0, 3
subject.snake.turn_left
subject.snake.move # 1, 3 (collision)
expect(subject).to be_over
expect(subject.score).to eq(50 * 4)
expect(subject.snake).to be_collided
expect(subject.snake.length).to eq(5)
expect(subject.snake.vertebrae[0].row).to eq(1)
expect(subject.snake.vertebrae[0].column).to eq(2)
expect(subject.snake.vertebrae[0].orientation).to eq(:east)
expect(subject.snake.vertebrae[1].row).to eq(1)
expect(subject.snake.vertebrae[1].column).to eq(3)
expect(subject.snake.vertebrae[1].orientation).to eq(:east)
expect(subject.snake.vertebrae[2].row).to eq(1)
expect(subject.snake.vertebrae[2].column).to eq(4)
expect(subject.snake.vertebrae[2].orientation).to eq(:north)
expect(subject.snake.vertebrae[3].row).to eq(0)
expect(subject.snake.vertebrae[3].column).to eq(4)
expect(subject.snake.vertebrae[3].orientation).to eq(:west)
expect(subject.snake.vertebrae[4].row).to eq(0)
expect(subject.snake.vertebrae[4].column).to eq(3)
expect(subject.snake.vertebrae[4].orientation).to eq(:south)
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/samples/elaborate/tic_tac_toe/board_spec.rb | spec/samples/elaborate/tic_tac_toe/board_spec.rb | require "spec_helper"
require File.join(ROOT_PATH, 'samples/elaborate/tic_tac_toe/board')
class TicTacToe
describe Board do
before do
@board = TicTacToe::Board.new
end
it "tests mark_center_x" do
expect(@board[2, 2].sign).to eq("")
@board.mark(2, 2)
expect(@board[2, 2].empty).to be_falsey
expect(@board[2, 2].sign).to eq("X")
expect(@board[1, 1].empty).to be_truthy
expect(@board[1, 2].empty).to be_truthy
expect(@board[1, 3].empty).to be_truthy
expect(@board[2, 1].empty).to be_truthy
expect(@board[2, 3].empty).to be_truthy
expect(@board[3, 1].empty).to be_truthy
expect(@board[3, 2].empty).to be_truthy
expect(@board[3, 3].empty).to be_truthy
end
it "tests mark_center_x_top_center_o_bottom_right_x" do
@board.mark(2, 2)
@board.mark(1, 2)
@board.mark(3, 3)
expect(@board[2, 2].empty).to be_falsey
expect(@board[1, 2].empty).to be_falsey
expect(@board[3, 3].empty).to be_falsey
expect(@board[2, 2].sign).to eq("X")
expect(@board[1, 2].sign).to eq("O")
expect(@board[3, 3].sign).to eq("X")
end
it "tests top_center_not_marked" do
expect(@board[1, 2].empty).to be_truthy
end
it "tests top_right_marked" do
@board.mark(1, 3)
expect(@board[1, 3].empty).to be_falsey
end
it "tests lower_right_marked" do
@board.mark(3, 3)
expect(@board[3, 3].empty).to be_falsey
end
it "tests game_over_false" do
expect(@board.game_over?).to be_falsey
expect(@board.current_sign).to eq("X")
expect(@board.game_status).to eq(Board::IN_PROGRESS)
end
it "tests game_over_X_wins_top_row_across" do
@board.mark(1, 1)
expect(@board[1, 1].sign).to eq("X")
@board.mark(2, 1)
expect(@board[2, 1].sign).to eq("O")
@board.mark(1, 2)
expect(@board[1, 2].sign).to eq("X")
@board.mark(2, 2)
expect(@board[2, 2].sign).to eq("O")
@board.mark(1, 3)
expect(@board[1, 3].sign).to eq("X")
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("X")
expect(@board.game_status).to eq(Board::WIN)
end
it "tests game_over_O_wins_top_row_across" do
@board.mark(2, 1)
@board.mark(1, 1)
@board.mark(2, 2)
@board.mark(1, 2)
@board.mark(3, 3)
@board.mark(1, 3)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("O")
end
it "tests game_over_X_wins_second_row_across" do
@board.mark(2, 1)
@board.mark(1, 1)
@board.mark(2, 2)
@board.mark(1, 2)
@board.mark(2, 3)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("X")
end
it "tests game_over_O_wins_second_row_across" do
@board.mark(1, 1)
@board.mark(2, 1)
@board.mark(3, 1)
@board.mark(2, 2)
@board.mark(1, 2)
@board.mark(2, 3)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("O")
end
it "tests game_over_X_wins_third_row_across" do
@board.mark(3, 1)
@board.mark(1, 1)
@board.mark(3, 2)
@board.mark(1, 2)
@board.mark(3, 3)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("X")
end
it "tests game_over_O_wins_third_row_across" do
@board.mark(1, 1)
@board.mark(3, 1)
@board.mark(1, 2)
@board.mark(3, 2)
@board.mark(2, 3)
@board.mark(3, 3)
expect(@board.game_over?).to be_truthy
end
it "tests game_over_X_wins_first_column_down" do
@board.mark(1, 1)
@board.mark(2, 2)
@board.mark(2, 1)
@board.mark(3, 2)
@board.mark(3, 1)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("X")
end
it "tests game_over_O_wins_first_column_down" do
@board.mark(2, 2)
@board.mark(1, 1)
@board.mark(3, 2)
@board.mark(2, 1)
@board.mark(3, 3)
@board.mark(3, 1)
expect(@board.game_over?).to be_truthy
end
it "tests game_over_X_wins_second_column_down" do
@board.mark(1, 2)
@board.mark(2, 1)
@board.mark(2, 2)
@board.mark(3, 1)
@board.mark(3, 2)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("X")
end
it "tests game_over_O_wins_second_column_down" do
@board.mark(2, 1)
@board.mark(1, 2)
@board.mark(3, 1)
@board.mark(2, 2)
@board.mark(2, 3)
@board.mark(3, 2)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("O")
end
it "tests game_over_X_wins_third_column_down" do
@board.mark(1, 3)
@board.mark(2, 1)
@board.mark(2, 3)
@board.mark(3, 1)
@board.mark(3, 3)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("X")
end
it "tests game_over_O_wins_third_column_down" do
@board.mark(2, 1)
@board.mark(1, 3)
@board.mark(3, 1)
@board.mark(2, 3)
@board.mark(3, 2)
@board.mark(3, 3)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq("O")
end
it "tests game_over_X_wins_top_left_to_bottom_right" do
@board.mark(1, 1)
@board.mark(2, 1)
@board.mark(2, 2)
@board.mark(3, 2)
@board.mark(3, 3)
expect(@board.winning_sign).to eq("X")
expect(@board.game_over?).to be_truthy
end
it "tests game_over_O_wins_top_left_to_bottom_right" do
@board.mark(2, 1)
@board.mark(1, 1)
@board.mark(3, 2)
@board.mark(2, 2)
@board.mark(2, 3)
@board.mark(3, 3)
expect(@board.winning_sign).to eq("O")
expect(@board.game_over?).to be_truthy
end
it "tests game_over_X_wins_top_right_to_bottom_left" do
@board.mark(1, 3)
@board.mark(2, 1)
@board.mark(2, 2)
@board.mark(3, 2)
@board.mark(3, 1)
expect(@board.winning_sign).to eq("X")
expect(@board.game_over?).to be_truthy
end
it "tests game_over_O_wins_top_right_to_bottom_left" do
@board.mark(2, 1)
@board.mark(1, 3)
@board.mark(3, 2)
@board.mark(2, 2)
@board.mark(1, 1)
@board.mark(3, 1)
expect(@board.winning_sign).to eq("O")
expect(@board.game_over?).to be_truthy
end
# 1 2 3
#1 x o x
#2 o x x
#3 o x o
it "tests game_over_draw" do
@board.mark(1, 1)
@board.mark(1, 2)
@board.mark(1, 3)
@board.mark(2, 1)
@board.mark(2, 2)
@board.mark(3, 1)
@board.mark(2, 3)
@board.mark(3, 3)
expect(@board.game_over?).to be_falsey
@board.mark(3, 2)
expect(@board.game_over?).to be_truthy
expect(@board.winning_sign).to eq(Cell::EMPTY)
expect(@board.game_status).to eq(Board::DRAW)
end
it "tests reset" do
@board.mark(1, 3)
@board.mark(2, 1)
@board.mark(2, 2)
@board.mark(3, 2)
@board.reset!
expect(@board.game_over?).to be_falsey
expect(@board.winning_sign).to eq(Cell::EMPTY)
expect(@board.game_status).to eq(Board::IN_PROGRESS)
expect(@board.current_sign).to eq("X")
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/samples/elaborate/contact_manager/contact_manager_presenter_spec.rb | spec/samples/elaborate/contact_manager/contact_manager_presenter_spec.rb | require "spec_helper"
require File.join(ROOT_PATH, 'samples/elaborate/contact_manager/contact_manager_presenter')
require File.join(ROOT_PATH, 'samples/elaborate/contact_manager/contact')
class ContactManager
describe ContactManagerPresenter do
let(:contacts) do
[
Contact.new(:first_name => "Anne", :last_name => "Sweeney", :email => "anne@sweeny.com"),
Contact.new(:first_name => "Beatrice", :last_name => "Jung", :email => "beatrice@jung.com"),
Contact.new(:first_name => "Frank", :last_name => "Deelio", :email => "frank@deelio.com"),
Contact.new(:first_name => "franky", :last_name => "miller", :email => "frank@miller.com"),
]
end
let(:contact_repository) { ContactRepository.new(contacts) }
subject(:contact_manager_presenter) { ContactManagerPresenter.new(contact_repository) }
it "tests find_specify_all_fields_for_one_result" do
contact_manager_presenter.first_name = "Frank"
contact_manager_presenter.last_name = "Deelio"
contact_manager_presenter.email = "frank@deelio.com"
contact_manager_presenter.find
contacts = contact_manager_presenter.results
expect(contacts).to_not be_nil
expect(contacts.size).to eq( 1)
contact = contacts[0]
expect(contact.is_a?(Contact)).to be_truthy
expect(contact.first_name).to eq( "Frank")
expect(contact.last_name).to eq( "Deelio")
expect(contact.email).to eq( "frank@deelio.com")
end
it "tests find_specify_one_field_for_two_results" do
contact_manager_presenter.first_name = "Frank"
contact_manager_presenter.find
contacts = contact_manager_presenter.results
expect(contacts).to_not be_nil
expect(contacts.size).to eq( 2)
contact1 = contacts[0]
contact2 = contacts[1]
expect(contact1.first_name).to eq( "Frank")
expect(contact1.last_name).to eq( "Deelio")
expect(contact1.email).to eq( "frank@deelio.com")
expect(contact2.first_name).to eq( "franky")
expect(contact2.last_name).to eq( "miller")
expect(contact2.email).to eq( "frank@miller.com")
end
it "tests find_specify_all_fields_for_no_results" do
contact_manager_presenter.first_name = "Julia"
contact_manager_presenter.last_name = "Big"
contact_manager_presenter.email = "julia@big.com"
contact_manager_presenter.find
contacts = contact_manager_presenter.results
expect(contacts).to_not be_nil
expect(contacts.size).to eq( 0)
end
it "tests find_specify_no_fields_for_all_results" do
contact_manager_presenter.find
contacts = contact_manager_presenter.results
expect(contacts).to_not be_nil
expect(contacts.size).to eq( 4)
expect(contacts[0].first_name).to eq( "Anne")
expect(contacts[1].first_name).to eq( "Beatrice")
expect(contacts[2].first_name).to eq( "Frank")
expect(contacts[3].first_name).to eq( "franky")
end
it "tests list_all_results" do
contact_manager_presenter.list
contacts = contact_manager_presenter.results
expect(contacts).to_not be_nil
expect(contacts.size).to eq( 4)
expect(contacts[0].first_name).to eq( "Anne")
expect(contacts[1].first_name).to eq( "Beatrice")
expect(contacts[2].first_name).to eq( "Frank")
expect(contacts[3].first_name).to eq( "franky")
end
it "tests initial_results" do
contacts = contact_manager_presenter.results
expect(contacts).to_not be_nil
expect(contacts.size).to eq( 0)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/samples/elaborate/game_of_life/model/grid_spec.rb | spec/samples/elaborate/game_of_life/model/grid_spec.rb | require 'spec_helper'
require File.join(ROOT_PATH, 'samples/elaborate/game_of_life/model/grid')
class GameOfLife
module Model
describe Grid do
describe '#new' do
let(:row_count_default) {100}
let(:column_count_default) {100}
let(:row_count) {20}
let(:column_count) {10}
it 'constructs a grid of 100x100 cells by default' do
grid = described_class.new
expect(grid.cell_rows.count).to eq(row_count_default)
row_count_default.times do |row_index|
row = grid.cell_rows[row_index]
expect(row).to be_a(Array)
expect(row.count).to eq(column_count_default)
column_count_default.times do |column_index|
cell = row[column_index]
expect(cell).to be_a(Cell)
expect(cell.row_index).to eq(row_index)
expect(cell.column_index).to eq(column_index)
expect(cell.grid).to eq(grid)
end
end
end
it 'constructs a grid of 20x10 cells by arguments' do
grid = described_class.new(row_count, column_count)
expect(grid.cell_rows.count).to eq(row_count)
row_count.times do |row_index|
row = grid.cell_rows[row_index]
expect(row).to be_a(Array)
expect(row.count).to eq(column_count)
column_count.times do |column_index|
cell = row[column_index]
expect(cell).to be_a(Cell)
expect(cell.row_index).to eq(row_index)
expect(cell.column_index).to eq(column_index)
expect(cell.grid).to eq(grid)
end
end
end
end
describe '#live!' do
it 'makes a dead cell alive' do
cell = subject.cell_rows[0][0]
expect(cell.alive?).to be_falsey
expect(cell.dead?).to be_truthy
cell.live!
expect(cell.alive?).to be_truthy
expect(cell.dead?).to be_falsey
end
end
describe '#die!' do
it 'makes a live cell dead' do
cell = subject.cell_rows[0][0]
cell.live!
expect(cell.alive?).to be_truthy
expect(cell.dead?).to be_falsey
cell.die!
expect(cell.alive?).to be_falsey
expect(cell.dead?).to be_truthy
end
end
describe '#step!' do
context 'live cell with fewer than 2 live neighbors' do
it 'dies when inside and has zero live neighbors' do
cell = subject.cell_rows[1][1]
cell.live!
subject.step!
cell = subject.cell_rows[1][1]
expect(cell.alive?).to be_falsey
end
it 'dies when inside and has one live neighbor' do
cell = subject.cell_rows[1][1]
cell.live!
cell_neighbor1 = subject.cell_rows[0][1]
cell_neighbor1.live!
subject.step!
cell = subject.cell_rows[1][1]
expect(cell.alive?).to be_falsey
end
it 'dies when in a corner and has zero live neighbors' do
cell = subject.cell_rows[0][0]
cell.live!
subject.step!
cell = subject.cell_rows[0][0]
expect(cell.alive?).to be_falsey
end
it 'dies when in a corner and has one live neighbor' do
cell = subject.cell_rows[0][0]
cell.live!
cell_neighbor1 = subject.cell_rows[0][1]
cell_neighbor1.live!
subject.step!
cell = subject.cell_rows[0][0]
expect(cell.alive?).to be_falsey
end
it 'dies when in top edge and has zero live neighbors' do
cell = subject.cell_rows[0][1]
cell.live!
subject.step!
cell = subject.cell_rows[0][1]
expect(cell.alive?).to be_falsey
end
it 'dies when in top edge and has one live neighbor' do
cell = subject.cell_rows[0][1]
cell.live!
cell_neighbor1 = subject.cell_rows[0][0]
cell_neighbor1.live!
subject.step!
cell = subject.cell_rows[0][1]
expect(cell.alive?).to be_falsey
end
end
context 'live cell with 2-3 live neighbors' do
it 'lives when inside and has two live neighbors' do
cell = subject.cell_rows[1][1]
cell.live!
cell_neighbor1 = subject.cell_rows[0][1]
cell_neighbor1.live!
cell_neighbor2 = subject.cell_rows[1][0]
cell_neighbor2.live!
subject.step!
cell = subject.cell_rows[1][1]
expect(cell.alive?).to be_truthy
end
end
context 'live cell with 4 or more live neighbors' do
it 'dies when inside and has 4 live neighbors' do
cell = subject.cell_rows[1][1]
cell.live!
cell_neighbor1 = subject.cell_rows[0][1]
cell_neighbor1.live!
cell_neighbor2 = subject.cell_rows[1][0]
cell_neighbor2.live!
cell_neighbor3 = subject.cell_rows[0][0]
cell_neighbor3.live!
cell_neighbor4 = subject.cell_rows[2][2]
cell_neighbor4.live!
subject.step!
cell = subject.cell_rows[1][1]
expect(cell.alive?).to be_falsey
end
end
context 'dead cell with 3 live neighbors' do
it 'lives when inside and has 3 live neighbors' do
cell = subject.cell_rows[1][1]
cell_neighbor1 = subject.cell_rows[0][1]
cell_neighbor1.live!
cell_neighbor2 = subject.cell_rows[1][0]
cell_neighbor2.live!
cell_neighbor3 = subject.cell_rows[0][0]
cell_neighbor3.live!
subject.step!
cell = subject.cell_rows[1][1]
expect(cell.alive?).to be_truthy
end
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__exec__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__exec__spec.rb | require "spec_helper"
module GlimmerSpec
context 'UI code execution' do
include Glimmer
after do
if @target
@target.async_exec do
@target.dispose
end
@target.start_event_loop
end
end
it 'asyncronously executes UI code' do
@target = shell {
@text = text {
text "text1"
}
}
async_exec do
@text.swt_widget.setText("text2")
end
expect(@text.swt_widget.getText).to_not eq("text2")
async_exec do
expect(@text.swt_widget.getText).to eq("text2")
end
end
it "syncronously executes UI code" do
@target = shell {
@text = text {
text "text1"
}
}
async_exec do
expect(@text.swt_widget.getText).to eq("text2")
end
# This takes prioerity over async_exec
sync_exec do
@text.swt_widget.setText("text2")
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__swt__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__swt__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer swt" do
include Glimmer
it 'returns SWT constant value for a single symbol' do
expect(swt(:center)).to eq(SWT::CENTER)
end
it 'returns SWT constant value for a single string' do
expect(swt('center')).to eq(SWT::CENTER)
end
it 'returns SWT constant value for a multiple symbols' do
expect(swt(:center, :border)).to eq(SWT::CENTER | SWT::BORDER)
end
it 'returns SWT constant value for a multiple strings' do
expect(swt('center', 'border')).to eq(SWT::CENTER | SWT::BORDER)
end
it 'errors out when passed no values' do
expect{swt}.to raise_error(Glimmer::Error)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__color__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__color__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Color" do
include Glimmer
it "tests label with RGBAlpha background/foreground color" do
@foreground = rgba(4, 40, 244, 50) # get singleton display
@foreground_color = @foreground.swt_color
@target = shell {
@label = label {
background rgba(4, 40, 244, 50) # get parent display
foreground @foreground_color # set as SWT Color object
}
}
color = @label.swt_widget.getBackground
expect(color.getRed).to eq(4)
expect(color.getGreen).to eq(40)
expect(color.getBlue).to eq(244)
expect(color.getAlpha).to eq(50)
expect(@foreground_color.getRed).to eq(4)
expect(@foreground_color.getGreen).to eq(40)
expect(@foreground_color.getBlue).to eq(244)
expect(@foreground_color.getAlpha).to eq(50)
expect(@foreground_color.getDevice).to eq(Glimmer::SWT::DisplayProxy.instance.swt_display)
expect(@foreground.getRed).to eq(4)
expect(@foreground.getGreen).to eq(40)
expect(@foreground.getBlue).to eq(244)
expect(@foreground.getAlpha).to eq(50)
expect(@foreground.getDevice).to eq(Glimmer::SWT::DisplayProxy.instance.swt_display)
end
it "tests label with RGB (no alpha) background/foreground color" do
@foreground = rgb(4, 40, 244) # get singleton display
@foreground_color = @foreground.swt_color
@target = shell {
@label = label {
background rgb(4, 40, 244) # get parent display
foreground @foreground_color # set as SWT Color object
}
}
color = @label.swt_widget.getBackground
expect(color.getRed).to eq(4)
expect(color.getGreen).to eq(40)
expect(color.getBlue).to eq(244)
expect(@foreground_color.getRed).to eq(4)
expect(@foreground_color.getGreen).to eq(40)
expect(@foreground_color.getBlue).to eq(244)
expect(@foreground_color.getDevice).to eq(Glimmer::SWT::DisplayProxy.instance.swt_display)
expect(@foreground_color.getDevice).to eq(Glimmer::SWT::DisplayProxy.instance.swt_display)
end
# Standard colors: not an exhaustive list. Sample taken from here: https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/SWT.html
[
:color_black,
'color_magenta',
:black,
'magenta',
].each do |standard_color|
it "tests label with standard #{standard_color} background color passed as a Ruby symbol" do
@target = shell {
@label = label {
background color(standard_color)
foreground color(standard_color)
}
}
background = @label.swt_widget.getBackground
foreground = @label.swt_widget.getForeground
swt_color_constant = Glimmer::SWT::SWTProxy['color_' + standard_color.to_s.sub(/^color_/, '')]
expected_color = Glimmer::SWT::DisplayProxy.instance.swt_display.getSystemColor(swt_color_constant)
expect(background).to eq(expected_color)
expect(foreground).to eq(expected_color)
end
end
it "tests label with RGBA background color without a display nor a parent" do
@background = rgba(4, 40, 244, 100)
@target = shell {
@label = label {
background @background
}
}
color = @label.swt_widget.getBackground
expect(color.getRed).to eq(4)
expect(color.getGreen).to eq(40)
expect(color.getBlue).to eq(244)
expect(color.getAlpha).to eq(100)
end
it "tests label with RGB background color without a display nor a parent" do
@background = rgba(4, 40, 244)
@target = shell {
@label = label {
background @background
}
}
color = @label.swt_widget.getBackground
expect(color.getRed).to eq(4)
expect(color.getGreen).to eq(40)
expect(color.getBlue).to eq(244)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__table__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__table__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Table Data Binding" do
include Glimmer
before(:all) do
class PersonCommunity
attr_accessor :groups
def initialize
@groups = []
end
end
class PersonGroup
attr_accessor :people
attr_accessor :selected_person
attr_accessor :selected_people
def initialize
@people = []
end
end
class Person
attr_accessor :name, :age, :adult, :dob, :salary
def formatted_dob
dob.strftime("%Y-%m-%d %I:%M:%S %p")
end
def name_options
["Ava Fang", "Bruce Ting", "Julia Fang"]
end
def last_name_options
name_options.map {|n| n.split.last}
end
def last_name
name.split.last
end
def last_name=(a_last_name)
self.name = name_options.detect { |n| n.split.last == a_last_name }
end
end
class ::RedTable
include Glimmer::UI::CustomWidget
body {
table(swt_style) {
background :red
}
}
end
end
after(:all) do
%w[
PersonCommunity
PersonGroup
Person
RedTable
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
before do
@process_event_loop_before_target_dispose = true
end
let(:person1) do
Person.new.tap do |person|
person.name = 'Bruce Ting'
person.age = 45
person.adult = true
person.dob = ::DateTime.new(1950, 4, 17, 13, 3, 55)
person.salary = 133000.50
end
end
let(:person2) do
Person.new.tap do |person|
person.name = 'Julia Fang'
person.age = 17
person.adult = false
person.dob = ::DateTime.new(1978, 11, 27, 22, 47, 25)
person.salary = 99000.7
end
end
let(:person3) do
Person.new.tap do |person|
person.name = 'Ava Fang'
person.age = 17
person.adult = false
person.dob = ::DateTime.new(1978, 11, 27, 22, 47, 25)
person.salary = 99000.7
end
end
let(:person4) do
Person.new.tap do |person|
person.name = 'Ava Fang'
person.age = 16
person.adult = false
person.dob = ::DateTime.new(1978, 11, 27, 22, 47, 25)
person.salary = 89000.7
end
end
let(:selected_person) { person2 }
let(:selected_people) { [person1, person2] }
let(:group) do
PersonGroup.new.tap do |g|
g.people << person1
g.people << person2
g.selected_person = selected_person
g.selected_people = selected_people
end
end
let(:community) do
PersonCommunity.new.tap do |c|
c.groups << group
end
end
context 'data-binding' do
context 'read' do
it 'data binds table items with inferred column properties by convention (no column_properties specified)' do
@target = shell {
@table = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items <= [group, :people]
}
@table_nested_indexed = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items <= [community, "groups[0].people"]
}
}
wait_until_table_data_binding_done(@table)
wait_until_table_data_binding_done(@table_nested_indexed)
expect(@table.swt_widget.getColumnCount).to eq(3)
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
expect(@table_nested_indexed.swt_widget.getColumnCount).to eq(3)
expect(@table_nested_indexed.swt_widget.getItems.size).to eq(2)
expect(@table_nested_indexed.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table_nested_indexed.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table_nested_indexed.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table_nested_indexed.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table_nested_indexed.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table_nested_indexed.swt_widget.getItems[1].getText(2)).to eq("false")
person3 = Person.new
person3.name = "Andrea Sherlock"
person3.age = 23
person3.adult = true
group.people << person3
expect(@table.swt_widget.getItems.size).to eq(3)
expect(@table.swt_widget.getItems[2].getText(0)).to eq("Andrea Sherlock")
expect(@table.swt_widget.getItems[2].getText(1)).to eq("23")
expect(@table.swt_widget.getItems[2].getText(2)).to eq("true")
person3.name = "Andrea Sherloque"
person3.age = 13
person3.adult = false
expect(@table.swt_widget.getItems[2].getText(0)).to eq("Andrea Sherloque")
expect(@table.swt_widget.getItems[2].getText(1)).to eq("13")
expect(@table.swt_widget.getItems[2].getText(2)).to eq("false")
group.people.delete person2
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Andrea Sherloque")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("13")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
group.people.delete_at(0)
expect(@table.swt_widget.getItems.size).to eq(1)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Andrea Sherloque")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("13")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("false")
group.people.clear
expect(0).to eq(@table.swt_widget.getItems.size)
group.people = [person2, person1]
expect(2).to eq(@table.swt_widget.getItems.size)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("false")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("true")
person1.name = "Bruce Flee"
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Bruce Flee")
end
it 'data binds table items with column_properties array value' do
@target = shell {
@table = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items <= [group, :people, column_properties: [:name, :age, :adult]]
}
}
wait_until_table_data_binding_done(@table)
expect(@table.swt_widget.getColumnCount).to eq(3)
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
end
it "data binds table items with column_properties hash value" do
@target = shell {
@table = table {
table_column {
text "Full Name"
width 120
}
table_column {
text "Age in Years"
width 120
}
table_column {
text "Adult"
width 120
}
items <= [group, :people, column_properties: {'Full Name' => :name, 'Age in Years' => 'age'}]
}
}
wait_until_table_data_binding_done(@table)
expect(@table.swt_widget.getColumnCount).to eq(3)
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
end
it "data binds table items with column_attributes alias for column_properties" do
@target = shell {
@table = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items <= [group, :people, column_properties: [:name, :age, :adult]]
}
}
wait_until_table_data_binding_done(@table)
expect(@table.swt_widget.getColumnCount).to eq(3)
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
end
end
context 'read with alternate syntax passing column_properties/column_attributes as an option to bind' do
it "data binds table items" do
@target = shell {
@table = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items bind(group, :people, column_properties: [:name, :age, :adult])
}
@table_nested_indexed = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items bind(community, "groups[0].people", column_attributes: [:name, :age, :adult])
}
}
wait_until_table_data_binding_done(@table)
wait_until_table_data_binding_done(@table_nested_indexed)
expect(@table.swt_widget.getColumnCount).to eq(3)
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
expect(@table_nested_indexed.swt_widget.getColumnCount).to eq(3)
expect(@table_nested_indexed.swt_widget.getItems.size).to eq(2)
expect(@table_nested_indexed.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table_nested_indexed.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table_nested_indexed.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table_nested_indexed.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table_nested_indexed.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table_nested_indexed.swt_widget.getItems[1].getText(2)).to eq("false")
person3 = Person.new
person3.name = "Andrea Sherlock"
person3.age = 23
person3.adult = true
group.people << person3
expect(@table.swt_widget.getItems.size).to eq(3)
expect(@table.swt_widget.getItems[2].getText(0)).to eq("Andrea Sherlock")
expect(@table.swt_widget.getItems[2].getText(1)).to eq("23")
expect(@table.swt_widget.getItems[2].getText(2)).to eq("true")
person3.name = "Andrea Sherloque"
person3.age = 13
person3.adult = false
expect(@table.swt_widget.getItems[2].getText(0)).to eq("Andrea Sherloque")
expect(@table.swt_widget.getItems[2].getText(1)).to eq("13")
expect(@table.swt_widget.getItems[2].getText(2)).to eq("false")
group.people.delete person2
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Andrea Sherloque")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("13")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
group.people.delete_at(0)
expect(@table.swt_widget.getItems.size).to eq(1)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Andrea Sherloque")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("13")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("false")
group.people.clear
expect(0).to eq(@table.swt_widget.getItems.size)
group.people = [person2, person1]
expect(2).to eq(@table.swt_widget.getItems.size)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("false")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("true")
person1.name = "Bruce Flee"
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Bruce Flee")
end
end
context 'read with Shine syntax' do
it "data binds table items" do
@target = shell {
@table = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items <= [group, :people, column_properties: [:name, :age, :adult]]
}
@table_nested_indexed = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items <= [community, "groups[0].people", column_attributes: [:name, :age, :adult]]
}
}
wait_until_table_data_binding_done(@table)
wait_until_table_data_binding_done(@table_nested_indexed)
expect(@table.swt_widget.getColumnCount).to eq(3)
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
expect(@table_nested_indexed.swt_widget.getColumnCount).to eq(3)
expect(@table_nested_indexed.swt_widget.getItems.size).to eq(2)
expect(@table_nested_indexed.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table_nested_indexed.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table_nested_indexed.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table_nested_indexed.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table_nested_indexed.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table_nested_indexed.swt_widget.getItems[1].getText(2)).to eq("false")
person3 = Person.new
person3.name = "Andrea Sherlock"
person3.age = 23
person3.adult = true
group.people << person3
expect(@table.swt_widget.getItems.size).to eq(3)
expect(@table.swt_widget.getItems[2].getText(0)).to eq("Andrea Sherlock")
expect(@table.swt_widget.getItems[2].getText(1)).to eq("23")
expect(@table.swt_widget.getItems[2].getText(2)).to eq("true")
person3.name = "Andrea Sherloque"
person3.age = 13
person3.adult = false
expect(@table.swt_widget.getItems[2].getText(0)).to eq("Andrea Sherloque")
expect(@table.swt_widget.getItems[2].getText(1)).to eq("13")
expect(@table.swt_widget.getItems[2].getText(2)).to eq("false")
group.people.delete person2
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Andrea Sherloque")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("13")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
group.people.delete_at(0)
expect(@table.swt_widget.getItems.size).to eq(1)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Andrea Sherloque")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("13")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("false")
group.people.clear
expect(0).to eq(@table.swt_widget.getItems.size)
group.people = [person2, person1]
expect(2).to eq(@table.swt_widget.getItems.size)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("false")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("true")
person1.name = "Bruce Flee"
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Bruce Flee")
end
it "data binds table single selection" do
@target = shell {
@table = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items bind(group, :people), column_properties(:name, :age, :adult)
selection bind(group, :selected_person)
}
}
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
expect(group.selected_person).to eq(person2)
person3 = Person.new
person3.name = "Andrea Sherlock"
person3.age = 23
person3.adult = true
group.people << person3
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
expect(group.selected_person).to eq(person2)
group.people.delete person2
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(0)
group.selected_person = person1
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person1)
expect(group.selected_person).to eq(person1)
item_height = @table.swt_widget.items.first.bounds.height
expect(@table.swt_widget.items[1].getData).to eq(person3)
@table.swt_widget.setSelection([@table.swt_widget.items[1]].to_java(TableItem))
event = Event.new
event.display = @table.swt_widget.getDisplay
event.item = @table.swt_widget.items[1]
event.widget = @table.swt_widget
event.type = swt(:selection)
event.x = 5
event.y = item_height + 5 # skip first item, go to second item
@table.swt_widget.notifyListeners(swt(:selection), event)
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person3)
expect(group.selected_person).to eq(person3)
end
it "data binds table multi selection" do
@target = shell {
@table = table(:multi) {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items bind(group, :people), column_properties(:name, :age, :adult)
selection bind(group, :selected_people)
}
}
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(2)
expect(selection[0].getData).to eq(person1)
expect(selection[1].getData).to eq(person2)
expect(group.selected_people[0]).to eq(person1)
expect(group.selected_people[1]).to eq(person2)
person3 = Person.new
person3.name = "Andrea Sherlock"
person3.age = 23
person3.adult = true
group.people << person3
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(2)
expect(selection[0].getData).to eq(person1)
expect(selection[1].getData).to eq(person2)
group.people.delete person2
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person1)
group.selected_people = [person1, person3]
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(2)
expect(selection[0].getData).to eq(person1)
expect(selection[1].getData).to eq(person3)
expect(group.selected_people).to eq([person1, person3])
end
it "data binds text widget to a string property for a custom widget table" do
@target = shell {
@table = red_table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items bind(group, :people), column_properties(:name, :age, :adult)
}
}
expect(@table.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@table.swt_widget.getColumnCount).to eq(3)
expect(@table.swt_widget.getItems.size).to eq(2)
expect(@table.swt_widget.getItems[0].getText(0)).to eq("Bruce Ting")
expect(@table.swt_widget.getItems[0].getText(1)).to eq("45")
expect(@table.swt_widget.getItems[0].getText(2)).to eq("true")
expect(@table.swt_widget.getItems[1].getText(0)).to eq("Julia Fang")
expect(@table.swt_widget.getItems[1].getText(1)).to eq("17")
expect(@table.swt_widget.getItems[1].getText(2)).to eq("false")
end
end
context 'write (edit)' do
it "triggers table widget editing on selected table item which is done via ENTER key" do
@target = shell {
@table = table {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items bind(group, :people), column_properties(:name, :age, :adult)
selection bind(group, :selected_person)
}
}
expect(@table.table_editor_widget_proxy).to be_nil
@write_done = false
@table.edit_selected_table_item(
0,
before_write: lambda {
expect(@table.edit_in_progress?).to eq(true)
},
after_write: lambda { |edited_table_item|
expect(edited_table_item.getText(0)).to eq('Julie Fan')
@write_done = true
}
)
expect(@table.table_editor_widget_proxy).to_not be_nil
@table.table_editor_widget_proxy.swt_widget.setText('Julie Fan')
# simulate hitting enter to trigger write action
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @table.table_editor_widget_proxy.swt_widget.getDisplay
event.item = @table.table_editor_widget_proxy.swt_widget
event.widget = @table.table_editor_widget_proxy.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keydown]
@table.table_editor_widget_proxy.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:keydown], event)
expect(@write_done).to eq(true)
expect(@table.edit_in_progress?).to eq(false)
expect(@cancel_done).to be_nil
expect(person2.name).to eq('Julie Fan')
# test that it maintains selection
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
end
unless OS.linux?
it "triggers table widget editing on selected table item via :editable SWT style" do
@target = shell {
@table = table(:editable) {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
items bind(group, :people), column_properties(:name, :age, :adult)
selection bind(group, :selected_person)
}
}
item_height = @table.swt_widget.items.first.bounds.height
expect(@table.table_editor_widget_proxy).to be_nil
event = Event.new
event.display = @table.swt_widget.getDisplay
event.item = @table.swt_widget.items.first
event.widget = @table.swt_widget
event.type = Glimmer::SWT::SWTProxy[:mouseup]
event.x = 5
event.y = item_height + (OS.mac? ? 5 : 10) # skip first item, go to the second item
@table.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:mouseup], event)
expect(@table.table_editor_widget_proxy).to_not be_nil
@table.table_editor_widget_proxy.swt_widget.setText('Julie Fan')
# simulate hitting enter to trigger write action
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @table.table_editor_widget_proxy.swt_widget.getDisplay
event.item = @table.table_editor_widget_proxy.swt_widget
event.widget = @table.table_editor_widget_proxy.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keydown]
@table.table_editor_widget_proxy.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:keydown], event)
expect(@table.edit_in_progress?).to eq(false)
expect(person2.name).to eq('Julie Fan')
# test that it maintains selection
selection = @table.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
end
it "triggers table widget editing on selected table item via Shine syntax bidirectional (two-way) data-binding <=>" do
@target = shell {
@table = table(:editable) {
table_column {
text "Name"
width 120
}
table_column {
text "Age"
width 120
}
table_column {
text "Adult"
width 120
}
# using <=> on items automatically makes table have :editable style retroactively
items <=> [group, :people, column_attributes: [:name, :age, :adult]]
selection <=> [group, :selected_person]
}
}
item_height = @table.swt_widget.items.first.bounds.height
expect(@table.table_editor_widget_proxy).to be_nil
event = Event.new
event.display = @table.swt_widget.getDisplay
event.item = @table.swt_widget.items.first
event.widget = @table.swt_widget
event.type = Glimmer::SWT::SWTProxy[:mouseup]
event.x = 5
event.y = item_height + (OS.mac? ? 5 : 10) # skip first item, go to the second item
@table.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:mouseup], event)
expect(@table.table_editor_widget_proxy).to_not be_nil
@table.table_editor_widget_proxy.swt_widget.setText('Julie Fan')
# simulate hitting enter to trigger write action
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | true |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__listeners__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__listeners__spec.rb | require "spec_helper"
require 'os'
module GlimmerSpec
describe "Glimmer Listeners" do
include Glimmer
before(:all) do
class Person
attr_accessor :name, :age, :adult
end
class ::RedButton
include Glimmer::UI::CustomWidget
body {
button(swt_style) {
background :red
}
}
end
end
after(:all) do
Object.send(:remove_const, :Person) if Object.const_defined?(:Person)
Object.send(:remove_const, :RedButton) if Object.const_defined?(:RedButton)
end
it "tests text widget verify listener" do
@target = shell {
composite {
@text = text {
text "Howdy"
on_verify_text do |verify_event|
verify_event.doit = false if verify_event.text == "Hello"
end
}
}
}
@text.swt_widget.setText("Hi")
expect(@text.swt_widget.getText).to eq("Hi")
@text.swt_widget.setText("Hello")
expect(@text.swt_widget.getText).to eq("Hi")
end
it "tests button widget selection listener" do
person = Person.new
person.name = "Bruce Ting"
@target = shell {
composite {
@button = button {
on_widget_selected do
person.name = "Bruce Lao"
end
}
}
}
expect(person.name).to eq("Bruce Ting")
@button.swt_widget.setSelection(true)
@button.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.name).to eq("Bruce Lao")
end
it "tests button widget selection listener on a custom widget button" do
person = Person.new
person.name = "Bruce Ting"
@target = shell {
composite {
@button = red_button {
on_widget_selected do
person.name = "Bruce Lao"
end
}
}
}
expect(@button.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(person.name).to eq("Bruce Ting")
@button.swt_widget.setSelection(true)
@button.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.name).to eq("Bruce Lao")
end
context "SWT event listener (hooked with addListener(SWT.Style, listener)" do
it "tests button SWT.Show event listener" do
person = Person.new
person.name = "Bruce Ting"
@target = shell {
composite {
@button = button {
visible false
on_swt_show do
@button_shown = true
end
}
}
}
expect(@button_shown).to eq(nil)
@button.swt_widget.setVisible(true)
expect(@button_shown).to eq(true)
end
it "fails in adding button SWT.invalid event listener" do
person = Person.new
person.name = "Bruce Ting"
@target = shell {
composite {
@button = button {
visible false
expect do
on_swt_invalid do
@button_shown = true
end
end.to raise_error(Glimmer::Error)
}
}
}
end
end
context 'Shell listeners for Application Menu Items' do
it 'listens to about menu item selection' do
if OS.mac?
system_menu = Glimmer::SWT::DisplayProxy.instance.swt_display.getSystemMenu
about_menu_item = system_menu.getItems.find {|menu_item| menu_item.getID == swt('ID_ABOUT')}
expect(about_menu_item.getListeners(swt(:Selection)).count).to eq(0)
end
@target = display {
on_about {
# No Op
}
}
if OS.mac?
expect(about_menu_item.getListeners(swt(:Selection)).count).to eq(1)
end
end
it 'listens to preferences menu item selection' do
if OS.mac?
system_menu = Glimmer::SWT::DisplayProxy.instance.swt_display.getSystemMenu
preferences_menu_item = system_menu.getItems.find {|menu_item| menu_item.getID == swt('ID_PREFERENCES')}
expect(preferences_menu_item.getListeners(swt(:Selection)).count).to eq(0)
end
@target = display {
on_preferences {
# No Op
}
}
if OS.mac?
expect(preferences_menu_item.getListeners(swt(:Selection)).count).to eq(1)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__checkbox_group__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__checkbox_group__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Radio Group" do
include Glimmer
before(:all) do
class Person
attr_accessor :countries, :countries_options
def initialize
self.countries_options=["Canada", "US", "Mexico"]
end
end
class ::RedCheckboxGroup
include Glimmer::UI::CustomWidget
body {
checkbox_group(swt_style) {
background :red
}
}
end
end
after(:all) do
Object.send(:remove_const, :Person) if Object.const_defined?(:Person)
Object.send(:remove_const, :RedCheckboxGroup) if Object.const_defined?(:RedCheckboxGroup)
end
let(:person) {Person.new}
it 'sets items, spawning checkboxes' do
@target = shell {
@checkbox_group = checkbox_group {
items person.countries_options
}
}
@checkbox_group.checkboxes.each do |checkbox|
expect(checkbox.swt_widget).to be_a(Button)
expect(checkbox).to have_style(:check)
end
end
it 'sets selection in items, selecting checkboxes accordingly' do
@target = shell {
@checkbox_group = check_group {
items person.countries_options
selection ['US', 'Mexico']
}
}
@checkbox_group.checks.each do |checkbox|
expect(checkbox.swt_widget).to be_a(Button)
expect(checkbox).to have_style(:check)
end
expect(@checkbox_group.checkboxes[0].selection).to be_falsey
expect(@checkbox_group.checkboxes[1].selection).to be_truthy
expect(@checkbox_group.checkboxes[2].selection).to be_truthy
end
it 'sets attribute (font) on checkbox group including all nested widgets' do
@target = shell {
@checkbox_group = checkbox_group {
items person.countries_options
font height: 27
}
}
@checkbox_group.checkboxes.each do |checkbox|
expect(checkbox.font.font_data.first.height).to eq(27)
end
@checkbox_group.labels.each do |label|
expect(label.font.font_data.first.height).to eq(27)
end
@checkbox_group.children.each do |composite|
expect(composite.font.font_data.first.height).to eq(27)
end
expect(@checkbox_group.font.font_data.first.height).to eq(27)
end
it 'adds selection listener to checkbox_group spawned checkboxes and mouse_up to matching labels' do
person.countries = ['Canada']
@listener_fired = false
@target = shell {
@checkbox_group = checkbox_group {
items person.countries_options
selection person.countries
on_widget_selected { |event|
expect(@checkbox_group.selection).to eq(['Canada', 'Mexico'])
expect(@checkbox_group.selection_indices).to eq([0, 2])
@listener_fired = true
}
}
}
@checkbox_group.checkboxes[2].selection = true
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @checkbox_group.checkboxes[2].swt_widget
event.widget = @checkbox_group.checkboxes[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@checkbox_group.checkboxes[2].swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(@listener_fired).to be_truthy
@listener_fired = false
person.countries = ['Canada']
async_exec {
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @checkbox_group.labels[2].swt_widget
event.widget = @checkbox_group.labels[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:mouseup]
@checkbox_group.labels[2].swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:mouseup], event)
expect(@listener_fired).to be_truthy
}
end
it 'adds mouse_up listener to checkbox_group spawned checkboxes and labels' do
@listener_fired = false
@target = shell {
@checkbox_group = checkbox_group {
items person.countries_options
on_mouse_up { |event|
expect(@checkbox_group.selection).to eq(['Mexico'])
expect(@checkbox_group.selection_indices).to eq([2])
@listener_fired = true
}
}
}
@checkbox_group.checkboxes[2].selection = true
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @checkbox_group.checkboxes[2].swt_widget
event.widget = @checkbox_group.checkboxes[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:mouseup]
@checkbox_group.checkboxes[2].swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:mouseup], event)
expect(@listener_fired).to be_truthy
@listener_fired = false
person.countries = ['Canada']
async_exec {
@checkbox_group.checkboxes[2].selection = true
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @checkbox_group.labels[2].swt_widget
event.widget = @checkbox_group.labels[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:mouseup]
@checkbox_group.labels[2].swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:mouseup], event)
expect(@listener_fired).to be_truthy
}
end
it 'data-binds selection property' do
@target = shell {
@checkbox_group = checkbox_group {
selection bind(person, :countries)
}
}
expect(@checkbox_group.checkboxes.count).to eq(3)
@checkbox_group.checkboxes.each do |checkbox|
expect(checkbox.selection).to be_falsey
end
expect(@checkbox_group.selection).to eq([])
expect(@checkbox_group.selection_indices).to eq([])
expect(@checkbox_group.items).to eq(person.countries_options)
person.countries = ["Canada", "Mexico"]
expect(@checkbox_group.checkboxes[0].selection).to be_truthy
expect(@checkbox_group.checkboxes[1].selection).to be_falsey
expect(@checkbox_group.checkboxes[2].selection).to be_truthy
expect(@checkbox_group.selection).to eq(["Canada", "Mexico"])
expect(@checkbox_group.selection_indices).to eq([0, 2])
person.countries_options << "France"
expect(@checkbox_group.checkboxes.count).to eq(4)
person.countries_options = ["Canada", "US", "Mexico", "Russia", "France"]
expect(@checkbox_group.checkboxes.count).to eq(5)
person.countries_options << "Italy"
person.countries_options << "Germany"
person.countries_options.unshift "Australia"
expect(@checkbox_group.checkboxes.count).to eq(8)
expect(@checkbox_group.checkboxes[0].selection).to be_falsey
expect(@checkbox_group.checkboxes[1].selection).to be_truthy
expect(@checkbox_group.checkboxes[2].selection).to be_falsey
expect(@checkbox_group.checkboxes[3].selection).to be_truthy
@checkbox_group.checkboxes[4..-1].each do |checkbox|
expect(checkbox.selection).to be_falsey
end
expect(@checkbox_group.selection).to eq(["Canada", "Mexico"])
expect(@checkbox_group.selection_indices).to eq([1, 3])
person.countries_options -= ['Canada']
expect(@checkbox_group.checkboxes[2].selection).to be_truthy
(@checkbox_group.checkboxes - [@checkbox_group.checkboxes[2]]).each do |checkbox|
expect(checkbox.selection).to be_falsey
end
expect(@checkbox_group.selection).to eq(['Mexico'])
expect(@checkbox_group.selection_indices).to eq([2])
@checkbox_group.select([2])
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @checkbox_group.checkboxes[2].swt_widget
event.widget = @checkbox_group.checkboxes[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@checkbox_group.checkboxes[2].notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(@checkbox_group.checkboxes[2].selection).to be_truthy
(@checkbox_group.checkboxes[0..1] + @checkbox_group.checkboxes[3..-1]).each do |checkbox|
expect(checkbox.selection).to be_falsey
end
expect(person.countries).to eq(["Mexico"])
person.countries = ["Russia"]
expect(@checkbox_group.checkboxes[3].selection).to be_truthy
(@checkbox_group.checkboxes[0..2] + @checkbox_group.checkboxes[4..-1]).each do |checkbox|
expect(checkbox.selection).to be_falsey
end
expect(@checkbox_group.selection).to eq(["Russia"])
expect(@checkbox_group.selection_indices).to eq([3])
person.countries = ["random value not in country options"]
@checkbox_group.checkboxes.each do |checkbox|
expect(checkbox.selection).to be_falsey
end
expect(@checkbox_group.selection).to eq([])
expect(@checkbox_group.selection_indices).to eq([])
person.countries = [""]
@checkbox_group.checkboxes.each do |checkbox|
expect(checkbox.selection).to be_falsey
end
expect(@checkbox_group.selection).to eq([])
expect(@checkbox_group.selection_indices).to eq([])
person.countries = []
@checkbox_group.checkboxes.each do |checkbox|
expect(checkbox.selection).to be_falsey
end
expect(@checkbox_group.selection).to eq([])
expect(@checkbox_group.selection_indices).to eq([])
end
it 'data binds selection property on a custom widget checkbox_group' do
person.countries = ['US', 'Mexico']
@target = shell {
@checkbox_group = red_checkbox_group {
selection bind(person, :countries)
}
}
expect(@checkbox_group.background).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@checkbox_group.checkboxes.count).to eq(3)
expect(@checkbox_group.selection_indices).to eq([1, 2])
expect(@checkbox_group.selection).to eq(['US', 'Mexico'])
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__menu_item__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__menu_item__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Menu Item" do
include Glimmer
before(:all) do
class ::RedShell
include Glimmer::UI::CustomShell
body {
shell {
background :red
}
}
end
class ::HistoryMenu
include Glimmer::UI::CustomWidget
body {
menu {
text '&History'
}
}
end
end
after(:all) do
Object.send(:remove_const, :RedShell) if Object.const_defined?(:RedShell)
Object.send(:remove_const, :HistoryMenu) if Object.const_defined?(:HistoryMenu)
end
context 'SWT shell/menu parents' do
it "renders menu bar" do
@target = shell {
@menu_bar = menu_bar {
menu {
text "&File"
menu_item {
text "E&xit"
}
menu_item(0) {
text "&New"
}
menu(1) {
text "&Options"
menu_item(:radio) {
text "Option 1"
}
menu_item(:separator)
menu_item(:check) {
text "Option 3"
}
}
}
menu {
text "&History"
menu {
text "&Recent"
menu_item {
text "File 1"
}
menu_item {
text "File 2"
}
}
}
}
}
expect(@menu_bar).to be_a(Glimmer::SWT::MenuProxy)
expect(@menu_bar.swt_widget).to have_style(:bar)
expect(@target.swt_widget.getMenuBar).to eq(@menu_bar.swt_widget)
expect(@menu_bar.swt_widget.getItems.size).to eq(2)
menu_item1 = @menu_bar.swt_widget.getItems[0]
expect(menu_item1.getText).to eq("&File")
expect(menu_item1).to have_style(:cascade)
menu_item2 = @menu_bar.swt_widget.getItems[1]
expect(menu_item2.getText).to eq("&History")
expect(menu_item2).to have_style(:cascade)
menu1 = menu_item1.getMenu
expect(menu1).to have_style(:drop_down)
expect(menu1.getItems.size).to eq(3)
menu1_menu_item1 = menu1.getItems[0]
expect(menu1_menu_item1.getText).to eq('&New')
expect(menu1_menu_item1).to have_style(:push)
menu1_menu_item2 = menu1.getItems[1]
expect(menu1_menu_item2.getText).to eq('&Options')
expect(menu1_menu_item2).to have_style(:cascade)
menu1_menu_item3 = menu1.getItems[2]
expect(menu1_menu_item3.getText).to eq('E&xit')
expect(menu1_menu_item3).to have_style(:push)
menu1_menu2 = menu1_menu_item2.getMenu
expect(menu1_menu2).to have_style(:drop_down)
menu1_menu2_menu_item1 = menu1_menu2.getItems[0]
expect(menu1_menu2_menu_item1.getText).to eq('Option 1')
expect(menu1_menu2_menu_item1).to have_style(:radio)
menu1_menu2_menu_item2 = menu1_menu2.getItems[1]
expect(menu1_menu2_menu_item2).to have_style(:separator)
menu1_menu2_menu_item3 = menu1_menu2.getItems[2]
expect(menu1_menu2_menu_item3.getText).to eq('Option 3')
expect(menu1_menu2_menu_item3).to have_style(:check)
menu2 = menu_item2.getMenu
expect(menu2).to have_style(:drop_down)
menu2_menu_item1 = menu2.getItems[0]
expect(menu2_menu_item1).to have_style(:cascade)
expect(menu2_menu_item1.getText).to eq("&Recent")
menu2_menu1_menu1 = menu2_menu_item1.getMenu
expect(menu2_menu1_menu1).to have_style(:drop_down)
menu2_menu1_menu1_menu_item1 = menu2_menu1_menu1.getItems[0]
expect(menu2_menu1_menu1_menu_item1.getText).to eq('File 1')
expect(menu2_menu1_menu1_menu_item1).to have_style(:push)
menu2_menu1_menu1_menu_item2 = menu2_menu1_menu1.getItems[1]
expect(menu2_menu1_menu1_menu_item2.getText).to eq('File 2')
expect(menu2_menu1_menu1_menu_item2).to have_style(:push)
end
it "renders pop up menu" do
@target = shell {
@label = label {
text 'Right-Click Me'
@pop_up_menu = menu {
menu {
text '&History'
menu {
text "&Recent"
menu_item {
text "File 1"
}
menu_item {
text "File 2"
}
}
}
}
}
}
expect(@pop_up_menu).to be_a(Glimmer::SWT::MenuProxy)
expect(@pop_up_menu.swt_widget).to have_style(:pop_up)
expect(@label.swt_widget.getMenu).to eq(@pop_up_menu.swt_widget)
expect(@pop_up_menu.swt_widget.getItems.size).to eq(1)
menu_item2 = @pop_up_menu.swt_widget.getItems[0]
expect(menu_item2.getText).to eq("&History")
expect(menu_item2).to have_style(:cascade)
menu2 = menu_item2.getMenu
expect(menu2).to have_style(:drop_down)
menu2_menu_item1 = menu2.getItems[0]
expect(menu2_menu_item1).to have_style(:cascade)
expect(menu2_menu_item1.getText).to eq("&Recent")
menu2_menu1_menu1 = menu2_menu_item1.getMenu
expect(menu2_menu1_menu1).to have_style(:drop_down)
menu2_menu1_menu1_menu_item1 = menu2_menu1_menu1.getItems[0]
expect(menu2_menu1_menu1_menu_item1.getText).to eq('File 1')
expect(menu2_menu1_menu1_menu_item1).to have_style(:push)
menu2_menu1_menu1_menu_item2 = menu2_menu1_menu1.getItems[1]
expect(menu2_menu1_menu1_menu_item2.getText).to eq('File 2')
expect(menu2_menu1_menu1_menu_item2).to have_style(:push)
end
it "attaches on_widget_selected for a dropdown menu on encapsulated cascade menu item" do
@target = shell {
@label = label {
text 'Right-Click Me'
@pop_up_menu = menu {
@history_menu = menu {
text '&History'
on_widget_selected {
@history_selected = true
}
}
}
}
}
expect(@history_selected).to eq(nil)
@history_menu.swt_menu_item.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(@history_selected).to eq(true)
end
end
context 'Custom shell/menu parents' do
it "renders menu bar" do
@target = red_shell {
@menu_bar = menu_bar {
menu {
text "&File"
menu_item {
text "E&xit"
}
menu_item(0) {
text "&New"
}
menu(1) {
text "&Options"
menu_item(:radio) {
text "Option 1"
}
menu_item(:separator)
menu_item(:check) {
text "Option 3"
}
}
}
history_menu {
menu {
text "&Recent"
menu_item {
text "File 1"
}
menu_item {
text "File 2"
}
}
}
}
}
expect(@menu_bar).to be_a(Glimmer::SWT::MenuProxy)
expect(@menu_bar.swt_widget).to have_style(:bar)
expect(@target.swt_widget.getMenuBar).to eq(@menu_bar.swt_widget)
expect(@menu_bar.swt_widget.getItems.size).to eq(2)
menu_item1 = @menu_bar.swt_widget.getItems[0]
expect(menu_item1.getText).to eq("&File")
expect(menu_item1).to have_style(:cascade)
menu_item2 = @menu_bar.swt_widget.getItems[1]
expect(menu_item2.getText).to eq("&History")
expect(menu_item2).to have_style(:cascade)
menu1 = menu_item1.getMenu
expect(menu1).to have_style(:drop_down)
expect(menu1.getItems.size).to eq(3)
menu1_menu_item1 = menu1.getItems[0]
expect(menu1_menu_item1.getText).to eq('&New')
expect(menu1_menu_item1).to have_style(:push)
menu1_menu_item2 = menu1.getItems[1]
expect(menu1_menu_item2.getText).to eq('&Options')
expect(menu1_menu_item2).to have_style(:cascade)
menu1_menu_item3 = menu1.getItems[2]
expect(menu1_menu_item3.getText).to eq('E&xit')
expect(menu1_menu_item3).to have_style(:push)
menu1_menu2 = menu1_menu_item2.getMenu
expect(menu1_menu2).to have_style(:drop_down)
menu1_menu2_menu_item1 = menu1_menu2.getItems[0]
expect(menu1_menu2_menu_item1.getText).to eq('Option 1')
expect(menu1_menu2_menu_item1).to have_style(:radio)
menu1_menu2_menu_item2 = menu1_menu2.getItems[1]
expect(menu1_menu2_menu_item2).to have_style(:separator)
menu1_menu2_menu_item3 = menu1_menu2.getItems[2]
expect(menu1_menu2_menu_item3.getText).to eq('Option 3')
expect(menu1_menu2_menu_item3).to have_style(:check)
menu2 = menu_item2.getMenu
expect(menu2).to have_style(:drop_down)
menu2_menu_item1 = menu2.getItems[0]
expect(menu2_menu_item1).to have_style(:cascade)
expect(menu2_menu_item1.getText).to eq("&Recent")
menu2_menu1_menu1 = menu2_menu_item1.getMenu
expect(menu2_menu1_menu1).to have_style(:drop_down)
menu2_menu1_menu1_menu_item1 = menu2_menu1_menu1.getItems[0]
expect(menu2_menu1_menu1_menu_item1.getText).to eq('File 1')
expect(menu2_menu1_menu1_menu_item1).to have_style(:push)
menu2_menu1_menu1_menu_item2 = menu2_menu1_menu1.getItems[1]
expect(menu2_menu1_menu1_menu_item2.getText).to eq('File 2')
expect(menu2_menu1_menu1_menu_item2).to have_style(:push)
end
it "renders pop up menu" do
@target = red_shell {
@pop_up_menu = menu {
history_menu {
menu {
text "&Recent"
menu_item {
text "File 1"
}
menu_item {
text "File 2"
}
}
}
}
}
expect(@pop_up_menu).to be_a(Glimmer::SWT::MenuProxy)
expect(@pop_up_menu.swt_widget).to have_style(:pop_up)
expect(@target.swt_widget.getMenu).to eq(@pop_up_menu.swt_widget)
expect(@pop_up_menu.swt_widget.getItems.size).to eq(1)
menu_item2 = @pop_up_menu.swt_widget.getItems[0]
expect(menu_item2.getText).to eq("&History")
expect(menu_item2).to have_style(:cascade)
menu2 = menu_item2.getMenu
expect(menu2).to have_style(:drop_down)
menu2_menu_item1 = menu2.getItems[0]
expect(menu2_menu_item1).to have_style(:cascade)
expect(menu2_menu_item1.getText).to eq("&Recent")
menu2_menu1_menu1 = menu2_menu_item1.getMenu
expect(menu2_menu1_menu1).to have_style(:drop_down)
menu2_menu1_menu1_menu_item1 = menu2_menu1_menu1.getItems[0]
expect(menu2_menu1_menu1_menu_item1.getText).to eq('File 1')
expect(menu2_menu1_menu1_menu_item1).to have_style(:push)
menu2_menu1_menu1_menu_item2 = menu2_menu1_menu1.getItems[1]
expect(menu2_menu1_menu1_menu_item2.getText).to eq('File 2')
expect(menu2_menu1_menu1_menu_item2).to have_style(:push)
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__constant__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__constant__spec.rb | require "spec_helper"
java_import 'org.eclipse.swt.widgets.Composite'
module GlimmerSpec
describe "Glimmer Constant" do
include Glimmer
it "test shell with default layout and composite" do
@target = shell {
composite(:border, :no_focus) {
}
}
expect(@target.swt_widget.children.size).to eq(1)
expect(@target.swt_widget.children[0]).to be_instance_of(Composite)
composite_widget = @target.swt_widget.children[0]
expect(composite_widget).to have_style(:no_focus)
expect(composite_widget).to have_style(:border)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__import_swt_packages__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__import_swt_packages__spec.rb | require "spec_helper"
describe Glimmer do
include Glimmer
after do
Glimmer::Config.import_swt_packages = true
%w[
SomeApp
SomeWidget
SomeShell
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
Glimmer::Config.send(:remove_class_variable, :@@import_swt_packages)
Glimmer::SWT.send(:remove_const, :Packages)
load 'glimmer/swt/packages.rb'
end
describe '.import_swt_packages' do
it 'enables automatic include of SWT packages in Glimmer apps by default' do
class SomeApp
include Glimmer
end
expect(Glimmer::Config.import_swt_packages).to eq(Glimmer::Config::DEFAULT_IMPORT_SWT_PACKAGES)
expect(SomeApp::Label).to eq(org.eclipse.swt.widgets.Label)
end
it 'explicitly enables automatic include of SWT packages in Glimmer apps' do
Glimmer::Config.import_swt_packages = true
class SomeApp
include Glimmer
end
expect(Glimmer::Config.import_swt_packages).to eq(Glimmer::Config::DEFAULT_IMPORT_SWT_PACKAGES)
expect(SomeApp::Label).to eq(org.eclipse.swt.widgets.Label)
end
it 'enables automatic include of SWT packages in Glimmer apps by specifying extra packages' do
Glimmer::Config.import_swt_packages += [
'org.eclipse.nebula.widgets.ganttchart'
]
class SomeApp
include Glimmer
end
expect(Glimmer::Config.import_swt_packages).to eq([
'org.eclipse.swt',
'org.eclipse.swt.widgets',
'org.eclipse.swt.layout',
'org.eclipse.swt.graphics',
'org.eclipse.swt.browser',
'org.eclipse.swt.custom',
'org.eclipse.swt.dnd',
'org.eclipse.swt.printing',
'org.eclipse.nebula.widgets.ganttchart',
])
expect(SomeApp::Label).to eq(org.eclipse.swt.widgets.Label)
end
it 'enables automatic include of SWT packages in Glimmer custom widgets by specifying extra packages' do
Glimmer::Config.import_swt_packages += [
'org.eclipse.nebula.widgets.ganttchart'
]
class SomeWidget
include Glimmer::UI::CustomWidget
body {
label {
}
}
end
expect(Glimmer::Config.import_swt_packages).to eq([
'org.eclipse.swt',
'org.eclipse.swt.widgets',
'org.eclipse.swt.layout',
'org.eclipse.swt.graphics',
'org.eclipse.swt.browser',
'org.eclipse.swt.custom',
'org.eclipse.swt.dnd',
'org.eclipse.swt.printing',
'org.eclipse.nebula.widgets.ganttchart',
])
expect(SomeWidget::Label).to eq(org.eclipse.swt.widgets.Label)
shell {
some_widget {
}
}
end
it 'enables automatic include of SWT packages in Glimmer custom shells by specifying extra packages' do
Glimmer::Config.import_swt_packages += [
'org.eclipse.nebula.widgets.ganttchart'
]
class SomeShell
include Glimmer::UI::CustomShell
body {
shell {
label {
}
}
}
end
expect(Glimmer::Config.import_swt_packages).to eq([
'org.eclipse.swt',
'org.eclipse.swt.widgets',
'org.eclipse.swt.layout',
'org.eclipse.swt.graphics',
'org.eclipse.swt.browser',
'org.eclipse.swt.custom',
'org.eclipse.swt.dnd',
'org.eclipse.swt.printing',
'org.eclipse.nebula.widgets.ganttchart',
])
expect(SomeShell::Label).to eq(org.eclipse.swt.widgets.Label)
some_shell {
label {
}
}
end
it 'enables automatic include of SWT packages in Glimmer apps by specifying a limited set of packages' do
Glimmer::Config.import_swt_packages = [
'org.eclipse.swt',
'org.eclipse.swt.widgets',
'org.eclipse.swt.layout',
'org.eclipse.swt.graphics',
'org.eclipse.swt.browser',
]
class SomeApp
include Glimmer
end
expect(Glimmer::Config.import_swt_packages).to eq([
'org.eclipse.swt',
'org.eclipse.swt.widgets',
'org.eclipse.swt.layout',
'org.eclipse.swt.graphics',
'org.eclipse.swt.browser',
])
expect(SomeApp::Label).to eq(org.eclipse.swt.widgets.Label)
end
it 'disables automatic include of SWT packages in Glimmer apps' do
Glimmer::Config.import_swt_packages = false
class SomeApp
include Glimmer
end
expect(Glimmer::Config.import_swt_packages).to eq(false)
expect {SomeApp::Label}.to raise_error(NameError)
end
it 'disables automatic include of SWT packages in Glimmer apps via nil value' do
Glimmer::Config.import_swt_packages = nil
class SomeApp
include Glimmer
end
expect(Glimmer::Config.import_swt_packages).to be_nil
expect {SomeApp::Label}.to raise_error(NameError)
end
it 'disables automatic include of SWT packages in Glimmer apps via empty array value' do
Glimmer::Config.import_swt_packages = []
class SomeApp
include Glimmer
end
expect(Glimmer::Config.import_swt_packages).to eq([])
expect {SomeApp::Label}.to raise_error(NameError)
end
it 'disables automatic include of SWT packages in Glimmer custom widgets' do
Glimmer::Config.import_swt_packages = false
class SomeWidget
include Glimmer::UI::CustomWidget
end
expect(Glimmer::Config.import_swt_packages).to eq(false)
expect {SomeWidget::Label}.to raise_error(NameError)
end
it 'disables automatic include of SWT packages in Glimmer custom shells' do
Glimmer::Config.import_swt_packages = false
class SomeShell
include Glimmer::UI::CustomShell
end
expect(Glimmer::Config.import_swt_packages).to eq(false)
expect {SomeShell::Label}.to raise_error(NameError)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__data_binding__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__data_binding__spec.rb | require 'spec_helper'
module GlimmerSpec
describe "Glimmer Data Binding" do
include Glimmer
before(:all) do
class Person
attr_accessor :name, :age, :adult, :name_selection
attr_reader :id
def initialize(id = nil)
@id = id
end
end
class PersonWithComputedValues
attr_accessor :first_name, :last_name, :year_of_birth
def name
"#{last_name}, #{first_name}"
end
def age
Time.now.year - year_of_birth
end
end
class PersonWithNestedComputedValues
class Address
attr_accessor :streets
def street_count
streets.count
end
end
attr_accessor :addresses
end
class Address
attr_accessor :street
end
class PersonWithNestedProperties
attr_accessor :address1, :address2
end
class PersonWithNestedIndexedProperties
attr_accessor :addresses, :names
end
class ::RedComposite
include Glimmer::UI::CustomWidget
body {
composite(swt_style) {
background :red
}
}
end
class ::RedText
include Glimmer::UI::CustomWidget
body {
text(swt_style) {
background :red
}
}
end
module ::Red
class Text
include Glimmer::UI::CustomWidget
body {
red_composite {
@red_text = red_text {
# NOOP
}
}
}
def custom_text=(value)
@red_text.swt_widget.setText value.to_s
end
def custom_text
@red_text.swt_widget.getText
end
def add_observer(observer, attribute_name)
if attribute_name.to_s == 'custom_text'
@red_text.add_observer(observer, 'text')
else
super
end
end
end
end
end
after(:all) do
::Red.send(:remove_const, :Text) if ::Red.const_defined?(:Text)
%w[
Person
PersonWithComputedValues
PersonWithNestedComputedValues
Address
PersonWithNestedProperties
PersonWithNestedIndexedProperties
RedComposite
RedText
Red
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
it "tests text widget data binding string property" do
person = Person.new
person.name = "Bruce Ting"
@target = shell {
composite {
@text = text {
text bind(person, :name)
}
}
}
expect(@text.swt_widget.getText).to eq("Bruce Ting")
person.name = "Lady Butterfly"
expect(@text.swt_widget.getText).to eq("Lady Butterfly")
@text.swt_widget.setText("Allen Deiley")
expect(person.name).to eq("Allen Deiley")
end
it "tests text widget data binding string property with Shine syntax" do
person = Person.new
person.name = "Bruce Ting"
@target = shell {
composite {
@text = text {
text <=> [person, :name]
}
}
}
expect(@text.swt_widget.getText).to eq("Bruce Ting")
person.name = "Lady Butterfly"
expect(@text.swt_widget.getText).to eq("Lady Butterfly")
@text.swt_widget.setText("Allen Deiley")
expect(person.name).to eq("Allen Deiley")
end
context "text widget selection" do
it "updates text widget selection when hitting key down" do
person = Person.new
person.name = "Bruce Ting"
person.name_selection = Point.new(1,4)
@target = shell {
composite {
@text = text {
text bind(person, :name)
selection bind(person, :name_selection)
}
}
}
expect(@text.swt_widget.getText).to eq("Bruce Ting")
expect(@text.swt_widget.getSelection.x).to eq(1)
expect(@text.swt_widget.getSelection.y).to eq(4)
@text.swt_widget.setSelection(Point.new(2, 4))
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:arrow_right]
event.doit = true
event.character = 26.chr
event.display = Glimmer::SWT::DisplayProxy.instance.swt_display
event.item = @text.swt_widget
event.widget = @text.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keydown]
@text.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:keydown], event)
expect(person.name_selection.x).to eq(2)
expect(person.name_selection.y).to eq(4)
end
it "updates text widget selection when hitting key down using Shine syntax" do
person = Person.new
person.name = "Bruce Ting"
person.name_selection = Point.new(1,4)
@target = shell {
composite {
@text = text {
text <=> [person, :name]
selection <=> [person, :name_selection]
}
}
}
expect(@text.swt_widget.getText).to eq("Bruce Ting")
expect(@text.swt_widget.getSelection.x).to eq(1)
expect(@text.swt_widget.getSelection.y).to eq(4)
@text.swt_widget.setSelection(Point.new(2, 4))
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:arrow_right]
event.doit = true
event.character = 26.chr
event.display = Glimmer::SWT::DisplayProxy.instance.swt_display
event.item = @text.swt_widget
event.widget = @text.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keydown]
@text.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:keydown], event)
expect(person.name_selection.x).to eq(2)
expect(person.name_selection.y).to eq(4)
end
it "updates text widget selection when clicking mouse down" do
person = Person.new
person.name = "Bruce Ting"
person.name_selection = Point.new(1,4)
@target = shell {
composite {
@text = text {
text bind(person, :name)
selection bind(person, :name_selection)
}
}
}
expect(@text.swt_widget.getText).to eq("Bruce Ting")
expect(@text.swt_widget.getSelection.x).to eq(1)
expect(@text.swt_widget.getSelection.y).to eq(4)
@text.swt_widget.setSelection(Point.new(2, 4))
event = Event.new
event.doit = true
event.display = Glimmer::SWT::DisplayProxy.instance.swt_display
event.item = @text.swt_widget
event.widget = @text.swt_widget
event.type = Glimmer::SWT::SWTProxy[:mousedown]
@text.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:mousedown], event)
expect(person.name_selection.x).to eq(2)
expect(person.name_selection.y).to eq(4)
end
end
it "tests red label custom widget data binding string property" do
person = Person.new
person.name = "Bruce Ting"
person2 = Person.new
person2.name = "Bruce Ting"
person3 = Person.new
person3.name = "Bruce Ting"
@target = shell {
composite {
@red_text = red_text {
text bind(person, :name)
}
}
red_composite {
@red_text2 = red_text {
text bind(person2, :name)
}
}
@red_text3 = red__text {
custom_text bind(person3, :name)
}
}
expect(@red_text.swt_widget.getText).to eq("Bruce Ting")
person.name = "Lady Butterfly"
expect(@red_text.swt_widget.getText).to eq("Lady Butterfly")
@red_text.swt_widget.setText("Allen Deiley")
expect(person.name).to eq("Allen Deiley")
expect(@red_text2.swt_widget.getText).to eq("Bruce Ting")
person2.name = "Lady Butterfly"
expect(@red_text2.swt_widget.getText).to eq("Lady Butterfly")
@red_text2.swt_widget.setText("Allen Deiley")
expect(person2.name).to eq("Allen Deiley")
red_text3_widget = @red_text3.swt_widget
red_text3_widget = red_text3_widget.getChildren.first
expect(red_text3_widget.getText).to eq("Bruce Ting")
expect(@red_text3.custom_text).to eq("Bruce Ting")
person3.name = "Lady Butterfly"
expect(red_text3_widget.getText).to eq("Lady Butterfly")
expect(@red_text3.custom_text).to eq("Lady Butterfly")
red_text3_widget.setText("Allen Deiley")
expect(person3.name).to eq("Allen Deiley")
@red_text3.custom_text = "Sean McFaun"
expect(person3.name).to eq("Sean McFaun")
end
it "tests label widget data binding string property" do
person = Person.new(839728)
person.name = "Bruce Ting"
@target = shell {
composite {
@label1 = label {
text bind(person, :id)
}
@label2 = label {
text bind(person, :name)
}
}
}
expect(@label1.swt_widget.getText).to eq("839728")
expect(@label2.swt_widget.getText).to eq("Bruce Ting")
person.name = "Lady Butterfly"
expect(@label2.swt_widget.getText).to eq("Lady Butterfly")
end
it "tests label widget computed value data binding string property" do
person = PersonWithComputedValues.new
person.first_name = "Marty"
person.last_name = "McFly"
@target = shell {
composite {
@label = label {
text bind(person, :name, computed_by: [:first_name, :last_name])
}
}
}
expect(@label.swt_widget.getText).to eq("McFly, Marty")
person.first_name = "Martin"
expect(@label.swt_widget.getText).to eq("McFly, Martin")
person.last_name = "MacFly"
expect(@label.swt_widget.getText).to eq("MacFly, Martin")
end
it "tests label widget computed value data binding integer property" do
person = PersonWithComputedValues.new
person.year_of_birth = Time.now.year - 40 #TODO TimeCop gem ?
@target = shell {
composite {
@label = label {
text bind(person, :age, on_write: :to_i, computed_by: :year_of_birth)
}
}
}
expect(@label.swt_widget.getText).to eq("40")
person.year_of_birth = Time.now.year - 41
expect(@label.swt_widget.getText).to eq("41")
end
it "tests checkbox widget data binding boolean property" do
person = Person.new
person.adult = true
@target = shell {
composite {
@check_box = button(:check) {
selection bind(person, :adult)
}
}
}
expect(@check_box.swt_widget.getSelection).to eq(true)
person.adult = false
expect(@check_box.swt_widget.getSelection).to eq(false)
@check_box.swt_widget.setSelection(true)
@check_box.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.adult).to eq(true)
end
it "tests radio widget data binding boolean property" do
person = Person.new
person.adult = true
@target = shell {
composite {
@radio = button(:radio) {
selection bind(person, :adult)
}
}
}
expect(@radio.swt_widget.getSelection).to eq(true)
person.adult = false
expect(@radio.swt_widget.getSelection).to eq(false)
@radio.swt_widget.setSelection(true)
@radio.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.adult).to eq(true)
end
it "tests spinner widget data binding integer selection property" do
person = Person.new
person.age = 17
@target = shell {
composite {
@spinner = spinner {
selection bind(person, :age)
}
}
}
expect(@spinner.swt_widget.getSelection).to eq(17)
person.age = 20
expect(@spinner.swt_widget.getSelection).to eq(20)
@spinner.swt_widget.setSelection(34)
@spinner.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.age).to eq(34)
end
it "tests menu item widget data binding boolean selection property" do
person = Person.new
person.adult = false
@target = shell {
menu_bar {
menu {
@menu_item = menu_item(:radio) {
text 'Adult'
selection bind(person, :adult)
}
}
}
}
expect(@menu_item.swt_widget.getSelection).to eq(false)
person.adult = true
expect(@menu_item.swt_widget.getSelection).to eq(true)
@menu_item.swt_widget.setSelection(false)
@menu_item.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.adult).to eq(false)
end
it "tests menu item widget read-only data binding of boolean selection property" do
person = Person.new
person.age = 17
@target = shell {
menu_bar {
menu {
@menu_item = menu_item(:radio) {
text 'Adult'
selection bind(person, :age, read_only: true) {|a| a >= 18}
}
}
}
}
expect(@menu_item.swt_widget.getSelection).to eq(false)
person.age = 20
expect(@menu_item.swt_widget.getSelection).to eq(true)
@menu_item.swt_widget.setSelection(false)
@menu_item.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.age).to eq(20)
end
it "tests menu item widget read-only data binding of boolean selection property with Shine syntax" do
person = Person.new
person.age = 17
@target = shell {
menu_bar {
menu {
@menu_item = menu_item(:radio) {
text 'Adult'
selection <= [person, :age, on_read: ->(a) { a >= 18 }]
}
}
}
}
expect(@menu_item.swt_widget.getSelection).to eq(false)
person.age = 20
expect(@menu_item.swt_widget.getSelection).to eq(true)
@menu_item.swt_widget.setSelection(false)
@menu_item.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.age).to eq(20)
end
it "tests menu item widget one-direction-only data binding of boolean enabled property" do
person = Person.new
person.adult = false
@target = shell {
menu_bar {
menu {
@menu_item = menu_item(:radio) {
text 'Smoker'
enabled bind(person, :adult)
}
}
}
}
expect(@menu_item.swt_widget.getEnabled).to eq(false)
person.adult = true
expect(@menu_item.swt_widget.getEnabled).to eq(true)
@menu_item.swt_widget.setEnabled(false)
@menu_item.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.adult).to eq(true)
end
unless ENV['CI'].to_s.downcase == 'true'
context 'focus' do
after do
if @target
@target.async_exec do
@target.dispose
end
@target.open
end
end
it 'tests widget data binding focus' do
person = Person.new
expect(person.adult).to be_nil
@target = shell {
alpha 0 # keep invisible while running specs
@text1 = text {
text "First one is focused by default"
}
@text2 = text {
focus bind(person, :adult)
text "Not focused"
}
}
@target.async_exec do
expect(@text1.swt_widget.isFocusControl).to eq(true)
expect(@text2.swt_widget.isFocusControl).to eq(false)
person.adult = true
expect(@text1.swt_widget.isFocusControl).to eq(false)
expect(@text2.swt_widget.isFocusControl).to eq(true)
expect(@text1.swt_widget.setFocus).to eq(true)
expect(person.adult).to eq(false)
expect(@text2.swt_widget.setFocus).to eq(true)
expect(person.adult).to eq(true)
end
# TODO test data binding in the other direction (from widget to model)
end
end
end
it "tests widget data binding enablement" do
person = Person.new
person.adult = true
@target = shell {
composite {
@text = text {
enabled bind(person, :adult)
}
}
}
expect(@text.swt_widget.isEnabled).to eq(true)
person.adult = false
expect(@text.swt_widget.isEnabled).to eq(false)
end
it "tests multiple widget data binding enablement to same model property" do
person = Person.new
person.adult = true
@target = shell {
composite {
@text = text {
enabled bind(person, :adult)
}
@text2 = text {
enabled bind(person, :adult)
}
@text3 = text {
enabled bind(person, :adult)
}
}
}
expect(@text.swt_widget.isEnabled).to eq(true)
expect(@text2.swt_widget.isEnabled).to eq(true)
expect(@text3.swt_widget.isEnabled).to eq(true)
person.adult = false
expect(@text.swt_widget.isEnabled).to eq(false)
expect(@text2.swt_widget.isEnabled).to eq(false)
expect(@text3.swt_widget.isEnabled).to eq(false)
end
it "tests multiple widget data bindings to different model properties" do
person = Person.new
person.name = "Nancy"
person.age = 15
person.adult = true
@target = shell {
composite {
@label = label {
text bind(person, :name)
}
@check_box = button(:check) {
selection bind(person, :adult)
}
}
}
expect(@label.swt_widget.getText).to eq("Nancy")
expect(@check_box.swt_widget.getSelection).to eq(true)
person.name = "Drew"
expect(@label.swt_widget.getText).to eq("Drew")
person.adult = false
expect(@check_box.swt_widget.getSelection).to eq(false)
@check_box.swt_widget.setSelection(true)
@check_box.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.adult).to eq(true)
end
context "nested data binding" do
it "tests text widget data binding to nested string property" do
person = PersonWithNestedProperties.new
person.address1 = Address.new
person.address2 = Address.new
person.address1.street = "20 Naper Ave"
person.address2.street = "101 Confession St"
@target = shell {
composite {
@address1_street_text_widget = text {
text bind(person, "address1.street")
}
}
composite {
@address2_street_text_widget = text {
text bind(person, "address2.street")
}
}
}
expect(@address1_street_text_widget.swt_widget.getText).to eq("20 Naper Ave")
expect(@address2_street_text_widget.swt_widget.getText).to eq("101 Confession St")
@address1_street_text_widget.swt_widget.setText "101 Confession St"
@address2_street_text_widget.swt_widget.setText "20 Naper Ave"
expect(person.address1.street).to eq("101 Confession St")
expect(person.address2.street).to eq("20 Naper Ave")
person.address1.street = "123 Main St"
person.address2.street = "100 Park Ave"
expect(@address1_street_text_widget.swt_widget.getText).to eq("123 Main St")
expect(@address2_street_text_widget.swt_widget.getText).to eq("100 Park Ave")
person.address2 = person.address1
expect(@address2_street_text_widget.swt_widget.getText).to eq("123 Main St")
person.address2 = nil
expect(@address2_street_text_widget.swt_widget.getText).to eq("")
person.address2 = Address.new
person.address2.street = "101 Confession St"
expect(@address2_street_text_widget.swt_widget.getText).to eq("101 Confession St")
person.address2.street = "123 Main St"
expect(@address2_street_text_widget.swt_widget.getText).to eq("123 Main St")
end
it "tests text widget data binding to nested indexed string property" do
person = PersonWithNestedIndexedProperties.new
@target = shell {
composite {
@name1 = text {
text bind(person, "names[0]")
}
@address1_street_text_widget = text {
text bind(person, "addresses[0].street")
}
}
composite {
@name2 = text {
text bind(person, "names[1]")
}
@address2_street_text_widget = text {
text bind(person, "addresses[1].street")
}
}
}
expect(@name1.swt_widget.getText).to eq("")
expect(@address1_street_text_widget.swt_widget.getText).to eq("")
expect(@name2.swt_widget.getText).to eq("")
expect(@address2_street_text_widget.swt_widget.getText).to eq("")
person.names = []
person.names[0] = 'Robert'
person.names[1] = 'Bob'
person.addresses = []
person.addresses[0] = Address.new
person.addresses[1] = Address.new
person.addresses[0].street = "20 Naper Ave"
person.addresses[1].street = "101 Confession St"
expect(@name1.swt_widget.getText).to eq("Robert")
expect(@address1_street_text_widget.swt_widget.getText).to eq("20 Naper Ave")
expect(@name2.swt_widget.getText).to eq("Bob")
expect(@address2_street_text_widget.swt_widget.getText).to eq("101 Confession St")
@name1.swt_widget.setText "Roberto"
@address1_street_text_widget.swt_widget.setText "101 Confession St"
@name2.swt_widget.setText "Bobo"
@address2_street_text_widget.swt_widget.setText "20 Naper Ave"
expect(person.names[0]).to eq("Roberto")
expect(person.addresses[0].street).to eq("101 Confession St")
expect(person.names[1]).to eq("Bobo")
expect(person.addresses[1].street).to eq("20 Naper Ave")
person.names[0] = "Robertissimo"
person.addresses[0].street = "123 Main St"
person.names[1] = "Bobissimo"
person.addresses[1].street = "100 Park Ave"
expect(@name1.swt_widget.getText).to eq("Robertissimo")
expect(@address1_street_text_widget.swt_widget.getText).to eq("123 Main St")
expect(@name2.swt_widget.getText).to eq("Bobissimo")
expect(@address2_street_text_widget.swt_widget.getText).to eq("100 Park Ave")
person.names[1] = person.names[0]
original_address2 = person.addresses[1]
person.addresses[1] = person.addresses[0]
expect(@name2.swt_widget.getText).to eq("Robertissimo")
expect(@address2_street_text_widget.swt_widget.getText).to eq("123 Main St")
# Ensure data-binding observers are removed when address value changed
original_address2.street = '838 Newman'
expect(@address2_street_text_widget.swt_widget.getText).to_not eq('838 Newman')
person.addresses[1].street = '838 Newman'
expect(@address2_street_text_widget.swt_widget.getText).to eq('838 Newman')
person.names[1] = nil
person.addresses[1] = nil
expect(@name2.swt_widget.getText).to eq("")
expect(@address2_street_text_widget.swt_widget.getText).to eq("")
person.addresses[1] = Address.new
person.addresses[1].street = "101 Confession St"
expect(@address2_street_text_widget.swt_widget.getText).to eq("101 Confession St")
person.addresses[1].street = "123 Main St"
expect(@address2_street_text_widget.swt_widget.getText).to eq("123 Main St")
# test removal of observers on severed nested chains
old_address2 = person.addresses[1]
expect(old_address2.property_observer_list('street').to_a.empty?).to be_falsey
person.addresses[1] = Address.new
expect(old_address2.property_observer_list('street').to_a.empty?).to be_truthy
old_address2 = person.addresses[1]
expect(old_address2.property_observer_list('street').to_a.empty?).to be_falsey
person.addresses.delete(old_address2)
expect(old_address2.property_observer_list('street').to_a.empty?).to be_truthy
person.addresses << old_address2
expect(old_address2.property_observer_list('street').to_a.empty?).to be_falsey
person.addresses.delete_at(1)
expect(old_address2.property_observer_list('street').to_a.empty?).to be_truthy
person.addresses << old_address2
old_address1 = person.addresses[0]
expect(old_address1.property_observer_list('street').to_a.empty?).to be_falsey
expect(old_address2.property_observer_list('street').to_a.empty?).to be_falsey
person.addresses.clear
expect(old_address1.property_observer_list('street').to_a.empty?).to be_truthy
expect(old_address2.property_observer_list('street').to_a.empty?).to be_truthy
person.addresses << old_address1
person.addresses << old_address2
old_addresses = person.addresses
old_address1 = person.addresses[0]
old_address2 = person.addresses[1]
expect(old_addresses.property_observer_list.to_a.empty?).to be_falsey
expect(old_address1.property_observer_list('street').to_a.empty?).to be_falsey
expect(old_address2.property_observer_list('street').to_a.empty?).to be_falsey
person.addresses = []
expect(old_addresses.property_observer_list.to_a.empty?).to be_truthy
expect(old_address1.property_observer_list('street').to_a.empty?).to be_truthy
expect(old_address2.property_observer_list('street').to_a.empty?).to be_truthy
end
it "tests label widget nested computed value data binding string property" do
person = PersonWithNestedComputedValues.new
person.addresses = []
person.addresses[0] = PersonWithNestedComputedValues::Address.new
person.addresses[1] = PersonWithNestedComputedValues::Address.new
person.addresses[0].streets = ['123 Main', '234 Park']
person.addresses[1].streets = ['456 Milwaukee', '789 Superior', '983 Owen']
@target = shell {
composite {
@label1 = label {
text bind(person, 'addresses[0].street_count', computed_by: ['addresses[0].streets'])
}
@label2 = label {
text bind(person, 'addresses[1].street_count', computed_by: ['addresses[1].streets'])
}
}
}
expect(@label1.swt_widget.getText).to eq("2")
expect(@label2.swt_widget.getText).to eq("3")
person.addresses[0].streets = []
expect(@label1.swt_widget.getText).to eq("0")
person.addresses[0].streets = ['8376 Erie']
expect(@label1.swt_widget.getText).to eq("1")
person.addresses[0].streets.clear
expect(@label1.swt_widget.getText).to eq("0")
person.addresses[1].streets << '923 Huron'
expect(@label2.swt_widget.getText).to eq("4")
end
it 'removes observers upon disposing a widget' do
person = Person.new
person.adult = true
@target = shell {
composite {
@radio = button(:radio) {
selection bind(person, :adult)
}
}
}
expect(@radio.swt_widget.getSelection).to eq(true)
@radio.swt_widget.dispose
expect {person.adult = false}.to_not raise_error
end
it 'removes nested/indexed observers upon disposing a widget' do
person = PersonWithNestedIndexedProperties.new
person.addresses = []
person.addresses[0] = Address.new
person.addresses[1] = Address.new
@target = shell {
composite {
@address1_street_text_widget = text {
text bind(person, "addresses[0].street")
}
@address1b_street_text_widget = text {
text bind(person, "addresses[0].street")
}
@address2_street_text_widget = text {
text bind(person, "addresses[1].street")
}
}
}
@address1_street_text_widget.swt_widget.dispose
expect {person.addresses[0].street = "123 Main St"}.to_not raise_error
expect(@address1b_street_text_widget.swt_widget.getText).to eq("123 Main St")
person.addresses[1].street = "79 Park Ave"
expect(@address2_street_text_widget.swt_widget.getText).to eq("79 Park Ave")
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__scrolled_composite__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__scrolled_composite__spec.rb | require "spec_helper"
module GlimmerSpec
describe 'Glimmer Scrolled Composite' do
include Glimmer
it 'renders a scrolled composite with v_scroll and h_scroll styles' do
@target = shell {
@scrolled_composite = scrolled_composite {
@label = label {
text "Hello"
}
}
}
expect(@target).to be_a(Glimmer::SWT::ShellProxy)
expect(@scrolled_composite).to be_a(Glimmer::SWT::ScrolledCompositeProxy)
expect(@scrolled_composite).to have_style(:h_scroll)
expect(@scrolled_composite).to have_style(:v_scroll)
expect(@scrolled_composite.swt_widget.content).to eq(@label.swt_widget)
expect(@scrolled_composite.swt_widget.expand_horizontal).to eq(true)
expect(@scrolled_composite.swt_widget.expand_vertical).to eq(true)
expect(@scrolled_composite.swt_widget.min_width).to_not eq(0)
expect(@scrolled_composite.swt_widget.min_height).to_not eq(0)
expect(@label.swt_widget.parent).to eq(@scrolled_composite.swt_widget)
end
it 'renders a scrolled composite with v_scroll and h_scroll styles in addition to specified style' do
@target = shell {
@scrolled_composite = scrolled_composite(:border) {
}
}
expect(@scrolled_composite).to_not have_style(:h_scroll)
expect(@scrolled_composite).to_not have_style(:v_scroll)
expect(@scrolled_composite).to have_style(:border)
end
it 'renders a scrolled composite without v_scroll and h_scroll styles if using an integer SWT style' do
@target = shell {
@scrolled_composite = scrolled_composite(swt(:none)) {
}
}
expect(@target).to be_a(Glimmer::SWT::ShellProxy)
expect(@scrolled_composite).to be_a(Glimmer::SWT::ScrolledCompositeProxy)
expect(@scrolled_composite).to_not have_style(:h_scroll)
expect(@scrolled_composite).to_not have_style(:v_scroll)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__layout__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__layout__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Layout" do
include Glimmer
describe 'FillLayout' do
it "sets FillLayout with all properties specified via property methods" do
@target = shell {
@composite = composite {
fill_layout {
type :horizontal
margin_width 30
margin_height 50
spacing 5
}
}
}
widget = @composite.swt_widget
layout = widget.getLayout
expect(layout.is_a?(FillLayout)).to eq(true)
expect(layout.type).to eq(Glimmer::SWT::SWTProxy[:horizontal])
expect(layout.marginWidth).to eq(30)
expect(layout.marginHeight).to eq(50)
expect(layout.spacing).to eq(5)
end
it "sets FillLayout with one SWT constructor argument" do
@target = shell {
@composite = composite {
fill_layout(:horizontal)
}
}
widget = @composite.swt_widget
layout = widget.getLayout
expect(layout.is_a?(FillLayout)).to eq(true)
expect(layout.type).to eq(Glimmer::SWT::SWTProxy[:horizontal])
expect(layout.marginWidth).to eq(15)
expect(layout.marginHeight).to eq(15)
end
xit "sets FillLayout with :no_margin SWT constructor argument" do
@target = shell {
@composite = composite {
fill_layout(:no_margin)
}
}
widget = @composite.swt_widget
layout = widget.getLayout
expect(layout.is_a?(FillLayout)).to eq(true)
expect(layout.type).to eq(Glimmer::SWT::SWTProxy[:horizontal])
expect(layout.marginWidth).to eq(0)
expect(layout.marginHeight).to eq(0)
end
end
describe 'RowLayout' do
it "sets RowLayout with all properties specified via property methods" do
@target = shell {
@composite = composite {
row_layout {
wrap true
pack false
justify true
type :vertical
margin_left 1
margin_top 2
margin_right 3
margin_bottom 4
spacing 5
}
}
}
widget = @composite.swt_widget
layout = widget.getLayout
expect(layout.is_a?(RowLayout)).to eq(true)
expect(layout.wrap).to eq(true)
expect(layout.pack).to eq(false)
expect(layout.justify).to eq(true)
expect(layout.type).to eq(Glimmer::SWT::SWTProxy[:vertical])
expect(layout.marginLeft).to eq(1)
expect(layout.marginTop).to eq(2)
expect(layout.marginRight).to eq(3)
expect(layout.marginBottom).to eq(4)
expect(layout.spacing).to eq(5)
end
it "sets RowLayout with one SWT constructor argument" do
@target = shell {
@composite = composite {
row_layout :horizontal
}
}
widget = @composite.swt_widget
layout = widget.getLayout
expect(layout.is_a?(RowLayout)).to eq(true)
expect(layout.type).to eq(Glimmer::SWT::SWTProxy[:horizontal])
expect(layout.marginWidth).to eq(15)
expect(layout.marginHeight).to eq(15)
end
end
describe 'GridLayout' do
it "sets GridLayout with all properties specified via property methods" do
@target = shell {
@composite = composite {
grid_layout {
make_columns_equal_width true
num_columns 8
margin_left 1
margin_top 2
margin_right 3
margin_bottom 4
margin_width 30
margin_height 50
horizontal_spacing 4
vertical_spacing 5
}
}
}
widget = @composite.swt_widget
layout = widget.getLayout
expect(layout.is_a?(GridLayout)).to eq(true)
expect(layout.makeColumnsEqualWidth).to eq(true)
expect(layout.numColumns).to eq(8)
expect(layout.marginLeft).to eq(1)
expect(layout.marginTop).to eq(2)
expect(layout.marginRight).to eq(3)
expect(layout.marginBottom).to eq(4)
expect(layout.marginWidth).to eq(30)
expect(layout.marginHeight).to eq(50)
expect(layout.horizontalSpacing).to eq(4)
expect(layout.verticalSpacing).to eq(5)
end
it "sets GridLayout with one SWT constructor argument" do
@target = shell {
@composite = composite {
grid_layout 8, true
}
}
widget = @composite.swt_widget
layout = widget.getLayout
expect(layout.is_a?(GridLayout)).to eq(true)
expect(layout.makeColumnsEqualWidth).to eq(true)
expect(layout.numColumns).to eq(8)
expect(layout.marginWidth).to eq(15)
expect(layout.marginHeight).to eq(15)
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__message_box__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__message_box__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Message Box" do
include Glimmer
it 'renders a message box without specifying a shell' do
@target = @message_box = message_box {
text 'Hello'
message 'Hello, this is a greeting!'
}
expect(@message_box).to be_a(Glimmer::SWT::MessageBoxProxy)
expect(@message_box.swt_widget).to be_a(MessageBox)
expect(@message_box.swt_widget.getText).to eq('Hello')
expect(@message_box.swt_widget.getMessage).to eq('Hello, this is a greeting!')
end
it 'renders a message box nested inside a shell' do
@target = shell {
@message_box = message_box {
text 'Hello'
message 'Hello, this is a greeting!'
}
}
expect(@message_box).to be_a(Glimmer::SWT::MessageBoxProxy)
expect(@message_box.swt_widget).to be_a(MessageBox)
expect(@message_box.swt_widget.getText).to eq('Hello')
expect(@message_box.swt_widget.getMessage).to eq('Hello, this is a greeting!')
end
it 'renders a message box nested inside a shell with some properties set via content method' do
@target = shell {
@message_box = message_box {
text 'Hello'
}
}
@message_box.content {
message 'Hello, this is a greeting!'
}
expect(@message_box).to be_a(Glimmer::SWT::MessageBoxProxy)
expect(@message_box.swt_widget).to be_a(MessageBox)
expect(@message_box.swt_widget.getText).to eq('Hello')
expect(@message_box.swt_widget.getMessage).to eq('Hello, this is a greeting!')
end
it 'renders a message box with style nested inside a shell' do
@target = shell {
@message_box = message_box(:icon_information, :yes, :no, :cancel) {
text 'Hello'
message 'Hello, this is a greeting!'
}
}
expect(@message_box).to be_a(Glimmer::SWT::MessageBoxProxy)
expect(@message_box.swt_widget).to be_a(MessageBox)
expect(@message_box.swt_widget.getText).to eq('Hello')
expect(@message_box.swt_widget.getMessage).to eq('Hello, this is a greeting!')
expect(@message_box.swt_widget).to have_style(:icon_information)
expect(@message_box.swt_widget).to have_style(:yes)
expect(@message_box.swt_widget).to have_style(:no)
expect(@message_box.swt_widget).to have_style(:cancel)
end
it 'renders a message box taking a shell as an argument' do
@target = shell
@message_box = message_box(@target) {
text 'Hello'
message 'Hello, this is a greeting!'
}
expect(@message_box).to be_a(Glimmer::SWT::MessageBoxProxy)
expect(@message_box.swt_widget).to be_a(MessageBox)
expect(@message_box.swt_widget.getText).to eq('Hello')
expect(@message_box.swt_widget.getMessage).to eq('Hello, this is a greeting!')
end
it 'renders a message box taking a shell as an argument and a style' do
@target = shell
@message_box = message_box(@target, :icon_error, :ok, :cancel) {
text 'Hello'
message 'Hello, this is a greeting!'
}
expect(@message_box).to be_a(Glimmer::SWT::MessageBoxProxy)
expect(@message_box.swt_widget).to be_a(MessageBox)
expect(@message_box.swt_widget.getText).to eq('Hello')
expect(@message_box.swt_widget.getMessage).to eq('Hello, this is a greeting!')
expect(@message_box.swt_widget).to have_style(:icon_error)
expect(@message_box.swt_widget).to have_style(:ok)
expect(@message_box.swt_widget).to have_style(:cancel)
end
it 'data-binds message box text and message' do
MessageData = Struct.new(:text, :message)
data = MessageData.new('Hello', 'Hello, this is a greeting!')
@target = shell
@message_box = message_box(@target) {
text bind(data, :text)
message bind(data, :message)
}
expect(@message_box.swt_widget.getText).to eq('Hello')
expect(@message_box.swt_widget.getMessage).to eq('Hello, this is a greeting!')
data.text = 'Howdy'
data.message = 'Howdy Partner!'
expect(@message_box.swt_widget.getText).to eq('Howdy')
expect(@message_box.swt_widget.getMessage).to eq('Howdy Partner!')
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__shine_data_binding__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__shine_data_binding__spec.rb | ## NOTE: Unsupported in Ruby 2 syntax
# require "spec_helper"
#
# require_relative "../../lib/shine"
#
# describe "Glimmer Shine Data Binding" do
# include Glimmer
#
# include_package 'org.eclipse.swt'
# include_package 'org.eclipse.swt.swt_widgets'
# include_package 'org.eclipse.swt.layout'
#
# after do
# @target.dispose if @target
# end
#
# class Person
# attr_accessor :name, :age, :adult
# end
#
# it "tests text_widget_data_binding_string_property_spaceship" do
# person = Person.new
# person.name = "Bruce Ting"
#
# @target = shell {
# composite {
# @text = text {
# }
# }
# }
#
# [@text, :text] <=> [person, :name]
#
# expect(@text.swt_widget.getText).to eq( "Bruce Ting")
#
# person.name = "Lady Butterfly"
# expect(@text.swt_widget.getText).to eq( "Lady Butterfly")
#
# @text.swt_widget.setText("Allen Cork")
# expect(person.name).to eq( "Allen Cork")
#
# comparison = ["he"] <=> ["he"]
# expect(comparison).to eq(0)
# end
#
# it "tests multiple_widget_data_bindings_to_different_model_properties_spaceship" do
# person = Person.new
# person.name = "Nancy"
# person.age = 15
# person.adult = true
#
# @target = shell {
# composite {
# @label = label {}
# @text = text {}
# @check_box = button(:check) {}
# }
# }
#
# [@label, :text] <=> [person, :name]
# [@text, :text] <=> [person, :age, on_write: :to_i]
# [@check_box, :selection] <=> [person, :adult]
#
# expect(@label.swt_widget.getText).to eq( "Nancy")
# expect(@text.swt_widget.getText).to eq( "15")
# expect(@check_box.swt_widget.getSelection).to eq( true)
#
# person.name = "Drew"
# expect(@label.swt_widget.getText).to eq( "Drew")
#
# person.age = 27
# expect(@text.swt_widget.getText).to eq( "27")
#
# person.adult = false
# expect(@check_box.swt_widget.getSelection).to eq( false)
#
# @text.swt_widget.setText("30")
# expect(person.age).to eq( 30)
#
# @check_box.swt_widget.setSelection(true)
# @check_box.swt_widget.notifyListeners(SWT::Selection, nil)
# expect(person.adult).to eq( true)
# end
#
# end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__image__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__image__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Image" do
include Glimmer
it "builds ImageProxy with file path" do
@target = @image = image(File.join(ROOT_PATH, 'images', 'glimmer-hello-world.png'))
expect(@target.bounds.width).to eq(132)
expect(@target.bounds.height).to eq(40)
end
it "builds ImageProxy with file path and width/height" do
@target = @image = image(File.join(ROOT_PATH, 'images', 'glimmer-hello-world.png'), width: 300, height: 200)
expect(@target.bounds.width).to eq(300)
expect(@target.bounds.height).to eq(200)
end
it "builds ImageProxy with file path and width, maintaining aspect ratio of height" do
@target = @image = image(File.join(ROOT_PATH, 'images', 'glimmer-hello-world.png'), width: 300)
expect(@target.bounds.width).to eq(300)
expect(@target.bounds.height).to eq(90)
end
it "builds ImageProxy with file path and height, maintaining aspect ratio of width" do
@target = @image = image(File.join(ROOT_PATH, 'images', 'glimmer-hello-world.png'), height: 200)
expect(@target.bounds.width).to eq(660)
expect(@target.bounds.height).to eq(200)
end
it 'builds ImageProxy with image' do
swt_image = Image.new(display.swt_display, File.join(ROOT_PATH, 'images', 'glimmer-hello-world.png'))
@target = @image = image(swt_image)
expect(@target.bounds.width).to eq(132)
expect(@target.bounds.height).to eq(40)
end
it 'builds ImageProxy with swt_image option' do
swt_image = Image.new(display.swt_display, File.join(ROOT_PATH, 'images', 'glimmer-hello-world.png'))
@target = @image = image(swt_image: swt_image)
expect(@target.bounds.width).to eq(132)
expect(@target.bounds.height).to eq(40)
end
it 'builds ImageProxy with array of args' do
@target = @image = image(display.swt_display, File.join(ROOT_PATH, 'images', 'glimmer-hello-world.png'))
expect(@target.bounds.width).to eq(132)
expect(@target.bounds.height).to eq(40)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__layout_data__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__layout_data__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Layout Data" do
include Glimmer
before(:all) do
class ::RedLabel
include Glimmer::UI::CustomWidget
body {
label(swt_style) {
background :red
}
}
end
end
after(:all) do
Object.send(:remove_const, :RedLabel) if Object.const_defined?(:RedLabel)
end
describe 'RowData' do
it "sets RowData with all properties specified via property methods" do
@target = shell {
composite {
row_layout(:horizontal)
@label = label {
layout_data {
exclude true
width 50
height 30
}
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(RowData)).to eq(true)
expect(layout_data.exclude).to eq(true)
expect(layout_data.width).to eq(50)
expect(layout_data.height).to eq(30)
end
it "sets RowData with width/height constructor arguments" do
@target = shell {
composite {
row_layout(:horizontal)
@label = label {
layout_data 50, 30
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(RowData)).to eq(true)
expect(layout_data.height).to eq(30)
expect(layout_data.width).to eq(50)
end
it "sets RowData with Point constructor argument" do
@point = Point.new(50, 30)
@target = shell {
composite {
row_layout(:horizontal)
@label = label {
layout_data @point
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(RowData)).to eq(true)
expect(layout_data.height).to eq(30)
expect(layout_data.width).to eq(50)
end
it "sets RowData explicitly" do
@point = Point.new(50, 30)
@target = shell {
composite {
row_layout(:horizontal)
@label = label {
layout_data RowData.new(50, 30)
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(RowData)).to eq(true)
expect(layout_data.height).to eq(30)
expect(layout_data.width).to eq(50)
end
it "sets RowData on a custom widget" do
@target = shell {
composite {
row_layout(:horizontal)
@label = red_label {
layout_data {
exclude true
width 50
height 30
}
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(RowData)).to eq(true)
expect(layout_data.exclude).to eq(true)
expect(layout_data.width).to eq(50)
expect(layout_data.height).to eq(30)
end
end
describe 'GridData' do
it "sets layout data with all properties specified via property methods" do
@target = shell {
composite {
# grid_layout # default layout
@label = label {
layout_data {
exclude true
width_hint 50
height_hint 30
grab_excess_horizontal_space true
grab_excess_vertical_space false
horizontal_alignment :end
vertical_alignment :beginning
horizontal_indent 10
vertical_indent 20
horizontal_span 15
vertical_span 25
minimum_width 49
minimum_height 29
}
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(GridData)).to eq(true)
expect(layout_data.exclude).to eq(true)
expect(layout_data.widthHint).to eq(50)
expect(layout_data.heightHint).to eq(30)
expect(layout_data.grabExcessHorizontalSpace).to eq(true)
expect(layout_data.grabExcessVerticalSpace).to eq(false)
expect(layout_data.horizontalAlignment).to eq(Glimmer::SWT::SWTProxy[:end])
expect(layout_data.verticalAlignment).to eq(Glimmer::SWT::SWTProxy[:beginning])
expect(layout_data.horizontalIndent).to eq(10)
expect(layout_data.verticalIndent).to eq(20)
expect(layout_data.horizontalSpan).to eq(15)
expect(layout_data.verticalSpan).to eq(25)
expect(layout_data.minimumWidth).to eq(49)
expect(layout_data.minimumHeight).to eq(29)
end
it "sets GridData with width/height constructor arguments" do
@target = shell {
composite {
# grid_layout # default layout
@label = label {
layout_data 50, 30
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(GridData)).to eq(true)
expect(layout_data.widthHint).to eq(50)
expect(layout_data.heightHint).to eq(30)
end
it "sets GridData with 4 constructor arguments" do
@target = shell {
composite {
# grid_layout # default layout
@label = label {
layout_data :fill, :end, true, false
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(GridData)).to eq(true)
expect(layout_data.grabExcessHorizontalSpace).to eq(true)
expect(layout_data.grabExcessVerticalSpace).to eq(false)
expect(layout_data.horizontalAlignment).to eq(Glimmer::SWT::SWTProxy[:fill])
expect(layout_data.verticalAlignment).to eq(Glimmer::SWT::SWTProxy[:end])
end
it "sets GridData with 6 constructor arguments" do
@target = shell {
composite {
# grid_layout # default layout
@label = label {
layout_data Glimmer::SWT::SWTProxy[:fill], Glimmer::SWT::SWTProxy[:end], true, false, 15, 25
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(GridData)).to eq(true)
expect(layout_data.grabExcessHorizontalSpace).to eq(true)
expect(layout_data.grabExcessVerticalSpace).to eq(false)
expect(layout_data.horizontalAlignment).to eq(Glimmer::SWT::SWTProxy[:fill])
expect(layout_data.verticalAlignment).to eq(Glimmer::SWT::SWTProxy[:end])
expect(layout_data.horizontalSpan).to eq(15)
expect(layout_data.verticalSpan).to eq(25)
end
it "sets GridData explicitly" do
@target = shell {
composite {
# grid_layout # default layout
@label = label {
layout_data GridData.new(Glimmer::SWT::SWTProxy[:fill], Glimmer::SWT::SWTProxy[:end], true, false)
}
}
}
widget = @label.swt_widget
layout_data = widget.getLayoutData
expect(layout_data.is_a?(GridData)).to eq(true)
expect(layout_data.grabExcessHorizontalSpace).to eq(true)
expect(layout_data.grabExcessVerticalSpace).to eq(false)
expect(layout_data.horizontalAlignment).to eq(Glimmer::SWT::SWTProxy[:fill])
expect(layout_data.verticalAlignment).to eq(Glimmer::SWT::SWTProxy[:end])
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__expand_item__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__expand_item__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Expand Item" do
include Glimmer
it "renders expand item composite with default layout" do
@target = shell {
@expand_bar = expand_bar {
@expand_item_composite = expand_item {
text "Expand Item 1"
label {text "Hello"}
}
}
}
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@expand_bar.swt_widget.items.size).to eq(1)
expect(@expand_item_composite.swt_widget).to be_instance_of(Composite)
expect(@expand_bar.swt_widget.items[0].control).to eq(@expand_item_composite.swt_widget)
expect(@expand_item_composite.swt_expand_item.getText).to eq("Expand Item 1")
expect(@expand_item_composite.swt_expand_item.getExpanded).to be_truthy
expect(@expand_item_composite.swt_widget.getLayout).to_not be_nil
expect(@expand_item_composite.swt_widget.getLayout).to be_instance_of(FillLayout)
expect(@expand_item_composite.swt_widget.getLayout.marginWidth).to eq(0)
expect(@expand_item_composite.swt_widget.getLayout.marginHeight).to eq(0)
expect(@expand_item_composite.swt_widget.getLayout.spacing).to eq(0)
unless OS.linux?
expect(@expand_item_composite.swt_widget.bounds.height > 0).to be_truthy
end
end
it "renders expand item composite with a specified height and not expanded" do
@target = shell {
@expand_bar = expand_bar {
@expand_item_composite = expand_item {
text "Expand Item 1"
height OS.windows? ? 500 : 501
expanded false
label {text "Hello"}
}
}
}
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@expand_bar.swt_widget.items.size).to eq(1)
expect(@expand_item_composite.swt_widget).to be_instance_of(Composite)
expect(@expand_bar.swt_widget.items[0].control).to eq(@expand_item_composite.swt_widget)
expect(@expand_item_composite.swt_expand_item.getText).to eq("Expand Item 1")
expect(@expand_item_composite.swt_expand_item.getExpanded).to be_falsey
unless OS.linux?
expect(@expand_item_composite.swt_widget.bounds.height).to eq(500) # 501 loses 1 pixel, so 500 (not really sure why, but that's how it works)
end
end
it "renders expand item composite with invalid parent (not an expand bar)" do
@target = shell
expect {
@target.content {
@invalid_parent = composite {
@expand_item_composite = expand_item {
text "Expand Item 1"
label {text "Hello"}
}
}
}
}.to raise_error(StandardError)
end
it "renders expand item composite with fill layout" do
@target = shell {
@expand_bar = expand_bar {
@expand_item_composite = expand_item {
grid_layout 1, false
text "Expand Item 2"
label {text "Hello"}
}
}
}
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@expand_bar.swt_widget.items.size).to eq(1)
expect(@expand_item_composite.swt_widget).to be_instance_of(Composite)
expect(@expand_bar.swt_widget.items[0].control).to eq(@expand_item_composite.swt_widget)
expect(@expand_item_composite.swt_expand_item.getText).to eq("Expand Item 2")
expect(@expand_item_composite.swt_widget.getLayout).to_not be_nil
expect(@expand_item_composite.swt_widget.getLayout).to be_instance_of(GridLayout)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__list_data_binding__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__list_data_binding__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer List Data Binding" do
include Glimmer
before(:all) do
class Person
attr_accessor :country, :country_options
attr_accessor :provinces, :provinces_options
def initialize
self.country_options=[
"",
"Canada",
"US",
"Mexico"
]
self.provinces_options=[
"",
"Quebec",
"Ontario",
"Manitoba",
"Saskatchewan",
"Alberta",
"British Columbia",
"Nova Skotia",
"Newfoundland"
]
end
end
class ::RedList
include Glimmer::UI::CustomWidget
body {
list(swt_style) {
background :red
}
}
end
end
after(:all) do
Object.send(:remove_const, :Person) if Object.const_defined?(:Person)
Object.send(:remove_const, :RedList) if Object.const_defined?(:RedList)
end
it "tests single selection property" do
person = Person.new
@target = shell {
@list = list {
selection bind(person, :country)
}
}
expect(@list.swt_widget.item_count).to eq(4)
expect(@list.swt_widget.selection_index).to eq(-1)
expect(@list.swt_widget.selection.to_a).to eq([])
@list.swt_widget.select(1)
@list.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.country).to eq("Canada")
person.country_options << "France"
expect(@list.swt_widget.item_count).to eq(5)
person.country_options=["", "Canada", "US", "Mexico", "Russia", "France"]
expect(@list.swt_widget.item_count).to eq(6)
person.country_options << "Italy"
person.country_options << "Germany"
person.country_options << "Australia"
expect(@list.swt_widget.item_count).to eq(9)
person.country = "Canada"
expect(@list.swt_widget.selection_index).to eq(1)
expect(@list.swt_widget.selection.to_a).to eq(["Canada"])
person.country = "Russia"
expect(@list.swt_widget.selection_index).to eq(4)
expect(@list.swt_widget.selection.to_a).to eq(["Russia"])
person.country = ""
expect(@list.swt_widget.selection_index).to eq(0)
expect(@list.swt_widget.selection.to_a).to eq([""])
person.country = "Japan"
expect(@list.swt_widget.selection_index).to eq(0)
expect(@list.swt_widget.selection.to_a).to eq([""])
@list.swt_widget.select(2)
@list.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.country).to eq("US")
end
it "tests single selection property with model preinitialized" do
person = Person.new
person.country = "Canada"
@target = shell {
@list = list {
selection bind(person, :country)
}
}
expect(@list.swt_widget.item_count).to eq(4)
expect(@list.swt_widget.selection_index).to eq(1)
expect(@list.swt_widget.selection.to_a).to eq(["Canada"])
@list.swt_widget.select(2)
@list.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.country).to eq("US")
person.country_options << "France"
expect(@list.swt_widget.item_count).to eq(5)
person.country_options=["", "Canada", "US", "Mexico", "Russia", "France"]
expect(@list.swt_widget.item_count).to eq(6)
person.country_options << "Italy"
person.country_options << "Germany"
person.country_options << "Australia"
expect(@list.swt_widget.item_count).to eq(9)
person.country = "Canada"
expect(@list.swt_widget.selection_index).to eq(1)
expect(@list.swt_widget.selection.to_a).to eq(["Canada"])
person.country = "Russia"
expect(@list.swt_widget.selection_index).to eq(4)
expect(@list.swt_widget.selection.to_a).to eq(["Russia"])
person.country = ""
expect(@list.swt_widget.selection_index).to eq(0)
expect(@list.swt_widget.selection.to_a).to eq([""])
person.country = "Japan"
expect(@list.swt_widget.selection_index).to eq(0)
expect(@list.swt_widget.selection.to_a).to eq([""])
end
it "tests multi selection property" do
person = Person.new
@target = shell {
@list = list(:multi) {
selection bind(person, :provinces)
}
}
expect(@list.swt_widget.selection_count.to_i).to eq(0)
expect(@list.swt_widget.selection.to_a).to eq([])
@list.swt_widget.select(1)
@list.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.provinces).to eq(["Quebec"])
@list.swt_widget.select(2)
@list.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.provinces).to eq(["Quebec", "Ontario"])
person.provinces=["Ontario", "Manitoba", "Alberta"]
expect(@list.swt_widget.selection_count.to_i).to eq(3)
expect(@list.swt_widget.selection_indices.to_a).to eq([2, 3, 5])
expect(@list.swt_widget.selection.to_a).to eq(["Ontario", "Manitoba", "Alberta"])
person.provinces << "Quebec"
person.provinces << "Saskatchewan"
person.provinces << "British Columbia"
expect(@list.swt_widget.selection_count.to_i).to eq(6)
expect(@list.swt_widget.selection_indices.to_a).to eq([1, 2, 3, 4, 5, 6])
expect(@list.swt_widget.selection.to_a).to eq(["Quebec", "Ontario", "Manitoba", "Saskatchewan", "Alberta", "British Columbia"])
end
it "tests multi selection property with model preinitialized" do
person = Person.new
person.provinces = []
@target = shell {
@list = list(:multi) {
selection bind(person, :provinces)
}
}
expect(@list.swt_widget.selection_count.to_i).to eq(0)
expect(@list.swt_widget.selection.to_a).to eq([])
@list.swt_widget.select(1)
@list.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.provinces).to eq(["Quebec"])
@list.swt_widget.select(2)
@list.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.provinces).to eq(["Quebec", "Ontario"])
person.provinces=["Ontario", "Manitoba", "Alberta"]
expect(@list.swt_widget.selection_count.to_i).to eq(3)
expect(@list.swt_widget.selection_indices.to_a).to eq([2, 3, 5])
expect(@list.swt_widget.selection.to_a).to eq(["Ontario", "Manitoba", "Alberta"])
person.provinces << "Quebec"
person.provinces << "Saskatchewan"
person.provinces << "British Columbia"
expect(@list.swt_widget.selection_count.to_i).to eq(6)
expect(@list.swt_widget.selection_indices.to_a).to eq([1, 2, 3, 4, 5, 6])
expect(@list.swt_widget.selection.to_a).to eq(["Quebec", "Ontario", "Manitoba", "Saskatchewan", "Alberta", "British Columbia"])
old_provinces = person.provinces
expect(old_provinces.property_observer_list.to_a.empty?).to be_falsey
person.provinces = ["Quebec", "Saskatchewan", "British Columbia"]
expect(@list.swt_widget.selection_count.to_i).to eq(3)
expect(@list.swt_widget.selection.to_a).to eq(["Quebec", "Saskatchewan", "British Columbia"])
# old binding doesn't observe anymore
old_provinces << "New Brunswick"
expect(@list.swt_widget.selection_count.to_i).to eq(3)
expect(@list.swt_widget.selection.to_a).to eq(["Quebec", "Saskatchewan", "British Columbia"])
expect(old_provinces.property_observer_list.to_a.empty?).to be_truthy
end
it "tests single selection property with a custom widget list" do
person = Person.new
@target = shell {
@list = red_list {
selection bind(person, :country)
}
}
expect(@list.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@list.swt_widget.item_count).to eq(4)
expect(@list.swt_widget.selection_index).to eq(-1)
expect(@list.swt_widget.selection.to_a).to eq([])
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__display__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__display__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Display" do
include Glimmer
context 'standard operation' do
after do
@target2.dispose if @target2
end
it "instantiates display" do
@target = display
expect(@target).to be_a(Glimmer::SWT::DisplayProxy)
expect(@target.swt_display).to be_a(Display)
expect(@target.swt_display.isDisposed).to be_falsey
expect(@target.isDisposed).to be_falsey
@target2 = display
expect(@target2.swt_display).to eq(@target.swt_display)
@target2.dispose
@target2 = display
expect(@target2.swt_display).to_not eq(@target.swt_display)
end
it "sets data('proxy')" do
@target = display
expect(@target.swt_display.get_data('proxy')).to eq(@target)
end
end
context 'filter listeners' do
it 'adds filter listener' do
@display = display {
on_swt_show {
@shown = true
}
}
@target = shell {
alpha 0 # keep invisible while running specs
}
async_exec do
expect(@shown).to eq(true)
@target.dispose
end
@target.open
end
it 'adds filter listener via alternative syntax' do
@display = display
@display.on_swt_show {
@shown = true
}
@target = shell {
alpha 0 # keep invisible while running specs
}
async_exec do
expect(@shown).to eq(true)
@target.dispose
end
@target.open
end
it 'adds filter listener via content method' do
@display = display.content {
on_swt_show {
@shown = true
}
}
@target = shell {
alpha 0 # keep invisible while running specs
}
async_exec do
expect(@shown).to eq(true)
@target.dispose
end
@target.open
end
end
context 'UI code execution' do
after do
if @target
@target.async_exec do
@target.dispose
end
@target.start_event_loop
end
end
it 'asyncronously executes UI code' do
@target = shell {
@text = text {
text "text1"
}
}
Glimmer::SWT::DisplayProxy.instance.swt_display.async_exec do
@text.swt_widget.setText("text2")
end
expect(@text.swt_widget.getText).to_not eq("text2")
Glimmer::SWT::DisplayProxy.instance.async_exec do
expect(@text.swt_widget.getText).to eq("text2")
end
end
it "syncronously executes UI code" do
@target = shell {
@text = text {
text "text1"
}
}
display.swt_display.async_exec do
expect(@text.swt_widget.getText).to eq("text2")
end
# This takes prioerity over async_exec
display.sync_exec do
@text.swt_widget.setText("text2")
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__drag_and_drop__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__drag_and_drop__spec.rb | require 'spec_helper'
require 'ostruct'
module GlimmerSpec
describe "Glimmer Drag & Drop" do
include Glimmer
before(:all) do
class ::RedLabel
include Glimmer::UI::CustomWidget
body {
label {
background :red
}
}
end
end
after(:all) do
Object.send(:remove_const, :RedLabel) if Object.const_defined?(:RedLabel)
end
context 'explicit drag_source and drop_target' do
it "creates a DragSource and DropTarget with default Style DND::DROP_COPY and transfer property as default TextTransfer value" do
@target = shell {
@drag_source_label = label {
on_drag_start { |event|
}
on_drag_set_data { |event|
}
on_drag_finished { |event|
}
}
@drop_target_label = label {
on_drag_enter { |event|
}
on_drag_leave { |event|
}
on_drag_operation_changed { |event|
}
on_drag_over { |event|
}
on_drop { |event|
}
on_drop_accept { |event|
}
}
}
@drag_source = @drag_source_label.drag_source_proxy
@drop_target = @drop_target_label.drop_target_proxy
expect(@drag_source).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drag_source.swt_widget).to be_a(org.eclipse.swt.dnd.DragSource)
expect(@drag_source.swt_widget.getStyle).to eq(DND::DROP_COPY)
expect(@drag_source.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.TextTransfer.getInstance].to_java(Transfer))
expect(@drop_target).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drop_target.swt_widget).to be_a(org.eclipse.swt.dnd.DropTarget)
expect(@drop_target.swt_widget.getStyle).to eq(DND::DROP_COPY)
expect(@drop_target.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.TextTransfer.getInstance].to_java(Transfer))
end
it "creates a DragSource and DropTarget with default Style DND::DROP_COPY and transfer property as default TextTransfer value on CustomWidget" do
@target = shell {
@drag_source_label = red_label {
on_drag_start { |event|
}
on_drag_set_data { |event|
}
on_drag_finished { |event|
}
}
@drop_target_label = red_label {
on_drag_enter { |event|
}
on_drag_leave { |event|
}
on_drag_operation_changed { |event|
}
on_drag_over { |event|
}
on_drop { |event|
}
on_drop_accept { |event|
}
}
}
@drag_source = @drag_source_label.drag_source_proxy
@drop_target = @drop_target_label.drop_target_proxy
expect(@drag_source).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drag_source.swt_widget).to be_a(org.eclipse.swt.dnd.DragSource)
expect(@drag_source.swt_widget.getStyle).to eq(DND::DROP_COPY)
expect(@drag_source.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.TextTransfer.getInstance].to_java(Transfer))
expect(@drop_target).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drop_target.swt_widget).to be_a(org.eclipse.swt.dnd.DropTarget)
expect(@drop_target.swt_widget.getStyle).to eq(DND::DROP_COPY)
expect(@drop_target.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.TextTransfer.getInstance].to_java(Transfer))
end
it "creates a DragSource and DropTarget with specified style DND::DROP_LINK and transfer property of HTMLTransfer value" do
@target = shell {
@drag_source_label = label { |drag_source_label_proxy|
drag_source_style dnd(:drop_link)
drag_source_transfer [org.eclipse.swt.dnd.HTMLTransfer.getInstance].to_java(Transfer)
@drag_source_effect_object = DragSourceEffect.new(drag_source_label_proxy.swt_widget)
drag_source_effect @drag_source_effect_object
on_drag_start { |event|
}
on_drag_set_data { |event|
}
on_drag_finished { |event|
}
}
@drop_target_label = label { |drop_target_label_proxy|
drop_target_style dnd('drop_link')
drop_target_transfer [org.eclipse.swt.dnd.HTMLTransfer.getInstance].to_java(Transfer)
@drop_target_effect_object = DropTargetEffect.new(drop_target_label_proxy.swt_widget)
drop_target_effect @drop_target_effect_object
on_drag_enter { |event|
}
on_drag_leave { |event|
}
on_drag_operation_changed { |event|
}
on_drag_over { |event|
}
on_drop { |event|
}
on_drop_accept { |event|
}
}
}
@drag_source = @drag_source_label.drag_source_proxy
@drop_target = @drop_target_label.drop_target_proxy
expect(@drag_source).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drag_source.swt_widget).to be_a(org.eclipse.swt.dnd.DragSource)
expect(@drag_source.swt_widget.getStyle).to eq(DND::DROP_LINK)
expect(@drag_source.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.HTMLTransfer.getInstance].to_java(Transfer))
expect(@drag_source.swt_widget.getDragSourceEffect).to eq(@drag_source_effect_object)
expect(@drop_target).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drop_target.swt_widget).to be_a(org.eclipse.swt.dnd.DropTarget)
expect(@drop_target.swt_widget.getStyle).to eq(DND::DROP_LINK)
expect(@drop_target.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.HTMLTransfer.getInstance].to_java(Transfer))
expect(@drop_target.swt_widget.getDropTargetEffect).to eq(@drop_target_effect_object)
end
it "creates a DragSource and DropTarget with specified style :drop_link and transfer property of :html value" do
@target = shell {
@drag_source_label = label {
drag_source_style :drop_link
drag_source_transfer :html
on_drag_start { |event|
}
on_drag_set_data { |event|
}
on_drag_finished { |event|
}
}
@drop_target_label = label {
drop_target_style 'drop_link'
drop_target_transfer :html
on_drag_enter { |event|
}
on_drag_leave { |event|
}
on_drag_operation_changed { |event|
}
on_drag_over { |event|
}
on_drop { |event|
}
on_drop_accept { |event|
}
}
}
@drag_source = @drag_source_label.drag_source_proxy
@drop_target = @drop_target_label.drop_target_proxy
expect(@drag_source).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drag_source.swt_widget).to be_a(org.eclipse.swt.dnd.DragSource)
expect(@drag_source.swt_widget.getStyle).to eq(DND::DROP_LINK)
expect(@drag_source.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.HTMLTransfer.getInstance].to_java(Transfer))
expect(@drop_target).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drop_target.swt_widget).to be_a(org.eclipse.swt.dnd.DropTarget)
expect(@drop_target.swt_widget.getStyle).to eq(DND::DROP_LINK)
expect(@drop_target.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.HTMLTransfer.getInstance].to_java(Transfer))
end
it "creates a DragSource and DropTarget with specified styles :drop_copy and :drop_move and transfer property as an array of values" do
@target = shell {
@drag_source_label = label {
drag_source_style 'drop_copy', 'drop_move'
drag_source_transfer :text, :html
on_drag_start { |event|
}
on_drag_set_data { |event|
}
on_drag_finished { |event|
}
}
@drop_target_label = label {
drop_target_style :drop_copy, :drop_move
drop_target_transfer :text, :html
on_drag_enter { |event|
}
on_drag_leave { |event|
}
on_drag_operation_changed { |event|
}
on_drag_over { |event|
}
on_drop { |event|
}
on_drop_accept { |event|
}
}
}
@drag_source = @drag_source_label.drag_source_proxy
@drop_target = @drop_target_label.drop_target_proxy
expect(@drag_source).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drag_source.swt_widget).to be_a(org.eclipse.swt.dnd.DragSource)
expect(@drag_source.has_style?([:drop_copy, :drop_move])).to be_truthy
expect(@drag_source.swt_widget.getStyle).to eq(Glimmer::SWT::DNDProxy[:drop_copy, :drop_move])
expect(@drag_source.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.TextTransfer.getInstance, org.eclipse.swt.dnd.HTMLTransfer.getInstance].to_java(Transfer))
expect(@drop_target.swt_widget).to be_a(org.eclipse.swt.dnd.DropTarget)
expect(@drop_target).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drop_target.has_style?([:drop_copy, :drop_move])).to be_truthy
expect(@drop_target.swt_widget.getStyle).to eq(Glimmer::SWT::DNDProxy[:drop_copy, :drop_move])
expect(@drop_target.swt_widget.getTransfer).to eq([org.eclipse.swt.dnd.TextTransfer.getInstance, org.eclipse.swt.dnd.HTMLTransfer.getInstance].to_java(Transfer))
end
it "creates an implicit DragSource and DropTarget with default style DND::DROP_COPY, default transfer :text, default on_drag_enter listener that sets default operation DND::DROP_COPY on_drag_enter in DropTarget" do
@target = shell {
@drag_source_label = label {
drag_source_style 'drop_copy', 'drop_move'
drag_source_transfer :file, :html, :image, :rtf, :text, :url
}
@drop_target_label = label {
drop_target_style :drop_copy, :drop_move
drop_target_transfer ['file', 'html', 'image', :rtf, :text, :url]
}
}
@drag_source = @drag_source_label.drag_source_proxy
@drop_target = @drop_target_label.drop_target_proxy
expect(@drag_source).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drag_source.swt_widget).to be_a(org.eclipse.swt.dnd.DragSource)
expect(@drag_source.has_style?([:drop_copy, :drop_move])).to be_truthy
expect(@drag_source.swt_widget.getStyle).to eq(Glimmer::SWT::DNDProxy[:drop_copy, :drop_move])
expect(@drag_source.swt_widget.getTransfer).to eq([
org.eclipse.swt.dnd.FileTransfer.getInstance,
org.eclipse.swt.dnd.HTMLTransfer.getInstance,
org.eclipse.swt.dnd.ImageTransfer.getInstance,
org.eclipse.swt.dnd.RTFTransfer.getInstance,
org.eclipse.swt.dnd.TextTransfer.getInstance,
org.eclipse.swt.dnd.URLTransfer.getInstance,
].to_java(Transfer))
expect(@drop_target.swt_widget).to be_a(org.eclipse.swt.dnd.DropTarget)
expect(@drop_target).to be_a(Glimmer::SWT::WidgetProxy)
expect(@drop_target.has_style?([:drop_copy, :drop_move])).to be_truthy
expect(@drop_target.swt_widget.getStyle).to eq(Glimmer::SWT::DNDProxy[:drop_copy, :drop_move])
expect(@drop_target.swt_widget.getTransfer).to eq([
org.eclipse.swt.dnd.FileTransfer.getInstance,
org.eclipse.swt.dnd.HTMLTransfer.getInstance,
org.eclipse.swt.dnd.ImageTransfer.getInstance,
org.eclipse.swt.dnd.RTFTransfer.getInstance,
org.eclipse.swt.dnd.TextTransfer.getInstance,
org.eclipse.swt.dnd.URLTransfer.getInstance,
].to_java(Transfer))
listeners = @drop_target.swt_widget.getDropListeners
event = OpenStruct.new
listeners.to_a[0].dragEnter(event)
expect(event.detail).to eq(DND::DROP_COPY)
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__tree__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__tree__spec.rb | require 'spec_helper'
module GlimmerSpec
describe "Glimmer Tree Data Binding" do
include Glimmer
before(:all) do
class Person
attr_accessor :name, :age, :adult, :coworkers
def initialize
@coworkers = []
end
end
class Manager < Person
attr_accessor :coworkers
end
class Company
attr_accessor :selected_coworker
attr_accessor :owner
def initialize
@owner = []
end
end
class CompanyGroup
attr_accessor :companies
def initialize
@companies = []
end
end
class ::RedTree
include Glimmer::UI::CustomWidget
body {
tree(swt_style) {
background :red
}
}
end
end
after(:all) do
%w[
Person
Manager
Company
RedTree
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
let(:person1) do
Person.new.tap do |person|
person.name = "Bruce Ting"
person.age = 45
person.adult = true
end
end
let(:person2) do
Person.new.tap do |person|
person.name = "Julia Fang"
person.age = 17
person.adult = false
end
end
let(:manager) do
Manager.new.tap do |m|
m.name = "Tim Harkins"
m.age = 79
m.adult = true
m.coworkers << person1
m.coworkers << person2
end
end
let(:selected_coworker) { person2 }
let(:company) do
Company.new.tap do |c|
c.owner = manager
c.selected_coworker = selected_coworker
end
end
let(:company_group) do
CompanyGroup.new.tap do |cg|
cg.companies << company
end
end
it "data binds tree widget tree item text to a string property" do
@target = shell {
@tree = tree {
items bind(company, :owner), tree_properties(children: :coworkers, text: :name)
}
}
expect(@tree.swt_widget).to have_style(:border)
expect(@tree.swt_widget).to have_style(:virtual)
expect(@tree.swt_widget).to have_style(:v_scroll)
expect(@tree.swt_widget).to have_style(:h_scroll)
expect(@tree.swt_widget.getItems.size).to eq(1)
root_node = @tree.swt_widget.getItems[0]
expect(root_node.getText).to eq("Tim Harkins")
expect(root_node.getItems.size).to eq(2)
node1 = root_node.getItems[0]
node2 = root_node.getItems[1]
expect(node1.getText).to eq("Bruce Ting")
expect(node2.getText).to eq("Julia Fang")
@tree.swt_widget.getItems.first.setExpanded(true)
manager.name = "Tim Lee Harkins"
# maintains expansion on tree item text change
expect(@tree.swt_widget.getItems.first.getExpanded).to eq(true)
root_node = @tree.swt_widget.getItems.first
expect(root_node.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1 = @tree.swt_widget.getItems.first.getItems.first
expect(node1.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2 = @tree.swt_widget.getItems.first.getItems.last
expect(node2.getText).to eq("Julia Katherine Fang")
person3 = Person.new
person3.name = "Bob David Kennith"
person3.age = 37
person3.adult = true
old_coworkers = Array[*manager.coworkers.clone]
manager.coworkers << person3
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(3)
node3 = root_node.getItems.last
expect(node3.getText).to eq("Bob David Kennith")
person2.coworkers << person3
node2 = @tree.swt_widget.getItems.first.getItems[1]
expect(node2.getItems.size).to eq(1)
node2a = node2.getItems.first
expect(node2a.getText).to eq("Bob David Kennith")
manager.coworkers = old_coworkers
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(2)
expect(root_node.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1 = @tree.swt_widget.getItems.first.getItems.first
expect(node1.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2 = @tree.swt_widget.getItems.first.getItems.last
expect(node2.getText).to eq("Julia Katherine Fang")
manager.coworkers << person3
manager.coworkers.delete_at(0)
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(2)
node1 = root_node.getItems.first
node2 = root_node.getItems.last
expect(node1.getText).to eq("Julia Katherine Fang")
expect(node2.getText).to eq("Bob David Kennith")
manager.coworkers = []
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(0)
manager.coworkers = nil
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(0)
company.owner = nil
expect(@tree.swt_widget.getItems.size).to eq(0)
end
it "data binds tree widget tree item text to a string property by passing a hash" do
@target = shell {
@tree = tree {
items bind(company, :owner, tree_properties: {children: :coworkers, text: :name})
}
}
expect(@tree.swt_widget).to have_style(:border)
expect(@tree.swt_widget).to have_style(:virtual)
expect(@tree.swt_widget).to have_style(:v_scroll)
expect(@tree.swt_widget).to have_style(:h_scroll)
expect(@tree.swt_widget.getItems.size).to eq(1)
root_node = @tree.swt_widget.getItems[0]
expect(root_node.getText).to eq("Tim Harkins")
expect(root_node.getItems.size).to eq(2)
node1 = root_node.getItems[0]
node2 = root_node.getItems[1]
expect(node1.getText).to eq("Bruce Ting")
expect(node2.getText).to eq("Julia Fang")
@tree.swt_widget.getItems.first.setExpanded(true)
manager.name = "Tim Lee Harkins"
# maintains expansion on tree item text change
expect(@tree.swt_widget.getItems.first.getExpanded).to eq(true)
root_node = @tree.swt_widget.getItems.first
expect(root_node.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1 = @tree.swt_widget.getItems.first.getItems.first
expect(node1.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2 = @tree.swt_widget.getItems.first.getItems.last
expect(node2.getText).to eq("Julia Katherine Fang")
person3 = Person.new
person3.name = "Bob David Kennith"
person3.age = 37
person3.adult = true
old_coworkers = Array[*manager.coworkers.clone]
manager.coworkers << person3
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(3)
node3 = root_node.getItems.last
expect(node3.getText).to eq("Bob David Kennith")
person2.coworkers << person3
node2 = @tree.swt_widget.getItems.first.getItems[1]
expect(node2.getItems.size).to eq(1)
node2a = node2.getItems.first
expect(node2a.getText).to eq("Bob David Kennith")
manager.coworkers = old_coworkers
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(2)
expect(root_node.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1 = @tree.swt_widget.getItems.first.getItems.first
expect(node1.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2 = @tree.swt_widget.getItems.first.getItems.last
expect(node2.getText).to eq("Julia Katherine Fang")
manager.coworkers << person3
manager.coworkers.delete_at(0)
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(2)
node1 = root_node.getItems.first
node2 = root_node.getItems.last
expect(node1.getText).to eq("Julia Katherine Fang")
expect(node2.getText).to eq("Bob David Kennith")
manager.coworkers = []
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(0)
manager.coworkers = nil
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(0)
company.owner = nil
expect(@tree.swt_widget.getItems.size).to eq(0)
end
it "data binds tree widget tree item text to a string property using Shine syntax" do
@target = shell {
@tree = tree {
items <= [company, :owner, tree_attributes: {children: :coworkers, text: :name}]
}
}
expect(@tree.swt_widget).to have_style(:border)
expect(@tree.swt_widget).to have_style(:virtual)
expect(@tree.swt_widget).to have_style(:v_scroll)
expect(@tree.swt_widget).to have_style(:h_scroll)
expect(@tree.swt_widget.getItems.size).to eq(1)
root_node = @tree.swt_widget.getItems[0]
expect(root_node.getText).to eq("Tim Harkins")
expect(root_node.getItems.size).to eq(2)
node1 = root_node.getItems[0]
node2 = root_node.getItems[1]
expect(node1.getText).to eq("Bruce Ting")
expect(node2.getText).to eq("Julia Fang")
@tree.swt_widget.getItems.first.setExpanded(true)
manager.name = "Tim Lee Harkins"
# maintains expansion on tree item text change
expect(@tree.swt_widget.getItems.first.getExpanded).to eq(true)
root_node = @tree.swt_widget.getItems.first
expect(root_node.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1 = @tree.swt_widget.getItems.first.getItems.first
expect(node1.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2 = @tree.swt_widget.getItems.first.getItems.last
expect(node2.getText).to eq("Julia Katherine Fang")
person3 = Person.new
person3.name = "Bob David Kennith"
person3.age = 37
person3.adult = true
old_coworkers = Array[*manager.coworkers.clone]
manager.coworkers << person3
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(3)
node3 = root_node.getItems.last
expect(node3.getText).to eq("Bob David Kennith")
person2.coworkers << person3
node2 = @tree.swt_widget.getItems.first.getItems[1]
expect(node2.getItems.size).to eq(1)
node2a = node2.getItems.first
expect(node2a.getText).to eq("Bob David Kennith")
manager.coworkers = old_coworkers
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(2)
expect(root_node.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1 = @tree.swt_widget.getItems.first.getItems.first
expect(node1.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2 = @tree.swt_widget.getItems.first.getItems.last
expect(node2.getText).to eq("Julia Katherine Fang")
manager.coworkers << person3
manager.coworkers.delete_at(0)
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(2)
node1 = root_node.getItems.first
node2 = root_node.getItems.last
expect(node1.getText).to eq("Julia Katherine Fang")
expect(node2.getText).to eq("Bob David Kennith")
manager.coworkers = []
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(0)
manager.coworkers = nil
root_node = @tree.swt_widget.getItems.first
expect(root_node.getItems.size).to eq(0)
company.owner = nil
expect(@tree.swt_widget.getItems.size).to eq(0)
end
it "data binds tree widget tree item text to an indexed string property" do
@target = shell {
@tree_nested_indexed = tree(:virtual, :border) {
items bind(company_group, "companies[0].owner"), tree_properties(children: :coworkers, text: :name)
}
}
expect(@tree_nested_indexed.swt_widget.getItems.size).to eq(1)
manager.name = "Tim Lee Harkins"
root_node_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first
expect(root_node_nested_indexed.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first.getItems.first
expect(node1_nested_indexed.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first.getItems.last
expect(node2_nested_indexed.getText).to eq("Julia Katherine Fang")
person3 = Person.new
person3.name = "Bob David Kennith"
person3.age = 37
person3.adult = true
old_coworkers = Array[*manager.coworkers.clone]
manager.coworkers << person3
root_node_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first
expect(root_node_nested_indexed.getItems.size).to eq(3)
node3_nested_indexed = root_node_nested_indexed.getItems.last
expect(node3_nested_indexed.getText).to eq("Bob David Kennith")
manager.coworkers = old_coworkers
root_node_nested_indexed = @tree_nested_indexed.swt_widget.getItems[0]
expect(root_node_nested_indexed.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first.getItems.first
expect(node1_nested_indexed.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first.getItems.last
expect(node2_nested_indexed.getText).to eq("Julia Katherine Fang")
manager.coworkers << person3
manager.coworkers.delete_at(0)
root_node_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first
expect(root_node_nested_indexed.getItems.size).to eq(2)
node1_nested_indexed = root_node_nested_indexed.getItems.first
node2_nested_indexed = root_node_nested_indexed.getItems.last
expect(node1_nested_indexed.getText).to eq("Julia Katherine Fang")
expect(node2_nested_indexed.getText).to eq("Bob David Kennith")
end
it "data binds tree widget tree item text to an indexed string property using Shine syntax" do
@target = shell {
@tree_nested_indexed = tree(:virtual, :border) {
items <= [company_group, "companies[0].owner", tree_attributes: {children: :coworkers, text: :name}]
}
}
expect(@tree_nested_indexed.swt_widget.getItems.size).to eq(1)
manager.name = "Tim Lee Harkins"
root_node_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first
expect(root_node_nested_indexed.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first.getItems.first
expect(node1_nested_indexed.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first.getItems.last
expect(node2_nested_indexed.getText).to eq("Julia Katherine Fang")
person3 = Person.new
person3.name = "Bob David Kennith"
person3.age = 37
person3.adult = true
old_coworkers = Array[*manager.coworkers.clone]
manager.coworkers << person3
root_node_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first
expect(root_node_nested_indexed.getItems.size).to eq(3)
node3_nested_indexed = root_node_nested_indexed.getItems.last
expect(node3_nested_indexed.getText).to eq("Bob David Kennith")
manager.coworkers = old_coworkers
root_node_nested_indexed = @tree_nested_indexed.swt_widget.getItems[0]
expect(root_node_nested_indexed.getText).to eq("Tim Lee Harkins")
person1.name = "Bruce A. Ting"
node1_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first.getItems.first
expect(node1_nested_indexed.getText).to eq("Bruce A. Ting")
person2.name = "Julia Katherine Fang"
node2_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first.getItems.last
expect(node2_nested_indexed.getText).to eq("Julia Katherine Fang")
manager.coworkers << person3
manager.coworkers.delete_at(0)
root_node_nested_indexed = @tree_nested_indexed.swt_widget.getItems.first
expect(root_node_nested_indexed.getItems.size).to eq(2)
node1_nested_indexed = root_node_nested_indexed.getItems.first
node2_nested_indexed = root_node_nested_indexed.getItems.last
expect(node1_nested_indexed.getText).to eq("Julia Katherine Fang")
expect(node2_nested_indexed.getText).to eq("Bob David Kennith")
end
it "data binds custom tree widget tree item text to a string property" do
@target = shell {
@tree = red_tree(:virtual, :border) {
items bind(company, :owner), tree_properties(children: :coworkers, text: :name)
}
}
expect(@tree.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@tree.swt_widget.getItems.size).to eq(1)
root_node = @tree.swt_widget.getItems[0]
expect(root_node.getText).to eq("Tim Harkins")
expect(root_node.getItems.size).to eq(2)
node1 = root_node.getItems[0]
node2 = root_node.getItems[1]
expect(node1.getText).to eq("Bruce Ting")
expect(node2.getText).to eq("Julia Fang")
end
it 'stores models as tree item data' do
@target = shell {
@tree = tree {
items bind(company, :owner), tree_properties(children: :coworkers, text: :name)
}
}
person1_tree_item = @tree.swt_widget.getItems.first
expect(person1_tree_item.getData).to eq(manager)
person2_tree_item = person1_tree_item.getItems[0]
expect(person2_tree_item.getData).to eq(person1)
person3_tree_item = person1_tree_item.getItems[1]
expect(person3_tree_item.getData).to eq(person2)
end
it "data binds tree widget selection" do
@target = shell {
@tree = tree {
items bind(company, :owner), tree_properties(children: :coworkers, text: :name)
selection bind(company, :selected_coworker)
}
}
expect(@tree.swt_widget.getItems.size).to eq(1)
root_node = @tree.swt_widget.getItems[0]
expect(root_node.getText).to eq("Tim Harkins")
expect(root_node.getItems.size).to eq(2)
node1 = root_node.getItems[0]
node2 = root_node.getItems[1]
expect(node1.getText).to eq("Bruce Ting")
expect(node2.getText).to eq("Julia Fang")
selection = @tree.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
company.selected_coworker = nil
selection = @tree.swt_widget.getSelection
expect(selection.size).to eq(0)
company.selected_coworker = selected_coworker
selection = @tree.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
person3 = Person.new
person3.name = "Bob David Kennith"
person3.age = 37
person3.adult = true
manager.coworkers << person3
# test that it maintains selection
selection = @tree.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
end
it "triggers tree widget editing on selected tree item which is done via ENTER key" do
@target = shell {
@tree = tree {
items bind(company, :owner), tree_properties(children: :coworkers, text: :name)
selection bind(company, :selected_coworker)
}
}
expect(@tree.tree_editor_text_proxy).to be_nil
@write_done = false
@tree.edit_selected_tree_item(
before_write: lambda {
expect(@tree.edit_in_progress?).to eq(true)
},
after_write: lambda { |edited_tree_item|
expect(edited_tree_item.getText).to eq('Julie Fan')
@write_done = true
}
)
expect(@tree.tree_editor_text_proxy).to_not be_nil
@tree.tree_editor_text_proxy.swt_widget.setText('Julie Fan')
# simulate hitting enter to trigger write action
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @tree.tree_editor_text_proxy.swt_widget.getDisplay
event.item = @tree.tree_editor_text_proxy.swt_widget
event.widget = @tree.tree_editor_text_proxy.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keydown]
@tree.tree_editor_text_proxy.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:keydown], event)
expect(@write_done).to eq(true)
expect(@tree.edit_in_progress?).to eq(false)
expect(@cancel_done).to be_nil
expect(person2.name).to eq('Julie Fan')
# test that it maintains selection
selection = @tree.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
end
it "triggers tree widget editing on specified tree item which is done via ENTER key" do
@target = shell {
@tree = tree {
items bind(company, :owner), tree_properties(children: :coworkers, text: :name)
selection bind(company, :selected_coworker)
}
}
expect(@tree.tree_editor_text_proxy).to be_nil
@write_done = false
@tree.edit_tree_item(
@tree.swt_widget.getSelection.first,
before_write: -> {expect(person2.name).to eq('Julia Fang')},
after_write: -> (edited_tree_item) { @write_done = true }
)
expect(@tree.tree_editor_text_proxy).to_not be_nil
@tree.tree_editor_text_proxy.swt_widget.setText('Julie Fan')
# simulate hitting enter to trigger write action
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @tree.tree_editor_text_proxy.swt_widget.getDisplay
event.item = @tree.tree_editor_text_proxy.swt_widget
event.widget = @tree.tree_editor_text_proxy.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keydown]
@tree.tree_editor_text_proxy.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:keydown], event)
expect(@write_done).to eq(true)
expect(@cancel_done).to be_nil
expect(person2.name).to eq('Julie Fan')
# test that it maintains selection
selection = @tree.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
end
it "triggers tree widget editing on selected tree item which is done via focus out" do
@target = shell {
@tree = tree {
items bind(company, :owner), tree_properties(children: :coworkers, text: :name)
selection bind(company, :selected_coworker)
}
}
expect(@tree.tree_editor_text_proxy).to be_nil
@write_done = false
@tree.edit_selected_tree_item(after_write: -> (edited_tree_item) { @write_done = true })
expect(@tree.tree_editor_text_proxy).to_not be_nil
@tree.tree_editor_text_proxy.swt_widget.setText('Julie Fan')
# simulate hitting enter to trigger write action
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @tree.tree_editor_text_proxy.swt_widget.getDisplay
event.item = @tree.tree_editor_text_proxy.swt_widget
event.widget = @tree.tree_editor_text_proxy.swt_widget
event.type = Glimmer::SWT::SWTProxy[:focusout]
@tree.tree_editor_text_proxy.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:focusout], event)
expect(@write_done).to eq(true)
expect(@cancel_done).to be_nil
expect(person2.name).to eq('Julie Fan')
# test that it maintains selection
selection = @tree.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
end
it "triggers tree widget editing on selected tree item and cancels by not making a change and focusing out" do
@target = shell {
@tree = tree {
items bind(company, :owner), tree_properties(children: :coworkers, text: :name)
selection bind(company, :selected_coworker)
}
}
expect(@tree.tree_editor_text_proxy).to be_nil
@tree.edit_selected_tree_item(after_write: -> { @write_done = true }, after_cancel: -> { @cancel_done = true })
expect(@tree.tree_editor_text_proxy).to_not be_nil
# simulate hitting enter to trigger write action
event = Event.new
event.keyCode = nil
event.doit = true
event.character = nil
event.display = @tree.tree_editor_text_proxy.swt_widget.getDisplay
event.item = @tree.tree_editor_text_proxy.swt_widget
event.widget = @tree.tree_editor_text_proxy.swt_widget
event.type = Glimmer::SWT::SWTProxy[:focusout]
@tree.tree_editor_text_proxy.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:focusout], event)
expect(@write_done).to be_nil
expect(@cancel_done).to eq(true)
expect(person2.name).to eq('Julia Fang')
# test that it maintains selection
selection = @tree.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
end
it "triggers tree widget editing on selected tree item and cancels by hitting escape button after making a change" do
@target = shell {
@tree = tree {
items bind(company, :owner), tree_properties(children: :coworkers, text: :name)
selection bind(company, :selected_coworker)
}
}
expect(@tree.tree_editor_text_proxy).to be_nil
@tree.edit_selected_tree_item(after_write: -> { @write_done = true }, after_cancel: -> { @cancel_done = true })
expect(@tree.tree_editor_text_proxy).to_not be_nil
@tree.tree_editor_text_proxy.swt_widget.setText('Julie Fan')
# simulate hitting enter to trigger write action
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:esc]
event.doit = true
event.character = nil
event.display = @tree.tree_editor_text_proxy.swt_widget.getDisplay
event.item = @tree.tree_editor_text_proxy.swt_widget
event.widget = @tree.tree_editor_text_proxy.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keydown]
@tree.tree_editor_text_proxy.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:keydown], event)
expect(@write_done).to be_nil
expect(@cancel_done).to eq(true)
expect(person2.name).to eq('Julia Fang')
# test that it maintains selection
selection = @tree.swt_widget.getSelection
expect(selection.size).to eq(1)
expect(selection.first.getData).to eq(person2)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__sash_form__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__sash_form__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer SashForm" do
include Glimmer
it "sets weights using an array after content of sash_form" do
@target = shell {
@sash_form = sash_form {
@composite1 = composite
@composite2 = composite
weights [1, 2]
}
}
expect(@sash_form.weights).to eq([333,666].to_java(Java::int))
end
it "sets weights using a splatted array after content of sash_form" do
@target = shell {
@sash_form = sash_form {
@composite1 = composite
@composite2 = composite
weights 1, 2
}
}
expect(@sash_form.weights).to eq([333,666].to_java(Java::int))
end
it "sets weights using a splatted array before content of sash_form" do
@target = shell {
@sash_form = sash_form {
weights 1, 2
@composite1 = composite
@composite2 = composite
}
}
expect(@sash_form.weights).to eq([333,666].to_java(Java::int))
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer_spec.rb | spec/lib/glimmer/dsl/swt/glimmer_spec.rb | require "spec_helper"
module GlimmerSpec
describe Glimmer do
include Glimmer
it "tests shell with no args having default layout and singleton display instance" do
@target = shell
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@target.swt_widget).to be_instance_of(Shell)
expect(@target.swt_widget.getLayout).to_not be_nil
expect(@target.swt_widget.getLayout).to be_instance_of(FillLayout)
expect(@target.has_style?(:shell_trim)).to eq(true)
end
it "tests shell with one arg of unresizable style bit combination" do
@target = shell(Glimmer::SWT::SWTProxy[:shell_trim] & (~Glimmer::SWT::SWTProxy[:resize]))
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@target.swt_widget).to be_instance_of(Shell)
expect(@target.has_style?(:close)).to eq(true)
expect(@target.has_style?(:title)).to eq(true)
expect(@target.has_style?(:min)).to eq(true)
expect(@target.has_style?(:max)).to eq(true)
expect(@target.has_style?(:resize)).to eq(false)
end
it "tests shell with one arg of convenience no_resize style bit" do
@target = shell(:no_resize)
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@target.swt_widget).to be_instance_of(Shell)
expect(@target.has_style?(:close)).to eq(true)
expect(@target.has_style?(:title)).to eq(true)
expect(@target.has_style?(:min)).to eq(true)
expect(@target.has_style?(:max)).to eq(false)
expect(@target.has_style?(:resize)).to eq(false)
end
it "tests shell with multiple style bits" do
@target = shell(:dialog_trim, :application_modal)
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@target.swt_widget).to be_instance_of(Shell)
expect(@target.has_style?(:dialog_trim)).to eq(true)
expect(@target.has_style?(:application_modal)).to eq(true)
end
it "tests shell with one arg of display" do
@display = Glimmer::SWT::DisplayProxy.instance.swt_display
@target = shell(@display)
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@target.swt_widget).to be_instance_of(Shell)
expect(@target.swt_widget.getLayout).to_not be_nil
expect(@target.swt_widget.getLayout).to be_instance_of(FillLayout)
expect(@target.has_style?(:shell_trim)).to eq(true)
end
it "tests shell with two args of display and style bit" do
@display = Glimmer::SWT::DisplayProxy.instance.swt_display
@target = shell(@display, :title)
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@target.swt_widget).to be_instance_of(Shell)
expect(@target.swt_widget.getLayout).to_not be_nil
expect(@target.swt_widget.getLayout).to be_instance_of(FillLayout)
expect(@target.has_style?(:close)).to eq(false)
expect(@target.has_style?(:title)).to eq(true)
expect(@target.has_style?(:min)).to eq(false)
expect(@target.has_style?(:max)).to eq(false)
expect(@target.has_style?(:resize)).to eq(false)
end
it "tests shell with two args of display and multiple style bits" do
@display = Glimmer::SWT::DisplayProxy.instance.swt_display
@target = shell(@display, :dialog_trim, :application_modal)
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@target.swt_widget).to be_instance_of(Shell)
expect(@target.swt_widget.getLayout).to_not be_nil
expect(@target.swt_widget.getLayout).to be_instance_of(FillLayout)
expect(@target.has_style?(:dialog_trim)).to eq(true)
expect(@target.has_style?(:application_modal)).to eq(true)
end
it "tests shell with one arg of parent shell" do
@target = shell
@dialog_shell = shell(@target.swt_widget)
expect(@dialog_shell).to_not be_nil
expect(@dialog_shell.swt_widget).to_not be_nil
expect(@dialog_shell.swt_widget).to be_instance_of(Shell)
expect(@dialog_shell.swt_widget.getLayout).to_not be_nil
expect(@dialog_shell.swt_widget.getLayout).to be_instance_of(FillLayout)
expect(@dialog_shell.has_style?(:dialog_trim)).to eq(true)
end
it "tests shell with two args of parent shell and style bit" do
@target = shell
@dialog_shell = shell(@target.swt_widget, :title)
expect(@dialog_shell).to_not be_nil
expect(@dialog_shell.swt_widget).to_not be_nil
expect(@dialog_shell.swt_widget).to be_instance_of(Shell)
expect(@dialog_shell.swt_widget.getLayout).to_not be_nil
expect(@dialog_shell.swt_widget.getLayout).to be_instance_of(FillLayout)
expect(@dialog_shell.has_style?(:dialog_trim)).to eq(false)
expect(@dialog_shell.has_style?(:title)).to eq(true)
end
it "renders shell with title and layout" do
shell_layout = GridLayout.new
@target = shell {
text "Title"
layout shell_layout
}
expect(@target.swt_widget.getText).to eq( "Title")
expect(@target.swt_widget.getLayout).to eq( shell_layout)
end
it "tests shell_with_bounds" do
@target = shell {
bounds 50, 75, 800, 600
}
expect(@target.swt_widget.getBounds).to eq( Rectangle.new(50, 75, 800, 600) )
end
it "tests shell_with_size" do
@target = shell {
size 800, 600
}
expect(@target.swt_widget.getSize).to eq( Point.new(800, 600) )
end
it "tests shell_and_composite_with_default_style_and_layout" do
@target = shell {
composite
}
expect(@target.swt_widget.children.size).to eq( 1)
expect(@target.swt_widget.children[0]).to be_instance_of(Composite)
composite_widget = @target.swt_widget.children[0]
expect(composite_widget).to have_style(:none)
expect(composite_widget.getLayout).to be_instance_of(GridLayout)
grid_layout = composite_widget.getLayout
expect(grid_layout.numColumns).to eq( 1)
expect(grid_layout.makeColumnsEqualWidth).to eq( false)
end
it "tests shell_and_group_with_default_style_and_layout" do
@target = shell {
group {
text "Title"
}
}
expect(@target.swt_widget.children.size).to eq( 1)
expect(@target.swt_widget.children[0]).to be_instance_of(Java::OrgEclipseSwtWidgets::Group)
group_widget = @target.swt_widget.children[0]
expect(group_widget).to have_style(:none)
expect(group_widget.getLayout).to be_instance_of(GridLayout)
grid_layout = group_widget.getLayout
expect(grid_layout.numColumns).to eq( 1)
expect(grid_layout.makeColumnsEqualWidth).to eq( false)
expect(group_widget.getText).to eq( "Title")
end
it "tests shell_and_composite_with_style_and_layout" do
composite_layout = RowLayout.new
@target = shell {
composite(:no_focus) {
layout composite_layout
}
}
expect(@target.swt_widget.children.size).to eq( 1)
expect(@target.swt_widget.children[0]).to be_instance_of(Composite)
composite_widget = @target.swt_widget.children[0]
expect(composite_widget).to have_style(:no_focus)
expect(composite_widget.getLayout).to eq( composite_layout)
end
it "tests shell_and_composite_and_text_with_default_style" do
@target = shell {
composite {
text {}
}
}
composite_widget = @target.swt_widget.children[0]
expect(composite_widget.children.size).to eq( 1)
expect(composite_widget.children[0]).to be_instance_of(Text)
text_widget = composite_widget.children[0]
expect(text_widget).to have_style(:border)
end
it "tests shell_and_composite_with_custom_layout_and_text_with_default_style" do
composite_layout = RowLayout.new
@target = shell {
composite {
text {}
layout composite_layout
}
}
composite_widget = @target.swt_widget.children[0]
expect(composite_widget.getLayout).to eq( composite_layout)
expect(composite_widget.children.size).to eq( 1)
expect(composite_widget.children[0]).to be_instance_of(Text)
text_widget = composite_widget.children[0]
expect(text_widget).to have_style(:border)
end
it "tests shell_and_composite_and_text_with_style_and_text" do
@target = shell {
composite {
text(:password) {
text "Hello"
}
}
}
composite_widget = @target.swt_widget.children[0]
expect(composite_widget.children.size).to eq( 1)
expect(composite_widget.children[0]).to be_instance_of(Text)
text_widget = composite_widget.children[0]
expect(text_widget).to have_style(:password)
expect(text_widget.getText).to eq( "Hello")
end
it "tests shell_and_spinner_default" do
@target = shell {
@spinner = spinner {
selection 55
}
}
expect(@spinner.swt_widget).to be_instance_of(Spinner)
expect(@spinner.swt_widget).to have_style(:border)
expect(@spinner.swt_widget.getSelection).to eq( 55)
end
it "tests shell_and_list_default" do
@target = shell {
@list = list {
}
}
expect(@list.swt_widget).to be_instance_of(List)
expect(@list.swt_widget).to have_style(:border)
expect(@list.swt_widget).to have_style(:single)
expect(@list.swt_widget).to have_style(:v_scroll)
end
it "tests shell_and_button_default" do
@target = shell {
@button = button {
text "Push Me"
}
}
expect(@button.swt_widget).to be_instance_of(Button)
expect(@button.swt_widget).to have_style(:push)
expect(@button.swt_widget.text).to eq( "Push Me")
end
if OS.mac?
it "tests shell and browser default" do
@target = shell {
@browser = browser {
text <<~HTML
<html>
<head>
</head>
<body>
<form>
<input id="answer" value="42">
</form>
</body>
</html>
HTML
on_completed {
expect(@browser.swt_widget.evaluate("document.getElementById('answer').value")).to eq('42')
}
}
}
expect(@browser.swt_widget.is_a?(Browser)).to be_truthy
end
end
it "tests shell_and_table_and_table_column_defaults" do
@target = shell {
@table = table {
@table_column = table_column {
}
}
}
expect(@table.swt_widget).to have_style(:border)
expect(@table.swt_widget.getHeaderVisible).to eq(true)
expect(@table.swt_widget.getLinesVisible).to eq(true)
expect(@table_column.swt_widget.getWidth).to eq( 80)
end
it "tests shell_containing_undefined_command" do
expect {
@target = shell {
undefined_command(:undefined_parameter) {
}
}
}.to raise_error(NoMethodError)
end
it "tests shell with invalid parent" do
expect {
@target = shell {
button {
shell
}
}
}.to raise_error(Glimmer::Error)
end
it "tests shell with valid shell parent" do
@target = shell {
@nested_shell = shell
}
expect(@nested_shell).to be_a(Glimmer::SWT::ShellProxy)
end
it 'sets background image via image path' do
@target = shell {
@composite = composite {
background_image File.join(ROOT_PATH, 'images', 'glimmer-hello-world.png')
}
}
expect(@composite.swt_widget.getBackgroundImage.is_a?(Image)).to eq(true)
end
it 'sets background image via image object' do
image_data = ImageData.new(File.join(ROOT_PATH, 'images', 'glimmer-hello-world.png'))
image = Image.new(display.swt_display, image_data)
@target = shell {
@composite = composite {
background_image image
}
}
expect(@composite.swt_widget.getBackgroundImage).to eq(image)
end
# TODO extract cursor specs into their own file
it 'sets cursor via abbreviated SWT style symbol' do
@target = shell {
@composite = composite {
cursor :appstarting
}
}
expect(@composite.swt_widget.cursor).to eq(display.swt_display.get_system_cursor(swt(:cursor_appstarting)))
end
it 'sets cursor via SWT style symbol' do
@target = shell {
@composite = composite {
cursor :cursor_appstarting
}
}
expect(@composite.swt_widget.cursor).to eq(display.swt_display.get_system_cursor(swt(:cursor_appstarting)))
end
it 'sets cursor via SWT style constant integer' do
@target = shell {
@composite = composite {
cursor swt(:cursor_appstarting)
}
}
expect(@composite.swt_widget.cursor).to eq(display.swt_display.get_system_cursor(swt(:cursor_appstarting)))
end
it 'sets cursor via cursor object' do
@cursor = cursor(:appstarting)
@target = shell {
@composite = composite {
cursor @cursor
}
}
expect(@composite.swt_widget.cursor).to eq(display.swt_display.get_system_cursor(swt(:cursor_appstarting)))
end
it 'fails to set invalid cursor via cursor object' do
expect {
@cursor = cursor(:invalid)
}.to raise_error(Glimmer::Error)
end
it 'renders radio button' do
@target = shell {
@radio = radio {
text 'radio button'
}
}
expect(@radio.swt_widget).to be_a(Button)
expect(@radio).to have_style(:radio)
expect(@radio.text).to eq('radio button')
end
it 'renders checkbox button' do
@target = shell {
@checkbox = checkbox {
text 'checkbox button'
}
}
expect(@checkbox.swt_widget).to be_a(Button)
expect(@checkbox).to have_style(:check)
expect(@checkbox.text).to eq('checkbox button')
end
it 'renders checkbox button' do
@target = shell {
@checkbox = check {
text 'checkbox button'
}
}
expect(@checkbox.swt_widget).to be_a(Button)
expect(@checkbox).to have_style(:check)
expect(@checkbox.text).to eq('checkbox button')
end
it 'renders toggle button' do
@target = shell {
@toggle = toggle {
text 'toggle button'
}
}
expect(@toggle.swt_widget).to be_a(Button)
expect(@toggle).to have_style(:toggle)
expect(@toggle.text).to eq('toggle button')
end
it 'renders arrow button' do
@target = shell {
@arrow = arrow
}
expect(@arrow.swt_widget).to be_a(Button)
expect(@arrow).to have_style(:arrow)
end
unless ENV['CI'].to_s.downcase == 'true'
context 'focus' do
after do
if @target
@target.async_exec do
@target.dispose
end
@target.open
end
end
it 'does not focus widget when not declaring focus true' do
@target = shell {
alpha 0 # keep invisible while running specs
@text1 = text {
text "First one is focused by default"
}
@text2 = text {
text "Not focused"
}
}
@target.async_exec do
expect(@text1.swt_widget.isFocusControl).to eq(true)
expect(@text2.swt_widget.isFocusControl).to eq(false)
end
end
it 'does not focus widget when declaring focus false' do
@target = shell {
alpha 0 # keep invisible while running specs
@text1 = text {
text "First one is focused by default"
}
@text2 = text {
focus false
text "Not focused"
}
}
@target.async_exec do
expect(@text1.swt_widget.isFocusControl).to eq(true)
expect(@text2.swt_widget.isFocusControl).to eq(false)
end
end
it 'focuses widget when declaring focus true' do
@target = shell {
alpha 0 # keep invisible while running specs
@text1 = text {
text "Not focused"
}
@text2 = text {
focus true
text "Focused"
}
}
@target.async_exec do
expect(@text1.swt_widget.isFocusControl).to eq(false)
expect(@text2.swt_widget.isFocusControl).to eq(true)
end
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__date_time__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__date_time__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Date Time" do
include Glimmer
before(:all) do
class Person
attr_accessor :dob
end
end
after(:all) do
%w[
Person
RedDateTime
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
let(:person) do
Person.new.tap do |person|
person.dob = DateTime.new(2038, 11, 29, 12, 47, 32)
end
end
it "renders date_time with default :date style, data-binding year, month, day" do
@target = shell {
@date_time = date_time {
year bind(person, :dob, on_read: ->(v) {v.year}, on_write: ->(v) {DateTime.new(v, person.dob.month, person.dob.day, person.dob.hour, person.dob.min, person.dob.sec)})
day bind(person, :dob, on_read: ->(v) {v.day}, on_write: ->(v) {DateTime.new(person.dob.year, person.dob.month, v, person.dob.hour, person.dob.min, person.dob.sec)})
month bind(person, :dob, on_read: ->(v) {v.month}, on_write: ->(v) {DateTime.new(person.dob.year, v, person.dob.day, person.dob.hour, person.dob.min, person.dob.sec)})
}
}
expect(@date_time).to_not be_nil
expect(@date_time.swt_widget).to be_a(Java::OrgEclipseSwtWidgets::DateTime)
expect(@date_time).to have_style(:date)
expect(@date_time.year).to eq(2038)
expect(@date_time.month).to eq(11)
expect(@date_time.day).to eq(29)
@date_time.day = 18
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.day).to eq(18)
@date_time.month = 7
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.month).to eq(7)
@date_time.year = 2020
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.year).to eq(2020)
person.dob = DateTime.new(2033, 3, 2, 12, 47, 32)
expect(@date_time.year).to eq(2033)
expect(@date_time.month).to eq(3)
expect(@date_time.day).to eq(2)
end
it "renders date_time with default :date style, data-binding date_time property" do
@target = shell {
@date_time = date_time {
date_time bind(person, :dob)
}
}
expect(@date_time).to_not be_nil
expect(@date_time.swt_widget).to be_a(Java::OrgEclipseSwtWidgets::DateTime)
expect(@date_time).to have_style(:date)
expect(@date_time.date_time).to eq(person.dob)
@date_time.date_time = DateTime.new(2013, 1, 12, 2, 7, 3)
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob).to eq(@date_time.date_time)
person.dob = DateTime.new(2033, 3, 2, 12, 47, 32)
expect(@date_time.date_time).to eq(person.dob)
end
it "renders date_time with default :date style, data-binding date property" do
@target = shell {
@date_time = date_time {
date bind(person, :dob, on_read: ->(v) {v.to_date}, on_write: ->(v) {v.to_datetime})
}
}
expect(@date_time).to_not be_nil
expect(@date_time.swt_widget).to be_a(Java::OrgEclipseSwtWidgets::DateTime)
expect(@date_time).to have_style(:date)
expect(@date_time.date).to eq(person.dob.to_date)
@date_time.date = DateTime.new(2013, 1, 12, 2, 7, 3).to_date
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.to_date).to eq(@date_time.date)
person.dob = DateTime.new(2033, 3, 2, 12, 47, 32)
expect(@date_time.date).to eq(person.dob.to_date)
end
it "renders date_time with :time style, data-binding hour, minute, second" do
@target = shell {
@date_time = date_time(:time) {
hours bind(person, :dob, on_read: ->(v) {v.hour}, on_write: ->(v) {DateTime.new(person.dob.year, person.dob.month, person.dob.day, v, person.dob.min, person.dob.sec)})
minutes bind(person, :dob, on_read: ->(v) {v.min}, on_write: ->(v) {DateTime.new(person.dob.year, person.dob.month, person.dob.day, person.dob.hour, v, person.dob.sec)})
seconds bind(person, :dob, on_read: ->(v) {v.sec}, on_write: ->(v) {DateTime.new(person.dob.year, person.dob.month, person.dob.day, person.dob.hour, person.dob.min, v)})
}
}
expect(@date_time).to_not be_nil
expect(@date_time.swt_widget).to be_a(Java::OrgEclipseSwtWidgets::DateTime)
expect(@date_time).to have_style(:time)
expect(@date_time.hours).to eq(12)
expect(@date_time.minutes).to eq(47)
expect(@date_time.seconds).to eq(32)
@date_time.hours = 20
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.hour).to eq(20)
@date_time.minutes = 7
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.min).to eq(7)
@date_time.seconds = 18
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.sec).to eq(18)
person.dob = DateTime.new(2033, 3, 2, 2, 4, 2)
expect(@date_time.hours).to eq(2)
expect(@date_time.minutes).to eq(4)
expect(@date_time.seconds).to eq(2)
end
it "renders date_time with :time style, data-binding time property" do
@target = shell {
@date_time = date_time(:time) {
time bind(person, :dob, on_read: ->(v) {v.to_time}, on_write: ->(v) {v.to_datetime})
}
}
expect(@date_time).to_not be_nil
expect(@date_time.swt_widget).to be_a(Java::OrgEclipseSwtWidgets::DateTime)
expect(@date_time).to have_style(:time)
expect(@date_time.time).to eq(person.dob.to_time)
@date_time.time = DateTime.new(2013, 1, 12, 2, 7, 3).to_time
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.to_time).to eq(@date_time.time)
person.dob = DateTime.new(2033, 3, 2, 12, 47, 32)
expect(@date_time.time).to eq(person.dob.to_time)
end
it "renders date widget alias" do
@target = shell {
@date_time = date
}
expect(@date_time).to_not be_nil
expect(@date_time.swt_widget).to be_a(Java::OrgEclipseSwtWidgets::DateTime)
expect(@date_time).to have_style(:date)
end
it "renders date_drop_down widget alias" do
@target = shell {
@date_time = date_drop_down
}
expect(@date_time).to_not be_nil
expect(@date_time.swt_widget).to be_a(Java::OrgEclipseSwtWidgets::DateTime)
expect(@date_time).to have_style(:date, :drop_down)
end
it "renders time widget alias" do
@target = shell {
@date_time = time
}
expect(@date_time).to_not be_nil
expect(@date_time.swt_widget).to be_a(Java::OrgEclipseSwtWidgets::DateTime)
expect(@date_time).to have_style(:time)
end
it "renders calendar widget alias" do
@target = shell {
@date_time = calendar
}
expect(@date_time).to_not be_nil
expect(@date_time.swt_widget).to be_a(Java::OrgEclipseSwtWidgets::DateTime)
expect(@date_time).to have_style(:calendar)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__data_binding_converters__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__data_binding_converters__spec.rb | require 'spec_helper'
module GlimmerSpec
describe "Glimmer Data Binding Converters" do
include Glimmer
before(:all) do
class Person
attr_accessor :name, :age, :spouse
end
end
after(:all) do
%w[
Person
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
it "converts value on write to model via value method symbol" do
person = Person.new
@target = shell {
composite {
@text = text {
text bind(person, :age, on_write: :to_i)
}
}
}
@text.swt_widget.setText("30")
expect(person.age).to eq(30)
end
it "converts value on write to model with lambda" do
person = Person.new
@target = shell {
composite {
@text = text {
text bind(person, :age, on_write: lambda {|a| a.to_i})
}
}
}
@text.swt_widget.setText("30")
expect(person.age).to eq(30)
end
xit "raises a Glimmer:Error if on_write converter is an invalid value method symbol" do
# TODO delete this test as it might no longer be needed with changes to glimmer making it not throw an error
person = Person.new
@target = shell {
composite {
@text = text {
text bind(person, :age, on_write: :to_garbage)
}
}
}
expect {
@text.swt_widget.setText("30")
}.to raise_error(Glimmer::Error)
end
xit "raises a Glimmer:Error if on_write converter is an invalid object" do
# TODO delete this test as it might no longer be needed with changes to glimmer making it not throw an error
person = Person.new
@target = shell {
composite {
@text = text {
text bind(person, :age, on_write: 33)
}
}
}
expect {
@text.swt_widget.setText("30")
}.to raise_error(Glimmer::Error)
end
it "converts value on write to widget using built-in default widget property data-binding converter" do
person = Person.new
person.age = 15
@target = shell {
composite {
@text = text {
text bind(person, :age)
}
}
}
expect(@text.swt_widget.getText).to eq("15")
person.age = 27
expect(@text.swt_widget.getText).to eq("27")
end
it "converts value on read from model via value method symbol" do
person = Person.new
person.name = 'Sean McFaun'
@target = shell {
composite {
@text = text {
text bind(person, :name, on_read: :upcase)
}
}
}
expect(@text.swt_widget.getText).to eq('SEAN MCFAUN')
person.name = 'Johnny Francone'
expect(@text.swt_widget.getText).to eq('JOHNNY FRANCONE')
end
it "converts value on read from model with lambda" do
person = Person.new
person.name = 'Sean McFaun'
@target = shell {
composite {
@text = text {
text bind(person, :name, on_read: lambda {|n| n.split(' ').first})
}
}
}
expect(@text.swt_widget.getText).to eq('Sean')
person.name = 'Johnny Francone'
expect(@text.swt_widget.getText).to eq('Johnny')
end
it "converts value on read from model with block shortcut syntax" do
person = Person.new
person.name = 'Sean McFaun'
@target = shell {
composite {
@text = text {
text bind(person, :name) {|n| n.split(' ').first}
}
}
}
expect(@text.swt_widget.getText).to eq('Sean')
person.name = 'Johnny Francone'
expect(@text.swt_widget.getText).to eq('Johnny')
end
it "converts nil value on read from model" do
person = Person.new
person.name = 'John'
spouse = Person.new
spouse.name = 'Mary'
person.spouse = spouse
@target = shell {
composite {
@text = text {
text bind(person, :name) {|n| n.nil? ? 'ANONYMOUS' : n.upcase}
}
@text2 = text {
text bind(person, 'spouse.name') {|n| n.nil? ? 'ANONYMOUS' : n.upcase}
}
}
}
expect(@text.swt_widget.getText).to eq('JOHN')
expect(@text2.swt_widget.getText).to eq('MARY')
person.name = 'Johnny'
expect(@text.swt_widget.getText).to eq('JOHNNY')
spouse.name = 'Marianne'
expect(@text2.swt_widget.getText).to eq('MARIANNE')
person.name = nil
expect(@text.swt_widget.getText).to eq('ANONYMOUS')
person.spouse = nil
expect(@text2.swt_widget.getText).to eq('ANONYMOUS')
end
it "converts value on read and write from model via value method symbols" do
person = Person.new
person.name = 'Sean McFaun'
@target = shell {
composite {
@text = text {
text bind(person, :name, on_read: :upcase, on_write: :downcase)
}
}
}
expect(@text.swt_widget.getText).to eq('SEAN MCFAUN')
@text.swt_widget.setText("Provan McCullough")
expect(person.name).to eq('provan mccullough')
expect(@text.swt_widget.getText).to eq('PROVAN MCCULLOUGH')
end
it "converts value on read and write from model via lambdas" do
person = Person.new
person.name = 'Sean McFaun'
@target = shell {
composite {
@text = text {
text bind(person, :name, on_read: lambda {|n| n.upcase}, on_write: lambda {|n| n.downcase})
}
}
}
expect(@text.swt_widget.getText).to eq('SEAN MCFAUN')
@text.swt_widget.setText("Provan McCullough")
expect(person.name).to eq('provan mccullough')
expect(@text.swt_widget.getText).to eq('PROVAN MCCULLOUGH')
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__combo_data_binding__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__combo_data_binding__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Combo Data Binding" do
include Glimmer
before(:all) do
class Person
attr_accessor :country, :country_options
def initialize
self.country_options=["", "Canada", "US", "Mexico"]
end
end
class ::RedCombo
include Glimmer::UI::CustomWidget
body {
combo(swt_style) {
background :red
}
}
end
end
after(:all) do
Object.send(:remove_const, :Person) if Object.const_defined?(:Person)
Object.send(:remove_const, :RedCombo) if Object.const_defined?(:RedCombo)
end
it "data-binds text property" do
person = Person.new
@target = shell {
@combo = combo {
text bind(person, :country)
}
}
@combo.swt_widget.setText('Random')
@combo.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:modify], nil)
expect(person.country).to eq('Random')
end
it "data-binds selection property" do
person = Person.new
@target = shell {
@combo = combo {
selection bind(person, :country)
}
}
expect(@combo.swt_widget.item_count).to eq(4)
expect(@combo.swt_widget.selection_index).to eq(-1)
expect(@combo.swt_widget.text).to eq("")
person.country = "Canada"
expect(@combo.swt_widget.text).to eq("Canada")
person.country_options << "France"
expect(@combo.swt_widget.item_count).to eq(5)
person.country_options=["", "Canada", "US", "Mexico", "Russia", "France"]
expect(@combo.swt_widget.item_count).to eq(6)
person.country_options << "Italy"
person.country_options << "Germany"
person.country_options << "Australia"
expect(@combo.swt_widget.item_count).to eq(9)
expect(@combo.swt_widget.text).to eq("")
@combo.swt_widget.select(2)
@combo.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.country).to eq("US")
@combo.swt_widget.setText('Random')
@combo.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:modify], nil)
expect(person.country).to eq('Random')
person.country = "Canada"
expect(@combo.swt_widget.text).to eq("Canada")
person.country = "Russia"
expect(@combo.swt_widget.text).to eq("Russia")
person.country = ""
expect(@combo.swt_widget.text).to eq("")
person.country = "Japan"
expect(@combo.swt_widget.text).to eq("Japan")
end
it "tests read only widget data binding selection property" do
person = Person.new
person.country = "Canada"
@target = shell {
@combo = combo(:read_only) {
selection bind(person, :country)
}
}
expect(@combo.swt_widget.item_count).to eq(4)
expect(@combo.swt_widget.text).to eq("Canada")
person.country_options << "France"
expect(@combo.swt_widget.item_count).to eq(5)
person.country_options=["", "Canada", "US", "Mexico", "Russia", "France"]
expect(@combo.swt_widget.item_count).to eq(6)
person.country_options << "Italy"
person.country_options << "Germany"
person.country_options << "Australia"
expect(@combo.swt_widget.item_count).to eq(9)
expect(@combo.swt_widget.text).to eq("")
@combo.swt_widget.select(8)
@combo.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], nil)
expect(person.country).to eq("Australia")
person.country = "Canada"
expect(@combo.swt_widget.text).to eq("Canada")
person.country = "Russia"
expect(@combo.swt_widget.text).to eq("Russia")
person.country = ""
expect(@combo.swt_widget.text).to eq("")
person.country = "Japan"
expect(@combo.swt_widget.text).to eq("")
end
it "tests data binding selection property on custom widget combo" do
person = Person.new
@target = shell {
@combo = red_combo {
selection bind(person, :country)
}
}
expect(@combo.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@combo.swt_widget.item_count).to eq(4)
expect(@combo.swt_widget.selection_index).to eq(-1)
expect(@combo.swt_widget.text).to eq("")
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__observe__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__observe__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Observe" do
include Glimmer
before do
class Person
attr_accessor :name, :main_address, :addresses
def initialize
self.addresses = []
end
end
class Address
attr_accessor :main_street, :streets
def initialize
@main_street = '123 Main St'
@streets = ['389 Park Ave', '928 Huron Ave']
end
end
end
after do
Object.send(:remove_const, :Person) if Object.const_defined?(:Person)
end
it 'observes/unobserves model property' do
person = Person.new
observer_registration = observe(person, :name) do |new_value|
expect(person.name).to eq('Sean Bugsley')
@observer_notified = true
end
person.name = 'Sean Bugsley'
expect(@observer_notified).to eq(true)
observer_registration.unregister
@observer_notified = false
person.name = 'Han Jones'
expect(@observer_notified).to eq(false)
end
it 'observes/unobserves model nested property' do
person = Person.new
address = Address.new
observer_registration = observe(person, 'main_address.main_street') do
expect(person.main_address.main_street).to eq('123 Main St')
@observer_notified = true
end
person.main_address = address
expect(@observer_notified).to eq(true)
observer_registration.unregister
@observer_notified = false
observer_registration = observe(person, 'main_address.main_street') do
expect(person.main_address.main_street).to eq('748 another main street')
@observer_notified = true
end
person.main_address.main_street = '748 another main street'
expect(@observer_notified).to eq(true)
observer_registration.unregister
@observer_notified = false
person.main_address.main_street = '362 yet another main street'
expect(@observer_notified).to eq(false)
end
it 'observes/unobserves model nested indexed property' do
person = Person.new
address = Address.new
observer_registration = observe(person, 'addresses[0].streets[0]') do
expect(person.addresses[0].streets[0]).to eq('389 Park Ave')
@observer_notified = true
end
person.addresses = [address]
expect(@observer_notified).to eq(true)
observer_registration.unregister
@observer_notified = false
observer_registration = observe(person, 'addresses[0].streets[0]') do
expect(person.addresses[0].streets[0]).to eq('38 Owen Blvd')
@observer_notified = true
end
person.addresses[0].streets[0] = '38 Owen Blvd'
expect(@observer_notified).to eq(true)
observer_registration.unregister
@observer_notified = false
person.addresses[0].streets[0] = '362 yet another blvd'
expect(@observer_notified).to eq(false)
end
it 'observes/unobserves array property' do
person = Person.new
address = Address.new
observer_registration = observe(person, 'addresses') do
expect(person.addresses.count).to eq(1)
@observer_notified = true
end
person.addresses << address
expect(@observer_notified).to eq(true)
observer_registration.unregister
@observer_notified = false
observer_registration = observe(person, 'addresses') do
expect(person.addresses.count).to eq(2)
@observer_notified = true
end
person.addresses << address.clone
expect(@observer_notified).to eq(true)
observer_registration.unregister
@observer_notified = false
person.addresses.clear
expect(@observer_notified).to eq(false)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__tab_item__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__tab_item__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Tab Item" do
include Glimmer
before(:all) do
class ::RedTabFolder
include Glimmer::UI::CustomWidget
body {
tab_folder {
background :red
}
}
end
end
after(:all) do
Object.send(:remove_const, :RedTabFolder) if Object.const_defined?(:RedTabFolder)
end
it "tests tab item composite with default layout" do
@target = shell {
@tab_folder = tab_folder {
@tab_item_composite = tab_item {
text "Tab 1"
label {text "Hello"}
}
}
}
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@tab_folder.swt_widget.items.size).to eq(1)
expect(@tab_item_composite.swt_widget).to be_instance_of(Composite)
expect(@tab_folder.swt_widget.items[0].control).to eq(@tab_item_composite.swt_widget)
expect(@tab_item_composite.swt_tab_item.getText).to eq("Tab 1")
expect(@tab_item_composite.swt_widget.getLayout).to_not be_nil
expect(@tab_item_composite.swt_widget.getLayout).to be_instance_of(GridLayout)
end
it "tests tab item composite with invalid parent (not a tab folder)" do
@target = shell
expect {
@target.content {
@invalid_parent = composite {
@tab_item_composite = tab_item {
text "Tab 1"
label {text "Hello"}
}
}
}
}.to raise_error(StandardError)
end
it "tests tab item composite with fill layout" do
@target = shell {
@tab_folder = tab_folder {
@tab_item_composite = tab_item {
text "Tab 2"
layout FillLayout.new
label {text "Hello"}
}
}
}
expect(@target).to_not be_nil
expect(@target.swt_widget).to_not be_nil
expect(@tab_folder.swt_widget.items.size).to eq(1)
expect(@tab_item_composite.swt_widget).to be_instance_of(Composite)
expect(@tab_folder.swt_widget.items[0].control).to eq(@tab_item_composite.swt_widget)
expect(@tab_item_composite.swt_tab_item.getText).to eq("Tab 2")
expect(@tab_item_composite.swt_widget.getLayout).to_not be_nil
expect(@tab_item_composite.swt_widget.getLayout).to be_instance_of(FillLayout)
end
it "builds custom widget tab" do
@target = shell {
@tab_folder = red_tab_folder {
@tab_item_composite = tab_item {
text "Tab 1"
}
}
}
expect(@tab_folder.swt_widget.items.size).to eq(1)
expect(@tab_folder.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@tab_item_composite.swt_widget).to be_instance_of(Composite)
expect(@tab_folder.swt_widget.items[0].control).to eq(@tab_item_composite.swt_widget)
expect(@tab_item_composite.swt_tab_item.getText).to eq("Tab 1")
expect(@tab_item_composite.swt_widget.getLayout).to_not be_nil
expect(@tab_item_composite.swt_widget.getLayout).to be_instance_of(GridLayout)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__radio_group__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__radio_group__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Radio Group" do
include Glimmer
before(:all) do
class Person
attr_accessor :country, :country_options
def initialize
self.country_options=["Canada", "US", "Mexico"]
end
end
class ::RedRadioGroup
include Glimmer::UI::CustomWidget
body {
radio_group(swt_style) {
background :red
}
}
end
end
after(:all) do
Object.send(:remove_const, :Person) if Object.const_defined?(:Person)
Object.send(:remove_const, :RedRadioGroup) if Object.const_defined?(:RedRadioGroup)
end
let(:person) {Person.new}
it 'sets items, spawning radios' do
@target = shell {
@radio_group = radio_group {
items person.country_options
}
}
@radio_group.radios.each do |radio|
expect(radio.swt_widget).to be_a(Button)
expect(radio).to have_style(:radio)
end
end
it 'sets selection in items, selecting radio accordingly' do
@target = shell {
@radio_group = radio_group {
items person.country_options
selection 'US'
}
}
@radio_group.radios.each do |radio|
expect(radio.swt_widget).to be_a(Button)
expect(radio).to have_style(:radio)
end
expect(@radio_group.radios[0].selection).to be_falsey
expect(@radio_group.radios[1].selection).to be_truthy
expect(@radio_group.radios[2].selection).to be_falsey
end
it 'sets attribute (background) on radio group including all nested widgets' do
@color = rgb(2, 102, 202).swt_color
@target = shell {
@radio_group = radio_group {
items person.country_options
background @color
}
}
@radio_group.radios.each do |radio|
expect(radio.background).to eq(@color)
end
@radio_group.labels.each do |label|
expect(label.background).to eq(@color)
end
@radio_group.children.each do |composite|
expect(composite.background).to eq(@color)
end
expect(@radio_group.background).to eq(@color)
end
it 'adds selection listener to radio_group spawned radios and mouse_up to matching labels' do
@listener_fired = false
@target = shell {
@radio_group = radio_group {
items person.country_options
on_widget_selected { |event|
expect(@radio_group.selection).to eq('Mexico')
expect(@radio_group.selection_index).to eq(2)
@listener_fired = true
}
}
}
@radio_group.radios[2].selection = true
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @radio_group.radios[2].swt_widget
event.widget = @radio_group.radios[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@radio_group.radios[2].notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(@listener_fired).to be_truthy
@listener_fired = false
@radio_group.selection = 'Canada'
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @radio_group.labels[2].swt_widget
event.widget = @radio_group.labels[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:mouseup]
@radio_group.labels[2].notifyListeners(Glimmer::SWT::SWTProxy[:mouseup], event)
expect(@listener_fired).to be_truthy
end
it 'adds mouse_up listener to radio_group spawned radios and labels' do
@listener_fired = false
@target = shell {
@radio_group = radio_group {
items person.country_options
on_mouse_up { |event|
expect(@radio_group.selection).to eq('Mexico')
expect(@radio_group.selection_index).to eq(2)
@listener_fired = true
}
}
}
@radio_group.radios[2].selection = true
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @radio_group.radios[2].swt_widget
event.widget = @radio_group.radios[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:mouseup]
@radio_group.radios[2].swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:mouseup], event)
expect(@listener_fired).to be_truthy
@listener_fired = false
@radio_group.selection = 'Canada'
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @radio_group.labels[2].swt_widget
event.widget = @radio_group.labels[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:mouseup]
@radio_group.labels[2].swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:mouseup], event)
expect(@listener_fired).to be_truthy
end
it 'data-binds selection property' do
@target = shell {
@radio_group = radio_group {
selection bind(person, :country)
}
}
expect(@radio_group.radios.count).to eq(3)
@radio_group.radios.each do |radio|
expect(radio.selection).to be_falsey
end
expect(@radio_group.selection).to eq("")
expect(@radio_group.selection_index).to eq(-1)
expect(@radio_group.items).to eq(person.country_options)
person.country = "Canada"
expect(@radio_group.radios[0].selection).to be_truthy
expect(@radio_group.radios[1].selection).to be_falsey
expect(@radio_group.radios[2].selection).to be_falsey
expect(@radio_group.selection).to eq("Canada")
expect(@radio_group.selection_index).to eq(0)
person.country_options << "France"
expect(@radio_group.radios.count).to eq(4)
person.country_options = ["Canada", "US", "Mexico", "Russia", "France"]
expect(@radio_group.radios.count).to eq(5)
person.country_options << "Italy"
person.country_options << "Germany"
person.country_options.unshift "Australia"
expect(@radio_group.radios.count).to eq(8)
expect(@radio_group.radios[0].selection).to be_falsey
expect(@radio_group.radios[1].selection).to be_truthy
@radio_group.radios[2..-1].each do |radio|
expect(radio.selection).to be_falsey
end
expect(@radio_group.selection).to eq("Canada")
expect(@radio_group.selection_index).to eq(1)
person.country_options -= ['Canada']
@radio_group.radios.each do |radio|
expect(radio.selection).to be_falsey
end
expect(@radio_group.selection).to eq("")
expect(@radio_group.selection_index).to eq(-1)
@radio_group.select(2)
event = Event.new
event.doit = true
event.display = display.swt_display
event.item = @radio_group.radios[2].swt_widget
event.widget = @radio_group.radios[2].swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@radio_group.radios[2].notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(@radio_group.radios[2].selection).to be_truthy
(@radio_group.radios[0..1] + @radio_group.radios[3..-1]).each do |radio|
expect(radio.selection).to be_falsey
end
expect(person.country).to eq("Mexico")
person.country = "Russia"
expect(@radio_group.radios[3].selection).to be_truthy
(@radio_group.radios[0..2] + @radio_group.radios[4..-1]).each do |radio|
expect(radio.selection).to be_falsey
end
expect(@radio_group.selection).to eq("Russia")
expect(@radio_group.selection_index).to eq(3)
person.country = "random value not in country options"
@radio_group.radios.each do |radio|
expect(radio.selection).to be_falsey
end
expect(@radio_group.selection).to eq("")
expect(@radio_group.selection_index).to eq(-1)
person.country = ""
@radio_group.radios.each do |radio|
expect(radio.selection).to be_falsey
end
expect(@radio_group.selection).to eq("")
expect(@radio_group.selection_index).to eq(-1)
person.country = nil
@radio_group.radios.each do |radio|
expect(radio.selection).to be_falsey
end
expect(@radio_group.selection).to eq("")
expect(@radio_group.selection_index).to eq(-1)
end
it 'data binds selection property on a custom widget radio_group' do
@target = shell {
@radio_group = red_radio_group {
selection bind(person, :country)
}
}
expect(@radio_group.background).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@radio_group.radios.count).to eq(3)
expect(@radio_group.selection_index).to eq(-1)
expect(@radio_group.selection).to eq("")
end
it 'data binds selection property on a custom widget radio_group with Shine syntax' do
@target = shell {
@radio_group = red_radio_group {
selection <=> [person, :country]
}
}
expect(@radio_group.background).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@radio_group.radios.count).to eq(3)
expect(@radio_group.selection_index).to eq(-1)
expect(@radio_group.selection).to eq("")
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__font__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__font__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Font" do
include Glimmer
it "sets font via hash having name, height, and style" do
@target = shell {
@label = label {
font name: 'Times', height: 36, style: :normal
}
}
font_data = @label.swt_widget.getFont.getFontData
font_datum = font_data.first
expect(font_datum.getName).to eq('Times')
expect(font_datum.getHeight).to eq(36)
expect(font_datum.getStyle).to eq(Glimmer::SWT::SWTProxy[:normal])
end
it "sets font with multiple styles" do
@target = shell {
@label = label {
font style: [:bold, :italic]
}
}
font_data = @label.swt_widget.getFont.getFontData
font_datum = font_data.first
expect(font_datum.getStyle).to eq(Glimmer::SWT::SWTProxy[:bold, :italic])
end
it "fails with a friendly message when label is given an invalid font style" do
@target = shell {
label {
expect {
font style: :deco
}.to raise_error("deco is an invalid font style! Valid values are :normal, :bold, and :italic")
}
}
end
it "sets font style as SWT constant" do
@target = shell {
@label = label {
font style: swt(:bold)
}
}
font_data = @label.swt_widget.getFont.getFontData
font_datum = font_data.first
expect(font_datum.getStyle).to eq(Glimmer::SWT::SWTProxy[:bold])
end
it "sets font as SWT Font object (builds Font using font keyword without parent)" do
@display = display
@font = font name: 'Times', height: 36, style: :normal
@target = shell {
@label = label {
font @font.swt_font
}
}
font_data = @label.swt_widget.getFont.getFontData
font_datum = font_data.first
expect(font_datum.getName).to eq('Times')
expect(font_datum.getHeight).to eq(36)
expect(font_datum.getStyle).to eq(Glimmer::SWT::SWTProxy[:normal])
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__styled_text__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__styled_text__spec.rb | require 'spec_helper'
module GlimmerSpec
describe "Glimmer Styled Text" do
include Glimmer
before(:all) do
class StyledTextPresenter
attr_accessor :text, :caret_offset, :selection_count, :selection, :top_index, :top_pixel
end
end
after(:all) do
%w[
StyledTextPresenter
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
before do
@process_event_loop_before_target_dispose = true
end
it "data-binds styled_text caret_offset" do
@styled_text_presenter = StyledTextPresenter.new
@styled_text_presenter.text = "This is a multi line\nstyled text widget."
@styled_text_presenter.caret_offset = 6
@target = shell {
@styled_text = styled_text {
text bind(@styled_text_presenter, :text)
caret_offset bind(@styled_text_presenter, :caret_offset)
}
}
expect(@styled_text.text).to eq(@styled_text_presenter.text)
expect(@styled_text.caret_offset).to eq(@styled_text_presenter.caret_offset)
@styled_text_presenter.caret_offset = 12
expect(@styled_text.caret_offset).to eq(@styled_text_presenter.caret_offset)
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @styled_text.swt_widget.display
event.item = @styled_text.swt_widget
event.widget = @styled_text.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keyup]
@styled_text.caret_offset = 21
@styled_text.notifyListeners(Glimmer::SWT::SWTProxy[:keyup], event)
expect(@styled_text_presenter.caret_offset).to eq(21)
end
it "data-binds styled_text caret_position to be compatible with text widget" do
@styled_text_presenter = StyledTextPresenter.new
@styled_text_presenter.text = "This is a multi line\nstyled text widget."
@styled_text_presenter.caret_offset = 6
@target = shell {
@styled_text = styled_text {
text bind(@styled_text_presenter, :text)
caret_position bind(@styled_text_presenter, :caret_offset)
}
}
expect(@styled_text.text).to eq(@styled_text_presenter.text)
expect(@styled_text.caret_offset).to eq(@styled_text_presenter.caret_offset)
@styled_text_presenter.caret_offset = 12
expect(@styled_text.caret_offset).to eq(@styled_text_presenter.caret_offset)
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @styled_text.swt_widget.display
event.item = @styled_text.swt_widget
event.widget = @styled_text.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keyup]
@styled_text.caret_offset = 21
@styled_text.notifyListeners(Glimmer::SWT::SWTProxy[:keyup], event)
expect(@styled_text_presenter.caret_offset).to eq(21)
end
it "data-binds styled_text selection_count" do
@styled_text_presenter = StyledTextPresenter.new
@styled_text_presenter.text = "This is a multi line\nstyled text widget."
@styled_text_presenter.selection_count = 6
@target = shell {
@styled_text = styled_text {
text bind(@styled_text_presenter, :text)
selection_count bind(@styled_text_presenter, :selection_count)
}
}
expect(@styled_text.text).to eq(@styled_text_presenter.text)
expect(@styled_text.selection_count).to eq(@styled_text_presenter.selection_count)
@styled_text_presenter.selection_count = 12
expect(@styled_text.selection_count).to eq(@styled_text_presenter.selection_count)
# just a fake event (not accurate)
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @styled_text.swt_widget.display
event.item = @styled_text.swt_widget
event.widget = @styled_text.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@styled_text.selection = Point.new(0, 21)
@styled_text.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(@styled_text_presenter.selection_count).to eq(21)
end
it "data-binds styled_text selection" do
@styled_text_presenter = StyledTextPresenter.new
@styled_text_presenter.text = "This is a multi line\nstyled text widget."
@styled_text_presenter.selection = Point.new(6, 6)
@target = shell {
@styled_text = styled_text {
text bind(@styled_text_presenter, :text)
selection bind(@styled_text_presenter, :selection)
}
}
async_exec {
expect(@styled_text).to be_a(Glimmer::SWT::StyledTextProxy)
expect(@styled_text.text).to eq(@styled_text_presenter.text)
expect(@styled_text.selection.x).to eq(@styled_text_presenter.selection.x)
expect(@styled_text.selection.y).to eq(@styled_text_presenter.selection.y)
}
async_exec {
@styled_text_presenter.selection = Point.new(7, 12)
}
async_exec {
expect(@styled_text.selection.x).to eq(@styled_text_presenter.selection.x)
expect(@styled_text.selection.y).to eq(@styled_text_presenter.selection.y)
}
async_exec {
@styled_text.selection = Point.new(0, 21)
}
async_exec {
# just a fake event (not accurate)
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @styled_text.swt_widget.display
event.item = @styled_text.swt_widget
event.widget = @styled_text.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keyup]
@styled_text.notifyListeners(Glimmer::SWT::SWTProxy[:keyup], event)
}
async_exec {
expect(@styled_text_presenter.selection.x).to eq(0)
expect(@styled_text_presenter.selection.y).to eq(21)
}
end
it "data-binds styled_text top_index" do
@styled_text_presenter = StyledTextPresenter.new
@styled_text_presenter.text = "This is a multi line\n"*26
@styled_text_presenter.top_index = 6
@target = shell {
@styled_text = styled_text {
text bind(@styled_text_presenter, :text)
top_index bind(@styled_text_presenter, :top_index)
}
}
expect(@styled_text.text).to eq(@styled_text_presenter.text)
expect(@styled_text.top_index).to eq(@styled_text_presenter.top_index)
@styled_text_presenter.top_index = 12
expect(@styled_text.top_index).to eq(@styled_text_presenter.top_index)
# just a fake event (not accurate)
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @styled_text.swt_widget.display
event.item = @styled_text.swt_widget
event.widget = @styled_text.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keyup]
@styled_text.top_index = 21
@styled_text.notifyListeners(Glimmer::SWT::SWTProxy[:paint], event)
expect(@styled_text_presenter.top_index).to eq(21)
end
it "data-binds styled_text top_pixel" do
@styled_text_presenter = StyledTextPresenter.new
@styled_text_presenter.text = "This is a multi line\nstyled text widget."*27
@styled_text_presenter.top_pixel = 6
@target = shell {
@styled_text = styled_text {
text bind(@styled_text_presenter, :text)
top_pixel bind(@styled_text_presenter, :top_pixel)
}
}
expect(@styled_text.text).to eq(@styled_text_presenter.text)
expect(@styled_text.top_pixel).to eq(@styled_text_presenter.top_pixel)
@styled_text_presenter.top_pixel = 12
expect(@styled_text.top_pixel).to eq(@styled_text_presenter.top_pixel)
# just a fake event (not accurate)
event = Event.new
event.keyCode = Glimmer::SWT::SWTProxy[:cr]
event.doit = true
event.character = "\n"
event.display = @styled_text.swt_widget.display
event.item = @styled_text.swt_widget
event.widget = @styled_text.swt_widget
event.type = Glimmer::SWT::SWTProxy[:keyup]
@styled_text.top_pixel = 21
@styled_text.notifyListeners(Glimmer::SWT::SWTProxy[:paint], event)
expect(@styled_text_presenter.top_pixel).to eq(21)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/dsl/swt/glimmer__dialog__spec.rb | spec/lib/glimmer/dsl/swt/glimmer__dialog__spec.rb | require "spec_helper"
module GlimmerSpec
describe "Glimmer Dialog" do
include Glimmer
it 'renders a dialog having dialog trim and application modal styles' do
@target = dialog
expect(@target).to be_a(Glimmer::SWT::ShellProxy)
expect(@target.swt_widget).to be_a(Shell)
expect(@target.swt_widget).to have_style(:dialog_trim)
expect(@target.swt_widget).to have_style(:application_modal)
end
it 'renders a dialog under a shell' do
@target = shell {
@dialog = dialog {
text 'Hello, World!'
@label = label
}
}
expect(@dialog).to be_a(Glimmer::SWT::ShellProxy)
expect(@dialog.swt_widget).to be_a(Shell)
expect(@dialog.swt_widget).to have_style(:dialog_trim)
expect(@dialog.swt_widget).to have_style(:application_modal)
expect(@dialog.swt_widget.getParent).to eq(@target.swt_widget)
expect(@dialog.swt_widget.getText).to eq('Hello, World!')
expect(@label.swt_widget.getParent).to eq(@dialog.swt_widget)
end
it 'renders a dialog nested explicitly under a shell via argument' do
@target = shell
@dialog = dialog(@target)
expect(@dialog).to be_a(Glimmer::SWT::ShellProxy)
expect(@dialog.swt_widget).to be_a(Shell)
expect(@dialog.swt_widget).to have_style(:dialog_trim)
expect(@dialog.swt_widget).to have_style(:application_modal)
expect(@dialog.swt_widget.getParent).to eq(@target.swt_widget)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/swt/table_proxy_spec.rb | spec/lib/glimmer/swt/table_proxy_spec.rb | require 'spec_helper'
module GlimmerSpec
describe Glimmer::SWT::TableProxy do
include Glimmer
before(:all) do
class Person
attr_accessor :name
def initialize(name)
@name = name
end
end
class Company
attr_accessor :name, :coworkers
def initialize(coworkers)
@coworkers = coworkers
end
end
end
after(:all) do
%w[
Person
Company
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
it 'is used with table expression' do
@target = shell {
@table = table {
}
@text = text {
}
}
expect(@table).to be_a(described_class)
expect(@text).to be_a(Glimmer::SWT::WidgetProxy)
end
describe '#search' do
let(:person1) { Person.new('Sean') }
let(:person2) { Person.new('Chuck') }
let(:person3) { Person.new('John') }
let(:person4) { Person.new('Mark') }
let(:person5) { Person.new('Derrick') }
let(:person6) { Person.new('Juana') }
let(:company1) do
Company.new([person1, person2, person3, person4, person5, person6])
end
before do
@target = shell {
@table = table {
table_column {
text 'Name'
width 120
}
items bind(company1, :coworkers), column_properties(:name)
}
}
end
it 'finds table items by block condition' do
table_items = @table.search { |table_item| table_item.getText.start_with?('J') }
expect(table_items.map(&:getText)).to eq(['John', 'Juana'])
end
it 'finds no table items' do
table_items = @table.search { |table_item| table_item.getText.start_with?('Z') }
expect(table_items.empty?).to be_truthy
end
it 'gets all table items by not passing a condition block' do
table_items = @table.search
expect(table_items.map(&:getText)).to eq(['Sean', 'Chuck', 'John', 'Mark', 'Derrick', 'Juana'])
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/swt/tree_proxy_spec.rb | spec/lib/glimmer/swt/tree_proxy_spec.rb | require 'spec_helper'
module GlimmerSpec
describe Glimmer::SWT::TreeProxy do
include Glimmer
before(:all) do
class Person
attr_accessor :name, :coworkers
def initialize(name)
@name = name
@coworkers = []
end
end
class Company
def initialize
@owner = []
end
attr_accessor :owner
end
end
after(:all) do
%w[
Person
Company
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
it 'is used with tree expression' do
@target = shell {
@tree = tree {
}
@text = text {
}
}
expect(@tree).to be_a(described_class)
expect(@text).to be_a(Glimmer::SWT::WidgetProxy)
end
describe '#depth_first_search' do
let(:person4) {Person.new('Mark')}
let(:person5) {Person.new('Derrick')}
let(:person2) do
Person.new('Chuck').tap do |person|
person.coworkers = [person4, person5]
end
end
let(:person6) { Person.new('Juana') }
let(:person3) do
Person.new('John').tap do |person|
person.coworkers = [person6]
end
end
let(:person1) do
Person.new('Sean').tap do |person|
person.coworkers = [person2, person3]
end
end
let(:company1) do
Company.new.tap do |company|
company.owner = person1
end
end
before do
@target = shell {
@tree = tree {
items bind(company1, :owner), tree_properties(children: :coworkers, text: :name)
}
}
end
it 'finds tree items by block condition' do
tree_items = @tree.depth_first_search { |tree_item| tree_item.getText.start_with?('J') }
expect(tree_items.map(&:getText)).to eq(['John', 'Juana'])
end
it 'finds no tree items' do
tree_items = @tree.depth_first_search { |tree_item| tree_item.getText.start_with?('Z') }
expect(tree_items.empty?).to be_truthy
end
it 'gets all tree items by not passing a condition block' do
tree_items = @tree.depth_first_search
expect(tree_items.map(&:getText)).to eq(%w[Sean Chuck Mark Derrick John Juana])
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/swt/widget_proxy_spec.rb | spec/lib/glimmer/swt/widget_proxy_spec.rb | require "spec_helper"
module GlimmerSpec
describe Glimmer::SWT::WidgetProxy do
include Glimmer
it "wraps an existing swt_widget instead of initializing with init_args" do
@target = shell
@swt_scrolled_composite = ScrolledComposite.new(@target.swt_widget, swt(:none))
@scrolled_composite = Glimmer::SWT::WidgetProxy.create(swt_widget: @swt_scrolled_composite)
expect(@scrolled_composite.swt_widget).to eq(@swt_scrolled_composite)
expect(@scrolled_composite.swt_widget.get_data('proxy')).to eq(@scrolled_composite)
expect(@scrolled_composite.parent_proxy).to be_a(Glimmer::SWT::ShellProxy)
expect(@scrolled_composite.parent_proxy.swt_widget).to eq(@swt_scrolled_composite.parent)
@swt_composite = Composite.new(@swt_scrolled_composite, swt(:none))
@composite = Glimmer::SWT::WidgetProxy.create(swt_widget: @swt_composite)
# verify default initializers are called on widget
expect(@swt_composite.get_layout).to be_a(GridLayout)
# verify post_initialize_child is called on parent
expect(@swt_scrolled_composite.content).to eq(@swt_composite)
end
it "wraps an existing composite without setting default layout if a layout exists" do
@target = shell {
@composite = composite {
fill_layout
}
}
expect(@composite.getLayout).to be_a(FillLayout)
@wrapper = Glimmer::SWT::WidgetProxy.new(swt_widget: @composite.swt_widget)
expect(@wrapper.swt_widget).to eq(@composite.swt_widget)
expect(@wrapper.getLayout).to be_a(FillLayout)
end
it "wraps an existing group without setting default layout if a layout exists" do
@target = shell {
@group = group {
fill_layout
}
}
expect(@group.getLayout).to be_a(FillLayout)
@wrapper = Glimmer::SWT::WidgetProxy.new(swt_widget: @group.swt_widget)
expect(@wrapper.swt_widget).to eq(@group.swt_widget)
expect(@wrapper.getLayout).to be_a(FillLayout)
end
it "sets data('proxy')" do
@target = shell {
@composite = composite {
@label = label {
}
}
}
expect(@label.get_data('proxy')).to eq(@label)
expect(@composite.get_data('proxy')).to eq(@composite)
end
it "returns data('proxy') in create method when passing a previously wrapped swt_widget" do
@target = shell {
@label = label
}
expect(Glimmer::SWT::WidgetProxy.create(swt_widget: @label.swt_widget)).to eq(@label)
end
it 'adds listener' do
@target = shell {
composite {
@text = text {
text "Howdy"
}
@text.on_verify_text do |verify_event|
verify_event.doit = false if verify_event.text == "Hello"
end
}
}
@text.setText("Hi")
expect(@text.getText).to eq("Hi")
@text.setText("Hello")
expect(@text.getText).to eq("Hi")
end
it 'adds content' do
@target = shell {
minimum_size 50, 20
}
@target.content {
minimum_size 300, 200
composite {
@text = text {
text "Howdy"
}
}
}
expect(@target.getMinimumSize.x).to eq(300)
expect(@target.getMinimumSize.y).to eq(200)
expect(@text.getText).to eq("Howdy")
end
context 'UI code execution' do
after do
if @target && !@target.isDisposed
@target.async_exec do
@target.dispose
end
@target.start_event_loop
end
end
it "syncronously and asynchronously executes UI code" do
@target = shell {
@text = text {
text "text1"
}
}
@target.async_exec do
expect(@text.getText).to eq("text2")
end
# This takes prioerity over async_exec
@target.sync_exec do
@text.setText("text2")
end
end
end
describe '#pack_same_size' do
it 'packs composite widget content while maintaining the same size despite child text widget needing more space with more content' do
@target = shell {
alpha 0 # keep invisible while running specs
grid_layout 1, false
@composite = composite {
@text = text {
layout_data :fill, :fill, true, true
text 'A'
}
}
}
@target.pack
text_width = @text.getSize.x
composite_width = @composite.getSize.x
shell_width = @target.getSize.x
@text.setText('A very long text it cannot fit in the screen if you keep reading on' + ' and on'*60)
@composite.pack_same_size
expect(@text.getSize.x).to eq(text_width)
expect(@composite.getSize.x).to eq(composite_width)
expect(@target.getSize.x).to eq(shell_width)
end
it 'packs text widget content while maintaining the same size despite needing more space with more content' do
@target = shell {
alpha 0 # keep invisible while running specs
grid_layout 1, false
@text = text {
layout_data :fill, :fill, true, true
text 'A'
}
}
@target.pack
text_width = @text.getSize.x
shell_width = @target.getSize.x
@text.setText('A very long text it cannot fit in the screen if you keep reading on' + ' and on'*60)
@text.pack_same_size
expect(@text.getSize.x).to eq(text_width)
expect(@target.getSize.x).to eq(shell_width)
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/swt/shell_proxy_spec.rb | spec/lib/glimmer/swt/shell_proxy_spec.rb | require "spec_helper"
module GlimmerSpec
describe Glimmer::SWT::ShellProxy do
include Glimmer
it "sets data('proxy')" do
@target = shell {
}
expect(@target.get_data('proxy')).to eq(@target)
end
unless OS.windows?
describe '#visible?' do
it 'returns false before initially opened and true afterwards' do
@target = described_class.new
@target.setAlpha(0) # keep invisible while running specs
expect(@target.visible?).to eq(false)
@target.async_exec do
expect(@target.visible?).to eq(true)
@target.close
expect(@target.visible?).to eq(false)
end
@target.open
end
it 'returns false if hidden after initially opened (this time with alias method show)' do
@target = described_class.new
@target.setAlpha(0) # keep invisible while running specs
@target.async_exec do
expect(@target.visible?).to eq(true)
@target.hide
expect(@target.visible?).to eq(false)
@target.close
end
@target.show
end
it 'returns false when visibility is set to false in described_class' do
@target = described_class.new
@target.setAlpha(0) # keep invisible while running specs
@target.async_exec do
expect(@target.visible?).to eq(true)
@target.visible = false
expect(@target.visible?).to eq(false)
expect(@target.isVisible).to eq(false)
@target.close
end
@target.visible = true
end
unless ENV['CI'].to_s.downcase == 'true'
describe '#include_focus_control?' do
after do
if @target
@target.async_exec do
@target.close
@target2&.close
end
@target.open
end
end
it 'is true for a shell that includes the focus control and false otherwise' do
@target = shell {
text {
focus true
}
}
@target.setAlpha(0) # keep invisible while running specs
@target2 = shell(@target) {
combo {
focus true
}
}
@target2.setAlpha(0) # keep invisible while running specs
expect(@target.include_focus_control?).to eq(false)
expect(@target2.include_focus_control?).to eq(false)
# async_exec blocks execute after opening target
async_exec do
@target2.open
@shell1_include_focus_control = @target.include_focus_control?
@shell2_include_focus_control = @target2.include_focus_control?
end
async_exec do
expect(@shell1_include_focus_control).to eq(false)
expect(@shell2_include_focus_control).to eq(true)
end
end
end
end
end
describe '#pack' do
it 'packs shell content by invoking SWT Shell#pack' do
@target = shell {
alpha 0 # keep invisible while running specs
grid_layout 1, false
@text = text {
layout_data :fill, :fill, true, true
text 'A'
}
}
text_width = @text.getSize.x
shell_width = @target.getSize.x
@text.setText('A very long text it cannot fit in the screen if you keep reading on' + ' and on'*60)
@target.pack # packing shell should resize text widget
expect(@text.getSize.x > text_width).to eq(true)
expect(@target.getSize.x > shell_width).to eq(true)
end
end
describe '#pack_same_size' do
it 'packs shell content while maintaining the same shell size (widget sizes may vary)' do
@target = shell {
alpha 0 # keep invisible while running specs
grid_layout 1, false
@text = text {
layout_data :fill, :fill, true, true
text 'A'
}
}
text_width = @text.getSize.x
shell_width = @target.getSize.x
@text.setText('A very long text it cannot fit in the screen if you keep reading on' + ' and on'*60)
@target.pack_same_size # packing shell should resize text widget but keep same shell size
expect(@text.getSize.x > text_width).to eq(true)
expect(@target.getSize.x).to eq(shell_width)
end
end
describe 'visibility observation' do
it 'notifies when becoming visible' do
@shown = false
@target = described_class.new
@target.setAlpha(0) # keep invisible while running specs
@target.on_swt_show {
@shown = true
}
@target.async_exec do
expect(@target.visible?).to eq(true)
expect(@shown).to eq(true)
@target.close
end
expect(@target.visible?).to eq(false)
expect(@shown).to eq(false)
@target.show
end
it 'notifies when becoming non-visible (observed with alternative syntax)' do
@target = described_class.new
@target.setAlpha(0) # keep invisible while running specs
@target.on_swt_hide {
expect(@target.visible?).to eq(false)
@target.close
}
@target.async_exec do
@target.hide
end
@target.show
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/swt/swt_proxy_spec.rb | spec/lib/glimmer/swt/swt_proxy_spec.rb | require "spec_helper"
java_import 'org.eclipse.swt.SWT'
module GlimmerSpec
describe Glimmer::SWT::SWTProxy do
describe '.constant' do
it 'returns SWT constant value for symbol' do
expect(Glimmer::SWT::SWTProxy.constant(:border)).to eq(::SWT::BORDER)
end
it 'returns SWT constant value for symbol representing an SWT constant that is not all caps' do
expect(Glimmer::SWT::SWTProxy.constant(:selection)).to eq(::SWT::Selection)
end
it 'returns SWT constant value for symbol representing an SWT constant that is not all caps when not specified in lower case' do
expect(Glimmer::SWT::SWTProxy.constant(:Resize)).to eq(::SWT::Resize)
end
it 'returns SWT constant value for symbol representing an SWT constant that is all caps when specified in lower case' do
expect(Glimmer::SWT::SWTProxy.constant(:resize)).to eq(::SWT::RESIZE)
end
it 'returns SWT constant value for symbol representing an extra SWT constant added in Glimmer for convenience' do
expect(Glimmer::SWT::SWTProxy.constant(:no_resize)).to eq(::SWT::SHELL_TRIM & ~::SWT::RESIZE & ~::SWT::MAX)
end
it 'returns SWT constant value for a negative symbol (postfixed by !)' do
expect(Glimmer::SWT::SWTProxy.constant(:max!)).to eq(~::SWT::MAX)
end
it 'returns SWT constant value for a negative symbol that is not all caps in SWT' do
expect(Glimmer::SWT::SWTProxy.constant(:activate!)).to eq(~::SWT::Activate)
end
it 'returns SWT constant value for a negative symbol representing an extra SWT constant added in Glimmer for convenience' do
expect(Glimmer::SWT::SWTProxy.constant(:no_resize!)).to eq(~(::SWT::SHELL_TRIM & ~::SWT::RESIZE & ~::SWT::MAX))
end
it 'returns SWT constant value for string' do
expect(Glimmer::SWT::SWTProxy.constant('border')).to eq(::SWT::BORDER)
end
it 'returns SWT constant value as is when passed in as a number' do
swt_constant = ::SWT::BORDER
expect(Glimmer::SWT::SWTProxy.constant(swt_constant)).to eq(swt_constant)
end
end
describe '.[]' do
context 'single argument' do
it 'returns SWT constant value' do
expect(Glimmer::SWT::SWTProxy[:border]).to eq(::SWT::BORDER)
end
it 'returns SWT constant value 0 (::SWT::NONE) for nil' do
expect(Glimmer::SWT::SWTProxy[nil]).to eq(::SWT::NONE)
end
end
context 'multiple arguments' do
it 'returns SWT constant value for homogonous values (symbols)' do
expect(Glimmer::SWT::SWTProxy[:border, :v_scroll]).to eq(::SWT::BORDER | ::SWT::V_SCROLL)
end
it 'returns SWT constant value for mixed values (symbol, string, and integer)' do
expect(Glimmer::SWT::SWTProxy['border', :v_scroll, ::SWT::CENTER]).to eq(::SWT::BORDER | ::SWT::V_SCROLL | ::SWT::CENTER)
end
it 'returns SWT constant value for negative and positive symbols' do
expect(Glimmer::SWT::SWTProxy[:shell_trim, :resize, :max!, :min!]).to eq((::SWT::SHELL_TRIM | ::SWT::SHELL_TRIM) & ~::SWT::MAX & ~::SWT::MIN)
end
it 'returns SWT constant value for values including an accelerator key character (CTRL+SHIFT+V)' do
expect(Glimmer::SWT::SWTProxy[:ctrl, :shift, :v]).to eq(::SWT::CTRL | ::SWT::SHIFT | 'v'.bytes.first)
end
end
context 'empty arguments' do
it 'returns SWT constant value 0 (::SWT::NONE) for empty arguments' do
expect(Glimmer::SWT::SWTProxy[]).to eq(::SWT::NONE)
end
end
context 'bad arguments' do
it 'displays a friendly error message' do
expect {Glimmer::SWT::SWTProxy[:bold, :beautiful]}.to raise_error("beautiful is an invalid SWT style! Please choose a style from org.eclipse.swt.SWT class constants.")
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/data_binding/observable_model_spec.rb | spec/lib/glimmer/data_binding/observable_model_spec.rb | require "spec_helper"
module GlimmerSpec
describe Glimmer::DataBinding::ObservableModel do
before(:all) do
class Person
attr_accessor :name
end
class SpecObserver
include Glimmer::DataBinding::Observer
attr_reader :observed_name
def call(name)
@observed_name = name
end
end
end
after(:all) do
%w[
Person
SpecPerson
].each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
it 'observes model' do
person = Person.new
person.name = "Marty"
expect(person.name).to eq("Marty")
observer = SpecObserver.new
observer.observe(person, :name)
person.name = "Julia"
expect(observer.observed_name).to eq("Julia")
expect(person.name).to eq("Julia")
end
it 'implements inspect (to avoid printing all observers by default)' do
person = Person.new
person.name = "Marty"
expect(person.name).to eq("Marty")
observer = SpecObserver.new
observer.observe(person, :name)
expect(person.inspect).to_not include('SpecObserver')
expect(person.inspect).to match(/#<GlimmerSpec::Person:0x.*>/)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/ui/custom_shell_spec.rb | spec/lib/glimmer/ui/custom_shell_spec.rb | require "spec_helper"
module GlimmerSpec
describe Glimmer::UI::CustomShell do
include Glimmer
before(:all) do
class ::TimeShell
include Glimmer::UI::CustomShell
body {
shell {
alpha 0 # keep invisible while running specs
label {
text "It is always beer'o'clock!"
}
}
}
end
class ::InvalidCustomShell
include Glimmer::UI::CustomShell
body {
composite
}
end
end
after(:all) do
Object.send(:remove_const, :TimeShell) if Object.const_defined?(:TimeShell)
Object.send(:remove_const, :InvalidCustomShell) if Object.const_defined?(:InvalidCustomShell)
end
after do
if @target && !@target.swt_widget.isDisposed
@target.async_exec do
@target.dispose
end
@target.open
end
end
it "sets data('custom_shell')" do
@target = time_shell
expect(@target.swt_widget.get_data('custom_shell')).to eq(@target)
end
it 'opens and closes' do
@target = time_shell
@target.swt_widget.setAlpha(0) # keep invisible while running specs
expect(@target.swt_widget.children.first.is_a?(Label)).to eq(true)
expect(@target.swt_widget.children.first.getText).to eq("It is always beer'o'clock!")
expect(@target.visible?).to eq(false)
@target.async_exec do
expect(@target.visible?).to eq(true)
end
end
it 'rejects a non shell body root' do
expect do
invalid_custom_shell
end.to raise_error(NameError)
end
it 'handles events' do
@target = time_shell
@target.on_swt_hide do
@time_shell_hidden = true
end
@target.async_exec do
@target.hide
end
@target.async_exec do
expect(@time_shell_hidden).to eq(true)
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/spec/lib/glimmer/ui/custom_widget_spec.rb | spec/lib/glimmer/ui/custom_widget_spec.rb | require "spec_helper"
module GlimmerSpec
describe Glimmer::UI::CustomWidget do
include Glimmer
before(:all) do
class ::RedLabel
include Glimmer::UI::CustomWidget
body {
label(swt_style) {
background :red
}
}
end
class ::ColoredLabel
include Glimmer::UI::CustomWidget
option :color
option :foreground_color, default: :red
body {
label(swt_style) {
background options[:color]
# foreground can change after instantiation via data-binding
foreground bind(self, :foreground_color)
}
}
end
class ::MultiColorLabel
include Glimmer::UI::CustomWidget
options :color1, :color2
options "font1", "font2"
def text=(value)
half_size = value.size/2
@label1.swt_widget.setText value[0...half_size]
@label2.swt_widget.setText value[half_size...value.size]
end
def text
value1 = @label1.swt_widget.getText
value2 = @label2.swt_widget.getText
"#{value1}#{value2}"
end
body {
composite {
fill_layout :horizontal
@label1 = label(swt_style) {
background color1
font font1
}
@label2 = label(swt_style) {
background color2
font font2
}
}
}
end
module Red
class Composite
include Glimmer::UI::CustomWidget
body {
composite(swt_style) {
background :red
}
}
end
class Label
include Glimmer::UI::CustomWidget
body {
label(swt_style) {
background :red
}
}
end
end
class Sandwich
include Glimmer::UI::CustomWidget
body {
composite(swt_style) {
fill_layout :vertical
background :white
label {
text 'SANDWICH TOP'
}
content.call
label {
text 'SANDWICH BOTTOM'
}
}
}
end
class ::BeforeAndAfter
include Glimmer::UI::CustomWidget
attr_reader :mouse_down
before_body do
@background = :red
@foreground = :green
end
after_body do
@label.swt_widget.setText "Before and After"
@label.swt_widget.setEnabled(false)
end
body {
composite {
background @background
@label = label {
background @background
foreground @foreground
on_mouse_down { |event|
@mouse_down = true
}
}
}
}
end
class ::InvalidCustomWidget
include Glimmer::UI::CustomWidget
end
class ::EmptyBodyCustomWidget
include Glimmer::UI::CustomWidget
body {}
end
end
after(:all) do
Object.send(:remove_const, :InvalidCustomWidget) if Object.const_defined?(:InvalidCustomWidget)
Object.send(:remove_const, :RedLabel) if Object.const_defined?(:RedLabel)
Object.send(:remove_const, :ColoredLabel) if Object.const_defined?(:ColoredLabel)
Object.send(:remove_const, :MultiColorLabel) if Object.const_defined?(:MultiColorLabel)
GlimmerSpec::Red.send(:remove_const, :Composite) if GlimmerSpec::Red.const_defined?(:Composite)
GlimmerSpec::Red.send(:remove_const, :Label) if GlimmerSpec::Red.const_defined?(:Label)
GlimmerSpec.send(:remove_const, :Red) if GlimmerSpec.const_defined?(:Red)
GlimmerSpec.send(:remove_const, :Sandwich) if GlimmerSpec.const_defined?(:Sandwich)
end
after do
@target.dispose if @target
end
it "builds custom widget with no namespace" do
@target = shell {
@red_label = red_label
}
expect(@red_label.swt_widget.getParent).to eq(@target.swt_widget)
expect(@red_label.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
end
it "sets data('custom_widget')" do
@target = shell {
@red_label = red_label
}
expect(@red_label.swt_widget.get_data('custom_widget')).to eq(@red_label)
end
it "builds custom widget with no namespace having attributes" do
@target = shell {
@red_label = red_label {
text 'Red Label'
}
}
expect(@red_label.swt_widget.getParent).to eq(@target.swt_widget)
expect(@red_label.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@red_label.swt_widget.getText).to eq('Red Label')
end
it "builds custom widget with an option" do
@target = shell {
@colored_label = colored_label(color: :blue)
}
expect(@colored_label.swt_widget.getParent).to eq(@target.swt_widget)
expect(@colored_label.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:blue).swt_color)
expect(@colored_label.swt_widget.getForeground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
@colored_label.foreground_color = :white
expect(@colored_label.swt_widget.getForeground).to eq(Glimmer::SWT::ColorProxy.new(:white).swt_color)
end
it "builds custom widget with namespace" do
@target = shell {
@red_label = glimmer_spec__red__label {
text 'Red Label'
}
}
expect(@red_label.swt_widget.getParent).to eq(@target.swt_widget)
expect(@red_label.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@red_label.swt_widget.getText).to eq('Red Label')
end
it "builds custom widget without mentioning full namespace" do
@target = shell {
@red_label = red__label {
text 'Red Label'
}
}
expect(@red_label.swt_widget.getParent).to eq(@target.swt_widget)
expect(@red_label.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@red_label.swt_widget.getText).to eq('Red Label')
end
it "builds custom widget with namespace and content" do
@target = shell {
@sandwich = glimmer_spec__sandwich {
label {
text 'SANDWICH CONTENT'
}
}
}
expect(@sandwich.swt_widget.getParent).to eq(@target.swt_widget)
expect(@sandwich.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:white).swt_color)
expect(@sandwich.swt_widget.getChildren.size).to eq(3)
expect(@sandwich.swt_widget.getChildren[0].getText).to eq('SANDWICH TOP')
expect(@sandwich.swt_widget.getChildren[1].getText).to eq('SANDWICH CONTENT')
expect(@sandwich.swt_widget.getChildren[2].getText).to eq('SANDWICH BOTTOM')
end
it "builds nested custom widgets" do
@target = shell {
@red_composite = glimmer_spec__red__composite {
row_layout :vertical
@red_label = glimmer_spec__red__label {
text 'Red Label'
}
}
}
expect(@red_composite.swt_widget.getParent).to eq(@target.swt_widget)
expect(@red_composite.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@red_composite.swt_widget.getLayout.is_a?(RowLayout)).to be_truthy
expect(@red_label.swt_widget.getParent).to eq(@red_composite.swt_widget)
expect(@red_label.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@red_label.swt_widget.getText).to eq('Red Label')
end
it "builds composite custom widgets having options" do
@target = shell {
@multi_color_label = multi_color_label(
:center,
color1: :red,
color2: :blue,
font1: {height: 62},
font2: {height: 73}
) {
text 'Hello,World!'
}
}
expect(@multi_color_label.swt_widget.getParent).to eq(@target.swt_widget)
expect(@multi_color_label.swt_widget.getChildren.size).to eq(2)
expect(@multi_color_label.swt_widget.getChildren[0]).to be_a(Label)
expect(@multi_color_label.swt_widget.getChildren[0].getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@multi_color_label.swt_widget.getChildren[0].getFont.getFontData[0].getHeight).to eq(62)
expect(@multi_color_label.swt_widget.getChildren[0].getText).to eq("Hello,")
expect(@multi_color_label.swt_widget.getChildren[0].getStyle & Glimmer::SWT::SWTProxy[:center]).to eq(Glimmer::SWT::SWTProxy[:center])
expect(@multi_color_label.swt_widget.getChildren[1]).to be_a(Label)
expect(@multi_color_label.swt_widget.getChildren[1].getBackground).to eq(Glimmer::SWT::ColorProxy.new(:blue).swt_color)
expect(@multi_color_label.swt_widget.getChildren[1].getFont.getFontData[0].getHeight).to eq(73)
expect(@multi_color_label.swt_widget.getChildren[1].getText).to eq("World!")
expect(@multi_color_label.swt_widget.getChildren[1].getStyle & Glimmer::SWT::SWTProxy[:center]).to eq(Glimmer::SWT::SWTProxy[:center])
end
it 'observes custom widget custom property' do
@target = shell {
@multi_color_label = multi_color_label(
:center,
color1: :red,
color2: :blue,
font1: {height: 62},
font2: {height: 73}
) {
text 'Hello,World!'
on_updated_text {
@updated_text = true
}
}
}
expect(@updated_text).to be_nil
@multi_color_label.text = 'Howdy,Partner!'
expect(@updated_text).to eq(true)
end
it 'observes custom widget custom property with alternative syntax' do
@target = shell {
@multi_color_label = multi_color_label(
:center,
color1: :red,
color2: :blue,
font1: {height: 62},
font2: {height: 73}
) {
text 'Hello,World!'
}
}
@multi_color_label.on_updated_text {
@updated_text_with_alternative_syntax = true
}
expect(@updated_text_with_alternative_syntax).to be_nil
@multi_color_label.text = 'Howdy,Partner!'
expect(@updated_text_with_alternative_syntax).to eq(true)
end
it 'executes before_body and after_body blocks' do
@target = shell {
@before_and_after = before_and_after
}
expect(@before_and_after.swt_widget.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
@label = @before_and_after.swt_widget.getChildren.first
expect(@label.getBackground).to eq(Glimmer::SWT::ColorProxy.new(:red).swt_color)
expect(@label.getForeground).to eq(Glimmer::SWT::ColorProxy.new(:green).swt_color)
expect(@label.getText).to eq('Before and After')
expect(@label.isEnabled).to eq(false)
event = Event.new
event.doit = true
event.character = "\n"
event.display = @label.getDisplay
event.item = @label
event.widget = @label
event.type = Glimmer::SWT::SWTProxy[:mousedown]
@label.notifyListeners(Glimmer::SWT::SWTProxy[:mousedown], event)
expect(@before_and_after.mouse_down).to eq(true)
end
it 'adds content' do
@target = shell {
@red_composite = glimmer_spec__red__composite
}
@red_composite.content {
@text = text {
text "Howdy"
}
}
expect(@red_composite.swt_widget.getChildren.first).to eq(@text.swt_widget)
expect(@text.swt_widget.getText).to eq('Howdy')
end
it 'returns Glimmer error if custom widget has no body in its definition' do
@target = shell {
expect {invalid_custom_widget}.to raise_error(Glimmer::Error)
}
end
it 'returns Glimmer error if custom widget has an empty body in its definition' do
@target = shell {
expect {empty_body_custom_widget}.to raise_error(Glimmer::Error)
}
end
context 'UI code execution' do
after do
if @target && !@target.swt_widget.isDisposed
@target.async_exec do
@target.dispose
end
@target.start_event_loop
end
end
it "syncronously and asynchronously executes UI code" do
@target = shell {
@red_label = red_label {
text "text1"
}
}
@red_label.async_exec do
expect(@red_label.swt_widget.getText).to eq("text2")
end
# This takes prioerity over async_exec
@red_label.sync_exec do
@red_label.swt_widget.setText("text2")
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer-dsl-swt.rb | lib/glimmer-dsl-swt.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
$LOAD_PATH.unshift(File.expand_path('..', __FILE__))
# External requires
if !['', 'false'].include?(ENV['GLIMMER_BUNDLER_SETUP'].to_s.strip.downcase)
bundler_group = ENV['GLIMMER_BUNDLER_SETUP'].to_s.strip.downcase
bundler_group = 'default' if bundler_group == 'true'
require 'bundler'
Bundler.setup(bundler_group)
end
require 'java'
require 'puts_debuggerer' if ("#{ENV['pd']}#{ENV['PD']}").to_s.downcase.include?('true')
# concurrent-ruby gem ensures glimmer relies on Concurrent data-structure classes
require 'concurrent/array'
require 'concurrent/hash'
require 'concurrent/set'
require 'glimmer'
require 'nested_inherited_jruby_include_package'
require 'super_module'
require 'date'
require 'facets/string/capitalized'
require 'facets/hash/symbolize_keys'
require 'matrix'
# Internal requires
require 'ext/glimmer/config'
require 'ext/glimmer'
require 'glimmer/dsl/swt/dsl'
if defined?(::IRB)
begin
Kernel.send(:remove_method, :y)
rescue
# No Op
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/ext/glimmer.rb | lib/ext/glimmer.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/swt/packages'
module Glimmer
class << self
def included(klass)
if Object.const_defined?(:ActiveSupport) && ActiveSupport.const_defined?(:Dependencies)
begin
ActiveSupport::Dependencies.unhook!
# override activesupport string method implementations if already loaded
gem 'facets'
load 'facets/string/snakecase.rb'
load 'facets/string/titlecase.rb'
load 'facets/string/camelcase.rb'
rescue => e
# noop TODO support logging unimportant details below debug level
end
end
if Config.import_swt_packages
klass.include(SWT::Packages)
klass.extend(SWT::Packages)
end
klass.extend(Glimmer)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/ext/rouge/themes/glimmer.rb | lib/ext/rouge/themes/glimmer.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module Rouge
module Themes
# A port of the pastie style from Pygments.
# See https://bitbucket.org/birkenfeld/pygments-main/src/default/pygments/styles/pastie.py
class Glimmer < Github
name 'glimmer'
style Comment::Single, fg: [106,115,125], italic: true # Also, Comments
style Keyword::Pseudo, fg: [:dark_red]
style Keyword, fg: [:blue]
style Literal::String::Single, fg: [106,115,125] # Also, Comments
style Literal::String::Double, fg: [0,92,197]
style Literal::String::Escape, fg: [:red]
style Literal::Number::Integer, fg: [:blue]
style Literal::String::Interpol, fg: [:blue]
style Literal::String::Symbol, fg: [:dark_green]
style Literal::String, fg: [:dark_blue]
style Name::Builtin, fg: [215,58,73]
style Name::Class, fg: [3,47,98]
style Name::Namespace, fg: [3,47,98]
style Name::Constant, fg: [0,92,197]
style Name::Function, fg: [:blue]
style Name::Variable::Instance, fg: [227,98,9]
style Name, fg: [111,66,193] #purple
style Operator, fg: [:red]
style Punctuation, fg: [:blue]
style Text, fg: [75, 75, 75]
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/ext/rouge/themes/glimmer_dark.rb | lib/ext/rouge/themes/glimmer_dark.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module Rouge
module Themes
# A port of the pastie style from Pygments.
# See https://bitbucket.org/birkenfeld/pygments-main/src/default/pygments/styles/pastie.py
class GlimmerDark < Github
name 'glimmer_dark'
style Comment::Single, fg: [149, 140, 130], italic: true # Also, Comments
style Keyword::Pseudo, fg: [188, 255, 255]
style Keyword::Declaration, fg: [188, 255, 255]
style Keyword, fg: [153, 38, 16], bold: true
style Literal::String::Single, fg: [149, 140, 130] # Also, Comments
style Literal::String::Double, fg: [255, 163, 58]
style Literal::String::Escape, fg: [6, 217, 141]
style Literal::Number::Integer, fg: [153, 38, 16], bold: true
style Literal::String::Interpol, fg: [153, 38, 16], bold: true
style Literal::String::Symbol, fg: [255, 127, 255]
style Literal::String, fg: [163, 215, 252]
style Name::Builtin, fg: [40, 197, 182]
style Name::Class, fg: [252, 208, 157]
style Name::Namespace, fg: [252, 208, 157]
style Name::Constant, fg: [255, 163, 58]
style Name::Function, fg: [153, 38, 16], bold: true
style Name::Variable::Instance, fg: [28, 157, 246]
style Name::Tag, fg: [247, 250, 136]
style Name::Attribute, fg: [255, 127, 127]
style Name, fg: [144, 189, 62] #inverse of purple
style Operator, fg: [6, 217, 141]
style Punctuation, fg: [102, 217, 239]
style Text, fg: [180, 180, 180]
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/ext/glimmer/config.rb | lib/ext/glimmer/config.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/config'
module Glimmer
module Config
DEFAULT_IMPORT_SWT_PACKAGES = [
'org.eclipse.swt',
'org.eclipse.swt.widgets',
'org.eclipse.swt.layout',
'org.eclipse.swt.graphics',
'org.eclipse.swt.browser',
'org.eclipse.swt.custom',
'org.eclipse.swt.dnd',
'org.eclipse.swt.printing',
]
DEFAULT_AUTO_SYNC_EXEC = true
class << self
# Tells Glimmer to import SWT packages into including class (default: true)
def import_swt_packages=(value)
@@import_swt_packages = value
end
# Returns whether Glimmer will import SWT packages into including class
def import_swt_packages
@@import_swt_packages = DEFAULT_IMPORT_SWT_PACKAGES if !defined?(@@import_swt_packages) || (defined?(@@import_swt_packages) && @@import_swt_packages == true)
@@import_swt_packages
end
# Tells Glimmer to avoid automatic use of sync_exec when invoking GUI calls from another thread (default: true)
def auto_sync_exec=(value)
@@auto_sync_exec = value
end
# Returns whether Glimmer will import SWT packages into including class
def auto_sync_exec
@@auto_sync_exec = DEFAULT_AUTO_SYNC_EXEC if !defined?(@@auto_sync_exec)
@@auto_sync_exec
end
alias auto_sync_exec? auto_sync_exec
# allowed logger types are :logger (default) and :logging (logging gem supporting async logging)
# updating logger type value resets logger
def logger_type=(logger_type_class)
@@logger_type = logger_type_class
reset_logger!
end
def logger_type
unless defined? @@logger_type
@@logger_type = :logger
end
@@logger_type
end
# Returns Logging Devices. Default is [:stdout, :syslog]
def logging_devices
unless defined? @@logging_devices
@@logging_devices = [:stdout, :syslog]
end
@@logging_devices
end
# Logging Devices is an array of these possible values: :stdout (default), :stderr, :file, :syslog (default), :stringio
def logging_devices=(devices)
@@logging_devices = devices
reset_logger!
end
def logging_device_file_options
@@logging_device_file_options = {size: 1_000_000, age: 'daily', roll_by: 'number'} unless defined? @@logging_device_file_options
@@logging_device_file_options
end
def logging_device_file_options=(custom_options)
@@logging_device_file_options = custom_options
reset_logger!
end
def logging_appender_options
@@logging_appender_options = {async: true, auto_flushing: 500, write_size: 500, flush_period: 60, immediate_at: [:error, :fatal], layout: logging_layout} unless defined? @@logging_appender_options
# TODO make this a glimmer command option
if ENV['GLIMMER_LOGGER_ASYNC'].to_s.downcase == 'false'
@@logging_appender_options.merge!(async: false, auto_flushing: 1, immediate_at: [:debug, :info, :warn, :error, :fatal])
end
@@logging_appender_options
end
def logging_appender_options=(custom_options)
@@logging_appender_options = custom_options
reset_logger!
end
def logging_layout
unless defined? @@logging_layout
@@logging_layout = Logging.layouts.pattern(
pattern: '[%d] %-5l %c: %m\n',
date_pattern: '%Y-%m-%d %H:%M:%S'
)
end
@@logging_layout
end
def logging_layout=(custom_layout)
@@logging_layout = custom_layout
reset_logger!
end
alias reset_logger_without_glimmer_dsl_swt! reset_logger!
def reset_logger!
if logger_type == :logger
reset_logger_without_glimmer_dsl_swt!
else
require 'logging'
@first_time = !defined?(@@logger)
old_level = logger.level unless @first_time
self.logger = Logging.logger['glimmer'].tap do |logger|
logger.level = old_level || :error
appenders = []
appenders << Logging.appenders.stdout(logging_appender_options) if logging_devices.include?(:stdout)
appenders << Logging.appenders.stderr(logging_appender_options) if logging_devices.include?(:stderr)
if logging_devices.include?(:file)
require 'fileutils'
FileUtils.mkdir_p('log')
appenders << Logging.appenders.rolling_file('log/glimmer.log', logging_appender_options.merge(logging_device_file_options)) if logging_devices.include?(:file)
end
if Object.const_defined?(:Syslog) && logging_devices.include?(:syslog)
Syslog.close if Syslog.opened?
appenders << Logging.appenders.syslog('glimmer', logging_appender_options)
end
logger.appenders = appenders
end
end
end
end
end
end
if ENV['GLIMMER_LOGGER_LEVEL']
if Glimmer::Config.logger_type == :logging
# if glimmer log level is being overridden for debugging purposes, then disable async logging making logging immediate
Glimmer::Config.logging_appender_options = Glimmer::Config.logging_appender_options.merge(async: false, auto_flushing: 1, immediate_at: [:unknown, :debug, :info, :error, :fatal])
Glimmer::Config.logging_devices = [:stdout]
end
begin
puts "Adjusting Glimmer logging level to #{ENV['GLIMMER_LOGGER_LEVEL']}"
Glimmer::Config.logger.level = ENV['GLIMMER_LOGGER_LEVEL'].strip
rescue => e
puts e.message
end
end
Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
method = method_symbol.to_s
return true if method == 'post_initialize_child'
return true if method == 'handle'
return true if method.end_with?('=')
return true if ['drag_source_proxy', 'drop_target_proxy'].include?(method) && is_a?(Glimmer::UI::CustomWidget)
return true if method == 'dispose' && is_a?(Glimmer::UI::CustomWidget) && respond_to?(method)
return true if ['finish_edit!', 'search', 'all_tree_items', 'depth_first_search'].include?(method) && is_a?(Glimmer::UI::CustomWidget) && body_root.respond_to?(method)
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/ui.rb | lib/glimmer/ui.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module Glimmer
module UI
end
GUI = UI # alias
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/rake_task.rb | lib/glimmer/rake_task.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module Glimmer
module RakeTask
RVM_FUNCTION = <<~MULTI_LINE_STRING
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
fi
MULTI_LINE_STRING
end
end
require 'rake'
require_relative 'rake_task/package'
ENV['GLIMMER_LOGGER_ENABLED'] = 'false'
require_relative '../ext/glimmer/config.rb'
require 'puts_debuggerer' if ("#{ENV['pd']}#{ENV['PD']}").to_s.downcase.include?('true')
namespace :glimmer do
desc 'Runs Glimmer app or custom shell gem in the current directory, unless app_path is specified, then runs it instead (app_path is optional)'
task :run, [:app_path] do |t, args|
require_relative 'launcher'
if args[:app_path].nil?
require 'fileutils'
current_directory_name = File.basename(FileUtils.pwd)
assumed_shell_script = File.join('.', 'bin', current_directory_name)
assumed_shell_script = Dir.glob('./bin/*').detect {|f| File.file?(f)} if !File.exist?(assumed_shell_script)
Glimmer::Launcher.new([assumed_shell_script]).launch
else
Glimmer::Launcher.new([args[:app_path]]).launch
end
end
desc 'Brings up the Glimmer Meta-Sample app to allow browsing, running, and viewing code of Glimmer samples'
task :samples do
Glimmer::Launcher.new([File.expand_path('../../../samples/elaborate/meta_sample.rb', __FILE__)]).launch
end
namespace :package do
desc 'Clean by removing "dist" and "packages" directories'
task :clean do
Glimmer::RakeTask::Package.clean
end
desc 'Generate gemspec'
task :gemspec do
Glimmer::RakeTask::Package.gemspec
end
desc 'Generate gem under pkg directory'
task :gem do
Glimmer::RakeTask::Package.gem
end
desc 'Generate JAR config file'
task :config do
Glimmer::RakeTask::Package.config
end
desc 'Generate JAR file'
task :jar do
Glimmer::RakeTask::Package.jar
end
desc 'Lock JARs'
task :lock_jars do
Glimmer::RakeTask::Package.lock_jars
end
desc 'Generate Native files. type can be dmg/pkg on the Mac, msi/exe on Windows, and rpm/deb on Linux (type is optional)'
task :native, [:type] do |t, args|
extra_args = ARGV.partition {|arg| arg.start_with?('package')}.last.to_a.join(' ')
Glimmer::RakeTask::Package.native(args[:type], extra_args)
end
end
desc 'Package app for distribution (generating config, jar, and native files) (type is optional)'
task :package, [:type] do |t, args|
Rake::Task['glimmer:package:gemspec'].execute
Rake::Task['glimmer:package:lock_jars'].execute
Rake::Task['glimmer:package:config'].execute
Rake::Task['glimmer:package:jar'].execute
Rake::Task['glimmer:package:native'].execute(args)
end
desc 'Scaffold Glimmer application directory structure to build a new app'
task :scaffold, [:app_name] do |t, args|
require_relative 'rake_task/scaffold'
Glimmer::RakeTask::Scaffold.app(args[:app_name])
end
namespace :scaffold do
desc 'Scaffold Glimmer::UI::CustomShell subclass (full window view) under app/views (namespace is optional) [alt: scaffold:cs]'
task :customshell, [:name, :namespace] do |t, args|
require_relative 'rake_task/scaffold'
Glimmer::RakeTask::Scaffold.custom_shell(args[:name], args[:namespace])
end
task :cs, [:name, :namespace] => :customshell
task :custom_shell, [:name, :namespace] => :customshell
task :"custom-shell", [:name, :namespace] => :customshell
desc 'Scaffold Glimmer::UI::CustomWidget subclass (part of a view) under app/views (namespace is optional) [alt: scaffold:cw]'
task :customwidget, [:name, :namespace] do |t, args|
require_relative 'rake_task/scaffold'
Glimmer::RakeTask::Scaffold.custom_widget(args[:name], args[:namespace])
end
task :cw, [:name, :namespace] => :customwidget
task :custom_widget, [:name, :namespace] => :customwidget
task :"custom-widget", [:name, :namespace] => :customwidget
desc 'Scaffold Glimmer::UI::CustomShape subclass (part of a view) under app/views (namespace is optional) [alt: scaffold:cp]'
task :customshape, [:name, :namespace] do |t, args|
require_relative 'rake_task/scaffold'
Glimmer::RakeTask::Scaffold.custom_shape(args[:name], args[:namespace])
end
task :cp, [:name, :namespace] => :customshape
task :custom_shape, [:name, :namespace] => :customshape
task :"custom-shape", [:name, :namespace] => :customshape
desc 'Desktopify a web app'
task :desktopify, [:app_name, :website] do |t, args|
require_relative 'rake_task/scaffold'
Glimmer::RakeTask::Scaffold.desktopify(args[:app_name], args[:website])
end
namespace :gem do
desc 'Scaffold Glimmer::UI::CustomShell subclass (full window view) under its own Ruby gem + app project (namespace is required) [alt: scaffold:gem:cs]'
task :customshell, [:name, :namespace] do |t, args|
require_relative 'rake_task/scaffold'
Glimmer::RakeTask::Scaffold.custom_shell_gem(args[:name], args[:namespace])
end
task :cs, [:name, :namespace] => :customshell
task :custom_shell, [:name, :namespace] => :customshell
task :"custom-shell", [:name, :namespace] => :customshell
desc 'Scaffold Glimmer::UI::CustomWidget subclass (part of a view) under its own Ruby gem project (namespace is required) [alt: scaffold:gem:cw]'
task :customwidget, [:name, :namespace] do |t, args|
require_relative 'rake_task/scaffold'
Glimmer::RakeTask::Scaffold.custom_widget_gem(args[:name], args[:namespace])
end
task :cw, [:name, :namespace] => :customwidget
task :custom_widget, [:name, :namespace] => :customwidget
task :"custom-widget", [:name, :namespace] => :customwidget
desc 'Scaffold Glimmer::UI::CustomShape subclass (part of a view) under its own Ruby gem project (namespace is required) [alt: scaffold:gem:cp]'
task :customshape, [:name, :namespace] do |t, args|
require_relative 'rake_task/scaffold'
Glimmer::RakeTask::Scaffold.custom_shape_gem(args[:name], args[:namespace])
end
task :cp, [:name, :namespace] => :customshape
task :custom_shape, [:name, :namespace] => :customshape
task :"custom-shape", [:name, :namespace] => :customshape
end
# legacy support
task :custom_shell_gem, [:name, :namespace] => 'gem:customshell'
task :custom_widget_gem, [:name, :namespace] => 'gem:customwidget'
task :custom_shape_gem, [:name, :namespace] => 'gem:customshape'
end
namespace :list do
task :list_require do
require_relative 'rake_task/list'
end
namespace :gems do
desc 'List Glimmer custom widget gems available at rubygems.org (query is optional) [alt: list:gems:cw]'
task :customwidget, [:query] => :list_require do |t, args|
Glimmer::RakeTask::List.custom_widget_gems(args[:query])
end
task :cw, [:query] => :customwidget
task :custom_widget, [:query] => :customwidget
task :"custom-widget", [:query] => :customwidget
desc 'List Glimmer custom shell gems available at rubygems.org (query is optional) [alt: list:gems:cs]'
task :customshell, [:query] => :list_require do |t, args|
Glimmer::RakeTask::List.custom_shell_gems(args[:query])
end
task :cs, [:query] => :customshell
task :custom_shell, [:query] => :customshell
task :"custom-shell", [:query] => :customshell
desc 'List Glimmer custom shape gems available at rubygems.org (query is optional) [alt: list:gems:cp]'
task :customshape, [:query] => :list_require do |t, args|
Glimmer::RakeTask::List.custom_shape_gems(args[:query])
end
task :cp, [:query] => :customshape
task :custom_shape, [:query] => :customshape
task :"custom-shape", [:query] => :customshape
desc 'List Glimmer DSL gems available at rubygems.org (query is optional)'
task :dsl, [:query] => :list_require do |t, args|
Glimmer::RakeTask::List.dsl_gems(args[:query])
end
end
# legacy support
task :custom_shell_gems, [:name, :namespace] => 'gems:customshell'
task :custom_widget_gems, [:name, :namespace] => 'gems:customwidget'
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/launcher.rb | lib/glimmer/launcher.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
if ARGV.include?('--bundler') && File.exist?(File.expand_path('./Gemfile'))
require 'bundler'
Bundler.setup(:default)
end
require 'fileutils'
require 'os'
module Glimmer
# Launcher of glimmer applications and main entry point for the `glimmer` command.
class Launcher
OPERATING_SYSTEMS_SUPPORTED = ["mac", "windows", "linux"]
# TODO convert to a bash script to achieve faster startup time
TEXT_USAGE = <<~MULTI_LINE_STRING
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v#{File.read(File.expand_path('../../../VERSION', __FILE__))}
Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args])
Runs Glimmer applications and tasks.
When applications are specified, they are run using JRuby,
automatically preloading the glimmer Ruby gem and SWT jar dependency.
Optionally, extra Glimmer options, JRuby options, and/or environment variables may be passed in.
Glimmer options:
- "--bundler=GROUP" : Activates gems in Bundler default group in Gemfile
- "--pd=BOOLEAN" : Requires puts_debuggerer to enable pd method
- "--quiet=BOOLEAN" : Does not announce file path of Glimmer application being launched
- "--debug" : Displays extra debugging information, passes "--debug" to JRuby, and enables debug logging
- "--log-level=VALUE" : Sets Glimmer's Ruby logger level ("ERROR" / "WARN" / "INFO" / "DEBUG"; default is none)
Tasks are run via rake. Some tasks take arguments in square brackets.
Available tasks are below (if you do not see any, please add `require 'glimmer/rake_task'` to Rakefile and rerun or run rake -T):
MULTI_LINE_STRING
GLIMMER_LIB_LOCAL = File.expand_path(File.join('lib', 'glimmer-dsl-swt.rb'))
GLIMMER_LIB_GEM = 'glimmer-dsl-swt'
GLIMMER_OPTIONS = %w[--log-level --quiet --bundler --pd]
GLIMMER_OPTION_ENV_VAR_MAPPING = {
'--log-level' => 'GLIMMER_LOGGER_LEVEL' ,
'--bundler' => 'GLIMMER_BUNDLER_SETUP' ,
'--pd' => 'PD' ,
}
REGEX_RAKE_TASK_WITH_ARGS = /^([^\[]+)\[?([^\]]*)\]?$/
class << self
def platform_os
OPERATING_SYSTEMS_SUPPORTED.detect {|os| OS.send("#{os}?")}
end
def is_arm64?
host_cpu = OS.host_cpu.downcase
host_cpu.include?('aarch64') || host_cpu.include?('arm')
end
def special_cpu_architecture_suffix
is_arm64? ? "_aarch64" : ''
end
def swt_jar_file
@swt_jar_file ||= File.expand_path(File.join(__FILE__, '..', '..', '..', 'vendor', 'swt', platform_os + special_cpu_architecture_suffix, 'swt.jar'))
end
def jruby_os_specific_options
OS.mac? ? "-J-XstartOnFirstThread" : ""
end
def glimmer_lib
unless @glimmer_lib
@glimmer_lib = GLIMMER_LIB_GEM
if File.exists?(GLIMMER_LIB_LOCAL)
@glimmer_lib = GLIMMER_LIB_LOCAL
puts "[DEVELOPMENT MODE] (detected #{@glimmer_lib})"
end
end
@glimmer_lib
end
def dev_mode?
glimmer_lib == GLIMMER_LIB_LOCAL
end
def glimmer_option_env_vars(glimmer_options)
GLIMMER_OPTION_ENV_VAR_MAPPING.reduce({}) do |hash, pair|
glimmer_options[pair.first] ? hash.merge(GLIMMER_OPTION_ENV_VAR_MAPPING[pair.first] => glimmer_options[pair.first]) : hash
end
end
def load_env_vars(env_vars)
env_vars.each do |key, value|
ENV[key] = value
end
end
def launch(application, jruby_options: [], env_vars: {}, glimmer_options: {})
jruby_options_string = jruby_options.join(' ') + ' ' if jruby_options.any?
env_vars = env_vars.merge(glimmer_option_env_vars(glimmer_options))
env_vars.each do |k,v|
ENV[k] = v
end
the_glimmer_lib = glimmer_lib
require 'puts_debuggerer' if the_glimmer_lib == GLIMMER_LIB_LOCAL
is_rake_task = !application.end_with?('.rb')
rake_tasks = []
if is_rake_task
load File.expand_path('./Rakefile') if File.exist?(File.expand_path('./Rakefile')) && caller.join("\n").include?('/bin/glimmer:')
require_relative 'rake_task'
rake_tasks = Rake.application.tasks.map(&:to_s).map {|t| t.sub('glimmer:', '')}
# handle a bash quirk with calling package[msi] while there is a "packages" directory locally (it passes package[msi] as packages)
application = 'package[msi]' if application == 'packages'
potential_rake_task_parts = application.match(REGEX_RAKE_TASK_WITH_ARGS)
application = potential_rake_task_parts[1]
rake_task_args = potential_rake_task_parts[2].split(',')
end
if rake_tasks.include?(application)
load_env_vars(glimmer_option_env_vars(glimmer_options))
rake_task = "glimmer:#{application}"
puts "Running Glimmer rake task: #{rake_task}" if jruby_options_string.to_s.include?('--debug')
Rake::Task[rake_task].invoke(*rake_task_args)
else
puts "Launching Glimmer Application: #{application}" if jruby_options_string.to_s.include?('--debug') || glimmer_options['--quiet'].to_s.downcase != 'true'
require the_glimmer_lib
load File.expand_path(application)
end
end
end
attr_reader :application_paths
attr_reader :env_vars
attr_reader :glimmer_options
attr_reader :jruby_options
def initialize(raw_options)
raw_options << '--quiet' if !caller.join("\n").include?('/bin/glimmer:') && !raw_options.join.include?('--quiet=')
raw_options << '--log-level=DEBUG' if raw_options.join.include?('--debug') && !raw_options.join.include?('--log-level=')
@application_path = extract_application_path(raw_options)
@env_vars = extract_env_vars(raw_options)
@glimmer_options = extract_glimmer_options(raw_options)
@jruby_options = raw_options
end
def launch
if @application_path.nil?
display_usage
else
launch_application
end
end
private
def launch_application
self.class.launch(
@application_path,
jruby_options: @jruby_options,
env_vars: @env_vars,
glimmer_options: @glimmer_options
)
end
def display_usage
puts TEXT_USAGE
display_tasks
end
def display_tasks
if OS.windows? || Launcher.is_arm64?
require 'rake'
Rake::TaskManager.record_task_metadata = true
require_relative 'rake_task'
tasks = Rake.application.tasks
task_lines = tasks.reject do |task|
task.comment.nil?
end.map do |task|
max_task_size = tasks.map(&:name_with_args).map(&:size).max + 1
task_name = task.name_with_args.sub('glimmer:', '')
line = "glimmer #{task_name.ljust(max_task_size)} # #{task.comment}"
end
puts task_lines.to_a
else
require 'rake-tui'
require 'tty-screen'
require_relative 'rake_task'
Rake::TUI.run(branding_header: nil, prompt_question: 'Select a Glimmer task to run:') do |task, tasks|
max_task_size = tasks.map(&:name_with_args).map(&:size).max + 1
task_name = task.name_with_args.sub('glimmer:', '')
line = "glimmer #{task_name.ljust(max_task_size)} # #{task.comment}"
bound = TTY::Screen.width - 6
line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
end
end
end
# Extract application path (which can also be a rake task, basically a non-arg)
def extract_application_path(options)
application_path = options.detect do |option|
!option.start_with?('-') && !option.include?('=')
end.tap do
options.delete(application_path)
end
end
def extract_env_vars(options)
options.select do |option|
!option.start_with?('-') && option.include?('=')
end.each do |env_var|
options.delete(env_var)
end.reduce({}) do |hash, env_var_string|
match = env_var_string.match(/^([^=]+)=(.+)$/)
hash.merge(match[1] => match[2])
end
end
def extract_glimmer_options(options)
options.select do |option|
GLIMMER_OPTIONS.reduce(false) do |result, glimmer_option|
result || option.include?(glimmer_option)
end
end.each do |glimmer_option|
options.delete(glimmer_option)
end.reduce({}) do |hash, glimmer_option_string|
match = glimmer_option_string.match(/^([^=]+)=?(.+)?$/)
hash.merge(match[1] => (match[2] || 'true'))
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/util/proc_tracker.rb | lib/glimmer/util/proc_tracker.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'delegate'
module Glimmer
module Util
class ProcTracker < DelegateClass(Proc)
def initialize(proc)
super(proc)
end
def call(*args)
__getobj__.call(*args)
@called = true
end
def called?
!!@called
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/exec_expression.rb | lib/glimmer/dsl/swt/exec_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/top_level_expression'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
# Mixin for common code in async_exec and sync_exec expressions
# Uses name in subclass to auto-derive exec_operation
module ExecExpression
include TopLevelExpression
def exec_operation
@exec_operation ||= self.class.name.split(/::/).last.sub(/Expression$/, '').underscore
end
def can_interpret?(parent, keyword, *args, &block)
keyword == exec_operation and
block_given?
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::DisplayProxy.instance.send(exec_operation, *args) do |*args|
begin
block.call(*args)
rescue => e
Glimmer::Config.logger.error {e.full_message}
end
end
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/image_expression.rb | lib/glimmer/dsl/swt/image_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/image_proxy'
require 'glimmer/swt/widget_proxy'
module Glimmer
module DSL
module SWT
# image expression
# Note: Cannot be a static expression because it clashes with image property expression
class ImageExpression < Expression
include TopLevelExpression
include ParentExpression
def can_interpret?(parent, keyword, *args, &block)
options = args.last.is_a?(Hash) ? args.last : {}
(keyword == 'image') and
(!args.empty?) and
(
options.keys.include?(:top_level) or
(
!parent.is_a?(Glimmer::SWT::Custom::Shape) and
(parent.nil? or parent.respond_to?('image=') or args.first.is_a?(Numeric))
)
)
end
def interpret(parent, keyword, *args, &block)
options = args.last.is_a?(Hash) ? args.last : {}
coordinate_args = args.size == (options.empty? ? 2 : 3)
args.unshift(parent) unless parent.nil? || options[:top_level]
@create_pixel_by_pixel = coordinate_args && block&.parameters&.count == 2
if @create_pixel_by_pixel
Glimmer::SWT::ImageProxy.create_pixel_by_pixel(*args, &block)
else
Glimmer::SWT::ImageProxy.create(*args, &block)
end
end
def add_content(parent, keyword, *args, &block)
return if @create_pixel_by_pixel || block&.parameters&.count == 2
super
parent.post_add_content
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/auto_exec_expression.rb | lib/glimmer/dsl/swt/auto_exec_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/swt/exec_expression'
module Glimmer
module DSL
module SWT
# Automatically executes code block against the SWT Event Loop
# with sync_exec if needed (inside a thread other than GUI thread)
# to manipulate SWT UI objects on the UI thread safely
class AutoExecExpression < StaticExpression
include ExecExpression
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/pixel_expression.rb | lib/glimmer/dsl/swt/pixel_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/swt/swt_proxy'
require 'glimmer/swt/custom/shape'
require 'glimmer/swt/custom/drawable'
module Glimmer
module DSL
module SWT
class PixelExpression < StaticExpression
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::Custom::Shape.new(parent, 'pixel', *args, &block)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/dnd_expression.rb | lib/glimmer/dsl/swt/dnd_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/swt/dnd_proxy'
# TODO consider turning static keywords like bind into methods
module Glimmer
module DSL
module SWT
# Responsible for returning DND constant values
#
# Named DndExpression (not DNDExpression) so that the DSL engine
# discovers quickly by convention
class DndExpression < StaticExpression
def can_interpret?(parent, keyword, *args, &block)
block.nil? &&
args.size > 0
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::DNDProxy[*args]
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/rgba_expression.rb | lib/glimmer/dsl/swt/rgba_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/swt/color_expression'
require 'glimmer/swt/color_proxy'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
class RgbaExpression < ColorExpression
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/menu_expression.rb | lib/glimmer/dsl/swt/menu_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer'
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/menu_proxy'
module Glimmer
module DSL
module SWT
class MenuExpression < StaticExpression
include ParentExpression
include_package 'org.eclipse.swt.widgets'
def can_interpret?(parent, keyword, *args, &block)
initial_condition = (keyword == 'menu')
if initial_condition
if parent.respond_to?(:swt_widget)
return true
else
raise Glimmer::Error, "menu may only be nested under a widget (like shell or another menu)!"
end
end
false
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::MenuProxy.new(parent, args)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/shine_data_binding_expression.rb | lib/glimmer/dsl/swt/shine_data_binding_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/shine_data_binding_expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/widget_binding'
require 'glimmer/swt/display_proxy'
require 'glimmer/data_binding/shine'
module Glimmer
module DSL
module SWT
class ShineDataBindingExpression < Glimmer::DSL::ShineDataBindingExpression
include_package 'org.eclipse.swt.widgets'
def can_interpret?(parent, keyword, *args, &block)
super and
(
(parent.respond_to?(:has_attribute?) and parent.has_attribute?(keyword)) or
(parent.respond_to?(:swt_widget) and (parent.swt_widget.is_a?(Table) or parent.swt_widget.is_a?(Tree)))
) and
!(parent.respond_to?(:swt_widget) && parent.swt_widget.class == org.eclipse.swt.widgets.Canvas && keyword == 'image')
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/sync_exec_expression.rb | lib/glimmer/dsl/swt/sync_exec_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/swt/exec_expression'
module Glimmer
module DSL
module SWT
# Synchronously executes code block against the SWT Event Loop
# to manipulate SWT UI objects on the UI thread safely with
# immediate priority when needed.
class SyncExecExpression < StaticExpression
include ExecExpression
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/color_expression.rb | lib/glimmer/dsl/swt/color_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/swt/color_proxy'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
class ColorExpression < StaticExpression
include TopLevelExpression
include_package 'org.eclipse.swt.widgets'
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::ColorProxy.create(*args)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/tray_expression.rb | lib/glimmer/dsl/swt/tray_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/display_proxy'
require 'glimmer/swt/tray_proxy'
module Glimmer
module DSL
module SWT
class TrayExpression < StaticExpression
include ParentExpression
def can_interpret?(parent, keyword, *args, &block)
super && parent.is_a?(Glimmer::SWT::DisplayProxy) && args.empty?
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::TrayProxy.instance
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/message_box_expression.rb | lib/glimmer/dsl/swt/message_box_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/shell_proxy'
require 'glimmer/swt/message_box_proxy'
require 'glimmer/swt/swt_proxy'
module Glimmer
module DSL
module SWT
class MessageBoxExpression < StaticExpression
include TopLevelExpression
include ParentExpression
include_package 'org.eclipse.swt.widgets'
def interpret(parent, keyword, *args, &block)
potential_parent = args.first
potential_parent = potential_parent.swt_widget if potential_parent.respond_to?(:swt_widget)
parent = nil
if potential_parent.is_a?(Shell)
args.shift
parent = potential_parent
elsif potential_parent.is_a?(Widget)
args.shift
parent = potential_parent.shell
end
Glimmer::SWT::MessageBoxProxy.new(parent, Glimmer::SWT::SWTProxy[args])
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/tray_item_expression.rb | lib/glimmer/dsl/swt/tray_item_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/display_proxy'
require 'glimmer/swt/tray_proxy'
require 'glimmer/swt/tray_item_proxy'
module Glimmer
module DSL
module SWT
class TrayItemExpression < StaticExpression
include ParentExpression
include_package 'org.eclipse.swt.widgets'
def can_interpret?(parent, keyword, *args, &block)
super and
parent.swt_widget.is_a?(Shell) and
args.empty?
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::TrayItemProxy.new(parent, *args)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/custom_shape_expression.rb | lib/glimmer/dsl/swt/custom_shape_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer'
require 'glimmer/dsl/expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/ui/custom_shape'
require 'glimmer/swt/custom/code_text'
require 'glimmer/swt/custom/checkbox_group'
module Glimmer
module DSL
module SWT
class CustomShapeExpression < Expression
# TODO Make custom shapes automatically generate static expressions
include ParentExpression
include TopLevelExpression
def can_interpret?(parent, keyword, *args, &block)
!!UI::CustomShape.for(keyword)
end
def interpret(parent, keyword, *args, &block)
options = args.last.is_a?(Hash) ? args.pop : {}
UI::CustomShape.for(keyword).new(parent, *args, options, &block).tap do |new_custom_shape|
new_custom_shape.body_root.paint_pixel_by_pixel(&block) if block&.parameters&.count == 2
end
end
def add_content(parent, keyword, *args, &block)
# TODO consider avoiding source_location
return if block&.parameters&.count == 2
if block.source_location == parent.content&.__getobj__.source_location
parent.content.call(parent) unless parent.content.called?
else
super
end
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb | lib/glimmer/dsl/swt/table_items_data_binding_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/table_items_binding'
module Glimmer
module DSL
module SWT
#Depends on BindCommandHandler and TableColumnPropertiesDataBindingCommandHandler
class TableItemsDataBindingExpression < Expression
include_package 'org.eclipse.swt.widgets'
def can_interpret?(parent, keyword, *args, &block)
keyword == "items" and
block.nil? and
parent.respond_to?(:swt_widget) and
parent.swt_widget.is_a?(Table) and
args.size.between?(1, 2) and
args[0].is_a?(DataBinding::ModelBinding) and
args[0].evaluate_property.is_a?(Array) and
(args[1].nil? or args[1].is_a?(Array))
end
def interpret(parent, keyword, *args, &block)
model_binding = args[0]
column_properties = args[1]
DataBinding::TableItemsBinding.new(parent, model_binding, column_properties)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/tree_properties_expression.rb | lib/glimmer/dsl/swt/tree_properties_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/tree_items_binding'
module Glimmer
module DSL
module SWT
# Responsible for providing a readable keyword (command symbol) to capture
# and return tree properties for use in TreeItemsDataBindingCommandHandler
class TreePropertiesExpression < StaticExpression
include_package 'org.eclipse.swt.widgets'
def can_interpret?(parent, keyword, *args, &block)
keyword == "tree_properties" and
block.nil? and
parent.respond_to?(:swt_widget) and
parent.swt_widget.is_a?(Tree)
end
def interpret(parent, keyword, *args, &block)
args
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/dialog_expression.rb | lib/glimmer/dsl/swt/dialog_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/shell_proxy'
require 'glimmer/swt/dialog_proxy'
module Glimmer
module DSL
module SWT
class DialogExpression < Expression
include TopLevelExpression
include ParentExpression
def can_interpret?(parent, keyword, *args, &block)
(
(keyword == 'dialog') or
(keyword.to_s.end_with?('dialog') and Glimmer::SWT::DialogProxy.dialog_class(keyword))
) and
(parent.nil? or parent.is_a?(org.eclipse.swt.widgets.Shell) or parent.is_a?(Glimmer::SWT::ShellProxy))
end
def interpret(parent, keyword, *args, &block)
# TODO reconcile this with the actual org.eclipse.swt.widgets.Dialog widget (maybe rename this as dialog_shell)
if keyword == 'dialog'
args = [parent] + args unless parent.nil?
args += [:dialog_trim, :application_modal]
Glimmer::SWT::ShellProxy.new(*args)
else
args = [parent] + args unless parent.nil?
Glimmer::SWT::DialogProxy.new(keyword, *args)
end
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/shell_expression.rb | lib/glimmer/dsl/swt/shell_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/shell_proxy'
module Glimmer
module DSL
module SWT
class ShellExpression < StaticExpression
include TopLevelExpression
include ParentExpression
def can_interpret?(parent, keyword, *args, &block)
super and
(parent.nil? or parent.is_a?(Glimmer::SWT::ShellProxy))
end
def interpret(parent, keyword, *args, &block)
args = [parent] + args unless parent.nil?
Glimmer::SWT::ShellProxy.new(*args)
end
end
class WindowExpression < ShellExpression
# Alias
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/block_property_expression.rb | lib/glimmer/dsl/swt/block_property_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
module Glimmer
module DSL
module SWT
class BlockPropertyExpression < Expression
def can_interpret?(parent, keyword, *args, &block)
block_given? and
args.size == 0 and
parent.respond_to?("#{keyword}_block=")
end
def interpret(parent, keyword, *args, &block)
parent.send("#{keyword}_block=", block)
nil
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/property_expression.rb | lib/glimmer/dsl/swt/property_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/swt/transform_proxy'
module Glimmer
module DSL
module SWT
class PropertyExpression < Expression
def can_interpret?(parent, keyword, *args, &block)
block.nil? and
(args.size > 0 || parent.is_a?(Glimmer::SWT::TransformProxy)) and
parent.respond_to?(:set_attribute) and
parent.respond_to?(:has_attribute?) and
parent.has_attribute?(keyword, *args) and
!(parent.respond_to?(:swt_widget) && parent.swt_widget.class == org.eclipse.swt.widgets.Canvas && keyword == 'image')
end
def interpret(parent, keyword, *args, &block)
parent.set_attribute(keyword, *args)
parent
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/cursor_expression.rb | lib/glimmer/dsl/swt/cursor_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/swt/cursor_proxy'
module Glimmer
module DSL
module SWT
# cursor expression
# Note: Cannot be a static expression because it clashes with cursor property expression
class CursorExpression < Expression
def can_interpret?(parent, keyword, *args, &block)
keyword.to_s == 'cursor' and
(parent.nil? or !parent.respond_to?('cursor')) and
args.size == 1 and
(args.first.is_a?(Integer) or textual?(args.first))
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::CursorProxy.new(*args)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb | lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/widget_binding'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
class RadioGroupSelectionDataBindingExpression < Expression
def can_interpret?(parent, keyword, *args, &block)
keyword == 'selection' and
block.nil? and
(parent.is_a?(Glimmer::SWT::Custom::RadioGroup) or (parent.is_a?(Glimmer::UI::CustomWidget) and parent.body_root.is_a?(Glimmer::SWT::Custom::RadioGroup)) ) and
args.size == 1 and
args[0].is_a?(DataBinding::ModelBinding) and
args[0].evaluate_options_property.is_a?(Array)
end
def interpret(parent, keyword, *args, &block)
model_binding = args[0]
#TODO make this options observer dependent and all similar observers in widget specific data binding handlers
# TODO consider delegating some of this work
widget_binding = DataBinding::WidgetBinding.new(parent, 'items', sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
widget_binding.call(model_binding.evaluate_options_property)
model = model_binding.base_model
widget_binding.observe(model, model_binding.options_property_name)
widget_binding = DataBinding::WidgetBinding.new(parent, 'selection', sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
widget_binding.call(model_binding.evaluate_property)
widget_binding.observe(model_binding)
raise(Glimmer::Error, "No radios found! Make sure radio selection is data-bound to a property having property_options as non-empty array!") if parent.get_items.empty?
Glimmer::SWT::DisplayProxy.instance.auto_exec(override_sync_exec: model_binding.binding_options[:sync_exec], override_async_exec: model_binding.binding_options[:async_exec]) do
parent.on_widget_selected do
model_binding.call(widget_binding.evaluate_property)
end
end
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/custom_widget_expression.rb | lib/glimmer/dsl/swt/custom_widget_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer'
require 'glimmer/dsl/expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/ui/custom_widget'
require 'glimmer/ui/custom_shell'
require 'glimmer/swt/custom/code_text'
require 'glimmer/swt/custom/refined_table'
require 'glimmer/swt/custom/radio_group'
require 'glimmer/swt/custom/checkbox_group'
module Glimmer
module DSL
module SWT
class CustomWidgetExpression < Expression
# TODO Make custom widgets automatically generate static expressions
include ParentExpression
include TopLevelExpression
def can_interpret?(parent, keyword, *args, &block)
custom_widget_class = UI::CustomWidget.for(keyword)
custom_widget_class and
(parent.respond_to?(:swt_widget) or
custom_widget_class.ancestors.include?(UI::CustomShell))
end
def interpret(parent, keyword, *args, &block)
options = args.last.is_a?(Hash) ? args.pop : {}
UI::CustomWidget.for(keyword).new(parent, *args, options, &block).tap do |new_custom_widget|
new_custom_widget.body_root.paint_pixel_by_pixel(&block) if block&.parameters&.count == 2
end
end
def add_content(parent, keyword, *args, &block)
# TODO consider avoiding source_location
return if block&.parameters&.count == 2
if block.source_location == parent.content&.__getobj__&.source_location
parent.content.call(parent) unless parent.content.called?
else
super
end
parent.post_add_content
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/expand_item_expression.rb | lib/glimmer/dsl/swt/expand_item_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer'
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/widget_proxy'
require 'glimmer/swt/expand_item_proxy'
module Glimmer
module DSL
module SWT
class ExpandItemExpression < StaticExpression
include ParentExpression
include_package 'org.eclipse.swt.widgets'
def can_interpret?(parent, keyword, *args, &block)
initial_condition = (keyword == 'expand_item') and parent.respond_to?(:swt_widget)
if initial_condition
if parent.swt_widget.is_a?(ExpandBar)
return true
else
Glimmer::Config.logger.error {"expand_item widget may only be used directly under a expand_bar widget!"}
end
end
false
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::ExpandItemProxy.new(parent, args)
end
def add_content(parent, keyword, *args, &block)
super
parent.post_add_content
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/multiply_expression.rb | lib/glimmer/dsl/swt/multiply_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/transform_proxy'
module Glimmer
module DSL
module SWT
# Special treatment for transform {multiply(){} } operation
class MultiplyExpression < Expression
include ParentExpression
def can_interpret?(parent, keyword, *args, &block)
(
keyword == 'multiply' or
keyword == 'multiplication'
) and
parent.is_a?(Glimmer::SWT::TransformProxy)
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::TransformProxy.new(parent, *args, multiply: true)
end
def add_content(parent, keyword, *args, &block)
super
parent.post_add_content
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/observe_expression.rb | lib/glimmer/dsl/swt/observe_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/dsl/observe_expression'
require 'glimmer/ui/custom_widget'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
class ObserveExpression < StaticExpression
include TopLevelExpression
include Glimmer::DSL::ObserveExpression
def interpret(parent, keyword, *args, &block)
observer_registration = super
Glimmer::SWT::DisplayProxy.current_custom_widgets_and_shapes.last&.observer_registrations&.push(observer_registration)
observer_registration
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/layout_data_expression.rb | lib/glimmer/dsl/swt/layout_data_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer'
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/layout_data_proxy'
# TODO consider turning static keywords like layout_data into methods
module Glimmer
module DSL
module SWT
class LayoutDataExpression < StaticExpression
include ParentExpression
def can_interpret?(parent, keyword, *args, &block)
super and
parent.respond_to?(:swt_widget)
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::LayoutDataProxy.new(parent, args)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/data_binding_expression.rb | lib/glimmer/dsl/swt/data_binding_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/widget_binding'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
# Responsible for wiring two-way data-binding for text and selection properties
# on Text, Button, and Spinner widgets.
# Does so by using the output of the bind(model, property) command in the form
# of a ModelBinding, which is then connected to an anonymous widget observer
# (aka widget_data_binder as per widget_data_binders array)
#
# Depends on BindExpression
class DataBindingExpression < Expression
def can_interpret?(parent, keyword, *args, &block)
args.size == 1 and
args[0].is_a?(DataBinding::ModelBinding)
end
def interpret(parent, keyword, *args, &block)
model_binding = args[0]
widget_binding = DataBinding::WidgetBinding.new(parent, keyword, sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
widget_binding.call(model_binding.evaluate_property)
#TODO make this options observer dependent and all similar observers in widget specific data binding handlers
widget_binding.observe(model_binding)
# TODO simplify this logic and put it where it belongs
parent.add_observer(model_binding, keyword) if parent.respond_to?(:add_observer, [model_binding, keyword])
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/dsl.rb | lib/glimmer/dsl/swt/dsl.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/launcher'
require ENV['SWT_JAR_FILE_PATH'] || "#{Glimmer::Launcher.swt_jar_file}"
require 'glimmer/dsl/engine'
Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f}
# Glimmer DSL expression configuration module
#
# When DSL engine interprets an expression, it attempts to handle
# with expressions listed here in the order specified.
# Every expression has a corresponding Expression subclass
# in glimmer/dsl
module Glimmer
module DSL
module SWT
Engine.add_dynamic_expressions(
SWT,
%w[
layout
listener
combo_selection_data_binding
checkbox_group_selection_data_binding
radio_group_selection_data_binding
list_selection_data_binding
tree_items_data_binding
table_items_data_binding
data_binding
cursor
font
image
multiply
property
shine_data_binding
block_property
dialog
widget
custom_widget
shape
custom_shape
]
)
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/transform_expression.rb | lib/glimmer/dsl/swt/transform_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/custom/shape'
require 'glimmer/swt/transform_proxy'
module Glimmer
module DSL
module SWT
class TransformExpression < StaticExpression
include TopLevelExpression
include ParentExpression
def can_interpret?(parent, keyword, *args, &block)
super and
(parent.nil? or parent.is_a?(Glimmer::SWT::Custom::Shape) or parent.is_a?(Glimmer::UI::CustomShape))
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::TransformProxy.new(parent, *args)
end
def add_content(parent, keyword, *args, &block)
super
parent.post_add_content
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb | lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/widget_binding'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
class ComboSelectionDataBindingExpression < Expression
include_package 'org.eclipse.swt.widgets'
include_package 'org.eclipse.swt.custom'
def can_interpret?(parent, keyword, *args, &block)
keyword == 'selection' and
block.nil? and
parent.respond_to?(:swt_widget) and
(parent.swt_widget.is_a?(Combo) || parent.swt_widget.is_a?(CCombo)) and
args.size == 1 and
args[0].is_a?(DataBinding::ModelBinding) and
args[0].evaluate_options_property.is_a?(Array)
end
def interpret(parent, keyword, *args, &block)
model_binding = args[0]
#TODO make this options observer dependent and all similar observers in widget specific data binding handlers
# TODO consider delegating some of this work
widget_binding = DataBinding::WidgetBinding.new(parent, 'items', sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
widget_binding.call(model_binding.evaluate_options_property)
widget_binding.observe(model_binding.model, model_binding.options_property_name)
widget_binding = DataBinding::WidgetBinding.new(parent, 'text', sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
widget_binding.call(model_binding.evaluate_property)
widget_binding.observe(model_binding)
Glimmer::SWT::DisplayProxy.instance.auto_exec(override_sync_exec: model_binding.binding_options[:sync_exec], override_async_exec: model_binding.binding_options[:async_exec]) do
parent.on_widget_selected do
model_binding.call(widget_binding.evaluate_property)
end
parent.on_modify_text do
model_binding.call(widget_binding.evaluate_property)
end
end
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/listener_expression.rb | lib/glimmer/dsl/swt/listener_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/swt/display_proxy'
require 'glimmer/swt/custom/shape'
require 'glimmer/ui/custom_shape'
module Glimmer
module DSL
module SWT
# Widget, Shape, and Display listener experssion
class ListenerExpression < Expression
def can_interpret?(parent, keyword, *args, &block)
Glimmer::Config.logger.debug {"keyword starts with on_: #{keyword.start_with?('on_')}"}
return false unless keyword.start_with?('on_')
proper_parent = parent.respond_to?(:swt_widget) || parent.is_a?(Glimmer::SWT::DisplayProxy) || parent.is_a?(Glimmer::SWT::Custom::Shape) || parent.is_a?(Glimmer::UI::CustomShape)
Glimmer::Config.logger.debug {"parent #{parent} is a widget, shape, or display: #{proper_parent}"}
return false unless proper_parent
Glimmer::Config.logger.debug {"block exists?: #{!block.nil?}"}
raise Glimmer::Error, "Listener is missing block for keyword: #{keyword}" unless block_given?
Glimmer::Config.logger.debug {"args are empty?: #{args.empty?}"}
raise Glimmer::Error, "Invalid listener arguments for keyword: #{keyword}(#{args})" unless args.empty?
result = parent.can_handle_observation_request?(keyword)
Glimmer::Config.logger.debug {"can add listener? #{result}"}
raise Glimmer::Error, "Invalid listener keyword: #{keyword}" unless result
true
end
def interpret(parent, keyword, *args, &block)
parent.handle_observation_request(keyword, &block)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/animation_expression.rb | lib/glimmer/dsl/swt/animation_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/custom/animation'
module Glimmer
module DSL
module SWT
class AnimationExpression < StaticExpression
include ParentExpression
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::Custom::Animation.new(parent)
end
def add_content(parent, keyword, *args, &block)
super
parent.post_add_content
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/bind_expression.rb | lib/glimmer/dsl/swt/bind_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/bind_expression'
module Glimmer
module DSL
module SWT
# Responsible for setting up the return value of the bind keyword (command symbol)
# as a ModelBinding. It is then used by another command handler like
# DataBindingCommandHandler for text and selection properties on Text and Spinner
# or TableItemsDataBindingCommandHandler for items in a Table
class BindExpression < StaticExpression
include Glimmer::DSL::BindExpression
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/swt_expression.rb | lib/glimmer/dsl/swt/swt_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/swt/swt_proxy'
# TODO consider turning static keywords like bind into methods
module Glimmer
module DSL
module SWT
# Responsible for returning SWT constant values
#
# Named SwtExpression (not SWTExpression) so that the DSL engine
# discovers quickly by convention
class SwtExpression < StaticExpression
def can_interpret?(parent, keyword, *args, &block)
block.nil? &&
args.size > 0
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::SWTProxy[*args]
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/shape_expression.rb | lib/glimmer/dsl/swt/shape_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/swt_proxy'
require 'glimmer/swt/custom/shape'
require 'glimmer/swt/custom/drawable'
module Glimmer
module DSL
module SWT
class ShapeExpression < Expression
include ParentExpression
def can_interpret?(parent, keyword, *args, &block)
# TODO support CustomShape parent as well
(parent.is_a?(Glimmer::SWT::Custom::Drawable) or parent.is_a?(Glimmer::SWT::Custom::Shape)) and
Glimmer::SWT::Custom::Shape.valid?(parent, keyword, *args, &block)
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::Custom::Shape.create(parent, keyword, *args, &block)
end
def add_content(parent, keyword, *args, &block)
super
parent.post_add_content
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/c_tab_item_expression.rb | lib/glimmer/dsl/swt/c_tab_item_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer'
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/widget_proxy'
require 'glimmer/swt/c_tab_item_proxy'
module Glimmer
module DSL
module SWT
class CTabItemExpression < StaticExpression
include ParentExpression
include_package 'org.eclipse.swt.custom'
def can_interpret?(parent, keyword, *args, &block)
initial_condition = (keyword == 'c_tab_item') and parent.respond_to?(:swt_widget)
if initial_condition
if parent.swt_widget.is_a?(CTabFolder)
return true
else
Glimmer::Config.logger.error {"c_tab_item widget may only be used directly under a c_tab_folder widget!"}
end
end
false
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::CTabItemProxy.new(parent, args)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/display_expression.rb | lib/glimmer/dsl/swt/display_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
class DisplayExpression < StaticExpression
include TopLevelExpression
include ParentExpression
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::DisplayProxy.instance(*args)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/font_expression.rb | lib/glimmer/dsl/swt/font_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/dsl/top_level_expression'
require 'glimmer/swt/font_proxy'
require 'glimmer/swt/custom/shape'
module Glimmer
module DSL
module SWT
# font expression
# Note: Cannot be a static expression because it clashes with font property expression
class FontExpression < Expression
include TopLevelExpression
def can_interpret?(parent, keyword, *args, &block)
keyword.to_s == 'font' and
(parent.nil? || !parent.respond_to?('font')) and
!parent.is_a?(Glimmer::SWT::Custom::Shape) and
args.size == 1 and
(args.first.is_a?(Hash) || args.first.is_a?(org.eclipse.swt.graphics.FontData))
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::FontProxy.create(*args)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/async_exec_expression.rb | lib/glimmer/dsl/swt/async_exec_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
require 'glimmer/dsl/swt/exec_expression'
module Glimmer
module DSL
module SWT
# Asynchronously executes code block against the SWT Event Loop
# to manipulate SWT UI objects on the UI thread safely
class AsyncExecExpression < StaticExpression
include ExecExpression
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb | lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/widget_binding'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
class CheckboxGroupSelectionDataBindingExpression < Expression
def can_interpret?(parent, keyword, *args, &block)
keyword == 'selection' and
block.nil? and
(parent.is_a?(Glimmer::SWT::Custom::CheckboxGroup) or (parent.is_a?(Glimmer::UI::CustomWidget) and parent.body_root.is_a?(Glimmer::SWT::Custom::CheckboxGroup)) ) and
args.size == 1 and
args[0].is_a?(DataBinding::ModelBinding) and
args[0].evaluate_options_property.is_a?(Array)
end
def interpret(parent, keyword, *args, &block)
model_binding = args[0]
#TODO make this options observer dependent and all similar observers in widget specific data binding handlers
# TODO consider delegating some of this work
widget_binding = DataBinding::WidgetBinding.new(parent, 'items', sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
widget_binding.call(model_binding.evaluate_options_property)
model = model_binding.base_model
widget_binding.observe(model, model_binding.options_property_name)
widget_binding = DataBinding::WidgetBinding.new(parent, 'selection', sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
widget_binding.call(model_binding.evaluate_property)
widget_binding.observe(model_binding)
Glimmer::SWT::DisplayProxy.instance.auto_exec(override_sync_exec: model_binding.binding_options[:sync_exec], override_async_exec: model_binding.binding_options[:async_exec]) do
parent.on_widget_selected do
model_binding.call(widget_binding.evaluate_property)
end
end
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/column_properties_expression.rb | lib/glimmer/dsl/swt/column_properties_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/static_expression'
module Glimmer
module DSL
module SWT
# Responsible for providing a readable keyword (command symbol) to capture
# and return column properties for use in TreeItemsDataBindingCommandHandler
class ColumnPropertiesExpression < StaticExpression
include_package 'org.eclipse.swt.widgets'
def can_interpret?(parent, keyword, *args, &block)
keyword == 'column_properties' and
block.nil? and
parent.respond_to?(:swt_widget) and
parent.swt_widget.is_a?(Table)
end
def interpret(parent, keyword, *args, &block)
args
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/layout_expression.rb | lib/glimmer/dsl/swt/layout_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer'
require 'glimmer/dsl/expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/layout_proxy'
require 'glimmer/swt/image_proxy'
module Glimmer
module DSL
module SWT
class LayoutExpression < Expression
include ParentExpression
include_package 'org.eclipse.swt.widgets'
include_package 'org.eclipse.swt.graphics'
def can_interpret?(parent, keyword, *args, &block)
keyword.to_s.end_with?('_layout') and
parent.respond_to?(:swt_widget) and
parent.swt_widget.is_a?(Composite) and
Glimmer::SWT::LayoutProxy.layout_exists?(keyword.to_s)
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::LayoutProxy.new(keyword, parent, args)
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/widget_expression.rb | lib/glimmer/dsl/swt/widget_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer'
require 'glimmer/dsl/expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/swt/custom/shape'
module Glimmer
module DSL
module SWT
class WidgetExpression < Expression
include ParentExpression
EXCLUDED_KEYWORDS = %w[shell display tab_item c_tab_item] + Glimmer::SWT::Custom::Shape.keywords - ['text']
def can_interpret?(parent, keyword, *args, &block)
!EXCLUDED_KEYWORDS.include?(keyword) and
parent.respond_to?(:swt_widget) and
!parent.is_a?(Glimmer::SWT::Custom::Shape) and
!((keyword.to_s == 'text') and (args.first.is_a?(String) or parent.swt_widget.class == org.eclipse.swt.widgets.Canvas)) and
Glimmer::SWT::WidgetProxy.widget_exists?(keyword)
end
def interpret(parent, keyword, *args, &block)
Glimmer::SWT::WidgetProxy.create(keyword, parent, args).tap do |new_widget_proxy|
new_widget_proxy.paint_pixel_by_pixel(&block) if block&.parameters&.count == 2
end
end
def add_content(parent, keyword, *args, &block)
return if block&.parameters&.count == 2
super
parent.post_add_content
parent.finish_add_content!
end
end
end
end
end
require 'glimmer/swt/widget_proxy'
require 'glimmer/swt/scrolled_composite_proxy'
require 'glimmer/swt/tree_proxy'
require 'glimmer/swt/table_proxy'
require 'glimmer/swt/table_column_proxy'
require 'glimmer/swt/sash_form_proxy'
require 'glimmer/swt/styled_text_proxy'
require 'glimmer/swt/date_time_proxy'
require 'glimmer/swt/tab_folder_proxy'
require 'glimmer/swt/combo_proxy'
require 'glimmer/swt/tool_bar_proxy'
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
AndyObtiva/glimmer-dsl-swt | https://github.com/AndyObtiva/glimmer-dsl-swt/blob/449cf07ada1ec965ae2ac91715ccdf22488df4ca/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb | lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb | # Copyright (c) 2007-2025 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer/dsl/expression'
require 'glimmer/data_binding/model_binding'
require 'glimmer/data_binding/widget_binding'
require 'glimmer/data_binding/list_selection_binding'
require 'glimmer/swt/display_proxy'
module Glimmer
module DSL
module SWT
class ListSelectionDataBindingExpression < Expression
include_package 'org.eclipse.swt.widgets'
def can_interpret?(parent, keyword, *args, &block)
keyword == 'selection' and
block.nil? and
parent.respond_to?(:swt_widget) and
parent.swt_widget.is_a?(List) and
args.size == 1 and
args[0].is_a?(DataBinding::ModelBinding) and
args[0].evaluate_options_property.is_a?(Array)
end
def interpret(parent, keyword, *args, &block)
model_binding = args[0]
widget_binding = DataBinding::WidgetBinding.new(parent, 'items', sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
widget_binding.call(model_binding.evaluate_options_property)
model = model_binding.base_model
#TODO make this options observer dependent and all similar observers in widget specific data binding interpretrs
widget_binding.observe(model, model_binding.options_property_name)
property_type = :string
property_type = :array if parent.has_style?(:multi)
list_selection_binding = DataBinding::ListSelectionBinding.new(parent, property_type, sync_exec: model_binding.binding_options[:sync_exec], async_exec: model_binding.binding_options[:async_exec])
list_selection_binding.call(model_binding.evaluate_property)
#TODO check if nested data binding works for list widget and other widgets that need custom data binding
list_selection_binding.observe(model_binding)
Glimmer::SWT::DisplayProxy.instance.auto_exec(override_sync_exec: model_binding.binding_options[:sync_exec], override_async_exec: model_binding.binding_options[:async_exec]) do
parent.on_widget_selected do
model_binding.call(list_selection_binding.evaluate_property)
end
end
end
end
end
end
end
| ruby | MIT | 449cf07ada1ec965ae2ac91715ccdf22488df4ca | 2026-01-04T17:52:38.125591Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.