Skip to content

Commit

Permalink
[3875] Refactor the tree event classes related to the explorer
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#3875
Signed-off-by: Jerome Gout <jerome.gout@obeosoft.com>
  • Loading branch information
jerome-obeo committed Aug 30, 2024
1 parent 74b59b2 commit 68c35f2
Show file tree
Hide file tree
Showing 27 changed files with 375 additions and 127 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ A migration participant has been added to automatically keep compatible all diag
- https://github.com/eclipse-sirius/sirius-web/issues/3834[#3834] [deck] Add more variables for DeckDescription
- https://github.com/eclipse-sirius/sirius-web/issues/3897[#3897] [sirius-web] Improve the search for projects
- https://github.com/eclipse-sirius/sirius-web/issues/3902[#3902] [core] Move the Help menu entry at the last position (after any contributed entries)
- https://github.com/eclipse-sirius/sirius-web/issues/3875[#3875] [sirius-web] Move explorer related code from sirius-components-trees to sirius-web-application

== v2024.7.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.command.CommandParameter;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.sirius.components.collaborative.trees.api.TreeConfiguration;
import org.eclipse.sirius.components.collaborative.trees.api.ITreeConfiguration;
import org.eclipse.sirius.components.collaborative.widget.reference.api.IReferenceWidgetRootCandidateSearchProvider;
import org.eclipse.sirius.components.core.CoreImageConstants;
import org.eclipse.sirius.components.core.URLParser;
Expand Down Expand Up @@ -99,7 +99,7 @@ public ModelBrowsersDescriptionProvider(IObjectService objectService, IURLParser

@Override
public List<IRepresentationDescription> getRepresentationDescriptions(IEditingContext editingContext) {
Predicate<VariableManager> containerDescriptionCanCreatePredicate = variableManager -> variableManager.get(TreeConfiguration.TREE_ID, String.class)
Predicate<VariableManager> containerDescriptionCanCreatePredicate = variableManager -> variableManager.get(ITreeConfiguration.TREE_ID, String.class)
.map(treeId -> treeId.startsWith(MODEL_BROWSER_CONTAINER_PREFIX))
.orElse(false);
Function<VariableManager, Boolean> containerDescriptionIsSelectableProvider = variableManager -> {
Expand All @@ -108,7 +108,7 @@ public List<IRepresentationDescription> getRepresentationDescriptions(IEditingCo
};
var containerDescription = this.getModelBrowserDescription(CONTAINER_DESCRIPTION_ID, containerDescriptionCanCreatePredicate, containerDescriptionIsSelectableProvider, this::getCreationScopeElements);

Predicate<VariableManager> referenceDescriptionCanCreatePredicate = variableManager -> variableManager.get(TreeConfiguration.TREE_ID, String.class)
Predicate<VariableManager> referenceDescriptionCanCreatePredicate = variableManager -> variableManager.get(ITreeConfiguration.TREE_ID, String.class)
.map(treeId -> treeId.startsWith(MODEL_BROWSER_REFERENCE_PREFIX))
.orElse(false);
Function<VariableManager, Boolean> referenceDescriptionIsSelectableProvider = variableManager -> {
Expand All @@ -126,7 +126,7 @@ private TreeDescription getModelBrowserDescription(String descriptionId, Predica

return TreeDescription.newTreeDescription(descriptionId)
.label(REPRESENTATION_NAME)
.idProvider(variableManager -> variableManager.get(TreeConfiguration.TREE_ID, String.class).orElse(null))
.idProvider(variableManager -> variableManager.get(ITreeConfiguration.TREE_ID, String.class).orElse(null))
.treeItemIdProvider(this::getTreeItemId)
.kindProvider(this::getKind)
.labelProvider(this::getLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import java.util.List;

import org.eclipse.sirius.components.collaborative.trees.api.TreeConfiguration;
import org.eclipse.sirius.components.collaborative.trees.api.ITreeConfiguration;
import org.eclipse.sirius.components.collaborative.widget.reference.browser.ModelBrowsersDescriptionProvider;
import org.eclipse.sirius.components.core.URLParser;
import org.eclipse.sirius.components.core.api.IEditingContext;
Expand Down Expand Up @@ -55,15 +55,15 @@ public void testModelBrowserDescriptionProvider() {
variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext);

var referenceTreeId = "modelBrowser://reference";
variableManager.put(TreeConfiguration.TREE_ID, referenceTreeId);
variableManager.put(ITreeConfiguration.TREE_ID, referenceTreeId);
var tree = new TreeRenderer(variableManager, referenceBrowserDescription.get()).render();
assertThat(tree).isNotNull();
assertThat(tree.getId()).isEqualTo(referenceTreeId);
assertThat(tree.getDescriptionId()).isEqualTo(ModelBrowsersDescriptionProvider.REFERENCE_DESCRIPTION_ID);
assertThat(tree.getKind()).isEqualTo(Tree.KIND);

var containerTreeId = "modelBrowser://container";
variableManager.put(TreeConfiguration.TREE_ID, containerTreeId);
variableManager.put(ITreeConfiguration.TREE_ID, containerTreeId);
tree = new TreeRenderer(variableManager, containerBrowserDescription.get()).render();
assertThat(tree).isNotNull();
assertThat(tree.getId()).isEqualTo(containerTreeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
* Obeo - initial API and implementation
*******************************************************************************/

import { TreeView, TreeItemActionProps } from '@eclipse-sirius/sirius-components-trees';
import IconButton from '@mui/material/IconButton';
import { makeStyles } from 'tss-react/mui';
import { TreeItemActionProps, TreeView } from '@eclipse-sirius/sirius-components-trees';
import UnfoldMoreIcon from '@mui/icons-material/UnfoldMore';
import IconButton from '@mui/material/IconButton';
import { useState } from 'react';
import { makeStyles } from 'tss-react/mui';
import { ModelBrowserFilterBar } from './ModelBrowserFilterBar';
import { ModelBrowserTreeViewProps, ModelBrowserTreeViewState } from './ModelBrowserTreeView.types';

Expand Down Expand Up @@ -69,6 +69,8 @@ export const ModelBrowserTreeView = ({
textToHighlight={state.filterBarText}
markedItemIds={markedItemIds}
treeItemActionRender={(props) => <WidgetReferenceTreeItemAction {...props} />}
eventType="explorerEvent"
eventInputType="ExplorerEventInput"
/>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,29 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.trees.api;
package org.eclipse.sirius.web.application.views.explorer;

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.trees.api.ITreeConfiguration;

/**
* The configuration of the tree event processor.
* The configuration of the explorer event processor.
*
* @author sbegaudeau
*/
public class TreeConfiguration implements IRepresentationConfiguration {

public static final String TREE_ID = "treeId";
public class ExplorerConfiguration implements ITreeConfiguration {

private final String treeId;

private final List<String> activeFilterIds;

private final List<String> expanded;

public TreeConfiguration(String editingContextId, String treeId, List<String> expanded, List<String> activeFilters) {
public ExplorerConfiguration(String editingContextId, String treeId, List<String> expanded, List<String> activeFilters) {
this.activeFilterIds = Objects.requireNonNull(activeFilters);
this.expanded = Objects.requireNonNull(expanded);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.trees.dto;
package org.eclipse.sirius.web.application.views.explorer;

import java.util.List;
import java.util.UUID;

import org.eclipse.sirius.components.core.api.IInput;

/**
* The input of the tree event subscription.
* The input of the explorer event subscription.
*
* @author sbegaudeau
*/
public record TreeEventInput(UUID id, String editingContextId, String treeId, List<String> expanded, List<String> activeFilterIds) implements IInput {
public record ExplorerEventInput(UUID id, String editingContextId, String treeId, List<String> expanded, List<String> activeFilterIds) implements IInput {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.trees;
package org.eclipse.sirius.web.application.views.explorer;

import java.util.List;
import java.util.Objects;
Expand All @@ -22,9 +22,9 @@
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.TreeConfiguration;
import org.eclipse.sirius.components.collaborative.trees.api.TreeCreationParameters;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
Expand All @@ -40,7 +40,7 @@
* @author sbegaudeau
*/
@Service
public class TreeEventProcessorFactory implements IRepresentationEventProcessorFactory {
public class ExplorerEventProcessorFactory implements IRepresentationEventProcessorFactory {

public static final String TREE_ID = UUID.nameUUIDFromBytes("explorer_tree_description".getBytes()).toString();

Expand All @@ -54,7 +54,7 @@ public class TreeEventProcessorFactory implements IRepresentationEventProcessorF

private final IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry;

public TreeEventProcessorFactory(IRepresentationDescriptionSearchService representationDescriptionSearchService, ITreeService treeService, List<ITreeEventHandler> treeEventHandlers,
public ExplorerEventProcessorFactory(IRepresentationDescriptionSearchService representationDescriptionSearchService, ITreeService treeService, List<ITreeEventHandler> treeEventHandlers,
ISubscriptionManagerFactory subscriptionManagerFactory, IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry) {
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.treeService = Objects.requireNonNull(treeService);
Expand All @@ -65,12 +65,12 @@ public TreeEventProcessorFactory(IRepresentationDescriptionSearchService represe

@Override
public boolean canHandle(IRepresentationConfiguration configuration) {
return configuration instanceof TreeConfiguration;
return configuration instanceof ExplorerConfiguration;
}

@Override
public Optional<IRepresentationEventProcessor> createRepresentationEventProcessor(IRepresentationConfiguration configuration, IEditingContext editingContext) {
if (configuration instanceof TreeConfiguration treeConfiguration) {
if (configuration instanceof ExplorerConfiguration treeConfiguration) {

Optional<TreeDescription> optionalTreeDescription = this.findTreeDescription(editingContext, treeConfiguration);
if (optionalTreeDescription.isPresent()) {
Expand All @@ -91,9 +91,9 @@ public Optional<IRepresentationEventProcessor> createRepresentationEventProcesso
return Optional.empty();
}

private Optional<TreeDescription> findTreeDescription(IEditingContext editingContext, TreeConfiguration treeConfiguration) {
private Optional<TreeDescription> findTreeDescription(IEditingContext editingContext, ExplorerConfiguration treeConfiguration) {
VariableManager variableManager = new VariableManager();
variableManager.put(TreeConfiguration.TREE_ID, treeConfiguration.getId());
variableManager.put(ExplorerConfiguration.TREE_ID, treeConfiguration.getId());
return this.representationDescriptionSearchService
.findAll(editingContext).values().stream()
.filter(TreeDescription.class::isInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.trees.graphql.datafetchers.subscription;
package org.eclipse.sirius.web.application.views.explorer;

import com.fasterxml.jackson.databind.ObjectMapper;

Expand All @@ -19,8 +19,6 @@
import java.util.Objects;

import org.eclipse.sirius.components.annotations.spring.graphql.SubscriptionDataFetcher;
import org.eclipse.sirius.components.collaborative.trees.api.TreeConfiguration;
import org.eclipse.sirius.components.collaborative.trees.dto.TreeEventInput;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.IEventProcessorSubscriptionProvider;
Expand All @@ -37,8 +35,8 @@
* @author hmarchadour
* @author pcdavid
*/
@SubscriptionDataFetcher(type = "Subscription", field = "treeEvent")
public class SubscriptionTreeEventDataFetcher implements IDataFetcherWithFieldCoordinates<Publisher<DataFetcherResult<IPayload>>> {
@SubscriptionDataFetcher(type = "Subscription", field = "explorerEvent")
public class SubscriptionExplorerEventDataFetcher implements IDataFetcherWithFieldCoordinates<Publisher<DataFetcherResult<IPayload>>> {

private static final String INPUT_ARGUMENT = "input";

Expand All @@ -48,7 +46,7 @@ public class SubscriptionTreeEventDataFetcher implements IDataFetcherWithFieldCo

private final IEventProcessorSubscriptionProvider eventProcessorSubscriptionProvider;

public SubscriptionTreeEventDataFetcher(ObjectMapper objectMapper, IExceptionWrapper exceptionWrapper, IEventProcessorSubscriptionProvider eventProcessorSubscriptionProvider) {
public SubscriptionExplorerEventDataFetcher(ObjectMapper objectMapper, IExceptionWrapper exceptionWrapper, IEventProcessorSubscriptionProvider eventProcessorSubscriptionProvider) {
this.objectMapper = Objects.requireNonNull(objectMapper);
this.exceptionWrapper = Objects.requireNonNull(exceptionWrapper);
this.eventProcessorSubscriptionProvider = Objects.requireNonNull(eventProcessorSubscriptionProvider);
Expand All @@ -57,8 +55,8 @@ public SubscriptionTreeEventDataFetcher(ObjectMapper objectMapper, IExceptionWra
@Override
public Publisher<DataFetcherResult<IPayload>> get(DataFetchingEnvironment environment) throws Exception {
Object argument = environment.getArgument(INPUT_ARGUMENT);
var input = this.objectMapper.convertValue(argument, TreeEventInput.class);
var treeConfiguration = new TreeConfiguration(input.editingContextId(), input.treeId(), input.expanded(), input.activeFilterIds());
var input = this.objectMapper.convertValue(argument, ExplorerEventInput.class);
var treeConfiguration = new ExplorerConfiguration(input.editingContextId(), input.treeId(), input.expanded(), input.activeFilterIds());

Map<String, Object> localContext = new HashMap<>();
localContext.put(LocalContextConstants.EDITING_CONTEXT_ID, input.editingContextId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extend type Subscription {
explorerEvent(input: ExplorerEventInput!): TreeEventPayload!
}

input ExplorerEventInput {
id: ID!
treeId: String!
editingContextId: ID!
expanded: [String!]!
activeFilterIds: [String!]!
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.trees.tests.graphql;
package org.eclipse.sirius.web.tests.services.explorer;

import java.util.Objects;

import org.eclipse.sirius.components.collaborative.trees.dto.TreeEventInput;
import org.eclipse.sirius.components.graphql.tests.api.IGraphQLRequestor;
import org.eclipse.sirius.components.graphql.tests.api.ISubscriptionRunner;
import org.eclipse.sirius.web.application.views.explorer.ExplorerEventInput;
import org.springframework.stereotype.Service;

import reactor.core.publisher.Flux;
Expand All @@ -27,24 +27,24 @@
* @author gdaniel
*/
@Service
public class TreeEventSubscriptionRunner implements ISubscriptionRunner<TreeEventInput> {
public class ExplorerEventSubscriptionRunner implements ISubscriptionRunner<ExplorerEventInput> {

private static final String TREE_EVENT_SUBSCRIPTION = """
subscription treeEvent($input: TreeEventInput!) {
treeEvent(input: $input) {
subscription explorerEvent($input: ExplorerEventInput!) {
explorerEvent(input: $input) {
__typename
}
}
""";

private final IGraphQLRequestor graphQLRequestor;

public TreeEventSubscriptionRunner(IGraphQLRequestor graphQLRequestor) {
public ExplorerEventSubscriptionRunner(IGraphQLRequestor graphQLRequestor) {
this.graphQLRequestor = Objects.requireNonNull(graphQLRequestor);
}

@Override
public Flux<Object> run(TreeEventInput input) {
public Flux<Object> run(ExplorerEventInput input) {
return this.graphQLRequestor.subscribe(TREE_EVENT_SUBSCRIPTION, input);
}

Expand Down
Loading

0 comments on commit 68c35f2

Please sign in to comment.