use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class MapModelBindingHelper method prepareMapContentFor.
protected void prepareMapContentFor(MultipleSubFormFieldDefinition field, Object fieldValue, Map<String, Object> formData, MapModelRenderingContext context) {
formData.put(field.getBinding(), new ArrayList<Map<String, Object>>());
final List<Map<String, Object>> nestedFormValues = (List<Map<String, Object>>) formData.get(field.getBinding());
final List<Map<String, Object>> nestedValues = (List<Map<String, Object>>) fieldValue;
if (nestedValues != null) {
nestedValues.forEach(nestedValue -> {
Map<String, Object> nestedFormValue = new HashMap<>();
FormDefinition creationForm = context.getAvailableForms().get(field.getCreationForm());
prepareMapContent(nestedFormValue, creationForm, nestedValue, context);
FormDefinition editionForm = context.getAvailableForms().get(field.getEditionForm());
prepareMapContent(nestedFormValue, editionForm, nestedValue, context);
nestedFormValues.add(nestedFormValue);
});
}
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class MapModelBindingHelper method prepareMapContentFor.
protected void prepareMapContentFor(SubFormFieldDefinition field, Object fieldValue, Map<String, Object> formData, MapModelRenderingContext context) {
FormDefinition subForm = context.getAvailableForms().get(field.getNestedForm());
formData.put(field.getBinding(), new HashMap<>());
Map<String, Object> nestedFormValues = (Map<String, Object>) formData.get(field.getBinding());
Map<String, Object> nestedValues = (Map<String, Object>) fieldValue;
if (nestedValues == null) {
nestedValues = new HashMap<>();
}
prepareMapContent(nestedFormValues, subForm, nestedValues, context);
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class MultipleSubFormWidget method initCrud.
protected void initCrud() {
final List<ColumnMeta> metas = new ArrayList<>();
HasProperties hasProperties = null;
try {
hasProperties = bindingHelper.getProxyDefinition();
} catch (Exception e) {
GWT.log("Unable to find proxy: " + e.getMessage());
}
for (TableColumnMeta meta : field.getColumnMetas()) {
String type = String.class.getName();
if (hasProperties != null) {
type = hasProperties.getBeanProperties().get(meta.getProperty()).getType().getName();
}
ColumnGenerator generator = columnGeneratorManager.getGeneratorByType(type);
if (generator != null) {
ColumnMeta<HasProperties> columnMeta = new ColumnMeta<HasProperties>(generator.getColumn(meta.getProperty()), meta.getLabel());
metas.add(columnMeta);
}
}
dataProvider = new AsyncDataProvider<HasProperties>() {
@Override
protected void onRangeChanged(HasData<HasProperties> hasData) {
if (tableValues != null) {
updateRowCount(tableValues.size(), true);
updateRowData(0, tableValues);
} else {
updateRowCount(0, true);
updateRowData(0, new ArrayList<HasProperties>());
}
}
};
crudComponent.init(new CrudActionsHelper() {
@Override
public int getPageSize() {
return PAGE_SIZE;
}
@Override
public boolean showEmbeddedForms() {
return true;
}
@Override
public boolean isAllowCreate() {
return !isReadOnly;
}
@Override
public boolean isAllowEdit() {
return !isReadOnly;
}
@Override
public boolean isAllowDelete() {
return !isReadOnly;
}
@Override
public List<ColumnMeta> getGridColumns() {
return metas;
}
@Override
public AsyncDataProvider getDataProvider() {
return dataProvider;
}
public IsFormView<Object> getCreateInstanceForm() {
if (field.getCreationForm() != null) {
BindableProxy<?> proxy = bindingHelper.getNewProxy();
formRenderer.render(renderingContext.getCopyFor(field.getCreationForm(), proxy));
return formRenderer;
}
return null;
}
public IsFormView<Object> getEditInstanceForm(int position) {
if (field.getEditionForm() != null) {
BindableProxy instanceProxy = bindingHelper.getProxyForModel(values.get(position));
BindableProxy editionProxy = bindingHelper.getProxyForModel(instanceProxy.deepUnwrap());
formRenderer.render(renderingContext.getCopyFor(field.getEditionForm(), editionProxy));
return formRenderer;
}
return null;
}
@Override
public void createInstance() {
IsFormView form = getCreateInstanceForm();
crudComponent.displayForm(translationService.getTranslation(CrudComponentConstants.CrudComponentViewImplNewInstanceTitle), form, new FormDisplayer.FormDisplayerCallback() {
@Override
public void onCancel() {
formRenderer.unBind();
}
@Override
public void onAccept() {
if (values == null) {
values = new ArrayList<>();
}
values.add(formRenderer.getModel());
tableValues.add((HasProperties) formRenderer.getModel());
refreshCrud();
fireFieldChange();
formRenderer.unBind();
}
});
}
@Override
public void editInstance(int index) {
IsFormView form = getEditInstanceForm(index);
crudComponent.displayForm(translationService.getTranslation(CrudComponentConstants.CrudComponentViewImplEditInstanceTitle), form, new FormDisplayer.FormDisplayerCallback() {
@Override
public void onCancel() {
formRenderer.unBind();
}
@Override
public void onAccept() {
BindableProxy editionProxy = (BindableProxy) formRenderer.getModel();
BindableProxy realProxy = bindingHelper.getProxyForModel(values.get(index));
FormDefinition editionform = (FormDefinition) renderingContext.getAvailableForms().get(field.getEditionForm());
editionform.getFields().forEach(fieldDefinition -> {
if (fieldDefinition.getBinding() != null) {
realProxy.set(fieldDefinition.getBinding(), editionProxy.get(fieldDefinition.getBinding()));
}
});
bindingHelper.afterEdit(realProxy);
values.set(index, realProxy);
tableValues.set(index, realProxy);
refreshCrud();
fireFieldChange();
formRenderer.unBind();
}
});
}
@Override
public void deleteInstance(int index) {
values.remove(index);
tableValues.remove(index);
refreshCrud();
fireFieldChange();
}
});
initValues();
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormEditorServiceImpl method createForm.
@Override
public Path createForm(Path path, String formName, FormModel formModel) {
org.uberfire.java.nio.file.Path kiePath = Paths.convert(path).resolve(formName);
try {
if (ioService.exists(kiePath)) {
throw new FileAlreadyExistsException(kiePath.toString());
}
FormDefinition form = new FormDefinition(formModel);
form.setId(UIDGenerator.generateUID());
form.setName(formName.substring(0, formName.lastIndexOf(".")));
form.setLayoutTemplate(new LayoutTemplate());
ioService.write(kiePath, formDefinitionSerializer.serialize(form), commentedOptionFactory.makeCommentedOption(""));
return Paths.convert(kiePath);
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
}
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormEditorServiceImpl method findForm.
protected FormDefinition findForm(org.uberfire.java.nio.file.Path path) throws Exception {
String template = ioService.readAllString(path).trim();
FormDefinition form = formDefinitionSerializer.deserialize(template);
if (form == null) {
form = new FormDefinition();
form.setId(UIDGenerator.generateUID());
}
return form;
}
Aggregations