Skip to content

Commit

Permalink
[1281] Add support for Link widget in Form representation
Browse files Browse the repository at this point in the history
Bug: #1281
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
  • Loading branch information
florianbarbin committed Aug 25, 2022
1 parent 6f916f8 commit 043cecf
Show file tree
Hide file tree
Showing 40 changed files with 3,683 additions and 26 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.adoc
Expand Up @@ -17,6 +17,9 @@ https://github.com/eclipse-sirius/sirius-components/issues/1231[#1231] [workbenc
https://github.com/eclipse-sirius/sirius-components/issues/1231[#1231] [workbench] Move the workbench related code to `@eclipse-sirius/sirius-components-core`. This move includes components such as `Workbench`, `RepresentationContext`, `WorkbenchViewContribution` for example
https://github.com/eclipse-sirius/sirius-components/issues/1231[#1231] [diagram] Move the code of the diagram and the selection wizard in the packages `@eclipse-sirius/sirius-components-diagrams` and `@eclipse-sirius/sirius-components-selection`
- https://github.com/eclipse-sirius/sirius-components/issues/1231[#1231] [core] Some code remain in the soon to be deprecated Sirius Component package `@eclipse-sirius/sirius-components`. Most of this code will either be moved to Sirius Web or be removed entirely (such as the old non MaterialUI widgets)
- https://github.com/eclipse-sirius/sirius-components/issues/1281[#1281] [form] The `LinkDescription` now requires a `displayProvider` and a `styleProvider`. The `displayProvider` is used to display the text of the hyperLink.
The GraphQL API has also been changed with two additional fields on the type `Link`: `display` and `style` (optional). The front-end use the `display` value instead of the `label` value to display the hyperlink text.
The `label` value is displayed before the widget to be consistent with other properties sections.


=== Dependency update
Expand All @@ -43,6 +46,9 @@ https://github.com/eclipse-sirius/sirius-components/issues/1231[#1231] [diagram]
- https://github.com/eclipse-sirius/sirius-components/issues/1265[#1265] [form] Add support for flexbox containers on FormDescriptionEditors
- https://github.com/eclipse-sirius/sirius-components/issues/1272[#1272] [form] Add support for button widget on FormDescriptions
- https://github.com/eclipse-sirius/sirius-components/issues/1273[#1273] [form] Add support for button widget on FormDescriptionEditors
- https://github.com/eclipse-sirius/sirius-components/issues/1266[#1266] [form] Add styling support on bar-chart and pie-chart Widgets in View DSL
- https://github.com/eclipse-sirius/sirius-components/issues/1275[#1275] [form] Add support for Label widget in Form representation
- https://github.com/eclipse-sirius/sirius-components/issues/1281[#1281] [form] Add support for Link widget in Form representation

== v2022.7.0

Expand Down Expand Up @@ -98,8 +104,6 @@ The actual definition of the application (e.g. Sirius Web), which must provide a
- https://github.com/eclipse-sirius/sirius-components/issues/1244[#1244] [form] Add support for flexbox containers on FormDescriptions
- https://github.com/eclipse-sirius/sirius-components/issues/1139[#1139] [form] Add support for a new Tree widget
- https://github.com/eclipse-sirius/sirius-components/issues/1140[#1140] [form] Widget groups now support a new setting (`displayMode = TOGGLEABLE_AREAS`) which allows end-users to select which of the widgets in the group are visible, and adapts their layout to the available horizontal space.
- https://github.com/eclipse-sirius/sirius-components/issues/1266[#1266] [form] Add styling support on bar-chart and pie-chart Widgets in View DSL
- https://github.com/eclipse-sirius/sirius-components/issues/1275[#1275] [form] Add support for label widget in forms

== v2022.5.0

Expand Down
Expand Up @@ -250,6 +250,17 @@ type Link implements Widget {
label: String!
iconURL: String
url: String!
display: String!
style: LinkStyle
}

type LinkStyle {
color: String
fontSize: Int
italic: Boolean
bold: Boolean
underline: Boolean
strikeThrough: Boolean
}

type Button implements Widget {
Expand Down
Expand Up @@ -29,6 +29,10 @@ public final class Link extends AbstractWidget {

private String url;

private String display;

private LinkStyle style;

private Link() {
// Prevent instantiation
}
Expand All @@ -37,14 +41,22 @@ public String getUrl() {
return this.url;
}

public String getDisplay() {
return this.display;
}

public LinkStyle getStyle() {
return this.style;
}

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

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, label: {2}, url: {3}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.getId(), this.label, this.url);
String pattern = "{0} '{'id: {1}, label: {2}, url: {3}, display: {4}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.getId(), this.label, this.url, this.display);
}

/**
Expand All @@ -62,6 +74,10 @@ public static final class Builder {

private String url;

private String display;

private LinkStyle style;

private List<Diagnostic> diagnostics;

private Builder(String id) {
Expand All @@ -83,6 +99,16 @@ public Builder url(String value) {
return this;
}

public Builder display(String display) {
this.display = Objects.requireNonNull(display);
return this;
}

public Builder style(LinkStyle style) {
this.style = Objects.requireNonNull(style);
return this;
}

public Builder diagnostics(List<Diagnostic> diagnostics) {
this.diagnostics = Objects.requireNonNull(diagnostics);
return this;
Expand All @@ -94,6 +120,8 @@ public Link build() {
link.label = Objects.requireNonNull(this.label);
link.iconURL = this.iconURL;
link.url = Objects.requireNonNull(this.url);
link.display = Objects.requireNonNull(this.display);
link.style = this.style; // Optional on purpose
link.diagnostics = Objects.requireNonNull(this.diagnostics);
return link;
}
Expand Down
@@ -0,0 +1,112 @@
/*******************************************************************************
* Copyright (c) 2022 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;

import java.text.MessageFormat;
import java.util.Objects;

import org.eclipse.sirius.components.annotations.Immutable;

/**
* The style of a Link Widget.
*
* @author fbarbin
*/
@Immutable
public final class LinkStyle extends AbstractFontStyle {

private String color;

private LinkStyle() {
// Prevent instantiation
}

public String getColor() {
return this.color;
}

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

@Override
public String toString() {
String pattern = "{0} '{'color: {1}, fontSize: {2}, italic: {3}, bold: {4}, underline: {5}, strikeThrough: {6},'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.color, this.fontSize, this.italic, this.bold, this.underline, this.strikeThrough);
}

/**
* Builder used to create the Link style.
*
* @author fbarbin
*/
@SuppressWarnings("checkstyle:HiddenField")
public static final class Builder {
private String color;

private int fontSize;

private boolean italic;

private boolean bold;

private boolean underline;

private boolean strikeThrough;

private Builder() {
}

public Builder color(String color) {
this.color = Objects.requireNonNull(color);
return this;
}

public Builder fontSize(int fontSize) {
this.fontSize = fontSize;
return this;
}

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

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

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

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

public LinkStyle build() {
LinkStyle linkStyle = new LinkStyle();
linkStyle.color = this.color;
linkStyle.fontSize = this.fontSize;
linkStyle.italic = this.italic;
linkStyle.bold = this.bold;
linkStyle.underline = this.underline;
linkStyle.strikeThrough = this.strikeThrough;
return linkStyle;
}

}
}
Expand Up @@ -15,9 +15,9 @@
import java.util.List;
import java.util.Objects;

import org.eclipse.sirius.components.forms.LinkStyle;
import org.eclipse.sirius.components.forms.description.LinkDescription;
import org.eclipse.sirius.components.forms.elements.LinkElementProps;
import org.eclipse.sirius.components.forms.elements.LinkElementProps.Builder;
import org.eclipse.sirius.components.forms.validation.DiagnosticComponent;
import org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps;
import org.eclipse.sirius.components.representations.Element;
Expand Down Expand Up @@ -46,15 +46,28 @@ public Element render() {
String label = linkDescription.getLabelProvider().apply(variableManager);
String iconURL = linkDescription.getIconURLProvider().apply(variableManager);
String url = linkDescription.getUrlProvider().apply(variableManager);
VariableManager displayVariableManager = variableManager.createChild();
displayVariableManager.put(LinkDescription.VALUE, url);
String display = linkDescription.getDisplayProvider().apply(displayVariableManager);
LinkStyle style = linkDescription.getStyleProvider().apply(variableManager);
List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(linkDescription, variableManager)));

// @formatter:on
Builder linkElementPropsBuilder = LinkElementProps.newLinkElementProps(id).label(label).url(url).children(children);
// @formatter:off
LinkElementProps.Builder linkElementPropsBuilder = LinkElementProps.newLinkElementProps(id)
.label(label)
.url(url)
.display(display)
.children(children);
// @formatter:on

if (style != null) {
linkElementPropsBuilder.style(style);
}
if (iconURL != null) {
linkElementPropsBuilder.iconURL(iconURL);
}
return new Element(LinkElementProps.TYPE, linkElementPropsBuilder.build());

LinkElementProps linkElementProps = linkElementPropsBuilder.build();
return new Element(LinkElementProps.TYPE, linkElementProps);
}
}
Expand Up @@ -18,6 +18,7 @@
import java.util.function.Function;

import org.eclipse.sirius.components.annotations.Immutable;
import org.eclipse.sirius.components.forms.LinkStyle;
import org.eclipse.sirius.components.representations.VariableManager;

/**
Expand All @@ -27,6 +28,8 @@
*/
@Immutable
public final class LinkDescription extends AbstractWidgetDescription {
public static final String VALUE = "value"; //$NON-NLS-1$

private Function<VariableManager, String> idProvider;

private Function<VariableManager, String> labelProvider;
Expand All @@ -35,6 +38,10 @@ public final class LinkDescription extends AbstractWidgetDescription {

private Function<VariableManager, String> urlProvider;

private Function<VariableManager, String> displayProvider;

private Function<VariableManager, LinkStyle> styleProvider;

private LinkDescription() {
// Prevent instantiation
}
Expand All @@ -55,6 +62,14 @@ public Function<VariableManager, String> getUrlProvider() {
return this.urlProvider;
}

public Function<VariableManager, String> getDisplayProvider() {
return this.displayProvider;
}

public Function<VariableManager, LinkStyle> getStyleProvider() {
return this.styleProvider;
}

public static Builder newLinkDescription(String id) {
return new Builder(id);
}
Expand Down Expand Up @@ -82,6 +97,10 @@ public static final class Builder {

private Function<VariableManager, String> urlProvider;

private Function<VariableManager, String> displayProvider;

private Function<VariableManager, LinkStyle> styleProvider;

private Function<VariableManager, List<?>> diagnosticsProvider;

private Function<Object, String> kindProvider;
Expand Down Expand Up @@ -112,6 +131,16 @@ public Builder urlProvider(Function<VariableManager, String> valueProvider) {
return this;
}

public Builder displayProvider(Function<VariableManager, String> displayProvider) {
this.displayProvider = Objects.requireNonNull(displayProvider);
return this;
}

public Builder styleProvider(Function<VariableManager, LinkStyle> styleProvider) {
this.styleProvider = Objects.requireNonNull(styleProvider);
return this;
}

public Builder diagnosticsProvider(Function<VariableManager, List<?>> diagnosticsProvider) {
this.diagnosticsProvider = Objects.requireNonNull(diagnosticsProvider);
return this;
Expand All @@ -134,6 +163,8 @@ public LinkDescription build() {
linkDescription.labelProvider = Objects.requireNonNull(this.labelProvider);
linkDescription.iconURLProvider = Objects.requireNonNull(this.iconURLProvider);
linkDescription.urlProvider = Objects.requireNonNull(this.urlProvider);
linkDescription.displayProvider = Objects.requireNonNull(this.displayProvider);
linkDescription.styleProvider = Objects.requireNonNull(this.styleProvider);
linkDescription.diagnosticsProvider = Objects.requireNonNull(this.diagnosticsProvider);
linkDescription.kindProvider = Objects.requireNonNull(this.kindProvider);
linkDescription.messageProvider = Objects.requireNonNull(this.messageProvider);
Expand Down

0 comments on commit 043cecf

Please sign in to comment.