Skip to content

Commit

Permalink
[4101] Add loop tree item label element description
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#4101
Signed-off-by: Jerome Gout <[email protected]>
  • Loading branch information
jerome-obeo committed Oct 14, 2024
1 parent baf90ae commit eb42458
Show file tree
Hide file tree
Showing 23 changed files with 1,085 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ never, always and if_children (to display the separator only if children exist).
Project template images will now have a predictable size of 150px by 110px.
This will allow specifier to create images that fir perfectly in the project template card.
- https://github.com/eclipse-sirius/sirius-web/issues/4095[#4095] Add conditional tree item label element description
- https://github.com/eclipse-sirius/sirius-web/issues/4101[#4101] Add loop tree item label element description


== v2024.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ private TreeItemLabelDescription entityStyle(TextStylePalette textStylePalette)
.children(
this.getEntityKeyFragment(textStylePalette),
this.getEntityValueFragment(textStylePalette),
new TreeBuilders().newTreeItemLabelFragmentDescription()
.labelExpression(" {")
.style(this.getTextStyleByName(textStylePalette, NORMAL_TEXT_STYLE_NAME))
.build(),
this.getAttributesFragments(textStylePalette),
new TreeBuilders().newTreeItemLabelFragmentDescription()
.labelExpression("}")
.style(this.getTextStyleByName(textStylePalette, NORMAL_TEXT_STYLE_NAME))
.build(),
this.getAbstractEntityValueFragment(textStylePalette))
.build();
}
Expand All @@ -176,6 +185,13 @@ private TreeItemLabelDescription defaultStyle() {
.build();
}

private TreeItemLabelElementDescription getEntityKeyFragment(TextStylePalette textStylePalette) {
return new TreeBuilders().newTreeItemLabelFragmentDescription()
.labelExpression("aql:'[Entity] '")
.style(this.getTextStyleByName(textStylePalette, BROWN_BOLD_TEXT_STYLE_NAME))
.build();
}

private TreeItemLabelElementDescription getEntityValueFragment(TextStylePalette textStylePalette) {
return new TreeBuilders().newTreeItemLabelFragmentDescription()
.labelExpression(AQL_SELF_GET_TREE_ITEM_LABEL)
Expand All @@ -193,10 +209,23 @@ private TreeItemLabelElementDescription getAbstractEntityValueFragment(TextStyle
.build();
}

private TreeItemLabelElementDescription getEntityKeyFragment(TextStylePalette textStylePalette) {
return new TreeBuilders().newTreeItemLabelFragmentDescription()
.labelExpression("aql:'[Entity] '")
.style(this.getTextStyleByName(textStylePalette, BROWN_BOLD_TEXT_STYLE_NAME))
private TreeItemLabelElementDescription getAttributesFragments(TextStylePalette textStylePalette) {
return new TreeBuilders().newForTreeItemLabelElementDescription()
.iterator("attribute")
.iterableExpression("aql:self.attributes")
.children(
new TreeBuilders().newTreeItemLabelFragmentDescription()
.labelExpression("aql:attribute.name")
.style(this.getTextStyleByName(textStylePalette, NORMAL_TEXT_STYLE_NAME))
.build(),
new TreeBuilders().newIfTreeItemLabelElementDescription()
.predicateExpression("aql:self.attributes->indexOf(attribute) < (self.attributes->size())")
.children(new TreeBuilders().newTreeItemLabelFragmentDescription()
.labelExpression(", ")
.style(this.getTextStyleByName(textStylePalette, NORMAL_TEXT_STYLE_NAME))
.build())
.build()
)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void givenAnExplorerRepresentationWhenWeSubscribeToItsEventThenTheReprese
assertThat(tree.getChildren().get(0).getChildren()).hasSize(1);
assertThat(tree.getChildren().get(0).getChildren().get(0).getLabel().toString()).isEqualTo("buck");
assertThat(tree.getChildren().get(0).getChildren().get(0).getChildren()).hasSize(3);
assertThat(tree.getChildren().get(0).getChildren().get(0).getChildren().get(2).getLabel().toString()).isEqualTo("[Entity] Human");
assertThat(tree.getChildren().get(0).getChildren().get(0).getChildren().get(2).getLabel().toString()).contains("[Entity] Human");
assertThat(tree.getChildren().get(0).getChildren().get(0).getChildren().get(2).getChildren()).hasSize(4);
assertThat(tree.getChildren().get(0).getChildren().get(0).getChildren().get(2).getChildren().get(0).getLabel().toString()).isEqualTo("superTypes");
settingId.set(tree.getChildren().get(0).getChildren().get(0).getChildren().get(2).getChildren().get(0).getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.function.Consumer;

import org.eclipse.sirius.components.collaborative.trees.dto.TreeRefreshedEventPayload;
import org.eclipse.sirius.components.core.api.labels.StyledString;
import org.eclipse.sirius.components.trees.Tree;
import org.eclipse.sirius.components.trees.TreeItem;
import org.eclipse.sirius.web.AbstractIntegrationTests;
Expand Down Expand Up @@ -116,6 +115,7 @@ public void givenAStudioWhenTheTreeItemLabelsAreRequestedThenTheCorrectStylesAre
// 2- check that styles are properly applied
// - check that the ROOT entity has not the abstract style applied.
// - check that the NamedElement entity has the abstract style (if style)
// - check that the Human entity has 3 attributes (for style)
var inputStyle = new ExplorerEventInput(UUID.randomUUID(), StudioIdentifiers.SAMPLE_STUDIO_PROJECT.toString(), explorerRepresentationId);
var fluxStyle = this.explorerEventSubscriptionRunner.run(inputStyle);

Expand All @@ -126,11 +126,15 @@ public void givenAStudioWhenTheTreeItemLabelsAreRequestedThenTheCorrectStylesAre
.getChildren()
.get(0)
.getChildren();
StyledString rootLabel = domainChildren.get(0).getLabel();
StyledString namedElementLabel = domainChildren.get(1).getLabel();
assertThat(rootLabel.styledStringFragments()).hasSize(2);
assertThat(namedElementLabel.styledStringFragments()).hasSize(3);
assertThat(namedElementLabel.toString()).isEqualTo("[Entity] NamedElement [abstract]");
var rootLabels = domainChildren.get(0).getLabel().styledStringFragments();
var namedElementLabels = domainChildren.get(1).getLabel().styledStringFragments();
var humanLabels = domainChildren.get(2).getLabel().styledStringFragments();
assertThat(rootLabels.get(rootLabels.size() - 1).text()).doesNotContain("[abstract]");
assertThat(namedElementLabels.get(namedElementLabels.size() - 1).text()).contains("[abstract]");
assertThat(humanLabels).hasSize(9);
assertThat(humanLabels.get(3).text()).isEqualTo("description");
assertThat(humanLabels.get(5).text()).isEqualTo("promoted");
assertThat(humanLabels.get(7).text()).isEqualTo("birthDate");
});

StepVerifier.create(fluxStyle)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2023, 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.components.view.builder.generated.tree;

/**
* Builder for ForTreeItemLabelElementDescriptionBuilder.
*
* @author BuilderGenerator
* @generated
*/
public class ForTreeItemLabelElementDescriptionBuilder {

/**
* Create instance org.eclipse.sirius.components.view.tree.ForTreeItemLabelElementDescription.
* @generated
*/
private org.eclipse.sirius.components.view.tree.ForTreeItemLabelElementDescription forTreeItemLabelElementDescription = org.eclipse.sirius.components.view.tree.TreeFactory.eINSTANCE.createForTreeItemLabelElementDescription();

/**
* Return instance org.eclipse.sirius.components.view.tree.ForTreeItemLabelElementDescription.
* @generated
*/
protected org.eclipse.sirius.components.view.tree.ForTreeItemLabelElementDescription getForTreeItemLabelElementDescription() {
return this.forTreeItemLabelElementDescription;
}

/**
* Return instance org.eclipse.sirius.components.view.tree.ForTreeItemLabelElementDescription.
* @generated
*/
public org.eclipse.sirius.components.view.tree.ForTreeItemLabelElementDescription build() {
return this.getForTreeItemLabelElementDescription();
}

/**
* Setter for Iterator.
*
* @generated
*/
public ForTreeItemLabelElementDescriptionBuilder iterator(java.lang.String value) {
this.getForTreeItemLabelElementDescription().setIterator(value);
return this;
}
/**
* Setter for IterableExpression.
*
* @generated
*/
public ForTreeItemLabelElementDescriptionBuilder iterableExpression(java.lang.String value) {
this.getForTreeItemLabelElementDescription().setIterableExpression(value);
return this;
}
/**
* Setter for Children.
*
* @generated
*/
public ForTreeItemLabelElementDescriptionBuilder children(org.eclipse.sirius.components.view.tree.TreeItemLabelElementDescription ... values) {
for (org.eclipse.sirius.components.view.tree.TreeItemLabelElementDescription value : values) {
this.getForTreeItemLabelElementDescription().getChildren().add(value);
}
return this;
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public IfTreeItemLabelElementDescriptionBuilder newIfTreeItemLabelElementDescrip
return new IfTreeItemLabelElementDescriptionBuilder();
}

/**
* Instantiate a ForTreeItemLabelElementDescriptionBuilder .
*
* @author BuilderGenerator
* @generated
*/
public ForTreeItemLabelElementDescriptionBuilder newForTreeItemLabelElementDescription() {
return new ForTreeItemLabelElementDescriptionBuilder();
}

/**
* Instantiate a TreeItemLabelFragmentDescriptionBuilder .
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.view.emf.tree;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -22,6 +23,7 @@
import org.eclipse.sirius.components.core.api.labels.StyledStringFragmentStyle;
import org.eclipse.sirius.components.core.api.labels.UnderLineStyle;
import org.eclipse.sirius.components.interpreter.AQLInterpreter;
import org.eclipse.sirius.components.view.tree.ForTreeItemLabelElementDescription;
import org.eclipse.sirius.components.view.tree.IfTreeItemLabelElementDescription;
import org.eclipse.sirius.components.view.tree.TreeItemLabelDescription;
import org.eclipse.sirius.components.view.tree.TreeItemLabelElementDescription;
Expand Down Expand Up @@ -61,6 +63,8 @@ private List<StyledStringFragment> convertElement(TreeItemLabelElementDescriptio
.flatMap(tiled -> this.convertElement(tiled).stream())
.toList();
}
} else if (element instanceof ForTreeItemLabelElementDescription forElement) {
result = this.convertForElementDescription(forElement);
}
return result;
}
Expand Down Expand Up @@ -91,11 +95,29 @@ private StyledStringFragment convertFragment(TreeItemLabelFragmentDescription fr
return new StyledStringFragment(text, styleBuilder.build());
}

private List<StyledStringFragment> convertForElementDescription(ForTreeItemLabelElementDescription forElement) {
var result = new ArrayList<StyledStringFragment>();
var iterable = evaluateObjectList(forElement.getIterableExpression());
iterable.forEach(iteration -> {
variables.put(forElement.getIterator(), iteration);
result.addAll(forElement.getChildren().stream()
.flatMap(tiled -> this.convertElement(tiled).stream())
.toList());
});
return result;
}

private Optional<String> evaluateString(String expression) {
return this.interpreter.evaluateExpression(this.variables, expression).asString();
}

private Optional<Boolean> evaluateBoolean(String expression) {
return this.interpreter.evaluateExpression(this.variables, expression).asBoolean();
}

private List<Object> evaluateObjectList(String expression) {
return interpreter.evaluateExpression(variables, expression)
.asObjects()
.orElse(List.of());
}
}
Loading

0 comments on commit eb42458

Please sign in to comment.