-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: #3875 Signed-off-by: Jerome Gout <[email protected]>
- Loading branch information
1 parent
68c35f2
commit 71bf311
Showing
32 changed files
with
779 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
.../components/collaborative/widget/reference/browser/ModelBrowserEventProcessorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.collaborative.widget.reference.browser; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration; | ||
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor; | ||
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessorFactory; | ||
import org.eclipse.sirius.components.collaborative.api.IRepresentationRefreshPolicyRegistry; | ||
import org.eclipse.sirius.components.collaborative.api.ISubscriptionManagerFactory; | ||
import org.eclipse.sirius.components.collaborative.trees.TreeEventProcessor; | ||
import org.eclipse.sirius.components.collaborative.trees.api.ITreeEventHandler; | ||
import org.eclipse.sirius.components.collaborative.trees.api.ITreeService; | ||
import org.eclipse.sirius.components.collaborative.trees.api.TreeCreationParameters; | ||
import org.eclipse.sirius.components.collaborative.widget.reference.configurations.ModelBrowserConfiguration; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService; | ||
import org.eclipse.sirius.components.trees.description.TreeDescription; | ||
import org.springframework.stereotype.Service; | ||
|
||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
|
||
/** | ||
* Used to create the tree event processors in the context of model browser. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@Service | ||
public class ModelBrowserEventProcessorFactory implements IRepresentationEventProcessorFactory { | ||
|
||
private final IRepresentationDescriptionSearchService representationDescriptionSearchService; | ||
|
||
private final ITreeService treeService; | ||
|
||
private final List<ITreeEventHandler> treeEventHandlers; | ||
|
||
private final ISubscriptionManagerFactory subscriptionManagerFactory; | ||
|
||
private final IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry; | ||
|
||
public ModelBrowserEventProcessorFactory(IRepresentationDescriptionSearchService representationDescriptionSearchService, List<ITreeEventHandler> treeEventHandlers, ITreeService treeService, IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry, ISubscriptionManagerFactory subscriptionManagerFactory) { | ||
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService); | ||
this.treeService = Objects.requireNonNull(treeService); | ||
this.treeEventHandlers = Objects.requireNonNull(treeEventHandlers); | ||
this.subscriptionManagerFactory = Objects.requireNonNull(subscriptionManagerFactory); | ||
this.representationRefreshPolicyRegistry = Objects.requireNonNull(representationRefreshPolicyRegistry); | ||
} | ||
|
||
@Override | ||
public boolean canHandle(IRepresentationConfiguration configuration) { | ||
return configuration instanceof ModelBrowserConfiguration; | ||
} | ||
|
||
@Override | ||
public Optional<IRepresentationEventProcessor> createRepresentationEventProcessor(IRepresentationConfiguration configuration, IEditingContext editingContext) { | ||
if (configuration instanceof ModelBrowserConfiguration modelBrowserConfiguration) { | ||
|
||
String descriptionId; | ||
if (modelBrowserConfiguration.getId().startsWith(ModelBrowsersDescriptionProvider.MODEL_BROWSER_CONTAINER_PREFIX)) { | ||
descriptionId = ModelBrowsersDescriptionProvider.CONTAINER_DESCRIPTION_ID; | ||
} else { | ||
descriptionId = ModelBrowsersDescriptionProvider.REFERENCE_DESCRIPTION_ID; | ||
} | ||
|
||
Optional<TreeDescription> optionalTreeDescription = this.representationDescriptionSearchService | ||
.findById(editingContext, descriptionId) | ||
.filter(TreeDescription.class::isInstance) | ||
.map(TreeDescription.class::cast); | ||
if (optionalTreeDescription.isPresent()) { | ||
var treeDescription = optionalTreeDescription.get(); | ||
|
||
TreeCreationParameters treeCreationParameters = TreeCreationParameters.newTreeCreationParameters(modelBrowserConfiguration.getId()) | ||
.treeDescription(treeDescription) | ||
.activeFilterIds(List.of()) | ||
.expanded(modelBrowserConfiguration.getExpanded()) | ||
.editingContext(editingContext) | ||
.build(); | ||
|
||
IRepresentationEventProcessor treeEventProcessor = new TreeEventProcessor(editingContext, this.treeService, treeCreationParameters, this.treeEventHandlers, | ||
this.subscriptionManagerFactory.create(), new SimpleMeterRegistry(), this.representationRefreshPolicyRegistry); | ||
return Optional.of(treeEventProcessor); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...s/components/collaborative/widget/reference/configurations/ModelBrowserConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.collaborative.widget.reference.configurations; | ||
|
||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration; | ||
import org.eclipse.sirius.components.collaborative.widget.reference.browser.ModelBrowsersDescriptionProvider; | ||
|
||
/** | ||
* The configuration of the model browser event processor. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
public class ModelBrowserConfiguration implements IRepresentationConfiguration { | ||
|
||
private final String treeId; | ||
|
||
private final List<String> expanded; | ||
|
||
public ModelBrowserConfiguration(String editingContextId, String treeId, List<String> expanded) { | ||
this.expanded = Objects.requireNonNull(expanded); | ||
|
||
StringBuilder idBuilder = new StringBuilder(treeId); | ||
if (treeId.endsWith(ModelBrowsersDescriptionProvider.MODEL_BROWSER_CONTAINER_PREFIX) || treeId.endsWith(ModelBrowsersDescriptionProvider.MODEL_BROWSER_REFERENCE_PREFIX)) { | ||
idBuilder.append("?"); | ||
} else { | ||
idBuilder.append("&"); | ||
} | ||
|
||
List<String> expandedObjectIds = expanded.stream().map(id -> URLEncoder.encode(id, StandardCharsets.UTF_8)).toList(); | ||
idBuilder.append("expandedIds=[").append(String.join(",", expandedObjectIds)).append("]"); | ||
|
||
this.treeId = idBuilder.toString(); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return this.treeId; | ||
} | ||
|
||
public List<String> getExpanded() { | ||
return this.expanded; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...reference/graphql/datafetchers/subscription/SubscriptionModelBrowserEventDataFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.widget.reference.graphql.datafetchers.subscription; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.sirius.components.annotations.spring.graphql.SubscriptionDataFetcher; | ||
import org.eclipse.sirius.components.collaborative.widget.reference.configurations.ModelBrowserConfiguration; | ||
import org.eclipse.sirius.components.collaborative.widget.reference.dto.ModelBrowserEventInput; | ||
import org.eclipse.sirius.components.core.api.IPayload; | ||
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates; | ||
import org.eclipse.sirius.components.graphql.api.IEventProcessorSubscriptionProvider; | ||
import org.eclipse.sirius.components.graphql.api.IExceptionWrapper; | ||
import org.eclipse.sirius.components.graphql.api.LocalContextConstants; | ||
import org.reactivestreams.Publisher; | ||
|
||
import graphql.execution.DataFetcherResult; | ||
import graphql.schema.DataFetchingEnvironment; | ||
|
||
/** | ||
* The data fetcher used to send the refreshed tree to a model browser subscription . | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@SubscriptionDataFetcher(type = "Subscription", field = "modelBrowserEvent") | ||
public class SubscriptionModelBrowserEventDataFetcher implements IDataFetcherWithFieldCoordinates<Publisher<DataFetcherResult<IPayload>>> { | ||
|
||
private static final String INPUT_ARGUMENT = "input"; | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
private final IExceptionWrapper exceptionWrapper; | ||
|
||
private final IEventProcessorSubscriptionProvider eventProcessorSubscriptionProvider; | ||
|
||
public SubscriptionModelBrowserEventDataFetcher(ObjectMapper objectMapper, IExceptionWrapper exceptionWrapper, IEventProcessorSubscriptionProvider eventProcessorSubscriptionProvider) { | ||
this.objectMapper = Objects.requireNonNull(objectMapper); | ||
this.exceptionWrapper = Objects.requireNonNull(exceptionWrapper); | ||
this.eventProcessorSubscriptionProvider = Objects.requireNonNull(eventProcessorSubscriptionProvider); | ||
} | ||
|
||
@Override | ||
public Publisher<DataFetcherResult<IPayload>> get(DataFetchingEnvironment environment) throws Exception { | ||
Object argument = environment.getArgument(INPUT_ARGUMENT); | ||
var input = this.objectMapper.convertValue(argument, ModelBrowserEventInput.class); | ||
var modelBrowserConfiguration = new ModelBrowserConfiguration(input.editingContextId(), input.treeId(), input.expanded()); | ||
|
||
Map<String, Object> localContext = new HashMap<>(); | ||
localContext.put(LocalContextConstants.EDITING_CONTEXT_ID, input.editingContextId()); | ||
localContext.put(LocalContextConstants.REPRESENTATION_ID, modelBrowserConfiguration.getId()); | ||
|
||
return this.exceptionWrapper.wrapFlux(() -> this.eventProcessorSubscriptionProvider.getSubscription(input.editingContextId(), modelBrowserConfiguration, input), input) | ||
.map(payload -> DataFetcherResult.<IPayload>newResult() | ||
.data(payload) | ||
.localContext(localContext) | ||
.build()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ackend/sirius-components-widget-reference/src/main/resources/schema/modelbrowser.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extend type Subscription { | ||
modelBrowserEvent(input: ModelBrowserEventInput!): TreeEventPayload! | ||
} | ||
|
||
input ModelBrowserEventInput { | ||
id: ID! | ||
treeId: String! | ||
editingContextId: ID! | ||
expanded: [String!]! | ||
} |
Oops, something went wrong.