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



1270
1271
1272
1273
1274
1275
1276
# File 'lib/rbcurse/rtable.rb', line 1270

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.



1266
1267
1268
# File 'lib/rbcurse/rtable.rb', line 1266

def column_selection_allowed
  @column_selection_allowed
end

Instance Method Details

#add_column(tc) ⇒ Object



1315
1316
1317
1318
1319
1320
# File 'lib/rbcurse/rtable.rb', line 1315

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



1298
1299
1300
# File 'lib/rbcurse/rtable.rb', line 1298

def clear_selection
  @selected_columns = []
end

#column(ix) ⇒ Object



1277
1278
1279
1280
# File 'lib/rbcurse/rtable.rb', line 1277

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

#column_countObject



1289
1290
1291
# File 'lib/rbcurse/rtable.rb', line 1289

def column_count
  @columns.length
end

#column_index(identifier) ⇒ Object

return index of column identified with identifier



1341
1342
1343
1344
# File 'lib/rbcurse/rtable.rb', line 1341

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

#column_property_changed(evt) ⇒ Object



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

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



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

def columns; @columns; end

#eachObject

yields a table column



1284
1285
1286
1287
1288
# File 'lib/rbcurse/rtable.rb', line 1284

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

#get_selection_modelObject

TODO - if we get into column selection somewhen



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

def get_selection_model
  @lsm
end

#get_total_column_widthObject

added 2009-10-07 23:04



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

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



1332
1333
1334
1335
1336
1337
1338
# File 'lib/rbcurse/rtable.rb', line 1332

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



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

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



1292
1293
1294
# File 'lib/rbcurse/rtable.rb', line 1292

def selected_column_count
  @selected_columns.length
end

#selected_columnsObject



1295
1296
1297
# File 'lib/rbcurse/rtable.rb', line 1295

def selected_columns
  @selected_columns
end

#set_selection_model(lsm) ⇒ Object



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

def set_selection_model lsm
  @column_selection_model = lsm
end