use of org.eclipse.sirius.components.forms.Form in project sirius-components by eclipse-sirius.
the class FormEventProcessor method refreshForm.
private Form refreshForm() {
VariableManager variableManager = new VariableManager();
variableManager.put(VariableManager.SELF, this.formCreationParameters.getObjects());
variableManager.put(GetOrCreateRandomIdProvider.PREVIOUS_REPRESENTATION_ID, this.formCreationParameters.getId());
variableManager.put(IEditingContext.EDITING_CONTEXT, this.formCreationParameters.getEditingContext());
FormComponentProps formComponentProps = new FormComponentProps(variableManager, this.formCreationParameters.getFormDescription());
Element element = new Element(FormComponent.class, formComponentProps);
Form form = new FormRenderer().render(element);
// $NON-NLS-1$
this.logger.trace("Form refreshed: {}", form.getId());
return form;
}
use of org.eclipse.sirius.components.forms.Form in project sirius-components by eclipse-sirius.
the class FormEventProcessorFactory method createRepresentationEventProcessor.
@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration, IEditingContext editingContext) {
if (IFormEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof FormConfiguration) {
FormConfiguration formConfiguration = (FormConfiguration) configuration;
Optional<Form> optionalForm = this.representationSearchService.findById(editingContext, formConfiguration.getId(), Form.class);
if (optionalForm.isPresent()) {
Form form = optionalForm.get();
// @formatter:off
Optional<FormDescription> optionalFormDescription = this.representationDescriptionSearchService.findById(editingContext, form.getDescriptionId()).filter(FormDescription.class::isInstance).map(FormDescription.class::cast);
// @formatter:on
Optional<Object> optionalObject = this.objectService.getObject(editingContext, form.getTargetObjectId());
if (optionalFormDescription.isPresent() && optionalObject.isPresent()) {
FormDescription formDescription = optionalFormDescription.get();
Object object = optionalObject.get();
// @formatter:off
FormCreationParameters formCreationParameters = FormCreationParameters.newFormCreationParameters(formConfiguration.getId()).editingContext(editingContext).formDescription(formDescription).objects(List.of(object)).build();
// @formatter:on
IRepresentationEventProcessor formEventProcessor = new FormEventProcessor(formCreationParameters, this.formEventHandlers, this.subscriptionManagerFactory.create(), this.widgetSubscriptionManagerFactory.create(), this.representationRefreshPolicyRegistry);
// @formatter:off
return Optional.of(formEventProcessor).filter(representationEventProcessorClass::isInstance).map(representationEventProcessorClass::cast);
// @formatter:on
}
}
}
return Optional.empty();
}
use of org.eclipse.sirius.components.forms.Form in project sirius-components by eclipse-sirius.
the class EditSelectEventHandlerTests method testSelectEdition.
@Test
public void testSelectEdition() {
// $NON-NLS-1$
String id = "Select id";
// $NON-NLS-1$
var input = new EditSelectInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, "false");
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<String, IStatus> newValueHandler = newValue -> {
hasBeenExecuted.set(true);
return new Success();
};
// @formatter:off
SelectOption trueOption = // $NON-NLS-1$
SelectOption.newSelectOption("true").label(// $NON-NLS-1$
"True").build();
SelectOption falseOption = // $NON-NLS-1$
SelectOption.newSelectOption("false").label(// $NON-NLS-1$
"False").build();
Select select = Select.newSelect(id).label(// $NON-NLS-1$
"label").value(// $NON-NLS-1$
"true").newValueHandler(newValueHandler).options(List.of(trueOption, falseOption)).diagnostics(List.of()).build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(List.of(select)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(List.of(group)).build();
Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(List.of(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(select);
}
};
EditSelectEventHandler handler = new EditSelectEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(EditSelectSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
use of org.eclipse.sirius.components.forms.Form in project sirius-components by eclipse-sirius.
the class EditTextfieldEventHandlerTests method testTextfieldEdition.
@Test
public void testTextfieldEdition() {
// $NON-NLS-1$
String id = "Textfield id";
// $NON-NLS-1$
var input = new EditTextfieldInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, "New value");
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<String, IStatus> newValueHandler = newValue -> {
hasBeenExecuted.set(true);
return new Success();
};
// @formatter:off
Textfield textfield = Textfield.newTextfield(id).label(// $NON-NLS-1$
"label").value(// $NON-NLS-1$
"Previous value").newValueHandler(newValueHandler).diagnostics(List.of()).build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(List.of(textfield)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(List.of(group)).build();
Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(List.of(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(textfield);
}
};
EditTextfieldEventHandler handler = new EditTextfieldEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(EditTextfieldSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
use of org.eclipse.sirius.components.forms.Form in project sirius-components by eclipse-sirius.
the class DeleteListItemEventHandlerTests method testListItemDeletion.
@Test
public void testListItemDeletion() {
// $NON-NLS-1$
String listId = "List id";
// $NON-NLS-1$
String listItemId = "element id to delete";
// $NON-NLS-1$
String changeKind = "delete something";
// $NON-NLS-1$
String changeDescriptionParameterKey = "change_description_parameter_key";
Map<String, Object> parameters = new HashMap<>();
parameters.put(changeDescriptionParameterKey, listItemId);
var input = new DeleteListItemInput(UUID.randomUUID(), FORM_ID.toString(), UUID.randomUUID().toString(), listId, listItemId);
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Supplier<IStatus> deleteHandler = () -> {
hasBeenExecuted.set(true);
return new Success(changeKind, parameters);
};
// @formatter:off
ListItem listItem = ListItem.newListItem(listItemId).deletable(true).deleteHandler(deleteHandler).imageURL(// $NON-NLS-1$
"").kind(// $NON-NLS-1$
"Diagram").label(// $NON-NLS-1$
"empty representation").build();
List list = List.newList(listId).diagnostics(Collections.emptyList()).items(Collections.singletonList(listItem)).label(// $NON-NLS-1$
"").build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(Collections.singletonList(list)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(Collections.singletonList(group)).build();
Form form = Form.newForm(FORM_ID.toString()).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(Collections.singletonList(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(list);
}
};
DeleteListItemEventHandler handler = new DeleteListItemEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(changeKind);
Map<String, Object> changeDescriptionParameters = changeDescription.getParameters();
assertThat(changeDescriptionParameters.get(changeDescriptionParameterKey)).isEqualTo(listItemId);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(DeleteListItemSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
Aggregations