Skip to content

Commit

Permalink
[4556] Add the support of row hierarchy in tables
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 Mar 6, 2025
1 parent 3ab0895 commit 92e8315
Show file tree
Hide file tree
Showing 60 changed files with 910 additions and 162 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Except for the specific case where `cause === 'refresh'` in `DiagramRenderer` (w
- https://github.com/eclipse-sirius/sirius-web/issues/4451[#4451] [diagram] Keep using the same node after a refresh if possible in order to avoid rerendering all the nodes after converting the diagram
- https://github.com/eclipse-sirius/sirius-web/issues/4575[#4575] [diagram] Memoize the style of a label to avoid rerendering them all when refreshing the diagram
- https://github.com/eclipse-sirius/sirius-web/issues/4577[#4577] [diagram] Improve the performance of the diagram by removing useless data from `DiagramContext`
- https://github.com/eclipse-sirius/sirius-web/issues/4556[#4556] [table] Add the support of row hierarchy in tables



Expand Down Expand Up @@ -290,7 +291,6 @@ To achieve that a new concept, `ProjectSemanticData` has been added along with a
- https://github.com/eclipse-sirius/sirius-web/issues/4411[#4411] [sirius-web] Add support for expressions returning a collection of strings in the query view



== v2025.1.0

=== Shapes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +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)
.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 @@ -91,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 @@ -11,10 +11,10 @@
* Obeo - initial API and implementation
*******************************************************************************/
import {
GQLWidget,
PropertySectionComponent,
PropertySectionComponentProps,
PropertySectionLabel,
GQLWidget,
} from '@eclipse-sirius/sirius-components-forms';
import { TableContent } from '@eclipse-sirius/sirius-components-tables';
import { makeStyles } from 'tss-react/mui';
Expand Down Expand Up @@ -57,13 +57,15 @@ const RawTableWidgetPropertySection: PropertySectionComponent<GQLTableWidget> =
onPaginationChange={() => {}}
onGlobalFilterChange={() => {}}
onColumnFiltersChange={() => {}}
onExpandedElementChange={() => {}}
enableColumnVisibility={false}
enableColumnResizing={false}
enableColumnFilters={false}
enableRowSizing={false}
enableGlobalFilter={false}
enablePagination={false}
enableColumnOrdering={false}
expandedRowIds={[]}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
import org.eclipse.sirius.components.core.api.ILabelService;
import org.eclipse.sirius.components.emf.tables.CursorBasedNavigationServices;
import org.eclipse.sirius.components.papaya.AnnotableElement;
import org.eclipse.sirius.components.papaya.Operation;
import org.eclipse.sirius.components.papaya.Package;
import org.eclipse.sirius.components.papaya.PapayaFactory;
import org.eclipse.sirius.components.papaya.PapayaPackage;
import org.eclipse.sirius.components.papaya.Parameter;
import org.eclipse.sirius.components.papaya.Type;
import org.eclipse.sirius.components.papaya.spec.PackageSpec;
import org.eclipse.sirius.components.representations.IRepresentationDescription;
Expand Down Expand Up @@ -101,6 +104,7 @@ public List<IRepresentationDescription> getRepresentationDescriptions(IEditingCo
.headerIndexLabelProvider(headerIndexLabelProvider)
.isResizablePredicate(variableManager -> true)
.initialHeightProvider(variableManager -> 53)
.depthLevelProvider(this::getSemanticElementDepthLevel)
.build();

var tableDescription = TableDescription.newTableDescription(TABLE_DESCRIPTION_ID)
Expand All @@ -114,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 All @@ -133,11 +138,11 @@ private PaginatedData getSemanticElements(VariableManager variableManager) {
var size = variableManager.get(TableRenderer.PAGINATION_SIZE, Integer.class).orElse(0);
var globalFilter = variableManager.get(TableRenderer.GLOBAL_FILTER_DATA, String.class).orElse(null);
List<ColumnFilter> columnFilters = variableManager.get(TableRenderer.COLUMN_FILTERS, List.class).orElse(List.of());
List<String> expandedIds = variableManager.get(TableRenderer.EXPANDED_IDS, List.class).orElse(List.of());

Predicate<EObject> predicate = eObject -> {
boolean isValidCandidate = eObject instanceof Type && EcoreUtil.isAncestor(self, eObject);
if (isValidCandidate) {
var type = (Type) eObject;
boolean isValidCandidate = this.isValidType(eObject, self) && this.hasExpandedParent(eObject, expandedIds);
if (isValidCandidate && eObject instanceof Type type) {
if (globalFilter != null && !globalFilter.isBlank()) {
isValidCandidate = type.getName() != null && type.getName().contains(globalFilter);
isValidCandidate = isValidCandidate || type.getDescription() != null && type.getDescription().contains(globalFilter);
Expand All @@ -146,12 +151,58 @@ private PaginatedData getSemanticElements(VariableManager variableManager) {
}
isValidCandidate = isValidCandidate && columnFilters.stream().allMatch(new PapayaColumnFilterPredicate(this.objectMapper, type));
}
if (isValidCandidate && eObject instanceof Operation operation) {
if (globalFilter != null && !globalFilter.isBlank()) {
isValidCandidate = operation.getName() != null && operation.getName().contains(globalFilter);
isValidCandidate = isValidCandidate || operation.getDescription() != null && operation.getDescription().contains(globalFilter);
isValidCandidate = isValidCandidate || operation.getVisibility() != null && operation.getVisibility().getLiteral().contains(globalFilter);
}
}
if (isValidCandidate && eObject instanceof Parameter parameter) {
if (globalFilter != null && !globalFilter.isBlank()) {
isValidCandidate = parameter.getName() != null && parameter.getName().contains(globalFilter);
isValidCandidate = isValidCandidate || parameter.getDescription() != null && parameter.getDescription().contains(globalFilter);
}
}
return isValidCandidate;
};

return new CursorBasedNavigationServices().collect(self, cursor, direction, size, predicate);
}

private boolean isValidType(EObject eObject, EObject self) {
// first should be inside the self element
boolean isValid = EcoreUtil.isAncestor(self, eObject);
boolean isValidElement = eObject instanceof Type ||
eObject instanceof Operation ||
// only consider parameter of regular operation (not constructor)
(eObject instanceof Parameter && eObject.eContainer() instanceof Operation);
return isValid && isValidElement;
}

private boolean hasExpandedParent(EObject eObject, List<String> expandedIds) {
EObject parent = eObject.eContainer();
if (parent != null && !(parent instanceof Package)) {
var parentId = this.identityService.getId(parent);
return expandedIds.contains(parentId) && this.hasExpandedParent(parent, expandedIds);
}
return true;
}

private Integer getSemanticElementDepthLevel(VariableManager variableManager) {
return variableManager.get(VariableManager.SELF, EObject.class)
.map(this::getEObjectDepthLevel)
.orElse(0);
}

private Integer getEObjectDepthLevel(EObject eObject) {
if (eObject instanceof Package) {
return -1;
} else {
return 1 + this.getEObjectDepthLevel(eObject.eContainer());
}
}

private List<ColumnDescription> getColumnDescriptions() {
var provider = new StructuralFeatureToDisplayNameProvider(new DisplayNameProvider(this.composedAdapterFactory));
Map<EStructuralFeature, String> featureToDisplayName = provider.getColumnsStructuralFeaturesDisplayName(PapayaFactory.eINSTANCE.createClass(), PapayaPackage.eINSTANCE.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public List<IRepresentationDescription> getRepresentationDescriptions(IEditingCo
.headerIndexLabelProvider(variableManager -> "")
.isResizablePredicate(variableManager -> false)
.initialHeightProvider(variableManager -> -1)
.depthLevelProvider(variableManager -> 0)
.build();

var tableDescription = TableDescription.newTableDescription(TABLE_DESCRIPTION_ID)
Expand All @@ -91,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
Loading

0 comments on commit 92e8315

Please sign in to comment.