use of org.eclipse.sirius.components.collaborative.forms.api.IFormInput in project sirius-components by eclipse-sirius.
the class DeleteListItemEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, Form form, IFormInput formInput) {
this.counter.increment();
String message = this.messageService.invalidInput(formInput.getClass().getSimpleName(), DeleteListItemInput.class.getSimpleName());
IPayload payload = new ErrorPayload(formInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
if (formInput instanceof DeleteListItemInput) {
DeleteListItemInput input = (DeleteListItemInput) formInput;
// @formatter:off
var optionalListItem = this.formQueryService.findWidget(form, input.getListId()).filter(List.class::isInstance).map(List.class::cast).stream().map(List::getItems).flatMap(Collection::stream).filter(item -> item.getId().toString().equals(input.getListItemId())).findFirst();
var status = optionalListItem.map(ListItem::getDeleteHandler).map(handler -> handler.get()).orElse(// $NON-NLS-1$
new Failure(""));
if (status instanceof Success) {
Success success = (Success) status;
changeDescription = new ChangeDescription(success.getChangeKind(), formInput.getRepresentationId(), formInput, success.getParameters());
payload = new DeleteListItemSuccessPayload(formInput.getId());
} else if (status instanceof Failure) {
payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
}
}
changeDescriptionSink.tryEmitNext(changeDescription);
payloadSink.tryEmitValue(payload);
}
use of org.eclipse.sirius.components.collaborative.forms.api.IFormInput in project sirius-components by eclipse-sirius.
the class EditCheckboxEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, Form form, IFormInput formInput) {
this.counter.increment();
String message = this.messageService.invalidInput(formInput.getClass().getSimpleName(), EditCheckboxInput.class.getSimpleName());
IPayload payload = new ErrorPayload(formInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
if (formInput instanceof EditCheckboxInput) {
EditCheckboxInput input = (EditCheckboxInput) formInput;
// @formatter:off
var optionalCheckbox = this.formQueryService.findWidget(form, input.getCheckboxId()).filter(Checkbox.class::isInstance).map(Checkbox.class::cast);
IStatus status = optionalCheckbox.map(Checkbox::getNewValueHandler).map(handler -> handler.apply(input.getNewValue())).orElse(// $NON-NLS-1$
new Failure(""));
if (status instanceof Success) {
payload = new EditCheckboxSuccessPayload(formInput.getId());
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, formInput.getRepresentationId(), formInput);
} else if (status instanceof Failure) {
payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
}
}
changeDescriptionSink.tryEmitNext(changeDescription);
payloadSink.tryEmitValue(payload);
}
use of org.eclipse.sirius.components.collaborative.forms.api.IFormInput in project sirius-components by eclipse-sirius.
the class EditRadioEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, Form form, IFormInput formInput) {
this.counter.increment();
String message = this.messageService.invalidInput(formInput.getClass().getSimpleName(), EditRadioInput.class.getSimpleName());
IPayload payload = new ErrorPayload(formInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
if (formInput instanceof EditRadioInput) {
EditRadioInput input = (EditRadioInput) formInput;
// @formatter:off
var optionalRadio = this.formQueryService.findWidget(form, input.getRadioId()).filter(Radio.class::isInstance).map(Radio.class::cast);
IStatus status = optionalRadio.map(Radio::getNewValueHandler).map(handler -> handler.apply(input.getNewValue())).orElse(// $NON-NLS-1$
new Failure(""));
if (status instanceof Success) {
payload = new EditRadioSuccessPayload(formInput.getId());
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, formInput.getRepresentationId(), formInput);
} else if (status instanceof Failure) {
payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
}
}
changeDescriptionSink.tryEmitNext(changeDescription);
payloadSink.tryEmitValue(payload);
}
use of org.eclipse.sirius.components.collaborative.forms.api.IFormInput in project sirius-components by eclipse-sirius.
the class EditSelectEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, Form form, IFormInput formInput) {
this.counter.increment();
String message = this.messageService.invalidInput(formInput.getClass().getSimpleName(), EditSelectInput.class.getSimpleName());
IPayload payload = new ErrorPayload(formInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
if (formInput instanceof EditSelectInput) {
EditSelectInput input = (EditSelectInput) formInput;
// @formatter:off
Optional<Select> optionalSelect = this.formQueryService.findWidget(form, input.getSelectId()).filter(Select.class::isInstance).map(Select.class::cast);
IStatus status = optionalSelect.map(Select::getNewValueHandler).map(handler -> handler.apply(input.getNewValue())).orElse(// $NON-NLS-1$
new Failure(""));
if (status instanceof Success) {
payload = new EditSelectSuccessPayload(formInput.getId());
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, formInput.getRepresentationId(), formInput);
} else if (status instanceof Failure) {
payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
}
}
changeDescriptionSink.tryEmitNext(changeDescription);
payloadSink.tryEmitValue(payload);
}
use of org.eclipse.sirius.components.collaborative.forms.api.IFormInput in project sirius-components by eclipse-sirius.
the class EditTextfieldEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, Form form, IFormInput formInput) {
this.counter.increment();
String message = this.messageService.invalidInput(formInput.getClass().getSimpleName(), EditTextfieldInput.class.getSimpleName());
IPayload payload = new ErrorPayload(formInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
if (formInput instanceof EditTextfieldInput) {
EditTextfieldInput input = (EditTextfieldInput) formInput;
// @formatter:off
IStatus status = this.formQueryService.findWidget(form, input.getTextfieldId()).map(widget -> {
Function<String, IStatus> handlerFunction = null;
if (widget instanceof Textfield) {
handlerFunction = ((Textfield) widget).getNewValueHandler();
} else if (widget instanceof Textarea) {
handlerFunction = ((Textarea) widget).getNewValueHandler();
}
return handlerFunction;
}).map(handler -> handler.apply(input.getNewValue())).orElse(// $NON-NLS-1$
new Failure(""));
if (status instanceof Success) {
payload = new EditTextfieldSuccessPayload(formInput.getId());
changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, formInput.getRepresentationId(), formInput);
} else if (status instanceof Failure) {
payload = new ErrorPayload(formInput.getId(), ((Failure) status).getMessage());
}
}
changeDescriptionSink.tryEmitNext(changeDescription);
payloadSink.tryEmitValue(payload);
}
Aggregations