Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2026 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 @@ -12,9 +12,9 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.deck;

import java.util.List;
import java.util.Objects;

import org.eclipse.sirius.components.collaborative.deck.api.IDeckContext;
import org.eclipse.sirius.components.deck.Deck;
import org.eclipse.sirius.components.deck.renderer.events.IDeckEvent;

Expand All @@ -23,39 +23,9 @@
*
* @author fbarbin
*/
public class DeckContext implements IDeckContext {

private Deck deck;

private IDeckEvent deckEvent;

public DeckContext(Deck initialDeck) {
this.deck = Objects.requireNonNull(initialDeck);
}

@Override
public void update(Deck newDeck) {
this.deck = Objects.requireNonNull(newDeck);
}

@Override
public Deck getDeck() {
return this.deck;
public record DeckContext(Deck deck, List<IDeckEvent> deckEvents) {
public DeckContext {
Objects.requireNonNull(deck);
Objects.requireNonNull(deckEvents);
}

@Override
public void reset() {
this.deckEvent = null;
}

@Override
public IDeckEvent getDeckEvent() {
return this.deckEvent;
}

@Override
public void setDeckEvent(IDeckEvent deckEvent) {
this.deckEvent = Objects.requireNonNull(deckEvent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.deck;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -21,7 +22,6 @@
import org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceStrategy;
import org.eclipse.sirius.components.collaborative.api.IRepresentationSearchService;
import org.eclipse.sirius.components.collaborative.api.ISubscriptionManager;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckContext;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventHandler;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventProcessor;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckInput;
Expand Down Expand Up @@ -63,12 +63,11 @@ public class DeckEventProcessor implements IDeckEventProcessor {

private final List<IDeckEventHandler> deckEventHandlers;

private final IDeckContext deckContext;
private DeckContext deckContext;

public DeckEventProcessor(IEditingContext editingContext, ISubscriptionManager subscriptionManager, DeckCreationService deckCreationService,
List<IDeckEventHandler> deckEventHandlers, IDeckContext deckContext, IRepresentationPersistenceStrategy representationPersistenceStrategy,
List<IDeckEventHandler> deckEventHandlers, DeckContext deckContext, IRepresentationPersistenceStrategy representationPersistenceStrategy,
IRepresentationSearchService representationSearchService) {

this.editingContext = Objects.requireNonNull(editingContext);
this.subscriptionManager = Objects.requireNonNull(subscriptionManager);
this.deckCreationService = Objects.requireNonNull(deckCreationService);
Expand All @@ -77,21 +76,21 @@ public DeckEventProcessor(IEditingContext editingContext, ISubscriptionManager s
this.representationPersistenceStrategy = Objects.requireNonNull(representationPersistenceStrategy);
this.representationSearchService = Objects.requireNonNull(representationSearchService);

String id = this.deckContext.getDeck().getId();
String id = this.deckContext.deck().getId();
this.logger.trace("Creating the deck event processor {}", id);

// We automatically refresh the representation before using it since things may have changed since the moment it
// has been saved in the database.
Deck deck = this.deckCreationService.refresh(this.editingContext, deckContext).orElse(null);
this.deckContext.update(deck);
this.deckContext = new DeckContext(deck, deckContext.deckEvents());

this.deckEventFlux = new DeckEventFlux(deck);

}

@Override
public IRepresentation getRepresentation() {
return this.deckContext.getDeck();
return this.deckContext.deck();
}

@Override
Expand Down Expand Up @@ -119,18 +118,17 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
public void refresh(ChangeDescription changeDescription) {
if (this.shouldRefresh(changeDescription)) {
Deck refreshedDeckRepresentation = this.deckCreationService.refresh(this.editingContext, this.deckContext).orElse(null);
this.deckContext.reset();
this.deckContext.update(refreshedDeckRepresentation);
this.deckContext = new DeckContext(refreshedDeckRepresentation, new ArrayList<>());
if (refreshedDeckRepresentation != null) {
this.representationPersistenceStrategy.applyPersistenceStrategy(changeDescription.getInput(), this.editingContext, refreshedDeckRepresentation);
this.logger.trace("Deck refreshed: {}", refreshedDeckRepresentation.getId());
}
this.deckEventFlux.deckRefreshed(changeDescription.getInput(), this.deckContext.getDeck());
} else if (changeDescription.getKind().equals(ChangeKind.RELOAD_REPRESENTATION) && changeDescription.getSourceId().equals(this.deckContext.getDeck().getId())) {
Optional<Deck> reloadedDeck = this.representationSearchService.findById(this.editingContext, this.deckContext.getDeck().getId(), Deck.class);
if (reloadedDeck.isPresent()) {
this.deckContext.update(reloadedDeck.get());
this.deckEventFlux.deckRefreshed(changeDescription.getInput(), this.deckContext.getDeck());
this.deckEventFlux.deckRefreshed(changeDescription.getInput(), this.deckContext.deck());
} else if (changeDescription.getKind().equals(ChangeKind.RELOAD_REPRESENTATION) && changeDescription.getSourceId().equals(this.deckContext.deck().getId())) {
Optional<Deck> optionalReloadedDeck = this.representationSearchService.findById(this.editingContext, this.deckContext.deck().getId(), Deck.class);
if (optionalReloadedDeck.isPresent()) {
this.deckContext = new DeckContext(optionalReloadedDeck.get(), new ArrayList<>());
this.deckEventFlux.deckRefreshed(changeDescription.getInput(), this.deckContext.deck());
}
}
}
Expand All @@ -153,7 +151,7 @@ public Flux<IPayload> getOutputEvents(IInput input) {

@Override
public void dispose() {
String id = Optional.ofNullable(this.deckContext.getDeck()).map(Deck::id).orElse(null);
String id = Optional.ofNullable(this.deckContext.deck()).map(Deck::id).orElse(null);
this.logger.trace("Disposing the deck event processor {}", id);
this.subscriptionManager.dispose();
this.deckEventFlux.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.deck;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -64,7 +65,7 @@ public Optional<IRepresentationEventProcessor> createRepresentationEventProcesso
var optionalDeck = this.representationSearchService.findById(editingContext, representationId, Deck.class);
if (optionalDeck.isPresent()) {
Deck deck = optionalDeck.get();
DeckContext deckContext = new DeckContext(deck);
DeckContext deckContext = new DeckContext(deck, new ArrayList<>());

IRepresentationEventProcessor deckEventProcessor = new DeckEventProcessor(editingContext, this.subscriptionManagerFactory.create(), this.deckCreationService, this.deckEventHandlers,
deckContext, this.representationPersistenceStrategy, this.representationSearchService);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2026 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 @@ -47,7 +47,6 @@ public interface IDeckCardService {
*/
IPayload dropCard(DropDeckCardInput dropDeckCardInput, IEditingContext editingContext, Deck deck);


/**
* Implementation which does nothing, used for mocks in unit tests.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Obeo.
* Copyright (c) 2023, 2026 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 @@ -14,6 +14,7 @@

import java.util.Optional;

import org.eclipse.sirius.components.collaborative.deck.DeckContext;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.deck.Deck;
import org.eclipse.sirius.components.deck.description.DeckDescription;
Expand Down Expand Up @@ -43,7 +44,7 @@ public interface IDeckCreationService {
*
* <p>
* Refreshing a deck seems to always be possible but it may not be the case. In some situation, the semantic element
* on which the previous deck has been created may not exist anymore and thus we can return an empty optional if we
* on which the previous deck has been created may not exist anymore, and thus we can return an empty optional if we
* are unable to refresh the deck.
* </p>
*
Expand All @@ -53,7 +54,7 @@ public interface IDeckCreationService {
* The deck representation context
* @return An updated deck if we have been able to refresh it.
*/
Optional<Deck> refresh(IEditingContext editingContext, IDeckContext deckContext);
Optional<Deck> refresh(IEditingContext editingContext, DeckContext deckContext);

/**
* Implementation which does nothing, used for mocks in unit tests.
Expand All @@ -68,7 +69,7 @@ public Deck create(Object targetObject, DeckDescription deckDescription, IEditin
}

@Override
public Optional<Deck> refresh(IEditingContext editingContext, IDeckContext deckContext) {
public Optional<Deck> refresh(IEditingContext editingContext, DeckContext deckContext) {
return Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2025 Obeo.
* Copyright (c) 2023, 2026 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 @@ -13,6 +13,7 @@
package org.eclipse.sirius.components.collaborative.deck.api;

import org.eclipse.sirius.components.collaborative.api.ChangeDescription;
import org.eclipse.sirius.components.collaborative.deck.DeckContext;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IPayload;

Expand All @@ -27,5 +28,5 @@
public interface IDeckEventHandler {
boolean canHandle(IEditingContext editingContext, IDeckInput deckInput);

void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDeckContext deckContext, IDeckInput deckInput);
void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, DeckContext deckContext, IDeckInput deckInput);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2026 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 @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.deck.api;

import org.eclipse.sirius.components.collaborative.deck.DeckContext;
import org.eclipse.sirius.components.collaborative.deck.dto.input.ChangeCardsVisibilityInput;
import org.eclipse.sirius.components.collaborative.deck.dto.input.ChangeLaneCollapsedStateInput;
import org.eclipse.sirius.components.collaborative.deck.dto.input.DropDeckLaneInput;
Expand All @@ -31,9 +32,9 @@ public interface IDeckLaneService {

IPayload dropLane(DropDeckLaneInput dropDeckLaneInput, IEditingContext editingContext, Deck deck);

IPayload changeLaneCollapsedState(ChangeLaneCollapsedStateInput input, IEditingContext editingContext, IDeckContext deckContext);
IPayload changeLaneCollapsedState(ChangeLaneCollapsedStateInput input, IEditingContext editingContext, DeckContext deckContext);

IPayload changeCardsVisibility(ChangeCardsVisibilityInput input, IEditingContext editingContext, IDeckContext deckContext);
IPayload changeCardsVisibility(ChangeCardsVisibilityInput input, IEditingContext editingContext, DeckContext deckContext);

/**
* Implementation which does nothing, used for mocks in unit tests.
Expand All @@ -53,12 +54,12 @@ public IPayload dropLane(DropDeckLaneInput dropDeckLaneInput, IEditingContext ed
}

@Override
public IPayload changeLaneCollapsedState(ChangeLaneCollapsedStateInput input, IEditingContext editingContext, IDeckContext deckContext) {
public IPayload changeLaneCollapsedState(ChangeLaneCollapsedStateInput input, IEditingContext editingContext, DeckContext deckContext) {
return null;
}

@Override
public IPayload changeCardsVisibility(ChangeCardsVisibilityInput input, IEditingContext editingContext, IDeckContext deckContext) {
public IPayload changeCardsVisibility(ChangeCardsVisibilityInput input, IEditingContext editingContext, DeckContext deckContext) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024, 2025 Obeo.
* Copyright (c) 2024, 2026 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 @@ -18,7 +18,7 @@
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.api.Monitoring;
import org.eclipse.sirius.components.collaborative.deck.DeckChangeKind;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckContext;
import org.eclipse.sirius.components.collaborative.deck.DeckContext;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventHandler;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckInput;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckLaneService;
Expand Down Expand Up @@ -63,7 +63,7 @@ public boolean canHandle(IEditingContext editingContext, IDeckInput deckInput) {
}

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDeckContext deckContext, IDeckInput deckInput) {
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, DeckContext deckContext, IDeckInput deckInput) {
this.counter.increment();

String message = this.messageService.invalidInput(deckInput.getClass().getSimpleName(), ChangeCardsVisibilityInput.class.getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024, 2025 Obeo.
* Copyright (c) 2024, 2026 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 @@ -18,7 +18,7 @@
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.api.Monitoring;
import org.eclipse.sirius.components.collaborative.deck.DeckChangeKind;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckContext;
import org.eclipse.sirius.components.collaborative.deck.DeckContext;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckEventHandler;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckInput;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckLaneService;
Expand Down Expand Up @@ -63,7 +63,7 @@ public boolean canHandle(IEditingContext editingContext, IDeckInput deckInput) {
}

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDeckContext deckContext, IDeckInput deckInput) {
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, DeckContext deckContext, IDeckInput deckInput) {
this.counter.increment();

String message = this.messageService.invalidInput(deckInput.getClass().getSimpleName(), ChangeLaneCollapsedStateInput.class.getSimpleName());
Expand Down
Loading
Loading