diff options
author | Maxime Porhel | 2015-01-16 16:19:07 +0000 |
---|---|---|
committer | Laurent Redor | 2015-02-06 16:06:03 +0000 |
commit | 3849cd7b1848e9354917e7b3bc9dc6e776b27f3b (patch) | |
tree | a336eb3602c55687468f8e1a1d004f2651e1a0aa | |
parent | 672917724f9ef4ad4c36321e0f3976d33f8b5ae1 (diff) | |
download | org.eclipse.sirius-3849cd7b1848e9354917e7b3bc9dc6e776b27f3b.tar.gz org.eclipse.sirius-3849cd7b1848e9354917e7b3bc9dc6e776b27f3b.tar.xz org.eclipse.sirius-3849cd7b1848e9354917e7b3bc9dc6e776b27f3b.zip |
[458973] Minimize event ends computation during layout
Compute event ends only once and not three times.
We did not choose to introduce two new constructors to indicate the
allEventEnds at creation because the chosen way allows other subclassers
to
provide a way to compute differently the getAllEventEnds and to be sure
they will be called/computed during execute.
Bug: 458973
Cherry-picked-from: 457678
Change-Id: Ibd6cc121067ad1abfb1c4f65084d1b48273f60a3
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
3 files changed, 42 insertions, 4 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshGraphicalOrderingOperation.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshGraphicalOrderingOperation.java index d23ec4f782..b77c607a5e 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshGraphicalOrderingOperation.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshGraphicalOrderingOperation.java @@ -98,7 +98,7 @@ public class RefreshGraphicalOrderingOperation extends AbstractModelChangeOperat } } }; - List<EventEnd> allEnds = Lists.newArrayList(Iterables.filter(RefreshOrderingHelper.getAllEventEnds(sequenceDiagram), isValidEnd)); + List<EventEnd> allEnds = Lists.newArrayList(Iterables.filter(getAllEventEnds(), isValidEnd)); Collections.sort(allEnds, Ordering.natural().onResultOf(new Function<EventEnd, Integer>() { @Override public Integer apply(EventEnd input) { @@ -113,6 +113,17 @@ public class RefreshGraphicalOrderingOperation extends AbstractModelChangeOperat } /** + * Returns all the event ends of the current Sequence diagram. + * + * The default implementation does the computation on each call, subclasses may override this method to change this behavior. + * + * @return an Iterable with all event ends. + */ + protected Iterable<? extends EventEnd> getAllEventEnds() { + return RefreshOrderingHelper.getAllEventEnds(sequenceDiagram); + } + + /** * Custom vertical function which do not return the real location of an * event end but allow to correctly order event end from logically * instantaneous ISequenceEvent. diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshSemanticOrderingsOperation.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshSemanticOrderingsOperation.java index dfededfa2d..4e521798bb 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshSemanticOrderingsOperation.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/RefreshSemanticOrderingsOperation.java @@ -95,10 +95,21 @@ public class RefreshSemanticOrderingsOperation extends AbstractModelChangeOperat * @return true if there is changes during this refresh, false otherwise. */ private boolean refreshGlobalOrdering(EventEndsOrdering semanticOrdering) { - Iterable<? extends EventEnd> allEnds = RefreshOrderingHelper.getAllEventEnds(sequenceDDiagram); + Iterable<? extends EventEnd> allEnds = getAllEventEnds(); return RefreshOrderingHelper.updateIfNeeded(semanticOrdering.getEventEnds(), computeEventEndsOrdering(semanticOrdering, allEnds)); } + /** + * Returns all the event ends of the current Sequence diagram. + * + * The default implementation does the computation on each call, subclasses may override this method to change this behavior. + * + * @return an Iterable with all event ends. + */ + protected Iterable<? extends EventEnd> getAllEventEnds() { + return RefreshOrderingHelper.getAllEventEnds(sequenceDDiagram); + } + private List<EventEnd> computeEventEndsOrdering(EventEndsOrdering semanticOrdering, Iterable<? extends EventEnd> allEnds) { Map<EObject, EventEnd> index = Maps.newHashMap(); for (EventEnd eventEnd : allEnds) { diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutCommand.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutCommand.java index f539d8e1ff..929a716f9c 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutCommand.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/RefreshLayoutCommand.java @@ -21,6 +21,8 @@ import org.eclipse.sirius.diagram.sequence.business.internal.elements.SequenceDi import org.eclipse.sirius.diagram.sequence.business.internal.operation.RefreshGraphicalOrderingOperation; import org.eclipse.sirius.diagram.sequence.business.internal.operation.RefreshSemanticOrderingsOperation; import org.eclipse.sirius.diagram.sequence.business.internal.operation.SynchronizeGraphicalOrderingOperation; +import org.eclipse.sirius.diagram.sequence.business.internal.ordering.RefreshOrderingHelper; +import org.eclipse.sirius.diagram.sequence.ordering.EventEnd; import org.eclipse.sirius.diagram.ui.business.internal.operation.AbstractModelChangeOperation; import org.eclipse.sirius.ui.tools.api.profiler.SiriusTasks; @@ -72,11 +74,25 @@ public class RefreshLayoutCommand extends RecordingCommand { * Everything has been committed, so we should be in a stable state * where it is safe to refresh both orderings. */ - AbstractModelChangeOperation<Boolean> refreshSemanticOrderingOperation = new RefreshSemanticOrderingsOperation(sequenceDDiagram); + + // Compute only once (and not three times) the event ends. + final Iterable<? extends EventEnd> allEventEnds = RefreshOrderingHelper.getAllEventEnds(sequenceDDiagram); + + AbstractModelChangeOperation<Boolean> refreshSemanticOrderingOperation = new RefreshSemanticOrderingsOperation(sequenceDDiagram) { + @Override + protected Iterable<? extends EventEnd> getAllEventEnds() { + return allEventEnds; + } + }; if (refreshSemanticOrderingOperation.execute()) { sequenceDiagram.clearOrderedCaches(); } - AbstractModelChangeOperation<Boolean> refreshGraphicalOrderingOperation = new RefreshGraphicalOrderingOperation(sequenceDiagram); + AbstractModelChangeOperation<Boolean> refreshGraphicalOrderingOperation = new RefreshGraphicalOrderingOperation(sequenceDiagram) { + @Override + protected Iterable<? extends EventEnd> getAllEventEnds() { + return allEventEnds; + } + }; if (refreshGraphicalOrderingOperation.execute()) { sequenceDiagram.clearOrderedCaches(); } |