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 8, 2023
1 parent 26f9cf3 commit 88ae46a
Show file tree
Hide file tree
Showing 22 changed files with 1,111 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -92,6 +92,7 @@ Introducing a generator of builders aimed to help creating view programmatically
- 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 @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.components.forms.graphql.datafetchers.form;

import java.util.regex.Pattern;

import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.forms.SelectOption;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
Expand All @@ -25,17 +27,26 @@
* If the <code>SelectOption.iconURL</code> is of the form <code>path/to/image.svg</code>, the rewritten value which will
* be seen by the frontend will be <code>/api/images/path/to/image.svg</code>.
*
* If the <code>SelectOption.iconURL</code> is of the form <code>path/to/UUID.svg</code>, the rewritten value which will
* be seen by the frontend will be <code>/api/images/custom/path/to/image.svg</code>.
*
* @author mcharfadi
*/
@QueryDataFetcher(type = "SelectOption", field = "iconURL")
public class SelectOptionIconURLDataFetcher implements IDataFetcherWithFieldCoordinates<String> {

private static final Pattern UUID_REGEX =
Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
@Override
public String get(DataFetchingEnvironment environment) throws Exception {
SelectOption option = environment.getSource();
String result = option.getIconURL();
if (result != null && !result.isBlank()) {
result = URLConstants.IMAGE_BASE_PATH + result;
if (UUID_REGEX.matcher(result).matches()) {
result = URLConstants.IMAGE_BASE_PATH + "/custom/" + result;
}
else {
result = URLConstants.IMAGE_BASE_PATH + result;
}
}
return result;
}
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 comments on commit 88ae46a

Please sign in to comment.