Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(880)

Side by Side Diff: frontend/client/src/autotest/planner/triage/FailureTable.java

Issue 1595019: Merge remote branch 'origin/upstream' into tempbranch (Closed)
Patch Set: Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 package autotest.planner.triage;
2
3 import autotest.common.spreadsheet.Spreadsheet;
4 import autotest.common.spreadsheet.Spreadsheet.CellInfo;
5 import autotest.common.spreadsheet.Spreadsheet.Header;
6 import autotest.common.spreadsheet.Spreadsheet.HeaderImpl;
7 import autotest.common.spreadsheet.Spreadsheet.SpreadsheetListener;
8 import autotest.common.ui.NotifyManager;
9
10 import com.google.gwt.json.client.JSONObject;
11 import com.google.gwt.user.client.IncrementalCommand;
12
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.Iterator;
16 import java.util.LinkedList;
17 import java.util.List;
18
19 class FailureTable implements SpreadsheetListener, TriagePopup.Listener {
20
21 public interface Display {
22 public Spreadsheet getSpreadsheet();
23 public TriagePopup.Display generateTriagePopupDisplay();
24 }
25
26 private static class Failure {
27 int id;
28 String machine;
29 boolean blocked;
30 String testName;
31 String reason;
32 boolean seen;
33
34 private Failure(int id, String machine, boolean blocked,
35 String testName, String reason, boolean seen) {
36 this.id = id;
37 this.machine = machine;
38 this.blocked = blocked;
39 this.testName = testName;
40 this.reason = reason;
41 this.seen = seen;
42 }
43
44 public static Failure fromJsonObject(JSONObject failureObj) {
45 return new Failure((int) failureObj.get("id").isNumber().doubleValue (),
46 failureObj.get("machine").isString().stringValue(),
47 failureObj.get("blocked").isBoolean().booleanValue(),
48 failureObj.get("test_name").isString().stringValue(),
49 failureObj.get("reason").isString().stringValue(),
50 failureObj.get("seen").isBoolean().booleanValue());
51 }
52 }
53
54 private Display display;
55 private String group;
56 private LinkedList<Failure> failures = new LinkedList<Failure>();
57 private boolean rendered;
58
59 public FailureTable(String group) {
60 this.group = group;
61 }
62
63 public void bindDisplay(Display display) {
64 this.display = display;
65 display.getSpreadsheet().setListener(this);
66 }
67
68 public void addFailure(JSONObject failureObj) {
69 setRendered(false);
70
71 Failure failure = Failure.fromJsonObject(failureObj);
72
73 if (failure.seen) {
74 failures.addLast(failure);
75 } else {
76 failures.addFirst(failure);
77 }
78 }
79
80 public Display getDisplay() {
81 if (!rendered) {
82 renderDisplay();
83 }
84
85 return display;
86 }
87
88 private void setRendered(boolean rendered) {
89 this.rendered = rendered;
90 display.getSpreadsheet().setVisible(rendered);
91 }
92
93 public void renderDisplay() {
94 Spreadsheet spreadsheet = display.getSpreadsheet();
95 spreadsheet.clear();
96
97 Header rowFields = HeaderImpl.fromBaseType(Collections.singletonList("ma chine"));
98 Header columnFields = new HeaderImpl();
99 columnFields.add("group");
100 columnFields.add("failure");
101 spreadsheet.setHeaderFields(rowFields, columnFields);
102
103 for (int i = 0; i < failures.size(); i++) {
104 Failure failure = failures.get(i);
105 String machine = (i+1) + ": " + failure.machine;
106 if (failure.blocked) {
107 machine += " (blocked)";
108 }
109 spreadsheet.addRowHeader(Collections.singletonList(machine));
110 }
111 spreadsheet.addColumnHeader(createHeaderGroup("Test"));
112 spreadsheet.addColumnHeader(createHeaderGroup("Reason"));
113
114 spreadsheet.prepareForData();
115
116 for (int row = 0; row < failures.size(); row++) {
117 CellInfo test = spreadsheet.getCellInfo(row, 0);
118 CellInfo reason = spreadsheet.getCellInfo(row, 1);
119 Failure failure = failures.get(row);
120
121 test.contents = failure.testName;
122 reason.contents = failure.reason;
123 test.testIndex = failure.id;
124 reason.testIndex = failure.id;
125
126 if (!failure.seen) {
127 test.contents = "<b>" + test.contents + "</b>";
128 reason.contents = "<b>" + reason.contents + "</b>";
129 }
130 }
131
132 spreadsheet.setVisible(true);
133
134 spreadsheet.render(new IncrementalCommand() {
135 @Override
136 public boolean execute() {
137 setRendered(true);
138 return false;
139 }
140 });
141 }
142
143 private List<String> createHeaderGroup(String label) {
144 List<String> header = new ArrayList<String>();
145 header.add(group);
146 header.add(label);
147 return header;
148 }
149
150 @Override
151 public void onCellClicked(CellInfo cellInfo, boolean isRightClick) {
152 if (cellInfo.testIndex == 0) {
153 return;
154 }
155
156 TriagePopup popup = new TriagePopup(this, cellInfo.testIndex);
157 popup.bindDisplay(display.generateTriagePopupDisplay());
158 popup.render();
159 }
160
161 @Override
162 public void onTriage(TriagePopup source) {
163 if (removeFailure(source.getId())) {
164 renderDisplay();
165 }
166 }
167
168 private boolean removeFailure(int id) {
169 setRendered(false);
170
171 Iterator<Failure> iter = failures.iterator();
172 while (iter.hasNext()) {
173 if (iter.next().id == id) {
174 iter.remove();
175 return true;
176 }
177 }
178
179 /*
180 * TODO: throw an Exception instead, and register a handler with
181 * GWT.setUncaughtExceptionHandler()
182 */
183 NotifyManager.getInstance().showError("Did not find failure id " + id);
184 setRendered(true);
185 return false;
186 }
187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698