Skip to content

Commit

Permalink
[3982] Add support for command palette
Browse files Browse the repository at this point in the history
Bug: #3982
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
  • Loading branch information
gcoutable committed Sep 24, 2024
1 parent 5f2fdc1 commit 6c226a3
Show file tree
Hide file tree
Showing 63 changed files with 2,890 additions and 396 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Both `IInput` and `IDomainEvent` implement `ICause` and will thus be used to ind
- https://github.com/eclipse-sirius/sirius-web/issues/3972[#3972] [diagram] The `InsideLabelStyle#displayHeaderSeparator` has been renamed to `headerSeparatorDisplayMode` and is no longer a boolean but an enum with three possible values: NEVER, ALWAYS, and IF-CHILDREN.
Previously, the value false was equivalent to NEVER, and true to IF-CHILDREN.
The new option ALWAYS allows the separator to be displayed in every case.
- https://github.com/eclipse-sirius/sirius-web/issues/3678[#3678] [core] Remove `IRepresentationMetadataSearchService#findByRepresentation`, use `IRepresentationMetadataSearchService#findByRepresentationId` instead.
- https://github.com/eclipse-sirius/sirius-web/issues/3678[#3678] [core] Remove `IRepresentationMetadataSearchService#findByRepresentation`, use `IRepresentationMetadataSearchService#findByRepresentationId` instead.
- https://github.com/eclipse-sirius/sirius-web/issues/3982[#3982] [sirius-web] The edit project view needs to declare the `OmniboxProvider` to benefit from the command palette.

=== Dependency update

Expand All @@ -53,12 +54,14 @@ The new option ALWAYS allows the separator to be displayed in every case.
- https://github.com/eclipse-sirius/sirius-web/issues/3763[#3763] [diagram] Make it possible to display semantic candidates in the selection dialog using a tree
- https://github.com/eclipse-sirius/sirius-web/issues/3979[#3979] [core] Add Project related REST APIs.
The new endpoints are:
** getProjects (`GET /api/rest/projects`): Get all projects.
** getProjects (`GET /api/rest/projects`): Get all projects.
** getProjectById (`GET /api/rest/projects/{projectId}`): Get project with the given id (projectId).
** createProject (`POST /projects`): Create a new project with the given name and
description (optional).
** deleteProject (`POST /api/rest/projects/{projectId}`): Delete the project with the given id (projectId).
** updateProject (`PUT /projects/{projectId}`): Update the project with the given id (projectId).
- https://github.com/eclipse-sirius/sirius-web/issues/3982[#3982] [core] Add support for the command palette.


=== Improvements

Expand Down
909 changes: 545 additions & 364 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/core/backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<module>sirius-components-representations</module>
<module>sirius-components-events</module>
<module>sirius-components-core</module>
<module>sirius-components-core-graphql</module>
<module>sirius-components-collaborative</module>
<module>sirius-components-graphql-api</module>
</modules>
Expand Down
4 changes: 4 additions & 0 deletions packages/core/backend/sirius-components-collaborative/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
</distributionManagement>

<dependencies>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
Expand Down
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.components.collaborative.dto;

import java.util.Objects;
import java.util.UUID;

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

/**
* The input for the get omnibox commands query.
*
* @author gcoutable
*/
public record GetOmniboxCommandsInput(UUID id, String query) implements IInput {
public GetOmniboxCommandsInput {
Objects.requireNonNull(id);
Objects.requireNonNull(query);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

package org.eclipse.sirius.components.collaborative.dto;

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

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

/**
* The payload for the get omnibox commands query.
*
* @author gcoutable
*/
public record GetOmniboxCommandsPayload(UUID id, List<OmniboxCommand> omniboxCommands) implements IPayload {
public GetOmniboxCommandsPayload {
Objects.requireNonNull(id);
Objects.requireNonNull(omniboxCommands);
}
}
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.components.collaborative.dto;

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

/**
* The omnibox command.
*
* @author gcoutable
*/
public record OmniboxCommand(UUID id, String label, String kind, List<String> iconURL, String description) {
public OmniboxCommand {
Objects.requireNonNull(id);
Objects.requireNonNull(label);
Objects.requireNonNull(kind);
Objects.requireNonNull(iconURL);
Objects.requireNonNull(description);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

package org.eclipse.sirius.components.collaborative.dto;

import java.util.UUID;

/**
* The omnibox context entry.
*
* @author gcoutable
*/
public record OmniboxContextEntry(UUID id, String label, String kind) {
}
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.web.application.dto;
package org.eclipse.sirius.components.collaborative.dto;

import graphql.relay.ConnectionCursor;
import graphql.relay.PageInfo;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

package org.eclipse.sirius.components.collaborative.handlers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

import org.eclipse.sirius.components.collaborative.api.ChangeDescription;
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler;
import org.eclipse.sirius.components.collaborative.api.IQueryService;
import org.eclipse.sirius.components.collaborative.api.Monitoring;
import org.eclipse.sirius.components.collaborative.dto.CreateChildInput;
import org.eclipse.sirius.components.collaborative.dto.GetOmniboxCommandsInput;
import org.eclipse.sirius.components.collaborative.dto.GetOmniboxCommandsPayload;
import org.eclipse.sirius.components.collaborative.dto.OmniboxCommand;
import org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectsInput;
import org.eclipse.sirius.components.collaborative.dto.QueryBasedObjectsSuccessPayload;
import org.eclipse.sirius.components.collaborative.messages.ICollaborativeMessageService;
import org.eclipse.sirius.components.core.api.ErrorPayload;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.representations.Message;
import org.eclipse.sirius.components.representations.MessageLevel;
import org.springframework.stereotype.Service;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import reactor.core.publisher.Sinks;

/**
* The event handler to retrieve omnibox commands in the context of an editing context.
*
* @author gcoutable
*/
@Service
public class GetOmniboxCommandsEventHandler implements IEditingContextEventHandler {

private final IObjectService objectService;

private final ICollaborativeMessageService messageService;

private final IQueryService queryService;

private final Counter counter;

public GetOmniboxCommandsEventHandler(IObjectService objectService, ICollaborativeMessageService messageService, IQueryService queryService, MeterRegistry meterRegistry) {
this.objectService = Objects.requireNonNull(objectService);
this.messageService = Objects.requireNonNull(messageService);
this.queryService = Objects.requireNonNull(queryService);

this.counter = Counter.builder(Monitoring.EVENT_HANDLER)
.tag(Monitoring.NAME, this.getClass().getSimpleName())
.register(meterRegistry);
}

@Override
public boolean canHandle(IEditingContext editingContext, IInput input) {
return input instanceof GetOmniboxCommandsInput;
}

@Override
public void handle(Sinks.One<IPayload> payloadSink, Sinks.Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
this.counter.increment();

List<Message> messages = List.of(new Message(this.messageService.invalidInput(input.getClass().getSimpleName(), CreateChildInput.class.getSimpleName()),
MessageLevel.ERROR));
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
IPayload payload = null;

if (input instanceof GetOmniboxCommandsInput getOmniboxCommandsInput) {
List<OmniboxCommand> omniboxCommands = new ArrayList<>();

var queryBasedObjectsInput = new QueryBasedObjectsInput(UUID.randomUUID(), "aql:editingContext.allContents()->select(e | e.name.contains('" + getOmniboxCommandsInput.query() + "'))", Map.of("editingContext", editingContext));
var objectsPayload = this.queryService.execute(editingContext, queryBasedObjectsInput);

if (objectsPayload instanceof QueryBasedObjectsSuccessPayload queryBasedObjectsSuccessPayload) {
queryBasedObjectsSuccessPayload.result().forEach(object -> {
var id = this.objectService.getId(object);
var label = this.objectService.getLabel(object);
var kind = this.objectService.getKind(object);
var iconURL = this.objectService.getImagePath(object);
omniboxCommands.add(new OmniboxCommand(UUID.fromString(id), label, kind, iconURL, ""));
});

payload = new GetOmniboxCommandsPayload(input.id(), omniboxCommands);
}
}

if (payload == null) {
payload = new ErrorPayload(input.id(), messages);
}

payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extend type Viewer {
omniboxCommands(contextEntries: [OmniboxContextEntry!]!, query: String!): OmniboxCommandsConnection!
}
input OmniboxContextEntry {
id: ID!
label: String!
kind: String!
}

type OmniboxCommandsConnection {
edges: [OmniboxCommandsEdge!]!
pageInfo: PageInfo!
}

type OmniboxCommandsEdge {
node: OmniboxCommand!
}

type OmniboxCommand {
id: ID!
label: String!
kind: String!
iconURL: [String!]!
description: String!
}
10 changes: 10 additions & 0 deletions packages/core/backend/sirius-components-core-graphql/.checkstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Sirius" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
<filter name="FilesFromPackage" enabled="true">
<filter-data value="src/main/resources"/>
</filter>
</fileset-config>
57 changes: 57 additions & 0 deletions packages/core/backend/sirius-components-core-graphql/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Loading

0 comments on commit 6c226a3

Please sign in to comment.