From 954f214f75a305633ee61d0a9afce62a15b54a6d Mon Sep 17 00:00:00 2001 From: Vladislav Chumak Date: Sun, 4 Dec 2016 16:45:33 +0100 Subject: [PATCH] bug3529 Fixed precendences of default settings building pipeline, improved labels in settings dialogs --- .../sap/sse/gwt/client/StringMessages.java | 6 -- .../shared/components/SettingsDialog.java | 6 +- .../settings/UserSettingsStorageManager.java | 70 ++++++++++++------- 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/StringMessages.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/StringMessages.java index ea9a51d941f..54f733fc0ff 100755 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/StringMessages.java +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/StringMessages.java @@ -23,10 +23,4 @@ public interface StringMessages extends Messages { String settings(); String settingsForComponent(String localizedShortName); String pleaseSelect(); - //TODO add to properties files - @DefaultMessage("Make default") - String makeDefault(); - //TODO add to properties files - @DefaultMessage("Restore default") - String restoreDefault(); } diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialog.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialog.java index 86e32774497..b63bb251286 100755 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialog.java +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialog.java @@ -95,15 +95,15 @@ public class SettingsDialog extends DataEntryDial } private void initMakeDefaultButtons(final Component component, StringMessages stringMessages) { - Button makeDefaultButton = new Button(stringMessages.makeDefault()); + Button makeDefaultButton = new Button(stringMessages.save()); makeDefaultButton.getElement().getStyle().setMargin(3, Unit.PX); - makeDefaultButton.ensureDebugId("MakeDefaultButton"); + makeDefaultButton.ensureDebugId("SaveButton"); getLeftButtonPannel().add(makeDefaultButton); makeDefaultButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { component.getComponentTreeNodeInfo().getComponentContext().makeSettingsDefault(component, getResult()); //TODO i18n + use nice styled dialog - Window.alert("Current settings have been set to default"); + Window.alert("Settings have been successfully saved"); } }); } diff --git a/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/settings/UserSettingsStorageManager.java b/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/settings/UserSettingsStorageManager.java index a9b7e9aec6f..cee4b9476ca 100644 --- a/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/settings/UserSettingsStorageManager.java +++ b/java/com.sap.sse.security.ui/src/main/java/com/sap/sse/security/ui/settings/UserSettingsStorageManager.java @@ -45,21 +45,17 @@ public class UserSettingsStorageManager implements Settings public void storeGlobalSettings(PerspectiveCompositeSettings globalSettings) { String serializedSettings = jsonSerializer.serializeToString(globalSettings); - if(userService.getCurrentUser() != null) { - storeGlobalSettingsOnServer(serializedSettings); - } - storeGlobalSettingsOnLocalStorage(serializedSettings); + storeGlobalSettingsJsonOnServer(serializedSettings); + storeGlobalSettingsJsonOnLocalStorage(serializedSettings); } public void storeContextSpecificSettings(PerspectiveCompositeSettings contextSpecificSettings) { String serializedSettings = jsonSerializer.serializeToString(contextSpecificSettings); - if(userService.getCurrentUser() != null) { - storeContextSpecificSettingsOnServer(serializedSettings); - } - storeContextSpecificSettingsOnLocalStorage(serializedSettings); + storeContextSpecificSettingsJsonOnServer(serializedSettings); + storeContextSpecificSettingsJsonOnLocalStorage(serializedSettings); } - private void storeContextSpecificSettingsOnLocalStorage(String serializedContextSpecificSettings) { + private void storeContextSpecificSettingsJsonOnLocalStorage(String serializedContextSpecificSettings) { Storage localStorage = Storage.getLocalStorageIfSupported(); if (localStorage != null) { localStorage.removeItem(storageContextSpecificKey); @@ -67,11 +63,13 @@ public class UserSettingsStorageManager implements Settings } } - private void storeContextSpecificSettingsOnServer(String serializedContextSpecificSettings) { - userService.setPreference(storageContextSpecificKey, serializedContextSpecificSettings); + private void storeContextSpecificSettingsJsonOnServer(String serializedContextSpecificSettings) { + if(userService.getCurrentUser() != null) { + userService.setPreference(storageContextSpecificKey, serializedContextSpecificSettings); + } } - private void storeGlobalSettingsOnLocalStorage(String serializedGlobalSettings) { + private void storeGlobalSettingsJsonOnLocalStorage(String serializedGlobalSettings) { Storage localStorage = Storage.getLocalStorageIfSupported(); if (localStorage != null) { localStorage.removeItem(storageGlobalKey); @@ -79,15 +77,13 @@ public class UserSettingsStorageManager implements Settings } } - private void storeGlobalSettingsOnServer(String serializedGlobalSettings) { - userService.setPreference(storageGlobalKey, serializedGlobalSettings); + private void storeGlobalSettingsJsonOnServer(String serializedGlobalSettings) { + if(userService.getCurrentUser() != null) { + userService.setPreference(storageGlobalKey, serializedGlobalSettings); + } } public void retrieveDefaultSettings(PerspectiveCompositeSettings defaultSettings, final DefaultSettingsLoadedCallback asyncCallback) { - defaultSettings = retrieveGlobalSettingsFromLocalStorage(defaultSettings); - defaultSettings = retrieveContextSpecificSettingsFromLocalStorage(defaultSettings); - - defaultSettings = retrieveDefaultSettingsFromUrl(defaultSettings); final SettingsJsonRetrievement settingsJsonRetrievement = new SettingsJsonRetrievement(defaultSettings); userService.addUserStatusEventHandler(new UserStatusEventHandler() { @@ -145,13 +141,35 @@ public class UserSettingsStorageManager implements Settings private void continueRetrieveDefaultSettings( UserSettingsStorageManager.SettingsJsonRetrievement settingsJsonRetrievement, DefaultSettingsLoadedCallback callback) { PerspectiveCompositeSettings defaultSettings = settingsJsonRetrievement.getDefaultSettings(); + + // has been any global settings from server retrieved? yes => apply as default and override LocalStorage if(settingsJsonRetrievement.getGlobalSettingsJson() != null) { defaultSettings = jsonSerializer.deserialize(defaultSettings, settingsJsonRetrievement.getGlobalSettingsJson()); + storeGlobalSettingsJsonOnLocalStorage(settingsJsonRetrievement.getGlobalSettingsJson()); + } else { + String localStorageGlobalSettingsJson = retrieveGlobalSettingsJsonFromLocalStorage(); + if(localStorageGlobalSettingsJson != null) { + //server has no global settings, local storage has => apply local storage settings and store them on server + defaultSettings = jsonSerializer.deserialize(defaultSettings, localStorageGlobalSettingsJson); + storeGlobalSettingsJsonOnServer(localStorageGlobalSettingsJson); + } } + + // has been any context specific settings from server retrieved? yes => apply as default and override LocalStorage if(settingsJsonRetrievement.getContextSpecificSettingsJson() != null) { defaultSettings = jsonSerializer.deserialize(defaultSettings, settingsJsonRetrievement.getContextSpecificSettingsJson()); + storeContextSpecificSettingsJsonOnLocalStorage(settingsJsonRetrievement.getContextSpecificSettingsJson()); + } else { + String localStorageContextSpecificSettingsJson = retrieveContextSpecificSettingsJsonFromLocalStorage(); + if(localStorageContextSpecificSettingsJson != null) { + //server has no context specific settings, local storage has => apply local storage settings and store them on server + defaultSettings = jsonSerializer.deserialize(defaultSettings, localStorageContextSpecificSettingsJson); + storeContextSpecificSettingsJsonOnServer(localStorageContextSpecificSettingsJson); + } } - defaultSettings = urlSerializer.deserializeFromCurrentLocation(defaultSettings); + + //URL settings have highest precedence + defaultSettings = retrieveDefaultSettingsFromUrl(defaultSettings); if(settingsJsonRetrievement.isErrorOccurred()) { callback.onError(settingsJsonRetrievement.getCaught(), defaultSettings); @@ -160,22 +178,20 @@ public class UserSettingsStorageManager implements Settings } } - private PerspectiveCompositeSettings retrieveGlobalSettingsFromLocalStorage(PerspectiveCompositeSettings defaultSettings) { + private String retrieveGlobalSettingsJsonFromLocalStorage() { Storage localStorage = Storage.getLocalStorageIfSupported(); if (localStorage != null) { - String serializedSettings = localStorage.getItem(storageGlobalKey); - defaultSettings = jsonSerializer.deserialize(defaultSettings, serializedSettings); + return localStorage.getItem(storageGlobalKey); } - return defaultSettings; + return null; } - private PerspectiveCompositeSettings retrieveContextSpecificSettingsFromLocalStorage(PerspectiveCompositeSettings defaultSettings) { + private String retrieveContextSpecificSettingsJsonFromLocalStorage() { Storage localStorage = Storage.getLocalStorageIfSupported(); if (localStorage != null) { - String serializedSettings = localStorage.getItem(storageContextSpecificKey); - defaultSettings = jsonSerializer.deserialize(defaultSettings, serializedSettings); + return localStorage.getItem(storageContextSpecificKey); } - return defaultSettings; + return null; } private void retrieveGlobalSettingsJsonFromServer(AsyncCallback asyncCallback) {