use of org.eclipse.sirius.components.forms.Form 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);
}
use of org.eclipse.sirius.components.forms.Form in project sirius-components by eclipse-sirius.
the class FormEventProcessor method refresh.
@Override
public void refresh(ChangeDescription changeDescription) {
if (this.shouldRefresh(changeDescription)) {
Form form = this.refreshForm();
this.currentForm.set(form);
if (this.sink.currentSubscriberCount() > 0) {
EmitResult emitResult = this.sink.tryEmitNext(new FormRefreshedEventPayload(changeDescription.getInput().getId(), form));
if (emitResult.isFailure()) {
// $NON-NLS-1$
String pattern = "An error has occurred while emitting a FormRefreshedEventPayload: {}";
this.logger.warn(pattern, emitResult);
}
}
}
}
use of org.eclipse.sirius.components.forms.Form in project sirius-components by eclipse-sirius.
the class CreateFormEventHandler method handle.
@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
this.counter.increment();
String message = this.messageService.invalidInput(input.getClass().getSimpleName(), CreateRepresentationInput.class.getSimpleName());
IPayload payload = new ErrorPayload(input.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);
if (input instanceof CreateRepresentationInput) {
CreateRepresentationInput createRepresentationInput = (CreateRepresentationInput) input;
Optional<IRepresentationDescription> optionalRepresentationDescription = this.representationDescriptionSearchService.findById(editingContext, createRepresentationInput.getRepresentationDescriptionId());
Optional<Object> optionalObject = this.objectService.getObject(editingContext, createRepresentationInput.getObjectId());
if (optionalRepresentationDescription.isPresent() && optionalObject.isPresent()) {
IRepresentationDescription representationDescription = optionalRepresentationDescription.get();
String targetObjectId = this.objectService.getId(optionalObject.get());
if (representationDescription instanceof FormDescription) {
// @formatter:off
Form form = Form.newForm(UUID.randomUUID().toString()).label(createRepresentationInput.getRepresentationName()).targetObjectId(targetObjectId).descriptionId(representationDescription.getId()).pages(// We don't store form pages, it will be re-render by the FormProcessor.
List.of()).build();
// @formatter:on
this.representationPersistenceService.save(editingContext, form);
payload = new CreateRepresentationSuccessPayload(input.getId(), form);
changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_CREATION, editingContext.getId(), input);
}
}
}
payloadSink.tryEmitValue(payload);
changeDescriptionSink.tryEmitNext(changeDescription);
}
use of org.eclipse.sirius.components.forms.Form in project sirius-components by eclipse-sirius.
the class EditMultiSelectEventHandler 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(), EditMultiSelectInput.class.getSimpleName());
IPayload payload = new ErrorPayload(formInput.getId(), message);
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, formInput.getRepresentationId(), formInput);
if (formInput instanceof EditMultiSelectInput) {
EditMultiSelectInput input = (EditMultiSelectInput) formInput;
// @formatter:off
Optional<MultiSelect> optionalMultiSelect = this.formQueryService.findWidget(form, input.getSelectId()).filter(MultiSelect.class::isInstance).map(MultiSelect.class::cast);
IStatus status = optionalMultiSelect.map(MultiSelect::getNewValuesHandler).map(handler -> handler.apply(input.getNewValues())).orElse(// $NON-NLS-1$
new Failure(""));
if (status instanceof Success) {
payload = new EditMultiSelectSuccessPayload(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.forms.Form in project sirius-components by eclipse-sirius.
the class FormRendererTests method checkResult.
private void checkResult(FormDescription description) {
// test SiriusViewExtensionDescriptionConverter
assertThat(description).isNotNull();
assertThat(description.getGroupDescriptions()).hasSize(1);
assertThat(description.getPageDescriptions()).hasSize(1);
assertThat(description.getPageDescriptions().get(0).getGroupDescriptions()).hasSize(1);
assertThat(description.getPageDescriptions()).hasSize(1);
assertThat(description.getPageDescriptions().get(0).getGroupDescriptions().get(0)).isEqualTo(description.getGroupDescriptions().get(0));
assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream())).hasSize(6);
assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(CheckboxDescription.class::isInstance)).hasSize(1);
assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(RadioDescription.class::isInstance)).hasSize(1);
assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(SelectDescription.class::isInstance)).hasSize(1);
assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(TextfieldDescription.class::isInstance)).hasSize(1);
assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(TextfieldDescription.class::isInstance)).hasSize(1);
Optional<ForDescription> forOptional = description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(ForDescription.class::isInstance).map(ForDescription.class::cast).findFirst();
assertThat(forOptional).isNotEmpty();
assertThat(forOptional.get().getIfDescriptions()).hasSize(1);
assertThat(forOptional.get().getIfDescriptions().stream().findFirst().get().getWidgetDescription()).isNotNull();
// Test FormRenderer
VariableManager variableManager = new VariableManager();
variableManager.put(VariableManager.SELF, List.of(EcorePackage.eINSTANCE));
FormRenderer formRenderer = new FormRenderer();
FormComponentProps props = new FormComponentProps(variableManager, description);
Element element = new Element(FormComponent.class, props);
Form form = formRenderer.render(element);
assertThat(form.getPages()).hasSize(1);
assertThat(form.getPages().stream().flatMap(p -> p.getGroups().stream())).hasSize(1);
assertThat(form.getPages().stream().flatMap(p -> p.getGroups().stream()).flatMap(g -> g.getWidgets().stream())).hasSize(5);
List<Group> groups = form.getPages().stream().flatMap(p -> p.getGroups().stream()).collect(Collectors.toList());
this.checkIdsInGroups(groups);
}
Aggregations