use of org.eclipse.sirius.components.forms.description.TextfieldDescription in project sirius-components by eclipse-sirius.
the class NodeStylePropertiesConfigurer method createTextField.
private TextfieldDescription createTextField(String id, String title, Function<Object, String> reader, BiConsumer<Object, String> writer, Object feature) {
Function<VariableManager, String> valueProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(reader).orElse(EMPTY);
BiFunction<VariableManager, String, IStatus> newValueHandler = (variableManager, newValue) -> {
var optionalDiagramMapping = variableManager.get(VariableManager.SELF, Object.class);
if (optionalDiagramMapping.isPresent()) {
writer.accept(optionalDiagramMapping.get(), newValue);
return new Success();
} else {
// $NON-NLS-1$
return new Failure("");
}
};
// @formatter:off
return TextfieldDescription.newTextfieldDescription(id).idProvider(variableManager -> id).labelProvider(variableManager -> title).valueProvider(valueProvider).newValueHandler(newValueHandler).diagnosticsProvider(this.getDiagnosticsProvider(feature)).kindProvider(this::kindProvider).messageProvider(this::messageProvider).build();
// @formatter:on
}
use of org.eclipse.sirius.components.forms.description.TextfieldDescription in project sirius-components by eclipse-sirius.
the class TextfieldComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
TextfieldDescription textfieldDescription = this.props.getTextfieldDescription();
String id = textfieldDescription.getIdProvider().apply(variableManager);
String label = textfieldDescription.getLabelProvider().apply(variableManager);
String value = textfieldDescription.getValueProvider().apply(variableManager);
BiFunction<VariableManager, String, IStatus> genericHandler = textfieldDescription.getNewValueHandler();
Function<String, IStatus> specializedHandler = newValue -> {
return genericHandler.apply(variableManager, newValue);
};
List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(textfieldDescription, variableManager)));
// @formatter:off
TextfieldElementProps textfieldElementProps = TextfieldElementProps.newTextfieldElementProps(id).label(label).value(value).newValueHandler(specializedHandler).children(children).build();
return new Element(TextfieldElementProps.TYPE, textfieldElementProps);
// @formatter:on
}
use of org.eclipse.sirius.components.forms.description.TextfieldDescription in project sirius-components by eclipse-sirius.
the class WidgetComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
AbstractWidgetDescription widgetDescription = this.props.getWidgetDescription();
Element element = null;
if (widgetDescription instanceof TextfieldDescription) {
TextfieldComponentProps textfieldProps = new TextfieldComponentProps(variableManager, (TextfieldDescription) widgetDescription);
element = new Element(TextfieldComponent.class, textfieldProps);
} else if (widgetDescription instanceof TextareaDescription) {
TextareaComponentProps textareaProps = new TextareaComponentProps(variableManager, (TextareaDescription) widgetDescription);
element = new Element(TextareaComponent.class, textareaProps);
} else if (widgetDescription instanceof CheckboxDescription) {
CheckboxComponentProps checkboxProps = new CheckboxComponentProps(variableManager, (CheckboxDescription) widgetDescription);
element = new Element(CheckboxComponent.class, checkboxProps);
} else if (widgetDescription instanceof SelectDescription) {
SelectComponentProps selectProps = new SelectComponentProps(variableManager, (SelectDescription) widgetDescription);
element = new Element(SelectComponent.class, selectProps);
} else if (widgetDescription instanceof MultiSelectDescription) {
MultiSelectComponentProps multiSelectProps = new MultiSelectComponentProps(variableManager, (MultiSelectDescription) widgetDescription);
element = new Element(MultiSelectComponent.class, multiSelectProps);
} else if (widgetDescription instanceof RadioDescription) {
RadioComponentProps radioProps = new RadioComponentProps(variableManager, (RadioDescription) widgetDescription);
element = new Element(RadioComponent.class, radioProps);
} else if (widgetDescription instanceof ListDescription) {
ListComponentProps listProps = new ListComponentProps(variableManager, (ListDescription) widgetDescription);
element = new Element(ListComponent.class, listProps);
} else if (widgetDescription instanceof LinkDescription) {
LinkComponentProps linkProps = new LinkComponentProps(variableManager, (LinkDescription) widgetDescription);
element = new Element(LinkComponent.class, linkProps);
} else {
// $NON-NLS-1$
String pattern = "Unsupported widget description: {}";
this.logger.warn(pattern, widgetDescription.getClass().getSimpleName());
}
return element;
}
use of org.eclipse.sirius.components.forms.description.TextfieldDescription in project sirius-components by eclipse-sirius.
the class WidgetDescriptionConverter method convertTextfield.
private TextfieldDescription convertTextfield(org.eclipse.sirius.properties.TextDescription textDescription) {
// $NON-NLS-1$
String labelExpression = Optional.ofNullable(textDescription.getLabelExpression()).orElse("");
StringValueProvider labelProvider = new StringValueProvider(this.interpreter, labelExpression);
// $NON-NLS-1$
String valueExpression = Optional.ofNullable(textDescription.getValueExpression()).orElse("");
StringValueProvider valueProvider = new StringValueProvider(this.interpreter, valueExpression);
BiFunction<VariableManager, String, IStatus> newValueHandler = this.getNewValueHandler(textDescription.getInitialOperation());
// @formatter:off
return TextfieldDescription.newTextfieldDescription(this.identifierProvider.getIdentifier(textDescription)).idProvider(new WidgetIdProvider()).labelProvider(labelProvider).valueProvider(valueProvider).newValueHandler(newValueHandler).diagnosticsProvider(this.getDiagnosticsProvider()).kindProvider(// $NON-NLS-1$
(object) -> "").messageProvider(// $NON-NLS-1$
(object) -> "").build();
// @formatter:on
}
Aggregations