Added delete repos command, made ListErrors better, and formatted buttons more nicely.

This commit is contained in:
Andrew Lalis 2018-09-01 08:25:45 +02:00
parent 10555a5d0c
commit a44814b1df
6 changed files with 81 additions and 13 deletions

View File

@ -42,6 +42,7 @@ public class Main {
executor.registerCommand("generate_assignments", new GenerateAssignmentsRepo());
executor.registerCommand("define_ta_teams", new DefineTaTeams(app));
executor.registerCommand("list_errors", new ListErrors());
executor.registerCommand("delete_repos", new DeleteRepos());
logger.info("GithubManager for Github Repositories in Educational Organizations.\n" +
"© Andrew Lalis (2018), All rights reserved.\n" +

View File

@ -168,6 +168,7 @@ public class GithubManager {
if (repo.getName().contains(substring)) {
try {
repo.delete();
logger.info("Deleted repository: " + repo.getName());
} catch (IOException e) {
InitializerApp.organization.addError(new Error(Severity.HIGH, "Could not delete repository: " + repo.getName()));
e.printStackTrace();

View File

@ -0,0 +1,17 @@
package nl.andrewlalis.ui.control.command.executables;
import nl.andrewlalis.git_api.GithubManager;
/**
* Deletes all repositories with a given substring.
*/
public class DeleteRepos extends GithubExecutable {
@Override
protected boolean executeWithManager(GithubManager manager, String[] args) {
if (args.length < 1) {
return false;
}
manager.deleteAllRepositories(args[0]);
return true;
}
}

View File

@ -22,6 +22,9 @@ public class ListErrors implements Executable {
@Override
public boolean execute(String[] args) {
StringBuilder sb = new StringBuilder("Runtime Errors:\n");
if (InitializerApp.organization.getErrors().isEmpty()) {
sb.append("None");
}
for (Error error : InitializerApp.organization.getErrors()) {
sb.append(error);
}

View File

@ -0,0 +1,32 @@
package nl.andrewlalis.ui.control.listeners;
import nl.andrewlalis.ui.control.command.CommandExecutor;
import nl.andrewlalis.ui.view.InitializerApp;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* A listener for when the user wants to delete repositories.
*/
public class DeleteReposListener extends ExecutableListener {
public DeleteReposListener(CommandExecutor executor, InitializerApp app) {
super(executor, app);
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
String input = JOptionPane.showInputDialog(this.app, "Please enter a string which, if a repository contains it, results in deleting the repository.", "Enter Substing", JOptionPane.QUESTION_MESSAGE);
if (input != null) {
int decision = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete all repositories that contain \"" + "\" in their name?", "Delete Repositories", JOptionPane.YES_NO_OPTION);
if (decision == JOptionPane.YES_OPTION) {
this.executor.executeCommand("delete_repos", new String[]{
app.getOrganizationName(),
app.getAccessToken(),
input
});
}
}
}
}

View File

@ -7,6 +7,7 @@ import nl.andrewlalis.ui.control.listeners.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -118,23 +119,22 @@ public class InitializerApp extends JFrame {
JPanel commonActionsPanel = new JPanel();
commonActionsPanel.setLayout(new BoxLayout(commonActionsPanel, BoxLayout.PAGE_AXIS));
JButton archiveAllButton = new JButton("Archive All");
archiveAllButton.addActionListener(new ArchiveAllListener(this.executor, this));
commonActionsPanel.add(archiveAllButton);
commonActionsPanel.add(this.generateButtonPanel("Archive All", new ArchiveAllListener(this.executor, this)));
commonActionsPanel.add(this.generateButtonPanel("Read Students File", new ReadStudentsFileListener(this.executor, this)));
commonActionsPanel.add(this.generateButtonPanel("Generate Assignments Repo", new GenerateAssignmentsRepoListener(this.executor, this)));
JButton generateStudentTeamsButton = new JButton("Read teams from file");
generateStudentTeamsButton.addActionListener(new ReadStudentsFileListener(this.executor, this));
commonActionsPanel.add(generateStudentTeamsButton);
// TODO: Enable this once the define teams dialog is complete.
// JButton defineTaTeamsButton = new JButton("Define TA Teams");
// defineTaTeamsButton.addActionListener(new DefineTaTeamsListener(this.executor, this));
// commonActionsPanel.add(f);
JButton generateAssignmentsRepoButton = new JButton("Generate Assignments Repo");
generateAssignmentsRepoButton.addActionListener(new GenerateAssignmentsRepoListener(this.executor, this));
commonActionsPanel.add(generateAssignmentsRepoButton);
commonActionsPanel.add(this.generateButtonPanel("Delete Repos", new DeleteReposListener(this.executor, this)));
JButton defineTaTeamsButton = new JButton("Define TA Teams");
defineTaTeamsButton.addActionListener(new DefineTaTeamsListener(this.executor, this));
commonActionsPanel.add(defineTaTeamsButton);
// Extra panel to push buttons to the top.
JPanel buttonAlignmentPanel = new JPanel(new BorderLayout());
buttonAlignmentPanel.add(commonActionsPanel, BorderLayout.NORTH);
githubManagerPanel.add(commonActionsPanel, BorderLayout.CENTER);
githubManagerPanel.add(buttonAlignmentPanel, BorderLayout.CENTER);
return githubManagerPanel;
}
@ -190,6 +190,20 @@ public class InitializerApp extends JFrame {
return newPanel;
}
/**
* Generates a button with an attached action listener.
* @param buttonText The text to display on the button.
* @param listener The listener to attach to the button.
* @return A BorderLayout JPanel which contains the button in the CENTER location.
*/
private JPanel generateButtonPanel(String buttonText, ActionListener listener) {
JPanel panel = new JPanel(new BorderLayout());
JButton button = new JButton(buttonText);
button.addActionListener(listener);
panel.add(button, BorderLayout.CENTER);
return panel;
}
/**
* Gets the organization name entered in the relevant field.
* @return The organization name the user has entered.