forked from eclipse-sirius/sirius-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3961] Extend the explorer to support multiple presentations
default explorer + one custom explorer for Domain Bug: eclipse-sirius#3961 Signed-off-by: Jerome Gout <[email protected]>
- Loading branch information
1 parent
94e74b7
commit c12e21e
Showing
35 changed files
with
916 additions
and
31 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
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
53 changes: 53 additions & 0 deletions
53
...application/views/explorer/controllers/EditingContextExplorerDescriptionsDataFetcher.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,53 @@ | ||
/******************************************************************************* | ||
* 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.controllers; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher; | ||
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates; | ||
import org.eclipse.sirius.components.graphql.api.IEditingContextDispatcher; | ||
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 graphql.schema.DataFetchingEnvironment; | ||
|
||
/** | ||
* Data fetcher for the EditingContext#explorerDescriptions. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@QueryDataFetcher(type = "EditingContext", field = "explorerDescriptions") | ||
public class EditingContextExplorerDescriptionsDataFetcher implements IDataFetcherWithFieldCoordinates<CompletableFuture<List<ExplorerDescriptionMetadata>>> { | ||
|
||
private final IEditingContextDispatcher editingContextDispatcher; | ||
|
||
public EditingContextExplorerDescriptionsDataFetcher(IEditingContextDispatcher editingContextDispatcher) { | ||
this.editingContextDispatcher = Objects.requireNonNull(editingContextDispatcher); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<List<ExplorerDescriptionMetadata>> get(DataFetchingEnvironment environment) throws Exception { | ||
String editingContextId = environment.getSource(); | ||
var input = new EditingContextExplorerDescriptionsInput(UUID.randomUUID(), editingContextId); | ||
return this.editingContextDispatcher.dispatchQuery(input.editingContextId(), input) | ||
.filter(EditingContextExplorerDescriptionsPayload.class::isInstance) | ||
.map(EditingContextExplorerDescriptionsPayload.class::cast) | ||
.map(EditingContextExplorerDescriptionsPayload::explorerDescriptionMetadata) | ||
.toFuture(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...se/sirius/web/application/views/explorer/dto/EditingContextExplorerDescriptionsInput.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,26 @@ | ||
/******************************************************************************* | ||
* 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.dto; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IInput; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
/** | ||
* The input object for the query field explorerDescriptions. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
public record EditingContextExplorerDescriptionsInput(@NotNull UUID id, @NotNull String editingContextId) implements IInput { } |
27 changes: 27 additions & 0 deletions
27
.../sirius/web/application/views/explorer/dto/EditingContextExplorerDescriptionsPayload.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,27 @@ | ||
/******************************************************************************* | ||
* 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.dto; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IPayload; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
/** | ||
* The payload object for the query field explorerDescriptions. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
public record EditingContextExplorerDescriptionsPayload(@NotNull UUID id, @NotNull List<ExplorerDescriptionMetadata> explorerDescriptionMetadata) implements IPayload { } |
22 changes: 22 additions & 0 deletions
22
...va/org/eclipse/sirius/web/application/views/explorer/dto/ExplorerDescriptionMetadata.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,22 @@ | ||
/******************************************************************************* | ||
* 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.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
/** | ||
* The metadata of an explorer description. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
public record ExplorerDescriptionMetadata(@NotNull String id, @NotNull String label) { } |
86 changes: 86 additions & 0 deletions
86
...eb/application/views/explorer/handlers/EditingContextExplorerDescriptionEventHandler.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,86 @@ | ||
/******************************************************************************* | ||
* 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.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.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; | ||
|
||
/** | ||
* Event handler to find all the explorer descriptions accessible from a given editing context. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@Service | ||
public class EditingContextExplorerDescriptionEventHandler implements IEditingContextEventHandler { | ||
|
||
|
||
private final IExplorerDescriptionMapper explorerDescriptionMapper; | ||
|
||
private final IRepresentationDescriptionSearchService representationDescriptionSearchService; | ||
|
||
private final List<IExplorerTreeDescriptionProvider> explorerTreeDescriptionProviders; | ||
|
||
public EditingContextExplorerDescriptionEventHandler(IExplorerDescriptionMapper explorerDescriptionMapper, IRepresentationDescriptionSearchService representationDescriptionSearchService, List<IExplorerTreeDescriptionProvider> explorerTreeDescriptionProviders) { | ||
this.explorerDescriptionMapper = Objects.requireNonNull(explorerDescriptionMapper); | ||
this.representationDescriptionSearchService = representationDescriptionSearchService; | ||
this.explorerTreeDescriptionProviders = explorerTreeDescriptionProviders; | ||
} | ||
|
||
@Override | ||
public boolean canHandle(IEditingContext editingContext, IInput input) { | ||
return input instanceof EditingContextExplorerDescriptionsInput; | ||
} | ||
|
||
@Override | ||
public void handle(Sinks.One<IPayload> payloadSink, Sinks.Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) { | ||
List<ExplorerDescriptionMetadata> explorerDescriptions = List.of(); | ||
if (input instanceof EditingContextExplorerDescriptionsInput) { | ||
explorerDescriptions = this.findAllExplorerTreeDescriptions(editingContext); | ||
} | ||
payloadSink.tryEmitValue(new EditingContextExplorerDescriptionsPayload(input.id(), explorerDescriptions)); | ||
} | ||
|
||
List<ExplorerDescriptionMetadata> 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; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...org/eclipse/sirius/web/application/views/explorer/services/ExplorerDescriptionMapper.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,33 @@ | ||
/******************************************************************************* | ||
* 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 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.springframework.stereotype.Service; | ||
|
||
/** | ||
* Used to convert an explorer candidate to a DTO. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@Service | ||
public class ExplorerDescriptionMapper implements IExplorerDescriptionMapper { | ||
|
||
@Override | ||
public ExplorerDescriptionMetadata toDTO(TreeDescription treeDescription) { | ||
return new ExplorerDescriptionMetadata(treeDescription.getId(), treeDescription.getLabel()); | ||
} | ||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
...clipse/sirius/web/application/views/explorer/services/api/IExplorerDescriptionMapper.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,25 @@ | ||
/******************************************************************************* | ||
* 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 org.eclipse.sirius.components.trees.description.TreeDescription; | ||
import org.eclipse.sirius.web.application.views.explorer.dto.ExplorerDescriptionMetadata; | ||
|
||
/** | ||
* Used to convert an explorer candidate to a DTO. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
public interface IExplorerDescriptionMapper { | ||
ExplorerDescriptionMetadata toDTO(TreeDescription treeDescription); | ||
} |
28 changes: 28 additions & 0 deletions
28
.../sirius/web/application/views/explorer/services/api/IExplorerTreeDescriptionProvider.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,28 @@ | ||
/******************************************************************************* | ||
* 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.components.trees.description.TreeDescription; | ||
|
||
/** | ||
* Interface to provide tree descriptions that could be used inside the explorer of Sirius web. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
public interface IExplorerTreeDescriptionProvider { | ||
|
||
List<TreeDescription> getDescriptions(IEditingContext editinContext); | ||
} |
Oops, something went wrong.