diff --git a/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/META-INF/MANIFEST.MF b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/META-INF/MANIFEST.MF index d44c6ca3c..7d129fe49 100644 --- a/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/META-INF/MANIFEST.MF +++ b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/META-INF/MANIFEST.MF @@ -10,7 +10,13 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.emf.common;bundle-version="2.19.0", com.google.guava;bundle-version="27.1.0", org.eclipse.emf.compare;bundle-version="3.5.3", - org.eclipse.swt;bundle-version="3.114.100" + org.eclipse.swt;bundle-version="3.114.100", + org.eclipse.papyrus.compare.diagram.ide.ui;bundle-version="2.8.1", + org.eclipse.emf.compare.ide.ui;bundle-version="4.4.3", + org.eclipse.emf.compare.edit;bundle-version="4.3.1", + org.eclipse.uml2.uml;bundle-version="5.5.0", + org.eclipse.papyrus.uml.tools;bundle-version="4.3.0", + org.eclipse.papyrus.infra.core;bundle-version="4.4.0" Bundle-RequiredExecutionEnvironment: JavaSE-11 Automatic-Module-Name: com.zeligsoft.domain.dds4ccm.ui.compare Bundle-ActivationPolicy: lazy diff --git a/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/plugin.xml b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/plugin.xml index 033daa7ac..e5982ec89 100644 --- a/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/plugin.xml +++ b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/plugin.xml @@ -12,5 +12,13 @@ ranking="20"> + + + + diff --git a/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/src/com/zeligsoft/domain/dds4ccm/ui/compare/contentmergeviewer/provider/DDS4CCMContextTester.java b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/src/com/zeligsoft/domain/dds4ccm/ui/compare/contentmergeviewer/provider/DDS4CCMContextTester.java new file mode 100644 index 000000000..bde0fa993 --- /dev/null +++ b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/src/com/zeligsoft/domain/dds4ccm/ui/compare/contentmergeviewer/provider/DDS4CCMContextTester.java @@ -0,0 +1,40 @@ +/** + * + */ +package com.zeligsoft.domain.dds4ccm.ui.compare.contentmergeviewer.provider; + +import java.util.Map; +import java.util.WeakHashMap; + +import org.eclipse.emf.compare.Comparison; +import org.eclipse.emf.compare.adapterfactory.context.AbstractContextTester; + +import com.zeligsoft.domain.dds4ccm.ui.compare.internal.context.DDS4CCMContextUtils; + +/** + * + */ +public class DDS4CCMContextTester extends AbstractContextTester { + + /** + * A weak cache of comparisons that have been already been tested. + */ + private final Map cache = new WeakHashMap<>(); + + /** + * {@inheritDoc} + */ + public boolean apply(Map context) { + Comparison comparison = getComparison(context); + if (comparison != null) { + Boolean result = cache.get(comparison); + if (result == null) { + result = Boolean.valueOf(DDS4CCMContextUtils.isDDS4CCMContext(comparison)); + cache.put(comparison, result); + } + return result.booleanValue(); + } + return false; + } + +} diff --git a/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/src/com/zeligsoft/domain/dds4ccm/ui/compare/contentmergeviewer/provider/DDS4CCMMergeViewerItemProvider.java b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/src/com/zeligsoft/domain/dds4ccm/ui/compare/contentmergeviewer/provider/DDS4CCMMergeViewerItemProvider.java new file mode 100644 index 000000000..3537bf24e --- /dev/null +++ b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/src/com/zeligsoft/domain/dds4ccm/ui/compare/contentmergeviewer/provider/DDS4CCMMergeViewerItemProvider.java @@ -0,0 +1,25 @@ +/** + * + */ +package com.zeligsoft.domain.dds4ccm.ui.compare.contentmergeviewer.provider; + +import java.util.List; + +import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.provider.CompareAccessorMergeViewerItemProvider; +import org.eclipse.emf.compare.rcp.ui.contentmergeviewer.accessor.ICompareAccessor; +import org.eclipse.emf.compare.rcp.ui.mergeviewer.item.provider.IMergeViewerItemProviderConfiguration; + +/** + * + */ +public class DDS4CCMMergeViewerItemProvider extends CompareAccessorMergeViewerItemProvider { + +// @Override +// public List getMergeViewerItems(Object object, +// final IMergeViewerItemProviderConfiguration configuration) { +// final List mergeViewerItems = super.getMergeViewerItems(object, configuration); +// +// return mergeViewerItems; +// } + +} diff --git a/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/src/com/zeligsoft/domain/dds4ccm/ui/compare/internal/context/DDS4CCMContextUtils.java b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/src/com/zeligsoft/domain/dds4ccm/ui/compare/internal/context/DDS4CCMContextUtils.java new file mode 100644 index 000000000..79277841f --- /dev/null +++ b/bundles/com.zeligsoft.domain.dds4ccm.ui.compare/src/com/zeligsoft/domain/dds4ccm/ui/compare/internal/context/DDS4CCMContextUtils.java @@ -0,0 +1,141 @@ +/** + * + */ +package com.zeligsoft.domain.dds4ccm.ui.compare.internal.context; + +import static com.google.common.collect.Collections2.transform; +import static com.google.common.collect.Iterables.any; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.compare.Comparison; +import org.eclipse.emf.compare.MatchResource; +import org.eclipse.emf.compare.scope.IComparisonScope2; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel; +import org.eclipse.papyrus.uml.tools.model.UmlModel; +import org.eclipse.uml2.uml.Element; + +/** + * + */ +public final class DDS4CCMContextUtils { + + /** The value ".di". */ + private static final String DI_FILE_EXTENSION = "." + DiModel.DI_FILE_EXTENSION; //$NON-NLS-1$ + + /** + * Hidden constructor for this utility class. + */ + private DDS4CCMContextUtils() { + // prevent instantiation + } + + /** Predicate specifying whether the given URI string ends with the Papyrus DI file extension. */ + private static final Predicate ENDS_WITH_PAPYRUS_EXTENSION = new Predicate() { + public boolean apply(String input) { + if (input != null) { + return input.endsWith(DI_FILE_EXTENSION); + } + return false; + } + }; + + /** Transforms an URI into the platform string representation. */ + private static final Function URI_TO_STRING = new Function() { + public String apply(URI input) { + String uriString = null; + if (input != null) { + uriString = input.toPlatformString(true); + if (uriString == null) { + uriString = input.toString(); + } + } + return uriString; + } + }; + + /** + * Predicate testing whether a {@link Resource} is a UML resource. + */ + private static final Predicate IS_UML_RESOURCE = new Predicate() { + public boolean apply(Resource input) { + if (input == null) { + // Null is not an UML resource + return false; + } + + URI uri = input.getURI(); + return (uri != null) && UmlModel.UML_FILE_EXTENSION.equals(uri.fileExtension()) + && !input.getContents().isEmpty() // + && input.getContents().get(0) instanceof Element; + } + }; + + /** + * Determines whether the comparison concerns Papyrus models. + * + * @param comparison + * the {@link Comparison} to check. + * @return {@code true} if the comparison concerns Papyrus models, {@code false} otherwise. + */ + public static boolean isDDS4CCMContext(Comparison comparison) { + final IComparisonScope2 comparisonScope = (IComparisonScope2)EcoreUtil + .getAdapter(comparison.eAdapters(), IComparisonScope2.class); + if (comparisonScope != null) { + return containsPapyrusURI(transform(comparisonScope.getAllInvolvedResourceURIs(), URI_TO_STRING)); + } + // Fallback if the scope is not available. This way of determining the Papyrus context is not as + // accurate since the MatchResources are already minimized. + return containsPapyrusURI(comparison.getMatchedResources()); + } + + /** + * Specifies whether the given matched resources contain a Papyrus resource. + * + * @param matchedResources + * the list of matched resources to check. + * @return true if the matched resources contain a Papyrus resources, false + * otherwise. + */ + private static boolean containsPapyrusURI(List matchedResources) { + final Builder setBuilder = ImmutableSet.builder(); + for (MatchResource res : matchedResources) { + for (String uri : ImmutableSet.of(res.getLeftURI(), res.getRightURI(), res.getOriginURI())) { + if (uri != null) { + setBuilder.add(uri); + } + } + } + return containsPapyrusURI(setBuilder.build()); + } + + /** + * Specifies whether the given URI strings contain a Papyrus resource. + * + * @param uris + * the set of uris to check. + * @return true if uris contain a Papyrus resources, false otherwise. + */ + private static boolean containsPapyrusURI(Collection uris) { + return any(uris, ENDS_WITH_PAPYRUS_EXTENSION); + } + + /** + * Obtains a predicate testing whether a resource is a UML resource. + * + * @return the UML resource predicate + */ + public static Predicate isUMLResource() { + return IS_UML_RESOURCE; + } + +}