use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.
the class FormEditorHelperTest method loadContent.
private void loadContent() {
testFieldManager = spy(new TestFieldManager());
when(editorFieldLayoutComponents.get()).thenAnswer(invocationOnMock -> {
final EditorFieldLayoutComponent mocked = mock(EditorFieldLayoutComponent.class);
return mocked;
});
when(formEditorService.loadContent(any())).then(invocation -> {
FormDefinition form = new FormDefinition();
form.setName("EmployeeTestForm");
form.setId("_random_id");
content = new FormModelerContent();
PortableJavaModel model = new PortableJavaModel("com.test.Employee");
model.getProperties().addAll(modelProperties);
form.setModel(model);
content.setDefinition(form);
content.setOverview(new Overview());
return content;
});
when(testFieldManager.getBaseFieldTypes()).thenAnswer(invocationOnMock -> {
List<String> baseFields = new ArrayList<>();
baseFields.add("TextBox");
baseFields.add("CheckBox");
return baseFields;
});
editorServiceCallerMock = new CallerMock<>(formEditorService);
formEditorHelper = new TestFormEditorHelper(testFieldManager, editorFieldLayoutComponents);
formEditorService.loadContent(null);
formEditorHelper.initHelper(content);
assertEquals(formEditorHelper.getEditorFieldTypes().size(), formEditorHelper.getBaseFieldsDraggables().size());
}
use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.
the class FormEditorHelper method initHelper.
public void initHelper(FormModelerContent content) {
this.content = content;
if (unbindedFields != null && !unbindedFields.isEmpty()) {
return;
}
for (FieldType baseType : enabledPaletteFieldTypes) {
EditorFieldLayoutComponent layoutComponent = editorFieldLayoutComponents.get();
if (layoutComponent != null) {
FieldDefinition field = fieldManager.getDefinitionByFieldType(baseType);
field.setName(generateUnboundFieldName(field));
layoutComponent.init(content.getRenderingContext(), field);
unbindedFields.put(field.getId(), new Pair<>(layoutComponent, field));
}
}
addAvailableFields();
}
use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.
the class FormEditorPresenter method loadAvailableFields.
protected void loadAvailableFields() {
LayoutDragComponentGroup group = new LayoutDragComponentGroup(translationService.getTranslation(FormEditorConstants.FormEditorPresenterModelFields));
editorHelper.getAvailableFields().values().forEach(fieldDefinition -> {
EditorFieldLayoutComponent layoutFieldComponent = editorFieldLayoutComponents.get();
if (layoutFieldComponent != null) {
layoutFieldComponent.init(editorHelper.getRenderingContext(), fieldDefinition);
group.addLayoutDragComponent(fieldDefinition.getId(), layoutFieldComponent);
}
});
layoutDragComponentPalette.addDraggableGroup(group);
}
use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.
the class FormEditorHelper method getFormField.
public FieldDefinition getFormField(String fieldId) {
FieldDefinition result = content.getDefinition().getFieldById(fieldId);
if (result == null) {
result = availableFields.get(fieldId);
if (result == null) {
if (unbindedFields.containsKey(fieldId)) {
Pair<EditorFieldLayoutComponent, FieldDefinition> pair = unbindedFields.get(fieldId);
result = pair.getK2();
result.setLabel(result.getFieldType().getTypeName());
if (result instanceof HasPlaceHolder) {
((HasPlaceHolder) result).setPlaceHolder(result.getFieldType().getTypeName());
}
unbindedFields.remove(result.getId());
FieldDefinition newField = fieldManager.getDefinitionByFieldType(result.getFieldType());
newField.setName(generateUnboundFieldName(newField));
EditorFieldLayoutComponent component = pair.getK1();
component.init(content.getRenderingContext(), newField);
unbindedFields.put(newField.getId(), new Pair<>(component, newField));
}
}
}
return result;
}
use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.
the class FormEditorPresenter method addAllDraggableGroupComponent.
protected void addAllDraggableGroupComponent(Collection<FieldDefinition> fields) {
String groupId = translationService.getTranslation(FormEditorConstants.FormEditorPresenterModelFields);
Iterator<FieldDefinition> it = fields.iterator();
while (it.hasNext()) {
FieldDefinition field = it.next();
EditorFieldLayoutComponent layoutFieldComponent = editorFieldLayoutComponents.get();
if (layoutFieldComponent != null) {
layoutFieldComponent.init(editorHelper.getRenderingContext(), field);
layoutDragComponentPalette.addDraggableComponent(groupId, field.getId(), layoutFieldComponent);
}
}
}
Aggregations