Added stuff

This commit is contained in:
Andrew Lalis 2018-08-27 17:53:31 +02:00
parent cd0aa85dba
commit 346419d5b6
5 changed files with 98 additions and 5 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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
});
}
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}