diff options
author | Nathalie Lepine | 2020-10-15 14:39:01 +0000 |
---|---|---|
committer | Maxime Porhel | 2021-02-22 20:07:06 +0000 |
commit | 6f85f2515370d43b971f3388a1e7fc0e3e35132b (patch) | |
tree | 50a1ec90bbc4b7a2d18d6ebc6e82725a91126e71 | |
parent | edc2391e0a05da12e7ef72feb3b986e3899679c2 (diff) | |
download | org.eclipse.sirius-6f85f2515370d43b971f3388a1e7fc0e3e35132b.tar.gz org.eclipse.sirius-6f85f2515370d43b971f3388a1e7fc0e3e35132b.tar.xz org.eclipse.sirius-6f85f2515370d43b971f3388a1e7fc0e3e35132b.zip |
[571400] Reuse move/resize validators datas for feedback
Bug: 571400
Cherry-picked-from: 567517
Change-Id: Ic5147ca69f366139f836ac52e319ed666cc564a4
Signed-off-by: Nathalie Lepine <nathalie.lepine@obeo.fr>
3 files changed, 98 insertions, 51 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/AbstractNodeEventResizeSelectionValidator.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/AbstractNodeEventResizeSelectionValidator.java index a590c54878..f311541026 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/AbstractNodeEventResizeSelectionValidator.java +++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/AbstractNodeEventResizeSelectionValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES 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,15 +10,13 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.gef.requests.ChangeBoundsRequest; -import org.eclipse.gmf.runtime.notation.Location; import org.eclipse.sirius.diagram.sequence.business.internal.RangeHelper; import org.eclipse.sirius.diagram.sequence.business.internal.elements.AbstractFrame; import org.eclipse.sirius.diagram.sequence.business.internal.elements.AbstractNodeEvent; @@ -55,7 +53,11 @@ import com.google.common.collect.Lists; */ public class AbstractNodeEventResizeSelectionValidator { - private static final String EXECUTION_RESIZE_VALIDATOR = "org.eclipse.sirius.sequence.resize.execution.validator"; //$NON-NLS-1$ + /** Last validator. */ + protected static AbstractNodeEventResizeSelectionValidator lastValidator; + + /** Last request. */ + protected static ChangeBoundsRequest lastRequest; /** * The expansionZine. @@ -67,10 +69,8 @@ public class AbstractNodeEventResizeSelectionValidator { */ protected ISequenceEvent finalParent; - /** - * Common map of future location for executions in move/resize. - */ - protected Map<AbstractNodeEvent, Location> moveDeltas = new HashMap<AbstractNodeEvent, Location>(); + /** validation done ? */ + protected boolean validationDone; private boolean valid; @@ -115,9 +115,9 @@ public class AbstractNodeEventResizeSelectionValidator { * reconnection. */ public final void validate() { - if (!initialized) { + if (!validationDone) { doValidation(); - initialized = true; + validationDone = true; } } @@ -127,6 +127,10 @@ public class AbstractNodeEventResizeSelectionValidator { */ private void doValidation() { Preconditions.checkNotNull(host, Messages.AbstractNodeEventResizeSelectionValidator_nullExecution); + if (!initialized) { + // Nothing to do + initialized = true; + } FinalParentHelper finalParentHelper = new FinalParentHelper(host, requestQuery); finalParentHelper.computeFinalParent(); @@ -136,7 +140,6 @@ public class AbstractNodeEventResizeSelectionValidator { if (finalParent == null && requestQuery.isResizeFromBottom() && expansionZone != null && expansionZone.width() != 0) { finalParent = host.getParentEvent(); } - valid = validateNewBoundsForAllTargets() && finalParent != null; valid = valid && checkGlobalPositions(); } @@ -221,6 +224,7 @@ public class AbstractNodeEventResizeSelectionValidator { } return okForParent; } + /** * If this execution is delimited by a start and finish message, make sure they always point to the same remote * execution/lifeline. @@ -412,23 +416,37 @@ public class AbstractNodeEventResizeSelectionValidator { * @return a validator. */ public static AbstractNodeEventResizeSelectionValidator getOrCreateValidator(ChangeBoundsRequest cbr, AbstractNodeEvent host) { - RequestQuery requestQuery = new RequestQuery(cbr); AbstractNodeEventResizeSelectionValidator validator = null; - Object object = cbr.getExtendedData().get(EXECUTION_RESIZE_VALIDATOR); - if (object instanceof AbstractNodeEventResizeSelectionValidator) { - validator = (AbstractNodeEventResizeSelectionValidator) object; - if (!validator.getRequestQuery().getLogicalDelta().equals(requestQuery.getLogicalDelta())) { - validator = null; - } + if (lastRequest != cbr) { + lastValidator = null; + lastRequest = null; + } else { + validator = lastValidator; + } + RequestQuery requestQuery = new RequestQuery(cbr); + if (validator != null && validator.getRequestQuery().getLogicalDelta() != new RequestQuery(lastRequest).getLogicalDelta() && validateSameSelection(validator, cbr, requestQuery, host)) { + validator.reInit(requestQuery); } if (validator == null && requestQuery.isResize()) { validator = new AbstractNodeEventResizeSelectionValidator(host, cbr); - cbr.getExtendedData().put(EXECUTION_RESIZE_VALIDATOR, validator); + lastValidator = validator; + lastRequest = cbr; } return validator; } + private void reInit(RequestQuery rq) { + validationDone = false; + requestQuery = rq; + valid = false; + invalidPositions = new ArrayList<>(); + } + + private static boolean validateSameSelection(AbstractNodeEventResizeSelectionValidator validator, ChangeBoundsRequest cbr, RequestQuery requestQuery, ISequenceEvent host) { + return !requestQuery.getISequenceEvents().isEmpty() && requestQuery.getISequenceEvents().iterator().next().equals(validator.host); + } + private RequestQuery getRequestQuery() { return requestQuery; } diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/AbstractSequenceInteractionValidator.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/AbstractSequenceInteractionValidator.java index 692a429232..d21c0e9038 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/AbstractSequenceInteractionValidator.java +++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/AbstractSequenceInteractionValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 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 @@ -15,6 +15,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; +import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.sirius.diagram.sequence.business.internal.elements.ISequenceEvent; import org.eclipse.sirius.diagram.sequence.business.internal.elements.Message; import org.eclipse.sirius.diagram.sequence.business.internal.elements.SequenceDiagram; @@ -30,29 +31,35 @@ import com.google.common.base.Function; */ public abstract class AbstractSequenceInteractionValidator { + /** Last validator. */ + protected static ISEComplexMoveValidator lastValidator; + + /** Last request. */ + protected static ChangeBoundsRequest lastRequest; + /** Keep the value of the validation. */ protected boolean valid = true; /** {@link RequestQuery} for the current Request. */ - protected final RequestQuery request; + protected RequestQuery request; /** The expansionZine. */ protected Range expansionZone = Range.emptyRange(); /** {@link ISequenceEvent} in errors. */ - protected final Set<ISequenceEvent> eventInError = new HashSet<ISequenceEvent>(); + protected Set<ISequenceEvent> eventInError = new HashSet<ISequenceEvent>(); /** invalid positions. */ - protected final Set<Integer> invalidPositions = new HashSet<Integer>(); + protected Set<Integer> invalidPositions = new HashSet<Integer>(); /** invalid ranges. */ - protected final Set<Range> invalidRanges = new HashSet<Range>(); + protected Set<Range> invalidRanges = new HashSet<Range>(); /** {@link ISequenceEvent}s moved. */ protected final Collection<ISequenceEvent> movedElements = new ArrayList<ISequenceEvent>(); /** {@link ISequenceEvent}s moved. */ - protected final Collection<Range> createdElements = new ArrayList<Range>(); + protected Collection<Range> createdElements = new ArrayList<Range>(); /** startReflexiveMessageToResize. */ protected final Collection<Message> startReflexiveMessageToResize = new HashSet<Message>(); @@ -60,7 +67,11 @@ public abstract class AbstractSequenceInteractionValidator { /** endReflexiveMessageToResize. */ protected final Collection<Message> endReflexiveMessageToResize = new HashSet<Message>(); - private boolean initialized; + /** validation done ? */ + protected boolean validationDone; + + /** initialized ? */ + protected boolean initialized; /** * Constructor. @@ -80,8 +91,7 @@ public abstract class AbstractSequenceInteractionValidator { public abstract SequenceDiagram getDiagram(); /** - * Get the {@link Function} which give the {@link Range} of a - * {@link ISequenceEvent}. + * Get the {@link Function} which give the {@link Range} of a {@link ISequenceEvent}. * * @return the {@link Range} of a {@link ISequenceEvent} */ @@ -93,8 +103,7 @@ public abstract class AbstractSequenceInteractionValidator { protected abstract void doValidation(); /** - * Return the validation status. Validate the request result in the first - * call only. + * Return the validation status. Validate the request result in the first call only. * * @return the validation status. */ @@ -104,15 +113,14 @@ public abstract class AbstractSequenceInteractionValidator { } /** - * Performs all the computations required to validate the resizing, and - * stores any important information which will be useful to actually execute - * the move if it is valid, like for example avoid contact with siblings or - * handle reconnection. + * Performs all the computations required to validate the resizing, and stores any important information which will + * be useful to actually execute the move if it is valid, like for example avoid contact with siblings or handle + * reconnection. */ public final void validate() { - if (!initialized) { + if (!validationDone) { doValidation(); - initialized = true; + validationDone = true; } } diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/ISEComplexMoveValidator.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/ISEComplexMoveValidator.java index 3353e7e798..2c162b8368 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/ISEComplexMoveValidator.java +++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/validator/ISEComplexMoveValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 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 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -56,8 +57,6 @@ import com.google.common.collect.Sets; */ public class ISEComplexMoveValidator extends AbstractSequenceInteractionValidator { - private static final String VALIDATOR = "org.eclipse.sirius.sequence.move.validator"; //$NON-NLS-1$ - /** List of top levels events of the current move. */ protected final Set<ISequenceEvent> topLevelElements = new HashSet<ISequenceEvent>(); @@ -70,7 +69,7 @@ public class ISEComplexMoveValidator extends AbstractSequenceInteractionValidato /** The primary selected {@link ISequenceEvent}. */ protected ISequenceEvent primarySelected; - private final int vMove; + private int vMove; private LinkedHashSet<ISequenceNode> sequenceNodesToMove = Sets.newLinkedHashSet(); @@ -166,9 +165,12 @@ public class ISEComplexMoveValidator extends AbstractSequenceInteractionValidato @Override protected void doValidation() { - populateMoves(); - populateMessageToResize(); - categorizeMoves(); + if (!initialized) { + populateMoves(); + populateMessageToResize(); + categorizeMoves(); + initialized = true; + } checkMoves(); @@ -176,6 +178,7 @@ public class ISEComplexMoveValidator extends AbstractSequenceInteractionValidato if (!startReflexiveMessageToResize.isEmpty() || !endReflexiveMessageToResize.isEmpty()) { valid = valid && (expansionZone == null || expansionZone.isEmpty()); } + } private void populateMoves() { @@ -597,21 +600,39 @@ public class ISEComplexMoveValidator extends AbstractSequenceInteractionValidato */ public static ISEComplexMoveValidator getOrCreateValidator(ChangeBoundsRequest cbr, RequestQuery requestQuery, ISequenceEvent host) { ISEComplexMoveValidator validator = null; - Object object = cbr.getExtendedData().get(VALIDATOR); - if (object instanceof ISEComplexMoveValidator) { - validator = (ISEComplexMoveValidator) object; - if (validator.request == null || !validator.request.getLogicalDelta().equals(requestQuery.getLogicalDelta())) { - validator = null; - } + if (lastRequest != cbr) { + lastValidator = null; + lastRequest = null; + } else { + validator = lastValidator; + } + if (validator != null && validator.vMove != requestQuery.getLogicalDelta().y && validateSameSelection(validator, cbr, requestQuery, host)) { + validator.reInit(requestQuery); } if (validator == null && requestQuery.isMove()) { Collection<ISequenceEvent> selectedIses = new RequestQuery(cbr).getISequenceEvents(); validator = new ISEComplexMoveValidator(host, requestQuery); validator.addAdditionalEntryPoints(selectedIses); - cbr.getExtendedData().put(VALIDATOR, validator); + lastValidator = validator; + lastRequest = cbr; } return validator; } + private void reInit(RequestQuery requestQuery) { + validationDone = false; + request = requestQuery; + vMove = request.getLogicalDelta().y; + valid = true; + expansionZone = Range.emptyRange(); + eventInError = new HashSet<ISequenceEvent>(); + invalidPositions = new HashSet<Integer>(); + invalidRanges = new HashSet<Range>(); + createdElements = new ArrayList<Range>(); + } + + private static boolean validateSameSelection(ISEComplexMoveValidator validator, ChangeBoundsRequest cbr, RequestQuery requestQuery, ISequenceEvent host) { + return Iterables.elementsEqual(requestQuery.getISequenceEvents(), validator.otherEntryPoints); + } } |