Cadbury has struck a deal with workers over the closure of its gum factory in the Catalan city of Barcelona.