Skip to content

Commit

Permalink
[3063] Re-resolve the current self from its id when refreshing a Sele…
Browse files Browse the repository at this point in the history
…ction

Bug: #3063
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
  • Loading branch information
pcdavid authored and sbegaudeau committed Feb 8, 2024
1 parent ecb1ea0 commit 11c7297
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ As a result, all the APIs relying on this code have been deleted too such as the
- https://github.com/eclipse-sirius/sirius-web/issues/3052[#3052] [diagram] Fix an issue that prevented user from reconnecting an edge.
- https://github.com/eclipse-sirius/sirius-web/issues/3030[#3030] [diagram] Fix the position of the palette when multiple diagrams are open at the same time (e.g. inside a portal)
- https://github.com/eclipse-sirius/sirius-web/issues/2823[#2823] [diagram] Fix an issue that prevents nodes from being resized smaller than their default size.
- https://github.com/eclipse-sirius/sirius-web/issues/3063[#3063] [selection] Ensure Selections are always refreshed using the _current_ version of their target element

=== New Features

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Obeo.
* Copyright (c) 2021, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -24,6 +24,7 @@
import org.eclipse.sirius.components.collaborative.selection.dto.SelectionRefreshedEventPayload;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.core.api.IRepresentationInput;
import org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider;
Expand Down Expand Up @@ -56,9 +57,11 @@ public class SelectionEventProcessor implements ISelectionEventProcessor {

private final SelectionDescription selectionDescription;

private final IObjectService objectService;

private final String id;

private final Object object;
private final String objectId;

private final IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry;

Expand All @@ -68,14 +71,14 @@ public class SelectionEventProcessor implements ISelectionEventProcessor {

private final AtomicReference<Selection> currentSelection = new AtomicReference<>();

public SelectionEventProcessor(IEditingContext editingContext, SelectionDescription selectionDescription, String id, Object object, ISubscriptionManager subscriptionManager,
public SelectionEventProcessor(IEditingContext editingContext, IObjectService objectService, SelectionDescription selectionDescription, String id, String objectId, ISubscriptionManager subscriptionManager,
IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry) {
this.logger.trace("Creating the selection event processor {}", id);

this.objectService = Objects.requireNonNull(objectService);
this.selectionDescription = Objects.requireNonNull(selectionDescription);
this.editingContext = Objects.requireNonNull(editingContext);
this.id = Objects.requireNonNull(id);
this.object = Objects.requireNonNull(object);
this.objectId = Objects.requireNonNull(objectId);
this.subscriptionManager = Objects.requireNonNull(subscriptionManager);
this.representationRefreshPolicyRegistry = Objects.requireNonNull(representationRefreshPolicyRegistry);

Expand Down Expand Up @@ -129,7 +132,8 @@ private IRepresentationRefreshPolicy getDefaultRefreshPolicy() {

private Selection refreshSelection() {
VariableManager variableManager = new VariableManager();
variableManager.put(VariableManager.SELF, this.object);
var optionalObject = this.objectService.getObject(this.editingContext, this.objectId);
variableManager.put(VariableManager.SELF, optionalObject.orElse(null));
variableManager.put(IEditingContext.EDITING_CONTEXT, this.editingContext);
variableManager.put(GetOrCreateRandomIdProvider.PREVIOUS_REPRESENTATION_ID, this.id);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Obeo.
* Copyright (c) 2021, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -72,9 +72,9 @@ public <T extends IRepresentationEventProcessor> Optional<T> createRepresentatio
Optional<Object> optionalObject = this.objectService.getObject(editingContext, selectionConfiguration.getTargetObjectId());
if (optionalSelectionDescription.isPresent() && optionalObject.isPresent()) {
SelectionDescription selectionDescription = optionalSelectionDescription.get();
Object object = optionalObject.get();
String objectId = this.objectService.getId(optionalObject.get());

IRepresentationEventProcessor selectionEventProcessor = new SelectionEventProcessor(editingContext, selectionDescription, selectionConfiguration.getId(), object,
IRepresentationEventProcessor selectionEventProcessor = new SelectionEventProcessor(editingContext, this.objectService, selectionDescription, selectionConfiguration.getId(), objectId,
this.subscriptionManagerFactory.create(), this.representationRefreshPolicyRegistry);

// @formatter:off
Expand Down

0 comments on commit 11c7297

Please sign in to comment.