com.talk2object.plum.interaction.rich.field.component.EntityFieldViewBuilder Maven / Gradle / Ivy
package com.talk2object.plum.interaction.rich.field.component;
import java.util.List;
import com.talk2object.plum.interaction.controller.AbstractController;
import com.talk2object.plum.interaction.controller.Controller;
import com.talk2object.plum.interaction.rich.field.EntityField;
import com.talk2object.plum.interaction.rich.field.InteractiveField;
import com.talk2object.plum.repository.biz.interafce.Collection;
import com.talk2object.plum.repository.biz.interafce.Repository;
import com.talk2object.plum.repository.context.RepositoryContextUtils;
import com.talk2object.plum.view._abstract.components.listbox.DropdownList;
import com.talk2object.plum.view._abstract.components.listbox.option.EntityOptions;
import com.talk2object.plum.view._abstract.components.listbox.option.ObjectOptions;
import com.talk2object.plum.view._abstract.window.UIComponent;
public class EntityFieldViewBuilder extends AbstractFieldViewBuilder {
@Override
protected UIComponent createComponent(InteractiveField input) {
Repository repo = RepositoryContextUtils.getRepository();
if (repo == null)
throw new RuntimeException(
"Repository not initialized, input type of 'Entity' is not supported.");
EntityField entityInput = (EntityField) input;
Collection collection = repo.getCollection(entityInput.getFieldClass());
DropdownList dlist = new DropdownList();
UIComponent component = dlist;
List entityList = collection.getAll();
if (input.isNullable())
entityList.add(0, null);
ObjectOptions options = new EntityOptions(entityList,
entityInput.getFieldClass());
dlist.setOptions(options);
new AbstractController(input, dlist) {
@Override
public void updateViewState() {
getView().setSelectedValue(getModel().getValue());
}
@Override
public void updateModelState() {
getModel().setValue(getView().getSelectedValue());
}
};
return component;
}
@Override
public Class getModelClass() {
return EntityField.class;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy