diff options
Diffstat (limited to 'src/main/ui/TemplateEditDialog.java')
-rw-r--r-- | src/main/ui/TemplateEditDialog.java | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/src/main/ui/TemplateEditDialog.java b/src/main/ui/TemplateEditDialog.java deleted file mode 100644 index a3986de..0000000 --- a/src/main/ui/TemplateEditDialog.java +++ /dev/null @@ -1,73 +0,0 @@ -package ui; - -import model.asn1.exceptions.ParseException; -import model.ca.Template; -import model.x501.Name; -import ui.widgets.CertEditDialog; - -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.util.function.Function; - -import static ui.widgets.UIUtils.alert; - -/** - * A dialog that allows users to input template name, subject, and validity. - */ -public class TemplateEditDialog extends CertEditDialog<Template> { - /** - * Callback function to check for name conflict. - */ - private final Function<String, Boolean> dupDetector; - - /** - * Text field for name. - */ - private JTextField templateComponent; - - /** - * EFFECTS: Init UI, title = New Template, OK button = Add, set dup detector. - */ - public TemplateEditDialog(Function<String, Boolean> dupDetector) { - super(); - this.dupDetector = dupDetector; - setTitle("New template"); - buttonOK.setText("Add"); - } - - /** - * EFFECTS: Initialize the subject text field with JTextField. - * MODIFIES: this - */ - @Override - protected JComponent createTemplateComponent() { - return templateComponent = new JTextField(); - } - - /** - * EFFECTS: Validate the form, set the result, and close the dialog. - * Name must not be null; Name must not conflict; Subject must be valid. - * MODIFIES: this - */ - @Override - protected void onOK(ActionEvent ev) { - if (templateComponent.getText().isEmpty()) { - alert(rootPane, getTitle(), "The template name must not be empty."); - return; - } - if (dupDetector.apply(templateComponent.getText())) { - alert(rootPane, getTitle(), "The template exists."); - return; - } - - try { - res = new Template(templateComponent.getText(), - false, - textFieldSubject.getText().isBlank() ? null : Name.parseString(textFieldSubject.getText()), - (Integer) spinnerValidity.getValue()); - dispose(); - } catch (ParseException e) { - alert(rootPane, getTitle(), e); - } - } -} |