/** @see org.eclipse.gef.commands.Command#canExecute() */ @Override public boolean canExecute() { boolean returnValue = true; if (foreignEntity.equals(primaryEntity)) { returnValue = false; } else { if (primaryEntity == null) { return false; } else { // Check for existence of relationship already List<ERDAssociation> relationships = primaryEntity.getPrimaryKeyRelationships(); for (int i = 0; i < relationships.size(); i++) { ERDAssociation currentRelationship = relationships.get(i); if (currentRelationship.getForeignKeyEntity().equals(foreignEntity)) { returnValue = false; break; } } } } return returnValue; }
/** @see org.eclipse.gef.commands.Command#redo() */ @Override public void redo() { foreignEntity.addForeignKeyRelationship(association, true); primaryEntity.addPrimaryKeyRelationship(association, true); }
/** Undo version of command */ @Override public void undo() { foreignEntity.removeForeignKeyRelationship(association, true); primaryEntity.removePrimaryKeyRelationship(association, true); }