package eu.toldi.rss;

import javax.swing.*;
import javax.swing.table.TableRowSorter;
import java.io.IOException;

public class UpdaterThread extends Thread{
    FeedData data;
    JTable table;

    public UpdaterThread(FeedData data,JTable table){
        this.data = data;
        this.table =table;
    }

    @Override
    public void run() {
        while (true) {
            try {
                sleep(60 * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (Feed f : data.getFeeds()) {
                try {
                    f.updateFeed();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            TableRowSorter<FeedData> sorter = (TableRowSorter<FeedData>) table.getRowSorter();
            table.setModel(data);
            table.setRowSorter(sorter);
            table.updateUI();
        }
    }
}
