public void onClick$btnSaveResource() { List componenttList = rowsResourceList.getChildren(); /// List<SelectedResource> selectedResourceList; // Valida si hay lista de recursos en el formulario if (componenttList.size() > 0) { ResourceRow resourceRow; int projectResourceIndex = -1; ProjectResource projectResource = new ProjectResource(); projectResource.setResourceCategoryId(this.resourceCategorySelected.getId()); projectResource.setSelectedResourceList(new ArrayList<SelectedResource>()); // Valida si hay recursos seleccionados en el proyecto que corresponden a la categoria // seleccionada // para eliminarlos if (this.project.getProjectResourceList() != null) { projectResourceIndex = getProjectResourceIndex(this.resourceCategorySelected.getId()); if (projectResourceIndex >= 0) { ProjectResource resource = (ProjectResource) this.project.getProjectResourceList().get(projectResourceIndex); this.project.getProjectResourceList().remove(projectResourceIndex); this.projectMgmtService.projectUpdate(this.project); this.projectMgmtService.deleteprojectResource(resource); } } saveProjectResources(componenttList, projectResource); desktop.removeAttribute("currentProject"); desktop.setAttribute("currentProject", this.project); grdEditResource.setVisible(false); btnSaveResource.setVisible(false); } }
public void createResourceForm(Long categoryId) { resourceCategorySelected = this.projectMgmtService.getResourceCategoryById(categoryId); this.clearResourceForm(); SelectedResource selectedResource; ResourceRow resourceRow; ProjectResource projectResourceFound = getProjectResource(categoryId); for (Resource resource : resourceCategorySelected.getResourceList()) { resourceRow = new ResourceRow(resource); rowsResourceList.getChildren().add(resourceRow); // Sets selected recources if (projectResourceFound == null) { continue; } else { for (int j = 0; j < projectResourceFound.getSelectedResourceList().size(); j++) { selectedResource = projectResourceFound.getSelectedResourceList().get(j); if (selectedResource.getResource().getId().compareTo(resource.getId()) == 0) { resourceRow.selectedResource(); resourceRow.setSelectedValue(selectedResource.getSelectedValue()); } } } } // Sets selected recources grdEditResource.setVisible(true); btnSaveResource.setVisible(true); }
private void saveProjectResources(List componenttList, ProjectResource projectResource) throws WrongValueException { ResourceRow resourceRow; // Determina si hay recursos seleccionados boolean isSelectedtResources = false; SelectedResource selectedResource; for (Iterator iterator = componenttList.iterator(); iterator.hasNext(); ) { resourceRow = (ResourceRow) iterator.next(); if (resourceRow.isSelectedResource()) { String selectedValue = resourceRow.getSelectedValue(); if (selectedValue == null || Strings.isBlank(selectedValue)) { throw new WrongValueException(resourceRow.getComponentValue(), "Value is requeried"); } selectedResource = new SelectedResource(); selectedResource.setResource(resourceRow.getResource()); selectedResource.setSelectedValue(selectedValue); projectResource.getSelectedResourceList().add(selectedResource); isSelectedtResources = true; } } if (isSelectedtResources) { this.project.getProjectResourceList().add(projectResource); this.projectMgmtService.projectUpdate(this.project); } }
private ProjectResource getProjectResource(Long resourceCategoryId) { ProjectResource projectResource = null; if (this.project.getProjectResourceList() == null) { return null; } this.project.getProjectResourceList().size(); if (this.project != null && this.project.getProjectResourceList() != null) { for (ProjectResource pResource : this.project.getProjectResourceList()) { if (pResource.getResourceCategoryId().compareTo(resourceCategoryId) == 0) { projectResource = pResource; break; } } } return projectResource; }
private int getProjectResourceIndex(Long categoryResourceId) { int indexFound = -1; if (this.project.getProjectResourceList() != null && this.project.getProjectResourceList().size() > 0) { ProjectResource projectResource; for (int j = 0; j < this.project.getProjectResourceList().size(); j++) { projectResource = this.project.getProjectResourceList().get(j); if (projectResource.getResourceCategoryId().compareTo(categoryResourceId) == 0) { // this.project.getProjectResourceList().remove(j); indexFound = j; break; } } } return indexFound; }