Class: Opine::Native::Table::OSXTable

Inherits:
Cocoa::NSObject
  • Object
show all
Defined in:
lib/opine/widgets/table_osx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, resources, options, &block) ⇒ OSXTable

Returns a new instance of OSXTable.



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
42
43
# File 'lib/opine/widgets/table_osx.rb', line 6

def initialize parent,resources,options,&block
  super()

  @parent = parent
  @resources = resources
  @columns = options[:columns] || @resources.columns.map{ |col| col.name }
  @hooks = {}

  table_container = Cocoa::NSScrollView.alloc.initWithFrame parent.frame.native
  @table_view = Cocoa::NSTableView.alloc.initWithFrame parent.frame.native

  columns = @columns.map do |name|
    col = Cocoa::NSTableColumn.alloc.initWithIdentifier name.to_s
    col.headerCell.setTitle name.to_s.humanize
    col.setWidth parent.frame.width / @columns.size
    table_view.addTableColumn col
    col
  end

  table_view.setDelegate self
  table_view.setDataSource self
  table_view.reloadData

  table_container.setDocumentView table_view
  table_container.setHasVerticalScroller true

  if parent.is_a? Opine::Window
    parent.content_view << table_container
  end

  table_container.setAutoresizingMask NSViewWidthSizable | NSViewHeightSizable

  table_container.release
  table_view.release
  columns.each do |col|
    col.release
  end
end

Instance Attribute Details

#hooksObject

Returns the value of attribute hooks.



5
6
7
# File 'lib/opine/widgets/table_osx.rb', line 5

def hooks
  @hooks
end

#table_viewObject

Returns the value of attribute table_view.



5
6
7
# File 'lib/opine/widgets/table_osx.rb', line 5

def table_view
  @table_view
end

Instance Method Details

#reloadObject



45
46
47
48
# File 'lib/opine/widgets/table_osx.rb', line 45

def reload
  @cache = @resources.to_a
  table_view.reloadData
end