ItEr35S14CUAdministracionMateriaisItEr34S14: Add Material to Material Category
This commit is contained in:
parent
cf66a19fc2
commit
e4e958a657
6 changed files with 78 additions and 12 deletions
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
package org.navalplanner.business.materials.daos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
import org.navalplanner.business.materials.entities.Material;
|
||||
|
||||
|
|
@ -30,4 +32,6 @@ import org.navalplanner.business.materials.entities.Material;
|
|||
*/
|
||||
public interface IMaterialDAO extends IGenericDAO<Material, Long> {
|
||||
|
||||
List<Material> getAll();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
package org.navalplanner.business.materials.daos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.materials.entities.Material;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -36,4 +38,9 @@ import org.springframework.stereotype.Repository;
|
|||
public class MaterialDAO extends GenericDAOHibernate<Material, Long> implements
|
||||
IMaterialDAO {
|
||||
|
||||
@Override
|
||||
public List<Material> getAll() {
|
||||
return list(Material.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@
|
|||
|
||||
package org.navalplanner.web.materials;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.materials.entities.Material;
|
||||
import org.navalplanner.business.materials.entities.MaterialCategory;
|
||||
import org.zkoss.ganttz.util.MutableTreeModel;
|
||||
|
||||
|
|
@ -37,4 +40,8 @@ public interface IMaterialsModel {
|
|||
|
||||
void removeMaterialCategory(MaterialCategory materialCategory);
|
||||
|
||||
void addMaterialToMaterialCategory(MaterialCategory materialCategory);
|
||||
|
||||
List<Material> getMaterials();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ package org.navalplanner.web.materials;
|
|||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
|
|
@ -31,6 +32,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.Util;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
|
|
@ -39,6 +41,7 @@ import org.zkoss.zk.ui.event.EventListener;
|
|||
import org.zkoss.zk.ui.event.Events;
|
||||
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.Textbox;
|
||||
import org.zkoss.zul.Tree;
|
||||
|
|
@ -65,6 +68,8 @@ public class MaterialsController extends
|
|||
|
||||
private Tree categoriesTree;
|
||||
|
||||
private Grid materials;
|
||||
|
||||
private Textbox txtCategory;
|
||||
|
||||
private IMessagesForUser messagesForUser;
|
||||
|
|
@ -222,4 +227,17 @@ public class MaterialsController extends
|
|||
return (Textbox) tc.getChildren().get(0);
|
||||
}
|
||||
|
||||
public void addMaterialToMaterialCategory(Treeitem treeitem) {
|
||||
if (treeitem == null) {
|
||||
return;
|
||||
}
|
||||
final MaterialCategory materialCategory = (MaterialCategory) treeitem.getValue();
|
||||
materialsModel.addMaterialToMaterialCategory(materialCategory);
|
||||
Util.reloadBindings(materials);
|
||||
}
|
||||
|
||||
public List<Material> getMaterials() {
|
||||
return materialsModel.getMaterials();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.navalplanner.web.materials;
|
|||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -9,6 +10,8 @@ import org.apache.commons.lang.Validate;
|
|||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.materials.daos.IMaterialCategoryDAO;
|
||||
import org.navalplanner.business.materials.daos.IMaterialDAO;
|
||||
import org.navalplanner.business.materials.entities.Material;
|
||||
import org.navalplanner.business.materials.entities.MaterialCategory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -24,8 +27,13 @@ public class MaterialsModel implements IMaterialsModel {
|
|||
@Autowired
|
||||
IMaterialCategoryDAO categoryDAO;
|
||||
|
||||
@Autowired
|
||||
IMaterialDAO materialDAO;
|
||||
|
||||
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) {
|
||||
|
|
@ -34,6 +42,11 @@ public class MaterialsModel implements IMaterialsModel {
|
|||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
|
|
@ -52,6 +65,15 @@ public class MaterialsModel implements IMaterialsModel {
|
|||
return materialCategories;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly=true)
|
||||
public List<Material> getMaterials() {
|
||||
if (materials.isEmpty()) {
|
||||
initializeMaterials();
|
||||
}
|
||||
return materials;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMaterialCategory(MaterialCategory parent, MaterialCategory child) throws ValidationException {
|
||||
Validate.notNull(child);
|
||||
|
|
@ -84,9 +106,16 @@ public class MaterialsModel implements IMaterialsModel {
|
|||
return obj1.getName().equals(obj2.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMaterialCategory(MaterialCategory materialCategory) {
|
||||
materialCategories.remove(materialCategory);
|
||||
}
|
||||
@Override
|
||||
public void removeMaterialCategory(MaterialCategory materialCategory) {
|
||||
materialCategories.remove(materialCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMaterialToMaterialCategory(MaterialCategory materialCategory) {
|
||||
Material material = Material.create("");
|
||||
material.setCategory(materialCategory);
|
||||
materials.add(material);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,14 +56,14 @@
|
|||
<vbox>
|
||||
<panel title="${i18n:_('Materials')}" border="normal">
|
||||
<panelchildren>
|
||||
<button label="${i18n:_('Add')}" onClick="materialsController.addMaterial(categoriesTree.selected)"/>
|
||||
<newdatasortablegrid>
|
||||
<button label="${i18n:_('Add')}" onClick="materialsController.addMaterialToMaterialCategory(categoriesTree.selectedItem)"/>
|
||||
<grid id="materials" model="@{materialsController.materials}">
|
||||
<columns>
|
||||
<newdatasortablecolumn label="${i18n:_('Code')}"/>
|
||||
<newdatasortablecolumn label="${i18n:_('Description')}"/>
|
||||
<newdatasortablecolumn label="${i18n:_('Unit price')}"/>
|
||||
<newdatasortablecolumn label="${i18n:_('Unit type')}"/>
|
||||
<newdatasortablecolumn label="${i18n:_('Disabled')}"/>
|
||||
<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}">
|
||||
|
|
@ -71,9 +71,10 @@
|
|||
<textbox value="@{material.description}" />
|
||||
<textbox value="@{material.defaultUnitPrice}" />
|
||||
<textbox value="@{material.unitType}" />
|
||||
<checkbox checked="@{material.disabled}" />
|
||||
</row>
|
||||
</rows>
|
||||
</newdatasortablegrid>
|
||||
</grid>
|
||||
</panelchildren>
|
||||
</panel>
|
||||
</vbox>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue