Skip to content

Commit

Permalink
[4425] Add new table cell widget description for textarea
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#4425
Signed-off-by: Jerome Gout <[email protected]>
  • Loading branch information
jerome-obeo committed Jan 17, 2025
1 parent d6d6413 commit a82573d
Show file tree
Hide file tree
Showing 47 changed files with 1,546 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ It can be activated using `sirius.web.graphql.tracing=true` since it is not enab
Some additional log has also been contributed on the frontend in order to view more easily the order and time of the GraphQL requests and responses.
- https://github.com/eclipse-sirius/sirius-web/issues/4430[#4430] [diagram] Add the PNG export of a diagram.
- https://github.com/eclipse-sirius/sirius-web/issues/4346[#4346] [query] The current selection is now available using both the variables `selection: Sequence{Object}` for the full selection and `self: Object` for the first selected object.

- https://github.com/eclipse-sirius/sirius-web/issues/4425[#4425] [table] Add new table cell widget description for textarea

=== Improvements

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.eclipse.sirius.components.tables.elements.IconLabelCellElementProps;
import org.eclipse.sirius.components.tables.elements.MultiSelectCellElementProps;
import org.eclipse.sirius.components.tables.elements.SelectCellElementProps;
import org.eclipse.sirius.components.tables.elements.TextareaCellElementProps;
import org.eclipse.sirius.components.tables.elements.TextfieldCellElementProps;

/**
Expand Down Expand Up @@ -59,6 +60,10 @@ private String getCellType(VariableManager variableManager) {
type = SelectCellElementProps.TYPE;
}
}
// description column should be multiline
if ("description".equals(eStructuralFeature.getName())) {
type = TextareaCellElementProps.TYPE;
}
if (type.isEmpty()) {
type = TextfieldCellElementProps.TYPE;
}
Expand All @@ -70,6 +75,10 @@ public Predicate<VariableManager> isTextfieldCell() {
return (variableManager) -> this.getCellType(variableManager).equals(TextfieldCellElementProps.TYPE);
}

public Predicate<VariableManager> isTextareaCell() {
return (variableManager) -> this.getCellType(variableManager).equals(TextareaCellElementProps.TYPE);
}

public Predicate<VariableManager> isCheckboxCell() {
return (variableManager) -> this.getCellType(variableManager).equals(CheckboxCellElementProps.TYPE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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
Expand Down Expand Up @@ -44,6 +44,7 @@
import org.eclipse.sirius.components.tables.descriptions.PaginatedData;
import org.eclipse.sirius.components.tables.descriptions.SelectCellDescription;
import org.eclipse.sirius.components.tables.descriptions.TableDescription;
import org.eclipse.sirius.components.tables.descriptions.TextareaCellDescription;
import org.eclipse.sirius.components.tables.descriptions.TextfieldCellDescription;
import org.eclipse.sirius.components.tables.renderer.TableRenderer;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -202,6 +203,13 @@ private List<ICellDescription> getCellDescriptions() {
.cellValueProvider(new CellStringValueProvider(this.identityService))
.build());

cellDescriptions.add(TextareaCellDescription.newTextareaCellDescription("textareaCells")
.canCreatePredicate(new CellTypePredicate().isTextareaCell())
.targetObjectIdProvider(new TableTargetObjectIdProvider(this.identityService))
.targetObjectKindProvider(new TableTargetObjectKindProvider(this.identityService))
.cellValueProvider(new CellStringValueProvider(this.identityService))
.build());

cellDescriptions.add(SelectCellDescription.newSelectCellDescription("selectCells")
.canCreatePredicate(new CellTypePredicate().isSelectCell())
.targetObjectIdProvider(new TableTargetObjectIdProvider(this.identityService))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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
Expand Down Expand Up @@ -39,6 +39,7 @@
import org.eclipse.sirius.components.tables.descriptions.PaginatedData;
import org.eclipse.sirius.components.tables.descriptions.SelectCellDescription;
import org.eclipse.sirius.components.tables.descriptions.TableDescription;
import org.eclipse.sirius.components.tables.descriptions.TextareaCellDescription;
import org.eclipse.sirius.components.tables.descriptions.TextfieldCellDescription;
import org.eclipse.sirius.components.tables.renderer.TableRenderer;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -202,6 +203,12 @@ private List<ICellDescription> getCellDescriptions() {
.targetObjectKindProvider(new TableTargetObjectKindProvider(this.identityService))
.cellValueProvider(new CellStringValueProvider(this.identityService))
.build());
cellDescriptions.add(TextareaCellDescription.newTextareaCellDescription("textareaCells")
.canCreatePredicate(new CellTypePredicate().isTextareaCell())
.targetObjectIdProvider(new TableTargetObjectIdProvider(this.identityService))
.targetObjectKindProvider(new TableTargetObjectKindProvider(this.identityService))
.cellValueProvider(new CellStringValueProvider(this.identityService))
.build());
cellDescriptions.add(CheckboxCellDescription.newCheckboxCellDescription("checkboxCells")
.canCreatePredicate(new CellTypePredicate().isCheckboxCell())
.targetObjectIdProvider(new TableTargetObjectIdProvider(this.identityService))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput;
import org.eclipse.sirius.components.collaborative.tables.TableRefreshedEventPayload;
import org.eclipse.sirius.components.tables.TextareaCell;
import org.eclipse.sirius.components.tables.TextfieldCell;
import org.eclipse.sirius.web.AbstractIntegrationTests;
import org.eclipse.sirius.web.data.PapayaIdentifiers;
Expand All @@ -46,7 +47,7 @@
*/
@Transactional
@SuppressWarnings("checkstyle:MultipleStringLiterals")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"sirius.web.test.enabled=studio"})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "sirius.web.test.enabled=studio" })
public class PapayaViewTableControllerIntegrationTests extends AbstractIntegrationTests {

@Autowired
Expand Down Expand Up @@ -87,12 +88,15 @@ public void givenSimpleViewTableDescriptionWhenSubscriptionIsCreatedThenTableIsR
.map(TableRefreshedEventPayload::table)
.ifPresentOrElse(table -> {
assertThat(table).isNotNull();
assertThat(table.getColumns()).hasSize(1);
assertThat(table.getColumns()).hasSize(2);
assertThat(table.getColumns().get(0).getHeaderLabel()).isEqualTo("Name");
assertThat(table.getColumns().get(0).getHeaderIndexLabel()).isEqualTo("0");
assertThat(table.getColumns().get(1).getHeaderLabel()).isEqualTo("Description");
assertThat(table.getColumns().get(1).getHeaderIndexLabel()).isEqualTo("1");
assertThat(table.getLines()).hasSize(2);
assertThat(table.getLines().get(0).getHeaderIndexLabel()).isEqualTo("0");
assertThat(table.getLines().get(0).getCells().get(0)).isInstanceOf(TextfieldCell.class);
assertThat(table.getLines().get(0).getCells().get(1)).isInstanceOf(TextareaCell.class);
assertThat(((TextfieldCell) table.getLines().get(0).getCells().get(0)).getValue()).isEqualTo("Success");
assertThat(table.getLines().get(1).getHeaderIndexLabel()).isEqualTo("1");
assertThat(table.getLines().get(1).getCells().get(0)).isInstanceOf(TextfieldCell.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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
Expand Down Expand Up @@ -61,6 +61,7 @@
import org.eclipse.sirius.components.tables.descriptions.PaginatedData;
import org.eclipse.sirius.components.tables.descriptions.SelectCellDescription;
import org.eclipse.sirius.components.tables.descriptions.TableDescription;
import org.eclipse.sirius.components.tables.descriptions.TextareaCellDescription;
import org.eclipse.sirius.components.tables.descriptions.TextfieldCellDescription;
import org.eclipse.sirius.web.papaya.representations.table.CellTypePredicate;
import org.eclipse.sirius.web.papaya.representations.table.ColumnTargetObjectIdProvider;
Expand Down Expand Up @@ -175,6 +176,12 @@ private List<ICellDescription> getCellDescriptions() {
.targetObjectKindProvider(variableManager -> "")
.cellValueProvider(this.getCellStringValueProvider())
.build());
cellDescriptions.add(TextareaCellDescription.newTextareaCellDescription("textareaCells")
.canCreatePredicate(new CellTypePredicate().isTextareaCell())
.targetObjectIdProvider(variableManager -> "")
.targetObjectKindProvider(variableManager -> "")
.cellValueProvider(this.getCellStringValueProvider())
.build());
cellDescriptions.add(CheckboxCellDescription.newCheckboxCellDescription("checkboxCells")
.canCreatePredicate(new CellTypePredicate().isCheckboxCell())
.targetObjectIdProvider(vm -> "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 CEA LIST.
* Copyright (c) 2024, 2025 CEA LIST.
* 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
Expand Down Expand Up @@ -83,8 +83,8 @@ private View createView() {
private TableDescription createTableDescription() {

var columnDescription = new TableBuilders().newColumnDescription()
.semanticCandidatesExpression("aql:'Name'")
.headerLabelExpression("Name")
.semanticCandidatesExpression("aql:Sequence{'Name', 'Description'}")
.headerLabelExpression("aql:self")
.headerIndexLabelExpression("aql:columnIndex")
.build();

Expand All @@ -93,18 +93,24 @@ private TableDescription createTableDescription() {
.headerIndexLabelExpression("aql:rowIndex")
.build();

var cellDescription = new TableBuilders().newCellDescription()
.preconditionExpression("aql:true")
var nameCellDescription = new TableBuilders().newCellDescription()
.preconditionExpression("aql:columnTargetObject.equals('Name')")
.valueExpression("aql:self.name")
.cellWidgetDescription(new TableBuilders().newCellTextfieldWidgetDescription().build())
.build();

var descriptionCellDescription = new TableBuilders().newCellDescription()
.preconditionExpression("aql:columnTargetObject.equals('Description')")
.valueExpression("aql:self.description")
.cellWidgetDescription(new TableBuilders().newCellTextareaWidgetDescription().build())
.build();

this.tableDescription = new TableBuilders().newTableDescription()
.domainType("papaya::Package")
.titleExpression("View Package Table")
.columnDescriptions(columnDescription)
.rowDescription(rowDescription)
.cellDescriptions(cellDescription)
.cellDescriptions(nameCellDescription, descriptionCellDescription)
.useStripedRowsExpression("aql:false")
.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2025 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.tables.dto;

import java.util.UUID;

/**
* The input object for the Textarea-based cell edition mutation.
*
* @author Jerome Gout
*/
public record EditTextareaCellInput(
UUID id,
String editingContextId,
String representationId,
String tableId,
UUID cellId,
String newValue) implements IEditCellInput {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.sirius.components.collaborative.tables.api.ITableEventHandler;
import org.eclipse.sirius.components.collaborative.tables.api.ITableInput;
import org.eclipse.sirius.components.collaborative.tables.dto.ChangeGlobalFilterValueInput;
import org.eclipse.sirius.components.collaborative.tables.dto.EditTextfieldCellInput;
import org.eclipse.sirius.components.collaborative.tables.messages.ICollaborativeTableMessageService;
import org.eclipse.sirius.components.core.api.ErrorPayload;
import org.eclipse.sirius.components.core.api.IEditingContext;
Expand Down Expand Up @@ -64,7 +63,7 @@ public void handle(Sinks.One<IPayload> payloadSink, Sinks.Many<ChangeDescription
this.counter.increment();

ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, tableInput.representationId(), tableInput);
String message = this.messageService.invalidInput(tableInput.getClass().getSimpleName(), EditTextfieldCellInput.class.getSimpleName());
String message = this.messageService.invalidInput(tableInput.getClass().getSimpleName(), ChangeGlobalFilterValueInput.class.getSimpleName());
IPayload payload = new ErrorPayload(tableInput.id(), message);

if (tableInput instanceof ChangeGlobalFilterValueInput changeGlobalFilterValueInput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.sirius.components.collaborative.tables.dto.EditCheckboxCellInput;
import org.eclipse.sirius.components.collaborative.tables.dto.EditMultiSelectCellInput;
import org.eclipse.sirius.components.collaborative.tables.dto.EditSelectCellInput;
import org.eclipse.sirius.components.collaborative.tables.dto.EditTextareaCellInput;
import org.eclipse.sirius.components.collaborative.tables.dto.EditTextfieldCellInput;
import org.eclipse.sirius.components.collaborative.tables.dto.IEditCellInput;
import org.eclipse.sirius.components.collaborative.tables.messages.ICollaborativeTableMessageService;
Expand Down Expand Up @@ -125,6 +126,9 @@ private Object getNewValue(IEditCellInput editCellInput) {
if (editCellInput instanceof EditTextfieldCellInput editTextfieldCellInput) {
newValue = editTextfieldCellInput.newValue();
}
if (editCellInput instanceof EditTextareaCellInput editTextareaCellInput) {
newValue = editTextareaCellInput.newValue();
}
if (editCellInput instanceof EditCheckboxCellInput editCheckboxCellInput) {
newValue = editCheckboxCellInput.newValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ type TextfieldCell implements Cell {
value: String!
}

type TextareaCell implements Cell {
id: ID!
columnId: ID!
targetObjectId: ID!
targetObjectKind: String!
value: String!
}

type SelectCell implements Cell {
id: ID!
columnId: ID!
Expand Down Expand Up @@ -139,6 +147,7 @@ extend type Mutation {
editSelectCell(input: EditSelectCellInput!): EditSelectCellPayload!
editMultiSelectCell(input: EditMultiSelectCellInput!): EditMultiSelectCellPayload!
editTextfieldCell(input: EditTextfieldCellInput!): EditTextfieldCellPayload!
editTextareaCell(input: EditTextareaCellInput!): EditTextareaCellPayload!
resizeTableColumn(input: ResizeTableColumnInput!): ResizeTableColumnPayload!
changeTableColumnVisibility(input: ChangeTableColumnVisibilityInput!): ChangeTableColumnVisibilityPayload!
resizeTableRow(input: ResizeTableRowInput!): ResizeTableRowPayload!
Expand Down Expand Up @@ -191,6 +200,17 @@ input EditTextfieldCellInput {

union EditTextfieldCellPayload = ErrorPayload | SuccessPayload

input EditTextareaCellInput {
id: ID!
editingContextId: ID!
representationId: ID!
tableId: ID!
cellId: ID!
newValue: String!
}

union EditTextareaCellPayload = ErrorPayload | SuccessPayload

input ResizeTableColumnInput {
id: ID!
editingContextId: ID!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2025 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.tables.graphql.datafetchers.mutation;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Objects;
import java.util.concurrent.CompletableFuture;

import org.eclipse.sirius.components.annotations.spring.graphql.MutationDataFetcher;
import org.eclipse.sirius.components.collaborative.tables.dto.EditTextareaCellInput;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.IEditingContextDispatcher;
import org.eclipse.sirius.components.graphql.api.IExceptionWrapper;

import graphql.schema.DataFetchingEnvironment;

/**
* The data fetcher used to edit a Textarea-based table cell.
*
* @author Jerome Gout
*/
@MutationDataFetcher(type = "Mutation", field = "editTextareaCell")
public class MutationEditTextareaCellDataFetcher implements IDataFetcherWithFieldCoordinates<CompletableFuture<IPayload>> {

private static final String INPUT_ARGUMENT = "input";

private final ObjectMapper objectMapper;

private final IExceptionWrapper exceptionWrapper;

private final IEditingContextDispatcher editingContextDispatcher;

public MutationEditTextareaCellDataFetcher(ObjectMapper objectMapper, IExceptionWrapper exceptionWrapper, IEditingContextDispatcher editingContextDispatcher) {
this.objectMapper = Objects.requireNonNull(objectMapper);
this.exceptionWrapper = Objects.requireNonNull(exceptionWrapper);
this.editingContextDispatcher = Objects.requireNonNull(editingContextDispatcher);
}

@Override
public CompletableFuture<IPayload> get(DataFetchingEnvironment environment) throws Exception {
Object argument = environment.getArgument(INPUT_ARGUMENT);
var input = this.objectMapper.convertValue(argument, EditTextareaCellInput.class);

return this.exceptionWrapper.wrapMono(() -> this.editingContextDispatcher.dispatchMutation(input.editingContextId(), input), input).toFuture();
}
}
Loading

0 comments on commit a82573d

Please sign in to comment.