glimmer-dsl-swt 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b097c051f15a0fd1a52677fd65d542a67532a2e1a51fc928fc22acd8e729953
4
- data.tar.gz: 203b4cd8bad18d912e83067fce0175e5667f7db503cfa67bf9beac6e72752508
3
+ metadata.gz: 70cb97f3e5f058b49cb24ddbe87281e9db925f6708e03d9d520545878608a3e7
4
+ data.tar.gz: 73ad3cf16e2a30f4227135ce0eed679a40d3ca222780b1f9b998535274eed720
5
5
  SHA512:
6
- metadata.gz: edb0568d6bcf252b89332050f2de545917bb6ce2bd687dae961e1aa1afb66d9a051420ea00745db028a93d3869ab5ca9229192d806daa3e0db652a5fffdc1df5
7
- data.tar.gz: 745dae7d8a1999c0267b4d4e7a66a37209bb59c29e4c0f9c7ccf31dc87b2bcd0903eef7c2a0bc6cb46a498200468ce9bcb28d1b5752b54a5a0340be350793e0e
6
+ metadata.gz: 0f0842bb53f0f8703970924e6f21374d1e64c955fd7a7135b4c864d7158221285a5ef9c89b7e01508d1393a5130388d79659672ad0fa4e1c35b4363bb772c47a
7
+ data.tar.gz: 65c239a07dd7a216873fbe6f56842c5b2e15ea9d6aa3a77ac301b3e064f2c6521afcb07731ba0a5df20fe7ea877f25716581386621ac987c00a73c77da0988a3
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
- # <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 /> Glimmer DSL for SWT 0.1.3 (Desktop GUI)
1
+ # <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 /> Glimmer DSL for SWT 0.2.0 (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
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)
5
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)
6
6
 
7
- [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.
8
10
 
9
11
  You may find full setup/usage instructions at the main [Glimmer project page](https://github.com/AndyObtiva/glimmer).
10
12
 
@@ -13,6 +15,23 @@ Other Glimmer DSL gems:
13
15
  - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
14
16
  - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
15
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
+
16
35
  ## Help
17
36
 
18
37
  ### Issues
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -2,9 +2,14 @@ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
2
2
 
3
3
  # External requires
4
4
  require 'java'
5
- require 'nested_inherited_jruby_include_package'
6
- require 'super_module'
7
- require 'glimmer'
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'
@@ -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))
@@ -31,8 +31,8 @@ module Glimmer
31
31
  "list" => [:border, :v_scroll],
32
32
  "button" => [:push],
33
33
  "menu_item" => [:push],
34
- "drag_source" => DND::DROP_COPY,
35
- "drop_target" => DND::DROP_COPY,
34
+ "drag_source" => [:drop_copy],
35
+ "drop_target" => [:drop_copy],
36
36
  }
37
37
 
38
38
  DEFAULT_INITIALIZERS = {
@@ -51,7 +51,7 @@ module Glimmer
51
51
  end,
52
52
  }
53
53
 
54
- attr_reader :swt_widget
54
+ attr_reader :swt_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer
55
55
 
56
56
  # Initializes a new SWT Widget
57
57
  #
@@ -84,7 +84,7 @@ module Glimmer
84
84
  if widget_custom_attribute
85
85
  @swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
86
86
  else
87
- @swt_widget.respond_to?(attribute_setter(attribute_name), args)
87
+ @swt_widget.respond_to?(attribute_setter(attribute_name), args) || respond_to?(ruby_attribute_setter(attribute_name), args)
88
88
  end
89
89
  end
90
90
 
@@ -92,9 +92,11 @@ module Glimmer
92
92
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
93
93
  if widget_custom_attribute
94
94
  widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
95
- else
95
+ elsif @swt_widget.respond_to?(attribute_setter(attribute_name), args)
96
96
  apply_property_type_converters(attribute_name, args)
97
97
  @swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
98
+ else
99
+ send(ruby_attribute_setter(attribute_name), args)
98
100
  end
99
101
  end
100
102
 
@@ -285,6 +287,21 @@ module Glimmer
285
287
  # TODO consider implementing if remove_observer is needed (consumers can remove listener via SWT API)
286
288
  end
287
289
 
290
+ def ensure_drag_source_proxy(style=[])
291
+ @drag_source_proxy ||= self.class.new('drag_source', self, style).tap do |proxy|
292
+ proxy.set_attribute(:transfer, :text)
293
+ end
294
+ end
295
+
296
+ def ensure_drop_target_proxy(style=[])
297
+ @drop_target_proxy ||= self.class.new('drop_target', self, style).tap do |proxy|
298
+ proxy.set_attribute(:transfer, :text)
299
+ proxy.on_drag_enter { |event|
300
+ event.detail = DNDProxy[:drop_copy]
301
+ }
302
+ end
303
+ end
304
+
288
305
  # TODO eliminate duplication in the following methods perhaps by relying on exceptions
289
306
 
290
307
  def can_handle_observation_request?(observation_request)
@@ -294,9 +311,31 @@ module Glimmer
294
311
  SWTProxy.has_constant?(constant_name)
295
312
  elsif observation_request.start_with?('on_')
296
313
  event = observation_request.sub(/^on_/, '')
297
- can_add_listener?(event)
298
- else
299
- false
314
+ can_add_listener?(event) || can_handle_drag_observation_request?(observation_request) || can_handle_drop_observation_request?(observation_request)
315
+ end
316
+ end
317
+
318
+ def can_handle_drag_observation_request?(observation_request)
319
+ return false unless swt_widget.is_a?(Control)
320
+ potential_drag_source = @drag_source_proxy.nil?
321
+ ensure_drag_source_proxy
322
+ @drag_source_proxy.can_handle_observation_request?(observation_request).tap do |result|
323
+ if potential_drag_source && !result
324
+ @drag_source_proxy.swt_widget.dispose
325
+ @drag_source_proxy = nil
326
+ end
327
+ end
328
+ end
329
+
330
+ def can_handle_drop_observation_request?(observation_request)
331
+ return false unless swt_widget.is_a?(Control)
332
+ potential_drop_target = @drop_target_proxy.nil?
333
+ ensure_drop_target_proxy
334
+ @drop_target_proxy.can_handle_observation_request?(observation_request).tap do |result|
335
+ if potential_drop_target && !result
336
+ @drop_target_proxy.swt_widget.dispose
337
+ @drop_target_proxy = nil
338
+ end
300
339
  end
301
340
  end
302
341
 
@@ -306,7 +345,14 @@ module Glimmer
306
345
  add_swt_event_listener(constant_name, &block)
307
346
  elsif observation_request.start_with?('on_')
308
347
  event = observation_request.sub(/^on_/, '')
309
- add_listener(event, &block)
348
+ if can_add_listener?(event)
349
+ event = observation_request.sub(/^on_/, '')
350
+ add_listener(event, &block)
351
+ elsif can_handle_drag_observation_request?(observation_request)
352
+ @drag_source_proxy&.handle_observation_request(observation_request, &block)
353
+ elsif can_handle_drop_observation_request?(observation_request)
354
+ @drop_target_proxy&.handle_observation_request(observation_request, &block)
355
+ end
310
356
  end
311
357
  end
312
358
 
@@ -331,7 +377,11 @@ module Glimmer
331
377
 
332
378
  def default_style(underscored_widget_name)
333
379
  styles = DEFAULT_STYLES[underscored_widget_name] || [:none]
334
- SWTProxy[styles]
380
+ SWTProxy[styles] rescue DNDProxy[styles]
381
+ end
382
+
383
+ def ruby_attribute_setter(attribute_name)
384
+ "#{attribute_name}="
335
385
  end
336
386
 
337
387
  def attribute_setter(attribute_name)
@@ -355,7 +405,7 @@ module Glimmer
355
405
  def add_listener(underscored_listener_name, &block)
356
406
  widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
357
407
  widget_listener_proxy = nil
358
- safe_block = lambda { |event| block.call(event) unless @swt_widget.isDisposed }
408
+ safe_block = lambda { |event| block.call(event) unless @swt_widget.isDisposed }
359
409
  listener = listener_class.new(listener_method => safe_block)
360
410
  @swt_widget.send(widget_add_listener_method, listener)
361
411
  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)
@@ -432,6 +482,38 @@ module Glimmer
432
482
  }
433
483
  end
434
484
 
485
+ def drag_source_style=(style)
486
+ ensure_drag_source_proxy(style)
487
+ end
488
+
489
+ def drop_target_style=(style)
490
+ ensure_drop_target_proxy(style)
491
+ end
492
+
493
+ def drag_source_transfer=(args)
494
+ args = args.first if !args.empty? && args.first.is_a?(ArrayJavaProxy)
495
+ ensure_drag_source_proxy
496
+ @drag_source_proxy.set_attribute(:transfer, args)
497
+ end
498
+
499
+ def drop_target_transfer=(args)
500
+ args = args.first if !args.empty? && args.first.is_a?(ArrayJavaProxy)
501
+ ensure_drop_target_proxy
502
+ @drop_target_proxy.set_attribute(:transfer, args)
503
+ end
504
+
505
+ def drag_source_effect=(args)
506
+ args = args.first if args.is_a?(Array)
507
+ ensure_drag_source_proxy
508
+ @drag_source_proxy.set_attribute(:drag_source_effect, args)
509
+ end
510
+
511
+ def drop_target_effect=(args)
512
+ args = args.first if args.is_a?(Array)
513
+ ensure_drop_target_proxy
514
+ @drop_target_proxy.set_attribute(:drop_target_effect, args)
515
+ end
516
+
435
517
  def apply_property_type_converters(attribute_name, args)
436
518
  if args.count == 1
437
519
  value = args.first
@@ -495,6 +577,7 @@ module Glimmer
495
577
  end
496
578
  end,
497
579
  :transfer => lambda do |value|
580
+ value = value.first if value.is_a?(Array) && value.size == 1 && value.first.is_a?(Array)
498
581
  transfer_object_extrapolator = lambda do |transfer_name|
499
582
  transfer_type = "#{transfer_name.to_s.camelcase(:upper)}Transfer".to_sym
500
583
  transfer_type_alternative = "#{transfer_name.to_s.upcase}Transfer".to_sym
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-28 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -292,6 +292,7 @@ files:
292
292
  - lib/glimmer/dsl/swt/data_binding_expression.rb
293
293
  - lib/glimmer/dsl/swt/dialog_expression.rb
294
294
  - lib/glimmer/dsl/swt/display_expression.rb
295
+ - lib/glimmer/dsl/swt/dnd_expression.rb
295
296
  - lib/glimmer/dsl/swt/dsl.rb
296
297
  - lib/glimmer/dsl/swt/exec_expression.rb
297
298
  - lib/glimmer/dsl/swt/layout_data_expression.rb