Skip to content

Commit

Permalink
[694] Add the support for representation refresh policy in selection
Browse files Browse the repository at this point in the history
Bug: #694
Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
  • Loading branch information
gcoutable committed Nov 9, 2021
1 parent 9039c13 commit a524532
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.eclipse.sirius.web.selection.renderer.SelectionRenderer;
import org.eclipse.sirius.web.spring.collaborative.api.ChangeDescription;
import org.eclipse.sirius.web.spring.collaborative.api.ChangeKind;
import org.eclipse.sirius.web.spring.collaborative.api.IRepresentationRefreshPolicy;
import org.eclipse.sirius.web.spring.collaborative.api.IRepresentationRefreshPolicyRegistry;
import org.eclipse.sirius.web.spring.collaborative.api.ISubscriptionManager;
import org.eclipse.sirius.web.spring.collaborative.selection.api.ISelectionEventProcessor;
import org.eclipse.sirius.web.spring.collaborative.selection.dto.SelectionRefreshedEventPayload;
Expand Down Expand Up @@ -60,6 +62,8 @@ public class SelectionEventProcessor implements ISelectionEventProcessor {

private final Object object;

private final IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry;

private final ISubscriptionManager subscriptionManager;

private final Many<IPayload> sink = Sinks.many().multicast().directBestEffort();
Expand All @@ -68,14 +72,16 @@ public class SelectionEventProcessor implements ISelectionEventProcessor {

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

public SelectionEventProcessor(IEditingContext editingContext, SelectionDescription selectionDescription, UUID id, Object object, ISubscriptionManager subscriptionManager) {
public SelectionEventProcessor(IEditingContext editingContext, SelectionDescription selectionDescription, UUID id, Object object, ISubscriptionManager subscriptionManager,
IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry) {
this.logger.trace("Creating the selection event processor {}", id); //$NON-NLS-1$

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

Selection selection = this.refreshSelection();
this.currentSelection.set(selection);
Expand All @@ -99,7 +105,7 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc

@Override
public void refresh(ChangeDescription changeDescription) {
if (ChangeKind.SEMANTIC_CHANGE.equals(changeDescription.getKind())) {
if (this.shouldRefresh(changeDescription)) {
Selection selection = this.refreshSelection();

this.currentSelection.set(selection);
Expand All @@ -111,6 +117,18 @@ public void refresh(ChangeDescription changeDescription) {
}
}

private boolean shouldRefresh(ChangeDescription changeDescription) {
// @formatter:off
return this.representationRefreshPolicyRegistry.getRepresentationRefreshPolicy(this.selectionDescription)
.orElseGet(this::defaultShouldRefresh)
.shouldRefresh(changeDescription);
// @formatter:on
}

private IRepresentationRefreshPolicy defaultShouldRefresh() {
return (changeDescription) -> ChangeKind.SEMANTIC_CHANGE.equals(changeDescription.getKind());
}

private Selection refreshSelection() {
VariableManager variableManager = new VariableManager();
variableManager.put(VariableManager.SELF, this.object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.sirius.web.spring.collaborative.api.IRepresentationConfiguration;
import org.eclipse.sirius.web.spring.collaborative.api.IRepresentationEventProcessor;
import org.eclipse.sirius.web.spring.collaborative.api.IRepresentationEventProcessorFactory;
import org.eclipse.sirius.web.spring.collaborative.api.IRepresentationRefreshPolicyRegistry;
import org.eclipse.sirius.web.spring.collaborative.api.ISubscriptionManagerFactory;
import org.eclipse.sirius.web.spring.collaborative.selection.api.ISelectionEventProcessor;
import org.eclipse.sirius.web.spring.collaborative.selection.api.SelectionConfiguration;
Expand All @@ -41,11 +42,14 @@ public class SelectionEventProcessorFactory implements IRepresentationEventProce

private final ISubscriptionManagerFactory subscriptionManagerFactory;

private final IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry;

public SelectionEventProcessorFactory(IRepresentationDescriptionSearchService representationDescriptionSearchService, IObjectService objectService,
ISubscriptionManagerFactory subscriptionManagerFactory) {
ISubscriptionManagerFactory subscriptionManagerFactory, IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry) {
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.objectService = Objects.requireNonNull(objectService);
this.subscriptionManagerFactory = Objects.requireNonNull(subscriptionManagerFactory);
this.representationRefreshPolicyRegistry = Objects.requireNonNull(representationRefreshPolicyRegistry);
}

@Override
Expand All @@ -72,7 +76,7 @@ public <T extends IRepresentationEventProcessor> Optional<T> createRepresentatio
Object object = optionalObject.get();

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

// @formatter:off
return Optional.of(selectionEventProcessor)
Expand Down

0 comments on commit a524532

Please sign in to comment.