diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Language.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Language.java
new file mode 100644
index 000000000..474c5668f
--- /dev/null
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/Language.java
@@ -0,0 +1,47 @@
+/*
+ * This file is part of NavalPlan
+ *
+ * Copyright (C) 2011 ComtecSF, S.L.
+ *
+ * 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 .
+ */
+
+package org.navalplanner.business.users.entities;
+
+import static org.navalplanner.business.i18n.I18nHelper._;
+
+/**
+ * Available languages.
+ *
+ * @author Cristina Alavarino Perez
+ * @author Ignacio Diaz Teijido
+ */
+public enum Language {
+
+ BROWSER_LANGUAGE(_("Use browser language configuration ")),
+ GALICIAN_LANGUAGE(_("Galician")),
+ SPANISH_LANGUAGE(_("Spanish")),
+ ENGLISH_LANGUAGE(_("English"));
+
+ private final String displayName;
+
+ private Language(String displayName) {
+ this.displayName = displayName;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+}
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/User.java b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/User.java
index 166eb7cec..38eef3300 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/User.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/users/entities/User.java
@@ -44,6 +44,8 @@ public class User extends BaseEntity {
private String password="";
+ private Language applicationLanguage = Language.BROWSER_LANGUAGE;
+
private Set roles = new HashSet();
private Set profiles = new HashSet();
@@ -197,4 +199,12 @@ public class User extends BaseEntity {
return lastConnectedScenario;
}
+ public Language getApplicationLanguage() {
+ return applicationLanguage;
+ }
+
+ public void setApplicationLanguage(Language applicationLanguage) {
+ this.applicationLanguage = applicationLanguage;
+ }
+
}
diff --git a/navalplanner-business/src/main/resources/db.changelog-1.1.xml b/navalplanner-business/src/main/resources/db.changelog-1.1.xml
index 2095cedfd..03fa9d480 100644
--- a/navalplanner-business/src/main/resources/db.changelog-1.1.xml
+++ b/navalplanner-business/src/main/resources/db.changelog-1.1.xml
@@ -18,4 +18,11 @@
columnDataType="BOOLEAN" />
+
+ Add new column to store the language of application for this user
+
+
+
+
+
diff --git a/navalplanner-business/src/main/resources/org/navalplanner/business/users/entities/Users.hbm.xml b/navalplanner-business/src/main/resources/org/navalplanner/business/users/entities/Users.hbm.xml
index 65a2788e0..89d940601 100644
--- a/navalplanner-business/src/main/resources/org/navalplanner/business/users/entities/Users.hbm.xml
+++ b/navalplanner-business/src/main/resources/org/navalplanner/business/users/entities/Users.hbm.xml
@@ -19,11 +19,15 @@
-
+
+
+
+ org.navalplanner.business.users.entities.Language
+
+
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java
index c68f94a0c..9638f22e7 100644
--- a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/CustomMenuController.java
@@ -338,6 +338,9 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
subItem(_("Project Costs Per Resource"),"/reports/orderCostsPerResource.zul", "15-informes.html"),
subItem(_("Task Scheduling Status In Project"),"/reports/workingArrangementsPerOrderReport.zul","15-informes.html"),
subItem(_("Materials Needs At Date"),"/reports/timeLineMaterialReport.zul","15-informes.html"));
+
+ topItem(_("My account"), "", "",
+ subItem(_("Settings"), "/users/settings.zul", ""));
}
private Vbox getRegisteredItemsInsertionPoint() {
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ISettingsModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ISettingsModel.java
new file mode 100644
index 000000000..8960ba7ad
--- /dev/null
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/ISettingsModel.java
@@ -0,0 +1,45 @@
+/*
+ * This file is part of NavalPlan
+ *
+ * Copyright (C) 2011 ComtecSF, S.L.
+ *
+ * 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 .
+ */
+package org.navalplanner.web.users;
+
+import org.navalplanner.business.common.exceptions.ValidationException;
+import org.navalplanner.business.users.entities.Language;
+import org.navalplanner.business.users.entities.User;
+
+/**
+ * Model for UI operations related to user settings
+ *
+ * @author Cristina Alvarino Perez
+ * @author Ignacio Diaz Teijido
+ */
+public interface ISettingsModel {
+
+ void setApplicationLanguage(Language applicationLanguage);
+
+ Language getApplicationLanguage();
+
+ User findByLoginUser(String login);
+
+ void initEdit(User user);
+
+ void confirmSave() throws ValidationException;
+
+ User getUser();
+
+}
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/SettingsController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/SettingsController.java
new file mode 100644
index 000000000..04aa4a66f
--- /dev/null
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/SettingsController.java
@@ -0,0 +1,112 @@
+/*
+ * This file is part of NavalPlan
+ *
+ * Copyright (C) 2011 ComtecSF, S.L.
+ *
+ * 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 .
+ */
+
+package org.navalplanner.web.users;
+
+import static org.navalplanner.web.I18nHelper._;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.navalplanner.business.common.exceptions.ValidationException;
+import org.navalplanner.business.users.entities.Language;
+import org.navalplanner.business.users.entities.User;
+import org.navalplanner.web.common.ConfigurationController;
+import org.navalplanner.web.common.IMessagesForUser;
+import org.navalplanner.web.common.Level;
+import org.navalplanner.web.common.MessagesForUser;
+import org.navalplanner.web.security.SecurityUtils;
+import org.zkoss.zk.ui.Component;
+import org.zkoss.zk.ui.util.GenericForwardComposer;
+import org.zkoss.zul.Combobox;
+import org.zkoss.zul.Comboitem;
+
+/**
+ * Controller for user settings
+ *
+ * @author Cristina Alvarino Perez
+ * @author Ignacio Diaz Teijido
+ */
+public class SettingsController extends GenericForwardComposer {
+
+ private static final Log LOG = LogFactory
+ .getLog(ConfigurationController.class);
+
+ private IMessagesForUser messages;
+
+ private Component messagesContainer;
+
+ private Combobox applicationLanguage;
+
+ private ISettingsModel settingsModel;
+
+ @Override
+ public void doAfterCompose(Component comp) throws Exception {
+ super.doAfterCompose(comp);
+ comp.setVariable("settingsController", this, true);
+ messages = new MessagesForUser(messagesContainer);
+
+ User user = settingsModel.findByLoginUser(SecurityUtils
+ .getSessionUserLoginName());
+
+ settingsModel.initEdit(user);
+
+ appendAllLanguages(applicationLanguage);
+
+ applicationLanguage.setSelectedIndex(settingsModel.getUser()
+ .getApplicationLanguage().ordinal());
+ }
+
+ private void appendAllLanguages(Combobox combo) {
+ for (Language language : getLanguageNames()) {
+ Comboitem item = combo.appendItem(_(language.getDisplayName()));
+ item.setValue(language);
+ }
+ }
+
+ public Language[] getLanguageNames() {
+ return Language.values();
+ }
+
+ public boolean save() {
+ try {
+ settingsModel.setApplicationLanguage(getSelectedLanguage());
+ settingsModel.confirmSave();
+ messages.showMessage(Level.INFO, _("Settings saved"));
+ applicationLanguage.setSelectedItem(applicationLanguage
+ .getSelectedItem());
+ return true;
+ } catch (ValidationException e) {
+ messages.showInvalidValues(e);
+ }
+ return false;
+ }
+
+ private Language getSelectedLanguage() {
+ Comboitem selectedItem = applicationLanguage.getSelectedItem();
+ if (selectedItem != null) {
+ return (Language) selectedItem.getValue();
+ }
+ return null;
+ }
+
+ private User getUser()
+ {
+ return settingsModel.getUser();
+ }
+}
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/SettingsModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/SettingsModel.java
new file mode 100644
index 000000000..5ca8269e4
--- /dev/null
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/SettingsModel.java
@@ -0,0 +1,115 @@
+/*
+ * This file is part of NavalPlan
+ *
+ * Copyright (C) 2011 ComtecSF, S.L.
+ *
+ * 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 .
+ */
+package org.navalplanner.web.users;
+
+import org.apache.commons.lang.Validate;
+import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
+import org.navalplanner.business.common.exceptions.ValidationException;
+import org.navalplanner.business.users.daos.IUserDAO;
+import org.navalplanner.business.users.entities.Language;
+import org.navalplanner.business.users.entities.Profile;
+import org.navalplanner.business.users.entities.User;
+import org.navalplanner.business.users.entities.UserRole;
+import org.navalplanner.web.common.concurrentdetection.OnConcurrentModification;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Model for UI operations related to user settings
+ *
+ * @author Cristina Alvarino Perez
+ * @author Ignacio Diaz Teijido
+ */
+@Service
+@Scope(BeanDefinition.SCOPE_PROTOTYPE)
+@OnConcurrentModification(goToPage = "/users/settings.zul")
+public class SettingsModel implements ISettingsModel {
+
+ @Autowired
+ private IUserDAO userDAO;
+
+ private User user;
+
+ @Override
+ public Language getApplicationLanguage() {
+ return user.getApplicationLanguage();
+ }
+
+ @Override
+ public void setApplicationLanguage(Language applicationLanguage) {
+ this.user.setApplicationLanguage(applicationLanguage);
+ }
+
+ @Override
+ @Transactional(readOnly = true)
+ public User findByLoginUser(String login) {
+ try {
+ return user = userDAO.findByLoginName(login);
+ } catch (InstanceNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ @Transactional(readOnly = true)
+ public void initEdit(User user) {
+ Validate.notNull(user);
+ this.user = getFromDB(user);
+ }
+
+ @Transactional(readOnly = true)
+ private User getFromDB(User user) {
+ return getFromDB(user.getId());
+ }
+
+ private User getFromDB(Long id) {
+ try {
+ User result = userDAO.find(id);
+ forceLoadEntities(result);
+ return result;
+ } catch (InstanceNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void forceLoadEntities(User user) {
+ user.getLoginName();
+ for (UserRole each : user.getRoles()) {
+ each.name();
+ }
+ for (Profile each : user.getProfiles()) {
+ each.getProfileName();
+ }
+ }
+
+ @Override
+ @Transactional
+ public void confirmSave() throws ValidationException {
+ userDAO.save(user);
+ }
+
+ @Override
+ public User getUser() {
+ return this.user;
+ }
+
+}
diff --git a/navalplanner-webapp/src/main/webapp/users/settings.zul b/navalplanner-webapp/src/main/webapp/users/settings.zul
new file mode 100644
index 000000000..7eda003b4
--- /dev/null
+++ b/navalplanner-webapp/src/main/webapp/users/settings.zul
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+