Skip to content

Commit

Permalink
[4556] Add a flag enableSubRows to control the sub rows support
Browse files Browse the repository at this point in the history
Bug: #4556
Signed-off-by: Jerome Gout <[email protected]>
  • Loading branch information
jerome-obeo committed Feb 25, 2025
1 parent 46b1462 commit 9f7401a
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,46 @@ public AbstractWidgetDescription caseTableWidgetDescription(org.eclipse.sirius.c
VariableManager childVariableManager = variableManager.createChild();
childVariableManager.put(VariableManager.SELF, viewTableDescription);
String id = formDescriptionEditorDescription.getTargetObjectIdProvider().apply(childVariableManager);
var lineDescription = LineDescription.newLineDescription(UUID.randomUUID().toString())
.targetObjectIdProvider(vm -> "")
.targetObjectKindProvider(vm -> "")
.semanticElementsProvider(vm -> new PaginatedData(List.of(), false, false, 0))
.headerLabelProvider(vm -> "")
.headerIconURLsProvider(vm -> List.of())
.headerIndexLabelProvider(vm -> "")
.isResizablePredicate(vm -> false)
.initialHeightProvider(vm -> -1)
.depthLevelProvider(vm -> 0)
.build();
var tableDescription = TableDescription.newTableDescription(UUID.randomUUID().toString())
.label("")
.labelProvider(vm -> TableWidgetPreviewConverterProvider.this.getWidgetLabel(viewTableDescription, "Table"))
.canCreatePredicate(vm -> true)
.targetObjectIdProvider(vm -> "")
.targetObjectKindProvider(vm -> "")
.isStripeRowPredicate(vm -> false)
.iconURLsProvider(vm -> List.of())
.columnDescriptions(List.of())
.cellDescriptions(List.of())
.lineDescription(lineDescription)
.build();
return TableWidgetDescription.newTableWidgetDescription(UUID.randomUUID().toString())
.idProvider(vm -> id)
.targetObjectIdProvider(vm -> "")
.labelProvider(vm -> TableWidgetPreviewConverterProvider.this.getWidgetLabel(viewTableDescription, "Table"))
.diagnosticsProvider(vm -> List.of())
.kindProvider(object -> "")
.messageProvider(object -> "")
.helpTextProvider(vm -> "")
.tableDescription(tableDescription)
.build();
return TableWidgetPreviewConverterProvider.this.getTableWidgetDescription(viewTableDescription, id);
}
};
}

private TableWidgetDescription getTableWidgetDescription(org.eclipse.sirius.components.view.widget.tablewidget.TableWidgetDescription viewTableDescription, String id) {
var lineDescription = LineDescription.newLineDescription(UUID.randomUUID().toString())
.targetObjectIdProvider(vm -> "")
.targetObjectKindProvider(vm -> "")
.semanticElementsProvider(vm -> new PaginatedData(List.of(), false, false, 0))
.headerLabelProvider(vm -> "")
.headerIconURLsProvider(vm -> List.of())
.headerIndexLabelProvider(vm -> "")
.isResizablePredicate(vm -> false)
.initialHeightProvider(vm -> -1)
.depthLevelProvider(vm -> 0)
.build();
var tableDescription = TableDescription.newTableDescription(UUID.randomUUID().toString())
.label("")
.labelProvider(vm -> this.getWidgetLabel(viewTableDescription, "Table"))
.canCreatePredicate(vm -> true)
.targetObjectIdProvider(vm -> "")
.targetObjectKindProvider(vm -> "")
.isStripeRowPredicate(vm -> false)
.iconURLsProvider(vm -> List.of())
.columnDescriptions(List.of())
.cellDescriptions(List.of())
.lineDescription(lineDescription)
.build();
return TableWidgetDescription.newTableWidgetDescription(UUID.randomUUID().toString())
.idProvider(vm -> id)
.targetObjectIdProvider(vm -> "")
.labelProvider(vm -> this.getWidgetLabel(viewTableDescription, "Table"))
.diagnosticsProvider(vm -> List.of())
.kindProvider(object -> "")
.messageProvider(object -> "")
.helpTextProvider(vm -> "")
.tableDescription(tableDescription)
.build();
}

public String getWidgetLabel(org.eclipse.sirius.components.view.form.WidgetDescription widgetDescription, String defaultLabel) {
String widgetLabel = defaultLabel;
Expand All @@ -92,5 +95,4 @@ public String getWidgetLabel(org.eclipse.sirius.components.view.form.WidgetDescr
}
return widgetLabel;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ export const widgetFields = `
totalRowCount
}
stripeRow
enableSubRows
globalFilter
columnFilters {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public List<IRepresentationDescription> getRepresentationDescriptions(IEditingCo
.cellDescriptions(this.getCellDescriptions())
.iconURLsProvider(variableManager -> List.of("/papaya-representations/package-table.svg"))
.isStripeRowPredicate(variableManager -> true)
.enableSubRows(true)
.build();

return List.of(tableDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public List<IRepresentationDescription> getRepresentationDescriptions(IEditingCo
.cellDescriptions(this.getCellDescriptions())
.iconURLsProvider(variableManager -> List.of("/papaya-representations/project-table.svg"))
.isStripeRowPredicate(variableManager -> false)
.enableSubRows(false)
.build();

return List.of(tableDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private TableWidgetDescription getTableWidgetDescription() {
.cellDescriptions(this.getCellDescriptions())
.iconURLsProvider(variableManager -> List.of())
.isStripeRowPredicate(variableManager -> false)
.enableSubRows(false)
.build();

return TableWidgetDescription.newTableWidgetDescription("tasksTableWidgetId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Table implements Representation {
paginationData: PaginationData
globalFilter: String
columnFilters: [ColumnFilter!]!
enableSubRows: Boolean!
}

type Column {
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 @@ -51,10 +51,16 @@ public final class Table implements IRepresentation {

private List<ColumnFilter> columnFilters;

private boolean enableSubRows;

private Table() {
// Prevent instantiation
}

public static Builder newTable(String id) {
return new Builder(id);
}

@Override
public String getId() {
return this.id;
Expand Down Expand Up @@ -103,8 +109,8 @@ public List<ColumnFilter> getColumnFilters() {
return this.columnFilters;
}

public static Builder newTable(String id) {
return new Builder(id);
public boolean isEnableSubRows() {
return this.enableSubRows;
}

@Override
Expand Down Expand Up @@ -143,6 +149,8 @@ public static final class Builder {

private List<ColumnFilter> columnFilters;

private boolean enableSubRows;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand Down Expand Up @@ -192,6 +200,11 @@ public Builder columnFilters(List<ColumnFilter> columnFilters) {
return this;
}

public Builder enableSubRows(boolean enableSubRows) {
this.enableSubRows = enableSubRows;
return this;
}

public Table build() {
Table table = new Table();
table.id = Objects.requireNonNull(this.id);
Expand All @@ -205,6 +218,7 @@ public Table build() {
table.paginationData = Objects.requireNonNull(this.paginationData);
table.globalFilter = Objects.requireNonNull(this.globalFilter);
table.columnFilters = Objects.requireNonNull(this.columnFilters);
table.enableSubRows = this.enableSubRows;
return table;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public Element render() {
.paginationData(new PaginationData(paginatedData.hasPreviousPage(), paginatedData.hasNextPage(), paginatedData.totalRowCount()))
.globalFilter(this.props.globalFilter())
.columnFilters(columnsFilters)
.enableSubRows(tableDescription.isEnableSubRows())
.build();

return new Element(TableElementProps.TYPE, tableElementProps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ public final class TableDescription implements IRepresentationDescription {

private Function<VariableManager, List<String>> iconURLsProvider;

private boolean enableSubRows;

private TableDescription() {
// Prevent instantiation
}

public static Builder newTableDescription(String id) {
return new Builder(id);
}

public String getId() {
return this.id;
}
Expand Down Expand Up @@ -110,8 +116,8 @@ public Function<VariableManager, List<String>> getIconURLsProvider() {
return this.iconURLsProvider;
}

public static Builder newTableDescription(String id) {
return new Builder(id);
public boolean isEnableSubRows() {
return this.enableSubRows;
}

@Override
Expand Down Expand Up @@ -150,6 +156,8 @@ public static final class Builder {

private Function<VariableManager, List<String>> iconURLsProvider;

private boolean enableSubRows;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand Down Expand Up @@ -200,7 +208,12 @@ public Builder cellDescriptions(List<ICellDescription> cellDescriptions) {
}

public Builder iconURLsProvider(Function<VariableManager, List<String>> iconURLsProvider) {
this.iconURLsProvider = Objects.requireNonNull(iconURLsProvider);
this.iconURLsProvider = Objects.requireNonNull(iconURLsProvider);
return this;
}

public Builder enableSubRows(boolean enableSubRows) {
this.enableSubRows = enableSubRows;
return this;
}

Expand All @@ -217,6 +230,7 @@ public TableDescription build() {
tableDescription.columnDescriptions = Objects.requireNonNull(this.columnDescriptions);
tableDescription.cellDescriptions = Objects.requireNonNull(this.cellDescriptions);
tableDescription.iconURLsProvider = Objects.requireNonNull(this.iconURLsProvider);
tableDescription.enableSubRows = this.enableSubRows;
return tableDescription;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @author lfasani
*/
public record TableElementProps(String id, String descriptionId, String targetObjectId, String targetObjectKind,
PaginationData paginationData, boolean stripeRow, List<Element> children, String globalFilter, List<ColumnFilter> columnFilters) implements IProps {
PaginationData paginationData, boolean stripeRow, List<Element> children, String globalFilter, List<ColumnFilter> columnFilters, boolean enableSubRows) implements IProps {

public static final String TYPE = "Table";

Expand Down Expand Up @@ -76,6 +76,8 @@ public static final class Builder {

private List<ColumnFilter> columnFilters;

private boolean enableSubRows;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand Down Expand Up @@ -120,8 +122,14 @@ public Builder columnFilters(List<ColumnFilter> columnFilters) {
return this;
}

public Builder enableSubRows(boolean enableSubRows) {
this.enableSubRows = enableSubRows;
return this;
}

public TableElementProps build() {
return new TableElementProps(this.id, this.descriptionId, this.targetObjectId, this.targetObjectKind, this.paginationData, this.stripeRow, this.children, this.globalFilter, this.columnFilters);
return new TableElementProps(this.id, this.descriptionId, this.targetObjectId, this.targetObjectKind, this.paginationData, this.stripeRow, this.children, this.globalFilter,
this.columnFilters, this.enableSubRows);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private Table instantiateTable(IProps props, List<Object> children) {
.paginationData(tableElementProps.paginationData())
.globalFilter(tableElementProps.globalFilter())
.columnFilters(tableElementProps.columnFilters())
.enableSubRows(tableElementProps.enableSubRows())
.build();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const getTableEventSubscription = `
totalRowCount
}
stripeRow
enableSubRows
globalFilter
columnFilters {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const RowChevronButton = ({ row, isExpanded, onExpandCollapse, hasChildre
<IconButton
onClick={(_) => onExpandCollapse(row.id)}
// the contrast between disabled and default text color is not enough
sx={{ marginLeft: theme.spacing(row.depthLevel), color: 'black' }}
sx={{ marginLeft: theme.spacing(row.depthLevel), marginRight: theme.spacing(-2), color: 'black' }}
disabled={!hasChildren}>
{isExpanded ? <ExpandMoreIcon /> : <ChevronRightIcon />}
</IconButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,15 @@ import { IconOverlay } from '@eclipse-sirius/sirius-components-core';
import Box from '@mui/material/Box';
import { useTheme } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import { RowChevronButton } from './RowChevronButton';
import { RowHeaderProps } from './RowHeader.types';

export const RowHeader = ({ row, isExpanded, hasChildren, onExpandCollapse }: RowHeaderProps) => {
export const RowHeader = ({ row, children }: RowHeaderProps) => {
const theme = useTheme();

return (
<Box display="flex" alignItems="center" justifyContent="space-between" gap={theme.spacing(2)}>
<RowChevronButton
row={row}
isExpanded={isExpanded}
onExpandCollapse={onExpandCollapse}
hasChildren={hasChildren}
/>
<Typography noWrap sx={{ marginLeft: theme.spacing(-2) }}>
{row.headerIndexLabel}
</Typography>
{children}
<Typography noWrap>{row.headerIndexLabel}</Typography>
<Box display="flex" alignItems="center" gap={theme.spacing(1)}>
<IconOverlay iconURL={row.headerIconURLs} alt={row.headerLabel} />
<Typography noWrap>{row.headerLabel}</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ import { GQLLine } from '../table/TableContent.types';

export interface RowHeaderProps {
row: GQLLine;
isExpanded: boolean;
onExpandCollapse: (rowId: string) => void;
hasChildren: boolean;
children: React.ReactNode;
}
Loading

0 comments on commit 9f7401a

Please sign in to comment.