From f541a994b9a83644a16f8c008f71c7249027b8a6 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 8 Feb 2021 18:18:43 +0100 Subject: [PATCH] Cleaned up adding attributes slightly, made attribute types more readable. --- .../actions/edits/AddAttributeAction.java | 9 +++++---- .../actions/edits/AddRelationAction.java | 3 ++- .../andrewlalis/erme/model/AttributeType.java | 20 ++++++++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddAttributeAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddAttributeAction.java index 9cef6fb..59ee032 100644 --- a/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddAttributeAction.java +++ b/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddAttributeAction.java @@ -44,6 +44,7 @@ public class AddAttributeAction extends AbstractAction { return; } Relation r = selectedRelations.get(0); + Attribute createdAttribute; Component c = (Component) e.getSource(); String name = JOptionPane.showInputDialog(c, "Enter the name of the attribute.", "Attribute Name", JOptionPane.PLAIN_MESSAGE); if (name == null) return; @@ -105,11 +106,11 @@ public class AddAttributeAction extends AbstractAction { eligibleAttributes.toArray(new Attribute[0]), eligibleAttributes.get(0) ); - if (fkAttribute != null) { - r.addAttribute(new ForeignKeyAttribute(r, type, name, fkAttribute), index); - } + if (fkAttribute == null) return; + createdAttribute = new ForeignKeyAttribute(r, type, name, fkAttribute); } else { - r.addAttribute(new Attribute(r, type, name), index); + createdAttribute = new Attribute(r, type, name); } + r.addAttribute(createdAttribute, index); } } diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddRelationAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddRelationAction.java index a945557..9f7c904 100644 --- a/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddRelationAction.java +++ b/src/main/java/nl/andrewlalis/erme/control/actions/edits/AddRelationAction.java @@ -31,8 +31,9 @@ public class AddRelationAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { + Component c = (Component) e.getSource(); String name = JOptionPane.showInputDialog( - (Component) e.getSource(), + c, "Enter the name of the relation.", "Add Relation", JOptionPane.PLAIN_MESSAGE diff --git a/src/main/java/nl/andrewlalis/erme/model/AttributeType.java b/src/main/java/nl/andrewlalis/erme/model/AttributeType.java index 42f667f..10a8430 100644 --- a/src/main/java/nl/andrewlalis/erme/model/AttributeType.java +++ b/src/main/java/nl/andrewlalis/erme/model/AttributeType.java @@ -1,7 +1,21 @@ package nl.andrewlalis.erme.model; +import lombok.Getter; + public enum AttributeType { - PLAIN, - ID_KEY, - PARTIAL_ID_KEY + PLAIN("Plain"), + ID_KEY("Identifier"), + PARTIAL_ID_KEY("Partial Identifier"); + + @Getter + private final String name; + + AttributeType(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.getName(); + } }