Class: Java::OrgEclipseSwtWidgets::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/lumix/result_view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/lumix/result_view.rb', line 3

def data
  @data
end

#tooltipsObject

Returns the value of attribute tooltips.



3
4
5
# File 'lib/lumix/result_view.rb', line 3

def tooltips
  @tooltips
end

Instance Method Details

#columns=(*titles) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lumix/result_view.rb', line 43

def columns=(*titles)
  if titles
    titles.each do |title|
      col = widgets::TableColumn.new(self, swt::CENTER)
      col.setText title
    end

    setHeaderVisible true
    setLinesVisible true
  end
end

#sort=(sort) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/lumix/result_view.rb', line 55

def sort=(sort)
  sort = Hash.new(true) if [true, :all].member?(sort)
  if sort
    columns.each_with_index do |col, index|
      if sort[col.text]
        col.addListener swt::Selection do
          if data
            @data = data.sort_by {|e| e[index] }
            update :clear
          end
        end
      end
    end
  end
end

#sweeten(app, opts = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lumix/result_view.rb', line 5

def sweeten(app, opts={}, &block)
  @data = []
  @tooltips = []
  super
  @redraw_thread = Thread.new do
    while !isDisposed
      if @dirty
        @dirty = false
        perform do
          setItemCount data.size
          clearAll if clear_all
        end
      end
      sleep 1 # TODO find a better alternative
    end
  end

  # TODO implement tooltips

  addListener swt::SetData do |e|
    item = e.item
    index = indexOf(item)
    item.setText(Array(data[index]).to_java(:string))
  end

  addListener swt::Resize do |e|
    default_weight = 1.0 / columns.size
    current_width = @old_width
    w = width
    columns[0..-2].each do |c|
      weight = c.width == 0 ? default_weight : c.width.to_f / current_width
      c.width = w * weight
    end
    columns[columns.size - 1].pack
    @old_width = w
  end
end