Class: RubyCurses::DefaultTableColumnModel

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

Overview

DTCM DCM

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Methods inherited from TableColumnModel

#total_column_width

Constructor Details

#initialize(cols = []) ⇒ DefaultTableColumnModel

takes a column names array



1304
1305
1306
1307
1308
1309
1310
# File 'lib/rbcurse/rtable.rb', line 1304

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 = []
end

Instance Attribute Details

#column_selection_allowedObject

Returns the value of attribute column_selection_allowed.



1300
1301
1302
# File 'lib/rbcurse/rtable.rb', line 1300

def column_selection_allowed
  @column_selection_allowed
end

Instance Method Details

#add_column(tc) ⇒ Object



1349
1350
1351
1352
1353
1354
# File 'lib/rbcurse/rtable.rb', line 1349

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



1332
1333
1334
# File 'lib/rbcurse/rtable.rb', line 1332

def clear_selection
  @selected_columns = []
end

#column(ix) ⇒ Object



1311
1312
1313
1314
# File 'lib/rbcurse/rtable.rb', line 1311

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

#column_countObject



1323
1324
1325
# File 'lib/rbcurse/rtable.rb', line 1323

def column_count
  @columns.length
end

#column_index(identifier) ⇒ Object

return index of column identified with identifier



1375
1376
1377
1378
# File 'lib/rbcurse/rtable.rb', line 1375

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

#column_property_changed(evt) ⇒ Object



1355
1356
1357
1358
1359
# File 'lib/rbcurse/rtable.rb', line 1355

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



1315
# File 'lib/rbcurse/rtable.rb', line 1315

def columns; @columns; end

#eachObject

yields a table column



1318
1319
1320
1321
1322
# File 'lib/rbcurse/rtable.rb', line 1318

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

#get_selection_modelObject

TODO - if we get into column selection somewhen



1380
1381
1382
# File 'lib/rbcurse/rtable.rb', line 1380

def get_selection_model
  @lsm
end

#get_total_column_widthObject

added 2009-10-07 23:04



1337
1338
1339
1340
1341
1342
1343
1344
1345
# File 'lib/rbcurse/rtable.rb', line 1337

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



1366
1367
1368
1369
1370
1371
1372
# File 'lib/rbcurse/rtable.rb', line 1366

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



1360
1361
1362
1363
1364
1365
# File 'lib/rbcurse/rtable.rb', line 1360

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



1326
1327
1328
# File 'lib/rbcurse/rtable.rb', line 1326

def selected_column_count
  @selected_columns.length
end

#selected_columnsObject



1329
1330
1331
# File 'lib/rbcurse/rtable.rb', line 1329

def selected_columns
  @selected_columns
end

#set_selection_model(lsm) ⇒ Object



1346
1347
1348
# File 'lib/rbcurse/rtable.rb', line 1346

def set_selection_model lsm
  @column_selection_model = lsm
end