Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Porhel2020-10-16 07:44:57 +0000
committerMaxime Porhel2021-02-22 20:05:17 +0000
commitad15c0ecc9ffd6b129656a888f9d884d9300cf7d (patch)
tree5e95fa1314f72de6df16634fee54392d1b5ac2ff
parentb242f2d4fb8f0358d45287e7ec97f8c283a9fe88 (diff)
downloadorg.eclipse.sirius-ad15c0ecc9ffd6b129656a888f9d884d9300cf7d.tar.gz
org.eclipse.sirius-ad15c0ecc9ffd6b129656a888f9d884d9300cf7d.tar.xz
org.eclipse.sirius-ad15c0ecc9ffd6b129656a888f9d884d9300cf7d.zip
[571400] Add a cache for vertical range
Bug: 571400 Cherry-picked-from: 567517 Change-Id: I6127afd3150638e67cf82ebb6600abe955b0fbb9 Signed-off-by: Nathalie Lepine <nathalie.lepine@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/ISequenceEventQuery.java51
-rw-r--r--plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceMessageViewQuery.java52
-rw-r--r--plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceNodeQuery.java64
-rw-r--r--plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/util/CacheHelper.java13
4 files changed, 103 insertions, 77 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/ISequenceEventQuery.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/ISequenceEventQuery.java
index 80eacbe754..55f4f221d9 100644
--- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/ISequenceEventQuery.java
+++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/ISequenceEventQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES.
* 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
@@ -57,9 +57,8 @@ public class ISequenceEventQuery {
*
* @param child
* the potential descendant.
- * @return <code>true</code> if <em>this</em> event is identical to the
- * child, the parent of the child or an indirect ancestor of the
- * child.
+ * @return <code>true</code> if <em>this</em> event is identical to the child, the parent of the child or an
+ * indirect ancestor of the child.
*/
public boolean isAncestorOrSelf(ISequenceEvent child) {
ISequenceEvent iSequenceEvent = event;
@@ -89,8 +88,7 @@ public class ISequenceEventQuery {
}
/**
- * Computes all the descendants of the specified execution, i.e. the
- * recursive transitive closure on getSubEvents().
+ * Computes all the descendants of the specified execution, i.e. the recursive transitive closure on getSubEvents().
*
* The current ise is not included.
*
@@ -101,8 +99,7 @@ public class ISequenceEventQuery {
}
/**
- * Computes all the descendants of the specified execution, i.e. the
- * recursive transitive closure on getSubEvents().
+ * Computes all the descendants of the specified execution, i.e. the recursive transitive closure on getSubEvents().
*
* @param includeSelf
* whether or not to consider "self" as a descendant.
@@ -113,14 +110,12 @@ public class ISequenceEventQuery {
}
/**
- * Computes all the descendants of the specified execution, i.e. the
- * recursive transitive closure on getSubEvents().
+ * Computes all the descendants of the specified execution, i.e. the recursive transitive closure on getSubEvents().
*
* @param includeSelf
* whether or not to consider "self" as a descendant.
* @param predicate
- * the predicate to select which descendants to include in the
- * collection.
+ * the predicate to select which descendants to include in the collection.
* @return all the proper descendant events of the given execution.
*/
public Set<ISequenceEvent> getAllDescendants(boolean includeSelf, Predicate<? super View> predicate) {
@@ -133,16 +128,13 @@ public class ISequenceEventQuery {
}
/**
- * Adds all the descendants of the specified edit part which verify the
- * predicate into a collection. Only children edit parts are considered, not
- * source and target connections.
+ * Adds all the descendants of the specified edit part which verify the predicate into a collection. Only children
+ * edit parts are considered, not source and target connections.
*
* @param predicate
- * the predicate to select which descendants to include in the
- * collection.
+ * the predicate to select which descendants to include in the collection.
* @param parts
- * the collection in which to add all the descendants of
- * <code>element</code> which verify the predicate.
+ * the collection in which to add all the descendants of <code>element</code> which verify the predicate.
*/
private void addAllDescendants(Predicate<? super View> predicate, Collection<ISequenceEvent> parts) {
addAllDescendants(event, predicate, parts);
@@ -171,8 +163,8 @@ public class ISequenceEventQuery {
}
/**
- * Finds all the sequence messages whose source or target is the specified
- * element or any of its descendant edit parts, without duplicates.
+ * Finds all the sequence messages whose source or target is the specified element or any of its descendant edit
+ * parts, without duplicates.
*
* @return the messages found without duplicates.
*/
@@ -184,8 +176,7 @@ public class ISequenceEventQuery {
}
/**
- * Finds all the sequence messages whose source is the specified element or
- * any of its descendant edit parts.
+ * Finds all the sequence messages whose source is the specified element or any of its descendant edit parts.
*
* @return the messages found.
*/
@@ -196,8 +187,7 @@ public class ISequenceEventQuery {
}
/**
- * Finds all the sequence messages whose target is the specified element or
- * any of its descendant edit parts.
+ * Finds all the sequence messages whose target is the specified element or any of its descendant edit parts.
*
* @return the messages found.
*/
@@ -208,8 +198,8 @@ public class ISequenceEventQuery {
}
/**
- * Finds all the sequence messages whose target is the specified element or
- * any of its descendant edit parts and add them to a collection.
+ * Finds all the sequence messages whose target is the specified element or any of its descendant edit parts and add
+ * them to a collection.
*
* @param element
* the element from which to start the search for messages.
@@ -232,8 +222,8 @@ public class ISequenceEventQuery {
}
/**
- * Finds all the sequence messages whose source is the specified element or
- * any of its descendant edit parts and add them to a collection.
+ * Finds all the sequence messages whose source is the specified element or any of its descendant edit parts and add
+ * them to a collection.
*
* @param element
* the element from which to start the search for messages.
@@ -256,8 +246,7 @@ public class ISequenceEventQuery {
}
/**
- * Common implementation of
- * {@link ISequenceEventEditPart#getOccupiedRange()}.
+ * Common implementation of {@link ISequenceEventEditPart#getOccupiedRange()}.
*
* @return the maximal range occupied by children of the event.
*/
diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceMessageViewQuery.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceMessageViewQuery.java
index 6497aa1f21..56c8a5605b 100644
--- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceMessageViewQuery.java
+++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceMessageViewQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES.
* 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
@@ -23,6 +23,7 @@ import org.eclipse.sirius.diagram.sequence.business.internal.elements.ISequenceE
import org.eclipse.sirius.diagram.sequence.business.internal.elements.Lifeline;
import org.eclipse.sirius.diagram.sequence.business.internal.elements.Message;
import org.eclipse.sirius.diagram.sequence.business.internal.layout.LayoutConstants;
+import org.eclipse.sirius.diagram.sequence.business.internal.util.CacheHelper;
import org.eclipse.sirius.diagram.sequence.util.Range;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
@@ -104,26 +105,34 @@ public class SequenceMessageViewQuery {
* @return the vertical range of the message.
*/
public Range getVerticalRange() {
- Range result;
- RelativeBendpoints bendpoints = (RelativeBendpoints) edge.getBendpoints();
- if (bendpoints == null || bendpoints.getPoints().isEmpty()) {
- result = Range.emptyRange();
- } else {
- int firstY = getFirstPointVerticalPosition(true);
- if (isLogicallyInstantaneous()) {
- if (validateFirstPointStability(firstY)) {
- result = new Range(firstY, firstY);
+ Range result = null;
+ if (CacheHelper.isDragTrackerCacheEnabled()) {
+ result = CacheHelper.getViewToRangeCache().get(edge);
+ }
+ if (result == null) {
+ RelativeBendpoints bendpoints = (RelativeBendpoints) edge.getBendpoints();
+ if (bendpoints == null || bendpoints.getPoints().isEmpty()) {
+ result = Range.emptyRange();
+ } else {
+ int firstY = getFirstPointVerticalPosition(true);
+ if (isLogicallyInstantaneous()) {
+ if (validateFirstPointStability(firstY)) {
+ result = new Range(firstY, firstY);
+ } else {
+ int lastY = getLastPointVerticalPosition(false);
+ result = new Range(lastY, lastY);
+ }
} else {
int lastY = getLastPointVerticalPosition(false);
- result = new Range(lastY, lastY);
- }
- } else {
- int lastY = getLastPointVerticalPosition(false);
- if (msgToSelfInvalidEndLocation(edge.getSource(), edge.getTarget())) {
- firstY = VerticalRangeFunction.INSTANCE.apply(edge.getSource()).getUpperBound();
- lastY = firstY + LayoutConstants.MESSAGE_TO_SELF_BENDPOINT_VERTICAL_GAP;
+ if (msgToSelfInvalidEndLocation(edge.getSource(), edge.getTarget())) {
+ firstY = VerticalRangeFunction.INSTANCE.apply(edge.getSource()).getUpperBound();
+ lastY = firstY + LayoutConstants.MESSAGE_TO_SELF_BENDPOINT_VERTICAL_GAP;
+ }
+ result = new Range(Math.min(firstY, lastY), Math.max(firstY, lastY));
}
- result = new Range(Math.min(firstY, lastY), Math.max(firstY, lastY));
+ }
+ if (CacheHelper.isDragTrackerCacheEnabled()) {
+ CacheHelper.getViewToRangeCache().put(edge, result);
}
}
return result;
@@ -252,7 +261,10 @@ public class SequenceMessageViewQuery {
View source = edge.getSource();
Range sourceRange = new Range(0, 0);
if (source instanceof Node) {
+ boolean cacheEnabled = CacheHelper.isDragTrackerCacheEnabled();
+ CacheHelper.setDragTrackerCacheEnabled(false);
sourceRange = new SequenceNodeQuery((Node) source).getVerticalRange();
+ CacheHelper.setDragTrackerCacheEnabled(cacheEnabled);
}
return getAnchorAbsolutePosition(srcAnchor, sourceRange);
// could not return 0 : other utility method take 0,5 precision point
@@ -273,7 +285,11 @@ public class SequenceMessageViewQuery {
}
View target = edge.getTarget();
if (target instanceof Node) {
+ boolean cacheEnabled = CacheHelper.isDragTrackerCacheEnabled();
+ CacheHelper.setDragTrackerCacheEnabled(false);
Range targetRange = new SequenceNodeQuery((Node) target).getVerticalRange();
+ CacheHelper.setDragTrackerCacheEnabled(cacheEnabled);
+
return getAnchorAbsolutePosition(tgtAnchor, targetRange);
}
return getSourceAnchorVerticalPosition();
diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceNodeQuery.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceNodeQuery.java
index abcf0ca170..34d8387e66 100644
--- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceNodeQuery.java
+++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceNodeQuery.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES.
* 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
@@ -21,6 +21,7 @@ import org.eclipse.sirius.diagram.WorkspaceImage;
import org.eclipse.sirius.diagram.sequence.business.internal.elements.AbstractNodeEvent;
import org.eclipse.sirius.diagram.sequence.business.internal.elements.EndOfLife;
import org.eclipse.sirius.diagram.sequence.business.internal.elements.Lifeline;
+import org.eclipse.sirius.diagram.sequence.business.internal.util.CacheHelper;
import org.eclipse.sirius.diagram.sequence.util.Range;
import org.eclipse.sirius.diagram.ui.business.internal.query.DNodeQuery;
import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper;
@@ -46,45 +47,52 @@ public class SequenceNodeQuery {
}
/**
- * Returns the vertical range of a sequence diagram element from its GMF
- * notation node.
+ * Returns the vertical range of a sequence diagram element from its GMF notation node.
*
* @return the vertical range of the element.
*/
public Range getVerticalRange() {
+ Range result = null;
EObject element = node.getElement();
if (!(element instanceof DDiagramElement)) {
- return null;
+ result = null;
} else {
- Rectangle absoluteBounds = GMFHelper.getAbsoluteBounds(node);
- int y = absoluteBounds.y;
- int height = absoluteBounds.height;
- // GMFHelper.getAbsoluteBounds() use default
- // DDiagramElementContainer (DNodeContainer/DNodeList) dimension if
- // size == (-1,-1) and here we need to have the real GMF size if ==
- // to (-1,-1)
- if (node.getLayoutConstraint() instanceof Size) {
- Size size = (Size) node.getLayoutConstraint();
- height = size.getHeight();
- }
- // handle container auto size -> range.widht = 0, next layout will
- // set the good value
- // check in interaction use view factory, that it cannot be there
- if (element instanceof DNodeContainer && height == -1) {
- height = 0;
- }
- if (height == -1 && element instanceof DNode && ((DNode) element).getOwnedStyle() instanceof WorkspaceImage) {
- height = new DNodeQuery((DNode) element).getDefaultDimension().height;
+ if (CacheHelper.isDragTrackerCacheEnabled()) {
+ result = CacheHelper.getViewToRangeCache().get(node);
}
+ if (result == null) {
+ Rectangle absoluteBounds = GMFHelper.getAbsoluteBounds(node);
+ int y = absoluteBounds.y;
+ int height = absoluteBounds.height;
+ // GMFHelper.getAbsoluteBounds() use default
+ // DDiagramElementContainer (DNodeContainer/DNodeList) dimension if
+ // size == (-1,-1) and here we need to have the real GMF size if ==
+ // to (-1,-1)
+ if (node.getLayoutConstraint() instanceof Size) {
+ Size size = (Size) node.getLayoutConstraint();
+ height = size.getHeight();
+ }
+ // handle container auto size -> range.widht = 0, next layout will
+ // set the good value
+ // check in interaction use view factory, that it cannot be there
+ if (element instanceof DNodeContainer && height == -1) {
+ height = 0;
+ }
+ if (height == -1 && element instanceof DNode && ((DNode) element).getOwnedStyle() instanceof WorkspaceImage) {
+ height = new DNodeQuery((DNode) element).getDefaultDimension().height;
+ }
- Range result = new Range(y, y + height);
+ result = new Range(y, y + height);
- if (isShifted()) {
- result = result.shifted(IBorderItemOffsets.DEFAULT_OFFSET.height);
+ if (isShifted()) {
+ result = result.shifted(IBorderItemOffsets.DEFAULT_OFFSET.height);
+ }
+ if (CacheHelper.isDragTrackerCacheEnabled()) {
+ CacheHelper.getViewToRangeCache().put(node, result);
+ }
}
-
- return result;
}
+ return result;
}
private boolean isShifted() {
diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/util/CacheHelper.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/util/CacheHelper.java
index 83190a3cde..d8416555ec 100644
--- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/util/CacheHelper.java
+++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/util/CacheHelper.java
@@ -14,9 +14,11 @@ import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.sirius.diagram.sequence.business.internal.elements.AbstractFrame;
import org.eclipse.sirius.diagram.sequence.business.internal.elements.ISequenceEvent;
import org.eclipse.sirius.diagram.sequence.business.internal.elements.Lifeline;
+import org.eclipse.sirius.diagram.sequence.util.Range;
/**
* Sequence cache helper.
@@ -32,6 +34,8 @@ public final class CacheHelper {
private static ConcurrentHashMap<ISequenceEvent, Collection<ISequenceEvent>> subEventsCache = new ConcurrentHashMap<>();
+ private static ConcurrentHashMap<View, Range> viewToRangeCache = new ConcurrentHashMap<>();
+
/**
* Avoid instantiation.
*/
@@ -64,6 +68,7 @@ public final class CacheHelper {
public static void clearDragTrackerCaches() {
coverageCache.clear();
subEventsCache.clear();
+ viewToRangeCache.clear();
}
/**
@@ -100,4 +105,12 @@ public final class CacheHelper {
return subEventsCache;
}
+ /**
+ * Get view to range cache.
+ *
+ * @return the viewToRangecache
+ */
+ public static Map<View, Range> getViewToRangeCache() {
+ return viewToRangeCache;
+ }
}

Back to the top