glimmer-dsl-swt 0.1.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -2
- data/RUBY_VERSION +1 -1
- data/VERSION +1 -1
- data/icons/scaffold_app.icns +0 -0
- data/lib/ext/glimmer.rb +8 -1
- data/lib/ext/glimmer/config.rb +12 -4
- data/lib/glimmer-dsl-swt.rb +8 -3
- data/lib/glimmer/data_binding/list_selection_binding.rb +0 -1
- data/lib/glimmer/data_binding/table_items_binding.rb +5 -4
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +4 -0
- data/lib/glimmer/dsl/swt/dnd_expression.rb +25 -0
- data/lib/glimmer/dsl/swt/message_box_expression.rb +0 -4
- data/lib/glimmer/package.rb +9 -1
- data/lib/glimmer/rake_task.rb +27 -0
- data/lib/glimmer/rake_task/list.rb +73 -0
- data/lib/glimmer/scaffold.rb +5 -1
- data/lib/glimmer/swt/dnd_proxy.rb +34 -0
- data/lib/glimmer/swt/packages.rb +9 -6
- data/lib/glimmer/swt/style_constantizable.rb +120 -0
- data/lib/glimmer/swt/swt_proxy.rb +20 -88
- data/lib/glimmer/swt/table_proxy.rb +34 -11
- data/lib/glimmer/swt/widget_proxy.rb +158 -15
- metadata +73 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fee38949564fb2b0f3874a1bad1229cfb813439f0dca2e08b8d293b8c61fecb9
|
4
|
+
data.tar.gz: eb0e920dba273a6a343aeeb34cc664c33b7238b151df0e8cd5a4679aaee85b29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5ca29f9d303aa9320acb7f97492c8caf9d7e1135597ba646a3e5b238ec6e47408da2e4ea87f74c50ae283cd313def6d35c93e622040123dfb438c12d9330f8c
|
7
|
+
data.tar.gz: cd22b1bf5093d4a3a1c9caea73d152678395e7aa0110bdcfbe1df2ee923ca85d601c8529120a17acadabe75af979fc3791477ec00dde075b59a1f13565f5cf2a
|
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
# <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=
|
1
|
+
# <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 /> Glimmer DSL for SWT 0.2.3 (Desktop GUI)
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
|
3
3
|
[![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-swt/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-swt?branch=master)
|
4
5
|
[![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
5
6
|
|
6
|
-
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for SWT enables desktop development with Glimmer.
|
7
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [SWT](https://www.eclipse.org/swt/) enables desktop development with [Glimmer](https://github.com/AndyObtiva/glimmer).
|
8
|
+
|
9
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) is a native-GUI cross-platform desktop development library written in Ruby. Glimmer's main innovation is a JRuby DSL that enables productive and efficient authoring of desktop application user-interfaces while relying on the robust Eclipse SWT library. Glimmer additionally innovates by having built-in data-binding support to greatly facilitate synchronizing the GUI with domain models. As a result, that achieves true decoupling of object oriented components, enabling developers to solve business problems without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models test-first afterwards.
|
7
10
|
|
8
11
|
You may find full setup/usage instructions at the main [Glimmer project page](https://github.com/AndyObtiva/glimmer).
|
9
12
|
|
@@ -12,6 +15,23 @@ Other Glimmer DSL gems:
|
|
12
15
|
- [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
|
13
16
|
- [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
|
14
17
|
|
18
|
+
## Example
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
include Glimmer
|
22
|
+
|
23
|
+
shell {
|
24
|
+
text 'Glimmer'
|
25
|
+
label {
|
26
|
+
text 'Hello, World!'
|
27
|
+
}
|
28
|
+
}.open
|
29
|
+
```
|
30
|
+
|
31
|
+
![Glimmer DSL for SWT Hello World](https://github.com/AndyObtiva/glimmer/blob/master/images/glimmer-hello-world.png)
|
32
|
+
|
33
|
+
Learn more at the main [Glimmer project page](https://github.com/AndyObtiva/glimmer).
|
34
|
+
|
15
35
|
## Help
|
16
36
|
|
17
37
|
### Issues
|
data/RUBY_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jruby-9.2.
|
1
|
+
jruby-9.2.12.0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.3
|
data/icons/scaffold_app.icns
CHANGED
Binary file
|
data/lib/ext/glimmer.rb
CHANGED
@@ -3,11 +3,18 @@ require 'glimmer/swt/packages'
|
|
3
3
|
module Glimmer
|
4
4
|
class << self
|
5
5
|
def included(klass)
|
6
|
+
if Object.const_defined?(:ActiveSupport) && ActiveSupport.const_defined?(:Dependencies)
|
7
|
+
begin
|
8
|
+
ActiveSupport::Dependencies.unhook!
|
9
|
+
rescue => e
|
10
|
+
# noop TODO support logging unimportant details below debug level
|
11
|
+
end
|
12
|
+
end
|
6
13
|
if Config.import_swt_packages
|
7
14
|
klass.include(SWT::Packages)
|
8
15
|
klass.extend(SWT::Packages)
|
9
|
-
klass.extend(Glimmer)
|
10
16
|
end
|
17
|
+
klass.extend(Glimmer)
|
11
18
|
end
|
12
19
|
end
|
13
20
|
end
|
data/lib/ext/glimmer/config.rb
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
module Glimmer
|
2
2
|
module Config
|
3
|
+
DEFAULT_IMPORT_SWT_PACKAGES = [
|
4
|
+
'org.eclipse.swt',
|
5
|
+
'org.eclipse.swt.widgets',
|
6
|
+
'org.eclipse.swt.layout',
|
7
|
+
'org.eclipse.swt.graphics',
|
8
|
+
'org.eclipse.swt.browser',
|
9
|
+
'org.eclipse.swt.custom',
|
10
|
+
'org.eclipse.swt.dnd',
|
11
|
+
]
|
12
|
+
|
3
13
|
class << self
|
4
14
|
# Tells Glimmer to import SWT packages into including class (default: true)
|
5
15
|
def import_swt_packages=(value)
|
6
|
-
@@import_swt_packages =
|
16
|
+
@@import_swt_packages = value
|
7
17
|
end
|
8
18
|
|
9
19
|
# Returns whether Glimmer will import SWT packages into including class
|
10
20
|
def import_swt_packages
|
11
|
-
|
12
|
-
@@import_swt_packages = true
|
13
|
-
end
|
21
|
+
@@import_swt_packages = DEFAULT_IMPORT_SWT_PACKAGES if !defined?(@@import_swt_packages) || (defined?(@@import_swt_packages) && @@import_swt_packages == true)
|
14
22
|
@@import_swt_packages
|
15
23
|
end
|
16
24
|
end
|
data/lib/glimmer-dsl-swt.rb
CHANGED
@@ -2,9 +2,14 @@ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
|
|
2
2
|
|
3
3
|
# External requires
|
4
4
|
require 'java'
|
5
|
-
|
6
|
-
require '
|
7
|
-
require
|
5
|
+
if ENV['BUNDLER_REQUIRE'].to_s.downcase == 'true'
|
6
|
+
require 'bundler'
|
7
|
+
Bundler.require
|
8
|
+
else
|
9
|
+
require 'nested_inherited_jruby_include_package'
|
10
|
+
require 'super_module'
|
11
|
+
require 'glimmer'
|
12
|
+
end
|
8
13
|
|
9
14
|
# Internal requires
|
10
15
|
require 'ext/glimmer/config'
|
@@ -22,23 +22,24 @@ module Glimmer
|
|
22
22
|
@table.body_root.column_properties = @column_properties
|
23
23
|
end
|
24
24
|
call(@model_binding.evaluate_property)
|
25
|
-
|
26
|
-
observe(model, model_binding.property_name_expression)
|
25
|
+
observe(model_binding)
|
27
26
|
@table.on_widget_disposed do |dispose_event|
|
28
27
|
unregister_all_observables
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
31
|
def call(new_model_collection=nil)
|
32
|
+
new_model_collection = @model_binding.evaluate_property # this ensures applying converters (e.g. :on_read)
|
33
33
|
if new_model_collection and new_model_collection.is_a?(Array)
|
34
34
|
observe(new_model_collection, @column_properties)
|
35
35
|
@model_collection = new_model_collection
|
36
36
|
end
|
37
|
-
populate_table(@model_collection, @table, @column_properties)
|
37
|
+
populate_table(@model_collection, @table, @column_properties)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def populate_table(model_collection, parent, column_properties)
|
41
41
|
selected_table_item_models = parent.swt_widget.getSelection.map(&:getData)
|
42
|
+
parent.finish_edit!
|
42
43
|
parent.swt_widget.removeAll
|
43
44
|
model_collection.each do |model|
|
44
45
|
table_item = TableItem.new(parent.swt_widget, SWT::SWTProxy[:none])
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'glimmer/dsl/static_expression'
|
2
|
+
require 'glimmer/swt/dnd_proxy'
|
3
|
+
|
4
|
+
# TODO consider turning static keywords like bind into methods
|
5
|
+
|
6
|
+
module Glimmer
|
7
|
+
module DSL
|
8
|
+
module SWT
|
9
|
+
# Responsible for returning DND constant values
|
10
|
+
#
|
11
|
+
# Named DndExpression (not DNDExpression) so that the DSL engine
|
12
|
+
# discovers quickly by convention
|
13
|
+
class DndExpression < StaticExpression
|
14
|
+
def can_interpret?(parent, keyword, *args, &block)
|
15
|
+
block.nil? &&
|
16
|
+
args.size > 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def interpret(parent, keyword, *args, &block)
|
20
|
+
Glimmer::SWT::DNDProxy[*args]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -14,10 +14,6 @@ module Glimmer
|
|
14
14
|
|
15
15
|
include_package 'org.eclipse.swt.widgets'
|
16
16
|
|
17
|
-
def can_interpret?(parent, keyword, *args, &block)
|
18
|
-
keyword == 'message_box'
|
19
|
-
end
|
20
|
-
|
21
17
|
def interpret(parent, keyword, *args, &block)
|
22
18
|
potential_parent = args.first
|
23
19
|
parent = args.shift if potential_parent.is_a?(Shell) || (potential_parent.respond_to?(:swt_widget) && potential_parent.swt_widget.is_a?(Shell))
|
data/lib/glimmer/package.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
require 'os'
|
2
2
|
|
3
|
+
# TODO refactor to nest under RakeTask namespace
|
4
|
+
|
3
5
|
module Glimmer
|
4
6
|
module Package
|
5
7
|
class << self
|
6
8
|
attr_accessor :javapackager_extra_args
|
7
9
|
|
10
|
+
def clean
|
11
|
+
require 'fileutils'
|
12
|
+
FileUtils.rm_rf('dist')
|
13
|
+
FileUtils.rm_rf('packages')
|
14
|
+
end
|
15
|
+
|
8
16
|
def config
|
9
17
|
project_name = File.basename(File.expand_path('.'))
|
10
18
|
if !File.exists?('config/warble.rb')
|
@@ -13,7 +21,7 @@ module Glimmer
|
|
13
21
|
system('warble config')
|
14
22
|
new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
|
15
23
|
if line.include?('config.dirs =')
|
16
|
-
line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts icons images sounds videos)')
|
24
|
+
line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts icons images sounds videos vendor)')
|
17
25
|
end
|
18
26
|
if line.include?('config.includes =')
|
19
27
|
line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
|
data/lib/glimmer/rake_task.rb
CHANGED
@@ -4,6 +4,11 @@ require_relative 'package'
|
|
4
4
|
|
5
5
|
namespace :glimmer do
|
6
6
|
namespace :package do
|
7
|
+
desc 'Clean by removing "dist" and "packages" directories'
|
8
|
+
task :clean do
|
9
|
+
Glimmer::Package.clean
|
10
|
+
end
|
11
|
+
|
7
12
|
desc 'Generate JAR config file'
|
8
13
|
task :config do
|
9
14
|
Glimmer::Package.config
|
@@ -59,4 +64,26 @@ namespace :glimmer do
|
|
59
64
|
Scaffold.custom_widget_gem(args[:custom_widget_name], args[:namespace])
|
60
65
|
end
|
61
66
|
end
|
67
|
+
|
68
|
+
namespace :list do
|
69
|
+
task :list_require do
|
70
|
+
require_relative 'rake_task/list'
|
71
|
+
end
|
72
|
+
|
73
|
+
desc 'List Glimmer custom widget gems available at rubygems.org (query is optional)'
|
74
|
+
task :custom_widget_gems, [:query] => :list_require do |t, args|
|
75
|
+
Glimmer::RakeTask::List.custom_widget_gems(args[:query])
|
76
|
+
end
|
77
|
+
|
78
|
+
desc 'List Glimmer custom shell gems available at rubygems.org (query is optional)'
|
79
|
+
task :custom_shell_gems, [:query] => :list_require do |t, args|
|
80
|
+
Glimmer::RakeTask::List.custom_shell_gems(args[:query])
|
81
|
+
end
|
82
|
+
|
83
|
+
desc 'List Glimmer DSL gems available at rubygems.org (query is optional)'
|
84
|
+
task :dsl_gems, [:query] => :list_require do |t, args|
|
85
|
+
Glimmer::RakeTask::List.dsl_gems(args[:query])
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
62
89
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'facets'
|
2
|
+
require 'text-table'
|
3
|
+
|
4
|
+
module Glimmer
|
5
|
+
module RakeTask
|
6
|
+
# Lists Glimmer related gems to use in rake_task.rb
|
7
|
+
class List
|
8
|
+
class << self
|
9
|
+
REGEX_GEM_LINE = /^([^\(]+) \(([^\)]+)\)$/
|
10
|
+
|
11
|
+
def custom_widget_gems(query=nil)
|
12
|
+
list_gems('glimmer-cw-', query) do |result|
|
13
|
+
puts
|
14
|
+
puts " Glimmer Custom Widget Gems#{" matching [#{query}]" if query} at rubygems.org:"
|
15
|
+
puts result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def custom_shell_gems(query=nil)
|
20
|
+
list_gems('glimmer-cs-', query) do |result|
|
21
|
+
puts
|
22
|
+
puts " Glimmer Custom Shell Gems#{" matching [#{query}]" if query} at rubygems.org:"
|
23
|
+
puts result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def dsl_gems(query=nil)
|
28
|
+
list_gems('glimmer-dsl-', query) do |result|
|
29
|
+
puts
|
30
|
+
puts " Glimmer DSL Gems#{" matching [#{query}]" if query} at rubygems.org:"
|
31
|
+
puts result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def list_gems(gem_prefix, query=nil, &printer)
|
36
|
+
lines = `gem search -d #{gem_prefix}`.split("\n")
|
37
|
+
gems = lines.slice_before {|l| l.match(REGEX_GEM_LINE) }.to_a
|
38
|
+
gems = gems.map do |gem|
|
39
|
+
{
|
40
|
+
name: gem[0].match(REGEX_GEM_LINE)[1],
|
41
|
+
version: gem[0].match(REGEX_GEM_LINE)[2],
|
42
|
+
author: gem[1].strip,
|
43
|
+
description: gem[4..-1].map(&:strip).join(' ')
|
44
|
+
}
|
45
|
+
end.select do |gem|
|
46
|
+
query.nil? || "#{gem[:name]} #{gem[:author]} #{gem[:description]}".downcase.include?(query.to_s.downcase)
|
47
|
+
end
|
48
|
+
printer.call(tablify(gem_prefix, gems))
|
49
|
+
end
|
50
|
+
|
51
|
+
def tablify(gem_prefix, gems)
|
52
|
+
array_of_arrays = gems.map do |gem|
|
53
|
+
[
|
54
|
+
gem[:name].sub(gem_prefix, '').underscore.titlecase,
|
55
|
+
gem[:name],
|
56
|
+
gem[:version],
|
57
|
+
gem[:author].sub('Author: ', ''),
|
58
|
+
gem[:description],
|
59
|
+
]
|
60
|
+
end
|
61
|
+
Text::Table.new(
|
62
|
+
:head => %w[Name Gem Version Author Description],
|
63
|
+
:rows => array_of_arrays,
|
64
|
+
:horizontal_padding => 1,
|
65
|
+
:vertical_boundary => ' ',
|
66
|
+
:horizontal_boundary => ' ',
|
67
|
+
:boundary_intersection => ' '
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/glimmer/scaffold.rb
CHANGED
@@ -2,6 +2,8 @@ require 'fileutils'
|
|
2
2
|
require 'os'
|
3
3
|
require 'facets'
|
4
4
|
|
5
|
+
# TODO refactor to nest under RakeTask namespace
|
6
|
+
|
5
7
|
class Scaffold
|
6
8
|
class << self
|
7
9
|
include FileUtils
|
@@ -56,7 +58,7 @@ class Scaffold
|
|
56
58
|
|
57
59
|
# for a library or gem, you might want to ignore these files since the code is
|
58
60
|
# intended to run in multiple environments; otherwise, check them in:
|
59
|
-
Gemfile.lock
|
61
|
+
# Gemfile.lock
|
60
62
|
# .ruby-version
|
61
63
|
# .ruby-gemset
|
62
64
|
|
@@ -177,6 +179,7 @@ class Scaffold
|
|
177
179
|
end
|
178
180
|
|
179
181
|
def custom_shell_gem(custom_shell_name, namespace)
|
182
|
+
return puts('Namespace is required! Usage: glimmer scaffold:custom_shell_gem[custom_shell_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
|
180
183
|
gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
|
181
184
|
gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
|
182
185
|
if namespace
|
@@ -216,6 +219,7 @@ class Scaffold
|
|
216
219
|
end
|
217
220
|
|
218
221
|
def custom_widget_gem(custom_widget_name, namespace)
|
222
|
+
return puts('Namespace is required! Usage: glimmer scaffold:custom_widget_gem[custom_widget_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
|
219
223
|
gem_name = "glimmer-cw-#{compact_name(custom_widget_name)}"
|
220
224
|
gem_summary = "#{human_name(custom_widget_name)} - Glimmer Custom Widget"
|
221
225
|
if namespace
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'glimmer/swt/style_constantizable'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
# Proxy for org.eclipse.swt.dnd.DND
|
6
|
+
#
|
7
|
+
# Follows the Proxy Design Pattern
|
8
|
+
class DNDProxy
|
9
|
+
include StyleConstantizable
|
10
|
+
|
11
|
+
class << self
|
12
|
+
JAVA_IMPORT = 'org.eclipse.swt.dnd.DND'
|
13
|
+
|
14
|
+
java_import JAVA_IMPORT
|
15
|
+
|
16
|
+
def constant_java_import
|
17
|
+
JAVA_IMPORT
|
18
|
+
end
|
19
|
+
|
20
|
+
def constant_source_class
|
21
|
+
DND
|
22
|
+
end
|
23
|
+
|
24
|
+
def constant_value_none
|
25
|
+
DND::DROP_NONE
|
26
|
+
end
|
27
|
+
|
28
|
+
def extra_styles
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/glimmer/swt/packages.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
require 'ext/glimmer/config'
|
2
|
+
|
1
3
|
module Glimmer
|
2
4
|
module SWT
|
3
5
|
# This contains Java imports of SWT Java packages
|
4
6
|
module Packages
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
class << self
|
8
|
+
def included(klass)
|
9
|
+
Glimmer::Config.import_swt_packages.to_a.each do |package|
|
10
|
+
include_package(package) if package.is_a?(String)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'glimmer/error'
|
2
|
+
|
3
|
+
module Glimmer
|
4
|
+
module SWT
|
5
|
+
# Mixin for all proxy classes that manage style constants (e.g. SWT, DND, etc...)
|
6
|
+
module StyleConstantizable
|
7
|
+
include SuperModule
|
8
|
+
|
9
|
+
class << self
|
10
|
+
REGEX_SYMBOL_NEGATIVITY = /^([^!]+)(!)?$/
|
11
|
+
|
12
|
+
def constant_java_import
|
13
|
+
raise 'Not implemented! Mixer must implement!'
|
14
|
+
end
|
15
|
+
|
16
|
+
def constant_source_class
|
17
|
+
raise 'Not implemented! Mixer must implement!'
|
18
|
+
end
|
19
|
+
|
20
|
+
def constant_value_none
|
21
|
+
raise 'Not implemented! Mixer must implement!'
|
22
|
+
end
|
23
|
+
|
24
|
+
# hash of extra styles (i.e. new style combinations)
|
25
|
+
def extra_styles
|
26
|
+
raise 'Not implemented! Mixer must implement!'
|
27
|
+
end
|
28
|
+
|
29
|
+
def error_message_invalid_style
|
30
|
+
" is an invalid #{constant_source_class.name.split(':').last} style! Please choose a style from #{constant_java_import} class constants." # TODO parameterize
|
31
|
+
end
|
32
|
+
|
33
|
+
# Gets constants (e.g. SWT::CONSTANT) where constant is
|
34
|
+
# passed in as a lower case symbol
|
35
|
+
def [](*symbols)
|
36
|
+
symbols = symbols.first if symbols.size == 1 && symbols.first.is_a?(Array)
|
37
|
+
result = symbols.compact.map do |symbol|
|
38
|
+
constant(symbol).tap do |constant_value|
|
39
|
+
raise Glimmer::Error, symbol.to_s + error_message_invalid_style unless constant_value.is_a?(Integer)
|
40
|
+
end
|
41
|
+
end.reduce do |output, constant_value|
|
42
|
+
if constant_value < 0
|
43
|
+
output & constant_value
|
44
|
+
else
|
45
|
+
output | constant_value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
result.nil? ? constant_value_none : result
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns style integer value for passed in symbol or allows
|
52
|
+
# passed in object to pass through (e.g. Integer). This makes is convenient
|
53
|
+
# to use symbols or actual style integers in Glimmer
|
54
|
+
# Does not raise error for invalid values. Just lets them pass as is.
|
55
|
+
# (look into [] operator if you want an error raised on invalid values)
|
56
|
+
def constant(symbol)
|
57
|
+
return symbol unless symbol.is_a?(Symbol) || symbol.is_a?(String)
|
58
|
+
symbol_string, negative = extract_symbol_string_negativity(symbol)
|
59
|
+
swt_constant_symbol = symbol_string.downcase == symbol_string ? symbol_string.upcase.to_sym : symbol_string.to_sym
|
60
|
+
bit_value = constant_source_class.const_get(swt_constant_symbol)
|
61
|
+
negative ? ~bit_value : bit_value
|
62
|
+
rescue => e
|
63
|
+
begin
|
64
|
+
# Glimmer::Config.logger&.debug(e.full_message)
|
65
|
+
alternative_swt_constant_symbol = constant_source_class.constants.find {|c| c.to_s.upcase == swt_constant_symbol.to_s.upcase}
|
66
|
+
bit_value = constant_source_class.const_get(alternative_swt_constant_symbol)
|
67
|
+
negative ? ~bit_value : bit_value
|
68
|
+
rescue => e
|
69
|
+
# Glimmer::Config.logger&.debug(e.full_message)
|
70
|
+
bit_value = extra_styles[swt_constant_symbol]
|
71
|
+
if bit_value
|
72
|
+
negative ? ~bit_value : bit_value
|
73
|
+
else
|
74
|
+
symbol
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def extract_symbol_string_negativity(symbol)
|
80
|
+
if symbol.is_a?(Symbol) || symbol.is_a?(String)
|
81
|
+
symbol_negativity_match = symbol.to_s.match(REGEX_SYMBOL_NEGATIVITY)
|
82
|
+
symbol = symbol_negativity_match[1]
|
83
|
+
negative = !!symbol_negativity_match[2]
|
84
|
+
[symbol, negative]
|
85
|
+
else
|
86
|
+
negative = symbol < 0
|
87
|
+
[symbol, negative]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def negative?(symbol)
|
92
|
+
extract_symbol_string_negativity(symbol)[1]
|
93
|
+
end
|
94
|
+
|
95
|
+
def has_constant?(symbol)
|
96
|
+
return false unless symbol.is_a?(Symbol) || symbol.is_a?(String)
|
97
|
+
constant(symbol).is_a?(Integer)
|
98
|
+
end
|
99
|
+
|
100
|
+
def constantify_args(args)
|
101
|
+
args.map {|arg| constant(arg)}
|
102
|
+
end
|
103
|
+
|
104
|
+
# Deconstructs a style integer into symbols
|
105
|
+
# Useful for debugging
|
106
|
+
def deconstruct(integer)
|
107
|
+
constant_source_class.constants.reduce([]) do |found, c|
|
108
|
+
constant_value = constant_source_class.const_get(c) rescue -1
|
109
|
+
is_found = constant_value.is_a?(Integer) && (constant_value & integer) == constant_value
|
110
|
+
is_found ? found += [c] : found
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def include?(swt_constant, *symbols)
|
115
|
+
swt_constant & self[symbols] == self[symbols]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -1,106 +1,38 @@
|
|
1
|
-
require 'glimmer/
|
1
|
+
require 'glimmer/swt/style_constantizable'
|
2
2
|
|
3
3
|
module Glimmer
|
4
|
-
module SWT
|
4
|
+
module SWT
|
5
5
|
# Proxy for org.eclipse.swt.SWT
|
6
6
|
#
|
7
7
|
# Follows the Proxy Design Pattern
|
8
|
-
class SWTProxy
|
9
|
-
|
10
|
-
java_import 'org.eclipse.swt.SWT'
|
11
|
-
|
12
|
-
ERROR_INVALID_STYLE = " is an invalid SWT style! Please choose a style from org.eclipse.swt.SWT class constants."
|
13
|
-
REGEX_SYMBOL_NEGATIVITY = /^([^!]+)(!)?$/
|
14
|
-
|
15
|
-
# Gets SWT constants as if calling SWT::CONSTANT where constant is
|
16
|
-
# passed in as a lower case symbol
|
17
|
-
def [](*symbols)
|
18
|
-
symbols = symbols.first if symbols.size == 1 && symbols.first.is_a?(Array)
|
19
|
-
result = symbols.compact.map do |symbol|
|
20
|
-
constant(symbol).tap do |constant_value|
|
21
|
-
raise Error, symbol.to_s + ERROR_INVALID_STYLE unless constant_value.is_a?(Integer)
|
22
|
-
end
|
23
|
-
end.reduce do |output, constant_value|
|
24
|
-
if constant_value < 0
|
25
|
-
output & constant_value
|
26
|
-
else
|
27
|
-
output | constant_value
|
28
|
-
end
|
29
|
-
end
|
30
|
-
result.nil? ? SWT::NONE : result
|
31
|
-
end
|
32
|
-
|
33
|
-
# Returns SWT style integer value for passed in symbol or allows
|
34
|
-
# passed in object to pass through (e.g. Integer). This makes is convenient
|
35
|
-
# to use symbols or actual SWT style integers in Glimmer
|
36
|
-
# Does not raise error for invalid values. Just lets them pass as is.
|
37
|
-
# (look into [] operator if you want an error raised on invalid values)
|
38
|
-
def constant(symbol)
|
39
|
-
return symbol unless symbol.is_a?(Symbol) || symbol.is_a?(String)
|
40
|
-
symbol_string, negative = extract_symbol_string_negativity(symbol)
|
41
|
-
swt_constant_symbol = symbol_string.downcase == symbol_string ? symbol_string.upcase.to_sym : symbol_string.to_sym
|
42
|
-
bit_value = SWT.const_get(swt_constant_symbol)
|
43
|
-
negative ? ~bit_value : bit_value
|
44
|
-
rescue => e
|
45
|
-
begin
|
46
|
-
# Glimmer::Config.logger&.debug(e.full_message)
|
47
|
-
alternative_swt_constant_symbol = SWT.constants.find {|c| c.to_s.upcase == swt_constant_symbol.to_s.upcase}
|
48
|
-
bit_value = SWT.const_get(alternative_swt_constant_symbol)
|
49
|
-
negative ? ~bit_value : bit_value
|
50
|
-
rescue => e
|
51
|
-
# Glimmer::Config.logger&.debug(e.full_message)
|
52
|
-
bit_value = Glimmer::SWT::SWTProxy::EXTRA_STYLES[swt_constant_symbol]
|
53
|
-
if bit_value
|
54
|
-
negative ? ~bit_value : bit_value
|
55
|
-
else
|
56
|
-
symbol
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
8
|
+
class SWTProxy
|
9
|
+
include StyleConstantizable
|
60
10
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
negative = symbol < 0
|
69
|
-
[symbol, negative]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def negative?(symbol)
|
74
|
-
extract_symbol_string_negativity(symbol)[1]
|
75
|
-
end
|
76
|
-
|
77
|
-
def has_constant?(symbol)
|
78
|
-
return false unless symbol.is_a?(Symbol) || symbol.is_a?(String)
|
79
|
-
constant(symbol).is_a?(Integer)
|
11
|
+
class << self
|
12
|
+
JAVA_IMPORT = 'org.eclipse.swt.SWT'
|
13
|
+
|
14
|
+
java_import JAVA_IMPORT
|
15
|
+
|
16
|
+
def constant_java_import
|
17
|
+
JAVA_IMPORT
|
80
18
|
end
|
81
19
|
|
82
|
-
def
|
83
|
-
|
20
|
+
def constant_source_class
|
21
|
+
SWT
|
84
22
|
end
|
85
23
|
|
86
|
-
|
87
|
-
|
88
|
-
def deconstruct(integer)
|
89
|
-
SWT.constants.reduce([]) do |found, c|
|
90
|
-
constant_value = SWT.const_get(c) rescue -1
|
91
|
-
is_found = constant_value.is_a?(Integer) && (constant_value & integer) == constant_value
|
92
|
-
is_found ? found += [c] : found
|
93
|
-
end
|
24
|
+
def constant_value_none
|
25
|
+
SWT::NONE
|
94
26
|
end
|
95
|
-
|
96
|
-
def
|
97
|
-
|
27
|
+
|
28
|
+
def extra_styles
|
29
|
+
EXTRA_STYLES
|
98
30
|
end
|
99
31
|
end
|
100
|
-
|
32
|
+
|
101
33
|
EXTRA_STYLES = {
|
102
34
|
NO_RESIZE: self[:shell_trim, :resize!, :max!]
|
103
|
-
}
|
35
|
+
}
|
104
36
|
end
|
105
37
|
end
|
106
38
|
end
|
@@ -68,6 +68,21 @@ module Glimmer
|
|
68
68
|
})
|
69
69
|
end
|
70
70
|
|
71
|
+
# Indicates if table is in edit mode, thus displaying a text widget for a table item cell
|
72
|
+
def edit_mode?
|
73
|
+
!!@edit_mode
|
74
|
+
end
|
75
|
+
|
76
|
+
def cancel_edit!
|
77
|
+
@cancel_edit&.call if @edit_mode
|
78
|
+
end
|
79
|
+
|
80
|
+
def finish_edit!
|
81
|
+
@finish_edit&.call if @edit_mode
|
82
|
+
end
|
83
|
+
|
84
|
+
# Indicates if table is editing a table item because the user hit ENTER or focused out after making a change in edit mode to a table item cell.
|
85
|
+
# It is set to false once change is saved to model
|
71
86
|
def edit_in_progress?
|
72
87
|
!!@edit_in_progress
|
73
88
|
end
|
@@ -78,24 +93,32 @@ module Glimmer
|
|
78
93
|
|
79
94
|
def edit_table_item(table_item, column_index, before_write: nil, after_write: nil, after_cancel: nil)
|
80
95
|
return if table_item.nil?
|
96
|
+
@cancel_edit&.call if @edit_mode
|
97
|
+
@edit_mode = true
|
81
98
|
content {
|
82
99
|
@table_editor_text_proxy = text {
|
83
100
|
focus true
|
84
101
|
text table_item.getText(column_index)
|
85
102
|
action_taken = false
|
86
|
-
|
87
|
-
@
|
103
|
+
@cancel_edit = lambda do
|
104
|
+
@cancel_in_progress = true
|
105
|
+
@table_editor_text_proxy&.swt_widget&.dispose
|
88
106
|
@table_editor_text_proxy = nil
|
89
107
|
after_cancel&.call
|
90
108
|
@edit_in_progress = false
|
91
|
-
|
92
|
-
|
93
|
-
|
109
|
+
@cancel_in_progress = false
|
110
|
+
@cancel_edit = nil
|
111
|
+
@edit_mode = false
|
112
|
+
end
|
113
|
+
@finish_edit = lambda do |event=nil|
|
114
|
+
if table_item.isDisposed
|
115
|
+
@cancel_edit.call
|
116
|
+
elsif !action_taken && !@edit_in_progress && !@cancel_in_progress
|
94
117
|
action_taken = true
|
95
118
|
@edit_in_progress = true
|
96
119
|
new_text = @table_editor_text_proxy.swt_widget.getText
|
97
120
|
if new_text == table_item.getText(column_index)
|
98
|
-
|
121
|
+
@cancel_edit.call
|
99
122
|
else
|
100
123
|
before_write&.call
|
101
124
|
table_item.setText(column_index, new_text)
|
@@ -103,19 +126,19 @@ module Glimmer
|
|
103
126
|
model.send("#{column_properties[column_index]}=", new_text) # makes table update itself, so must search for selected table item again
|
104
127
|
edited_table_item = search { |ti| ti.getData == model }.first
|
105
128
|
swt_widget.showItem(edited_table_item)
|
106
|
-
@table_editor_text_proxy
|
129
|
+
@table_editor_text_proxy&.swt_widget&.dispose
|
107
130
|
@table_editor_text_proxy = nil
|
108
131
|
after_write&.call(edited_table_item)
|
109
132
|
@edit_in_progress = false
|
110
133
|
end
|
111
134
|
end
|
112
|
-
|
113
|
-
on_focus_lost(
|
135
|
+
end
|
136
|
+
on_focus_lost(&@finish_edit)
|
114
137
|
on_key_pressed { |key_event|
|
115
138
|
if key_event.keyCode == swt(:cr)
|
116
|
-
|
139
|
+
@finish_edit.call(key_event)
|
117
140
|
elsif key_event.keyCode == swt(:esc)
|
118
|
-
|
141
|
+
@cancel_edit.call
|
119
142
|
end
|
120
143
|
}
|
121
144
|
}
|
@@ -2,6 +2,7 @@ require 'glimmer/swt/widget_listener_proxy'
|
|
2
2
|
require 'glimmer/swt/color_proxy'
|
3
3
|
require 'glimmer/swt/font_proxy'
|
4
4
|
require 'glimmer/swt/swt_proxy'
|
5
|
+
require 'glimmer/swt/dnd_proxy'
|
5
6
|
require 'glimmer/data_binding/observable_widget'
|
6
7
|
|
7
8
|
# TODO refactor to make file smaller and extract sub-widget-proxies out of this
|
@@ -30,6 +31,8 @@ module Glimmer
|
|
30
31
|
"list" => [:border, :v_scroll],
|
31
32
|
"button" => [:push],
|
32
33
|
"menu_item" => [:push],
|
34
|
+
"drag_source" => [:drop_copy],
|
35
|
+
"drop_target" => [:drop_copy],
|
33
36
|
}
|
34
37
|
|
35
38
|
DEFAULT_INITIALIZERS = {
|
@@ -48,7 +51,7 @@ module Glimmer
|
|
48
51
|
end,
|
49
52
|
}
|
50
53
|
|
51
|
-
attr_reader :swt_widget
|
54
|
+
attr_reader :swt_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer
|
52
55
|
|
53
56
|
# Initializes a new SWT Widget
|
54
57
|
#
|
@@ -72,7 +75,18 @@ module Glimmer
|
|
72
75
|
if @arg_extractor_mapping[underscored_widget_name]
|
73
76
|
@arg_extractor_mapping[underscored_widget_name].call(args)
|
74
77
|
else
|
75
|
-
|
78
|
+
extra_options = []
|
79
|
+
style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
|
80
|
+
if style_args.any?
|
81
|
+
style_arg_start_index = args.index(style_args.first)
|
82
|
+
style_arg_last_index = args.index(style_args.last)
|
83
|
+
extra_options = args[style_arg_last_index+1..-1]
|
84
|
+
args = args[style_arg_start_index..style_arg_last_index]
|
85
|
+
elsif args.first.is_a?(Integer)
|
86
|
+
extra_options = args[1..-1]
|
87
|
+
args = args[0..0]
|
88
|
+
end
|
89
|
+
[args, extra_options]
|
76
90
|
end
|
77
91
|
end
|
78
92
|
|
@@ -81,7 +95,7 @@ module Glimmer
|
|
81
95
|
if widget_custom_attribute
|
82
96
|
@swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
|
83
97
|
else
|
84
|
-
@swt_widget.respond_to?(attribute_setter(attribute_name), args)
|
98
|
+
@swt_widget.respond_to?(attribute_setter(attribute_name), args) || respond_to?(ruby_attribute_setter(attribute_name), args)
|
85
99
|
end
|
86
100
|
end
|
87
101
|
|
@@ -89,9 +103,11 @@ module Glimmer
|
|
89
103
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
90
104
|
if widget_custom_attribute
|
91
105
|
widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
|
92
|
-
|
106
|
+
elsif @swt_widget.respond_to?(attribute_setter(attribute_name), args)
|
93
107
|
apply_property_type_converters(attribute_name, args)
|
94
108
|
@swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
|
109
|
+
else
|
110
|
+
send(ruby_attribute_setter(attribute_name), args)
|
95
111
|
end
|
96
112
|
end
|
97
113
|
|
@@ -129,6 +145,23 @@ module Glimmer
|
|
129
145
|
observer.call(false)
|
130
146
|
}
|
131
147
|
end,
|
148
|
+
:selection => lambda do |observer|
|
149
|
+
on_widget_selected { |selection_event|
|
150
|
+
observer.call(@swt_widget.getSelection)
|
151
|
+
} if can_handle_observation_request?(:on_widget_selected)
|
152
|
+
end,
|
153
|
+
:text => lambda do |observer|
|
154
|
+
on_modify_text { |modify_event|
|
155
|
+
observer.call(@swt_widget.getText)
|
156
|
+
} if can_handle_observation_request?(:on_modify_text)
|
157
|
+
end,
|
158
|
+
},
|
159
|
+
Java::OrgEclipseSwtWidgets::Combo => {
|
160
|
+
:text => lambda do |observer|
|
161
|
+
on_modify_text { |modify_event|
|
162
|
+
observer.call(@swt_widget.getText)
|
163
|
+
}
|
164
|
+
end,
|
132
165
|
},
|
133
166
|
Java::OrgEclipseSwtWidgets::Text => {
|
134
167
|
:text => lambda do |observer|
|
@@ -251,7 +284,12 @@ module Glimmer
|
|
251
284
|
end
|
252
285
|
|
253
286
|
def has_style?(style)
|
254
|
-
|
287
|
+
begin
|
288
|
+
comparison = SWTProxy[style]
|
289
|
+
rescue
|
290
|
+
comparison = DNDProxy[style]
|
291
|
+
end
|
292
|
+
(@swt_widget.style & comparison) == comparison
|
255
293
|
end
|
256
294
|
|
257
295
|
def dispose
|
@@ -268,15 +306,28 @@ module Glimmer
|
|
268
306
|
def add_observer(observer, property_name)
|
269
307
|
property_listener_installers = @swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact
|
270
308
|
widget_listener_installers = property_listener_installers.map{|installer| installer[property_name.to_s.to_sym]}.compact if !property_listener_installers.empty?
|
271
|
-
widget_listener_installers.to_a.
|
272
|
-
widget_listener_installer.call(observer)
|
273
|
-
end
|
309
|
+
widget_listener_installers.to_a.first&.call(observer)
|
274
310
|
end
|
275
311
|
|
276
312
|
def remove_observer(observer, property_name)
|
277
313
|
# TODO consider implementing if remove_observer is needed (consumers can remove listener via SWT API)
|
278
314
|
end
|
279
315
|
|
316
|
+
def ensure_drag_source_proxy(style=[])
|
317
|
+
@drag_source_proxy ||= self.class.new('drag_source', self, style).tap do |proxy|
|
318
|
+
proxy.set_attribute(:transfer, :text)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
def ensure_drop_target_proxy(style=[])
|
323
|
+
@drop_target_proxy ||= self.class.new('drop_target', self, style).tap do |proxy|
|
324
|
+
proxy.set_attribute(:transfer, :text)
|
325
|
+
proxy.on_drag_enter { |event|
|
326
|
+
event.detail = DNDProxy[:drop_copy]
|
327
|
+
}
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
280
331
|
# TODO eliminate duplication in the following methods perhaps by relying on exceptions
|
281
332
|
|
282
333
|
def can_handle_observation_request?(observation_request)
|
@@ -286,9 +337,31 @@ module Glimmer
|
|
286
337
|
SWTProxy.has_constant?(constant_name)
|
287
338
|
elsif observation_request.start_with?('on_')
|
288
339
|
event = observation_request.sub(/^on_/, '')
|
289
|
-
can_add_listener?(event)
|
290
|
-
|
291
|
-
|
340
|
+
can_add_listener?(event) || can_handle_drag_observation_request?(observation_request) || can_handle_drop_observation_request?(observation_request)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
def can_handle_drag_observation_request?(observation_request)
|
345
|
+
return false unless swt_widget.is_a?(Control)
|
346
|
+
potential_drag_source = @drag_source_proxy.nil?
|
347
|
+
ensure_drag_source_proxy
|
348
|
+
@drag_source_proxy.can_handle_observation_request?(observation_request).tap do |result|
|
349
|
+
if potential_drag_source && !result
|
350
|
+
@drag_source_proxy.swt_widget.dispose
|
351
|
+
@drag_source_proxy = nil
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
def can_handle_drop_observation_request?(observation_request)
|
357
|
+
return false unless swt_widget.is_a?(Control)
|
358
|
+
potential_drop_target = @drop_target_proxy.nil?
|
359
|
+
ensure_drop_target_proxy
|
360
|
+
@drop_target_proxy.can_handle_observation_request?(observation_request).tap do |result|
|
361
|
+
if potential_drop_target && !result
|
362
|
+
@drop_target_proxy.swt_widget.dispose
|
363
|
+
@drop_target_proxy = nil
|
364
|
+
end
|
292
365
|
end
|
293
366
|
end
|
294
367
|
|
@@ -298,7 +371,14 @@ module Glimmer
|
|
298
371
|
add_swt_event_listener(constant_name, &block)
|
299
372
|
elsif observation_request.start_with?('on_')
|
300
373
|
event = observation_request.sub(/^on_/, '')
|
301
|
-
|
374
|
+
if can_add_listener?(event)
|
375
|
+
event = observation_request.sub(/^on_/, '')
|
376
|
+
add_listener(event, &block)
|
377
|
+
elsif can_handle_drag_observation_request?(observation_request)
|
378
|
+
@drag_source_proxy&.handle_observation_request(observation_request, &block)
|
379
|
+
elsif can_handle_drop_observation_request?(observation_request)
|
380
|
+
@drop_target_proxy&.handle_observation_request(observation_request, &block)
|
381
|
+
end
|
302
382
|
end
|
303
383
|
end
|
304
384
|
|
@@ -310,12 +390,24 @@ module Glimmer
|
|
310
390
|
|
311
391
|
def style(underscored_widget_name, styles)
|
312
392
|
styles = [styles].flatten.compact
|
313
|
-
styles.empty?
|
393
|
+
if styles.empty?
|
394
|
+
default_style(underscored_widget_name)
|
395
|
+
else
|
396
|
+
begin
|
397
|
+
SWTProxy[*styles]
|
398
|
+
rescue
|
399
|
+
DNDProxy[*styles]
|
400
|
+
end
|
401
|
+
end
|
314
402
|
end
|
315
403
|
|
316
404
|
def default_style(underscored_widget_name)
|
317
405
|
styles = DEFAULT_STYLES[underscored_widget_name] || [:none]
|
318
|
-
SWTProxy[styles]
|
406
|
+
SWTProxy[styles] rescue DNDProxy[styles]
|
407
|
+
end
|
408
|
+
|
409
|
+
def ruby_attribute_setter(attribute_name)
|
410
|
+
"#{attribute_name}="
|
319
411
|
end
|
320
412
|
|
321
413
|
def attribute_setter(attribute_name)
|
@@ -339,7 +431,7 @@ module Glimmer
|
|
339
431
|
def add_listener(underscored_listener_name, &block)
|
340
432
|
widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
|
341
433
|
widget_listener_proxy = nil
|
342
|
-
safe_block = lambda { |event| block.call(event) unless @swt_widget.isDisposed }
|
434
|
+
safe_block = lambda { |event| block.call(event) unless @swt_widget.isDisposed }
|
343
435
|
listener = listener_class.new(listener_method => safe_block)
|
344
436
|
@swt_widget.send(widget_add_listener_method, listener)
|
345
437
|
widget_listener_proxy = WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: listener, widget_add_listener_method: widget_add_listener_method, swt_listener_class: listener_class, swt_listener_method: listener_method)
|
@@ -416,6 +508,38 @@ module Glimmer
|
|
416
508
|
}
|
417
509
|
end
|
418
510
|
|
511
|
+
def drag_source_style=(style)
|
512
|
+
ensure_drag_source_proxy(style)
|
513
|
+
end
|
514
|
+
|
515
|
+
def drop_target_style=(style)
|
516
|
+
ensure_drop_target_proxy(style)
|
517
|
+
end
|
518
|
+
|
519
|
+
def drag_source_transfer=(args)
|
520
|
+
args = args.first if !args.empty? && args.first.is_a?(ArrayJavaProxy)
|
521
|
+
ensure_drag_source_proxy
|
522
|
+
@drag_source_proxy.set_attribute(:transfer, args)
|
523
|
+
end
|
524
|
+
|
525
|
+
def drop_target_transfer=(args)
|
526
|
+
args = args.first if !args.empty? && args.first.is_a?(ArrayJavaProxy)
|
527
|
+
ensure_drop_target_proxy
|
528
|
+
@drop_target_proxy.set_attribute(:transfer, args)
|
529
|
+
end
|
530
|
+
|
531
|
+
def drag_source_effect=(args)
|
532
|
+
args = args.first if args.is_a?(Array)
|
533
|
+
ensure_drag_source_proxy
|
534
|
+
@drag_source_proxy.set_attribute(:drag_source_effect, args)
|
535
|
+
end
|
536
|
+
|
537
|
+
def drop_target_effect=(args)
|
538
|
+
args = args.first if args.is_a?(Array)
|
539
|
+
ensure_drop_target_proxy
|
540
|
+
@drop_target_proxy.set_attribute(:drop_target_effect, args)
|
541
|
+
end
|
542
|
+
|
419
543
|
def apply_property_type_converters(attribute_name, args)
|
420
544
|
if args.count == 1
|
421
545
|
value = args.first
|
@@ -478,6 +602,25 @@ module Glimmer
|
|
478
602
|
value.to_s
|
479
603
|
end
|
480
604
|
end,
|
605
|
+
:transfer => lambda do |value|
|
606
|
+
value = value.first if value.is_a?(Array) && value.size == 1 && value.first.is_a?(Array)
|
607
|
+
transfer_object_extrapolator = lambda do |transfer_name|
|
608
|
+
transfer_type = "#{transfer_name.to_s.camelcase(:upper)}Transfer".to_sym
|
609
|
+
transfer_type_alternative = "#{transfer_name.to_s.upcase}Transfer".to_sym
|
610
|
+
transfer_class = org.eclipse.swt.dnd.const_get(transfer_type) rescue org.eclipse.swt.dnd.const_get(transfer_type_alternative)
|
611
|
+
transfer_class.getInstance
|
612
|
+
end
|
613
|
+
result = value
|
614
|
+
if value.is_a?(Symbol) || value.is_a?(String)
|
615
|
+
result = [transfer_object_extrapolator.call(value)]
|
616
|
+
elsif value.is_a?(Array)
|
617
|
+
result = value.map do |transfer_name|
|
618
|
+
transfer_object_extrapolator.call(transfer_name)
|
619
|
+
end
|
620
|
+
end
|
621
|
+
result = result.to_java(Transfer) unless result.is_a?(ArrayJavaProxy)
|
622
|
+
result
|
623
|
+
end,
|
481
624
|
:visible => lambda do |value|
|
482
625
|
!!value
|
483
626
|
end,
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-swt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 0.9.
|
18
|
+
version: 0.9.4
|
19
19
|
name: glimmer
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.9.
|
26
|
+
version: 0.9.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.8.
|
60
|
+
version: 0.8.2
|
61
61
|
name: puts_debuggerer
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
@@ -65,7 +65,27 @@ dependencies:
|
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.8.
|
68
|
+
version: 0.8.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.2.4
|
75
|
+
- - "<"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.0.0
|
78
|
+
name: text-table
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.2.4
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 2.0.0
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
90
|
requirement: !ruby/object:Gem::Requirement
|
71
91
|
requirements:
|
@@ -194,7 +214,49 @@ dependencies:
|
|
194
214
|
- - "~>"
|
195
215
|
- !ruby/object:Gem::Version
|
196
216
|
version: 3.5.0
|
197
|
-
|
217
|
+
- !ruby/object:Gem::Dependency
|
218
|
+
requirement: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - '='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 0.8.23
|
223
|
+
name: coveralls
|
224
|
+
type: :development
|
225
|
+
prerelease: false
|
226
|
+
version_requirements: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - '='
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: 0.8.23
|
231
|
+
- !ruby/object:Gem::Dependency
|
232
|
+
requirement: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 0.16.1
|
237
|
+
name: simplecov
|
238
|
+
type: :development
|
239
|
+
prerelease: false
|
240
|
+
version_requirements: !ruby/object:Gem::Requirement
|
241
|
+
requirements:
|
242
|
+
- - "~>"
|
243
|
+
- !ruby/object:Gem::Version
|
244
|
+
version: 0.16.1
|
245
|
+
- !ruby/object:Gem::Dependency
|
246
|
+
requirement: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - "~>"
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: 0.7.0
|
251
|
+
name: simplecov-lcov
|
252
|
+
type: :development
|
253
|
+
prerelease: false
|
254
|
+
version_requirements: !ruby/object:Gem::Requirement
|
255
|
+
requirements:
|
256
|
+
- - "~>"
|
257
|
+
- !ruby/object:Gem::Version
|
258
|
+
version: 0.7.0
|
259
|
+
description: Glimmer DSL for SWT (Desktop GUI) - JRuby on SWT
|
198
260
|
email: andy.am@gmail.com
|
199
261
|
executables:
|
200
262
|
- glimmer
|
@@ -230,6 +292,7 @@ files:
|
|
230
292
|
- lib/glimmer/dsl/swt/data_binding_expression.rb
|
231
293
|
- lib/glimmer/dsl/swt/dialog_expression.rb
|
232
294
|
- lib/glimmer/dsl/swt/display_expression.rb
|
295
|
+
- lib/glimmer/dsl/swt/dnd_expression.rb
|
233
296
|
- lib/glimmer/dsl/swt/dsl.rb
|
234
297
|
- lib/glimmer/dsl/swt/exec_expression.rb
|
235
298
|
- lib/glimmer/dsl/swt/layout_data_expression.rb
|
@@ -254,9 +317,11 @@ files:
|
|
254
317
|
- lib/glimmer/launcher.rb
|
255
318
|
- lib/glimmer/package.rb
|
256
319
|
- lib/glimmer/rake_task.rb
|
320
|
+
- lib/glimmer/rake_task/list.rb
|
257
321
|
- lib/glimmer/scaffold.rb
|
258
322
|
- lib/glimmer/swt/color_proxy.rb
|
259
323
|
- lib/glimmer/swt/display_proxy.rb
|
324
|
+
- lib/glimmer/swt/dnd_proxy.rb
|
260
325
|
- lib/glimmer/swt/font_proxy.rb
|
261
326
|
- lib/glimmer/swt/layout_data_proxy.rb
|
262
327
|
- lib/glimmer/swt/layout_proxy.rb
|
@@ -264,6 +329,7 @@ files:
|
|
264
329
|
- lib/glimmer/swt/message_box_proxy.rb
|
265
330
|
- lib/glimmer/swt/packages.rb
|
266
331
|
- lib/glimmer/swt/shell_proxy.rb
|
332
|
+
- lib/glimmer/swt/style_constantizable.rb
|
267
333
|
- lib/glimmer/swt/swt_proxy.rb
|
268
334
|
- lib/glimmer/swt/tab_item_proxy.rb
|
269
335
|
- lib/glimmer/swt/table_proxy.rb
|