ItEr50S13AdaptacionServiciosRESTItEr49S18 : Refactoring the enumeration UnitTypeEnum to an Entity.

After the following patch, it must be updated or dropped the column unit_type to the table material.
Its unit_type can be null.

Option A:
ALTER TABLE material ALTER unit_type TYPE BIGINT;
UPDATE material SET unit_type = null;
-------
Option B:
ALTER TABLE material DROP unit_type BIGINT;
ALTER TABLE material ADD unit_type BIGINT;
This commit is contained in:
Susana Montes Pedreira 2010-03-24 14:12:11 +01:00 committed by Javier Moran Rua
parent cacfec4bbc
commit a0b22dc8c7
26 changed files with 493 additions and 34 deletions

View file

@ -35,6 +35,7 @@ import org.navalplanner.business.labels.daos.ILabelDAO;
import org.navalplanner.business.labels.daos.ILabelTypeDAO;
import org.navalplanner.business.materials.daos.IMaterialCategoryDAO;
import org.navalplanner.business.materials.daos.IMaterialDAO;
import org.navalplanner.business.materials.daos.IUnitTypeDAO;
import org.navalplanner.business.orders.daos.IHoursGroupDAO;
import org.navalplanner.business.orders.daos.IOrderDAO;
import org.navalplanner.business.orders.daos.IOrderElementDAO;
@ -165,6 +166,9 @@ public class Registry {
@Autowired
private ICalendarExceptionTypeDAO calendarExceptionTypeDAO;
@Autowired
private IUnitTypeDAO unitTypeDAO;
private Registry() {
}
@ -172,6 +176,10 @@ public class Registry {
return singleton;
}
public static IUnitTypeDAO getUnitTypeDAO() {
return getInstance().unitTypeDAO;
}
public static IAdvanceTypeDAO getAdvanceTypeDao() {
return getInstance().advanceTypeDao;
}

View file

@ -18,9 +18,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.navalplanner.business.materials.entities;
package org.navalplanner.business.materials.bootstrap;
import org.navalplanner.business.IDataBootstrap;
import org.navalplanner.business.materials.entities.MaterialCategory;
/**
* Contratct for {@link MaterialCategory}.

View file

@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.navalplanner.business.materials.entities;
package org.navalplanner.business.materials.bootstrap;
import org.navalplanner.business.calendars.entities.CalendarExceptionType;
import org.navalplanner.business.materials.daos.IMaterialCategoryDAO;

View file

@ -18,10 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.navalplanner.business.materials.entities;
package org.navalplanner.business.materials.bootstrap;
import org.navalplanner.business.common.Registry;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.materials.entities.MaterialCategory;
/**

View file

@ -1,3 +1,5 @@
/*
* This file is part of NavalPlan
*
@ -18,9 +20,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.navalplanner.business.materials.entities;
package org.navalplanner.business.materials.bootstrap;
import org.navalplanner.business.materials.entities.UnitType;
/**
* Defines the default {@link UnitType}.
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
public enum PredefinedUnitTypes {
public enum UnitTypeEnum {
UNITS("units"),
KILOGRAMS("kg"),
KILOMETERS("km"),
@ -32,10 +42,18 @@ public enum UnitTypeEnum {
private String measure;
private UnitTypeEnum(String measure) {
private PredefinedUnitTypes(String measure) {
this.measure = measure;
}
public UnitType createUnitType() {
return UnitType.create(measure);
}
public String getMeasure() {
return measure;
}
public String toString() {
return measure;
}

View file

@ -0,0 +1,55 @@
/*
* This file is part of NavalPlan
*
* 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 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/>.
*/
package org.navalplanner.business.materials.bootstrap;
import org.navalplanner.business.IDataBootstrap;
import org.navalplanner.business.materials.daos.IUnitTypeDAO;
import org.navalplanner.business.materials.entities.UnitType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* Creates the bootstrap of the predefined {@link UnitType}.
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@Component
@Scope("singleton")
public class UnitTypeBootstrap implements IDataBootstrap {
@Autowired
private IUnitTypeDAO unitTypeDAO;
@Transactional
@Override
public void loadRequiredData() {
for (PredefinedUnitTypes predefinedUnitType : PredefinedUnitTypes
.values()) {
if (!unitTypeDAO.existsUnitTypeByName(predefinedUnitType
.getMeasure())) {
unitTypeDAO.save(predefinedUnitType.createUnitType());
}
}
}
}

View file

@ -0,0 +1,40 @@
/*
* This file is part of NavalPlan
*
* 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 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/>.
*/
package org.navalplanner.business.materials.daos;
import java.util.List;
import org.navalplanner.business.common.daos.IIntegrationEntityDAO;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.materials.entities.UnitType;
/**
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
public interface IUnitTypeDAO extends IIntegrationEntityDAO<UnitType> {
List<UnitType> getAll();
UnitType findByName(String measure) throws InstanceNotFoundException;
boolean existsUnitTypeByName(String measure);
}

View file

@ -0,0 +1,77 @@
/*
* This file is part of NavalPlan
*
* 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 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/>.
*/
package org.navalplanner.business.materials.daos;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.Restrictions;
import org.navalplanner.business.common.daos.IntegrationEntityDAO;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.materials.entities.UnitType;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
/**
* DAO for {@link UnitType}
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class UnitTypeDAO extends IntegrationEntityDAO<UnitType> implements
IUnitTypeDAO {
@Override
public List<UnitType> getAll() {
return list(UnitType.class);
}
@Override
public UnitType findByName(String measure) throws InstanceNotFoundException {
if (StringUtils.isBlank(measure)) {
throw new InstanceNotFoundException(null, getEntityClass()
.getName());
}
UnitType unitType = (UnitType) getSession().createCriteria(
UnitType.class).add(
Restrictions.eq("measure", measure)).uniqueResult();
if (unitType == null) {
throw new InstanceNotFoundException(measure, getEntityClass()
.getName());
} else {
return unitType;
}
}
@Override
public boolean existsUnitTypeByName(String measure) {
try {
findByName(measure);
} catch (InstanceNotFoundException e) {
return false;
}
return true;
}
}

View file

@ -45,7 +45,7 @@ public class Material extends BaseEntity implements Comparable {
private BigDecimal defaultUnitPrice = new BigDecimal(0);
private UnitTypeEnum unitType;
private UnitType unitType;
private boolean disabled;
@ -105,11 +105,11 @@ public class Material extends BaseEntity implements Comparable {
this.defaultUnitPrice = defaultUnitPrice;
}
public UnitTypeEnum getUnitType() {
public UnitType getUnitType() {
return unitType;
}
public void setUnitType(UnitTypeEnum unitType) {
public void setUnitType(UnitType unitType) {
this.unitType = unitType;
}

View file

@ -0,0 +1,64 @@
/*
* This file is part of NavalPlan
*
* 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 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/>.
*/
package org.navalplanner.business.materials.entities;
import org.hibernate.validator.NotEmpty;
import org.navalplanner.business.common.IntegrationEntity;
import org.navalplanner.business.common.Registry;
import org.navalplanner.business.materials.daos.IUnitTypeDAO;
/**
* UnitType entity
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*
*/
public class UnitType extends IntegrationEntity{
public static UnitType create(String measure) {
return (UnitType) create(new UnitType(measure));
}
private String measure;
// Default constructor, needed by Hibernate
protected UnitType() {
}
private UnitType(String measure) {
this.measure = measure;
}
@NotEmpty(message = "measure not specified")
public String getMeasure() {
return measure;
}
public void setMeasure(String measure) {
this.measure = measure;
}
@Override
protected IUnitTypeDAO getIntegrationEntityDAO() {
return Registry.getUnitTypeDAO();
}
}

View file

@ -17,11 +17,7 @@
<property name="defaultUnitPrice" column="default_unit_price" />
<property name="unitType" column="unit_type" >
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.navalplanner.business.materials.entities.UnitTypeEnum</param>
</type>
</property>
<many-to-one name="unitType" class="UnitType" column="unit_type" />
<property name="disabled"/>
@ -29,6 +25,21 @@
</class>
<!-- UnitType -->
<class name="UnitType" table="UNIT_TYPE">
<id name="id" type="long" access="property">
<generator class="hilo">
<param name="max_lo">100</param>
</generator>
</id>
<version name="version" access="property" type="long" />
<property name="code" access="property" not-null="true" unique="true"/>
<property name="measure" access="field"/>
</class>
<!-- MaterialCategory -->
<class name="MaterialCategory" table="MATERIAL_CATEGORY">
<id name="id" type="long" access="property">

View file

@ -26,6 +26,7 @@ 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.navalplanner.business.materials.entities.UnitType;
import org.zkoss.ganttz.util.MutableTreeModel;
/**
@ -53,4 +54,7 @@ public interface IMaterialsModel {
void removeMaterial(Material material);
List<UnitType> getUnitTypes();
void loadUnitTypes();
}

View file

@ -32,6 +32,7 @@ import org.hibernate.validator.InvalidValue;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.materials.entities.Material;
import org.navalplanner.business.materials.entities.MaterialCategory;
import org.navalplanner.business.materials.entities.UnitType;
import org.navalplanner.web.common.ConstraintChecker;
import org.navalplanner.web.common.IMessagesForUser;
import org.navalplanner.web.common.Level;
@ -47,6 +48,10 @@ import org.zkoss.zk.ui.event.InputEvent;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Row;
import org.zkoss.zul.Rows;
@ -86,6 +91,7 @@ public class MaterialsController extends
private Component messagesContainer;
private UnitTypeListRenderer unitTypeListRenderer = new UnitTypeListRenderer();
@Override
public void doAfterCompose(Component comp) throws Exception {
@ -93,6 +99,9 @@ public class MaterialsController extends
comp.setVariable("materialsController", this, true);
messagesForUser = new MessagesForUser(messagesContainer);
// load the unit types
loadUnitTypes();
// Renders grid and enables delete button is material is new
gridMaterials.addEventListener("onInitRender", new EventListener() {
@ -115,6 +124,21 @@ public class MaterialsController extends
});
}
private void loadUnitTypes() {
materialsModel.loadUnitTypes();
}
public List<UnitType> getUnitTypes() {
return materialsModel.getUnitTypes();
}
public void selectUnitType(Component self) {
Listitem selectedItem = ((Listbox) self).getSelectedItem();
UnitType unitType = (UnitType) selectedItem.getValue();
Material material = (Material) ((Row) self.getParent()).getValue();
material.setUnitType(unitType);
}
public TreeModel getMaterialCategories() {
return materialsModel.getMaterialCategories();
}
@ -410,4 +434,29 @@ public class MaterialsController extends
Util.reloadBindings(gridMaterials);
}
public UnitTypeListRenderer getRenderer() {
return unitTypeListRenderer;
}
/**
* RowRenderer for a @{UnitType} element
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
public class UnitTypeListRenderer implements ListitemRenderer {
@Override
public void render(Listitem listItem, Object data) throws Exception {
final UnitType unitType = (UnitType) data;
listItem.setValue(unitType);
Listcell listCell = new Listcell(unitType.getMeasure());
listItem.appendChild(listCell);
Material material = (Material) ((Row) listItem.getListbox()
.getParent()).getValue();
if ((material.getUnitType() != null)
&& (unitType.getId().equals(material.getUnitType().getId()))) {
listItem.getListbox().setSelectedItem(listItem);
}
}
}
}

View file

@ -35,8 +35,10 @@ import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
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.daos.IUnitTypeDAO;
import org.navalplanner.business.materials.entities.Material;
import org.navalplanner.business.materials.entities.MaterialCategory;
import org.navalplanner.business.materials.entities.UnitType;
import org.navalplanner.web.common.concurrentdetection.OnConcurrentModification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
@ -56,9 +58,14 @@ public class MaterialsModel implements IMaterialsModel {
@Autowired
IMaterialDAO materialDAO;
@Autowired
IUnitTypeDAO unitTypeDAO;
MutableTreeModel<MaterialCategory> materialCategories = MutableTreeModel
.create(MaterialCategory.class);
private List<UnitType> unitTypes = new ArrayList<UnitType>();
@Override
@Transactional(readOnly=true)
public MutableTreeModel<MaterialCategory> getMaterialCategories() {
@ -87,6 +94,9 @@ public class MaterialsModel implements IMaterialsModel {
private void initializeMaterials(Set<Material> materials) {
for (Material each: materials) {
each.getDescription();
if (each.getUnitType() != null) {
each.getUnitType().getMeasure();
}
}
}
@ -231,4 +241,18 @@ public class MaterialsModel implements IMaterialsModel {
return result;
}
@Override
@Transactional(readOnly = true)
public void loadUnitTypes() {
List<UnitType> result = new ArrayList<UnitType>();
for (UnitType each : unitTypeDAO.findAll()) {
each.getMeasure();
result.add(each);
}
this.unitTypes = result;
}
public List<UnitType> getUnitTypes() {
return this.unitTypes;
}
}

View file

@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory;
import org.navalplanner.business.materials.entities.Material;
import org.navalplanner.business.materials.entities.MaterialAssignment;
import org.navalplanner.business.materials.entities.MaterialCategory;
import org.navalplanner.business.materials.entities.UnitType;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.web.common.Util;
import org.zkoss.zk.ui.Component;
@ -45,7 +46,9 @@ import org.zkoss.zul.Doublebox;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Row;
import org.zkoss.zul.SimpleListModel;
@ -88,6 +91,7 @@ public abstract class AssignedMaterialsController<T, A> extends GenericForwardCo
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
getModel().loadUnitTypes();
createAssignmentsBoxComponent(assignmentsBox);
}
@ -508,6 +512,63 @@ public abstract class AssignedMaterialsController<T, A> extends GenericForwardCo
protected abstract double getUnits(A assignment);
private UnitTypeListRenderer unitTypeListRenderer = new UnitTypeListRenderer();
public List<UnitType> getUnitTypes() {
return getModel().getUnitTypes();
}
public void selectUnitType(Component self) {
Listitem selectedItem = ((Listbox) self).getSelectedItem();
UnitType unitType = (UnitType) selectedItem.getValue();
Material material = (Material) ((Row) self.getParent()).getValue();
material.setUnitType(unitType);
}
public UnitTypeListRenderer getRenderer() {
return unitTypeListRenderer;
}
/**
* RowRenderer for a @{UnitType} element
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
public class UnitTypeListRenderer implements ListitemRenderer {
@Override
public void render(Listitem listItem, Object data) throws Exception {
final UnitType unitType = (UnitType) data;
listItem.setValue(unitType);
Listcell listCell = new Listcell(unitType.getMeasure());
listItem.appendChild(listCell);
Listbox listbox = listItem.getListbox();
Component parent = listbox.getParent();
if (parent instanceof Row) {
Object assigment = (Object) ((Row) parent).getValue();
if (getModel().isCurrentUnitType(assigment, unitType)) {
listItem.getListbox().setSelectedItem(listItem);
}
return;
}
if (parent instanceof Listcell) {
Material material = (Material) ((Listitem) (parent.getParent()))
.getValue();
if (isCurrentUnitType(material, unitType)) {
listItem.getListbox().setSelectedItem(listItem);
}
}
}
}
private boolean isCurrentUnitType(Material material, UnitType unitType) {
return ((material != null)
&& (material.getUnitType() != null)
&& (unitType
.getId().equals(material.getUnitType().getId())));
}
}

View file

@ -26,8 +26,10 @@ import java.util.List;
import org.navalplanner.business.materials.daos.IMaterialCategoryDAO;
import org.navalplanner.business.materials.daos.IMaterialDAO;
import org.navalplanner.business.materials.daos.IUnitTypeDAO;
import org.navalplanner.business.materials.entities.Material;
import org.navalplanner.business.materials.entities.MaterialCategory;
import org.navalplanner.business.materials.entities.UnitType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.zkoss.ganttz.util.MutableTreeModel;
@ -46,6 +48,9 @@ public abstract class AssignedMaterialsModel<T, A> implements
@Autowired
private IMaterialDAO materialDAO;
@Autowired
private IUnitTypeDAO unitTypeDAO;
private MutableTreeModel<MaterialCategory> materialCategories = MutableTreeModel
.create(MaterialCategory.class);
@ -54,6 +59,8 @@ public abstract class AssignedMaterialsModel<T, A> implements
private List<Material> matchingMaterials = new ArrayList<Material>();
private List<UnitType> unitTypes = new ArrayList<UnitType>();
@Transactional(readOnly = true)
public void initEdit(T element) {
assignAndReattach(element);
@ -246,4 +253,14 @@ public abstract class AssignedMaterialsModel<T, A> implements
protected abstract BigDecimal getTotalPrice(A each);
@Override
@Transactional(readOnly = true)
public void loadUnitTypes() {
unitTypes = unitTypeDAO.findAll();
}
@Override
public List<UnitType> getUnitTypes() {
return unitTypes;
}
}

View file

@ -28,6 +28,7 @@ import java.util.Set;
import org.navalplanner.business.materials.entities.Material;
import org.navalplanner.business.materials.entities.MaterialAssignment;
import org.navalplanner.business.materials.entities.MaterialCategory;
import org.navalplanner.business.materials.entities.UnitType;
import org.navalplanner.business.orders.daos.IOrderElementDAO;
import org.navalplanner.business.orders.entities.OrderElement;
import org.springframework.beans.factory.annotation.Autowired;
@ -139,4 +140,12 @@ public class AssignedMaterialsToOrderElementModel extends
return orderElement != null;
}
@Override
public boolean isCurrentUnitType(Object assigment, UnitType unitType) {
MaterialAssignment material = (MaterialAssignment) assigment;
return ((material != null)
&& (material.getMaterial().getUnitType() != null) && (unitType
.getId().equals(material.getMaterial().getUnitType().getId())));
}
}

View file

@ -24,6 +24,7 @@ import java.util.List;
import org.navalplanner.business.materials.entities.Material;
import org.navalplanner.business.materials.entities.MaterialCategory;
import org.navalplanner.business.materials.entities.UnitType;
import org.zkoss.zul.TreeModel;
/**
@ -42,6 +43,8 @@ public interface IAssignedMaterialsModel<T, A> {
List<A> getAssignedMaterials(MaterialCategory materialCategory);
abstract boolean isCurrentUnitType(Object assigment, UnitType unitType);
List<Material> getMatchingMaterials();
TreeModel getMaterialCategories();
@ -54,4 +57,8 @@ public interface IAssignedMaterialsModel<T, A> {
void searchMaterials(String text, MaterialCategory materialCategory);
void loadUnitTypes();
List<UnitType> getUnitTypes();
}

View file

@ -21,6 +21,7 @@
package org.navalplanner.web.orders.materials;
import org.navalplanner.business.materials.entities.MaterialAssignment;
import org.navalplanner.business.materials.entities.UnitType;
import org.navalplanner.business.orders.entities.OrderElement;
@ -30,6 +31,8 @@ import org.navalplanner.business.orders.entities.OrderElement;
public interface IAssignedMaterialsToOrderElementModel extends
IAssignedMaterialsModel<OrderElement, MaterialAssignment> {
boolean isCurrentUnitType(Object assigment, UnitType unitType);
OrderElement getOrderElement();
void initEdit(OrderElement orderElement);

View file

@ -27,6 +27,7 @@ import java.util.List;
import org.navalplanner.business.materials.entities.Material;
import org.navalplanner.business.materials.entities.MaterialAssignmentTemplate;
import org.navalplanner.business.materials.entities.MaterialCategory;
import org.navalplanner.business.materials.entities.UnitType;
import org.navalplanner.business.templates.daos.IOrderElementTemplateDAO;
import org.navalplanner.business.templates.entities.OrderElementTemplate;
import org.navalplanner.web.orders.materials.AssignedMaterialsModel;
@ -130,4 +131,12 @@ public class AssignedMaterialsToOrderElementTemplateModel extends
template.removeMaterialAssignment(materialAssignment);
}
@Override
public boolean isCurrentUnitType(Object assigment, UnitType unitType) {
MaterialAssignmentTemplate material = (MaterialAssignmentTemplate) assigment;
return ((material != null)
&& (material.getMaterial().getUnitType() != null) && (unitType
.getId().equals(material.getMaterial().getUnitType().getId())));
}
}

View file

@ -20,6 +20,7 @@
package org.navalplanner.web.templates.materials;
import org.navalplanner.business.materials.entities.MaterialAssignmentTemplate;
import org.navalplanner.business.materials.entities.UnitType;
import org.navalplanner.business.templates.entities.OrderElementTemplate;
import org.navalplanner.web.orders.materials.IAssignedMaterialsModel;
@ -30,6 +31,8 @@ import org.navalplanner.web.orders.materials.IAssignedMaterialsModel;
public interface IAssignedMaterialsToOrderElementTemplateModel extends
IAssignedMaterialsModel<OrderElementTemplate, MaterialAssignmentTemplate> {
public boolean isCurrentUnitType(Object assigment, UnitType unitType);
OrderElementTemplate getTemplate();
}

View file

@ -40,10 +40,10 @@ import org.navalplanner.business.common.Registry;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.labels.entities.Label;
import org.navalplanner.business.materials.bootstrap.PredefinedMaterialCategories;
import org.navalplanner.business.materials.entities.Material;
import org.navalplanner.business.materials.entities.MaterialAssignment;
import org.navalplanner.business.materials.entities.MaterialCategory;
import org.navalplanner.business.materials.entities.PredefinedMaterialCategories;
import org.navalplanner.business.orders.entities.HoursGroup;
import org.navalplanner.business.orders.entities.ICriterionRequirable;
import org.navalplanner.business.orders.entities.Order;

View file

@ -28,11 +28,6 @@
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<zscript>
Object[] unitTypes = org.navalplanner.business.materials.entities.UnitTypeEnum
.values();
</zscript>
<window self="@{define(content)}"
apply="org.navalplanner.web.materials.MaterialsController">
<vbox id="messagesContainer" />
@ -100,8 +95,9 @@
constraint="no empty:${i18n:_('cannot be null or empty')}" />
<textbox value="@{material.description}" />
<doublebox value="@{material.defaultUnitPrice}" />
<listbox mold="select" model="@{unitTypes}"
selectedItem="@{material.unitType}"/>
<listbox mold="select" model="@{materialsController.unitTypes}"
onSelect = "materialsController.selectUnitType(self)"
itemRenderer="@{materialsController.renderer}"/>
<label value="@{material.category.name}" />
<checkbox checked="@{material.disabled}" />
<button sclass="icono"

View file

@ -22,8 +22,10 @@
<datebox value="@{assignedMaterial.estimatedAvailability}" />
<doublebox value="@{assignedMaterial.units}"
onChange="assignedMaterialsController.updateTotalPrice(self.parent)" />
<listbox mold="select" model="@{unitTypes}"
selectedItem="@{assignedMaterial.material.unitType}" disabled="true" />
<listbox mold="select" model="@{assignedMaterialsController.unitTypes}"
onSelect = "assignedMaterialsController.selectUnitType(self)"
itemRenderer="@{assignedMaterialsController.renderer}"
disabled="true"/>
<doublebox value="@{assignedMaterial.unitPrice}"
onChange="assignedMaterialsController.updateTotalPrice(self.parent)" />
<doublebox value="@{assignedMaterial.totalPrice}" disabled="${true}"/>

View file

@ -19,8 +19,6 @@
-->
<zk>
<zscript><![CDATA[
Object[] unitTypes = org.navalplanner.business.materials.entities.UnitTypeEnum
.values();
Object[] materialStatus = org.navalplanner.business.materials.entities.MaterialStatusEnum
.values();
materialAssignmentComponent = self;
@ -116,10 +114,10 @@
<listcell label="@{material.code}" />
<listcell label="@{material.description}" />
<listcell>
<listbox mold="select"
model="@{unitTypes}"
selectedItem="@{material.unitType}"
disabled="true" />
<listbox mold="select" model="@{assignedMaterialsController.unitTypes}"
onSelect = "assignedMaterialsController.selectUnitType(self)"
itemRenderer="@{assignedMaterialsController.renderer}"
disabled="true"/>
</listcell>
<listcell label="@{material.defaultUnitPrice}" />
<listcell label="@{material.category.name}" />

View file

@ -19,8 +19,10 @@
readonly="true" />
<doublebox value="@{assignedMaterial.units}"
onChange="assignedMaterialsController.updateTotalPrice(self.parent)" />
<listbox mold="select" model="@{unitTypes}"
selectedItem="@{assignedMaterial.material.unitType}" disabled="true" />
<listbox mold="select" model="@{assignedMaterialsController.unitTypes}"
onSelect = "assignedMaterialsController.selectUnitType(self)"
itemRenderer="@{assignedMaterialsController.renderer}"
disabled="true"/>
<doublebox value="@{assignedMaterial.unitPrice}"
onChange="assignedMaterialsController.updateTotalPrice(self.parent)" />
<doublebox id="totalPrice" value="@{assignedMaterial.totalPrice}" disabled="${true}"/>