1*ca987122SIngo Weinhold /* 2*ca987122SIngo Weinhold * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3*ca987122SIngo Weinhold * Distributed under the terms of the MIT License. 4*ca987122SIngo Weinhold */ 5*ca987122SIngo Weinhold 6*ca987122SIngo Weinhold #include "main_window/TeamsPage.h" 7*ca987122SIngo Weinhold 8*ca987122SIngo Weinhold #include <stdio.h> 9*ca987122SIngo Weinhold 10*ca987122SIngo Weinhold #include <new> 11*ca987122SIngo Weinhold 12*ca987122SIngo Weinhold #include "table/TableColumns.h" 13*ca987122SIngo Weinhold 14*ca987122SIngo Weinhold 15*ca987122SIngo Weinhold // #pragma mark - TeamsTableModel 16*ca987122SIngo Weinhold 17*ca987122SIngo Weinhold 18*ca987122SIngo Weinhold class MainWindow::TeamsPage::TeamsTableModel : public TableModel { 19*ca987122SIngo Weinhold public: 20*ca987122SIngo Weinhold TeamsTableModel(Model* model) 21*ca987122SIngo Weinhold : 22*ca987122SIngo Weinhold fModel(model) 23*ca987122SIngo Weinhold { 24*ca987122SIngo Weinhold } 25*ca987122SIngo Weinhold 26*ca987122SIngo Weinhold virtual int32 CountColumns() const 27*ca987122SIngo Weinhold { 28*ca987122SIngo Weinhold return 4; 29*ca987122SIngo Weinhold } 30*ca987122SIngo Weinhold 31*ca987122SIngo Weinhold virtual int32 CountRows() const 32*ca987122SIngo Weinhold { 33*ca987122SIngo Weinhold return fModel->CountTeams(); 34*ca987122SIngo Weinhold } 35*ca987122SIngo Weinhold 36*ca987122SIngo Weinhold virtual bool GetValueAt(int32 rowIndex, int32 columnIndex, Variant& value) 37*ca987122SIngo Weinhold { 38*ca987122SIngo Weinhold Model::Team* team = fModel->TeamAt(rowIndex); 39*ca987122SIngo Weinhold if (team == NULL) 40*ca987122SIngo Weinhold return false; 41*ca987122SIngo Weinhold 42*ca987122SIngo Weinhold switch (columnIndex) { 43*ca987122SIngo Weinhold case 0: 44*ca987122SIngo Weinhold value.SetTo(team->ID()); 45*ca987122SIngo Weinhold return true; 46*ca987122SIngo Weinhold case 1: 47*ca987122SIngo Weinhold value.SetTo(team->Name(), VARIANT_DONT_COPY_DATA); 48*ca987122SIngo Weinhold return true; 49*ca987122SIngo Weinhold case 2: 50*ca987122SIngo Weinhold value.SetTo(team->CreationTime()); 51*ca987122SIngo Weinhold return true; 52*ca987122SIngo Weinhold case 3: 53*ca987122SIngo Weinhold value.SetTo(team->DeletionTime()); 54*ca987122SIngo Weinhold return true; 55*ca987122SIngo Weinhold default: 56*ca987122SIngo Weinhold return false; 57*ca987122SIngo Weinhold } 58*ca987122SIngo Weinhold } 59*ca987122SIngo Weinhold 60*ca987122SIngo Weinhold private: 61*ca987122SIngo Weinhold Model* fModel; 62*ca987122SIngo Weinhold }; 63*ca987122SIngo Weinhold 64*ca987122SIngo Weinhold 65*ca987122SIngo Weinhold // #pragma mark - TeamsPage 66*ca987122SIngo Weinhold 67*ca987122SIngo Weinhold 68*ca987122SIngo Weinhold MainWindow::TeamsPage::TeamsPage(MainWindow* parent) 69*ca987122SIngo Weinhold : 70*ca987122SIngo Weinhold BGroupView(B_VERTICAL), 71*ca987122SIngo Weinhold fParent(parent), 72*ca987122SIngo Weinhold fTeamsTable(NULL), 73*ca987122SIngo Weinhold fTeamsTableModel(NULL), 74*ca987122SIngo Weinhold fModel(NULL) 75*ca987122SIngo Weinhold 76*ca987122SIngo Weinhold { 77*ca987122SIngo Weinhold SetName("Teams"); 78*ca987122SIngo Weinhold 79*ca987122SIngo Weinhold fTeamsTable = new Table("teams list", 0); 80*ca987122SIngo Weinhold AddChild(fTeamsTable->ToView()); 81*ca987122SIngo Weinhold 82*ca987122SIngo Weinhold fTeamsTable->AddColumn(new Int32TableColumn(0, "ID", 40, 20, 1000, 83*ca987122SIngo Weinhold B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT)); 84*ca987122SIngo Weinhold fTeamsTable->AddColumn(new StringTableColumn(1, "Name", 80, 40, 1000, 85*ca987122SIngo Weinhold B_TRUNCATE_END, B_ALIGN_LEFT)); 86*ca987122SIngo Weinhold fTeamsTable->AddColumn(new BigtimeTableColumn(2, "Creation", 80, 40, 1000, 87*ca987122SIngo Weinhold true, B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT)); 88*ca987122SIngo Weinhold fTeamsTable->AddColumn(new BigtimeTableColumn(3, "Deletion", 80, 40, 1000, 89*ca987122SIngo Weinhold false, B_TRUNCATE_MIDDLE, B_ALIGN_RIGHT)); 90*ca987122SIngo Weinhold 91*ca987122SIngo Weinhold fTeamsTable->AddTableListener(this); 92*ca987122SIngo Weinhold } 93*ca987122SIngo Weinhold 94*ca987122SIngo Weinhold 95*ca987122SIngo Weinhold MainWindow::TeamsPage::~TeamsPage() 96*ca987122SIngo Weinhold { 97*ca987122SIngo Weinhold fTeamsTable->SetTableModel(NULL); 98*ca987122SIngo Weinhold delete fTeamsTableModel; 99*ca987122SIngo Weinhold } 100*ca987122SIngo Weinhold 101*ca987122SIngo Weinhold 102*ca987122SIngo Weinhold void 103*ca987122SIngo Weinhold MainWindow::TeamsPage::SetModel(Model* model) 104*ca987122SIngo Weinhold { 105*ca987122SIngo Weinhold if (model == fModel) 106*ca987122SIngo Weinhold return; 107*ca987122SIngo Weinhold 108*ca987122SIngo Weinhold if (fModel != NULL) { 109*ca987122SIngo Weinhold fTeamsTable->SetTableModel(NULL); 110*ca987122SIngo Weinhold delete fTeamsTableModel; 111*ca987122SIngo Weinhold fTeamsTableModel = NULL; 112*ca987122SIngo Weinhold } 113*ca987122SIngo Weinhold 114*ca987122SIngo Weinhold fModel = model; 115*ca987122SIngo Weinhold 116*ca987122SIngo Weinhold if (fModel != NULL) { 117*ca987122SIngo Weinhold fTeamsTableModel = new(std::nothrow) TeamsTableModel(fModel); 118*ca987122SIngo Weinhold fTeamsTable->SetTableModel(fTeamsTableModel); 119*ca987122SIngo Weinhold } 120*ca987122SIngo Weinhold } 121*ca987122SIngo Weinhold 122*ca987122SIngo Weinhold 123*ca987122SIngo Weinhold void 124*ca987122SIngo Weinhold MainWindow::TeamsPage::TableRowInvoked(Table* table, int32 rowIndex) 125*ca987122SIngo Weinhold { 126*ca987122SIngo Weinhold Model::Team* team = fModel->TeamAt(rowIndex); 127*ca987122SIngo Weinhold if (team != NULL) 128*ca987122SIngo Weinhold fParent->OpenTeamWindow(team); 129*ca987122SIngo Weinhold } 130