# Implementing a ListStore

**URL:** <https://www.ruby-forum.com/t/implementing-a-liststore/85329>\
**Category:** Ruby-Gnome 2\
**Created:** [February 12, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/implementing-a-liststore/85329 "2007-02-12T18:39:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gendag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f04885/32.png) [@gendag](https://www.ruby-forum.com/u/gendag)\
**Post date:** [February 12, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/implementing-a-liststore/85329/1 "2007-02-12T18:39:39Z")

</div>

I need to display a list of articles taken from a database.  
The list is large (more than 300 articles and the number will grow up)  
and  
I use ActiveRecord to dialog with the DB.

My problem is that saving each article in the ListStore is a bit slow  
and  
taking inspiration from the article  
[http://www.kdedevelopers.org/node/2670](http://www.kdedevelopers.org/node/2670) I  
thought  
I could write my own ListStore that internally use the articels list get  
from  
ActiveRecord.

The problem is that I don’t know which methods I have to re-define to  
make  
my  
StoreList work. Which interface I have to implement?  
Here there is an example:

####################################################################

require ‘gtk2’

class MyListStore \< Gtk::ListStore  
def initialize(model)  
@model = model  
super(String)  
end

# these are the method that I didn’r re-define

exclude = %w{object\_id **send**  **id** }

# In this way I re-define all the methods

# and each method raise a NotImplementedError,

# in this way I thought to know which method

# the View uses to get the data from the store,

# but no exception is thrown and In the wiew

# no row is shown

instance\_methods(true).each do |method|  
a \<\< method  
if(exclude.find(){|el| el == method}.nil?)  
str = %{  
def #{method}()  
raise NotImplementedError.new(‘#{method}’)  
end}  
module\_eval(str)  
end  
end  
end

# The controller set up the connection with the DB

controller = Controller::Controller.new(File::dirname( **FILE** ))

@window = Gtk::Window.new(Gtk:🪟:TOPLEVEL)  
@window.set\_default\_size(900, 400)  
@window.set\_border\_width(10)  
@window.signal\_connect(‘delete\_event’) {Gtk.main\_quit}

articles = Article.find(:all)  
table\_store = MyListStore.new(articles)  
table\_view = Gtk::TreeView.new(table\_store)

renderer = Gtk::CellRendererText.new  
renderer.xalign = 0.5  
renderer.yalign = 0.5  
col = Gtk::TreeViewColumn.new(‘Barcode’, renderer, :text =\> 0)  
col.alignment = 0.5  
table\_view.append\_column(col)  
@window.add(table\_view)  
@window.show\_all  
Gtk.main  
####################################################################

The table view is displaied but no rows is present. I’ve redefined all  
the  
methods  
of MyListStore to throw an exception, in this way I whought to know  
which  
methods  
the View uses to get the data from the Store, but no exception was  
thrown.

Thank you,

Gendag
