Search in sources :

Example 1 with CheckboxDescription

use of org.eclipse.sirius.components.forms.description.CheckboxDescription 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;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) LinkDescription(org.eclipse.sirius.components.forms.description.LinkDescription) Element(org.eclipse.sirius.components.representations.Element) MultiSelectDescription(org.eclipse.sirius.components.forms.description.MultiSelectDescription) ListDescription(org.eclipse.sirius.components.forms.description.ListDescription) AbstractWidgetDescription(org.eclipse.sirius.components.forms.description.AbstractWidgetDescription) TextareaDescription(org.eclipse.sirius.components.forms.description.TextareaDescription) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) MultiSelectDescription(org.eclipse.sirius.components.forms.description.MultiSelectDescription)

Example 2 with CheckboxDescription

use of org.eclipse.sirius.components.forms.description.CheckboxDescription in project sirius-components by eclipse-sirius.

the class WidgetDescriptionConverter method convertCheckbox.

private CheckboxDescription convertCheckbox(org.eclipse.sirius.properties.CheckboxDescription checkboxDescription) {
    StringValueProvider labelProvider = new StringValueProvider(this.interpreter, checkboxDescription.getLabelExpression());
    BiFunction<VariableManager, Boolean, IStatus> newValueHandler = (variableManager, newValue) -> {
        Map<String, Object> variables = variableManager.getVariables();
        variables.put(NEW_VALUE, newValue);
        InitialOperation initialOperation = checkboxDescription.getInitialOperation();
        ModelOperation modelOperation = initialOperation.getFirstModelOperations();
        var modelOperationHandlerSwitch = this.modelOperationHandlerSwitchProvider.getModelOperationHandlerSwitch(this.interpreter);
        Optional<IModelOperationHandler> optionalModelOperationHandler = modelOperationHandlerSwitch.apply(modelOperation);
        return optionalModelOperationHandler.map(handler -> {
            return handler.handle(variables);
        }).orElse(// $NON-NLS-1$
        new Failure(""));
    };
    // $NON-NLS-1$
    String valueExpression = Optional.ofNullable(checkboxDescription.getValueExpression()).orElse("");
    Function<VariableManager, Boolean> valueProvider = new BooleanValueProvider(this.interpreter, valueExpression);
    // @formatter:off
    return CheckboxDescription.newCheckboxDescription(this.identifierProvider.getIdentifier(checkboxDescription)).idProvider(new WidgetIdProvider()).labelProvider(labelProvider).valueProvider(valueProvider).newValueHandler(newValueHandler).diagnosticsProvider((variableManager) -> List.of()).kindProvider(// $NON-NLS-1$
    (object) -> "").messageProvider(// $NON-NLS-1$
    (object) -> "").build();
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) BiFunction(java.util.function.BiFunction) InitialOperation(org.eclipse.sirius.viewpoint.description.tool.InitialOperation) LoggerFactory(org.slf4j.LoggerFactory) SelectComponent(org.eclipse.sirius.components.forms.components.SelectComponent) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TextareaDescription(org.eclipse.sirius.components.forms.description.TextareaDescription) IStatus(org.eclipse.sirius.components.representations.IStatus) StringValueProvider(org.eclipse.sirius.components.compatibility.utils.StringValueProvider) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) Map(java.util.Map) WidgetDescription(org.eclipse.sirius.properties.WidgetDescription) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) Logger(org.slf4j.Logger) AbstractWidgetDescription(org.eclipse.sirius.components.forms.description.AbstractWidgetDescription) Failure(org.eclipse.sirius.components.representations.Failure) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) BooleanValueProvider(org.eclipse.sirius.components.compatibility.utils.BooleanValueProvider) IModelOperationHandler(org.eclipse.sirius.components.compatibility.api.IModelOperationHandler) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Objects(java.util.Objects) RadioComponent(org.eclipse.sirius.components.forms.components.RadioComponent) List(java.util.List) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) Optional(java.util.Optional) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Collections(java.util.Collections) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) InitialOperation(org.eclipse.sirius.viewpoint.description.tool.InitialOperation) IStatus(org.eclipse.sirius.components.representations.IStatus) StringValueProvider(org.eclipse.sirius.components.compatibility.utils.StringValueProvider) Optional(java.util.Optional) BooleanValueProvider(org.eclipse.sirius.components.compatibility.utils.BooleanValueProvider) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) Map(java.util.Map) Failure(org.eclipse.sirius.components.representations.Failure)

Example 3 with CheckboxDescription

use of org.eclipse.sirius.components.forms.description.CheckboxDescription in project sirius-components by eclipse-sirius.

the class CheckboxComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    CheckboxDescription checkboxDescription = this.props.getCheckboxDescription();
    String id = checkboxDescription.getIdProvider().apply(variableManager);
    String label = checkboxDescription.getLabelProvider().apply(variableManager);
    Boolean value = checkboxDescription.getValueProvider().apply(variableManager);
    BiFunction<VariableManager, Boolean, IStatus> genericHandler = checkboxDescription.getNewValueHandler();
    Function<Boolean, IStatus> specializedHandler = newValue -> genericHandler.apply(variableManager, newValue);
    List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(checkboxDescription, variableManager)));
    // @formatter:off
    CheckboxElementProps checkboxElementProps = CheckboxElementProps.newCheckboxElementProps(id).label(label).value(value.booleanValue()).newValueHandler(specializedHandler).children(children).build();
    return new Element(CheckboxElementProps.TYPE, checkboxElementProps);
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) Objects(java.util.Objects) List(java.util.List) IStatus(org.eclipse.sirius.components.representations.IStatus) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) BiFunction(java.util.function.BiFunction) CheckboxElementProps(org.eclipse.sirius.components.forms.elements.CheckboxElementProps) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Function(java.util.function.Function) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) Element(org.eclipse.sirius.components.representations.Element) IComponent(org.eclipse.sirius.components.representations.IComponent) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) IStatus(org.eclipse.sirius.components.representations.IStatus) Element(org.eclipse.sirius.components.representations.Element) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) CheckboxElementProps(org.eclipse.sirius.components.forms.elements.CheckboxElementProps)

Example 4 with CheckboxDescription

use of org.eclipse.sirius.components.forms.description.CheckboxDescription in project sirius-components by eclipse-sirius.

the class NodeStylePropertiesConfigurer method createCheckbox.

private CheckboxDescription createCheckbox(String id, String title, Function<Object, Boolean> reader, BiConsumer<Object, Boolean> writer, Object feature) {
    Function<VariableManager, Boolean> valueProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(reader).orElse(Boolean.FALSE);
    BiFunction<VariableManager, Boolean, 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 CheckboxDescription.newCheckboxDescription(id).idProvider(variableManager -> id).labelProvider(variableManager -> title).valueProvider(valueProvider).newValueHandler(newValueHandler).diagnosticsProvider(this.getDiagnosticsProvider(feature)).kindProvider(this::kindProvider).messageProvider(this::messageProvider).build();
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) IPropertiesDescriptionRegistryConfigurer(org.eclipse.sirius.components.collaborative.forms.services.api.IPropertiesDescriptionRegistryConfigurer) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) LineStyle(org.eclipse.sirius.components.view.LineStyle) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) BiFunction(java.util.function.BiFunction) SelectComponent(org.eclipse.sirius.components.forms.components.SelectComponent) Function(java.util.function.Function) CustomImage(org.eclipse.sirius.components.emf.view.CustomImage) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) LabelStyle(org.eclipse.sirius.components.view.LabelStyle) IStatus(org.eclipse.sirius.components.representations.IStatus) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) ICustomImageSearchService(org.eclipse.sirius.components.emf.view.ICustomImageSearchService) BiConsumer(java.util.function.BiConsumer) IValidationService(org.eclipse.sirius.components.collaborative.validation.api.IValidationService) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) Failure(org.eclipse.sirius.components.representations.Failure) Predicate(java.util.function.Predicate) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) Success(org.eclipse.sirius.components.representations.Success) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) EObject(org.eclipse.emf.ecore.EObject) UUID(java.util.UUID) ConditionalNodeStyle(org.eclipse.sirius.components.view.ConditionalNodeStyle) Collectors(java.util.stream.Collectors) ViewPackage(org.eclipse.sirius.components.view.ViewPackage) Objects(java.util.Objects) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) Component(org.springframework.stereotype.Component) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) BorderStyle(org.eclipse.sirius.components.view.BorderStyle) Optional(java.util.Optional) IPropertiesDescriptionRegistry(org.eclipse.sirius.components.collaborative.forms.services.api.IPropertiesDescriptionRegistry) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Comparator(java.util.Comparator) IStatus(org.eclipse.sirius.components.representations.IStatus) EObject(org.eclipse.emf.ecore.EObject) Success(org.eclipse.sirius.components.representations.Success) Failure(org.eclipse.sirius.components.representations.Failure)

Aggregations

CheckboxDescription (org.eclipse.sirius.components.forms.description.CheckboxDescription)4 VariableManager (org.eclipse.sirius.components.representations.VariableManager)4 List (java.util.List)3 Objects (java.util.Objects)3 BiFunction (java.util.function.BiFunction)3 Function (java.util.function.Function)3 SelectDescription (org.eclipse.sirius.components.forms.description.SelectDescription)3 TextfieldDescription (org.eclipse.sirius.components.forms.description.TextfieldDescription)3 IStatus (org.eclipse.sirius.components.representations.IStatus)3 Optional (java.util.Optional)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2 SelectComponent (org.eclipse.sirius.components.forms.components.SelectComponent)2 AbstractWidgetDescription (org.eclipse.sirius.components.forms.description.AbstractWidgetDescription)2 RadioDescription (org.eclipse.sirius.components.forms.description.RadioDescription)2 TextareaDescription (org.eclipse.sirius.components.forms.description.TextareaDescription)2 Element (org.eclipse.sirius.components.representations.Element)2 Failure (org.eclipse.sirius.components.representations.Failure)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1