Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3021] Improve the support of the Sirius Web user interface
Bug: #3021 Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
- Loading branch information
1 parent
19b5f53
commit 11f727a
Showing
14 changed files
with
575 additions
and
6 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...clipse/sirius/web/application/editingcontext/controllers/EditingContextIdDataFetcher.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,31 @@ | ||
/******************************************************************************* | ||
* 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.editingcontext.controllers; | ||
|
||
import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher; | ||
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates; | ||
|
||
import graphql.schema.DataFetchingEnvironment; | ||
|
||
/** | ||
* Data fetcher for the field EditingContext#id. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@QueryDataFetcher(type = "EditingContext", field = "id") | ||
public class EditingContextIdDataFetcher implements IDataFetcherWithFieldCoordinates<String> { | ||
@Override | ||
public String get(DataFetchingEnvironment environment) throws Exception { | ||
return environment.getSource(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...s/web/application/editingcontext/controllers/ProjectCurrentEditingContextDataFetcher.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,45 @@ | ||
/******************************************************************************* | ||
* 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.editingcontext.controllers; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher; | ||
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates; | ||
import org.eclipse.sirius.components.graphql.api.LocalContextConstants; | ||
import org.eclipse.sirius.web.application.project.dto.ProjectDTO; | ||
|
||
import graphql.execution.DataFetcherResult; | ||
import graphql.schema.DataFetchingEnvironment; | ||
|
||
/** | ||
* Data fetcher for the field Project#currentEditingContext. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@QueryDataFetcher(type = "Project", field = "currentEditingContext") | ||
public class ProjectCurrentEditingContextDataFetcher implements IDataFetcherWithFieldCoordinates<DataFetcherResult<String>> { | ||
@Override | ||
public DataFetcherResult<String> get(DataFetchingEnvironment environment) throws Exception { | ||
ProjectDTO project = environment.getSource(); | ||
String editingContextId = project.id().toString(); | ||
Map<String, Object> localContext = new HashMap<>(); | ||
localContext.put(LocalContextConstants.EDITING_CONTEXT_ID, editingContextId); | ||
|
||
return DataFetcherResult.<String>newResult() | ||
.data(editingContextId) | ||
.localContext(localContext) | ||
.build(); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...eclipse/sirius/web/application/project/controllers/ViewerProjectTemplatesDataFetcher.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,84 @@ | ||
/******************************************************************************* | ||
* 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.project.controllers; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher; | ||
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates; | ||
import org.eclipse.sirius.web.application.dto.PageInfoWithCount; | ||
import org.eclipse.sirius.web.application.project.dto.ProjectTemplateDTO; | ||
import org.eclipse.sirius.web.application.project.services.api.IProjectTemplateApplicationService; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
|
||
import graphql.relay.Connection; | ||
import graphql.relay.ConnectionCursor; | ||
import graphql.relay.DefaultConnection; | ||
import graphql.relay.DefaultConnectionCursor; | ||
import graphql.relay.DefaultEdge; | ||
import graphql.relay.Edge; | ||
import graphql.relay.Relay; | ||
import graphql.schema.DataFetchingEnvironment; | ||
|
||
/** | ||
* Data fetcher for the field Viewer#projectTemplates. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@QueryDataFetcher(type = "DefaultViewer", field = "projectTemplates") | ||
public class ViewerProjectTemplatesDataFetcher implements IDataFetcherWithFieldCoordinates<Connection<ProjectTemplateDTO>> { | ||
|
||
private static final String PAGE_ARGUMENT = "page"; | ||
|
||
private static final String LIMIT_ARGUMENT = "limit"; | ||
|
||
private final IProjectTemplateApplicationService projectTemplateApplicationService; | ||
|
||
public ViewerProjectTemplatesDataFetcher(IProjectTemplateApplicationService projectTemplateApplicationService) { | ||
this.projectTemplateApplicationService = Objects.requireNonNull(projectTemplateApplicationService); | ||
} | ||
|
||
@Override | ||
public Connection<ProjectTemplateDTO> get(DataFetchingEnvironment environment) throws Exception { | ||
int page = Optional.<Integer> ofNullable(environment.getArgument(PAGE_ARGUMENT)) | ||
.filter(pageArgument -> pageArgument > 0) | ||
.orElse(0); | ||
int limit = Optional.<Integer> ofNullable(environment.getArgument(LIMIT_ARGUMENT)) | ||
.filter(limitArgument -> limitArgument > 0) | ||
.orElse(20); | ||
|
||
var pageable = PageRequest.of(page, limit); | ||
var projectTemplatePage = this.projectTemplateApplicationService.findAll(pageable); | ||
return this.toConnection(projectTemplatePage); | ||
} | ||
|
||
private Connection<ProjectTemplateDTO> toConnection(Page<ProjectTemplateDTO> projectTemplatePage) { | ||
var edges = projectTemplatePage.stream().map(projectTemplateDTO -> { | ||
var globalId = new Relay().toGlobalId("ProjectTemplate", projectTemplateDTO.id()); | ||
var cursor = new DefaultConnectionCursor(globalId); | ||
return (Edge<ProjectTemplateDTO>) new DefaultEdge<>(projectTemplateDTO, cursor); | ||
}).toList(); | ||
|
||
ConnectionCursor startCursor = edges.stream().findFirst() | ||
.map(Edge::getCursor) | ||
.orElse(null); | ||
ConnectionCursor endCursor = null; | ||
if (!edges.isEmpty()) { | ||
endCursor = edges.get(edges.size() - 1).getCursor(); | ||
} | ||
var pageInfo = new PageInfoWithCount(startCursor, endCursor, projectTemplatePage.hasPrevious(), projectTemplatePage.hasNext(), projectTemplatePage.getTotalElements()); | ||
return new DefaultConnection<>(edges, pageInfo); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...tion/src/main/java/org/eclipse/sirius/web/application/project/dto/ProjectTemplateDTO.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.project.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
/** | ||
* The DTO for project templates. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public record ProjectTemplateDTO( | ||
@NotNull String id, | ||
@NotNull String label, | ||
@NotNull String imageURL) { | ||
} |
58 changes: 58 additions & 0 deletions
58
...rg/eclipse/sirius/web/application/project/services/ProjectTemplateApplicationService.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,58 @@ | ||
/******************************************************************************* | ||
* 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.project.services; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.sirius.web.application.project.dto.ProjectTemplateDTO; | ||
import org.eclipse.sirius.web.application.project.services.api.IProjectTemplateApplicationService; | ||
import org.eclipse.sirius.web.application.project.services.api.IProjectTemplateProvider; | ||
import org.eclipse.sirius.web.application.project.services.api.ProjectTemplate; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Used to interact with project templates. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class ProjectTemplateApplicationService implements IProjectTemplateApplicationService { | ||
|
||
private final List<IProjectTemplateProvider> projectTemplateProviders; | ||
|
||
public ProjectTemplateApplicationService(List<IProjectTemplateProvider> projectTemplateProviders) { | ||
this.projectTemplateProviders = Objects.requireNonNull(projectTemplateProviders); | ||
} | ||
|
||
@Override | ||
public Page<ProjectTemplateDTO> findAll(Pageable pageable) { | ||
var projectTemplates = this.projectTemplateProviders.stream() | ||
.map(IProjectTemplateProvider::getProjectTemplates) | ||
.flatMap(List::stream) | ||
.sorted(Comparator.comparing(ProjectTemplate::label)) | ||
.toList(); | ||
|
||
int startIndex = (int) pageable.getOffset() * pageable.getPageSize(); | ||
int endIndex = Math.min(((int) pageable.getOffset() + 1) * pageable.getPageSize(), projectTemplates.size()); | ||
var projectTemplateDTOs = projectTemplates.subList(startIndex, endIndex).stream() | ||
.map(projectTemplate -> new ProjectTemplateDTO(projectTemplate.id(), projectTemplate.label(), projectTemplate.imageURL())) | ||
.toList(); | ||
|
||
return new PageImpl<>(projectTemplateDTOs, pageable, projectTemplates.size()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...lipse/sirius/web/application/project/services/api/IProjectTemplateApplicationService.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.project.services.api; | ||
|
||
import org.eclipse.sirius.web.application.project.dto.ProjectTemplateDTO; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
/** | ||
* Used to interact with project templates. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public interface IProjectTemplateApplicationService { | ||
Page<ProjectTemplateDTO> findAll(Pageable pageable); | ||
} |
31 changes: 31 additions & 0 deletions
31
.../org/eclipse/sirius/web/application/project/services/api/IProjectTemplateInitializer.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,31 @@ | ||
/******************************************************************************* | ||
* 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.project.services.api; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.sirius.components.core.RepresentationMetadata; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
|
||
/** | ||
* Initializes the contents of a new project created from a project template. The initializer can add new documents to | ||
* the project, create initial representations, and optionally indicate such a representation to automatically open when | ||
* the user is redirected to the newly create project. | ||
* | ||
* @author pcdavid | ||
*/ | ||
public interface IProjectTemplateInitializer { | ||
boolean canHandle(String projectTemplateId); | ||
|
||
Optional<RepresentationMetadata> handle(String projectTemplateId, IEditingContext editingContext); | ||
} |
25 changes: 25 additions & 0 deletions
25
...ava/org/eclipse/sirius/web/application/project/services/api/IProjectTemplateProvider.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.project.services.api; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Used to register project templates in the backend. This only considers templates' metadata, see | ||
* {@link IProjectTemplateInitializer} for the definition of the actual contents of a project created from a template. | ||
* | ||
* @author pcdavid | ||
*/ | ||
public interface IProjectTemplateProvider { | ||
List<ProjectTemplate> getProjectTemplates(); | ||
} |
36 changes: 36 additions & 0 deletions
36
...rc/main/java/org/eclipse/sirius/web/application/project/services/api/ProjectTemplate.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,36 @@ | ||
/******************************************************************************* | ||
* 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.project.services.api; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
/** | ||
* Description of a project template. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public record ProjectTemplate( | ||
@NotNull String id, | ||
@NotNull String label, | ||
@NotNull String imageURL, | ||
@NotNull List<ProjectTemplateNature> natures) { | ||
public ProjectTemplate { | ||
Objects.requireNonNull(id); | ||
Objects.requireNonNull(label); | ||
Objects.requireNonNull(imageURL); | ||
Objects.requireNonNull(natures); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...n/java/org/eclipse/sirius/web/application/project/services/api/ProjectTemplateNature.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.project.services.api; | ||
|
||
import java.util.Objects; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
/** | ||
* The nature of a project template. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public record ProjectTemplateNature(@NotNull String id) { | ||
public ProjectTemplateNature { | ||
Objects.requireNonNull(id); | ||
} | ||
} |
Oops, something went wrong.