ItEr35S14CUAdministracionMateriaisItEr34S14: Save category and materials
This commit is contained in:
parent
e4e958a657
commit
72765be5e0
6 changed files with 211 additions and 99 deletions
|
|
@ -324,4 +324,8 @@ public class MutableTreeModel<T> extends AbstractTreeModel {
|
|||
return getChildCount(getRoot()) == 0;
|
||||
}
|
||||
|
||||
public boolean hasChildren(T node) {
|
||||
return getChildCount(node) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
</id>
|
||||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="code" unique="true"/>
|
||||
<property name="code" unique="true" not-null="true"/>
|
||||
|
||||
<property name="description"/>
|
||||
|
||||
|
|
|
|||
|
|
@ -36,12 +36,14 @@ public interface IMaterialsModel {
|
|||
|
||||
void addMaterialCategory(MaterialCategory parent, MaterialCategory child) throws ValidationException;
|
||||
|
||||
void addMaterialToMaterialCategory(MaterialCategory materialCategory);
|
||||
|
||||
void confirmSave() throws ValidationException;
|
||||
|
||||
MutableTreeModel<MaterialCategory> getMaterialCategories();
|
||||
|
||||
List<Material> getMaterials(MaterialCategory materialCategory);
|
||||
|
||||
void removeMaterialCategory(MaterialCategory materialCategory);
|
||||
|
||||
void addMaterialToMaterialCategory(MaterialCategory materialCategory);
|
||||
|
||||
List<Material> getMaterials();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.navalplanner.web.materials;
|
|||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -32,6 +33,7 @@ import org.navalplanner.business.materials.entities.Material;
|
|||
import org.navalplanner.business.materials.entities.MaterialCategory;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
import org.navalplanner.web.common.Level;
|
||||
import org.navalplanner.web.common.MessagesForUser;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
|
|
@ -43,6 +45,7 @@ import org.zkoss.zk.ui.util.GenericForwardComposer;
|
|||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Grid;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.SimpleListModel;
|
||||
import org.zkoss.zul.Textbox;
|
||||
import org.zkoss.zul.Tree;
|
||||
import org.zkoss.zul.TreeModel;
|
||||
|
|
@ -68,7 +71,7 @@ public class MaterialsController extends
|
|||
|
||||
private Tree categoriesTree;
|
||||
|
||||
private Grid materials;
|
||||
private Grid gridMaterials;
|
||||
|
||||
private Textbox txtCategory;
|
||||
|
||||
|
|
@ -81,6 +84,7 @@ public class MaterialsController extends
|
|||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
comp.setVariable("materialsController", this, true);
|
||||
messagesForUser = new MessagesForUser(messagesContainer);
|
||||
}
|
||||
|
||||
public TreeModel getMaterialCategories() {
|
||||
|
|
@ -233,11 +237,52 @@ public class MaterialsController extends
|
|||
}
|
||||
final MaterialCategory materialCategory = (MaterialCategory) treeitem.getValue();
|
||||
materialsModel.addMaterialToMaterialCategory(materialCategory);
|
||||
Util.reloadBindings(materials);
|
||||
Util.reloadBindings(gridMaterials);
|
||||
}
|
||||
|
||||
public void saveAndExit() {
|
||||
save();
|
||||
messagesForUser.showMessage(Level.INFO, _("Materials saved"));
|
||||
}
|
||||
|
||||
private void save() {
|
||||
validate();
|
||||
try {
|
||||
materialsModel.confirmSave();
|
||||
} catch (ValidationException e) {
|
||||
messagesForUser.showInvalidValues(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void validate() {
|
||||
ConstraintChecker.
|
||||
}
|
||||
|
||||
public void saveAndContinue() {
|
||||
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
|
||||
}
|
||||
|
||||
public void refreshMaterials() {
|
||||
final List<Material> materials = getMaterials();
|
||||
gridMaterials.setModel(new SimpleListModel(materials));
|
||||
Util.reloadBindings(gridMaterials);
|
||||
}
|
||||
|
||||
public List<Material> getMaterials() {
|
||||
return materialsModel.getMaterials();
|
||||
return getMaterials(categoriesTree.getSelectedItem());
|
||||
}
|
||||
|
||||
private List<Material> getMaterials(Treeitem treeitem) {
|
||||
final List<Material> result = new ArrayList<Material>();
|
||||
if (treeitem != null) {
|
||||
final MaterialCategory materialCategory = (MaterialCategory) treeitem.getValue();
|
||||
result.addAll(materialsModel.getMaterials(materialCategory));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.materials.daos.IMaterialCategoryDAO;
|
||||
|
|
@ -32,31 +33,7 @@ public class MaterialsModel implements IMaterialsModel {
|
|||
|
||||
MutableTreeModel<MaterialCategory> materialCategories = MutableTreeModel.create(MaterialCategory.class);
|
||||
|
||||
List<Material> materials = new ArrayList<Material>();
|
||||
|
||||
private void initializeMaterialCategories() {
|
||||
final List<MaterialCategory> categories = categoryDAO.getAllRootMaterialCategories();
|
||||
for (MaterialCategory materialCategory: categories) {
|
||||
materialCategories.addToRoot(materialCategory);
|
||||
addCategories(materialCategory, materialCategory.getSubcategories());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void initializeMaterials() {
|
||||
materials = new ArrayList(materialDAO.getAll());
|
||||
}
|
||||
|
||||
private void addCategories(MaterialCategory materialCategory, Set<MaterialCategory> categories) {
|
||||
for (MaterialCategory category: categories) {
|
||||
materialCategories.add(materialCategory, category);
|
||||
final Set<MaterialCategory> subcategories = category.getSubcategories();
|
||||
if (subcategories != null) {
|
||||
addCategories(category, subcategories);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly=true)
|
||||
public MutableTreeModel<MaterialCategory> getMaterialCategories() {
|
||||
if (materialCategories.isEmpty()) {
|
||||
|
|
@ -65,13 +42,38 @@ public class MaterialsModel implements IMaterialsModel {
|
|||
return materialCategories;
|
||||
}
|
||||
|
||||
private void initializeMaterialCategories() {
|
||||
final List<MaterialCategory> categories = categoryDAO.getAllRootMaterialCategories();
|
||||
for (MaterialCategory materialCategory: categories) {
|
||||
initializeMaterials(materialCategory.getMaterials());
|
||||
materialCategories.addToRoot(materialCategory);
|
||||
addCategories(materialCategory, materialCategory.getSubcategories());
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeMaterials(Set<Material> materials) {
|
||||
for (Material each: materials) {
|
||||
each.getDescription();
|
||||
}
|
||||
}
|
||||
|
||||
private void addCategories(MaterialCategory materialCategory, Set<MaterialCategory> categories) {
|
||||
for (MaterialCategory category: categories) {
|
||||
initializeMaterials(category.getMaterials());
|
||||
materialCategories.add(materialCategory, category);
|
||||
final Set<MaterialCategory> subcategories = category.getSubcategories();
|
||||
if (subcategories != null) {
|
||||
addCategories(category, subcategories);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly=true)
|
||||
public List<Material> getMaterials() {
|
||||
if (materials.isEmpty()) {
|
||||
initializeMaterials();
|
||||
}
|
||||
return materials;
|
||||
public List<Material> getMaterials(MaterialCategory materialCategory) {
|
||||
List<Material> result = new ArrayList<Material>();
|
||||
result.addAll(materialCategory.getMaterials());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -115,7 +117,30 @@ public class MaterialsModel implements IMaterialsModel {
|
|||
public void addMaterialToMaterialCategory(MaterialCategory materialCategory) {
|
||||
Material material = Material.create("");
|
||||
material.setCategory(materialCategory);
|
||||
materials.add(material);
|
||||
materialCategory.addMaterial(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void confirmSave() throws ValidationException {
|
||||
List<MaterialCategory> categories = new ArrayList<MaterialCategory>();
|
||||
asList(materialCategories.getRoot(), categories);
|
||||
for (MaterialCategory each: categories) {
|
||||
categoryDAO.save(each);
|
||||
}
|
||||
}
|
||||
|
||||
private void asList(MaterialCategory root, List<MaterialCategory> result) {
|
||||
List<MaterialCategory> list = new ArrayList<MaterialCategory>();
|
||||
for (int i = 0; i < materialCategories.getChildCount(root); i++) {
|
||||
final MaterialCategory materialCategory = materialCategories.getChild(root, i);
|
||||
list.add(materialCategory);
|
||||
result.add(materialCategory);
|
||||
}
|
||||
|
||||
for (MaterialCategory each: list) {
|
||||
asList(each, result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
<!--
|
||||
This file is part of ###PROJECT_NAME###
|
||||
This file is part of ###PROJECT_NAME###
|
||||
|
||||
Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
Desenvolvemento Tecnolóxico de Galicia
|
||||
Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
Desenvolvemento Tecnolóxico de Galicia
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<?page id="labelTypesList"?>
|
||||
|
|
@ -29,57 +29,93 @@
|
|||
|
||||
<zk>
|
||||
<window self="@{define(content)}"
|
||||
apply="org.navalplanner.web.materials.MaterialsController" >
|
||||
|
||||
<hbox>
|
||||
|
||||
apply="org.navalplanner.web.materials.MaterialsController">
|
||||
<vbox id="messagesContainer" />
|
||||
<tabbox>
|
||||
<tabs>
|
||||
<tab label="${i18n:_('Materials')}"></tab>
|
||||
</tabs>
|
||||
<tabpanels>
|
||||
<tabpanel>
|
||||
<hbox>
|
||||
<!-- Categories -->
|
||||
<vbox>
|
||||
<panel title="${i18n:_('Categories')}"
|
||||
border="normal">
|
||||
<panelchildren>
|
||||
<textbox id="txtCategory"
|
||||
style="margin-bottom: 4px;" />
|
||||
<button label="${i18n:_('Add')}"
|
||||
onClick="materialsController.addMaterialCategory()" />
|
||||
<tree id="categoriesTree"
|
||||
width="280px" rows="10" vflex="true" multiple="true"
|
||||
model="@{materialsController.materialCategories}"
|
||||
treeitemRenderer="@{materialsController.materialCategoryRenderer}"
|
||||
onSelect="materialsController.refreshMaterials()">
|
||||
<treecols>
|
||||
<treecol label="Name" />
|
||||
<treecol label="" />
|
||||
</treecols>
|
||||
</tree>
|
||||
</panelchildren>
|
||||
</panel>
|
||||
</vbox>
|
||||
|
||||
<vbox>
|
||||
<panel title="${i18n:_('Categories')}" border="normal">
|
||||
<panelchildren>
|
||||
<textbox id="txtCategory" style="margin-bottom: 4px;" />
|
||||
<button label="${i18n:_('Add')}" onClick="materialsController.addMaterialCategory()"/>
|
||||
<tree id="categoriesTree" width="280px" rows="10"
|
||||
vflex="true" multiple="true"
|
||||
model="@{materialsController.materialCategories}"
|
||||
treeitemRenderer="@{materialsController.materialCategoryRenderer}">
|
||||
<treecols>
|
||||
<treecol label="Name" />
|
||||
<treecol label="" />
|
||||
</treecols>
|
||||
</tree>
|
||||
</panelchildren>
|
||||
</panel>
|
||||
</vbox>
|
||||
<!-- Materials -->
|
||||
<vbox>
|
||||
<panel title="${i18n:_('Materials')}"
|
||||
border="normal">
|
||||
<panelchildren>
|
||||
<button label="${i18n:_('Add')}"
|
||||
onClick="materialsController.addMaterialToMaterialCategory(categoriesTree.selectedItem)" />
|
||||
<grid id="gridMaterials"
|
||||
fixedLayout="true"
|
||||
model="@{materialsController.materials}">
|
||||
<columns>
|
||||
<column
|
||||
label="${i18n:_('Code')}" />
|
||||
<column
|
||||
label="${i18n:_('Description')}" />
|
||||
<column
|
||||
label="${i18n:_('Unit price')}" />
|
||||
<column
|
||||
label="${i18n:_('Unit type')}" />
|
||||
<column
|
||||
label="${i18n:_('Disabled')}" />
|
||||
</columns>
|
||||
<rows>
|
||||
<row
|
||||
self="@{each='material'}" value="@{material}">
|
||||
<textbox
|
||||
value="@{material.code}" constraint="no empty:${i18n:_('cannot be null or empty')}" />
|
||||
<textbox
|
||||
value="@{material.description}" />
|
||||
<intbox
|
||||
value="@{material.defaultUnitPrice}" constraint="no empty:${i18n:_('cannot be null or empty')}" />
|
||||
<textbox
|
||||
value="@{material.unitType}" constraint="no empty:${i18n:_('cannot be null or empty')}" />
|
||||
<checkbox
|
||||
checked="@{material.disabled}" />
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
<vbox>
|
||||
<panel title="${i18n:_('Materials')}" border="normal">
|
||||
<panelchildren>
|
||||
<button label="${i18n:_('Add')}" onClick="materialsController.addMaterialToMaterialCategory(categoriesTree.selectedItem)"/>
|
||||
<grid id="materials" model="@{materialsController.materials}">
|
||||
<columns>
|
||||
<column label="${i18n:_('Code')}"/>
|
||||
<column label="${i18n:_('Description')}"/>
|
||||
<column label="${i18n:_('Unit price')}"/>
|
||||
<column label="${i18n:_('Unit type')}"/>
|
||||
<column label="${i18n:_('Disabled')}"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row self="@{each='material'}" value="@{material}">
|
||||
<textbox value="@{material.code}" />
|
||||
<textbox value="@{material.description}" />
|
||||
<textbox value="@{material.defaultUnitPrice}" />
|
||||
<textbox value="@{material.unitType}" />
|
||||
<checkbox checked="@{material.disabled}" />
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</panelchildren>
|
||||
</panel>
|
||||
</vbox>
|
||||
</panelchildren>
|
||||
</panel>
|
||||
</vbox>
|
||||
|
||||
</hbox>
|
||||
</hbox>
|
||||
</tabpanel>
|
||||
</tabpanels>
|
||||
</tabbox>
|
||||
|
||||
<button onClick="materialsController.saveAndExit()"
|
||||
label="${i18n:_('Save')}" />
|
||||
<button onClick="materialsController.saveAndContinue()"
|
||||
label="${i18n:_('Save & Continue')}" />
|
||||
<button onClick="materialsController.cancel()"
|
||||
label="${i18n:_('Cancel')}" />
|
||||
|
||||
</window>
|
||||
|
||||
</zk>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue