glimmer-dsl-swt 4.17.8.3 → 4.17.10.3

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
@@ -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
@@ -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
@@ -26,15 +26,15 @@ module Glimmer
26
26
  # Proxy for org.eclipse.swt.SWT
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
- class SWTProxy
30
- include StyleConstantizable
29
+ class SWTProxy
30
+ include StyleConstantizable
31
31
 
32
32
  class << self
33
33
  JAVA_IMPORT = 'org.eclipse.swt.SWT'
34
34
 
35
35
  java_import JAVA_IMPORT
36
36
 
37
- def constant_java_import
37
+ def constant_java_import
38
38
  JAVA_IMPORT
39
39
  end
40
40
 
@@ -53,8 +53,7 @@ module Glimmer
53
53
 
54
54
  EXTRA_STYLES = {
55
55
  NO_RESIZE: self[:shell_trim, :resize!, :max!],
56
- NO_SORT: -7,
57
- }
56
+ }
58
57
  end
59
58
  end
60
59
  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
@@ -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
@@ -20,10 +20,13 @@
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
26
- class TableColumnProxy < Glimmer::SWT::WidgetProxy
27
+ # A proxy object representing SWT TableColumn
28
+ # Accepts a :no_sort custom style to disable sorting on this column
29
+ class TableColumnProxy < Glimmer::SWT::WidgetProxy
27
30
  attr_reader :no_sort, :sort_property, :editor
28
31
  alias no_sort? no_sort
29
32
  attr_accessor :sort_block, :sort_by_block
@@ -32,7 +35,7 @@ module Glimmer
32
35
  @no_sort = args.delete(:no_sort)
33
36
  super
34
37
  on_widget_selected do |event|
35
- parent.sort_by_column(self)
38
+ parent.sort_by_column!(self)
36
39
  end unless no_sort?
37
40
  end
38
41
 
@@ -40,10 +43,15 @@ module Glimmer
40
43
  @sort_property = args unless args.empty?
41
44
  end
42
45
 
46
+ # Sets editor (e.g. combo)
43
47
  def editor=(args)
44
48
  @editor = args
45
49
  end
46
50
 
51
+ def editable?
52
+ !@editor&.include?(:none)
53
+ end
54
+
47
55
  end
48
56
  end
49
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|
@@ -155,30 +218,100 @@ module Glimmer
155
218
  }
156
219
  }
157
220
  end,
158
- }
221
+ },
222
+ spinner: {
223
+ widget_value_property: :selection,
224
+ editor_gui: lambda do |args, model, property, table_proxy|
225
+ first_time = true
226
+ table_proxy.table_editor.minimumHeight = 25
227
+ table_editor_widget_proxy = spinner(*args) {
228
+ selection model.send(property)
229
+ focus true
230
+ on_focus_lost {
231
+ table_proxy.finish_edit!
232
+ }
233
+ on_key_pressed { |key_event|
234
+ if key_event.keyCode == swt(:cr)
235
+ table_proxy.finish_edit!
236
+ elsif key_event.keyCode == swt(:esc)
237
+ table_proxy.cancel_edit!
238
+ end
239
+ }
240
+ }
241
+ table_editor_widget_proxy
242
+ end,
243
+ },
159
244
  }
160
245
  end
161
246
  end
162
247
 
163
- attr_reader :table_editor, :table_editor_widget_proxy, :sort_property, :sort_direction, :sort_block, :sort_type, :sort_by_block, :additional_sort_properties, :editor
248
+ attr_reader :table_editor, :table_editor_widget_proxy, :sort_property, :sort_direction, :sort_block, :sort_type, :sort_by_block, :additional_sort_properties, :editor, :editable, :initial_sort_property
164
249
  attr_accessor :column_properties
250
+ alias editable? editable
165
251
 
166
252
  def initialize(underscored_widget_name, parent, args)
253
+ @editable = args.delete(:editable)
167
254
  super
168
255
  @table_editor = TableEditor.new(swt_widget)
169
256
  @table_editor.horizontalAlignment = SWTProxy[:left]
170
257
  @table_editor.grabHorizontal = true
171
258
  @table_editor.minimumHeight = 20
259
+ if editable?
260
+ content {
261
+ on_mouse_up { |event|
262
+ edit_table_item(event.table_item, event.column_index)
263
+ }
264
+ }
265
+ end
172
266
  end
173
267
 
174
268
  def model_binding
175
269
  swt_widget.data
176
270
  end
177
271
 
178
- def sort_by_column(table_column_proxy)
179
- index = swt_widget.columns.to_a.index(table_column_proxy.swt_widget)
180
- new_sort_property = table_column_proxy.sort_property || [column_properties[index]]
181
- if new_sort_property.size == 1 && !additional_sort_properties.to_a.empty?
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
282
+ end
283
+
284
+ def detect_sort_type
285
+ @sort_type = sort_property.size.times.map { String }
286
+ array = model_binding.evaluate_property
287
+ sort_property.each_with_index do |a_sort_property, i|
288
+ values = array.map { |object| object.send(a_sort_property) }
289
+ value_classes = values.map(&:class).uniq
290
+ if value_classes.size == 1
291
+ @sort_type[i] = value_classes.first
292
+ elsif value_classes.include?(Integer)
293
+ @sort_type[i] = Integer
294
+ elsif value_classes.include?(Float)
295
+ @sort_type[i] = Float
296
+ end
297
+ end
298
+ end
299
+
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
304
+ end
305
+
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?
182
315
  selected_additional_sort_properties = additional_sort_properties.clone
183
316
  if selected_additional_sort_properties.include?(new_sort_property.first)
184
317
  selected_additional_sort_properties.delete(new_sort_property.first)
@@ -188,39 +321,32 @@ module Glimmer
188
321
  end
189
322
  end
190
323
 
191
- @sort_direction = @sort_direction.nil? || @sort_property != new_sort_property || @sort_direction == :descending ? :ascending : :descending
324
+ @sort_direction = @sort_direction.nil? || @sort_property.first != new_sort_property.first || @sort_direction == :descending ? :ascending : :descending
192
325
  swt_widget.sort_direction = @sort_direction == :ascending ? SWTProxy[:up] : SWTProxy[:down]
193
326
 
194
- @sort_property = new_sort_property
195
- swt_widget.sort_column = table_column_proxy.swt_widget
196
-
197
- @sort_by_block = nil
198
- @sort_block = nil
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
199
336
  @sort_type = nil
200
- if table_column_proxy.sort_by_block
337
+ if table_column_proxy&.sort_by_block
201
338
  @sort_by_block = table_column_proxy.sort_by_block
202
- elsif table_column_proxy.sort_block
339
+ elsif table_column_proxy&.sort_block
203
340
  @sort_block = table_column_proxy.sort_block
204
341
  else
205
342
  detect_sort_type
206
343
  end
207
- sort
344
+
345
+ sort!
208
346
  end
209
347
 
210
- def detect_sort_type
211
- @sort_type = sort_property.size.times.map { String }
212
- array = model_binding.evaluate_property
213
- sort_property.each_with_index do |a_sort_property, i|
214
- values = array.map { |object| object.send(a_sort_property) }
215
- value_classes = values.map(&:class).uniq
216
- if value_classes.size == 1
217
- @sort_type[i] = value_classes.first
218
- elsif value_classes.include?(Integer)
219
- @sort_type[i] = Integer
220
- elsif value_classes.include?(Float)
221
- @sort_type[i] = Float
222
- end
223
- end
348
+ def initial_sort!
349
+ sort_by_column!
224
350
  end
225
351
 
226
352
  def additional_sort_properties=(args)
@@ -240,7 +366,7 @@ module Glimmer
240
366
  swt_widget.items.map {|item| column_count.times.map {|i| item.get_text(i)} }
241
367
  end
242
368
 
243
- def sort
369
+ def sort!
244
370
  return unless sort_property && (sort_type || sort_block || sort_by_block)
245
371
  array = model_binding.evaluate_property
246
372
  array = array.sort_by(&:hash) # this ensures consistent subsequent sorting in case there are equivalent sorts to avoid an infinite loop
@@ -281,22 +407,16 @@ module Glimmer
281
407
  search
282
408
  end
283
409
 
284
- def widget_property_listener_installers
285
- super.merge({
286
- Java::OrgEclipseSwtWidgets::Table => {
287
- selection: lambda do |observer|
288
- on_widget_selected { |selection_event|
289
- observer.call(@swt_widget.getSelection)
290
- }
291
- end
292
- },
293
- })
294
- end
295
-
296
410
  def post_initialize_child(table_column_proxy)
297
411
  table_column_proxies << table_column_proxy
298
412
  end
299
413
 
414
+ def post_add_content
415
+ return if @initially_sorted
416
+ initial_sort!
417
+ @initially_sorted = true
418
+ end
419
+
300
420
  def table_column_proxies
301
421
  @table_column_proxies ||= []
302
422
  end
@@ -329,7 +449,8 @@ module Glimmer
329
449
  return if table_item.nil?
330
450
  model = table_item.data
331
451
  property = column_properties[column_index]
332
- @cancel_edit&.call if @edit_mode
452
+ cancel_edit!
453
+ return unless table_column_proxies[column_index].editable?
333
454
  action_taken = false
334
455
  @edit_mode = true
335
456
 
@@ -354,7 +475,7 @@ module Glimmer
354
475
  end
355
476
 
356
477
  @finish_edit = lambda do |event=nil|
357
- new_value = @table_editor_widget_proxy&.swt_widget&.send(widget_value_property)
478
+ new_value = @table_editor_widget_proxy&.send(widget_value_property)
358
479
  if table_item.isDisposed
359
480
  @cancel_edit.call
360
481
  elsif !new_value.nil? && !action_taken && !@edit_in_progress && !@cancel_in_progress