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);
}
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;
}
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();
}
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;
}
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;
}
Aggregations