Merge "Improve Papyrus context check"
diff --git a/plugins/compare/bundles/org.eclipse.papyrus.compare.diagram.ide.ui/src/org/eclipse/papyrus/compare/diagram/ide/ui/contentmergeviewer/provider/PapyrusContextTester.java b/plugins/compare/bundles/org.eclipse.papyrus.compare.diagram.ide.ui/src/org/eclipse/papyrus/compare/diagram/ide/ui/contentmergeviewer/provider/PapyrusContextTester.java
index a10b688..4268fc2 100644
--- a/plugins/compare/bundles/org.eclipse.papyrus.compare.diagram.ide.ui/src/org/eclipse/papyrus/compare/diagram/ide/ui/contentmergeviewer/provider/PapyrusContextTester.java
+++ b/plugins/compare/bundles/org.eclipse.papyrus.compare.diagram.ide.ui/src/org/eclipse/papyrus/compare/diagram/ide/ui/contentmergeviewer/provider/PapyrusContextTester.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016 EclipseSource Muenchen GmbH and others.
+ * Copyright (c) 2016, 2017 EclipseSource Muenchen GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,11 +10,13 @@
*******************************************************************************/
package org.eclipse.papyrus.compare.diagram.ide.ui.contentmergeviewer.provider;
+import static org.eclipse.papyrus.compare.diagram.ide.ui.internal.context.PapyrusContextUtil.isPapyrusContext;
+
import java.util.Map;
+import java.util.WeakHashMap;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.adapterfactory.context.AbstractContextTester;
-import org.eclipse.papyrus.compare.diagram.ide.ui.internal.context.PapyrusContextUtil;
/**
* Indicates whether we are in a Papyrus context.
@@ -24,12 +26,22 @@
public class PapyrusContextTester 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 (context != null) {
- return PapyrusContextUtil.isPapyrusContext(comparison);
+ if (comparison != null) {
+ Boolean result = cache.get(comparison);
+ if (result == null) {
+ result = Boolean.valueOf(isPapyrusContext(comparison));
+ cache.put(comparison, result);
+ }
+ return result.booleanValue();
}
return false;
}
diff --git a/plugins/compare/bundles/org.eclipse.papyrus.compare.diagram.ide.ui/src/org/eclipse/papyrus/compare/diagram/ide/ui/internal/context/PapyrusContextUtil.java b/plugins/compare/bundles/org.eclipse.papyrus.compare.diagram.ide.ui/src/org/eclipse/papyrus/compare/diagram/ide/ui/internal/context/PapyrusContextUtil.java
index ffee9ad..75ba760 100644
--- a/plugins/compare/bundles/org.eclipse.papyrus.compare.diagram.ide.ui/src/org/eclipse/papyrus/compare/diagram/ide/ui/internal/context/PapyrusContextUtil.java
+++ b/plugins/compare/bundles/org.eclipse.papyrus.compare.diagram.ide.ui/src/org/eclipse/papyrus/compare/diagram/ide/ui/internal/context/PapyrusContextUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016 EclipseSource Muenchen GmbH and others.
+ * Copyright (c) 2016, 2017 EclipseSource Muenchen GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -36,11 +36,14 @@
*/
public final class PapyrusContextUtil {
+ /** The value ".di". */
+ private static final String DI_FILE_EXTENSION = "." + DiModel.DI_FILE_EXTENSION; //$NON-NLS-1$
+
/** 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(DiModel.DI_FILE_EXTENSION);
+ return input.endsWith(DI_FILE_EXTENSION);
}
return false;
}