glimmer-dsl-swt 4.17.9.0 → 4.17.10.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -69,7 +69,7 @@ module Glimmer
69
69
  old_tree_item_expansion_by_data = old_tree_items.reduce({}) {|hash, ti| hash.merge(ti.getData => ti.getExpanded)}
70
70
  old_tree_items.each do |tree_item|
71
71
  tree_item.getData('observer_registrations').each(&:unregister)
72
- end
72
+ end
73
73
  parent.swt_widget.items.each(&:dispose)
74
74
  parent.swt_widget.removeAll
75
75
  populate_tree_node(model_tree_root_node, parent.swt_widget, tree_properties)
@@ -85,9 +85,9 @@ module Glimmer
85
85
  array + [observe(model_tree_node, key_value_pair.last)]
86
86
  end
87
87
 
88
- tree_item.setData('observer_registrations', observer_registrations)
89
- tree_item.setData(model_tree_node)
90
- tree_item.setText((model_tree_node && model_tree_node.send(tree_properties[:text])).to_s)
88
+ tree_item.set_data('observer_registrations', observer_registrations)
89
+ tree_item.set_data(model_tree_node)
90
+ tree_item.text = (model_tree_node && model_tree_node.send(tree_properties[:text])).to_s
91
91
  [model_tree_node && model_tree_node.send(tree_properties[:children])].flatten.to_a.compact.each do |child|
92
92
  populate_tree_node(child, tree_item, tree_properties)
93
93
  end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -31,12 +31,12 @@ module Glimmer
31
31
  OPERATING_SYSTEMS_SUPPORTED = ["mac", "windows", "linux"]
32
32
 
33
33
  TEXT_USAGE = <<~MULTI_LINE_STRING
34
- Glimmer (Ruby Desktop Development GUI Library) - JRuby Gem: glimmer-dsl-swt v#{File.read(File.expand_path('../../../VERSION', __FILE__))}
34
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v#{File.read(File.expand_path('../../../VERSION', __FILE__))}
35
35
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
36
36
 
37
- Runs Glimmer applications and tasks.
37
+ Runs Glimmer applications and tasks.
38
38
 
39
- When applications are specified, they are run using JRuby,
39
+ When applications are specified, they are run using JRuby,
40
40
  automatically preloading the glimmer Ruby gem and SWT jar dependency.
41
41
 
42
42
  Optionally, extra Glimmer options, JRuby options, and/or environment variables may be passed in.
@@ -112,7 +112,7 @@ module Glimmer
112
112
  def launch(application, jruby_options: [], env_vars: {}, glimmer_options: {})
113
113
  jruby_options_string = jruby_options.join(' ') + ' ' if jruby_options.any?
114
114
  env_vars = env_vars.merge(glimmer_option_env_vars(glimmer_options))
115
- env_vars_string = env_vars.map do |k,v|
115
+ env_vars_string = env_vars.map do |k,v|
116
116
  if OS.windows? && ENV['PROMPT'] # detect command prompt (or powershell)
117
117
  "set #{k}=#{v} && "
118
118
  else
@@ -224,8 +224,8 @@ module Glimmer
224
224
  task_name = task.name_with_args.sub('glimmer:', '')
225
225
  line = "glimmer #{task_name.ljust(max_task_size)} # #{task.comment}"
226
226
  bound = TTY::Screen.width - 6
227
- line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
228
- end
227
+ line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
228
+ end
229
229
  end
230
230
  end
231
231
 
@@ -88,18 +88,26 @@ module Glimmer
88
88
 
89
89
  # Opens shell and starts SWT's UI thread event loop
90
90
  def open
91
+ open_only
92
+ start_event_loop unless nested?
93
+ end
94
+ alias show open
95
+
96
+ # Opens without starting the event loop.
97
+ def open_only
91
98
  if @opened_before
92
99
  @swt_widget.setVisible(true)
93
- # notify_observers('visible')
94
100
  else
95
101
  @opened_before = true
96
102
  @swt_widget.pack
97
103
  center
98
104
  @swt_widget.open
99
- start_event_loop
100
105
  end
101
106
  end
102
- alias show open
107
+
108
+ def nested?
109
+ !parent.nil?
110
+ end
103
111
 
104
112
  def hide
105
113
  @swt_widget.setVisible(false)
@@ -113,6 +121,10 @@ module Glimmer
113
121
  def visible=(visibility)
114
122
  visibility ? show : hide
115
123
  end
124
+
125
+ def include_focus_control?
126
+ DisplayProxy.instance.focus_control&.shell == swt_widget
127
+ end
116
128
 
117
129
  def pack
118
130
  @swt_widget.pack
@@ -169,6 +181,9 @@ module Glimmer
169
181
  super
170
182
  end
171
183
  end
184
+
172
185
  end
186
+
173
187
  end
188
+
174
189
  end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -27,17 +27,12 @@ module Glimmer
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
29
  class StyledTextProxy < WidgetProxy
30
- def set_attribute(attribute_name, *args)
31
- if attribute_name.to_s == 'selection'
32
- if args.first
33
- async_exec { @swt_widget.setCaretOffset(args.first.x) }
34
- async_exec { @swt_widget.setSelection(args.first) }
35
- end
36
- else
37
- super(attribute_name, *args)
38
- end
30
+ def initialize(*args)
31
+ super
32
+ on_modify_text { |event|
33
+ @last_modify_text = text
34
+ }
39
35
  end
40
-
41
36
  end
42
37
  end
43
38
  end
@@ -39,6 +39,7 @@ module Glimmer
39
39
  #
40
40
  # Follows the Proxy Design Pattern
41
41
  class TabItemProxy < WidgetProxy
42
+ ATTRIBUTES = %w[text image]
42
43
  include_package 'org.eclipse.swt.widgets'
43
44
 
44
45
  attr_reader :widget_proxy, :swt_tab_item
@@ -51,7 +52,7 @@ module Glimmer
51
52
  end
52
53
 
53
54
  def has_attribute?(attribute_name, *args)
54
- if attribute_name.to_s == "text"
55
+ if ATTRIBUTES.include?(attribute_name.to_s)
55
56
  true
56
57
  else
57
58
  super(attribute_name, *args)
@@ -63,6 +64,8 @@ module Glimmer
63
64
  if attribute_name.to_s == "text"
64
65
  text_value = args[0]
65
66
  @swt_tab_item.setText text_value
67
+ elsif attribute_name.to_s == "image"
68
+ widget_proxy.set_attribute('image', *args)
66
69
  else
67
70
  super(attribute_name, *args)
68
71
  end
@@ -71,6 +74,8 @@ module Glimmer
71
74
  def get_attribute(attribute_name)
72
75
  if attribute_name.to_s == "text"
73
76
  @swt_tab_item.getText
77
+ elsif attribute_name.to_s == "image"
78
+ widget_proxy.get_attribute('image')
74
79
  else
75
80
  super(attribute_name)
76
81
  end
@@ -20,6 +20,7 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  require 'glimmer/swt/widget_proxy'
23
+ require 'glimmer/swt/swt_proxy'
23
24
 
24
25
  module Glimmer
25
26
  module SWT
@@ -34,7 +35,7 @@ module Glimmer
34
35
  @no_sort = args.delete(:no_sort)
35
36
  super
36
37
  on_widget_selected do |event|
37
- parent.sort_by_column(self)
38
+ parent.sort_by_column!(self)
38
39
  end unless no_sort?
39
40
  end
40
41
 
@@ -42,10 +43,15 @@ module Glimmer
42
43
  @sort_property = args unless args.empty?
43
44
  end
44
45
 
46
+ # Sets editor (e.g. combo)
45
47
  def editor=(args)
46
48
  @editor = args
47
49
  end
48
50
 
51
+ def editable?
52
+ !@editor&.include?(:none)
53
+ end
54
+
49
55
  end
50
56
  end
51
57
  end
@@ -132,6 +132,69 @@ module Glimmer
132
132
  }
133
133
  end,
134
134
  },
135
+ date: {
136
+ widget_value_property: :date_time,
137
+ editor_gui: lambda do |args, model, property, table_proxy|
138
+ first_time = true
139
+ table_proxy.table_editor.minimumHeight = 25
140
+ date(*args) {
141
+ date_time model.send(property)
142
+ focus true
143
+ on_focus_lost {
144
+ table_proxy.finish_edit!
145
+ }
146
+ on_key_pressed { |key_event|
147
+ if key_event.keyCode == swt(:cr)
148
+ table_proxy.finish_edit!
149
+ elsif key_event.keyCode == swt(:esc)
150
+ table_proxy.cancel_edit!
151
+ end
152
+ }
153
+ }
154
+ end,
155
+ },
156
+ date_drop_down: {
157
+ widget_value_property: :date_time,
158
+ editor_gui: lambda do |args, model, property, table_proxy|
159
+ first_time = true
160
+ table_proxy.table_editor.minimumHeight = 25
161
+ date_drop_down(*args) {
162
+ date_time model.send(property)
163
+ focus true
164
+ on_focus_lost {
165
+ table_proxy.finish_edit!
166
+ }
167
+ on_key_pressed { |key_event|
168
+ if key_event.keyCode == swt(:cr)
169
+ table_proxy.finish_edit!
170
+ elsif key_event.keyCode == swt(:esc)
171
+ table_proxy.cancel_edit!
172
+ end
173
+ }
174
+ }
175
+ end,
176
+ },
177
+ time: {
178
+ widget_value_property: :date_time,
179
+ editor_gui: lambda do |args, model, property, table_proxy|
180
+ first_time = true
181
+ table_proxy.table_editor.minimumHeight = 25
182
+ time(*args) {
183
+ date_time model.send(property)
184
+ focus true
185
+ on_focus_lost {
186
+ table_proxy.finish_edit!
187
+ }
188
+ on_key_pressed { |key_event|
189
+ if key_event.keyCode == swt(:cr)
190
+ table_proxy.finish_edit!
191
+ elsif key_event.keyCode == swt(:esc)
192
+ table_proxy.cancel_edit!
193
+ end
194
+ }
195
+ }
196
+ end,
197
+ },
135
198
  radio: {
136
199
  widget_value_property: :selection,
137
200
  editor_gui: lambda do |args, model, property, table_proxy|
@@ -174,11 +237,6 @@ module Glimmer
174
237
  table_proxy.cancel_edit!
175
238
  end
176
239
  }
177
- # on_widget_selected {
178
- # if !OS.windows? || !first_time || first_time && model.send(property) != table_editor_widget_proxy.swt_widget.text
179
- # table_proxy.finish_edit!
180
- # end
181
- # }
182
240
  }
183
241
  table_editor_widget_proxy
184
242
  end,
@@ -211,36 +269,16 @@ module Glimmer
211
269
  swt_widget.data
212
270
  end
213
271
 
214
- def sort_by_column(table_column_proxy)
215
- index = swt_widget.columns.to_a.index(table_column_proxy.swt_widget)
216
- new_sort_property = table_column_proxy.sort_property || [column_properties[index]]
217
- if new_sort_property.size == 1 && !additional_sort_properties.to_a.empty?
218
- selected_additional_sort_properties = additional_sort_properties.clone
219
- if selected_additional_sort_properties.include?(new_sort_property.first)
220
- selected_additional_sort_properties.delete(new_sort_property.first)
221
- new_sort_property += selected_additional_sort_properties
222
- else
223
- new_sort_property += additional_sort_properties
224
- end
225
- end
226
-
227
- @sort_direction = @sort_direction.nil? || @sort_property != new_sort_property || @sort_direction == :descending ? :ascending : :descending
228
- swt_widget.sort_direction = @sort_direction == :ascending ? SWTProxy[:up] : SWTProxy[:down]
229
-
230
- @sort_property = new_sort_property
231
- swt_widget.sort_column = table_column_proxy.swt_widget
232
-
233
- @sort_by_block = nil
234
- @sort_block = nil
235
- @sort_type = nil
236
- if table_column_proxy.sort_by_block
237
- @sort_by_block = table_column_proxy.sort_by_block
238
- elsif table_column_proxy.sort_block
239
- @sort_block = table_column_proxy.sort_block
240
- else
241
- detect_sort_type
242
- end
243
- sort
272
+ def sort_block=(comparator)
273
+ @sort_block = comparator
274
+ end
275
+
276
+ def sort_by_block=(property_picker)
277
+ @sort_by_block = property_picker
278
+ end
279
+
280
+ def sort_property=(new_sort_property)
281
+ @sort_property = [new_sort_property].flatten.compact
244
282
  end
245
283
 
246
284
  def detect_sort_type
@@ -259,24 +297,63 @@ module Glimmer
259
297
  end
260
298
  end
261
299
 
262
- def additional_sort_properties=(args)
263
- @additional_sort_properties = args unless args.empty?
300
+ def column_sort_properties
301
+ column_properties.zip(table_column_proxies.map(&:sort_property)).map do |pair|
302
+ [pair.compact.last].flatten.compact
303
+ end
264
304
  end
265
305
 
266
- def editor=(args)
267
- @editor = args
306
+ # Sorts by specified TableColumnProxy object. If nil, it uses the table default sort instead.
307
+ def sort_by_column!(table_column_proxy=nil)
308
+ index = swt_widget.columns.to_a.index(table_column_proxy.swt_widget) unless table_column_proxy.nil?
309
+ new_sort_property = table_column_proxy.nil? ? @sort_property : table_column_proxy.sort_property || [column_properties[index]]
310
+ return if table_column_proxy.nil? && new_sort_property.nil? && @sort_block.nil? && @sort_by_block.nil?
311
+ if new_sort_property && table_column_proxy.nil? && new_sort_property.size == 1 && (index = column_sort_properties.index(new_sort_property))
312
+ table_column_proxy = table_column_proxies[index]
313
+ end
314
+ if new_sort_property && new_sort_property.size == 1 && !additional_sort_properties.to_a.empty?
315
+ selected_additional_sort_properties = additional_sort_properties.clone
316
+ if selected_additional_sort_properties.include?(new_sort_property.first)
317
+ selected_additional_sort_properties.delete(new_sort_property.first)
318
+ new_sort_property += selected_additional_sort_properties
319
+ else
320
+ new_sort_property += additional_sort_properties
321
+ end
322
+ end
323
+
324
+ @sort_direction = @sort_direction.nil? || @sort_property.first != new_sort_property.first || @sort_direction == :descending ? :ascending : :descending
325
+ swt_widget.sort_direction = @sort_direction == :ascending ? SWTProxy[:up] : SWTProxy[:down]
326
+
327
+ @sort_property = [new_sort_property].flatten.compact
328
+ table_column_index = column_properties.index(new_sort_property.to_s.to_sym)
329
+ table_column_proxy ||= table_column_proxies[table_column_index] if table_column_index
330
+ swt_widget.sort_column = table_column_proxy.swt_widget if table_column_proxy
331
+
332
+ if table_column_proxy
333
+ @sort_by_block = nil
334
+ @sort_block = nil
335
+ end
336
+ @sort_type = nil
337
+ if table_column_proxy&.sort_by_block
338
+ @sort_by_block = table_column_proxy.sort_by_block
339
+ elsif table_column_proxy&.sort_block
340
+ @sort_block = table_column_proxy.sort_block
341
+ else
342
+ detect_sort_type
343
+ end
344
+
345
+ sort!
268
346
  end
269
347
 
270
- def cells_for(model)
271
- column_properties.map {|property| model.send(property)}
348
+ def initial_sort!
349
+ sort_by_column!
272
350
  end
273
351
 
274
- def cells
275
- column_count = @table.column_properties.size
276
- swt_widget.items.map {|item| column_count.times.map {|i| item.get_text(i)} }
352
+ def additional_sort_properties=(args)
353
+ @additional_sort_properties = args unless args.empty?
277
354
  end
278
355
 
279
- def sort
356
+ def sort!
280
357
  return unless sort_property && (sort_type || sort_block || sort_by_block)
281
358
  array = model_binding.evaluate_property
282
359
  array = array.sort_by(&:hash) # this ensures consistent subsequent sorting in case there are equivalent sorts to avoid an infinite loop
@@ -305,6 +382,19 @@ module Glimmer
305
382
  model_binding.call(sorted_array)
306
383
  end
307
384
 
385
+ def editor=(args)
386
+ @editor = args
387
+ end
388
+
389
+ def cells_for(model)
390
+ column_properties.map {|property| model.send(property)}
391
+ end
392
+
393
+ def cells
394
+ column_count = @table.column_properties.size
395
+ swt_widget.items.map {|item| column_count.times.map {|i| item.get_text(i)} }
396
+ end
397
+
308
398
  # Performs a search for table items matching block condition
309
399
  # If no condition block is passed, returns all table items
310
400
  # Returns a Java TableItem array to easily set as selection on org.eclipse.swt.Table if needed
@@ -317,22 +407,16 @@ module Glimmer
317
407
  search
318
408
  end
319
409
 
320
- def widget_property_listener_installers
321
- super.merge({
322
- Java::OrgEclipseSwtWidgets::Table => {
323
- selection: lambda do |observer|
324
- on_widget_selected { |selection_event|
325
- observer.call(@swt_widget.getSelection)
326
- }
327
- end
328
- },
329
- })
330
- end
331
-
332
410
  def post_initialize_child(table_column_proxy)
333
411
  table_column_proxies << table_column_proxy
334
412
  end
335
413
 
414
+ def post_add_content
415
+ return if @initially_sorted
416
+ initial_sort!
417
+ @initially_sorted = true
418
+ end
419
+
336
420
  def table_column_proxies
337
421
  @table_column_proxies ||= []
338
422
  end
@@ -365,7 +449,8 @@ module Glimmer
365
449
  return if table_item.nil?
366
450
  model = table_item.data
367
451
  property = column_properties[column_index]
368
- @cancel_edit&.call if @edit_mode
452
+ cancel_edit!
453
+ return unless table_column_proxies[column_index].editable?
369
454
  action_taken = false
370
455
  @edit_mode = true
371
456
 
@@ -390,7 +475,7 @@ module Glimmer
390
475
  end
391
476
 
392
477
  @finish_edit = lambda do |event=nil|
393
- new_value = @table_editor_widget_proxy&.swt_widget&.send(widget_value_property)
478
+ new_value = @table_editor_widget_proxy&.send(widget_value_property)
394
479
  if table_item.isDisposed
395
480
  @cancel_edit.call
396
481
  elsif !new_value.nil? && !action_taken && !@edit_in_progress && !@cancel_in_progress