Class: RubyCurses::DefaultTableColumnModel

Inherits:
TableColumnModel show all
Includes:
Enumerable, EventHandler
Defined in:
lib/rbcurse/extras/widgets/rtable.rb

Overview

DTCM DCM

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TableColumnModel

#total_column_width

Constructor Details

#initialize(cols = []) ⇒ DefaultTableColumnModel

takes a column names array



1396
1397
1398
1399
1400
1401
1402
1403
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1396

def initialize cols=[]
  @columns = []
  @total_column_width= -1
  ##cols.each_with_index {|c, index| @columns << TableColumn.new(index, c, c, 10) }
  cols.each_with_index {|c, index| add_column(TableColumn.new(index, c, c, 10)) }
  @selected_columns = []
  @_events = [:TABLE_COLUMN_MODEL_EVENT, :PROPERTY_CHANGE]
end

Instance Attribute Details

#column_selection_allowedObject

Returns the value of attribute column_selection_allowed.



1392
1393
1394
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1392

def column_selection_allowed
  @column_selection_allowed
end

Instance Method Details

#add_column(tc) ⇒ Object



1442
1443
1444
1445
1446
1447
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1442

def add_column tc
  @columns << tc
  tc.bind(:PROPERTY_CHANGE){|e| column_property_changed(e)}
  tmce = TableColumnModelEvent.new(nil, @columns.length-1, self, :INSERT)
  fire_handler :TABLE_COLUMN_MODEL_EVENT, tmce
end

#clear_selectionObject



1425
1426
1427
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1425

def clear_selection
  @selected_columns = []
end

#column(ix) ⇒ Object



1404
1405
1406
1407
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1404

def column ix
  raise "Invalid arg #{ix}" if ix < 0 or ix > (@columns.length() -1)
  @columns[ix]
end

#column_countObject



1416
1417
1418
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1416

def column_count
  @columns.length
end

#column_index(identifier) ⇒ Object

return index of column identified with identifier



1468
1469
1470
1471
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1468

def column_index identifier
  @columns.each_with_index {|c, i| return i if c.identifier == identifier }
  return nil
end

#column_property_changed(evt) ⇒ Object



1448
1449
1450
1451
1452
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1448

def column_property_changed evt
  $log.debug "DTCM def column_property_changed #{evt} "
  # need to send changeevent FIXME XXX
  fire_handler :PROPERTY_CHANGE, self
end

#columnsObject



1408
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1408

def columns; @columns; end

#eachObject

yields a table column



1411
1412
1413
1414
1415
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1411

def each
  @columns.each { |c| 
    yield c 
  }
end

#get_selection_modelObject

TODO - if we get into column selection somewhen



1473
1474
1475
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1473

def get_selection_model
  @lsm
end

#get_total_column_widthObject

added 2009-10-07 23:04



1430
1431
1432
1433
1434
1435
1436
1437
1438
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1430

def get_total_column_width
  @total_column_width = -1 # XXX
  if @total_column_width == -1
    total = 0
    each { |c| total += c.width ; $log.debug "get_total_column_width: #{c.width}"}
    @total_column_width = total
  end
  return @total_column_width 
end

#move_column(ix, newix) ⇒ Object



1459
1460
1461
1462
1463
1464
1465
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1459

def move_column ix, newix
  #    acol = remove_column column(ix)
  acol = @columns.delete_at ix 
  @columns.insert newix, acol
  tmce = TableColumnModelEvent.new(ix, newix, self, :MOVE)
  fire_handler :TABLE_COLUMN_MODEL_EVENT, tmce
end

#remove_column(tc) ⇒ Object



1453
1454
1455
1456
1457
1458
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1453

def remove_column tc
  ix = @columns.index tc
  @columns.delete  tc
  tmce = TableColumnModelEvent.new(ix, nil, self, :DELETE)
  fire_handler :TABLE_COLUMN_MODEL_EVENT, tmce
end

#selected_column_countObject



1419
1420
1421
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1419

def selected_column_count
  @selected_columns.length
end

#selected_columnsObject



1422
1423
1424
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1422

def selected_columns
  @selected_columns
end

#set_selection_model(lsm) ⇒ Object



1439
1440
1441
# File 'lib/rbcurse/extras/widgets/rtable.rb', line 1439

def set_selection_model lsm
  @column_selection_model = lsm
end