From b438d6b8a1d97e9c8b4c9af7538ac7e0dbf60c9c Mon Sep 17 00:00:00 2001 From: Jerome Gout Date: Mon, 9 Sep 2024 10:15:37 +0200 Subject: [PATCH] [3961] Review changes Bug: https://github.com/eclipse-sirius/sirius-web/issues/3961 Signed-off-by: Jerome Gout --- ...ontextExplorerDescriptionEventHandler.java | 38 +++++++++-- .../services/ExplorerDescriptionService.java | 66 ------------------- .../api/IExplorerDescriptionService.java | 28 -------- ...orerRepresentationDescriptionProvider.java | 47 +++++-------- ...DomainExplorerTreeDescriptionProvider.java | 10 ++- .../src/views/explorer/ExplorerView.tsx | 48 +++++--------- .../src/views/explorer/ExplorerView.types.ts | 5 +- .../views/explorer}/TreeDescriptionsMenu.tsx | 10 +-- .../explorer}/TreeDescriptionsMenu.types.ts | 8 +-- .../views/explorer/useExplorerDescriptions.ts | 17 ++++- .../explorer/useExplorerDescriptions.types.ts | 3 +- .../explorer/useExplorerSubscription.tsx | 3 +- .../trees/description/TreeDescription.java | 33 +++++++++- .../sirius-components-trees/src/index.ts | 1 - .../src/toolbar/TreeToolBar.tsx | 15 +---- .../src/toolbar/TreeToolBar.types.ts | 5 +- 16 files changed, 134 insertions(+), 203 deletions(-) delete mode 100644 packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/ExplorerDescriptionService.java delete mode 100644 packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/api/IExplorerDescriptionService.java rename packages/{trees/frontend/sirius-components-trees/src/toolbar => sirius-web/frontend/sirius-web-application/src/views/explorer}/TreeDescriptionsMenu.tsx (90%) rename packages/{trees/frontend/sirius-components-trees/src/toolbar => sirius-web/frontend/sirius-web-application/src/views/explorer}/TreeDescriptionsMenu.types.ts (74%) diff --git a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/handlers/EditingContextExplorerDescriptionEventHandler.java b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/handlers/EditingContextExplorerDescriptionEventHandler.java index be751b61b62..494d40e4212 100644 --- a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/handlers/EditingContextExplorerDescriptionEventHandler.java +++ b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/handlers/EditingContextExplorerDescriptionEventHandler.java @@ -12,18 +12,24 @@ *******************************************************************************/ package org.eclipse.sirius.web.application.views.explorer.handlers; +import java.util.Comparator; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import org.eclipse.sirius.components.collaborative.api.ChangeDescription; import org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler; import org.eclipse.sirius.components.core.api.IEditingContext; import org.eclipse.sirius.components.core.api.IInput; import org.eclipse.sirius.components.core.api.IPayload; +import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService; +import org.eclipse.sirius.components.trees.description.TreeDescription; import org.eclipse.sirius.web.application.views.explorer.dto.EditingContextExplorerDescriptionsInput; import org.eclipse.sirius.web.application.views.explorer.dto.EditingContextExplorerDescriptionsPayload; import org.eclipse.sirius.web.application.views.explorer.dto.ExplorerDescriptionMetadata; -import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerDescriptionService; +import org.eclipse.sirius.web.application.views.explorer.services.ExplorerDescriptionProvider; +import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerDescriptionMapper; +import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerTreeDescriptionProvider; import org.springframework.stereotype.Service; import reactor.core.publisher.Sinks; @@ -36,10 +42,17 @@ @Service public class EditingContextExplorerDescriptionEventHandler implements IEditingContextEventHandler { - private final IExplorerDescriptionService explorerDescriptionService; - public EditingContextExplorerDescriptionEventHandler(IExplorerDescriptionService explorerDescriptionService) { - this.explorerDescriptionService = Objects.requireNonNull(explorerDescriptionService); + private final IExplorerDescriptionMapper explorerDescriptionMapper; + + private final IRepresentationDescriptionSearchService representationDescriptionSearchService; + + private final List explorerTreeDescriptionProviders; + + public EditingContextExplorerDescriptionEventHandler(IExplorerDescriptionMapper explorerDescriptionMapper, IRepresentationDescriptionSearchService representationDescriptionSearchService, List explorerTreeDescriptionProviders) { + this.explorerDescriptionMapper = Objects.requireNonNull(explorerDescriptionMapper); + this.representationDescriptionSearchService = representationDescriptionSearchService; + this.explorerTreeDescriptionProviders = explorerTreeDescriptionProviders; } @Override @@ -51,8 +64,23 @@ public boolean canHandle(IEditingContext editingContext, IInput input) { public void handle(Sinks.One payloadSink, Sinks.Many changeDescriptionSink, IEditingContext editingContext, IInput input) { List explorerDescriptions = List.of(); if (input instanceof EditingContextExplorerDescriptionsInput) { - explorerDescriptions = this.explorerDescriptionService.findAll(editingContext); + explorerDescriptions = this.findAllExplorerTreeDescriptions(editingContext); } payloadSink.tryEmitValue(new EditingContextExplorerDescriptionsPayload(input.id(), explorerDescriptions)); } + + List findAllExplorerTreeDescriptions(IEditingContext editingContext) { + var optionalDefaultExplorerDescription = this.representationDescriptionSearchService.findById(editingContext, ExplorerDescriptionProvider.DESCRIPTION_ID) + .filter(TreeDescription.class::isInstance) + .map(TreeDescription.class::cast); + + var explorers = this.explorerTreeDescriptionProviders.stream() + .flatMap(provider -> provider.getDescriptions(editingContext).stream()) + .map(this.explorerDescriptionMapper::toDTO) + .sorted(Comparator.comparing(ExplorerDescriptionMetadata::label)) + .collect(Collectors.toList()); + + optionalDefaultExplorerDescription.ifPresent(treeDescription -> explorers.add(this.explorerDescriptionMapper.toDTO(treeDescription))); + return explorers; + } } diff --git a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/ExplorerDescriptionService.java b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/ExplorerDescriptionService.java deleted file mode 100644 index d59befe44ff..00000000000 --- a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/ExplorerDescriptionService.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * 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.web.application.views.explorer.services; - -import java.util.Comparator; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -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.eclipse.sirius.web.application.views.explorer.dto.ExplorerDescriptionMetadata; -import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerDescriptionMapper; -import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerDescriptionService; -import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerTreeDescriptionProvider; -import org.springframework.stereotype.Service; - -/** - * Service to manipulate explorer description candidates. - * - * @author Jerome Gout - */ -@Service -public class ExplorerDescriptionService implements IExplorerDescriptionService { - - private final IExplorerDescriptionMapper explorerDescriptionMapper; - - private final IRepresentationDescriptionSearchService representationDescriptionSearchService; - - private final List explorerTreeDescriptionProviders; - - public ExplorerDescriptionService(IExplorerDescriptionMapper explorerDescriptionMapper, IRepresentationDescriptionSearchService representationDescriptionSearchService, List explorerTreeDescriptionProviders) { - this.explorerDescriptionMapper = Objects.requireNonNull(explorerDescriptionMapper); - this.representationDescriptionSearchService = representationDescriptionSearchService; - this.explorerTreeDescriptionProviders = explorerTreeDescriptionProviders; - } - - @Override - public List findAll(IEditingContext editingContext) { - var optionalDefaultExplorerDescription = this.representationDescriptionSearchService.findById(editingContext, ExplorerDescriptionProvider.DESCRIPTION_ID) - .filter(TreeDescription.class::isInstance) - .map(TreeDescription.class::cast); - - var explorers = this.explorerTreeDescriptionProviders.stream() - .flatMap(provider -> provider.getDescriptions(editingContext).stream()) - .map(this.explorerDescriptionMapper::toDTO) - .sorted(Comparator.comparing(ExplorerDescriptionMetadata::label)) - .collect(Collectors.toList()); - - if (optionalDefaultExplorerDescription.isPresent()) { - explorers.add(this.explorerDescriptionMapper.toDTO(optionalDefaultExplorerDescription.get())); - } - return explorers; - } -} diff --git a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/api/IExplorerDescriptionService.java b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/api/IExplorerDescriptionService.java deleted file mode 100644 index 0e7cb21ca69..00000000000 --- a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/api/IExplorerDescriptionService.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * 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.web.application.views.explorer.services.api; - -import java.util.List; - -import org.eclipse.sirius.components.core.api.IEditingContext; -import org.eclipse.sirius.web.application.views.explorer.dto.ExplorerDescriptionMetadata; - -/** - * Service to manipulate explorer candidates. - * - * @author Jerome Gout - */ -public interface IExplorerDescriptionService { - - List findAll(IEditingContext editingContext); -} diff --git a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/tree/DomainExplorerRepresentationDescriptionProvider.java b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/tree/DomainExplorerRepresentationDescriptionProvider.java index 4855df60d26..038ebb2a5e4 100644 --- a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/tree/DomainExplorerRepresentationDescriptionProvider.java +++ b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/tree/DomainExplorerRepresentationDescriptionProvider.java @@ -17,18 +17,14 @@ import java.util.Optional; import org.eclipse.emf.edit.domain.EditingDomain; -import org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider; import org.eclipse.sirius.components.core.api.IEditingContext; -import org.eclipse.sirius.components.core.api.IObjectService; -import org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService; -import org.eclipse.sirius.components.core.api.IURLParser; +import org.eclipse.sirius.components.core.api.IEditingContextRepresentationDescriptionProvider; import org.eclipse.sirius.components.domain.Domain; import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext; import org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider; import org.eclipse.sirius.components.representations.IRepresentationDescription; import org.eclipse.sirius.components.representations.VariableManager; import org.eclipse.sirius.components.trees.description.TreeDescription; -import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationDataSearchService; import org.springframework.stereotype.Service; /** @@ -37,41 +33,30 @@ * @author Jerome Gout */ @Service -public class DomainExplorerRepresentationDescriptionProvider extends DomainTreeRepresentationDescriptionProvider { +public class DomainExplorerRepresentationDescriptionProvider implements IEditingContextRepresentationDescriptionProvider { public static final String DESCRIPTION_ID = "domain_explorer_description"; - public DomainExplorerRepresentationDescriptionProvider(IObjectService objectService, IURLParser urlParser, List representationImageProviders, - IRepresentationDataSearchService representationDataSearchService, IRepresentationMetadataSearchService representationMetadataSearchService) { - super(objectService, urlParser, representationImageProviders, representationDataSearchService, representationMetadataSearchService); + private final DomainTreeRepresentationDescriptionProvider domainTreeRepresentationDescriptionProvider; + + public DomainExplorerRepresentationDescriptionProvider(DomainTreeRepresentationDescriptionProvider domainTreeRepresentationDescriptionProvider) { + this.domainTreeRepresentationDescriptionProvider = domainTreeRepresentationDescriptionProvider; } @Override public List getRepresentationDescriptions(IEditingContext editingContext) { - var result = super.getRepresentationDescriptions(editingContext); + var result = this.domainTreeRepresentationDescriptionProvider.getRepresentationDescriptions(editingContext); TreeDescription domainTreeDescription = (TreeDescription) result.get(0); - var explorerDescription = TreeDescription.newTreeDescription(DESCRIPTION_ID) - .label("Domain explorer") - .idProvider(new GetOrCreateRandomIdProvider()) - .canCreatePredicate(variableManager -> false) - .treeItemIdProvider(domainTreeDescription.getTreeItemIdProvider()) - .kindProvider(domainTreeDescription.getKindProvider()) - .labelProvider(domainTreeDescription.getLabelProvider()) - .targetObjectIdProvider(variableManager -> variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class).map(IEditingContext::getId).orElse(null)) - .iconURLProvider(domainTreeDescription.getIconURLProvider()) - .editableProvider(domainTreeDescription.getEditableProvider()) - .deletableProvider(domainTreeDescription.getDeletableProvider()) - .selectableProvider(domainTreeDescription.getSelectableProvider()) - .elementsProvider(this::getElements) - .hasChildrenProvider(domainTreeDescription.getHasChildrenProvider()) - .childrenProvider(domainTreeDescription.getChildrenProvider()) - .parentObjectProvider(domainTreeDescription.getParentObjectProvider()) - .deleteHandler(domainTreeDescription.getDeleteHandler()) - .renameHandler(domainTreeDescription.getRenameHandler()) - .treeItemObjectProvider(domainTreeDescription.getTreeItemObjectProvider()) - .build(); + var explorerDescription = TreeDescription.newTreeDescription(domainTreeDescription) + .id(DESCRIPTION_ID) + .label("Domain explorer") + .idProvider(new GetOrCreateRandomIdProvider()) + .canCreatePredicate(variableManager -> false) + .targetObjectIdProvider(variableManager -> variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class).map(IEditingContext::getId).orElse(null)) + .elementsProvider(this::getElements) + .build(); return List.of(explorerDescription); } @@ -83,7 +68,7 @@ private List getElements(VariableManager variableManager) { .map(IEMFEditingContext.class::cast) .map(IEMFEditingContext::getDomain) .map(EditingDomain::getResourceSet); - return optionalResourceSet.map(resourceSet -> resourceSet.getResources().stream() + return optionalResourceSet.map(resourceSet -> resourceSet.getResources().stream() .flatMap(res -> res.getContents().stream()) .filter(Domain.class::isInstance) .map(Domain.class::cast) diff --git a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/tree/DomainExplorerTreeDescriptionProvider.java b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/tree/DomainExplorerTreeDescriptionProvider.java index 4dc945cfc52..a3f233f929c 100644 --- a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/tree/DomainExplorerTreeDescriptionProvider.java +++ b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/tree/DomainExplorerTreeDescriptionProvider.java @@ -40,7 +40,7 @@ public DomainExplorerTreeDescriptionProvider(IRepresentationDescriptionSearchSer @Override public List getDescriptions(IEditingContext editingContext) { - var optionalDomainExplorerDescription = this.getDomainExplorerTreeDescrption(editingContext); + var optionalDomainExplorerDescription = this.getDomainExplorerTreeDescription(editingContext); if (optionalDomainExplorerDescription.isPresent()) { return List.of(optionalDomainExplorerDescription.get()); @@ -48,7 +48,7 @@ public List getDescriptions(IEditingContext editingContext) { return List.of(); } - private Optional getDomainExplorerTreeDescrption(IEditingContext editingContext) { + private Optional getDomainExplorerTreeDescription(IEditingContext editingContext) { if (this.isContainingDomainElement(editingContext)) { return this.representationDescriptionSearchService .findById(editingContext, DomainExplorerRepresentationDescriptionProvider.DESCRIPTION_ID) @@ -61,10 +61,8 @@ private Optional getDomainExplorerTreeDescrption(IEditingContex private boolean isContainingDomainElement(IEditingContext editingContext) { if (editingContext instanceof IEMFEditingContext emfEditingContext) { return emfEditingContext.getDomain().getResourceSet().getResources().stream() - .filter(res -> res.getContents().size() > 0) - .map(res -> res.getContents().get(0)) - .filter(Domain.class::isInstance) - .count() > 0; + .flatMap(res -> res.getContents().stream()) + .anyMatch(Domain.class::isInstance); } return false; } diff --git a/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/ExplorerView.tsx b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/ExplorerView.tsx index 5d406fdd195..301883e2a91 100644 --- a/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/ExplorerView.tsx +++ b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/ExplorerView.tsx @@ -13,7 +13,6 @@ import { WorkbenchViewComponentProps } from '@eclipse-sirius/sirius-components-core'; import { FilterBar, - TreeDescription, TreeFilter, TreeToolBar, TreeToolBarContext, @@ -28,6 +27,7 @@ import { ExplorerViewState } from './ExplorerView.types'; import { useExplorerDescriptions } from './useExplorerDescriptions'; import { useExplorerSubscription } from './useExplorerSubscription'; import { DEFAULT_EXPLORER_DESCRIPTION_ID } from './useExplorerSubscription.types'; +import { TreeDescriptionsMenu } from './TreeDescriptionsMenu'; const useStyles = makeStyles()((theme: Theme) => ({ treeView: { @@ -52,8 +52,7 @@ export const ExplorerView = ({ editingContextId, readOnly }: WorkbenchViewCompon treeFilters: [], expanded: [], maxDepth: 1, - treeDescriptions: [], - activeTreeDescription: null, + activeTreeDescriptionId: DEFAULT_EXPLORER_DESCRIPTION_ID, }; const [state, setState] = useState(initialState); const treeToolBarContributionComponents = useContext(TreeToolBarContext).map( @@ -63,7 +62,7 @@ export const ExplorerView = ({ editingContextId, readOnly }: WorkbenchViewCompon const { tree } = useExplorerSubscription( editingContextId, - state.activeTreeDescription?.id, + state.activeTreeDescriptionId, activeTreeFilterIds, state.expanded, state.maxDepth @@ -71,7 +70,7 @@ export const ExplorerView = ({ editingContextId, readOnly }: WorkbenchViewCompon const { loading, treeFilters } = useTreeFilters(editingContextId, 'explorer://'); - const { loading: explorersLoading, explorerDescriptions } = useExplorerDescriptions(editingContextId); + const { explorerDescriptions } = useExplorerDescriptions(editingContextId); useEffect(() => { if (!loading) { @@ -84,25 +83,6 @@ export const ExplorerView = ({ editingContextId, readOnly }: WorkbenchViewCompon } }, [loading, treeFilters]); - const getDefaultExplorerDescription = (all: TreeDescription[]): TreeDescription => { - const defaultIndex = all.findIndex((td) => td.id === DEFAULT_EXPLORER_DESCRIPTION_ID); - return all[defaultIndex]; - }; - - useEffect(() => { - if (!explorersLoading) { - const allExplorerDescriptions: TreeDescription[] = explorerDescriptions.map((gqlExplorerDescription) => ({ - id: gqlExplorerDescription.id, - label: gqlExplorerDescription.label, - })); - setState((prevState) => ({ - ...prevState, - treeDescriptions: allExplorerDescriptions, - activeTreeDescription: getDefaultExplorerDescription(allExplorerDescriptions), - })); - } - }, [explorersLoading, explorerDescriptions]); - const treeElement = useRef(null); useEffect(() => { const downHandler = (event) => { @@ -154,6 +134,16 @@ export const ExplorerView = ({ editingContextId, readOnly }: WorkbenchViewCompon setState((prevState) => ({ ...prevState, expanded, maxDepth })); }; + const treeDescriptionSelector: JSX.Element = explorerDescriptions.length > 1 && ( + + setState((prevState) => ({ ...prevState, activeTreeDescriptionId: treeDescription.id })) + } + /> + ); + return (
- setState((prevState) => ({ ...prevState, activeTreeDescription: treeDescription })) - } - /> + treeToolBarContributionComponents={treeToolBarContributionComponents}> + {treeDescriptionSelector} +
{filterBar} ({ checkedTreeDescription: { @@ -33,7 +33,7 @@ const useTreeDescriptionsMenuStyles = makeStyles()((_) => ({ export const TreeDescriptionsMenu = ({ treeDescriptions, - activeTreeDescription, + activeTreeDescriptionId, onTreeDescriptionChange, }: TreeDescriptionsMenuProps) => { const { classes } = useTreeDescriptionsMenuStyles(); @@ -59,7 +59,7 @@ export const TreeDescriptionsMenu = ({ prevOpen.current = open; }, [open]); - const updateActiveTreeDescription = (treeDescription: TreeDescription) => { + const updateActiveTreeDescription = (treeDescription: TreeDescriptionMetadata) => { onTreeDescriptionChange(treeDescription); setOpen(false); }; @@ -82,11 +82,11 @@ export const TreeDescriptionsMenu = ({ {treeDescriptions.map((td) => ( updateActiveTreeDescription(td)}> diff --git a/packages/trees/frontend/sirius-components-trees/src/toolbar/TreeDescriptionsMenu.types.ts b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/TreeDescriptionsMenu.types.ts similarity index 74% rename from packages/trees/frontend/sirius-components-trees/src/toolbar/TreeDescriptionsMenu.types.ts rename to packages/sirius-web/frontend/sirius-web-application/src/views/explorer/TreeDescriptionsMenu.types.ts index ae129889708..a28b80c6931 100644 --- a/packages/trees/frontend/sirius-components-trees/src/toolbar/TreeDescriptionsMenu.types.ts +++ b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/TreeDescriptionsMenu.types.ts @@ -12,12 +12,12 @@ *******************************************************************************/ export interface TreeDescriptionsMenuProps { - treeDescriptions: TreeDescription[]; - activeTreeDescription: TreeDescription; - onTreeDescriptionChange: (treeDescription: TreeDescription) => void; + treeDescriptions: TreeDescriptionMetadata[]; + activeTreeDescriptionId: string; + onTreeDescriptionChange: (treeDescription: TreeDescriptionMetadata) => void; } -export interface TreeDescription { +export interface TreeDescriptionMetadata { id: string; label: string; } diff --git a/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerDescriptions.ts b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerDescriptions.ts index e64b5b0e47d..b6523abc88b 100644 --- a/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerDescriptions.ts +++ b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerDescriptions.ts @@ -13,7 +13,8 @@ import { gql, useQuery } from '@apollo/client'; import { useMultiToast } from '@eclipse-sirius/sirius-components-core'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; +import { TreeDescriptionMetadata } from './TreeDescriptionsMenu.types'; import { GQLExplorerDescription, GQLGetAllExplorerDescriptionsData, @@ -35,6 +36,8 @@ const getAllExplorerDescriptionsQuery = gql` `; export const useExplorerDescriptions = (editingContextId: string): UseExplorerDescriptionValue => { + const [treeDescriptions, setTreeDescriptions] = useState([]); + const { loading, data, error } = useQuery( getAllExplorerDescriptionsQuery, { @@ -55,8 +58,18 @@ export const useExplorerDescriptions = (editingContextId: string): UseExplorerDe const explorerDescriptions: GQLExplorerDescription[] = data?.viewer.editingContext.explorerDescriptions || []; + useEffect(() => { + if (!loading) { + const allExplorerDescriptions: TreeDescriptionMetadata[] = explorerDescriptions.map((gqlExplorerDescription) => ({ + id: gqlExplorerDescription.id, + label: gqlExplorerDescription.label, + })); + setTreeDescriptions(allExplorerDescriptions); + } + }, [loading, explorerDescriptions]); + return { - explorerDescriptions, + explorerDescriptions: treeDescriptions, loading, }; }; diff --git a/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerDescriptions.types.ts b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerDescriptions.types.ts index a2d031d3b21..30b70999229 100644 --- a/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerDescriptions.types.ts +++ b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerDescriptions.types.ts @@ -10,9 +10,10 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { TreeDescriptionMetadata } from './TreeDescriptionsMenu.types'; export interface UseExplorerDescriptionValue { - explorerDescriptions: GQLExplorerDescription[]; + explorerDescriptions: TreeDescriptionMetadata[]; loading: boolean; } diff --git a/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerSubscription.tsx b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerSubscription.tsx index 405f0b964f7..8c74e2f9bae 100644 --- a/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerSubscription.tsx +++ b/packages/sirius-web/frontend/sirius-web-application/src/views/explorer/useExplorerSubscription.tsx @@ -22,7 +22,6 @@ import { } from '@eclipse-sirius/sirius-components-trees'; import { useEffect, useState } from 'react'; import { - DEFAULT_EXPLORER_DESCRIPTION_ID, GQLExplorerEventData, GQLExplorerEventInput, GQLExplorerEventVariables, @@ -47,7 +46,7 @@ export const useExplorerSubscription = ( const input: GQLExplorerEventInput = { id: state.id, editingContextId, - treeId: `explorer://?treeDescriptionId=${encodeURIComponent(treeDescriptionId || DEFAULT_EXPLORER_DESCRIPTION_ID)}`, + treeId: `explorer://?treeDescriptionId=${encodeURIComponent(treeDescriptionId)}`, activeFilterIds, expanded, }; diff --git a/packages/trees/backend/sirius-components-trees/src/main/java/org/eclipse/sirius/components/trees/description/TreeDescription.java b/packages/trees/backend/sirius-components-trees/src/main/java/org/eclipse/sirius/components/trees/description/TreeDescription.java index 73e1c3c76cc..941501d379c 100644 --- a/packages/trees/backend/sirius-components-trees/src/main/java/org/eclipse/sirius/components/trees/description/TreeDescription.java +++ b/packages/trees/backend/sirius-components-trees/src/main/java/org/eclipse/sirius/components/trees/description/TreeDescription.java @@ -89,6 +89,10 @@ public static Builder newTreeDescription(String id) { return new Builder(id); } + public static Builder newTreeDescription(TreeDescription treeDescription) { + return new Builder(treeDescription); + } + @Override public String getId() { return this.id; @@ -182,7 +186,7 @@ public String toString() { @SuppressWarnings("checkstyle:HiddenField") public static final class Builder { - private final String id; + private String id; private String label; @@ -224,6 +228,33 @@ private Builder(String id) { this.id = Objects.requireNonNull(id); } + private Builder(TreeDescription treeDescription) { + this.id = treeDescription.getId(); + this.label = treeDescription.getLabel(); + this.idProvider = treeDescription.getIdProvider(); + this.treeItemIdProvider = treeDescription.getTreeItemIdProvider(); + this.kindProvider = treeDescription.getKindProvider(); + this.labelProvider = treeDescription.getLabelProvider(); + this.targetObjectIdProvider = treeDescription.getTargetObjectIdProvider(); + this.parentObjectProvider = treeDescription.getParentObjectProvider(); + this.iconURLProvider = treeDescription.getIconURLProvider(); + this.editableProvider = treeDescription.getEditableProvider(); + this.deletableProvider = treeDescription.getDeletableProvider(); + this.selectableProvider = treeDescription.getSelectableProvider(); + this.elementsProvider = treeDescription.getElementsProvider(); + this.childrenProvider = treeDescription.getChildrenProvider(); + this.hasChildrenProvider = treeDescription.getHasChildrenProvider(); + this.canCreatePredicate = treeDescription.getCanCreatePredicate(); + this.deleteHandler = treeDescription.getDeleteHandler(); + this.renameHandler = treeDescription.getRenameHandler(); + this.treeItemObjectProvider = treeDescription.getTreeItemObjectProvider(); + } + + public Builder id(String id) { + this.id = Objects.requireNonNull(id); + return this; + } + public Builder label(String label) { this.label = Objects.requireNonNull(label); return this; diff --git a/packages/trees/frontend/sirius-components-trees/src/index.ts b/packages/trees/frontend/sirius-components-trees/src/index.ts index 215608a318f..11aa353bf17 100644 --- a/packages/trees/frontend/sirius-components-trees/src/index.ts +++ b/packages/trees/frontend/sirius-components-trees/src/index.ts @@ -10,7 +10,6 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -export * from './toolbar/TreeDescriptionsMenu.types'; export * from './toolbar/TreeToolBar'; export * from './toolbar/TreeToolBarContext'; export * from './toolbar/TreeToolBarContext.types'; diff --git a/packages/trees/frontend/sirius-components-trees/src/toolbar/TreeToolBar.tsx b/packages/trees/frontend/sirius-components-trees/src/toolbar/TreeToolBar.tsx index 56dbc088cc7..31d9b4ea387 100644 --- a/packages/trees/frontend/sirius-components-trees/src/toolbar/TreeToolBar.tsx +++ b/packages/trees/frontend/sirius-components-trees/src/toolbar/TreeToolBar.tsx @@ -16,7 +16,6 @@ import IconButton from '@mui/material/IconButton'; import React from 'react'; import { makeStyles } from 'tss-react/mui'; import { TreeFiltersMenu } from '../views/TreeFiltersMenu'; -import { TreeDescriptionsMenu } from './TreeDescriptionsMenu'; import { TreeToolBarProps } from './TreeToolBar.types'; import { TreeToolBarContributionComponentProps } from './TreeToolBarContribution.types'; @@ -41,11 +40,9 @@ export const TreeToolBar = ({ synchronized, treeFilters, onTreeFilterMenuItemClick, - treeDescriptions, - activeTreeDescription, - onTreeDescriptionChange, treeToolBarContributionComponents, readOnly, + children, }: TreeToolBarProps) => { const { classes } = useTreeToolbarStyles(); @@ -54,14 +51,6 @@ export const TreeToolBar = ({ treeFiltersMenu = ; } - const treeDescriptionSelector: JSX.Element = treeDescriptions.length > 1 && ( - - ); - const preferenceButtonSynchronizeTitle = synchronized ? 'Disable synchronization with representation' : 'Enable synchronization with representation'; @@ -78,7 +67,7 @@ export const TreeToolBar = ({ return element; })} {treeFiltersMenu} - {treeDescriptionSelector} + {children} void; treeFilters: TreeFilter[]; onTreeFilterMenuItemClick: (filters: TreeFilter[]) => void; - treeDescriptions: TreeDescription[]; - activeTreeDescription: TreeDescription; - onTreeDescriptionChange: (treeDescription: TreeDescription) => void; treeToolBarContributionComponents: ((props: TreeToolBarContributionComponentProps) => JSX.Element)[]; readOnly: boolean; + children: React.ReactNode; } export interface TreeToolBarState {