class Opine::Native::Table::OSXTable

Attributes

hooks[RW]
table_view[RW]

Public Class Methods

new(parent,resources,options,&block) click to toggle source
Calls superclass method
# 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

Public Instance Methods

reload() click to toggle source
# File lib/opine/widgets/table_osx.rb, line 45
def reload
  @cache = @resources.to_a
  table_view.reloadData
end

Private Instance Methods

cache() click to toggle source
# File lib/opine/widgets/table_osx.rb, line 51
def cache
  @cache ||= @resources.to_a
end
numberOfRowsInTableView(table_view) click to toggle source
# File lib/opine/widgets/table_osx.rb, line 55
def numberOfRowsInTableView table_view
  cache.size
end
tableView(table_view, objectValueForTableColumn: nil, row: nil) click to toggle source
# File lib/opine/widgets/table_osx.rb, line 59
def tableView(table_view, objectValueForTableColumn: nil, row: nil)
  cache[row].send(objectValueForTableColumn.identifier.to_s.to_sym).to_s
end