Skip to content

Commit 3b3abfb

Browse files
committed
Add link to submission's web page in successful result view
1 parent dfa7dbd commit 3b3abfb

File tree

2 files changed

+72
-39
lines changed

2 files changed

+72
-39
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/ui/SubmissionResultWaitingDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void showSubmissionButton(URI showSubmissionUrl) {
7171
if (showSubmissionUrl == null) {
7272
return;
7373
}
74-
showSubmissionButton.setAction(new AbstractAction("Show submission in browser") {
74+
showSubmissionButton.setAction(new AbstractAction("View submission in browser") {
7575
@Override
7676
public void actionPerformed(ActionEvent ae) {
7777
try {

tmc-plugin/src/fi/helsinki/cs/tmc/ui/SuccessfulSubmissionDialog.java

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
import fi.helsinki.cs.tmc.core.domain.Exercise;
44
import fi.helsinki.cs.tmc.core.domain.submission.SubmissionResult;
5-
6-
import java.awt.Component;
7-
85
import fi.helsinki.cs.tmc.core.domain.submission.FeedbackAnswer;
96
import fi.helsinki.cs.tmc.core.domain.submission.FeedbackQuestion;
107
import fi.helsinki.cs.tmc.ui.feedback.FeedbackQuestionPanel;
118
import fi.helsinki.cs.tmc.ui.feedback.FeedbackQuestionPanelFactory;
129

10+
import com.google.common.base.Optional;
11+
12+
import java.awt.Component;
1313
import java.awt.Font;
1414
import java.awt.event.ActionEvent;
1515
import java.awt.event.ActionListener;
16+
import java.net.MalformedURLException;
17+
import java.net.URI;
1618
import java.net.URL;
1719
import java.util.ArrayList;
1820
import java.util.List;
@@ -25,28 +27,31 @@
2527
import javax.swing.JDialog;
2628
import javax.swing.JLabel;
2729
import javax.swing.JPanel;
30+
2831
import org.apache.commons.lang3.StringEscapeUtils;
2932
import org.apache.commons.lang3.StringUtils;
3033
import org.openide.awt.HtmlBrowser;
3134

32-
import static fi.helsinki.cs.tmc.ui.Boxer.*;
35+
import static fi.helsinki.cs.tmc.ui.Boxer.hbox;
36+
import static fi.helsinki.cs.tmc.ui.Boxer.hglue;
3337

3438
public class SuccessfulSubmissionDialog extends JDialog {
35-
39+
3640
private static final Logger log = Logger.getLogger(SuccessfulSubmissionDialog.class.getName());
37-
41+
3842
private JButton okButton;
39-
43+
private JButton showSubmissionButton;
44+
4045
private List<FeedbackQuestionPanel> feedbackQuestionPanels;
4146

4247
public SuccessfulSubmissionDialog(Exercise exercise, SubmissionResult result) {
4348
this.setTitle(exercise.getName() + " passed");
44-
49+
4550
JPanel contentPane = new JPanel();
4651
contentPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
4752
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
4853
setContentPane(contentPane);
49-
54+
5055
addYayLabel();
5156
addVSpace(6);
5257
if (exercise.requiresReview() && !result.getMissingReviewPoints().isEmpty()) {
@@ -59,17 +64,17 @@ public SuccessfulSubmissionDialog(Exercise exercise, SubmissionResult result) {
5964
addVSpace(20);
6065
addFeedbackQuestions(result); //TODO: maybe put in box
6166
addVSpace(10);
62-
addOkButton();
63-
67+
addButtons(result);
68+
6469
pack();
6570
}
66-
71+
6772
public void addOkListener(ActionListener okListener) {
6873
this.okButton.addActionListener(okListener);
6974
}
70-
75+
7176
public List<FeedbackAnswer> getFeedbackAnswers() {
72-
List<FeedbackAnswer> answers = new ArrayList<FeedbackAnswer>();
77+
List<FeedbackAnswer> answers = new ArrayList<>();
7378
for (FeedbackQuestionPanel panel : feedbackQuestionPanels) {
7479
FeedbackAnswer answer = panel.getAnswer();
7580
if (answer != null) {
@@ -78,42 +83,42 @@ public List<FeedbackAnswer> getFeedbackAnswers() {
7883
}
7984
return answers;
8085
}
81-
86+
8287
private void addVSpace(int height) {
8388
add(Box.createVerticalStrut(height));
8489
}
85-
90+
8691
private Box leftAligned(Component component) {
8792
return hbox(component, hglue());
8893
}
89-
94+
9095
private void addYayLabel() {
9196
JLabel yayLabel = new JLabel("All tests passed on the server.");
92-
97+
9398
Font font = yayLabel.getFont();
9499
font = font.deriveFont(Font.BOLD, font.getSize2D() * 1.2f);
95100
yayLabel.setFont(font);
96-
101+
97102
yayLabel.setForeground(new java.awt.Color(0, 153, 51));
98103
yayLabel.setIcon(ConvenientDialogDisplayer.getDefault().getSmileyIcon());
99-
104+
100105
getContentPane().add(leftAligned(yayLabel));
101106
}
102-
107+
103108
private void addRequiresReviewLabels() {
104109
JLabel lbl1 = new JLabel("This exercise requires a code review.");
105110
JLabel lbl2 = new JLabel("It will have a yellow marker until it's accepted by an instructor.");
106111
getContentPane().add(leftAligned(lbl1));
107112
getContentPane().add(leftAligned(lbl2));
108113
}
109-
114+
110115
private void addPointsLabel(SubmissionResult result) {
111116
JLabel pointsLabel = new JLabel(getPointsMsg(result));
112117
pointsLabel.setFont(pointsLabel.getFont().deriveFont(Font.BOLD));
113-
118+
114119
getContentPane().add(leftAligned(pointsLabel));
115120
}
116-
121+
117122
private String getPointsMsg(SubmissionResult result) {
118123
if (!result.getPoints().isEmpty()) {
119124
String msg = "Points permanently awarded: " + StringUtils.join(result.getPoints(), ", ") + ".";
@@ -131,19 +136,19 @@ private void addModelSolutionButton(SubmissionResult result) {
131136
public void actionPerformed(ActionEvent ev) {
132137
try {
133138
HtmlBrowser.URLDisplayer.getDefault().showURLExternal(new URL(solutionUrl));
134-
} catch (Exception ex) {
139+
} catch (MalformedURLException ex) {
135140
ConvenientDialogDisplayer.getDefault().displayError("Failed to open browser.\n" + ex.getMessage());
136141
}
137142
}
138143
});
139-
144+
140145
getContentPane().add(leftAligned(solutionButton));
141146
}
142147
}
143148

144149
private void addFeedbackQuestions(SubmissionResult result) {
145-
this.feedbackQuestionPanels = new ArrayList<FeedbackQuestionPanel>();
146-
150+
this.feedbackQuestionPanels = new ArrayList<>();
151+
147152
if (!result.getFeedbackQuestions().isEmpty() && result.getFeedbackAnswerUrl() != null) {
148153
for (FeedbackQuestion question : result.getFeedbackQuestions()) {
149154
try {
@@ -153,12 +158,12 @@ private void addFeedbackQuestions(SubmissionResult result) {
153158
log.warning(e.getMessage());
154159
}
155160
}
156-
161+
157162
if (!feedbackQuestionPanels.isEmpty()) { // Some failsafety
158163
JLabel feedbackLabel = new JLabel("Feedback (leave empty to not send)");
159164
feedbackLabel.setFont(feedbackLabel.getFont().deriveFont(Font.BOLD));
160165
getContentPane().add(leftAligned(feedbackLabel));
161-
166+
162167
for (FeedbackQuestionPanel panel : feedbackQuestionPanels) {
163168
getContentPane().add(leftAligned(panel));
164169
}
@@ -167,17 +172,45 @@ private void addFeedbackQuestions(SubmissionResult result) {
167172
}
168173
}
169174
}
170-
171-
private void addOkButton() {
175+
176+
private void addButtons(SubmissionResult result) {
177+
JPanel buttonPane = new JPanel();
178+
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
179+
180+
Optional<URI> submissionUrl = Optional.absent();
181+
final String submissionUrlString = result.getSubmissionUrl();
182+
if (submissionUrlString != null && !submissionUrlString.isEmpty()) {
183+
submissionUrl = Optional.of(URI.create(submissionUrlString));
184+
}
185+
addShowSubmissionButton(buttonPane, submissionUrl);
186+
addOkButton(buttonPane);
187+
getContentPane().add(buttonPane);
188+
}
189+
190+
private void addOkButton(JPanel buttonPane) {
172191
okButton = new JButton("OK");
173-
okButton.addActionListener(new ActionListener() {
192+
okButton.addActionListener((ActionEvent e) -> {
193+
setVisible(false);
194+
dispose();
195+
});
196+
buttonPane.add(hbox(hglue(), okButton));
197+
}
198+
199+
private void addShowSubmissionButton(JPanel buttonPane, Optional<URI> submissionUrl) {
200+
if (!submissionUrl.isPresent()) {
201+
return;
202+
}
203+
showSubmissionButton = new JButton("View submission in browser");
204+
showSubmissionButton.setAction(new AbstractAction("View submission in browser") {
174205
@Override
175-
public void actionPerformed(ActionEvent e) {
176-
setVisible(false);
177-
dispose();
206+
public void actionPerformed(ActionEvent ae) {
207+
try {
208+
HtmlBrowser.URLDisplayer.getDefault().showURLExternal(submissionUrl.get().toURL());
209+
} catch (MalformedURLException ex) {
210+
ConvenientDialogDisplayer.getDefault().displayError("Failed to open browser.\n" + ex.getMessage());
211+
}
178212
}
179213
});
180-
getContentPane().add(hbox(hglue(), okButton));
214+
buttonPane.add(showSubmissionButton);
181215
}
182-
183216
}

0 commit comments

Comments
 (0)