| 1 |
/** |
| 2 |
* Copyright (c) 2008 Tom Schindl and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v2.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v20.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Tom Schindl <[email protected]> - port to EMF in 295683 |
| 10 |
*/ |
| 11 |
package org.eclipse.emf.databinding.edit.internal; |
| 12 |
|
| 13 |
import java.util.Set; |
| 14 |
|
| 15 |
import org.eclipse.core.databinding.observable.set.SetDiff; |
| 16 |
|
| 17 |
import org.eclipse.emf.common.command.Command; |
| 18 |
import org.eclipse.emf.databinding.internal.EMFSetProperty; |
| 19 |
import org.eclipse.emf.ecore.EStructuralFeature; |
| 20 |
import org.eclipse.emf.edit.command.AddCommand; |
| 21 |
import org.eclipse.emf.edit.command.RemoveCommand; |
| 22 |
import org.eclipse.emf.edit.domain.EditingDomain; |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p> |
| 27 |
* |
| 28 |
* @since 2.6 |
| 29 |
*/ |
| 30 |
public class EMFEditSetProperty extends EMFSetProperty |
| 31 |
{ |
| 32 |
private final EditingDomain editingDomain; |
| 33 |
|
| 34 |
public EMFEditSetProperty(EditingDomain editingDomain, EStructuralFeature eStructuralFeature) |
| 35 |
{ |
| 36 |
super(eStructuralFeature); |
| 37 |
this.editingDomain = editingDomain; |
| 38 |
} |
| 39 |
|
| 40 |
@Override |
| 41 |
protected void doSetSet(Object source, Set set, SetDiff diff) |
| 42 |
{ |
| 43 |
if( diff.getAdditions() != null && ! diff.getAdditions().isEmpty() ) { |
| 44 |
execute(AddCommand.create(editingDomain, source, getFeature(), diff.getAdditions())); |
| 45 |
} |
| 46 |
|
| 47 |
if( diff.getRemovals() != null && ! diff.getRemovals().isEmpty() ) { |
| 48 |
execute(RemoveCommand.create(editingDomain, source, getFeature(), diff.getRemovals())); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
private void execute(Command command) |
| 53 |
{ |
| 54 |
editingDomain.getCommandStack().execute(command); |
| 55 |
} |
| 56 |
} |