private void LoadAttendancesListData() { // Add to attendances list. // First we check if there are persons added. if (PersonsManager.Instance.PersonsCount() == 0) return; /* We get the last 3 events before the actual date. If they do not exists, then * we quit. */ Event[] lastEventsAgain = EventsManager.Instance.RetrieveLast(3); if (lastEventsAgain.Length == 0) { this.CleanAttendancesList(); return; } /* If they have changed, we continue, if not we stop: it's not necessary * to update anything. */ if (lastEventsAgain.Length == this.lastEventsOnAttendancesList.Count) { int j; for (j=0; j<lastEventsAgain.Length; j++) { // Check if events (objects) are equals if (!lastEventsAgain[j].Equals(this.lastEventsOnAttendancesList[j])) break; } /* If events are the same, regenerate columns titles (maybe it's not necessary, * but it the same that checking if they are equals or not to the correct one). */ if (j == lastEventsAgain.Length) { foreach(CustomTreeViewColumn ctvc in this.tvAttendances.Columns) { if (ctvc.Event != null) ctvc.Title = this.GenerateColumnTitle(ctvc.Event); } return; } } // Clear attendances list this.CleanAttendancesList(); // Add as lastEvents the really last events :) this.lastEventsOnAttendancesList.AddRange(lastEventsAgain); // We'll need to update the model, so we save the new types List<Type> columnTypes = new List<Type>(); // Types to create ListStore. First type is string (name of persons) columnTypes.Add(typeof(Person)); // Add column of persons CustomTreeViewColumn persons = new CustomTreeViewColumn(); persons.Title = "Personas"; CellRendererText personCell = new CellRendererText(); persons.PackStart(personCell, true); persons .SetCellDataFunc(personCell, new TreeCellDataFunc(this.RenderNameAndSurname)); this.tvAttendances.AppendColumn(persons); // Add new ones CustomTreeViewColumn eventColumn; CustomCellRendererToggle eventCellRenderer; int k = 1; foreach(Event anEvent in this.lastEventsOnAttendancesList) { columnTypes.Add(typeof(bool)); // Create cell renderer eventCellRenderer = new CustomCellRendererToggle(k, anEvent); eventCellRenderer.Activatable = true; eventCellRenderer.Toggled += new ToggledHandler(this.OnCellRendererColumnsToggleEvent); // Create column eventColumn = new CustomTreeViewColumn(anEvent); eventColumn.Title = this.GenerateColumnTitle(anEvent); eventColumn.Alignment = 0.5f; eventColumn.PackStart(eventCellRenderer, true); eventColumn.AddAttribute(eventCellRenderer, "active", k++); this.tvAttendances.AppendColumn(eventColumn); } // Add an empty column to avoid last one to expand CellRendererText eventCellRendererText = new CellRendererText(); eventCellRendererText.Sensitive = false; // Create column eventColumn = new CustomTreeViewColumn(); eventColumn.Title = ""; eventColumn.PackStart(eventCellRendererText, false); this.tvAttendances.AppendColumn(eventColumn); // Last type is Person // columnTypes.Add(typeof(Person)); this.attendances = new ListStore(columnTypes.ToArray()); this.tvAttendances.Model = this.attendances; // Clean dictionary with persons and TreeIter of attendances list this.treeItersOnAttendancesList.Clear(); // We add all persons again AttendancesManager am = AttendancesManager.Instance; ArrayList data = new ArrayList(); TreeIter iter; foreach (Person p in PersonsManager.Instance.RetrieveAll()) { data.Clear(); // Person's data data.Add(p); // Events foreach (Event anEvent in this.lastEventsOnAttendancesList) data.Add(am.Attended(p, anEvent)); // ... and the person object itself. We'll need it. // data.Add(p); iter = this.attendances.AppendValues(data.ToArray()); if (!this.treeItersOnAttendancesList.ContainsKey(p)) this.treeItersOnAttendancesList.Add(p, iter); } return; }
private void LoadAttendancesListData() { // Add to attendances list. // First we check if there are persons added. if (PersonsManager.Instance.PersonsCount() == 0) { return; } /* We get the last 3 events before the actual date. If they do not exists, then * we quit. */ Event[] lastEventsAgain = EventsManager.Instance.RetrieveLast(3); if (lastEventsAgain.Length == 0) { this.CleanAttendancesList(); return; } /* If they have changed, we continue, if not we stop: it's not necessary * to update anything. */ if (lastEventsAgain.Length == this.lastEventsOnAttendancesList.Count) { int j; for (j = 0; j < lastEventsAgain.Length; j++) { // Check if events (objects) are equals if (!lastEventsAgain[j].Equals(this.lastEventsOnAttendancesList[j])) { break; } } /* If events are the same, regenerate columns titles (maybe it's not necessary, * but it the same that checking if they are equals or not to the correct one). */ if (j == lastEventsAgain.Length) { foreach (CustomTreeViewColumn ctvc in this.tvAttendances.Columns) { if (ctvc.Event != null) { ctvc.Title = this.GenerateColumnTitle(ctvc.Event); } } return; } } // Clear attendances list this.CleanAttendancesList(); // Add as lastEvents the really last events :) this.lastEventsOnAttendancesList.AddRange(lastEventsAgain); // We'll need to update the model, so we save the new types List <Type> columnTypes = new List <Type>(); // Types to create ListStore. First type is string (name of persons) columnTypes.Add(typeof(Person)); // Add column of persons CustomTreeViewColumn persons = new CustomTreeViewColumn(); persons.Title = "Personas"; CellRendererText personCell = new CellRendererText(); persons.PackStart(personCell, true); persons .SetCellDataFunc(personCell, new TreeCellDataFunc(this.RenderNameAndSurname)); this.tvAttendances.AppendColumn(persons); // Add new ones CustomTreeViewColumn eventColumn; CustomCellRendererToggle eventCellRenderer; int k = 1; foreach (Event anEvent in this.lastEventsOnAttendancesList) { columnTypes.Add(typeof(bool)); // Create cell renderer eventCellRenderer = new CustomCellRendererToggle(k, anEvent); eventCellRenderer.Activatable = true; eventCellRenderer.Toggled += new ToggledHandler(this.OnCellRendererColumnsToggleEvent); // Create column eventColumn = new CustomTreeViewColumn(anEvent); eventColumn.Title = this.GenerateColumnTitle(anEvent); eventColumn.Alignment = 0.5f; eventColumn.PackStart(eventCellRenderer, true); eventColumn.AddAttribute(eventCellRenderer, "active", k++); this.tvAttendances.AppendColumn(eventColumn); } // Add an empty column to avoid last one to expand CellRendererText eventCellRendererText = new CellRendererText(); eventCellRendererText.Sensitive = false; // Create column eventColumn = new CustomTreeViewColumn(); eventColumn.Title = ""; eventColumn.PackStart(eventCellRendererText, false); this.tvAttendances.AppendColumn(eventColumn); // Last type is Person // columnTypes.Add(typeof(Person)); this.attendances = new ListStore(columnTypes.ToArray()); this.tvAttendances.Model = this.attendances; // Clean dictionary with persons and TreeIter of attendances list this.treeItersOnAttendancesList.Clear(); // We add all persons again AttendancesManager am = AttendancesManager.Instance; ArrayList data = new ArrayList(); TreeIter iter; foreach (Person p in PersonsManager.Instance.RetrieveAll()) { data.Clear(); // Person's data data.Add(p); // Events foreach (Event anEvent in this.lastEventsOnAttendancesList) { data.Add(am.Attended(p, anEvent)); } // ... and the person object itself. We'll need it. // data.Add(p); iter = this.attendances.AppendValues(data.ToArray()); if (!this.treeItersOnAttendancesList.ContainsKey(p)) { this.treeItersOnAttendancesList.Add(p, iter); } } return; }