Skip to content

Commit

Permalink
gwt: Fix StatisticsPresenter bug that was spawning multiple requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
calin-iorgulescu committed Feb 20, 2015
1 parent 72c2add commit d530387
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ public class StatisticsPresenter implements Presenter {
public interface Widget {
HTMLTable getTeamTable();
HTMLTable getStudentTable();
void displayInfo(User user, Assignment[] assignments, ResultInfo[] teamResultInfo, ResultInfo[] studentResultInfo);
void displayInfo(User user, Assignment[] assignments,
ArrayList<ResultInfo> teamResultInfo, ArrayList<ResultInfo> studentResultInfo);
void displayResultDetails(String htmlDetails);
}

private class TableClickHandler implements ClickHandler {
final HTMLTable table;
final ResultInfo[] resultsInfo;
final ArrayList<ResultInfo> resultsInfo;

public TableClickHandler(HTMLTable table, ResultInfo[] resultsInfo) {
public TableClickHandler(HTMLTable table, ArrayList<ResultInfo> resultsInfo) {
this.table = table;
this.resultsInfo = resultsInfo;
}
Expand All @@ -41,7 +42,7 @@ public void onClick(ClickEvent event) {
HTMLTable.Cell cell = this.table.getCellForEvent(event);
if (cell != null) {
GWT.log("Click for cell " + cell, null);
ResultInfo resultInfo = this.resultsInfo[cell.getRowIndex() - 1];
ResultInfo resultInfo = this.resultsInfo.get(cell.getRowIndex() - 1);
String assignmentId = assignments[cell.getCellIndex() - 1].id;
if (resultInfo.results.containsKey(assignmentId)) {
if (resultInfo.owner == ResultInfo.OwnerType.USER) {
Expand All @@ -65,7 +66,7 @@ public void onClick(ClickEvent event) {
private String courseId;
private User user;
private Assignment[] assignments;
private ResultInfo[] teamResultsInfo, studentResultsInfo;
private ArrayList<ResultInfo> teamResultsInfo, studentResultsInfo;

public StatisticsPresenter(HandlerManager eventBus, HTTPService service,
String courseId, User user, Assignment[] assignments, StatisticsPresenter.Widget widget) {
Expand All @@ -74,7 +75,10 @@ public StatisticsPresenter(HandlerManager eventBus, HTTPService service,
this.courseId = courseId;
this.assignments = assignments;
this.user = user;
this.teamResultsInfo = new ArrayList<ResultInfo>();
this.studentResultsInfo = new ArrayList<ResultInfo>();
bindWidget(widget);
listenTableEvents();
}

private void listenTableEvents() {
Expand Down Expand Up @@ -138,22 +142,17 @@ public void clearEventHandlers() {
}

private void processResults(ResultInfo[] resultsInfo) {
ArrayList<ResultInfo> teamResults = new ArrayList<ResultInfo>();
ArrayList<ResultInfo> studentResults = new ArrayList<ResultInfo>();
studentResultsInfo.clear();
teamResultsInfo.clear();
for (ResultInfo result : resultsInfo) {
if (result.owner == ResultInfo.OwnerType.USER) {
studentResults.add(result);
studentResultsInfo.add(result);
}

if (result.owner == ResultInfo.OwnerType.TEAM) {
teamResults.add(result);
teamResultsInfo.add(result);
}
}

teamResultsInfo = new ResultInfo[teamResults.size()];
teamResultsInfo = teamResults.toArray(teamResultsInfo);
studentResultsInfo = new ResultInfo[studentResults.size()];
studentResultsInfo = studentResults.toArray(studentResultsInfo);
}

@Override
Expand All @@ -172,7 +171,6 @@ public void onFailure(Throwable caught) {
public void onSuccess(ResultInfo[] result) {
container.clear();
processResults(result);
listenTableEvents();
widget.displayInfo(user, assignments, teamResultsInfo, studentResultsInfo);
container.add((com.google.gwt.user.client.ui.Widget) widget);
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.RESET, null));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ro.pub.cs.vmchecker.client.ui;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
Expand Down Expand Up @@ -87,7 +89,7 @@ public HTMLTable getStudentTable() {
return studentTable;
}

private void populateTable(HTMLTable table, User user, Assignment assignments[], ResultInfo[] resultsInfo) {
private void populateTable(HTMLTable table, User user, Assignment assignments[], ArrayList<ResultInfo> resultsInfo) {
table.setCellPadding(5);
table.setCellSpacing(0);
table.setStyleName(style.table());
Expand All @@ -102,8 +104,8 @@ private void populateTable(HTMLTable table, User user, Assignment assignments[],
}
}
/* complete the content */
for (i = 1; i <= resultsInfo.length; i++) {
ResultInfo result = resultsInfo[i - 1];
for (i = 1; i <= resultsInfo.size(); i++) {
ResultInfo result = resultsInfo.get(i - 1);
for (int j = 0; j <= assignments.length; j++) {
table.getCellFormatter().addStyleName(i, j, style.cell());
/* the first column contains the student's name */
Expand All @@ -126,22 +128,23 @@ private void populateTable(HTMLTable table, User user, Assignment assignments[],
}

@Override
public void displayInfo(User user, Assignment[] assignments, ResultInfo[] teamResultsInfo, ResultInfo[] studentResultsInfo) {
public void displayInfo(User user, Assignment[] assignments,
ArrayList<ResultInfo> teamResultsInfo, ArrayList<ResultInfo> studentResultsInfo) {
tablePanel.clear();

/* if there are no submissions to show, display the appropriate message. */
if (teamResultsInfo.length == 0 && studentResultsInfo.length == 0) {
if (teamResultsInfo.size() == 0 && studentResultsInfo.size() == 0) {
tablePanel.add(noSubmissionAvailableMessage);
return;
}

if (teamResultsInfo.length != 0) {
if (teamResultsInfo.size() != 0) {
tablePanel.add(teamTitle);
populateTable(teamTable, user, assignments, teamResultsInfo);
tablePanel.add(teamTable);
}

if (studentResultsInfo.length != 0) {
if (studentResultsInfo.size() != 0) {
tablePanel.add(studentTitle);
populateTable(studentTable, user, assignments, studentResultsInfo);
tablePanel.add(studentTable);
Expand Down

0 comments on commit d530387

Please sign in to comment.