Skip to content

Commit

Permalink
[1233] Handle Form Description Widgets styles
Browse files Browse the repository at this point in the history
Handle the styling of the Select, MultiSelect, Textarea, Radio, Checkbox
widgets from View DSL.

Bug: eclipse-sirius#1233
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
  • Loading branch information
AxelRICHARD committed May 31, 2022
1 parent f1ea560 commit 2d030f0
Show file tree
Hide file tree
Showing 102 changed files with 9,826 additions and 229 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
=== New features

- https://github.com/eclipse-sirius/sirius-components/issues/1212[#1212] [form] Add styling support on Textfield Widget in View DSL

- https://github.com/eclipse-sirius/sirius-components/issues/1233[#1233] [form] Handle styling of the View DSL widgets

== v2022.5.0

Expand Down Expand Up @@ -88,6 +88,7 @@ When closed, clicking on any of the views' icon will re-open the panel to make t
- https://github.com/eclipse-sirius/sirius-components/issues/1181[#1181] [form] Add backend for a form description editor
- https://github.com/eclipse-sirius/sirius-components/issues/1201[#1201] [charts] Prepare support for charts in Sirius Components
- https://github.com/eclipse-sirius/sirius-components/issues/1180[#1180] [diagram] Add support for the dynamic computation of the connector tools to control the tools displayed in the contextual menu.
- https://github.com/eclipse-sirius/sirius-components/issues/1212[#1212] [form] Add support for styling of the View DSL widgets

== v2022.3.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.sirius.components.collaborative.api.ChangeDescription;
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.api.Monitoring;
Expand All @@ -32,6 +33,7 @@
import org.eclipse.sirius.components.view.FormDescription;
import org.eclipse.sirius.components.view.ViewFactory;
import org.eclipse.sirius.components.view.WidgetDescription;
import org.eclipse.sirius.components.view.WidgetDescriptionStyle;
import org.springframework.stereotype.Service;

import io.micrometer.core.instrument.Counter;
Expand Down Expand Up @@ -101,6 +103,7 @@ protected boolean addWidget(IEditingContext editingContext, IFormDescriptionEdit
if (eClassifier instanceof EClass) {
var widgetDescription = ViewFactory.eINSTANCE.create((EClass) eClassifier);
if (widgetDescription instanceof WidgetDescription) {
this.createStyle((WidgetDescription) widgetDescription);
((FormDescription) formDescription).getWidgets().add(index, (WidgetDescription) widgetDescription);
return true;
}
Expand All @@ -109,4 +112,15 @@ protected boolean addWidget(IEditingContext editingContext, IFormDescriptionEdit
}
return false;
}

private void createStyle(WidgetDescription widgetDescription) {
EClassifier eClassifier = ViewFactory.eINSTANCE.getEPackage().getEClassifier(widgetDescription.eClass().getName() + "Style"); //$NON-NLS-1$
if (eClassifier instanceof EClass) {
var widgetDescriptionStyle = ViewFactory.eINSTANCE.create((EClass) eClassifier);
if (widgetDescriptionStyle instanceof WidgetDescriptionStyle) {
EStructuralFeature styleFeature = widgetDescription.eClass().getEStructuralFeature("style"); //$NON-NLS-1$
widgetDescription.eSet(styleFeature, widgetDescriptionStyle);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ type Checkbox implements Widget {
diagnostics: [Diagnostic!]!
label: String!
value: Boolean!
style: CheckboxStyle
}

type CheckboxStyle {
color: String
}

type List implements Widget {
Expand All @@ -95,13 +100,25 @@ type MultiSelect implements Widget {
label: String!
options: [SelectOption!]!
values: [String]
style: MultiSelectStyle
}

type MultiSelectStyle {
backgroundColor: String
foregroundColor: String
fontSize: Int
italic: Boolean
bold: Boolean
underline: Boolean
strikeThrough: Boolean
}

type Radio implements Widget {
id: ID!
diagnostics: [Diagnostic!]!
label: String!
options: [RadioOption!]!
style: RadioStyle
}

type RadioOption {
Expand All @@ -110,27 +127,58 @@ type RadioOption {
selected: Boolean!
}

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

type Select implements Widget {
id: ID!
diagnostics: [Diagnostic!]!
label: String!
options: [SelectOption!]!
value: String
style: SelectStyle
}

type SelectOption {
id: ID!
label: String!
}

type SelectStyle {
backgroundColor: String
foregroundColor: String
fontSize: Int
italic: Boolean
bold: Boolean
underline: Boolean
strikeThrough: Boolean
}

type Textarea implements Widget {
id: ID!
diagnostics: [Diagnostic!]!
label: String!
value: String!
style: TextareaStyle
}

type TextareaStyle {
backgroundColor: String
foregroundColor: String
fontSize: Int
italic: Boolean
bold: Boolean
underline: Boolean
strikeThrough: Boolean
}


type Textfield implements Widget {
id: ID!
diagnostics: [Diagnostic!]!
Expand All @@ -142,6 +190,11 @@ type Textfield implements Widget {
type TextfieldStyle {
backgroundColor: String
foregroundColor: String
fontSize: Int
italic: Boolean
bold: Boolean
underline: Boolean
strikeThrough: Boolean
}

type Link implements Widget {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* 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.emf.view.form;

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

import org.eclipse.sirius.components.forms.CheckboxStyle;
import org.eclipse.sirius.components.forms.CheckboxStyle.Builder;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.view.CheckboxDescriptionStyle;

/**
* The style provider for the Checkbox Description widget of the View DSL.
*
* @author arichard
*/
public class CheckboxStyleProvider implements Function<VariableManager, CheckboxStyle> {

private final CheckboxDescriptionStyle viewStyle;

public CheckboxStyleProvider(CheckboxDescriptionStyle viewStyle) {
this.viewStyle = Objects.requireNonNull(viewStyle);
}

@Override
public CheckboxStyle apply(VariableManager variableManager) {
Builder checkboxStyleBuilder = CheckboxStyle.newCheckboxStyle();

String color = this.viewStyle.getColor();
if (color != null && !color.isBlank()) {
checkboxStyleBuilder.color(color);
}

return checkboxStyleBuilder.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* 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.emf.view.form;

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

import org.eclipse.sirius.components.forms.MultiSelectStyle;
import org.eclipse.sirius.components.forms.MultiSelectStyle.Builder;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.view.MultiSelectDescriptionStyle;

/**
* The style provider for the MultiSelect Description widget of the View DSL.
*
* @author arichard
*/
public class MultiSelectStyleProvider implements Function<VariableManager, MultiSelectStyle> {

private final MultiSelectDescriptionStyle viewStyle;

public MultiSelectStyleProvider(MultiSelectDescriptionStyle viewStyle) {
this.viewStyle = Objects.requireNonNull(viewStyle);
}

@Override
public MultiSelectStyle apply(VariableManager variableManager) {
Builder multiSelectStyleBuilder = MultiSelectStyle.newMultiSelectStyle();

String backgroundColor = this.viewStyle.getBackgroundColor();
if (backgroundColor != null && !backgroundColor.isBlank()) {
multiSelectStyleBuilder.backgroundColor(backgroundColor);
}
String foregroundColor = this.viewStyle.getForegroundColor();
if (foregroundColor != null && !foregroundColor.isBlank()) {
multiSelectStyleBuilder.foregroundColor(foregroundColor);
}
int fontSize = this.viewStyle.getFontSize();
boolean italic = this.viewStyle.isItalic();
boolean bold = this.viewStyle.isBold();
boolean underline = this.viewStyle.isUnderline();
boolean strikeThrough = this.viewStyle.isStrikeThrough();

// @formatter:off
return multiSelectStyleBuilder
.fontSize(fontSize)
.italic(italic)
.bold(bold)
.underline(underline)
.strikeThrough(strikeThrough)
.build();
// @formatter:on
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*******************************************************************************
* 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.emf.view.form;

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

import org.eclipse.sirius.components.forms.RadioStyle;
import org.eclipse.sirius.components.forms.RadioStyle.Builder;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.view.RadioDescriptionStyle;

/**
* The style provider for the Radio Description widget of the View DSL.
*
* @author arichard
*/
public class RadioStyleProvider implements Function<VariableManager, RadioStyle> {

private final RadioDescriptionStyle viewStyle;

public RadioStyleProvider(RadioDescriptionStyle viewStyle) {
this.viewStyle = Objects.requireNonNull(viewStyle);
}

@Override
public RadioStyle apply(VariableManager variableManager) {
Builder radioStyleBuilder = RadioStyle.newRadioStyle();

String color = this.viewStyle.getColor();
if (color != null && !color.isBlank()) {
radioStyleBuilder.color(color);
}
int fontSize = this.viewStyle.getFontSize();
boolean italic = this.viewStyle.isItalic();
boolean bold = this.viewStyle.isBold();
boolean underline = this.viewStyle.isUnderline();
boolean strikeThrough = this.viewStyle.isStrikeThrough();

// @formatter:off
return radioStyleBuilder
.fontSize(fontSize)
.italic(italic)
.bold(bold)
.underline(underline)
.strikeThrough(strikeThrough)
.build();
// @formatter:on
}

}
Loading

0 comments on commit 2d030f0

Please sign in to comment.