Java 类org.eclipse.emf.ecore.change.FeatureChange 实例源码

项目:Vitruv    文件:ChangeDescriptionPrinter.java   
public static void printChangeDescription(ChangeDescription cd) {
    System.err.println("* Saved, detected a change.");
    System.err.println("* Saved, got change desc: " + cd.toString());
    System.err.println("* CD Class: " + cd.getClass().getCanonicalName());

    EMap<EObject, EList<FeatureChange>> changes = cd.getObjectChanges();

    for (EObject obj : changes.keySet()) {
        if (obj == null) {
            System.err.println("Got null object");
            continue;
        }
        System.err.println("Object: " + obj.toString());
        EList<FeatureChange> fcList = changes.get(obj);
        for (FeatureChange fc : fcList) {
            processFeatureChange(obj, fc, "  ");
        }
    }
}
项目:xtext-core    文件:PartialSerializer.java   
protected IAstRegion findRegion(IEObjectRegion owner, FeatureChange change) {
    EStructuralFeature feature = change.getFeature();
    if (feature instanceof EReference && ((EReference) feature).isContainment()) {
        ITextRegionAccess access = owner.getTextRegionAccess();
        EObject oldValue = change.getReferenceValue();
        if (oldValue != null) {
            return access.regionForEObject(oldValue);
        }
        EObject value = (EObject) owner.getSemanticElement().eGet(feature);
        if (value != null) {
            return access.regionForEObject(value);
        }
        return null;
    } else {
        return owner.getRegionFor().feature(feature);
    }
}
项目:OpenSPIFe    文件:SPIFePlanIntegrationOperation.java   
@Override
void execute() {
    ListChange listChange = null;

    if (newElement instanceof BinaryTemporalConstraint){
        listChange = createListFeatureChange(ChangeKind.ADD_LITERAL, position, (EObject)newElement);
        addToChangeDescription(parent, featureOfElement, listChange, changeDescription2);
    }
    else if(newElement instanceof TemporalChain){
        FeatureChange featureChange = createFeatureChange(parent, featureOfElement, newElement);
        addToChangeDescription(parent, featureOfElement, featureChange, changeDescription2);
    }
    else {
        listChange = createListFeatureChange(ChangeKind.ADD_LITERAL, position, (EObject)newElement);
        addToChangeDescription(parent, featureOfElement, listChange, changeDescription1);
    }
}
项目:OpenSPIFe    文件:SPIFePlanIntegrationOperation.java   
/** For completion. To ensure a proper FeatureChange use <i>createFeatureChange()</i> methods.
 * @param target
 * @param feature
 * @param indexToRemove
 * @return
 */
public static FeatureChange createRemoveFromListFeatureChange(EObject target, EStructuralFeature feature, int indexToRemove) {
    Object value = target.eGet(feature);
    FeatureChange fc = null;
    if(value instanceof List) {
        if ((((List) value).size() - 1) < indexToRemove)
            return null;

        fc = factory.createFeatureChange(feature, value, false);
        EObject object = (EObject) ((List) value).get(indexToRemove);
        ListChange listChange = createListFeatureChange(ChangeKind.REMOVE_LITERAL, indexToRemove, object);
        fc.getListChanges().add(listChange);
    }

    return fc;
}
项目:Vitruv    文件:ChangeDescriptionPrinter.java   
protected static void processFeatureChange(EObject affectedObj, FeatureChange fc, String prefix) {

    System.err.println(prefix + "Feature change on feature " + fc.getFeatureName());
    System.err.println("\t  Target value: " + fc.getValue());
    System.err.println("\tRollback value: " + affectedObj.eGet(fc.getFeature()));
    for (ListChange lc : fc.getListChanges()) {
        if (lc.getKind() == ChangeKind.ADD_LITERAL) {
            System.err.println(prefix + "\t - Adding Children: " + lc.getValues());
        }
        else if (lc.getKind() == ChangeKind.REMOVE_LITERAL) {
            System.err.println(prefix + "\t - Deleting Children: " + lc.getValues());
        }
    }
}
项目:xtext-core    文件:PartialSerializer.java   
protected List<SerializationStrategy> trySerializeIndividualFeatures(EObjectChange change, IEObjectRegion original,
        ISerializationContext context, IConstraint constraint) {
    List<SerializationStrategy> result = Lists.newArrayList();
    EObject object = change.getEObject();
    for (FeatureChange featureChange : change.getChanges()) {
        EStructuralFeature feature = featureChange.getFeature();
        List<SerializationStrategy> values = null;
        // if (feature instanceof EReference && ((EReference)
        // feature).isContainment()) {
        // if (feature.isMany()) {
        // values = trySerializeMultiValueContainment(object, featureChange,
        // original, constraint);
        // } else {
        // values = trySerializeSingleValue(object, featureChange, original,
        // constraint);
        // }
        // } else {
        if (feature.isMany()) {
            values = trySerializeMultiValue(object, featureChange, original, constraint);
        } else {
            values = trySerializeSingleValue(object, featureChange, original, constraint);
        }
        // }
        if (values == null) {
            return null;
        }
        result.addAll(values);
    }
    return result;
}
项目:OpenSPIFe    文件:SPIFePlanIntegrationOperation.java   
/** Receives the EObject to be modified and Map of EStructuralFeatures and the new values to be set 
 * and generates the proper FeatureChanges for target to be applied using
 * the ChangeDescription and ChangeDescriptionOperation.
 * 
 * @param target - EObject to be modified
 * @param map - Map where key -> EStructuralFeature, value -> new value
 * @return
 */
public static EList<FeatureChange> createFeatureChangesFromFeatureMap(EObject target, Map<EStructuralFeature, Object> changesMap) {

    EList<FeatureChange> featureChanges = new BasicEList();
    for (Entry<EStructuralFeature, Object> changeEntry : changesMap.entrySet()) {
        EStructuralFeature feature = changeEntry.getKey();
        Object value = changeEntry.getValue();

        FeatureChange featureChange = null;
        if(value instanceof List) {
            List newValue = (List) value;

            Object currentValue = target.eGet(feature);
            if(currentValue instanceof List) {                  
                List listCurrentValues = (List) currentValue;

                Set toDelete = new HashSet(listCurrentValues);
                toDelete.removeAll(newValue);

                Set toAdd = new HashSet(newValue);
                toAdd.removeAll(listCurrentValues);

                featureChange = createFeatureChangeForMultivalueFeatures(target, feature, toAdd, toDelete);
            }
        } else {
            featureChange = createFeatureChange(target, feature, value);
        }

        if(featureChange != null) {
            featureChanges.add(featureChange);
        }
    }

    return featureChanges;

}
项目:OpenSPIFe    文件:SPIFePlanIntegrationOperation.java   
/** For completion. To ensure a proper FeatureChange use <i>createFeatureChange()</i> methods.
 * @param target
 * @param feature
 * @param objectToAdd
 * @param whereToAdd
 * @return
 */
public static FeatureChange createAddToListFeatureChange(EObject target, EStructuralFeature feature, EObject objectToAdd, int whereToAdd) {
    Object value = target.eGet(feature);
    FeatureChange fc = null;
    if(value instanceof List) {
        if ((((List) value).size() - 1) < whereToAdd)
            whereToAdd = ((List) value).size();

        fc = factory.createFeatureChange(feature, value, true);
        ListChange listChange = createListFeatureChange(ChangeKind.ADD_LITERAL, whereToAdd, objectToAdd);
        fc.getListChanges().add(listChange);
    }

    return fc;
}
项目:OpenSPIFe    文件:SPIFePlanIntegrationOperation.java   
public ChangeDescription createAddActivityToPlanChangeDescription(EPlan plan, EActivity activity) {

        ChangeDescription cd = ChangeFactory.eINSTANCE.createChangeDescription();
        EStructuralFeature feature = PlanPackage.Literals.EPLAN_PARENT__CHILDREN;
        List activitiesToAdd = new BasicEList(); 
        activitiesToAdd.add(activity);

        FeatureChange featureChange = createFeatureChangeForMultivalueFeatures(plan, feature, activitiesToAdd, null);
        if(featureChange != null) {
            EList<FeatureChange> allFeatureChanges = new BasicEList();
            allFeatureChanges.add(featureChange);
            cd.getObjectChanges().put(plan, allFeatureChanges);
        }
        return cd;
    }
项目:xtext-core    文件:ChangeTreeProvider.java   
public EObjectChange(EObject eObject, EList<FeatureChange> changes) {
    super();
    Preconditions.checkNotNull(eObject);
    this.eObject = eObject;
    this.changes = changes;
}
项目:xtext-core    文件:ChangeTreeProvider.java   
public EList<FeatureChange> getChanges() {
    return changes == null ? ECollections.emptyEList() : changes;
}
项目:OpenSPIFe    文件:TransactionRecordingUndoableOperation.java   
@Override
public void applyAndReverse() {
    preApply(true);

    List<EObject> objectsBeforeApply = new UniqueEList.FastCompare<EObject>();
    List<EObject> objectsAfterApply = new UniqueEList.FastCompare<EObject>();

    // Apply the change and reverse the change information.
    //
    for (Map.Entry<EObject, EList<FeatureChange>> entry : getObjectChanges()) {
        try {
            applyAndReverseObjectChanges(entry, objectsBeforeApply, objectsAfterApply);
        } catch (Exception e) {
            LogUtil.errorOnce("applying object change: " + e.getMessage());
        }
    }

    for (ResourceChange resourceChange : getResourceChanges()) {
        Resource resource = resourceChange.getResource();
        if (resource != null) {
            objectsBeforeApply.addAll(resource.getContents());
        }
        resourceChange.applyAndReverse();
        if (resource != null) {
            objectsAfterApply.addAll(resource.getContents());
        }
    }

    // The next line leaves objectsBeforeApply with all the objects that
    // were
    // added during the last recording.
    objectsBeforeApply.removeAll(objectsAfterApply);

    // Reverse the objects to attach and detach lists.
    //
    getObjectsToAttach().clear();
    for (EObject eObject : objectsBeforeApply) {
        if (eObject.eContainer() == null && eObject.eResource() == null) {
            getObjectsToAttach().add(eObject);
        }
    }
    oldContainmentInformation = null;
}
项目:OpenSPIFe    文件:SPIFePlanIntegrationOperation.java   
/** Received the target EObject, the feature to be edited and new value to set.
 * This method is used for features that are NOT instances of a list, if it's a List 
 * returns <i>null</i> (please use other createFeatureChange method).
 * 
 * @param target - object to be edited
 * @param feature - feature to be edited
 * @param newValue - value to set
 * @return FeatureChange
 */
public static FeatureChange createFeatureChange(EObject target, EStructuralFeature feature, Object newValue) {
    Object value = target.eGet(feature);
    if(!(value instanceof List)) {
        return factory.createFeatureChange(feature, newValue, true);
    }
    return null;
}