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.
[1146] Add support for EditingContext actions
Bug: eclipse-sirius#1146 Signed-off-by: Raphaël Pagé <raphael.page@obeo.fr>
- Loading branch information
1 parent
9a96908
commit 45a4c76
Showing
13 changed files
with
666 additions
and
13 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...in/java/org/eclipse/sirius/components/collaborative/api/IEditingContextActionHandler.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) 2022 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.api; | ||
|
||
import org.eclipse.sirius.components.collaborative.dto.InvokeEditingContextActionInput; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.representations.IStatus; | ||
|
||
/** | ||
* Process the given {@link InvokeEditingContextActionInput}. | ||
* | ||
* @author rpage | ||
*/ | ||
public interface IEditingContextActionHandler { | ||
boolean canHandle(IEditingContext editingContext, String actionId); | ||
|
||
IStatus handle(IEditingContext editingContext, String actionId); | ||
} |
27 changes: 27 additions & 0 deletions
27
...n/java/org/eclipse/sirius/components/collaborative/api/IEditingContextActionProvider.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) 2022 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.api; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.sirius.components.collaborative.dto.EditingContextAction; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
|
||
/** | ||
* Used to provide the EditingContext Actions of an {@link IEditingContext}. | ||
* | ||
* @author rpage | ||
*/ | ||
public interface IEditingContextActionProvider { | ||
List<EditingContextAction> getEditingContextAction(IEditingContext editingContext); | ||
} |
46 changes: 46 additions & 0 deletions
46
...e/src/main/java/org/eclipse/sirius/components/collaborative/dto/EditingContextAction.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,46 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.text.MessageFormat; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Details of an EditingContext Action. | ||
* | ||
* @author rpage | ||
*/ | ||
public class EditingContextAction { | ||
private final String id; | ||
|
||
private final String label; | ||
|
||
public EditingContextAction(String id, String label) { | ||
this.id = Objects.requireNonNull(id); | ||
this.label = Objects.requireNonNull(label); | ||
} | ||
|
||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
public String getLabel() { | ||
return this.label; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{'id: {1}, label: {2}'}'"; //$NON-NLS-1$ | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.label); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...n/java/org/eclipse/sirius/components/collaborative/dto/GetEditingContextActionsInput.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,50 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.text.MessageFormat; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IInput; | ||
|
||
/** | ||
* The input object for this query. | ||
* | ||
* @author rpage | ||
*/ | ||
public final class GetEditingContextActionsInput implements IInput { | ||
private final UUID id; | ||
|
||
private final String editingContextId; | ||
|
||
public GetEditingContextActionsInput(UUID id, String editingContextId) { | ||
this.id = Objects.requireNonNull(id); | ||
this.editingContextId = Objects.requireNonNull(editingContextId); | ||
} | ||
|
||
@Override | ||
public UUID getId() { | ||
return this.id; | ||
} | ||
|
||
public String getEditingContextId() { | ||
return this.editingContextId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{'id: {1}, editingContextId: {2}'}'"; //$NON-NLS-1$ | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.editingContextId); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...g/eclipse/sirius/components/collaborative/dto/GetEditingContextActionsSuccessPayload.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,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.text.MessageFormat; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IPayload; | ||
|
||
/** | ||
* The payload object for this query. | ||
* | ||
* @author rpage | ||
*/ | ||
public final class GetEditingContextActionsSuccessPayload implements IPayload { | ||
private final UUID id; | ||
|
||
private final List<EditingContextAction> editingContextActions; | ||
|
||
public GetEditingContextActionsSuccessPayload(UUID id, List<EditingContextAction> editingContextActions) { | ||
this.id = Objects.requireNonNull(id); | ||
this.editingContextActions = Objects.requireNonNull(editingContextActions); | ||
} | ||
|
||
@Override | ||
public UUID getId() { | ||
return this.id; | ||
} | ||
|
||
public List<EditingContextAction> getEditingContextActions() { | ||
return this.editingContextActions; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{'id: {1}, editingContextActions: {2}'}'"; //$NON-NLS-1$ | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.editingContextActions); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...java/org/eclipse/sirius/components/collaborative/dto/InvokeEditingContextActionInput.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,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.text.MessageFormat; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.collaborative.handlers.InvokeEditingContextActionEventHandler; | ||
import org.eclipse.sirius.components.core.api.IInput; | ||
|
||
/** | ||
* The input object of the {@link InvokeEditingContextActionEventHandler}. | ||
* | ||
* @author rpage | ||
*/ | ||
public final class InvokeEditingContextActionInput implements IInput { | ||
private UUID id; | ||
|
||
private String editingContextId; | ||
|
||
private String actionId; | ||
|
||
@Override | ||
public UUID getId() { | ||
return this.id; | ||
} | ||
|
||
public String getEditingContextId() { | ||
return this.editingContextId; | ||
} | ||
|
||
public String getActionId() { | ||
return this.actionId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{'id: {1}, editingContextId: {2}, actionId: {3}'}'"; //$NON-NLS-1$ | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.editingContextId, this.actionId); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...eclipse/sirius/components/collaborative/dto/InvokeEditingContextActionSuccessPayload.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,43 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.text.MessageFormat; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.core.api.IPayload; | ||
|
||
/** | ||
* The payload of the Invoke Editing Context Action mutation. | ||
* | ||
* @author rpage | ||
*/ | ||
public final class InvokeEditingContextActionSuccessPayload implements IPayload { | ||
private final UUID id; | ||
|
||
public InvokeEditingContextActionSuccessPayload(UUID id) { | ||
this.id = Objects.requireNonNull(id); | ||
} | ||
|
||
@Override | ||
public UUID getId() { | ||
return this.id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{'id: {1}'}'"; //$NON-NLS-1$ | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...clipse/sirius/components/collaborative/handlers/GetEditingContextActionsEventHandler.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,94 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.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.ChangeKind; | ||
import org.eclipse.sirius.components.collaborative.api.IEditingContextActionProvider; | ||
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler; | ||
import org.eclipse.sirius.components.collaborative.api.Monitoring; | ||
import org.eclipse.sirius.components.collaborative.dto.EditingContextAction; | ||
import org.eclipse.sirius.components.collaborative.dto.GetEditingContextActionsInput; | ||
import org.eclipse.sirius.components.collaborative.dto.GetEditingContextActionsSuccessPayload; | ||
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.IPayload; | ||
import org.springframework.stereotype.Service; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import reactor.core.publisher.Sinks.Many; | ||
import reactor.core.publisher.Sinks.One; | ||
|
||
/** | ||
* Handler used to access to the EditingContext Actions. | ||
* | ||
* @author rpage | ||
*/ | ||
@Service | ||
public class GetEditingContextActionsEventHandler implements IEditingContextEventHandler { | ||
private final ICollaborativeMessageService messageService; | ||
|
||
private final Counter counter; | ||
|
||
private final List<IEditingContextActionProvider> editingContextActionProviders; | ||
|
||
public GetEditingContextActionsEventHandler(ICollaborativeMessageService messageService, List<IEditingContextActionProvider> editingContextActionProviders, MeterRegistry meterRegistry) { | ||
this.messageService = Objects.requireNonNull(messageService); | ||
this.editingContextActionProviders = Objects.requireNonNull(editingContextActionProviders); | ||
|
||
// @formatter:off | ||
this.counter = Counter.builder(Monitoring.EVENT_HANDLER) | ||
.tag(Monitoring.NAME, this.getClass().getSimpleName()) | ||
.register(meterRegistry); | ||
// @formatter:on | ||
} | ||
|
||
@Override | ||
public boolean canHandle(IEditingContext editingContext, IInput input) { | ||
return input instanceof GetEditingContextActionsInput; | ||
} | ||
|
||
@Override | ||
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) { | ||
this.counter.increment(); | ||
|
||
String message = this.messageService.invalidInput(input.getClass().getSimpleName(), GetEditingContextActionsInput.class.getSimpleName()); | ||
IPayload payload = new ErrorPayload(input.getId(), message); | ||
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input); | ||
|
||
if (input instanceof GetEditingContextActionsInput) { | ||
GetEditingContextActionsInput editingContextActionsInput = (GetEditingContextActionsInput) input; | ||
|
||
// @formatter:off | ||
List<EditingContextAction> editingContextActions = this.editingContextActionProviders.stream() | ||
.flatMap(provider -> provider.getEditingContextAction(editingContext).stream()) | ||
.collect(Collectors.toList()); | ||
// @formatter:on | ||
|
||
editingContextActions.sort((a1, a2) -> a1.getLabel().compareTo(a2.getLabel())); | ||
|
||
payload = new GetEditingContextActionsSuccessPayload(editingContextActionsInput.getId(), editingContextActions); | ||
changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input); | ||
} | ||
|
||
payloadSink.tryEmitValue(payload); | ||
changeDescriptionSink.tryEmitNext(changeDescription); | ||
} | ||
} |
Oops, something went wrong.