-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #512 from ZeligsoftDev/streams/v3-issues/499
Fixes Issue #499 on v3
- Loading branch information
Showing
5 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...zeligsoft/domain/dds4ccm/ui/compare/contentmergeviewer/provider/DDS4CCMContextTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Comparison, Boolean> cache = new WeakHashMap<>(); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public boolean apply(Map<Object, Object> 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; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...domain/dds4ccm/ui/compare/contentmergeviewer/provider/DDS4CCMMergeViewerItemProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Object> getMergeViewerItems(Object object, | ||
// final IMergeViewerItemProviderConfiguration configuration) { | ||
// final List<Object> mergeViewerItems = super.getMergeViewerItems(object, configuration); | ||
// | ||
// return mergeViewerItems; | ||
// } | ||
|
||
} |
141 changes: 141 additions & 0 deletions
141
...are/src/com/zeligsoft/domain/dds4ccm/ui/compare/internal/context/DDS4CCMContextUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> ENDS_WITH_PAPYRUS_EXTENSION = new Predicate<String>() { | ||
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, String> URI_TO_STRING = new Function<URI, String>() { | ||
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<Resource> IS_UML_RESOURCE = new Predicate<Resource>() { | ||
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 <code>true</code> if the matched resources contain a Papyrus resources, <code>false</code> | ||
* otherwise. | ||
*/ | ||
private static boolean containsPapyrusURI(List<MatchResource> matchedResources) { | ||
final Builder<String> 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 <code>true</code> if uris contain a Papyrus resources, <code>false</code> otherwise. | ||
*/ | ||
private static boolean containsPapyrusURI(Collection<String> 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<Resource> isUMLResource() { | ||
return IS_UML_RESOURCE; | ||
} | ||
|
||
} |