Dipole states in stable and unstable nuclei