Skip to content

Commit

Permalink
[2004] Add an optional icon to select widget options
Browse files Browse the repository at this point in the history
Bug: #2004
Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
  • Loading branch information
mcharfadi committed Jun 21, 2023
1 parent aadf3f9 commit 60d6796
Show file tree
Hide file tree
Showing 48 changed files with 725 additions and 57 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ An absent/empty candidates expression now simply means the widget is empty.
=== New Features

- https://github.com/eclipse-sirius/sirius-components/issues/2039[#2039] [project] A new "Blank Studio" project template is available to create a project with the "studio" nature but no initial content
- 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%]

=== Improvements

Expand Down
Binary file added doc/screenshots/ShowIconOptionSelectWidget.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 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
Expand Down Expand Up @@ -90,6 +90,7 @@ private SelectDescription getSelectDescription() {
.optionsProvider(this.getOptionsProvider())
.optionIdProvider(this.getOptionIdProvider())
.optionLabelProvider(this.getOptionLabelProvider())
.optionIconURLProvider(variableManager -> variableManager.get(SelectComponent.CANDIDATE_VARIABLE, Object.class).map(this.objectService::getImagePath).orElse(""))
.newValueHandler(this.getNewValueHandler())
.diagnosticsProvider(this.propertiesValidationProvider.getDiagnosticsProvider())
.kindProvider(this.propertiesValidationProvider.getKindProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private MultiSelectDescription getMultiSelectDescription() {
.optionsProvider(this.getOptionsProvider())
.optionIdProvider(this.getOptionIdProvider())
.optionLabelProvider(this.getOptionLabelProvider())
.optionIconURLProvider(variableManager -> variableManager.get(SelectComponent.CANDIDATE_VARIABLE, Object.class).map(this.objectService::getImagePath).orElse(""))
.newValuesHandler(this.getNewValuesHandler())
.diagnosticsProvider(this.propertiesValidationProvider.getDiagnosticsProvider())
.kindProvider(this.propertiesValidationProvider.getKindProvider())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 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
Expand Down Expand Up @@ -260,6 +260,7 @@ private SelectDescription convertSelect(org.eclipse.sirius.properties.SelectDesc
.optionsProvider(optionsProvider)
.optionIdProvider(optionIdProvider)
.optionLabelProvider(optionLabelProvider)
.optionIconURLProvider(vm -> "")
.newValueHandler(newValueHandler)
.diagnosticsProvider(variableManager -> List.of())
.kindProvider(object -> "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedImage;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.ReflectiveItemProvider;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.emf.services.api.IEMFKindService;
Expand Down Expand Up @@ -151,10 +151,10 @@ public String getFullLabel(Object object) {

@Override
public String getImagePath(Object object) {
if (object instanceof EObject eObject && !(object instanceof DynamicEObjectImpl)) {
if (object instanceof EObject eObject) {

Adapter adapter = this.composedAdapterFactory.adapt(eObject, IItemLabelProvider.class);
if (adapter instanceof IItemLabelProvider labelProvider) {
if (adapter instanceof IItemLabelProvider labelProvider && !(adapter instanceof ReflectiveItemProvider)) {
try {
Object image = labelProvider.getImage(eObject);
String imageFullPath = this.findImagePath(image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public MultiSelectStyle build() {
boolean bold = this.viewStyle.isBold();
boolean underline = this.viewStyle.isUnderline();
boolean strikeThrough = this.viewStyle.isStrikeThrough();
boolean isShowIcon = this.viewStyle.isShowIcon();

// @formatter:off
return multiSelectStyleBuilder
Expand All @@ -63,6 +64,7 @@ public MultiSelectStyle build() {
.bold(bold)
.underline(underline)
.strikeThrough(strikeThrough)
.showIcon(isShowIcon)
.build();
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public SelectStyle build() {
boolean bold = this.viewStyle.isBold();
boolean underline = this.viewStyle.isUnderline();
boolean strikeThrough = this.viewStyle.isStrikeThrough();
boolean isShowIcon = this.viewStyle.isShowIcon();

// @formatter:off
return selectStyleBuilder
Expand All @@ -63,6 +64,7 @@ public SelectStyle build() {
.bold(bold)
.underline(underline)
.strikeThrough(strikeThrough)
.showIcon(isShowIcon)
.build();
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public AbstractWidgetDescription caseSelectDescription(org.eclipse.sirius.compon
.valueProvider(vm -> "")
.optionIdProvider(vm -> "")
.optionLabelProvider(vm -> "")
.optionIconURLProvider(vm -> "")
.optionsProvider(vm -> List.of())
.newValueHandler((vm, value) -> new Success())
.diagnosticsProvider(vm -> List.of())
Expand Down Expand Up @@ -228,6 +229,7 @@ public AbstractWidgetDescription caseMultiSelectDescription(org.eclipse.sirius.c
.valuesProvider(vm -> List.of())
.optionIdProvider(vm -> "")
.optionLabelProvider(vm -> "")
.optionIconURLProvider(vm -> "")
.optionsProvider(vm -> List.of())
.newValuesHandler((vm, values) -> new Success())
.diagnosticsProvider(vm -> List.of())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type Select implements Widget {
type SelectOption {
id: ID!
label: String!
iconURL: String
}

type SelectStyle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
<artifactId>sirius-components-annotations-spring</artifactId>
<version>2023.6.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-forms</artifactId>
<version>2023.6.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-collaborative-forms</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* 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.forms.graphql.datafetchers.form;

import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.forms.SelectOption;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.URLConstants;

import graphql.schema.DataFetchingEnvironment;

/**
* Data fetcher for SelectOption.iconURL, to rewrite the relative path of the image into an absolute path on the server.
* <p>
* 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>.
*
* @author mcharfadi
*/
@QueryDataFetcher(type = "SelectOption", field = "iconURL")
public class SelectOptionIconURLDataFetcher implements IDataFetcherWithFieldCoordinates<String> {

@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;
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 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
Expand Down Expand Up @@ -29,6 +29,8 @@ public final class MultiSelectStyle extends AbstractFontStyle {

private String foregroundColor;

private boolean showIcon;

private MultiSelectStyle() {
// Prevent instantiation
}
Expand All @@ -41,14 +43,18 @@ public String getForegroundColor() {
return this.foregroundColor;
}

public boolean isShowIcon() {
return this.showIcon;
}

public static Builder newMultiSelectStyle() {
return new Builder();
}

@Override
public String toString() {
String pattern = "{0} '{'backgroundColor: {1}, foregroundColor: {2}, fontSize: {3}, italic: {4}, bold: {5}, underline: {6}, strikeThrough: {7},'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.backgroundColor, this.foregroundColor, this.fontSize, this.italic, this.bold, this.underline, this.strikeThrough);
String pattern = "{0} '{'backgroundColor: {1}, foregroundColor: {2}, fontSize: {3}, italic: {4}, bold: {5}, underline: {6}, strikeThrough: {7}, isShowIcon: {8'}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.backgroundColor, this.foregroundColor, this.fontSize, this.italic, this.bold, this.underline, this.strikeThrough, this.showIcon);
}

/**
Expand All @@ -72,6 +78,8 @@ public static final class Builder {

private boolean strikeThrough;

private boolean showIcon;

private Builder() {
}

Expand Down Expand Up @@ -100,6 +108,11 @@ public Builder bold(boolean bold) {
return this;
}

public Builder showIcon(boolean showIcon) {
this.showIcon = showIcon;
return this;
}

public Builder underline(boolean underline) {
this.underline = underline;
return this;
Expand All @@ -119,6 +132,7 @@ public MultiSelectStyle build() {
multiSelectStyle.bold = this.bold;
multiSelectStyle.underline = this.underline;
multiSelectStyle.strikeThrough = this.strikeThrough;
multiSelectStyle.showIcon = this.showIcon;
return multiSelectStyle;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 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
Expand Down Expand Up @@ -28,6 +28,8 @@ public final class SelectOption {

private String label;

private String iconURL;

private SelectOption() {
// Prevent instantiation
}
Expand All @@ -40,14 +42,18 @@ public String getLabel() {
return this.label;
}

public String getIconURL() {
return this.iconURL;
}

public static Builder newSelectOption(String id) {
return new Builder(id);
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, label: {2}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.label);
String pattern = "{0} '{'id: {1}, label: {2}', iconUrl: {3}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.label, this.iconURL);
}

/**
Expand All @@ -61,6 +67,8 @@ public static final class Builder {

private String label;

private String iconURL;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand All @@ -70,10 +78,16 @@ public Builder label(String label) {
return this;
}

public Builder iconURL(String iconURL) {
this.iconURL = iconURL;
return this;
}

public SelectOption build() {
SelectOption selectOption = new SelectOption();
selectOption.id = Objects.requireNonNull(this.id);
selectOption.label = Objects.requireNonNull(this.label);
selectOption.iconURL = this.iconURL;
return selectOption;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 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
Expand Down Expand Up @@ -28,6 +28,8 @@ public final class SelectStyle extends AbstractFontStyle {

private String foregroundColor;

private boolean showIcon;

private SelectStyle() {
// Prevent instantiation
}
Expand All @@ -40,14 +42,18 @@ public String getForegroundColor() {
return this.foregroundColor;
}

public boolean isShowIcon() {
return this.showIcon;
}

public static Builder newSelectStyle() {
return new Builder();
}

@Override
public String toString() {
String pattern = "{0} '{'backgroundColor: {1}, foregroundColor: {2}, fontSize: {3}, italic: {4}, bold: {5}, underline: {6}, strikeThrough: {7},'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.backgroundColor, this.foregroundColor, this.fontSize, this.italic, this.bold, this.underline, this.strikeThrough);
String pattern = "{0} '{'backgroundColor: {1}, foregroundColor: {2}, fontSize: {3}, italic: {4}, bold: {5}, underline: {6}, strikeThrough: {7}, isShowIcon: {8'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.backgroundColor, this.foregroundColor, this.fontSize, this.italic, this.bold, this.underline, this.strikeThrough, this.showIcon);
}

/**
Expand All @@ -71,6 +77,8 @@ public static final class Builder {

private boolean strikeThrough;

private boolean showIcon;

private Builder() {
}

Expand Down Expand Up @@ -99,6 +107,11 @@ public Builder bold(boolean bold) {
return this;
}

public Builder showIcon(boolean showIcon) {
this.showIcon = showIcon;
return this;
}

public Builder underline(boolean underline) {
this.underline = underline;
return this;
Expand All @@ -118,6 +131,7 @@ public SelectStyle build() {
selectStyle.bold = this.bold;
selectStyle.underline = this.underline;
selectStyle.strikeThrough = this.strikeThrough;
selectStyle.showIcon = this.showIcon;
return selectStyle;
}

Expand Down
Loading

0 comments on commit 60d6796

Please sign in to comment.