diff --git a/src/main/java/nl/andrewlalis/ui/control/command/executables/ArchiveRepos.java b/src/main/java/nl/andrewlalis/ui/control/command/executables/ArchiveRepos.java index 3f7368b..5e43269 100644 --- a/src/main/java/nl/andrewlalis/ui/control/command/executables/ArchiveRepos.java +++ b/src/main/java/nl/andrewlalis/ui/control/command/executables/ArchiveRepos.java @@ -8,9 +8,7 @@ import java.io.IOException; * Represents the action archive all repositories with a certain substring in their name. * It takes the following arguments: * - * 1. Organization name - * 2. Access Token - * 3. Repo substring to archive by + * 1. Repo substring to archive by */ public class ArchiveRepos extends GithubExecutable { diff --git a/src/main/java/nl/andrewlalis/ui/control/command/executables/ReadStudentsFileToDB.java b/src/main/java/nl/andrewlalis/ui/control/command/executables/ReadStudentsFileToDB.java index 2baf651..2d3ddc3 100644 --- a/src/main/java/nl/andrewlalis/ui/control/command/executables/ReadStudentsFileToDB.java +++ b/src/main/java/nl/andrewlalis/ui/control/command/executables/ReadStudentsFileToDB.java @@ -10,6 +10,10 @@ import java.util.List; /** * Execute this class to read students from a supplied filename and teamsize, and store their * information in the database. + * Requires the following arguments: + * + * 1. filename + * 2. teamsize */ public class ReadStudentsFileToDB implements Executable { diff --git a/src/main/java/nl/andrewlalis/ui/control/listeners/ArchiveAllListener.java b/src/main/java/nl/andrewlalis/ui/control/listeners/ArchiveAllListener.java new file mode 100644 index 0000000..cbdca70 --- /dev/null +++ b/src/main/java/nl/andrewlalis/ui/control/listeners/ArchiveAllListener.java @@ -0,0 +1,30 @@ +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; +import java.awt.event.ActionListener; + +public class ArchiveAllListener extends ExecutableListener { + + InitializerApp app; + + public ArchiveAllListener(CommandExecutor executor, InitializerApp app) { + super(executor); + this.app = app; + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + String response = JOptionPane.showInputDialog(null, "Enter a substring to archive repositories by.", "Enter a substring", JOptionPane.QUESTION_MESSAGE); + if (response != null) { + this.executor.executeCommand("archiveall", new String[]{ + this.app.getOrganizationName(), + this.app.getAccessToken(), + response + }); + } + } +} diff --git a/src/main/java/nl/andrewlalis/ui/control/listeners/ExecutableListener.java b/src/main/java/nl/andrewlalis/ui/control/listeners/ExecutableListener.java new file mode 100644 index 0000000..545bfc5 --- /dev/null +++ b/src/main/java/nl/andrewlalis/ui/control/listeners/ExecutableListener.java @@ -0,0 +1,19 @@ +package nl.andrewlalis.ui.control.listeners; + +import nl.andrewlalis.ui.control.command.CommandExecutor; +import nl.andrewlalis.ui.control.command.Executable; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * An action listener which is pre-set to execute an executable once an action is performed. + */ +public abstract class ExecutableListener implements ActionListener { + + protected CommandExecutor executor; + + public ExecutableListener(CommandExecutor executor) { + this.executor = executor; + } +} diff --git a/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java b/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java index e02ca8f..109be5b 100644 --- a/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java +++ b/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java @@ -1,8 +1,10 @@ package nl.andrewlalis.ui.view; -import nl.andrewlalis.ui.control.command.CommandExecutor; -import nl.andrewlalis.ui.control.listeners.CommandFieldKeyListener; import nl.andrewlalis.ui.control.OutputTextHandler; +import nl.andrewlalis.ui.control.command.CommandExecutor; +import nl.andrewlalis.ui.control.command.executables.ArchiveRepos; +import nl.andrewlalis.ui.control.listeners.ArchiveAllListener; +import nl.andrewlalis.ui.control.listeners.CommandFieldKeyListener; import javax.swing.*; import java.awt.*; @@ -111,6 +113,30 @@ public class InitializerApp extends JFrame { githubManagerPanel.add(infoInputPanel, BorderLayout.NORTH); + // Common actions panel. + 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); + + JButton generateStudentTeamsButton = new JButton("Read teams from file"); + generateStudentTeamsButton.addActionListener(actionEvent -> { + JFileChooser chooser = new JFileChooser(); + int returnValue = chooser.showOpenDialog(null); + if (returnValue == JFileChooser.APPROVE_OPTION) { + this.executor.executeCommand("readstudents", new String[]{ + chooser.getSelectedFile().getName(), + teamSizeField.getText() + }); + } + + }); + commonActionsPanel.add(generateStudentTeamsButton); + + githubManagerPanel.add(commonActionsPanel, BorderLayout.CENTER); + return githubManagerPanel; } @@ -165,4 +191,20 @@ public class InitializerApp extends JFrame { return newPanel; } + /** + * Gets the organization name entered in the relevant field. + * @return The organization name the user has entered. + */ + public String getOrganizationName() { + return this.organizationField.getText().trim(); + } + + /** + * Gets the oauth access token entered in the relevant field. + * @return The access token the user has entered. + */ + public String getAccessToken() { + return this.accessTokenField.getText().trim(); + } + }