Search in sources :

Example 1 with AllocationCommunityComboBoxModel

use of io.imunity.furms.ui.components.support.models.allocation.AllocationCommunityComboBoxModel in project furms by unity-idm.

the class ProjectAllocationDashboardFormView method communityAllocation.

private ComboBox<AllocationCommunityComboBoxModel> communityAllocation(Label availableAmountLabel) {
    final ComboBox<AllocationCommunityComboBoxModel> communityAllocationComboBox = new ComboBox<>();
    communityAllocationComboBox.setItemLabelGenerator(resourceType -> resourceType.name);
    communityAllocationComboBox.setReadOnly(true);
    communityAllocationComboBox.setItems(binder.getBean().getAllocationCommunity());
    AllocationCommunityComboBoxModel allocationCommunity = binder.getBean().getAllocationCommunity();
    availableAmount = projectAllocationService.getAvailableAmount(binder.getBean().getCommunityId(), allocationCommunity.id);
    availableAmountLabel.setText(createAvailableLabelContent(allocationCommunity.split));
    binder.forField(communityAllocationComboBox).bind(ProjectAllocationViewModel::getAllocationCommunity, ProjectAllocationViewModel::setAllocationCommunity);
    return communityAllocationComboBox;
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) AllocationCommunityComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.AllocationCommunityComboBoxModel)

Example 2 with AllocationCommunityComboBoxModel

use of io.imunity.furms.ui.components.support.models.allocation.AllocationCommunityComboBoxModel in project furms by unity-idm.

the class ProjectAllocationDashboardFormView method amountField.

private BigDecimalField amountField() {
    final BigDecimalField amountField = new BigDecimalField();
    amountField.setValueChangeMode(EAGER);
    Optional<AllocationCommunityComboBoxModel> communityAlloc = Optional.ofNullable(binder.getBean().getAllocationCommunity());
    amountField.setReadOnly(!communityAlloc.map(alloc -> alloc.split).orElse(true));
    createUnitLabel(amountField, binder.getBean().getResourceType().unit);
    binder.forField(amountField).withValidator(Objects::nonNull, getTranslation("view.community-admin.project-allocation.form.error.validation.field.amount")).withValidator(this::isAmountCorrect, getTranslation("view.community-admin.project-allocation.form.error.validation.field.amount.range")).bind(ProjectAllocationViewModel::getAmount, ProjectAllocationViewModel::setAmount);
    amountField.setValue(availableAmount);
    return amountField;
}
Also used : ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException(io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException) DefaultNameField(io.imunity.furms.ui.components.DefaultNameField) DashboardView(io.imunity.furms.ui.views.community.DashboardView) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) ValueProvider(com.vaadin.flow.function.ValueProvider) ComponentUtil(com.vaadin.flow.component.ComponentUtil) Binder(com.vaadin.flow.data.binder.Binder) Label(com.vaadin.flow.component.html.Label) PageTitle(io.imunity.furms.ui.components.PageTitle) ComboBox(com.vaadin.flow.component.combobox.ComboBox) FurmsFormLayout(io.imunity.furms.ui.components.FurmsFormLayout) Route(com.vaadin.flow.router.Route) BigDecimal(java.math.BigDecimal) ResourceMeasureUnit(io.imunity.furms.domain.resource_types.ResourceMeasureUnit) LUMO_TERTIARY(com.vaadin.flow.component.button.ButtonVariant.LUMO_TERTIARY) ProjectAllocationService(io.imunity.furms.api.project_allocation.ProjectAllocationService) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) Setter(com.vaadin.flow.data.binder.Setter) UI(com.vaadin.flow.component.UI) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) CommunityAdminMenu(io.imunity.furms.ui.views.community.CommunityAdminMenu) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) Collectors.toSet(java.util.stream.Collectors.toSet) FormButtons(io.imunity.furms.ui.components.FormButtons) AllocationCommunityComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.AllocationCommunityComboBoxModel) BigDecimalField(com.vaadin.flow.component.textfield.BigDecimalField) Set(java.util.Set) ZERO(java.math.BigDecimal.ZERO) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Objects(java.util.Objects) Button(com.vaadin.flow.component.button.Button) ProjectService(io.imunity.furms.api.projects.ProjectService) Optional(java.util.Optional) ESCAPE(com.vaadin.flow.component.Key.ESCAPE) ResourceTypeComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.ResourceTypeComboBoxModel) ResourceAllocationsGridItem(io.imunity.furms.ui.components.resource_allocations.ResourceAllocationsGridItem) LUMO_PRIMARY(com.vaadin.flow.component.button.ButtonVariant.LUMO_PRIMARY) AllocationCommunityComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.AllocationCommunityComboBoxModel) Objects(java.util.Objects) BigDecimalField(com.vaadin.flow.component.textfield.BigDecimalField)

Example 3 with AllocationCommunityComboBoxModel

use of io.imunity.furms.ui.components.support.models.allocation.AllocationCommunityComboBoxModel in project furms by unity-idm.

the class ProjectAllocationDashboardFormView method createViewModel.

private ProjectAllocationViewModel createViewModel() {
    final ResourceAllocationsGridItem item = ComponentUtil.getData(UI.getCurrent(), ResourceAllocationsGridItem.class);
    ComponentUtil.setData(UI.getCurrent(), ResourceAllocationsGridItem.class, null);
    return ProjectAllocationViewModel.builder().communityId(item.getCommunityId()).resourceType(new ResourceTypeComboBoxModel(item.getResourceType().id, item.getResourceType().name, item.getResourceType().unit)).allocationCommunity(new AllocationCommunityComboBoxModel(item.getId(), item.getName(), item.isSplit(), item.getCredit().getUnit())).build();
}
Also used : ResourceTypeComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.ResourceTypeComboBoxModel) AllocationCommunityComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.AllocationCommunityComboBoxModel) ResourceAllocationsGridItem(io.imunity.furms.ui.components.resource_allocations.ResourceAllocationsGridItem)

Aggregations

AllocationCommunityComboBoxModel (io.imunity.furms.ui.components.support.models.allocation.AllocationCommunityComboBoxModel)3 ComboBox (com.vaadin.flow.component.combobox.ComboBox)2 ResourceAllocationsGridItem (io.imunity.furms.ui.components.resource_allocations.ResourceAllocationsGridItem)2 ResourceTypeComboBoxModel (io.imunity.furms.ui.components.support.models.allocation.ResourceTypeComboBoxModel)2 ComponentUtil (com.vaadin.flow.component.ComponentUtil)1 ESCAPE (com.vaadin.flow.component.Key.ESCAPE)1 UI (com.vaadin.flow.component.UI)1 Button (com.vaadin.flow.component.button.Button)1 LUMO_PRIMARY (com.vaadin.flow.component.button.ButtonVariant.LUMO_PRIMARY)1 LUMO_TERTIARY (com.vaadin.flow.component.button.ButtonVariant.LUMO_TERTIARY)1 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)1 Label (com.vaadin.flow.component.html.Label)1 BigDecimalField (com.vaadin.flow.component.textfield.BigDecimalField)1 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)1 Binder (com.vaadin.flow.data.binder.Binder)1 Setter (com.vaadin.flow.data.binder.Setter)1 EAGER (com.vaadin.flow.data.value.ValueChangeMode.EAGER)1 ValueProvider (com.vaadin.flow.function.ValueProvider)1 Route (com.vaadin.flow.router.Route)1 ProjectAllocationService (io.imunity.furms.api.project_allocation.ProjectAllocationService)1