package ui; import model.ca.Template; /** * The screen that allows users to list templates and manage them. */ public class TemplatesScreen implements UIHandler { private final JCA session; /** * EFFECTS: Init with the session. */ public TemplatesScreen(JCA session) { this.session = session; } /** * EFFECTS: Print help. */ @Override public void help() { System.out.println("show\tList templates\n" + "add\tCreate a new template\n" + "enable\tEnable a template\n" + "disable\tDisable a template\n" + "delete\tDelete a template\n" + "exit\tGo to main menu\n" + "help\tPrint this message"); } /** * EFFECTS: List templates in Name[ENABLED / DISABLED] Subject Validity format. */ @Override public void show() { session.getTemplates().forEach(tem -> System.out.printf("%s[%s]\t%s\t%d Days\n", tem.getName(), tem.isEnabled() ? "ENABLED" : "DISABLED", tem.getSubject(), tem.getValidity())); } /** * EFFECTS: Create a new template with the given name and switch to the template set screen. */ private void handleAdd(String... args) { if (args.length <= 1) { System.out.println("Usage: add "); return; } if (session.findTemplate(args[1], false) != null) { System.out.println("The template already exists."); return; } session.setScreen(Screen.TEMPLATE_SET, new Template(args[1], false, null, 30)); } /** * EFFECTS: Handle the enable / disable commands. * MODIFIES: session */ private void handleEnableDisable(boolean enable, String... args) { if (args.length <= 1) { System.out.printf("Usage: %s