Search in sources :

Example 1 with Match

use of org.eclipse.emf.compare.Match in project tdq-studio-se by Talend.

the class DQReferenceMerger method addInTarget.

/*
     * override this method to fix a specail case: when add a catalog on database server,this new one can't be added in
     * local db connection
     */
@Override
protected void addInTarget(ReferenceChange diff, boolean rightToLeft) {
    final Match match = diff.getMatch();
    final EObject expectedContainer;
    if (rightToLeft) {
        expectedContainer = match.getLeft();
    } else {
        expectedContainer = match.getRight();
    }
    if (expectedContainer == null) {
        // one of the "required" diffs should have created our container.
        return;
    }
    final Comparison comparison = match.getComparison();
    final EReference reference = diff.getReference();
    final EObject expectedValue;
    final Match valueMatch = comparison.getMatch(diff.getValue());
    if (valueMatch == null) {
        // This is an out of scope value.
        if (diff.getValue().eIsProxy()) {
            // Copy the proxy
            expectedValue = EcoreUtil.copy(diff.getValue());
        } else {
            // Use the same value.
            expectedValue = diff.getValue();
        }
    } else if (rightToLeft) {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setLeft(expectedValue);
        } else {
            // qiongli: when I add catalog on remote server,test on reload, should replace "valueMatch.getLeft()"
            // with "valueMatch.getRight()" at here.
            // expectedValue = valueMatch.getLeft();
            expectedValue = valueMatch.getRight();
            // qiongli: remove the newest DataManage from the right Catalog or Schema,avoid a missing
            // "datamanage herf=" "
            Catalog catlog = SwitchHelpers.CATALOG_SWITCH.doSwitch(expectedValue);
            Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(expectedValue);
            if (catlog != null) {
                EList<DataManager> dataManager = catlog.getDataManager();
                dataManager.clear();
            } else if (schema != null) {
                EList<DataManager> dataManager = schema.getDataManager();
                dataManager.clear();
            }
        }
    } else {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setRight(expectedValue);
        } else {
            expectedValue = valueMatch.getLeft();
        }
    }
    // We have the container, reference and value. We need to know the insertion index.
    if (reference.isMany()) {
        final int insertionIndex = findInsertionIndex(comparison, diff, rightToLeft);
        final List<EObject> targetList = (List<EObject>) safeEGet(expectedContainer, reference);
        addAt(targetList, expectedValue, insertionIndex);
    } else {
        safeESet(expectedContainer, reference, expectedValue);
    }
    if (reference.isContainment()) {
        // Copy XMI ID when applicable.
        final Resource initialResource = diff.getValue().eResource();
        final Resource targetResource = expectedValue.eResource();
        if (initialResource instanceof XMIResource && targetResource instanceof XMIResource) {
            ((XMIResource) targetResource).setID(expectedValue, ((XMIResource) initialResource).getID(diff.getValue()));
        }
    }
// no need to check this for DQ items,
// checkImpliedDiffsOrdering(diff, rightToLeft);
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Resource(org.eclipse.emf.ecore.resource.Resource) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Catalog(orgomg.cwm.resource.relational.Catalog) Match(org.eclipse.emf.compare.Match) EList(org.eclipse.emf.common.util.EList) Comparison(org.eclipse.emf.compare.Comparison) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) EReference(org.eclipse.emf.ecore.EReference)

Example 2 with Match

use of org.eclipse.emf.compare.Match in project InformationSystem by ObeoNetwork.

the class ExportAsSQLScriptsAction method getContainingFolder.

private IResource getContainingFolder(Comparison comparison) {
    if (comparison.getMatches() != null && comparison.getMatches().isEmpty() == false) {
        Match match = comparison.getMatches().get(0);
        Resource resource = match.getLeft().eResource();
        if (resource instanceof CDOResource) {
            return getModelingProject(resource);
        } else if (resource.getURI().isPlatformResource()) {
            String uri = resource.getURI().toPlatformString(true);
            Path path = new Path(uri);
            return ResourcesPlugin.getWorkspace().getRoot().getFile(path).getParent();
        } else if (activeEditor.getEditorInput() instanceof ThreeWayResourceCompareInput) {
            // The resource is a SVN resource
            try {
                IEditorInput editorInput = activeEditor.getEditorInput();
                Field localField = editorInput.getClass().getDeclaredField("local");
                localField.setAccessible(true);
                ILocalResource local = (ILocalResource) localField.get(editorInput);
                return local.getResource().getParent();
            } catch (ReflectiveOperationException e) {
            // The fallback case below will apply
            } catch (SecurityException e) {
            // The fallback case below will apply
            } catch (IllegalArgumentException e) {
            // The fallback case below will apply
            }
        }
        // Fallback case
        ContainerSelectionDialog projectSelectionDialog = new ContainerSelectionDialog(activeEditor.getSite().getShell(), null, false, "Sélectionner le projet de destination :");
        projectSelectionDialog.setTitle("Sélection de projet");
        if (projectSelectionDialog.open() == ContainerSelectionDialog.OK && projectSelectionDialog.getResult().length == 1) {
            Path projectPath = (Path) projectSelectionDialog.getResult()[0];
            IResource selectedResource = ResourcesPlugin.getWorkspace().getRoot().findMember(projectPath);
            if (selectedResource instanceof IProject) {
                return selectedResource;
            }
        }
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) ThreeWayResourceCompareInput(org.eclipse.team.svn.ui.compare.ThreeWayResourceCompareInput) ILocalResource(org.eclipse.team.svn.core.resource.ILocalResource) Resource(org.eclipse.emf.ecore.resource.Resource) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource) ILocalResource(org.eclipse.team.svn.core.resource.ILocalResource) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) Match(org.eclipse.emf.compare.Match) Field(java.lang.reflect.Field) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Example 3 with Match

use of org.eclipse.emf.compare.Match in project InformationSystem by ObeoNetwork.

the class DiffContentService method getSubDiffs.

public List<Diff> getSubDiffs(Diff diffParent, Comparison comparison) {
    EObject targetValue = getTargetValue(diffParent);
    Match matchOfValue = comparison.getMatch(targetValue);
    if (targetValue != null && matchOfValue != null) {
        return Lists.newArrayList(Iterables.filter(matchOfValue.getAllDifferences(), getSubDiffsPredicate(diffParent)));
    }
    return Collections.emptyList();
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Match(org.eclipse.emf.compare.Match)

Example 4 with Match

use of org.eclipse.emf.compare.Match in project InformationSystem by ObeoNetwork.

the class ExportAsSQLScriptsAction method areDatabaseDifferences.

/**
 * Checks whether the given {@link Comparison} is between two {@link DataBase}.
 * @param comparison
 * @return
 */
private boolean areDatabaseDifferences(Comparison comparison) {
    for (Diff diff : comparison.getDifferences()) {
        Match parentMatch = diff.getMatch();
        while (ComparePackage.Literals.MATCH.isInstance(parentMatch.eContainer())) {
            parentMatch = (Match) parentMatch.eContainer();
        }
        // Should be DataBase
        EObject left = parentMatch.getLeft();
        // Should be DataBase
        EObject right = parentMatch.getRight();
        if (left != null && left.eClass().getEPackage() == DatabasePackage.eINSTANCE || right != null && right.eClass().getEPackage() == DatabasePackage.eINSTANCE) {
            return true;
        }
    }
    return false;
}
Also used : Diff(org.eclipse.emf.compare.Diff) EObject(org.eclipse.emf.ecore.EObject) Match(org.eclipse.emf.compare.Match)

Example 5 with Match

use of org.eclipse.emf.compare.Match in project InformationSystem by ObeoNetwork.

the class DiffContentService method isInAddOrDelete.

/**
 * It checks if the given difference is about an added or deleted object.<br>
 * It enables to choose to keep involved differences under an add or delete.
 *
 * @param diff
 * @return
 */
private static boolean isInAddOrDelete(Diff diff) {
    Match match = diff.getMatch();
    Comparison comparison = match.getComparison();
    EObject left = match.getLeft();
    if (left != null) {
        return isInAddOrDelete(comparison, left);
    }
    EObject right = match.getRight();
    if (right != null) {
        return isInAddOrDelete(comparison, right);
    }
    return false;
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) EObject(org.eclipse.emf.ecore.EObject) Match(org.eclipse.emf.compare.Match)

Aggregations

Match (org.eclipse.emf.compare.Match)7 EObject (org.eclipse.emf.ecore.EObject)5 Diff (org.eclipse.emf.compare.Diff)3 EList (org.eclipse.emf.common.util.EList)2 Comparison (org.eclipse.emf.compare.Comparison)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 DBDiff (org.obeonetwork.dsl.database.dbevolution.DBDiff)2 Field (java.lang.reflect.Field)1 List (java.util.List)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 Path (org.eclipse.core.runtime.Path)1 CDOResource (org.eclipse.emf.cdo.eresource.CDOResource)1 AttributeChange (org.eclipse.emf.compare.AttributeChange)1 ReferenceChange (org.eclipse.emf.compare.ReferenceChange)1 EReference (org.eclipse.emf.ecore.EReference)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 XMIResource (org.eclipse.emf.ecore.xmi.XMIResource)1 ILocalResource (org.eclipse.team.svn.core.resource.ILocalResource)1 ThreeWayResourceCompareInput (org.eclipse.team.svn.ui.compare.ThreeWayResourceCompareInput)1