aboutsummaryrefslogtreecommitdiff
path: root/src/main/ui/IssueDialog.java
diff options
context:
space:
mode:
authorYuuta Liang <yuutaw@student.cs.ubc.ca>2023-11-28 18:19:39 -0800
committerYuuta Liang <yuutaw@student.cs.ubc.ca>2023-11-28 18:19:39 -0800
commit1073af21305360bd33903c533cdac57e9f936294 (patch)
tree2c2d9c343ffe2577286fb53e016f06f6cdc53cbf /src/main/ui/IssueDialog.java
parente13adbb9a9146dd5ece890449e3cad958a502f86 (diff)
downloadjca-1073af21305360bd33903c533cdac57e9f936294.tar
jca-1073af21305360bd33903c533cdac57e9f936294.tar.gz
jca-1073af21305360bd33903c533cdac57e9f936294.tar.bz2
jca-1073af21305360bd33903c533cdac57e9f936294.zip
Move TUI and GUI into separate packages
Signed-off-by: Yuuta Liang <yuutaw@student.cs.ubc.ca>
Diffstat (limited to 'src/main/ui/IssueDialog.java')
-rw-r--r--src/main/ui/IssueDialog.java101
1 files changed, 0 insertions, 101 deletions
diff --git a/src/main/ui/IssueDialog.java b/src/main/ui/IssueDialog.java
deleted file mode 100644
index c757d8f..0000000
--- a/src/main/ui/IssueDialog.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package ui;
-
-import model.asn1.exceptions.ParseException;
-import model.ca.Template;
-import model.csr.CertificationRequest;
-import model.x501.Name;
-import ui.widgets.CertEditDialog;
-
-import javax.swing.*;
-import java.awt.event.ActionEvent;
-import java.util.List;
-
-import static ui.widgets.UIUtils.alert;
-
-/**
- * Dialog that allows user to choose a template and edit the incoming CSR properties to get it signed.
- */
-public class IssueDialog extends CertEditDialog<Template> {
- /**
- * The list of templates.
- */
- private final List<Template> templates;
-
- /**
- * The incoming CSR.
- */
- private final CertificationRequest csr;
-
- /**
- * Combo box to choose template.
- */
- private JComboBox<String> componentTemp;
-
- /**
- * The selected template, immutable.
- */
- private Template selectedTemplate;
-
- /**
- * EFFECTS: Init the dialog with CSR and templates.
- * REQUIRES: csr must have a subject; templates must have at least one enabled.
- */
- public IssueDialog(CertificationRequest csr, List<Template> templates) {
- super();
- this.csr = csr;
- this.templates = templates;
-
- setTitle("Issue new certificate");
- buttonOK.setText("Issue");
- componentTemp.setModel(new DefaultComboBoxModel<>(templates.stream()
- .filter(Template::isEnabled).map(Template::getName).toArray(String[]::new)));
- componentTemp.addActionListener(this::onTemplateChange);
-
- onTemplateChange(null);
- pack();
- }
-
- /**
- * EFFECTS: Create the templates combo box.
- * MODIFIES: this
- */
- @Override
- protected JComponent createTemplateComponent() {
- return componentTemp = new JComboBox<>();
- }
-
- /**
- * EFFECTS: Validate the form, compose a resulting template, close the dialog.
- * MODIFIES: this
- */
- @Override
- protected void onOK(ActionEvent ev) {
- if (textFieldSubject.getText().isEmpty()) {
- alert(this, getTitle(), "Subject must not be empty.");
- return;
- }
- try {
- res = new Template(selectedTemplate.getName(),
- true,
- Name.parseString(textFieldSubject.getText()),
- ((SpinnerNumberModel) spinnerValidity.getModel()).getNumber().longValue());
- dispose();
- } catch (ParseException e) {
- alert(this, getTitle(), e);
- }
- }
-
- /**
- * EFFECTS: Handle template change, rewrite the form with the new template.
- * MODIFIES: this
- */
- private void onTemplateChange(ActionEvent ae) {
- selectedTemplate = templates.stream()
- .filter(temp -> temp.getName().equals(componentTemp.getSelectedItem()))
- .findFirst()
- .get();
- textFieldSubject.setText(selectedTemplate.getSubject() != null ? selectedTemplate.getSubject().toString() :
- csr.getCertificationRequestInfo().getSubject().toString());
- spinnerValidity.setValue(selectedTemplate.getValidity());
- }
-}