Skip to content

Commit

Permalink
[test] Add a first table to the papaya details view description
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Dec 18, 2024
1 parent a6b506b commit 9b32181
Show file tree
Hide file tree
Showing 9 changed files with 400 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 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
Expand Down Expand Up @@ -85,6 +85,10 @@ public static Builder newGroupDescription(String id) {
return new Builder(id);
}

public static Builder newGroupDescription(GroupDescription groupDescription) {
return new Builder(groupDescription);
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}'}'";
Expand Down Expand Up @@ -118,6 +122,17 @@ private Builder(String id) {
this.id = Objects.requireNonNull(id);
}

private Builder(GroupDescription groupDescription) {
this.id = Objects.requireNonNull(groupDescription.getId());
this.idProvider = Objects.requireNonNull(groupDescription.getIdProvider());
this.labelProvider = Objects.requireNonNull(groupDescription.getLabelProvider());
this.displayModeProvider = Objects.requireNonNull(groupDescription.getDisplayModeProvider());
this.semanticElementsProvider = Objects.requireNonNull(groupDescription.getSemanticElementsProvider());
this.toolbarActionDescriptions = Objects.requireNonNull(groupDescription.getToolbarActionDescriptions());
this.controlDescriptions = Objects.requireNonNull(groupDescription.getControlDescriptions());
this.borderStyleProvider = Objects.requireNonNull(groupDescription.getBorderStyleProvider());
}

public Builder idProvider(Function<VariableManager, String> idProvider) {
this.idProvider = Objects.requireNonNull(idProvider);
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 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
Expand Down Expand Up @@ -79,6 +79,10 @@ public static Builder newPageDescription(String id) {
return new Builder(id);
}

public static Builder newPageDescription(PageDescription pageDescription) {
return new Builder(pageDescription);
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}'}'";
Expand Down Expand Up @@ -111,6 +115,16 @@ private Builder(String id) {
this.id = Objects.requireNonNull(id);
}

private Builder(PageDescription pageDescription) {
this.id = Objects.requireNonNull(pageDescription.getId());
this.idProvider = Objects.requireNonNull(pageDescription.getIdProvider());
this.labelProvider = Objects.requireNonNull(pageDescription.getLabelProvider());
this.semanticElementsProvider = Objects.requireNonNull(pageDescription.getSemanticElementsProvider());
this.groupDescriptions = Objects.requireNonNull(pageDescription.getGroupDescriptions());
this.toolbarActionDescriptions = Objects.requireNonNull(pageDescription.getToolbarActionDescriptions());
this.canCreatePredicate = Objects.requireNonNull(pageDescription.getCanCreatePredicate());
}

public Builder idProvider(Function<VariableManager, String> idProvider) {
this.idProvider = Objects.requireNonNull(idProvider);
return this;
Expand All @@ -136,8 +150,8 @@ public Builder toolbarActionDescriptions(List<ButtonDescription> toolbarActionDe
return this;
}

public Builder canCreatePredicate(Predicate<VariableManager> predicate) {
this.canCreatePredicate = Objects.requireNonNull(predicate);
public Builder canCreatePredicate(Predicate<VariableManager> canCreatePredicate) {
this.canCreatePredicate = Objects.requireNonNull(canCreatePredicate);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class PapayaJavaServiceProvider implements IJavaServiceProvider {

@Override
public List<Class<?>> getServiceClasses(View view) {
var isComponentDiagram = view.getDescriptions().stream()
var isPapayaRepresentation = view.getDescriptions().stream()
.anyMatch(representationDescription -> representationDescription.getDomainType().startsWith(PapayaPackage.eNS_PREFIX + ":"));
if (isComponentDiagram) {
if (isPapayaRepresentation) {
return List.of(PapayaRepresentationServices.class, ComponentDiagramServices.class, ClassDiagramServices.class);
}
return List.of();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*******************************************************************************
* 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.web.papaya.views.details;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiFunction;
import java.util.function.Function;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.sirius.components.core.api.IIdentityService;
import org.eclipse.sirius.components.core.api.ILabelService;
import org.eclipse.sirius.components.papaya.Class;
import org.eclipse.sirius.components.papaya.PapayaPackage;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.tables.descriptions.ColumnDescription;
import org.eclipse.sirius.components.tables.descriptions.ICellDescription;
import org.eclipse.sirius.components.tables.descriptions.LineDescription;
import org.eclipse.sirius.components.tables.descriptions.PaginatedData;
import org.eclipse.sirius.components.tables.descriptions.TableDescription;
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;
import org.springframework.stereotype.Service;

/**
* Used to contribute the attributes table.
*
* @author sbegaudeau
*/
@Service
public class AttributesTableDescriptionProvider {

private final IIdentityService identityService;

private final ILabelService labelService;

public AttributesTableDescriptionProvider(IIdentityService identityService, ILabelService labelService) {
this.identityService = Objects.requireNonNull(identityService);
this.labelService = Objects.requireNonNull(labelService);
}

public TableDescription getTableDescription() {
Function<VariableManager, String> targetObjectIdProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.map(this.identityService::getId)
.orElse(null);

Function<VariableManager, String> targetObjectKind = variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.map(this.identityService::getKind)
.orElse(null);

Function<VariableManager, String> labelProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.map(this.labelService::getLabel)
.orElse(null);

Function<VariableManager, PaginatedData> semanticElementsProvider = variableManager -> variableManager.get(VariableManager.SELF, Class.class)
.map(aClass -> {
List<Object> objects = new ArrayList<>();
objects.addAll(aClass.getAttributes());
return new PaginatedData(objects, false, false, objects.size());
})
.orElse(new PaginatedData(List.of(), false, false, 0));

LineDescription lineDescription = LineDescription.newLineDescription(UUID.nameUUIDFromBytes("Table - Line".getBytes()).toString())
.targetObjectIdProvider(targetObjectIdProvider)
.targetObjectKindProvider(targetObjectKind)
.semanticElementsProvider(semanticElementsProvider)
.headerLabelProvider(variableManager -> "")
.headerIconURLsProvider(variableManager -> List.of())
.headerIndexLabelProvider(variableManager -> "")
.isResizablePredicate(variableManager -> false)
.initialHeightProvider(variableManager -> 0)
.build();

var nameColumnDescription = ColumnDescription.newColumnDescription("name")
.semanticElementsProvider(variableManager -> List.of(PapayaPackage.eINSTANCE.getNamedElement_Name()))
.targetObjectIdProvider(new ColumnTargetObjectIdProvider())
.targetObjectKindProvider(variableManager -> "")
.headerLabelProvider(variableManager -> "Name")
.headerIconURLsProvider(variableManager -> List.of())
.headerIndexLabelProvider(variableManager -> "")
.initialWidthProvider(variableManager -> -1)
.isResizablePredicate(variableManager -> false)
.filterVariantProvider(variableManager -> "")
.build();

List<ColumnDescription> columnDescriptions = List.of(nameColumnDescription);

BiFunction<VariableManager, Object, String> valueProvider = (variableManager, columnTargetObject) -> {
String value = "";
Optional<EObject> optionalEObject = variableManager.get(VariableManager.SELF, EObject.class);
if (optionalEObject.isPresent() && columnTargetObject instanceof EStructuralFeature eStructuralFeature) {
EObject eObject = optionalEObject.get();
Object objectValue = eObject.eGet(eStructuralFeature);
if (eStructuralFeature instanceof EReference eReference) {
if (!eReference.isMany() && !eReference.isContainment()) {
value = this.identityService.getId(objectValue);
}
} else if (objectValue != null) {
value = objectValue.toString();
}
}
return value;
};

var nameCellDescription = TextfieldCellDescription.newTextfieldCellDescription("name")
.canCreatePredicate(new CellTypePredicate().isTextfieldCell())
.targetObjectIdProvider(variableManager -> "")
.targetObjectKindProvider(variableManager -> "")
.cellValueProvider(valueProvider)
.build();

List<ICellDescription> cellDescriptions = List.of(nameCellDescription);

return TableDescription.newTableDescription("table")
.label("tasksTableLabel")
.targetObjectIdProvider(targetObjectIdProvider)
.targetObjectKindProvider(targetObjectKind)
.labelProvider(labelProvider)
.lineDescription(lineDescription)
.columnDescriptions(columnDescriptions)
.cellDescriptions(cellDescriptions)
.iconURLsProvider(variableManager -> List.of())
.isStripeRowPredicate(variableManager -> false)
.build();
}
}
Loading

0 comments on commit 9b32181

Please sign in to comment.