Cleaned up adding attributes slightly, made attribute types more readable.

This commit is contained in:
Andrew Lalis 2021-02-08 18:18:43 +01:00
parent cac3381c54
commit f541a994b9
3 changed files with 24 additions and 8 deletions

View File

@ -44,6 +44,7 @@ public class AddAttributeAction extends AbstractAction {
return; return;
} }
Relation r = selectedRelations.get(0); Relation r = selectedRelations.get(0);
Attribute createdAttribute;
Component c = (Component) e.getSource(); Component c = (Component) e.getSource();
String name = JOptionPane.showInputDialog(c, "Enter the name of the attribute.", "Attribute Name", JOptionPane.PLAIN_MESSAGE); String name = JOptionPane.showInputDialog(c, "Enter the name of the attribute.", "Attribute Name", JOptionPane.PLAIN_MESSAGE);
if (name == null) return; if (name == null) return;
@ -105,11 +106,11 @@ public class AddAttributeAction extends AbstractAction {
eligibleAttributes.toArray(new Attribute[0]), eligibleAttributes.toArray(new Attribute[0]),
eligibleAttributes.get(0) eligibleAttributes.get(0)
); );
if (fkAttribute != null) { if (fkAttribute == null) return;
r.addAttribute(new ForeignKeyAttribute(r, type, name, fkAttribute), index); createdAttribute = new ForeignKeyAttribute(r, type, name, fkAttribute);
}
} else { } else {
r.addAttribute(new Attribute(r, type, name), index); createdAttribute = new Attribute(r, type, name);
} }
r.addAttribute(createdAttribute, index);
} }
} }

View File

@ -31,8 +31,9 @@ public class AddRelationAction extends AbstractAction {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Component c = (Component) e.getSource();
String name = JOptionPane.showInputDialog( String name = JOptionPane.showInputDialog(
(Component) e.getSource(), c,
"Enter the name of the relation.", "Enter the name of the relation.",
"Add Relation", "Add Relation",
JOptionPane.PLAIN_MESSAGE JOptionPane.PLAIN_MESSAGE

View File

@ -1,7 +1,21 @@
package nl.andrewlalis.erme.model; package nl.andrewlalis.erme.model;
import lombok.Getter;
public enum AttributeType { public enum AttributeType {
PLAIN, PLAIN("Plain"),
ID_KEY, ID_KEY("Identifier"),
PARTIAL_ID_KEY PARTIAL_ID_KEY("Partial Identifier");
@Getter
private final String name;
AttributeType(String name) {
this.name = name;
}
@Override
public String toString() {
return this.getName();
}
} }