-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b59a83
commit 28f2806
Showing
8 changed files
with
261 additions
and
8 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/io/github/thepieterdc/dodona/plugin/authentication/AuthenticationConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2018-2019. All rights reserved. | ||
* | ||
* @author Pieter De Clercq | ||
* @author Tobiah Lissens | ||
* | ||
* https://github.com/thepieterdc/dodona-plugin-jetbrains/ | ||
*/ | ||
|
||
package io.github.thepieterdc.dodona.plugin.authentication; | ||
|
||
/** | ||
* Provides an authentication token to the caller. | ||
*/ | ||
@FunctionalInterface | ||
public interface AuthenticationConsumer { | ||
/** | ||
* Authenticates the current class using the provided authentication token. | ||
* | ||
* @param token the authentication token | ||
*/ | ||
void authenticate(final String token); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/io/github/thepieterdc/dodona/plugin/tasks/ShowSubmissionTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2018-2019. All rights reserved. | ||
* | ||
* @author Pieter De Clercq | ||
* @author Tobiah Lissens | ||
* | ||
* https://github.com/thepieterdc/dodona-plugin-jetbrains/ | ||
*/ | ||
|
||
package io.github.thepieterdc.dodona.plugin.tasks; | ||
|
||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.openapi.project.Project; | ||
import io.github.thepieterdc.dodona.plugin.DodonaBundle; | ||
import io.github.thepieterdc.dodona.plugin.api.DodonaExecutor; | ||
import io.github.thepieterdc.dodona.plugin.authentication.DodonaAuthenticator; | ||
import io.github.thepieterdc.dodona.plugin.ui.browser.BrowserDialog; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.swing.*; | ||
|
||
/** | ||
* Shows a submission result. | ||
*/ | ||
public class ShowSubmissionTask extends AbstractDodonaBackgroundTask { | ||
private final DodonaExecutor executor; | ||
private final long submissionId; | ||
|
||
/** | ||
* ShowSubmissionTask constructor. | ||
* | ||
* @param project the current project | ||
* @param submissionId the submission id | ||
*/ | ||
private ShowSubmissionTask(final Project project, | ||
final long submissionId) { | ||
super(project, DodonaBundle.message("tasks.show_submission.title")); | ||
this.executor = DodonaAuthenticator.getInstance().getExecutor(); | ||
this.submissionId = submissionId; | ||
} | ||
|
||
/** | ||
* Creates a submission rendering task. | ||
* | ||
* @param project the current project | ||
* @param submissionId the id of the submission to display | ||
* @return the task | ||
*/ | ||
@Nonnull | ||
public static DodonaBackgroundTask create(final Project project, | ||
final long submissionId) { | ||
return new ShowSubmissionTask(project, submissionId); | ||
} | ||
|
||
@Override | ||
public void run(@NotNull final ProgressIndicator progress) { | ||
// Update the progressbar. | ||
progress.setIndeterminate(true); | ||
progress.setText(DodonaBundle.message("tasks.show_submission.loading")); | ||
|
||
// Fetch the url of the submission. | ||
final String url = this.executor.execute(dodona -> | ||
dodona.submissions().get(this.submissionId), progress) | ||
.getUrl(); | ||
|
||
// Show a BrowserDialog with the submission | ||
SwingUtilities.invokeLater(() -> { | ||
// Create the window. | ||
final BrowserDialog browser = new BrowserDialog( | ||
this.myProject, | ||
DodonaBundle.message("tasks.show_submission.title") | ||
); | ||
|
||
// Append the authentication data. | ||
DodonaAuthenticator.getInstance().authenticate(browser); | ||
|
||
// Load the url and show the browser. | ||
browser.loadUrl(url); | ||
browser.show(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/io/github/thepieterdc/dodona/plugin/ui/browser/BrowserDialog.form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="io.github.thepieterdc.dodona.plugin.ui.browser.BrowserDialog"> | ||
<grid id="27dc6" binding="rootPanel" layout-manager="CardLayout" hgap="0" vgap="0"> | ||
<constraints> | ||
<xy x="20" y="20" width="500" height="400"/> | ||
</constraints> | ||
<properties> | ||
<focusable value="false"/> | ||
</properties> | ||
<border type="none"/> | ||
<children/> | ||
</grid> | ||
</form> |
105 changes: 105 additions & 0 deletions
105
src/main/java/io/github/thepieterdc/dodona/plugin/ui/browser/BrowserDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2018-2019. All rights reserved. | ||
* | ||
* @author Pieter De Clercq | ||
* @author Tobiah Lissens | ||
* | ||
* https://github.com/thepieterdc/dodona-plugin-jetbrains/ | ||
*/ | ||
|
||
package io.github.thepieterdc.dodona.plugin.ui.browser; | ||
|
||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.ui.DialogWrapper; | ||
import com.intellij.ui.ScrollPaneFactory; | ||
import com.intellij.util.ui.AsyncProcessIcon; | ||
import io.github.thepieterdc.dodona.plugin.authentication.AuthenticationConsumer; | ||
import org.jetbrains.annotations.NonNls; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Dialog showing a webbrowser. | ||
*/ | ||
public class BrowserDialog extends DialogWrapper implements AuthenticationConsumer { | ||
@NonNls | ||
private static final String CARD_LOADING = "BROWSER_LOADING"; | ||
@NonNls | ||
private static final String CARD_PAGE = "BROWSER_PAGE"; | ||
|
||
@NonNls | ||
private static final String CONTENT_TYPE = "text/html"; | ||
|
||
private static final int HEIGHT = 250; | ||
private static final int WIDTH = 400; | ||
|
||
private String token; | ||
|
||
private final AsyncProcessIcon loadingIcon; | ||
|
||
private final JEditorPane browserPanel; | ||
private JPanel rootPanel; | ||
|
||
/** | ||
* BrowserDialog constructor. | ||
* | ||
* @param project the current project | ||
*/ | ||
public BrowserDialog(final Project project, | ||
final String title) { | ||
super(project, true); | ||
this.browserPanel = new JEditorPane(); | ||
this.loadingIcon = new AsyncProcessIcon(this.getClass() + ".loading"); | ||
this.rootPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT)); | ||
|
||
this.setTitle(title); | ||
this.init(); | ||
|
||
this.initialize(); | ||
} | ||
|
||
@Override | ||
public void authenticate(final String nwToken) { | ||
this.token = nwToken; | ||
} | ||
|
||
@Override | ||
protected JComponent createCenterPanel() { | ||
return this.rootPanel; | ||
} | ||
|
||
/** | ||
* Initializes the UI. | ||
*/ | ||
private void initialize() { | ||
// Configure the browser panel. | ||
this.browserPanel.setContentType(CONTENT_TYPE); | ||
this.browserPanel.setEditable(false); | ||
|
||
// Add the browser panel. | ||
this.rootPanel.add( | ||
ScrollPaneFactory.createScrollPane(this.browserPanel), | ||
CARD_PAGE | ||
); | ||
|
||
// Add the loading panel. | ||
final JPanel loadingPanel = new JPanel(new BorderLayout()); | ||
loadingPanel.add(this.loadingIcon, BorderLayout.CENTER); | ||
this.rootPanel.add(loadingPanel, CARD_LOADING); | ||
} | ||
|
||
/** | ||
* Loads the given url in the browser window. | ||
* | ||
* @param url the url to load | ||
*/ | ||
public void loadUrl(final String url) { | ||
try { | ||
this.browserPanel.setPage(url); | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/io/github/thepieterdc/dodona/plugin/ui/browser/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2018-2019. All rights reserved. | ||
* | ||
* @author Pieter De Clercq | ||
* @author Tobiah Lissens | ||
* | ||
* https://github.com/thepieterdc/dodona-plugin-jetbrains/ | ||
*/ | ||
|
||
/** | ||
* Browser component. | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
package io.github.thepieterdc.dodona.plugin.ui.browser; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters