Added read students listener, improved repository descriptions for student teams.
This commit is contained in:
		
							parent
							
								
									346419d5b6
								
							
						
					
					
						commit
						8c8ddb60cf
					
				| 
						 | 
					@ -65,8 +65,11 @@ public class StudentTeam extends Team{
 | 
				
			||||||
    public String generateRepoDescription() {
 | 
					    public String generateRepoDescription() {
 | 
				
			||||||
        StringBuilder sb = new StringBuilder();
 | 
					        StringBuilder sb = new StringBuilder();
 | 
				
			||||||
        sb.append("Group ").append(this.id).append(": ");
 | 
					        sb.append("Group ").append(this.id).append(": ");
 | 
				
			||||||
        for (Student s : this.getStudents()) {
 | 
					        for (int i = 0; i < this.memberCount(); i++) {
 | 
				
			||||||
            sb.append(s.getName()).append(' ');
 | 
					            sb.append(this.getStudents()[i].getName());
 | 
				
			||||||
 | 
					            if (i != this.memberCount()-1) {
 | 
				
			||||||
 | 
					                sb.append(", ");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return sb.toString();
 | 
					        return sb.toString();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,20 +5,19 @@ import nl.andrewlalis.ui.view.InitializerApp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.swing.*;
 | 
					import javax.swing.*;
 | 
				
			||||||
import java.awt.event.ActionEvent;
 | 
					import java.awt.event.ActionEvent;
 | 
				
			||||||
import java.awt.event.ActionListener;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Listens for when the user performs an action with the intent to archive all repositories.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
public class ArchiveAllListener extends ExecutableListener {
 | 
					public class ArchiveAllListener extends ExecutableListener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    InitializerApp app;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ArchiveAllListener(CommandExecutor executor, InitializerApp app) {
 | 
					    public ArchiveAllListener(CommandExecutor executor, InitializerApp app) {
 | 
				
			||||||
        super(executor);
 | 
					        super(executor, app);
 | 
				
			||||||
        this.app = app;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void actionPerformed(ActionEvent actionEvent) {
 | 
					    public void actionPerformed(ActionEvent actionEvent) {
 | 
				
			||||||
        String response = JOptionPane.showInputDialog(null, "Enter a substring to archive repositories by.", "Enter a substring", JOptionPane.QUESTION_MESSAGE);
 | 
					        String response = JOptionPane.showInputDialog(this.app, "Enter a substring to archive repositories by.", "Enter a substring", JOptionPane.QUESTION_MESSAGE);
 | 
				
			||||||
        if (response != null) {
 | 
					        if (response != null) {
 | 
				
			||||||
            this.executor.executeCommand("archiveall", new String[]{
 | 
					            this.executor.executeCommand("archiveall", new String[]{
 | 
				
			||||||
                    this.app.getOrganizationName(),
 | 
					                    this.app.getOrganizationName(),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,19 +1,29 @@
 | 
				
			||||||
package nl.andrewlalis.ui.control.listeners;
 | 
					package nl.andrewlalis.ui.control.listeners;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.andrewlalis.ui.control.command.CommandExecutor;
 | 
					import nl.andrewlalis.ui.control.command.CommandExecutor;
 | 
				
			||||||
import nl.andrewlalis.ui.control.command.Executable;
 | 
					import nl.andrewlalis.ui.view.InitializerApp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.awt.event.ActionEvent;
 | 
					 | 
				
			||||||
import java.awt.event.ActionListener;
 | 
					import java.awt.event.ActionListener;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * An action listener which is pre-set to execute an executable once an action is performed.
 | 
					 * An action listener which is pre-set to execute an executable once an action is performed.
 | 
				
			||||||
 | 
					 * Since these are used for the user interface, an instance of the application is passed, for the purpose of providing
 | 
				
			||||||
 | 
					 * a parent component for many popups, and to have access to input fields.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public abstract class ExecutableListener implements ActionListener {
 | 
					public abstract class ExecutableListener implements ActionListener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The executor, with some registered commands that will be executed by listeners which extend this one.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    protected CommandExecutor executor;
 | 
					    protected CommandExecutor executor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public ExecutableListener(CommandExecutor executor) {
 | 
					    /**
 | 
				
			||||||
 | 
					     * An instance of the UI application.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected InitializerApp app;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ExecutableListener(CommandExecutor executor, InitializerApp app) {
 | 
				
			||||||
        this.executor = executor;
 | 
					        this.executor = executor;
 | 
				
			||||||
 | 
					        this.app = app;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,33 @@
 | 
				
			||||||
 | 
					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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Listens for when the user performs an action to read all students from a file, and output the contents to a database.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class ReadStudentsFileListener extends ExecutableListener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ReadStudentsFileListener(CommandExecutor executor, InitializerApp app) {
 | 
				
			||||||
 | 
					        super(executor, app);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void actionPerformed(ActionEvent actionEvent) {
 | 
				
			||||||
 | 
					        JFileChooser chooser = new JFileChooser();
 | 
				
			||||||
 | 
					        int fileResponse = chooser.showOpenDialog(this.app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (fileResponse == JFileChooser.APPROVE_OPTION) {
 | 
				
			||||||
 | 
					            String teamSizeString = JOptionPane.showInputDialog(this.app, "Enter the student team size.", "Team Size", JOptionPane.QUESTION_MESSAGE);
 | 
				
			||||||
 | 
					            if (teamSizeString != null) {
 | 
				
			||||||
 | 
					                this.executor.executeCommand("readstudents", new String[]{
 | 
				
			||||||
 | 
					                        chooser.getSelectedFile().getName(),
 | 
				
			||||||
 | 
					                        teamSizeString
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@ import nl.andrewlalis.ui.control.command.CommandExecutor;
 | 
				
			||||||
import nl.andrewlalis.ui.control.command.executables.ArchiveRepos;
 | 
					import nl.andrewlalis.ui.control.command.executables.ArchiveRepos;
 | 
				
			||||||
import nl.andrewlalis.ui.control.listeners.ArchiveAllListener;
 | 
					import nl.andrewlalis.ui.control.listeners.ArchiveAllListener;
 | 
				
			||||||
import nl.andrewlalis.ui.control.listeners.CommandFieldKeyListener;
 | 
					import nl.andrewlalis.ui.control.listeners.CommandFieldKeyListener;
 | 
				
			||||||
 | 
					import nl.andrewlalis.ui.control.listeners.ReadStudentsFileListener;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.swing.*;
 | 
					import javax.swing.*;
 | 
				
			||||||
import java.awt.*;
 | 
					import java.awt.*;
 | 
				
			||||||
| 
						 | 
					@ -108,8 +109,6 @@ public class InitializerApp extends JFrame {
 | 
				
			||||||
        this.teachingAssistantsField.setText("teaching-assistants");
 | 
					        this.teachingAssistantsField.setText("teaching-assistants");
 | 
				
			||||||
        infoInputPanel.add(generateTextFieldPanel("Student Repo Prefix", this.studentRepoField));
 | 
					        infoInputPanel.add(generateTextFieldPanel("Student Repo Prefix", this.studentRepoField));
 | 
				
			||||||
        this.studentRepoField.setText("advoop_2018");
 | 
					        this.studentRepoField.setText("advoop_2018");
 | 
				
			||||||
        infoInputPanel.add(generateTextFieldPanel("Team Size", this.teamSizeField));
 | 
					 | 
				
			||||||
        this.teamSizeField.setText("2");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        githubManagerPanel.add(infoInputPanel, BorderLayout.NORTH);
 | 
					        githubManagerPanel.add(infoInputPanel, BorderLayout.NORTH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -122,17 +121,7 @@ public class InitializerApp extends JFrame {
 | 
				
			||||||
        commonActionsPanel.add(archiveAllButton);
 | 
					        commonActionsPanel.add(archiveAllButton);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        JButton generateStudentTeamsButton = new JButton("Read teams from file");
 | 
					        JButton generateStudentTeamsButton = new JButton("Read teams from file");
 | 
				
			||||||
        generateStudentTeamsButton.addActionListener(actionEvent -> {
 | 
					        generateStudentTeamsButton.addActionListener(new ReadStudentsFileListener(this.executor, this));
 | 
				
			||||||
            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);
 | 
					        commonActionsPanel.add(generateStudentTeamsButton);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        githubManagerPanel.add(commonActionsPanel, BorderLayout.CENTER);
 | 
					        githubManagerPanel.add(commonActionsPanel, BorderLayout.CENTER);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue