Skip to content

Commit

Permalink
[2044] Custom icons to edges and nodes label in view dsl
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#2044
Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
  • Loading branch information
mcharfadi committed Jun 9, 2023
1 parent ab4a297 commit d010602
Show file tree
Hide file tree
Showing 27 changed files with 1,295 additions and 161 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -17,6 +17,7 @@
- https://github.com/eclipse-sirius/sirius-components/issues/2004[#2004] [form] Add the possibility to show select options' icons.
+
image:doc/screenshots/ShowIconOptionSelectWidget.jpg[Icons on select widget option,70%,30%]
- https://github.com/eclipse-sirius/sirius-components/issues/2044[#2044] [view] Add custom icons to edges and nodes label in view dsl

=== Improvements

Expand Down
Expand Up @@ -65,15 +65,14 @@ describe('/projects/:projectId/edit - Color Palette', () => {
cy.getByTestId('Color').click().get('[data-value="color_dark"]').should('exist').click();
cy.getByTestId('Border Color').click().get('[data-value="border_blue"]').should('exist').click();
});

it('can select color from color palette in edge style properties', () => {
cy.getByTestId('ViewNewModel-toggle').click();
cy.getByTestId('View-toggle').click();
cy.get('[title="view::DiagramDescription"]').dblclick();
cy.getByTestId('LinkedTo Edge-toggle').click();
cy.get('[title="view::EdgeStyle"]').click();
cy.getByTestId('Color').click();
cy.contains('FixedColor color_blue').click();
cy.contains('color_blue').click();
});

});
});
Expand Up @@ -29,7 +29,6 @@
*/
@QueryDataFetcher(type = "SelectOption", field = "iconURL")
public class SelectOptionIconURLDataFetcher implements IDataFetcherWithFieldCoordinates<String> {

@Override
public String get(DataFetchingEnvironment environment) throws Exception {
SelectOption option = environment.getSource();
Expand Down
Expand Up @@ -61,6 +61,7 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
this.addTargetArrowStylePropertyDescriptor(object);
this.addEdgeWidthPropertyDescriptor(object);
this.addShowIconPropertyDescriptor(object);
this.addLabelIconPropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
}
Expand Down Expand Up @@ -186,6 +187,17 @@ protected void addShowIconPropertyDescriptor(Object object) {
ViewPackage.Literals.EDGE_STYLE__SHOW_ICON, true, false, false, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the Label Icon feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
protected void addLabelIconPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_EdgeStyle_labelIcon_feature"), this.getString("_UI_PropertyDescriptor_description", "_UI_EdgeStyle_labelIcon_feature", "_UI_EdgeStyle_type"),
ViewPackage.Literals.EDGE_STYLE__LABEL_ICON, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This returns ConditionalEdgeStyle.gif. <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -240,6 +252,7 @@ public void notifyChanged(Notification notification) {
case ViewPackage.CONDITIONAL_EDGE_STYLE__TARGET_ARROW_STYLE:
case ViewPackage.CONDITIONAL_EDGE_STYLE__EDGE_WIDTH:
case ViewPackage.CONDITIONAL_EDGE_STYLE__SHOW_ICON:
case ViewPackage.CONDITIONAL_EDGE_STYLE__LABEL_ICON:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
Expand Down
Expand Up @@ -60,6 +60,7 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
this.addTargetArrowStylePropertyDescriptor(object);
this.addEdgeWidthPropertyDescriptor(object);
this.addShowIconPropertyDescriptor(object);
this.addLabelIconPropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
}
Expand Down Expand Up @@ -174,6 +175,17 @@ protected void addShowIconPropertyDescriptor(Object object) {
ViewPackage.Literals.EDGE_STYLE__SHOW_ICON, true, false, false, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the Label Icon feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
protected void addLabelIconPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_EdgeStyle_labelIcon_feature"), this.getString("_UI_PropertyDescriptor_description", "_UI_EdgeStyle_labelIcon_feature", "_UI_EdgeStyle_type"),
ViewPackage.Literals.EDGE_STYLE__LABEL_ICON, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This returns EdgeStyle.gif. <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -227,6 +239,7 @@ public void notifyChanged(Notification notification) {
case ViewPackage.EDGE_STYLE__TARGET_ARROW_STYLE:
case ViewPackage.EDGE_STYLE__EDGE_WIDTH:
case ViewPackage.EDGE_STYLE__SHOW_ICON:
case ViewPackage.EDGE_STYLE__LABEL_ICON:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
Expand Down
Expand Up @@ -63,6 +63,7 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
this.addWidthComputationExpressionPropertyDescriptor(object);
this.addHeightComputationExpressionPropertyDescriptor(object);
this.addShowIconPropertyDescriptor(object);
this.addLabelIconPropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
}
Expand Down Expand Up @@ -216,6 +217,18 @@ protected void addShowIconPropertyDescriptor(Object object) {
ViewPackage.Literals.NODE_STYLE_DESCRIPTION__SHOW_ICON, true, false, false, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the Label Icon feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
protected void addLabelIconPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_NodeStyleDescription_labelIcon_feature"),
this.getString("_UI_PropertyDescriptor_description", "_UI_NodeStyleDescription_labelIcon_feature", "_UI_NodeStyleDescription_type"),
ViewPackage.Literals.NODE_STYLE_DESCRIPTION__LABEL_ICON, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This returns IconLabelNodeStyleDescription.gif. <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -272,6 +285,7 @@ public void notifyChanged(Notification notification) {
case ViewPackage.ICON_LABEL_NODE_STYLE_DESCRIPTION__WIDTH_COMPUTATION_EXPRESSION:
case ViewPackage.ICON_LABEL_NODE_STYLE_DESCRIPTION__HEIGHT_COMPUTATION_EXPRESSION:
case ViewPackage.ICON_LABEL_NODE_STYLE_DESCRIPTION__SHOW_ICON:
case ViewPackage.ICON_LABEL_NODE_STYLE_DESCRIPTION__LABEL_ICON:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
Expand Down
Expand Up @@ -63,6 +63,7 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
this.addWidthComputationExpressionPropertyDescriptor(object);
this.addHeightComputationExpressionPropertyDescriptor(object);
this.addShowIconPropertyDescriptor(object);
this.addLabelIconPropertyDescriptor(object);
this.addShapePropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
Expand Down Expand Up @@ -217,6 +218,18 @@ protected void addShowIconPropertyDescriptor(Object object) {
ViewPackage.Literals.NODE_STYLE_DESCRIPTION__SHOW_ICON, true, false, false, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the Label Icon feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
protected void addLabelIconPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_NodeStyleDescription_labelIcon_feature"),
this.getString("_UI_PropertyDescriptor_description", "_UI_NodeStyleDescription_labelIcon_feature", "_UI_NodeStyleDescription_type"),
ViewPackage.Literals.NODE_STYLE_DESCRIPTION__LABEL_ICON, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the Shape feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -285,6 +298,7 @@ public void notifyChanged(Notification notification) {
case ViewPackage.IMAGE_NODE_STYLE_DESCRIPTION__WIDTH_COMPUTATION_EXPRESSION:
case ViewPackage.IMAGE_NODE_STYLE_DESCRIPTION__HEIGHT_COMPUTATION_EXPRESSION:
case ViewPackage.IMAGE_NODE_STYLE_DESCRIPTION__SHOW_ICON:
case ViewPackage.IMAGE_NODE_STYLE_DESCRIPTION__LABEL_ICON:
case ViewPackage.IMAGE_NODE_STYLE_DESCRIPTION__SHAPE:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
Expand Down
Expand Up @@ -63,6 +63,7 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
this.addWidthComputationExpressionPropertyDescriptor(object);
this.addHeightComputationExpressionPropertyDescriptor(object);
this.addShowIconPropertyDescriptor(object);
this.addLabelIconPropertyDescriptor(object);
this.addWithHeaderPropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
Expand Down Expand Up @@ -217,6 +218,18 @@ protected void addShowIconPropertyDescriptor(Object object) {
ViewPackage.Literals.NODE_STYLE_DESCRIPTION__SHOW_ICON, true, false, false, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the Label Icon feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
protected void addLabelIconPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_NodeStyleDescription_labelIcon_feature"),
this.getString("_UI_PropertyDescriptor_description", "_UI_NodeStyleDescription_labelIcon_feature", "_UI_NodeStyleDescription_type"),
ViewPackage.Literals.NODE_STYLE_DESCRIPTION__LABEL_ICON, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the With Header feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -285,6 +298,7 @@ public void notifyChanged(Notification notification) {
case ViewPackage.RECTANGULAR_NODE_STYLE_DESCRIPTION__WIDTH_COMPUTATION_EXPRESSION:
case ViewPackage.RECTANGULAR_NODE_STYLE_DESCRIPTION__HEIGHT_COMPUTATION_EXPRESSION:
case ViewPackage.RECTANGULAR_NODE_STYLE_DESCRIPTION__SHOW_ICON:
case ViewPackage.RECTANGULAR_NODE_STYLE_DESCRIPTION__LABEL_ICON:
case ViewPackage.RECTANGULAR_NODE_STYLE_DESCRIPTION__WITH_HEADER:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
Expand Down
Expand Up @@ -77,7 +77,8 @@ public class ViewPropertiesDescriptionRegistryConfigurer implements IPropertiesD
private static final List<EClass> TYPES_WITH_CUSTOM_PROPERTIES = List.of(
ViewPackage.Literals.IMAGE_NODE_STYLE_DESCRIPTION,
ViewPackage.Literals.ICON_LABEL_NODE_STYLE_DESCRIPTION,
ViewPackage.Literals.RECTANGULAR_NODE_STYLE_DESCRIPTION
ViewPackage.Literals.RECTANGULAR_NODE_STYLE_DESCRIPTION,
ViewPackage.Literals.EDGE_STYLE
);
// @formatter:on
private final IObjectService objectService;
Expand Down
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2023 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.emf.compatibility;

import java.util.List;
import java.util.function.Function;

import org.eclipse.sirius.components.representations.VariableManager;

/**
* Configuration for the properties view for some of the View DSL elements.
*
* @author mcharfadi
*/
public interface IPropertiesConfigurerService {

Function<VariableManager, List<?>> getDiagnosticsProvider(Object feature);

Function<Object, String> getKindProvider();

Function<Object, String> getMessageProvider();

Function<VariableManager, String> getTargetObjectIdProvider();
}
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2023 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.emf.compatibility;

import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;

import org.eclipse.sirius.components.forms.description.AbstractControlDescription;
import org.eclipse.sirius.components.forms.description.CheckboxDescription;
import org.eclipse.sirius.components.forms.description.GroupDescription;
import org.eclipse.sirius.components.forms.description.PageDescription;
import org.eclipse.sirius.components.representations.VariableManager;

/**
* Customizes the properties view for some of the View DSL elements.
*
* @author mcharfadi
*/
public interface IPropertiesWidgetCreationService {

PageDescription createSimplePageDescription(GroupDescription groupDescription, Predicate<VariableManager> canCreatePredicate);

GroupDescription createSimpleGroupDescription(List<AbstractControlDescription> controls);

CheckboxDescription createCheckbox(String id, String title, Function<Object, Boolean> reader, BiConsumer<Object, Boolean> writer, Object feature);
}
@@ -0,0 +1,104 @@
/*******************************************************************************
* Copyright (c) 2023 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.emf.compatibility;

import java.util.List;
import java.util.Objects;
import java.util.function.Function;

import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.sirius.components.collaborative.validation.api.IValidationService;
import org.eclipse.sirius.components.representations.VariableManager;
import org.springframework.stereotype.Service;

/**
* Configuration for the properties view for some of the View DSL elements.
*
* @author mcharfadi
*/
@Service
public class PropertiesConfigurerService implements IPropertiesConfigurerService {

private final IValidationService validationService;

public PropertiesConfigurerService(IValidationService validationService) {
this.validationService = Objects.requireNonNull(validationService);
}

@Override
public Function<VariableManager, String> getTargetObjectIdProvider() {
// @formatter:off
return variableManager -> variableManager.get(VariableManager.SELF, Object.class)
.filter(self -> self instanceof List<?>)
.map(self -> (List<?>) self)
.flatMap(self -> self.stream().findFirst())
.filter(EObject.class::isInstance)
.map(EObject.class::cast)
.map(obj -> EcoreUtil.getURI(obj).toString())
.orElse(null);
// @formatter:on
}

@Override
public Function<VariableManager, List<?>> getDiagnosticsProvider(Object feature) {
return variableManager -> {
var optionalSelf = variableManager.get(VariableManager.SELF, EObject.class);

if (optionalSelf.isPresent()) {
EObject self = optionalSelf.get();
List<Object> diagnostics = this.validationService.validate(self, feature);
return diagnostics;
}

return List.of();
};
}

@Override
public Function<Object, String> getKindProvider() {
return object -> {
String kind = "Unknown";
if (object instanceof Diagnostic) {
Diagnostic diagnostic = (Diagnostic) object;
switch (diagnostic.getSeverity()) {
case org.eclipse.emf.common.util.Diagnostic.ERROR:
kind = "Error";
break;
case org.eclipse.emf.common.util.Diagnostic.WARNING:
kind = "Warning";
break;
case org.eclipse.emf.common.util.Diagnostic.INFO:
kind = "Info";
break;
default:
kind = "Unknown";
break;
}
}
return kind;
};
}

@Override
public Function<Object, String> getMessageProvider() {
return object -> {
if (object instanceof Diagnostic) {
Diagnostic diagnostic = (Diagnostic) object;
return diagnostic.getMessage();
}
return "";
};
}
}

0 comments on commit d010602

Please sign in to comment.