Class: RubyCurses::DefaultTableModel
- Inherits:
-
TableModel
- Object
- TableModel
- RubyCurses::DefaultTableModel
- Includes:
- EventHandler
- Defined in:
- lib/rbcurse/rtable.rb
Overview
DTM
Instance Attribute Summary collapse
-
#last_regex ⇒ Object
readonly
Returns the value of attribute last_regex.
Instance Method Summary collapse
- #<<(obj) ⇒ Object
- #ask_search_forward ⇒ Object
- #column_count ⇒ Object
-
#data=(data) ⇒ Object
for those quick cases when you wish to replace all the data and not have an event per row being generated.
-
#delete(obj) ⇒ Object
create tablemodelevent and fire_table_changed for all listeners.
-
#delete_all ⇒ Object
added 2009-01-17 21:36 Use with caution, does not call events per row.
- #delete_at(row) ⇒ Object
-
#find_match(regex, ix0 = 0, ix1 = row_count()) ⇒ Object
continues previous search.
-
#find_next ⇒ Object
dtm findnext.
- #find_prev(regex = @last_regex, start = @search_found_ix) ⇒ Object
-
#get_value_at(row, col) ⇒ Object
please avoid directly hitting this.
-
#initialize(data, colnames_array) ⇒ DefaultTableModel
constructor
A new instance of DefaultTableModel.
-
#insert(row, obj) ⇒ Object
create tablemodelevent and fire_table_changed for all listeners.
- #row_count ⇒ Object
-
#set_value_at(row, col, val) ⇒ Object
please avoid directly hitting this.
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Methods inherited from TableModel
Constructor Details
#initialize(data, colnames_array) ⇒ DefaultTableModel
Returns a new instance of DefaultTableModel.
1419 1420 1421 1422 |
# File 'lib/rbcurse/rtable.rb', line 1419 def initialize data, colnames_array @data = data @column_identifiers = colnames_array end |
Instance Attribute Details
#last_regex ⇒ Object (readonly)
Returns the value of attribute last_regex.
1417 1418 1419 |
# File 'lib/rbcurse/rtable.rb', line 1417 def last_regex @last_regex end |
Instance Method Details
#<<(obj) ⇒ Object
1450 1451 1452 1453 1454 1455 |
# File 'lib/rbcurse/rtable.rb', line 1450 def << obj @data << obj tme = TableModelEvent.new(@data.length-1,@data.length-1, :ALL_COLUMNS, self, :INSERT) fire_handler :TABLE_MODEL_EVENT, tme # create tablemodelevent and fire_table_changed for all listeners end |
#ask_search_forward ⇒ Object
1497 1498 1499 1500 1501 1502 1503 1504 1505 |
# File 'lib/rbcurse/rtable.rb', line 1497 def ask_search_forward regex = get_string "Enter regex to search for:" ix = get_list_data_model.find_match regex if ix.nil? alert("No matching data for: #{regex}") else set_focus_on(ix) end end |
#column_count ⇒ Object
1423 1424 1425 1426 1427 |
# File 'lib/rbcurse/rtable.rb', line 1423 def column_count # 2010-01-12 19:35 changed count to size since size is supported in 1.8.6 also #@column_identifiers.count @column_identifiers.size end |
#data=(data) ⇒ Object
for those quick cases when you wish to replace all the data and not have an event per row being generated
1490 1491 1492 1493 1494 1495 1496 |
# File 'lib/rbcurse/rtable.rb', line 1490 def data=(data) raise "Data nil or invalid" if data.nil? or data.size == 0 delete_all @data = data tme = TableModelEvent.new(0, @data.length-1,:ALL_COLUMNS, self, :INSERT) fire_handler :TABLE_MODEL_EVENT, tme end |
#delete(obj) ⇒ Object
create tablemodelevent and fire_table_changed for all listeners
1462 1463 1464 1465 1466 1467 1468 1469 1470 |
# File 'lib/rbcurse/rtable.rb', line 1462 def delete obj row = @data.index obj return if row.nil? ret = @data.delete obj tme = TableModelEvent.new(row, row,:ALL_COLUMNS, self, :DELETE) fire_handler :TABLE_MODEL_EVENT, tme # create tablemodelevent and fire_table_changed for all listeners return ret end |
#delete_all ⇒ Object
added 2009-01-17 21:36 Use with caution, does not call events per row
1481 1482 1483 1484 1485 1486 |
# File 'lib/rbcurse/rtable.rb', line 1481 def delete_all len = @data.length-1 @data=[] tme = TableModelEvent.new(0, len,:ALL_COLUMNS, self, :DELETE) fire_handler :TABLE_MODEL_EVENT, tme end |
#delete_at(row) ⇒ Object
1471 1472 1473 1474 1475 1476 1477 |
# File 'lib/rbcurse/rtable.rb', line 1471 def delete_at row ret = @data.delete_at row # create tablemodelevent and fire_table_changed for all listeners tme = TableModelEvent.new(row, row,:ALL_COLUMNS, self, :DELETE) fire_handler :TABLE_MODEL_EVENT, tme return ret end |
#find_match(regex, ix0 = 0, ix1 = row_count()) ⇒ Object
continues previous search
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 |
# File 'lib/rbcurse/rtable.rb', line 1508 def find_match regex, ix0=0, ix1=row_count() $log.debug " find_match got #{regex} #{ix0} #{ix1}" @last_regex = regex @search_start_ix = ix0 @search_end_ix = ix1 @data.each_with_index do |row, ix| next if ix < ix0 break if ix > ix1 if row.grep(/#{regex}/) != [] #if !row.match(regex).nil? @search_found_ix = ix return ix end end return nil end |
#find_next ⇒ Object
dtm findnext
1541 1542 1543 1544 1545 |
# File 'lib/rbcurse/rtable.rb', line 1541 def find_next raise "No more search" if @last_regex.nil? start = @search_found_ix && @search_found_ix+1 || 0 return find_match @last_regex, start, @search_end_ix end |
#find_prev(regex = @last_regex, start = @search_found_ix) ⇒ Object
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 |
# File 'lib/rbcurse/rtable.rb', line 1524 def find_prev regex=@last_regex, start = @search_found_ix raise "No previous search" if @last_regex.nil? $log.debug " find_prev #{@search_found_ix} : #{@current_index}" start -= 1 unless start == 0 @last_regex = regex @search_start_ix = start start.downto(0) do |ix| row = @data[ix] if row.grep(/#{regex}/) != [] @search_found_ix = ix return ix end end return nil #return find_match @last_regex, start, @search_end_ix end |
#get_value_at(row, col) ⇒ Object
please avoid directly hitting this. Suggested to use get_value_at of jtable since columns could have been switched.
1444 1445 1446 1447 1448 1449 |
# File 'lib/rbcurse/rtable.rb', line 1444 def get_value_at row, col #$log.debug " def get_value_at #{row}, #{col} " raise "IndexError get_value_at #{row}, #{col}" if @data.nil? or row >= @data.size return @data[row][ col] end |
#insert(row, obj) ⇒ Object
create tablemodelevent and fire_table_changed for all listeners
1456 1457 1458 1459 1460 1461 |
# File 'lib/rbcurse/rtable.rb', line 1456 def insert row, obj @data.insert row, obj tme = TableModelEvent.new(row, row,:ALL_COLUMNS, self, :INSERT) fire_handler :TABLE_MODEL_EVENT, tme # create tablemodelevent and fire_table_changed for all listeners end |
#row_count ⇒ Object
1428 1429 1430 |
# File 'lib/rbcurse/rtable.rb', line 1428 def row_count @data.length end |
#set_value_at(row, col, val) ⇒ Object
please avoid directly hitting this. Suggested to use get_value_at of jtable since columns could have been switched.
1434 1435 1436 1437 1438 1439 1440 |
# File 'lib/rbcurse/rtable.rb', line 1434 def set_value_at row, col, val # $log.debug " def set_value_at #{row}, #{col}, #{val} " # if editing allowed @data[row][col] = val tme = TableModelEvent.new(row, row, col, self, :UPDATE) fire_handler :TABLE_MODEL_EVENT, tme end |