ItEr60S04ValidacionEProbasFuncionaisItEr59S04: [Bug #565] Fixed translation problem for enums from business layer.

This commit is contained in:
Manuel Rego Casasnovas 2010-08-04 09:18:06 +02:00
parent be81a2f5f0
commit 3743f552e9
26 changed files with 143 additions and 125 deletions

View file

@ -20,7 +20,7 @@
package org.navalplanner.business.materials.entities;
import org.navalplanner.business.i18n.I18nHelper;
import static org.navalplanner.business.i18n.I18nHelper._;
/**
*
@ -34,13 +34,6 @@ public enum MaterialStatusEnum {
PROCESSING(_("PROCESSING")),
CANCELED(_("CANCELED"));
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
private String description;
private MaterialStatusEnum(String description) {
@ -48,7 +41,7 @@ public enum MaterialStatusEnum {
}
public String toString() {
return I18nHelper._(this.description);
return this.description;
}
}

View file

@ -20,7 +20,7 @@
package org.navalplanner.business.orders.entities;
import org.navalplanner.business.i18n.I18nHelper;
import static org.navalplanner.business.i18n.I18nHelper._;
/**
@ -33,13 +33,6 @@ public enum OrderStatusEnum {
_("FINISHED")), CANCELLED(_("CANCELLED")), SUBCONTRACTED_PENDING_ORDER(
_("SUBCONTRACTED PENDING ORDER")), STORED(_("STORED"));
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
private String description;
private OrderStatusEnum(String description) {
@ -47,7 +40,7 @@ public enum OrderStatusEnum {
}
public String toString() {
return I18nHelper._(this.description);
return this.description;
}
public static OrderStatusEnum getDefault() {

View file

@ -20,7 +20,7 @@
package org.navalplanner.business.planner.entities;
import org.navalplanner.business.i18n.I18nHelper;
import static org.navalplanner.business.i18n.I18nHelper._;
/**
* Possible states of a {@link SubcontractedTaskData}.
@ -31,13 +31,6 @@ public enum SubcontractState {
PENDING(_("Pending"), true), FAILED_SENT(_("Failed sent"), true), SUCCESS_SENT(
_("Success sent"), false);
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
private String name;
private boolean sendable;
@ -48,7 +41,7 @@ public enum SubcontractState {
@Override
public String toString() {
return I18nHelper._(name);
return name;
}
public boolean isSendable() {

View file

@ -20,7 +20,7 @@
package org.navalplanner.business.planner.entities;
import org.navalplanner.business.i18n.I18nHelper;
import static org.navalplanner.business.i18n.I18nHelper._;
public enum TaskStatusEnum {
ALL(_("All")),
@ -29,13 +29,6 @@ public enum TaskStatusEnum {
PENDING(_("Pending")),
BLOCKED(_("Blocked"));
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
private String value;
private TaskStatusEnum(String value) {
@ -43,6 +36,6 @@ public enum TaskStatusEnum {
}
public String toString() {
return I18nHelper._(value);
return value;
}
}

View file

@ -235,4 +235,9 @@ public class WorkingArrangementPerOrderDTO {
}
return false;
}
public void setStatus(String status) {
this.status = status;
}
}

View file

@ -20,7 +20,7 @@
package org.navalplanner.business.resources.entities;
import org.navalplanner.business.i18n.I18nHelper;
import static org.navalplanner.business.i18n.I18nHelper._;
/**
@ -33,13 +33,6 @@ public enum ResourceEnum {
WORKER(Worker.class, _("WORKER")),
MACHINE(Machine.class, _("MACHINE"));
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
private Class<? extends Resource> klass;
private final String displayName;
@ -53,7 +46,7 @@ public enum ResourceEnum {
}
public String getDisplayName() {
return I18nHelper._(displayName);
return displayName;
}
public static ResourceEnum getDefault() {

View file

@ -20,7 +20,7 @@
package org.navalplanner.business.users.entities;
import org.navalplanner.business.i18n.I18nHelper;
import static org.navalplanner.business.i18n.I18nHelper._;
/**
* Available types of {@link OrderAuthorization}.
@ -32,13 +32,6 @@ public enum OrderAuthorizationType {
READ_AUTHORIZATION(_("Read authorization")),
WRITE_AUTHORIZATION(_("Write authorization"));
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
private final String displayName;
private OrderAuthorizationType(String displayName) {
@ -46,6 +39,6 @@ public enum OrderAuthorizationType {
}
public String getDisplayName() {
return I18nHelper._(displayName);
return displayName;
}
}

View file

@ -20,7 +20,7 @@
package org.navalplanner.business.users.entities;
import org.navalplanner.business.i18n.I18nHelper;
import static org.navalplanner.business.i18n.I18nHelper._;
/**
* Available user roles.
@ -36,13 +36,6 @@ public enum UserRole {
ROLE_EDIT_ALL_ORDERS(_("All orders edition allowed")),
ROLE_CREATE_ORDER(_("Order creation allowed"));
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
private final String displayName;
private UserRole(String displayName) {
@ -50,7 +43,7 @@ public enum UserRole {
}
public String getDisplayName() {
return I18nHelper._(displayName);
return displayName;
}
}

View file

@ -23,20 +23,13 @@
*/
package org.navalplanner.business.workreports.entities;
import org.navalplanner.business.i18n.I18nHelper;
import static org.navalplanner.business.i18n.I18nHelper._;
public enum HoursManagementEnum {
NUMBER_OF_HOURS(_("Number of assigned hours.")),
HOURS_CALCULATED_BY_CLOCK(_("Number of hours calculated by clock.")),
NUMBER_OF_HOURS_AND_CLOCK(_("Number of assigned hours and the time."));
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
NUMBER_OF_HOURS(_("Number of assigned hours")),
HOURS_CALCULATED_BY_CLOCK(_("Number of hours calculated by clock")),
NUMBER_OF_HOURS_AND_CLOCK(_("Number of assigned hours and the time"));
private String description;
@ -45,7 +38,7 @@ public enum HoursManagementEnum {
}
public String toString() {
return I18nHelper._(this.description);
return this.description;
}
public static HoursManagementEnum getDefault() {

View file

@ -23,7 +23,7 @@
*/
package org.navalplanner.business.workreports.entities;
import org.navalplanner.business.i18n.I18nHelper;
import static org.navalplanner.business.i18n.I18nHelper._;
/**
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
@ -32,13 +32,6 @@ public enum PositionInWorkReportEnum {
HEADING(_("heading")), LINE(_("line"));
/**
* Forces to mark the string as needing translation
*/
private static String _(String string) {
return string;
}
private String displayName;
private PositionInWorkReportEnum(String displayName) {
@ -50,7 +43,7 @@ public enum PositionInWorkReportEnum {
}
public String toString() {
return I18nHelper._(displayName);
return displayName;
}
}

View file

@ -0,0 +1,48 @@
/*
* This file is part of NavalPlan
*
* Copyright (C) 2009-2010 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.web.common;
import static org.navalplanner.web.I18nHelper._;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
/**
* {@link Enum} types needs to be translated in the webapp module, because of it
* is not possible to known the user language in the business layer.
*
* This class provides a basic renderer that just call to the translation method
* and could be useful to translate {@link Enum} that are showed into
* {@link Listbox}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public class EnumsListitemRenderer implements ListitemRenderer {
@Override
public void render(Listitem item, Object data) throws Exception {
item.setValue(data);
item.appendChild(new Listcell(_(data.toString())));
}
}

View file

@ -942,7 +942,7 @@ public class OrderCRUDController extends GenericForwardComposer {
appendLabel(row, order.getCustomerReference());
appendObject(row, order.getTotalBudget());
appendObject(row, order.getTotalHours());
appendObject(row, order.getState());
appendObject(row, _(order.getState().toString()));
appendOperations(row, order);
row.setTooltiptext(getTooltipText(order));
@ -1222,4 +1222,5 @@ public class OrderCRUDController extends GenericForwardComposer {
}
}
}
}

View file

@ -283,11 +283,9 @@ public class ResourceAllocationController extends GenericForwardComposer {
private static String asString(ResourceEnum resourceType) {
switch (resourceType) {
case RESOURCE:
return _("Resource");
case MACHINE:
return _("Machine");
case WORKER:
return _("Worker");
return _(resourceType.getDisplayName());
default:
LOG.warn("no i18n for " + resourceType.name());
return resourceType.name();

View file

@ -99,7 +99,7 @@ public class WorkingArrangementsPerOrderController extends NavalplannerReportCon
// Task status
final TaskStatusEnum taskStatus = getSelectedTaskStatus();
result.put("taskStatus", taskStatus.toString());
result.put("taskStatus", _(taskStatus.toString()));
return result;
}

View file

@ -20,6 +20,8 @@
package org.navalplanner.web.reports;
import static org.navalplanner.web.I18nHelper._;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
@ -181,8 +183,12 @@ public class WorkingArrangementsPerOrderModel implements
// Add current task
final Set<Dependency> dependencies = task
.getDependenciesWithThisDestination();
result.add(new WorkingArrangementPerOrderDTO(deadLineOrder, task,
taskStatus, showDependencies && !dependencies.isEmpty()));
WorkingArrangementPerOrderDTO workingArrangementPerOrderDTO = new WorkingArrangementPerOrderDTO(
deadLineOrder, task, taskStatus, showDependencies
&& !dependencies.isEmpty());
workingArrangementPerOrderDTO.setStatus(_(workingArrangementPerOrderDTO
.getStatus()));
result.add(workingArrangementPerOrderDTO);
// Add dependencies
if (showDependencies) {
@ -194,8 +200,10 @@ public class WorkingArrangementsPerOrderModel implements
orderElement.getName(), orderElement.getCode(), each
.getType().toString(), orderElement
.getAdvancePercentage());
result.add(new WorkingArrangementPerOrderDTO(task, taskStatus,
dependencyDTO));
WorkingArrangementPerOrderDTO dto = new WorkingArrangementPerOrderDTO(
task, taskStatus, dependencyDTO);
dto.setStatus(_(dto.getStatus()));
result.add(dto);
}
}
return result;

View file

@ -309,7 +309,7 @@ public class CriterionAdminController_V2 extends GenericForwardComposer {
private void setupResourceCombobox(Combobox combo) {
for(ResourceEnum resource : ResourceEnum.values()) {
Comboitem item = combo.appendItem(resource.getDisplayName());
Comboitem item = combo.appendItem(_(resource.getDisplayName()));
item.setValue(resource);
}
}

View file

@ -109,7 +109,7 @@ public class SubcontractedTasksController extends GenericForwardComposer {
appendLabel(row, subcontractedTaskData.getWorkDescription());
appendLabel(row, toString(subcontractedTaskData
.getSubcontractPrice()));
appendLabel(row, toString(subcontractedTaskData.getState()));
appendLabel(row, _(toString(subcontractedTaskData.getState())));
appendOperations(row, subcontractedTaskData);
}

View file

@ -32,15 +32,17 @@ import org.navalplanner.business.users.entities.Profile;
import org.navalplanner.business.users.entities.ProfileOrderAuthorization;
import org.navalplanner.business.users.entities.User;
import org.navalplanner.business.users.entities.UserOrderAuthorization;
import org.navalplanner.business.users.entities.UserRole;
import org.navalplanner.web.common.IMessagesForUser;
import org.navalplanner.web.common.Level;
import org.navalplanner.web.common.Util;
import org.navalplanner.web.security.SecurityUtils;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Comboitem;
import org.zkoss.zul.api.Button;
import org.zkoss.zul.Label;
import org.zkoss.zul.Row;
import org.zkoss.zul.RowRenderer;
/**
* Controller for CRUD actions over an {@link OrderAuthorization}
@ -136,4 +138,25 @@ public class OrderAuthorizationController extends GenericForwardComposer{
messagesForUser = component;
}
public RowRenderer getOrderAuthorizationRenderer() {
return new RowRenderer() {
@Override
public void render(Row row, Object data) throws Exception {
final ProfileOrderAuthorization profileOrderAuthorization = (ProfileOrderAuthorization) data;
row.appendChild(new Label(profileOrderAuthorization.getProfile().getProfileName()));
row.appendChild(new Label(_(profileOrderAuthorization.getAuthorizationType().getDisplayName())));
row.appendChild(Util.createRemoveButton(new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
removeOrderAuthorization(profileOrderAuthorization);
}
}));
}
};
}
}

View file

@ -83,7 +83,7 @@ public class ProfileCRUDController extends GenericForwardComposer implements
*/
private void appendAllUserRoles(Combobox combo) {
for(UserRole role : getAllRoles()) {
Comboitem item = combo.appendItem(role.getDisplayName());
Comboitem item = combo.appendItem(_(role.getDisplayName()));
item.setValue(role);
}
}

View file

@ -92,7 +92,7 @@ public class UserCRUDController extends GenericForwardComposer implements
*/
private void appendAllUserRoles(Combobox combo) {
for(UserRole role : UserRole.values()) {
Comboitem item = combo.appendItem(role.getDisplayName());
Comboitem item = combo.appendItem(_(role.getDisplayName()));
item.setValue(role);
}
}

View file

@ -34,6 +34,7 @@ import org.navalplanner.business.workreports.entities.PositionInWorkReportEnum;
import org.navalplanner.business.workreports.entities.WorkReportLabelTypeAssigment;
import org.navalplanner.business.workreports.entities.WorkReportType;
import org.navalplanner.business.workreports.valueobjects.DescriptionField;
import org.navalplanner.web.common.EnumsListitemRenderer;
import org.navalplanner.web.common.IMessagesForUser;
import org.navalplanner.web.common.Level;
import org.navalplanner.web.common.MessagesForUser;
@ -325,9 +326,10 @@ public class WorkReportTypeCRUDController extends GenericForwardComposer
if (workReportTypeModel
.isHeadingDescriptionField((DescriptionField) row.getValue())) {
labelPosition.setValue(PositionInWorkReportEnum.HEADING.name());
labelPosition.setValue(_(PositionInWorkReportEnum.HEADING
.toString()));
} else {
labelPosition.setValue(PositionInWorkReportEnum.LINE.name());
labelPosition.setValue(_(PositionInWorkReportEnum.LINE.toString()));
}
}
@ -414,6 +416,7 @@ public class WorkReportTypeCRUDController extends GenericForwardComposer
listPosition.setModel(new SimpleListModel(
getPositionInWorkReportEnums()));
listPosition.setItemRenderer(new EnumsListitemRenderer());
return listPosition;
}
@ -497,8 +500,8 @@ public class WorkReportTypeCRUDController extends GenericForwardComposer
private void appendLabelPosition(Row row) {
org.zkoss.zul.Label labelPosition = new org.zkoss.zul.Label();
labelPosition.setParent(row);
labelPosition.setValue(workReportTypeModel.getLabelAssigmentPosition(
(WorkReportLabelTypeAssigment) row.getValue()).name());
labelPosition.setValue(_(workReportTypeModel.getLabelAssigmentPosition(
(WorkReportLabelTypeAssigment) row.getValue()).toString()));
}
private void appendLabel(Row row) {

View file

@ -51,7 +51,8 @@
<doublebox value="@{assignedMaterial.totalPrice}" disabled="${true}"/>
<label value="@{assignedMaterial.material.category.name}" width="150px" />
<listbox mold="select" model="@{materialStatus}"
selectedItem="@{assignedMaterial.status}"/>
selectedItem="@{assignedMaterial.status}"
itemRenderer="org.navalplanner.web.common.EnumsListitemRenderer" />
<hbox>
<button sclass="icono"
image="/common/img/ico_borrar1.png"

View file

@ -151,7 +151,8 @@
<label value="${i18n:_('State')}" />
<listbox id="listOrderStatus" mold="select" rows="1" width="220px"
model="@{controller.orderStatus}"
selectedItem="@{controller.order.state}"/>
selectedItem="@{controller.order.state}"
itemRenderer="org.navalplanner.web.common.EnumsListitemRenderer" />
</row>
</rows>
</grid>

View file

@ -35,25 +35,13 @@
profileWriteAuthCheckbox.checked);"/>
</hbox>
<grid id="profilesAuthListing"
model="@{orderAuthorizationController.profileOrderAuthorizations}">
model="@{orderAuthorizationController.profileOrderAuthorizations}"
rowRenderer="@{orderAuthorizationController.orderAuthorizationRenderer}" >
<columns sizable="true">
<column label="${i18n:_('Profile name')}" />
<column label="${i18n:_('Permissions')}" />
<column label="${i18n:_('Actions')}" />
</columns>
<rows>
<row self="@{each='authorization'}" value="@{authorization}">
<label value="@{authorization.profile.profileName}" />
<label value="@{authorization.authorizationType.displayName}" />
<hbox>
<button sclass="icono" image="/common/img/ico_borrar1.png"
hoverImage="/common/img/ico_borrar.png"
onClick="orderAuthorizationController.
removeOrderAuthorization(self.parent.parent.value);"
tooltiptext="${i18n:_('Delete')}" />
</hbox>
</row>
</rows>
</grid>
</panelchildren>
</panel>

View file

@ -68,7 +68,8 @@
<panelchildren>
<listbox id="lbTaskStatus"
model="@{controller.tasksStatus}"
mold="select" />
mold="select"
itemRenderer="org.navalplanner.web.common.EnumsListitemRenderer" />
</panelchildren>
</panel>

View file

@ -62,7 +62,8 @@
<listbox visible = "@{controller.editable}"
id="listDatePosition" mold="select" rows="1"
model="@{controller.positionInWorkReportEnums}"
selectedItem="@{controller.datePosition}"/>
selectedItem="@{controller.datePosition}"
itemRenderer="org.navalplanner.web.common.EnumsListitemRenderer" />
<label visible = "@{controller.readOnly}"
value="@{controller.datePosition}" width="300px"/>
</hbox>
@ -73,7 +74,8 @@
<listbox visible = "@{controller.editable}"
id="listResourcePosition" mold="select"
model="@{controller.positionInWorkReportEnums}"
selectedItem="@{controller.resourcePosition}"/>
selectedItem="@{controller.resourcePosition}"
itemRenderer="org.navalplanner.web.common.EnumsListitemRenderer" />
<label visible = "@{controller.readOnly}"
value="@{controller.resourcePosition}" width="300px"/>
</hbox>
@ -84,7 +86,8 @@
<listbox visible = "@{controller.editable}"
id="listOrderElementPosition" mold="select"
model="@{controller.positionInWorkReportEnums}"
selectedItem="@{controller.orderElementPosition}"/>
selectedItem="@{controller.orderElementPosition}"
itemRenderer="org.navalplanner.web.common.EnumsListitemRenderer" />
<label visible = "@{controller.readOnly}"
value="@{controller.orderElementPosition}" width="300px"/>
</hbox>
@ -95,7 +98,8 @@
<listbox visible = "@{controller.editable}"
id="listHoursManagement" mold="select"
model="@{controller.hoursManagementEnums}"
selectedItem="@{controller.workReportType.hoursManagement}"/>
selectedItem="@{controller.workReportType.hoursManagement}"
itemRenderer="org.navalplanner.web.common.EnumsListitemRenderer" />
<label visible = "@{controller.readOnly}"
value="@{controller.workReportType.hoursManagement}" width="300px"/>
</hbox>