From bdb06146cada0031b63346720345cb759269aed6 Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Tue, 7 Apr 2015 09:30:44 +0000 Subject: [PATCH] Add ability to disable automatic screen settings save #PL-5191 --- .../haulmont/cuba/client/ClientConfig.java | 4 ++ .../security/app/UserSettingServiceBean.java | 61 +++++++++++-------- .../desktop/gui/components/DesktopWindow.java | 20 ++++-- .../settings/DesktopSettingsClient.java | 6 ++ .../desktop/sys/DesktopWindowManager.java | 19 ++++++ .../cuba/security/app/UserSettingService.java | 5 +- .../cuba/gui/components/AbstractWindow.java | 5 ++ .../haulmont/cuba/gui/components/Window.java | 3 + .../cuba/gui/components/WindowDelegate.java | 4 ++ .../com/haulmont/cuba/gui/messages.properties | 3 + .../haulmont/cuba/gui/messages_ru.properties | 2 + .../haulmont/cuba/gui/settings/Settings.java | 7 ++- .../cuba/gui/settings/SettingsClient.java | 2 + .../cuba/gui/settings/SettingsImpl.java | 6 ++ .../src/com/haulmont/cuba/web/AppWindow.java | 55 ++++++++++++++--- .../haulmont/cuba/web/WebWindowManager.java | 41 +++++++++---- .../com/haulmont/cuba/web/gui/WebWindow.java | 23 +++++-- .../cuba/web/settings/WebSettingsClient.java | 6 ++ .../com/haulmont/cuba/web/gui/WebWindow.java | 5 ++ .../cuba/web/settings/WebSettingsClient.java | 6 ++ 20 files changed, 227 insertions(+), 56 deletions(-) diff --git a/modules/client/src/com/haulmont/cuba/client/ClientConfig.java b/modules/client/src/com/haulmont/cuba/client/ClientConfig.java index 3de0a84a64..43cced8605 100644 --- a/modules/client/src/com/haulmont/cuba/client/ClientConfig.java +++ b/modules/client/src/com/haulmont/cuba/client/ClientConfig.java @@ -232,4 +232,8 @@ public interface ClientConfig extends Config { @DefaultBoolean(true) boolean getSystemInfoScriptsEnabled(); void setSystemInfoScriptsEnabled(boolean enabled); + + @Property("cuba.manualSaveScreenSettings") + @DefaultBoolean(false) + boolean getManualSaveScreenSettings(); } \ No newline at end of file diff --git a/modules/core/src/com/haulmont/cuba/security/app/UserSettingServiceBean.java b/modules/core/src/com/haulmont/cuba/security/app/UserSettingServiceBean.java index 0b04456b07..e688317fcd 100644 --- a/modules/core/src/com/haulmont/cuba/security/app/UserSettingServiceBean.java +++ b/modules/core/src/com/haulmont/cuba/security/app/UserSettingServiceBean.java @@ -14,6 +14,7 @@ import org.dom4j.Document; import org.dom4j.Element; import org.springframework.stereotype.Service; +import javax.annotation.Nullable; import javax.inject.Inject; import java.util.HashMap; import java.util.List; @@ -46,22 +47,11 @@ public class UserSettingServiceBean implements UserSettingService { String value; Transaction tx = persistence.createTransaction(); try { - EntityManager em = persistence.getEntityManager(); + UserSetting us = findUserSettings(clientType, name); - TypedQuery q = em.createQuery( - "select s from sec$UserSetting s where s.user.id = ?1 and s.name =?2 and s.clientType = ?3", - UserSetting.class); - q.setParameter(1, userSessionSource.getUserSession().getUser().getId()); - q.setParameter(2, name); - q.setParameter(3, clientType == null ? null : clientType.getId()); - q.setViewName("userSetting.value"); - - List list = q.getResultList(); - - value = list.isEmpty() ? null : list.get(0).getValue(); + value = us == null ? null : us.getValue(); tx.commit(); - } finally { tx.end(); } @@ -79,23 +69,16 @@ public class UserSettingServiceBean implements UserSettingService { try { EntityManager em = persistence.getEntityManager(); - TypedQuery q = em.createQuery( - "select s from sec$UserSetting s where s.user.id = ?1 and s.name =?2 and s.clientType = ?3", - UserSetting.class); - q.setParameter(1, userSessionSource.getUserSession().getUser().getId()); - q.setParameter(2, name); - q.setParameter(3, clientType == null ? null : clientType.getId()); - - List list = q.getResultList(); - if (list.isEmpty()) { - UserSetting us = new UserSetting(); + UserSetting us = findUserSettings(clientType, name); + if (us == null) { + us = new UserSetting(); us.setUser(em.getReference(User.class, userSessionSource.getUserSession().getUser().getId())); us.setName(name); us.setClientType(clientType); us.setValue(value); + em.persist(us); } else { - UserSetting us = list.get(0); us.setValue(value); } @@ -105,6 +88,22 @@ public class UserSettingServiceBean implements UserSettingService { } } + @Override + public void deleteSettings(ClientType clientType, String name) { + Transaction tx = persistence.createTransaction(); + try { + UserSetting us = findUserSettings(clientType, name); + EntityManager em = persistence.getEntityManager(); + if(us!=null){ + em.remove(us); + } + + tx.commit(); + } finally { + tx.end(); + } + } + @Override public void copySettings(User fromUser, User toUser) { MetaClass metaClass = metadata.getClassNN(UserSetting.class); @@ -175,6 +174,20 @@ public class UserSettingServiceBean implements UserSettingService { } } + @Nullable + protected UserSetting findUserSettings(ClientType clientType, String name) { + EntityManager em = persistence.getEntityManager(); + + TypedQuery q = em.createQuery( + "select s from sec$UserSetting s where s.user.id = ?1 and s.name =?2 and s.clientType = ?3", + UserSetting.class); + q.setParameter(1, userSessionSource.getUserSession().getUser().getId()); + q.setParameter(2, name); + q.setParameter(3, clientType == null ? null : clientType.getId()); + + return q.getFirstResult(); + } + protected Map copyPresentations(User fromUser, User toUser) { Map presentationMap = new HashMap<>(); Transaction tx = persistence.createTransaction(); diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopWindow.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopWindow.java index 3d8f6c8674..978e8da1e2 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopWindow.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopWindow.java @@ -154,6 +154,11 @@ public class DesktopWindow implements Window, Component.Disposable, delegate.saveSettings(); } + @Override + public void deleteSettings() { + delegate.deleteSettings(); + } + @Override public void setFocusComponent(String componentId) { this.focusComponentId = componentId; @@ -232,10 +237,12 @@ public class DesktopWindow implements Window, Component.Disposable, return false; } + ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); + if (!forceClose && isModified()) { final Committable committable = (getWrapper() instanceof Committable) ? (Committable) getWrapper() : (this instanceof Committable) ? (Committable) this : null; - if ((committable != null) && configuration.getConfig(ClientConfig.class).getUseSaveConfirmation()) { + if ((committable != null) && clientConfig.getUseSaveConfirmation()) { windowManager.showOptionDialog( messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("saveUnsaved"), @@ -303,10 +310,13 @@ public class DesktopWindow implements Window, Component.Disposable, return false; } - if (delegate.getWrapper() != null) - delegate.getWrapper().saveSettings(); - else - saveSettings(); + if (!clientConfig.getManualSaveScreenSettings()) { + if (delegate.getWrapper() != null) { + delegate.getWrapper().saveSettings(); + } else { + saveSettings(); + } + } delegate.disposeComponents(); diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/settings/DesktopSettingsClient.java b/modules/desktop/src/com/haulmont/cuba/desktop/settings/DesktopSettingsClient.java index a9eeade4e2..2815c8b3f7 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/settings/DesktopSettingsClient.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/settings/DesktopSettingsClient.java @@ -51,6 +51,12 @@ public class DesktopSettingsClient implements SettingsClient { userSettingService.saveSetting(ClientType.DESKTOP, name, value); } + @Override + public void deleteSettings(String name) { + getCache().put(name, Optional.absent()); + userSettingService.deleteSettings(ClientType.DESKTOP, name); + } + protected Map> getCache() { ApplicationSession session = App.getInstance().getApplicationSession(); if (session == null) { diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/sys/DesktopWindowManager.java b/modules/desktop/src/com/haulmont/cuba/desktop/sys/DesktopWindowManager.java index 7326319059..a535099116 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/sys/DesktopWindowManager.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/sys/DesktopWindowManager.java @@ -852,6 +852,25 @@ public class DesktopWindowManager extends WindowManager { Configuration configuration = AppBeans.get(Configuration.NAME); ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); + if (clientConfig.getManualSaveScreenSettings()) { + JMenuItem saveSettingsItem = new JMenuItem(messages.getMainMessage("actions.saveSettings")); + saveSettingsItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + window.saveSettings(); + } + }); + popupMenu.add(saveSettingsItem); + + JMenuItem restoreToDefaultsItem = new JMenuItem(messages.getMainMessage("actions.restoreToDefaults")); + restoreToDefaultsItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + window.deleteSettings(); + } + }); + popupMenu.add(restoreToDefaultsItem); + } if (clientConfig.getLayoutAnalyzerEnabled()) { JMenuItem analyzeLayoutItem = new JMenuItem(messages.getMainMessage("actions.analyzeLayout")); analyzeLayoutItem.addActionListener(new ActionListener() { diff --git a/modules/global/src/com/haulmont/cuba/security/app/UserSettingService.java b/modules/global/src/com/haulmont/cuba/security/app/UserSettingService.java index 341d10067d..b0dc6ef012 100644 --- a/modules/global/src/com/haulmont/cuba/security/app/UserSettingService.java +++ b/modules/global/src/com/haulmont/cuba/security/app/UserSettingService.java @@ -31,6 +31,9 @@ public interface UserSettingService { /** Save settings for the current user */ void saveSetting(ClientType clientType, String name, String value); + /** Delete settings for the current user */ + void deleteSettings(ClientType clientType, String name); + /** Copy user settings to another user */ void copySettings(User fromUser, User toUser); -} +} \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/AbstractWindow.java b/modules/gui/src/com/haulmont/cuba/gui/components/AbstractWindow.java index 2ad960620c..3f9f961163 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/AbstractWindow.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/AbstractWindow.java @@ -111,6 +111,11 @@ public class AbstractWindow extends AbstractFrame ((Window) frame).saveSettings(); } + @Override + public void deleteSettings() { + ((Window) frame).deleteSettings(); + } + @Override public void setFocusComponent(String componentId) { ((Window) frame).setFocusComponent(componentId); diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/Window.java b/modules/gui/src/com/haulmont/cuba/gui/components/Window.java index 5c2d45bc50..4734f75431 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/Window.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/Window.java @@ -74,6 +74,9 @@ public interface Window extends IFrame, Component.HasCaption { * to save user settings if they have been changed. */ void saveSettings(); + /** This method is called by the framework on reset to defaults action */ + void deleteSettings(); + /** * Set a component to be focused after the screen is opened. * @param componentId component's ID in XML. If null, then first focusable component will be focused diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/WindowDelegate.java b/modules/gui/src/com/haulmont/cuba/gui/components/WindowDelegate.java index ca162fad09..21512efee8 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/WindowDelegate.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/WindowDelegate.java @@ -132,6 +132,10 @@ public class WindowDelegate { } } + public void deleteSettings() { + settings.delete(); + } + public void applySettings(Settings settings) { this.settings = settings; ComponentsHelper.walkComponents( diff --git a/modules/gui/src/com/haulmont/cuba/gui/messages.properties b/modules/gui/src/com/haulmont/cuba/gui/messages.properties index d383bb4811..86f4401d3c 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/messages.properties +++ b/modules/gui/src/com/haulmont/cuba/gui/messages.properties @@ -287,6 +287,9 @@ unableToLoadControllerClass=Unable to load controller class searchSelect.notFound=Not found items for filter: %s searchSelect.minimumLengthOfFilter=Minimum length of search string is %s +actions.saveSettings=Save settings +actions.restoreToDefaults=Restore to defaults + actions.analyzeLayout=Analyze layout actions.exportSelectedTitle=Confirm export diff --git a/modules/gui/src/com/haulmont/cuba/gui/messages_ru.properties b/modules/gui/src/com/haulmont/cuba/gui/messages_ru.properties index da44b2a7bb..992c94a0a5 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/messages_ru.properties +++ b/modules/gui/src/com/haulmont/cuba/gui/messages_ru.properties @@ -285,6 +285,8 @@ unableToLoadControllerClass=Невозможно загрузить класс searchSelect.notFound=Не найдено записей для фильтра: %s searchSelect.minimumLengthOfFilter=Минимальная длина строки для поиска %s +actions.saveSettings=Сохранить настройки +actions.restoreToDefaults=Сбросить настройки actions.analyzeLayout=Проанализировать компоновку экрана timeZone.auto=Авто diff --git a/modules/gui/src/com/haulmont/cuba/gui/settings/Settings.java b/modules/gui/src/com/haulmont/cuba/gui/settings/Settings.java index 9402202098..00ba5acecf 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/settings/Settings.java +++ b/modules/gui/src/com/haulmont/cuba/gui/settings/Settings.java @@ -8,6 +8,9 @@ import org.dom4j.Element; /** * Interface to user settings of a window + * + * @author krivopustov + * @version $Id$ */ public interface Settings { @@ -18,4 +21,6 @@ public interface Settings { void setModified(boolean modified); void commit(); -} + + void delete(); +} \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/settings/SettingsClient.java b/modules/gui/src/com/haulmont/cuba/gui/settings/SettingsClient.java index 7e2a9421d9..856d41143a 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/settings/SettingsClient.java +++ b/modules/gui/src/com/haulmont/cuba/gui/settings/SettingsClient.java @@ -19,4 +19,6 @@ public interface SettingsClient { String getSetting(String name); void setSetting(String name, @Nullable String value); + + void deleteSettings(String name); } \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/settings/SettingsImpl.java b/modules/gui/src/com/haulmont/cuba/gui/settings/SettingsImpl.java index 5803e1bdf1..18ae9a4962 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/settings/SettingsImpl.java +++ b/modules/gui/src/com/haulmont/cuba/gui/settings/SettingsImpl.java @@ -86,4 +86,10 @@ public class SettingsImpl implements Settings { modified = false; } } + + @Override + public void delete() { + getSettingsClient().deleteSettings(name); + modified = false; + } } \ No newline at end of file diff --git a/modules/web/src/com/haulmont/cuba/web/AppWindow.java b/modules/web/src/com/haulmont/cuba/web/AppWindow.java index 41a267418e..6e13ea43c1 100644 --- a/modules/web/src/com/haulmont/cuba/web/AppWindow.java +++ b/modules/web/src/com/haulmont/cuba/web/AppWindow.java @@ -1074,15 +1074,16 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH protected Map closeHandlers = null; protected com.vaadin.event.Action closeAllTabs; - protected com.vaadin.event.Action closeOtherTabs; - protected com.vaadin.event.Action closeCurrentTab; protected com.vaadin.event.Action showInfo; protected com.vaadin.event.Action analyzeLayout; + protected com.vaadin.event.Action saveSettings; + protected com.vaadin.event.Action restoreToDefaults; + public AppTabSheet() { setCloseHandler(new CloseHandler() { @Override @@ -1096,16 +1097,19 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH } }); - addActionHandler(this); - Messages messages = AppBeans.get(Messages.NAME); + closeAllTabs = new com.vaadin.event.Action(messages.getMainMessage("actions.closeAllTabs")); closeOtherTabs = new com.vaadin.event.Action(messages.getMainMessage("actions.closeOtherTabs")); closeCurrentTab = new com.vaadin.event.Action(messages.getMainMessage("actions.closeCurrentTab")); showInfo = new com.vaadin.event.Action(messages.getMainMessage("actions.showInfo")); analyzeLayout = new com.vaadin.event.Action(messages.getMainMessage("actions.analyzeLayout")); + saveSettings = new com.vaadin.event.Action(messages.getMainMessage("actions.saveSettings")); + restoreToDefaults = new com.vaadin.event.Action(messages.getMainMessage("actions.restoreToDefaults")); addStyleName("cuba-main-tabsheet"); + + addActionHandler(this); } @Override @@ -1175,15 +1179,19 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH actions.add(closeAllTabs); if (target != null) { + Configuration configuration = AppBeans.get(Configuration.NAME); + ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); + if (clientConfig.getManualSaveScreenSettings()) { + actions.add(saveSettings); + actions.add(restoreToDefaults); + } + UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); UserSession userSession = sessionSource.getUserSession(); if (userSession.isSpecificPermitted(ShowInfoAction.ACTION_PERMISSION) && findEditor((Layout) target) != null) { actions.add(showInfo); } - - Configuration configuration = AppBeans.get(Configuration.NAME); - ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); if (clientConfig.getLayoutAnalyzerEnabled()) { actions.add(analyzeLayout); } @@ -1204,6 +1212,10 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH showInfo(target); } else if (analyzeLayout == action) { analyzeLayout(target); + } else if (saveSettings == action) { + saveSettings(target); + } else if (restoreToDefaults == action) { + restoreToDefaults(target); } } @@ -1246,6 +1258,35 @@ public class AppWindow extends UIView implements UserSubstitutionListener, CubaH } } + @Nullable + protected com.haulmont.cuba.gui.components.Window getWindow(Object target) { + if (target instanceof Layout) { + Layout layout = (Layout) target; + for (Component component : layout) { + if (component instanceof WindowBreadCrumbs) { + WindowBreadCrumbs breadCrumbs = (WindowBreadCrumbs) component; + return breadCrumbs.getCurrentWindow(); + } + } + } + + return null; + } + + public void restoreToDefaults(Object target) { + com.haulmont.cuba.gui.components.Window window = getWindow(target); + if (window != null) { + window.deleteSettings(); + } + } + + public void saveSettings(Object target) { + com.haulmont.cuba.gui.components.Window window = getWindow(target); + if (window != null) { + window.saveSettings(); + } + } + public interface TabCloseHandler { void onClose(TabSheet tabSheet, Component tabContent); } diff --git a/modules/web/src/com/haulmont/cuba/web/WebWindowManager.java b/modules/web/src/com/haulmont/cuba/web/WebWindowManager.java index a7ddc90c90..07fb9f9b58 100644 --- a/modules/web/src/com/haulmont/cuba/web/WebWindowManager.java +++ b/modules/web/src/com/haulmont/cuba/web/WebWindowManager.java @@ -12,6 +12,7 @@ import com.haulmont.cuba.core.global.Messages; import com.haulmont.cuba.core.global.SilentException; import com.haulmont.cuba.gui.*; import com.haulmont.cuba.gui.components.*; +import com.haulmont.cuba.gui.components.Action; import com.haulmont.cuba.gui.components.Window; import com.haulmont.cuba.gui.config.WindowInfo; import com.haulmont.cuba.gui.dev.LayoutAnalyzer; @@ -25,8 +26,7 @@ import com.haulmont.cuba.web.sys.WindowBreadCrumbs; import com.haulmont.cuba.web.toolkit.ui.CubaLabel; import com.haulmont.cuba.web.toolkit.ui.CubaTabSheet; import com.haulmont.cuba.web.toolkit.ui.CubaWindow; -import com.vaadin.event.ShortcutAction; -import com.vaadin.event.ShortcutListener; +import com.vaadin.event.*; import com.vaadin.server.Page; import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.label.ContentMode; @@ -774,10 +774,7 @@ public class WebWindowManager extends WindowManager { protected CubaWindow createDialogWindow(Window window) { CubaWindow dialogWindow = new CubaWindow(window.getCaption()); dialogWindow.setErrorHandler(ui); - // if layout analyzer allowed - if (clientConfig.getLayoutAnalyzerEnabled()) { - dialogWindow.addContextActionHandler(new LayoutAnalyzerOpener(window)); - } + dialogWindow.addContextActionHandler(new DialogWindowActionHandler(window)); return dialogWindow; } @@ -1276,23 +1273,43 @@ public class WebWindowManager extends WindowManager { } } - protected class LayoutAnalyzerOpener implements com.vaadin.event.Action.Handler { + protected class DialogWindowActionHandler implements com.vaadin.event.Action.Handler { protected Window window; - protected com.vaadin.event.Action analyzeAction = - new com.vaadin.event.Action(messages.getMainMessage("actions.analyzeLayout")); + protected com.vaadin.event.Action saveSettingsAction; + protected com.vaadin.event.Action restoreToDefaultsAction; - public LayoutAnalyzerOpener(Window window) { + protected com.vaadin.event.Action analyzeAction; + + public DialogWindowActionHandler(Window window) { this.window = window; + + saveSettingsAction = new com.vaadin.event.Action(messages.getMainMessage("actions.saveSettings")); + restoreToDefaultsAction = new com.vaadin.event.Action(messages.getMainMessage("actions.restoreToDefaults")); + analyzeAction = new com.vaadin.event.Action(messages.getMainMessage("actions.analyzeLayout")); } @Override public com.vaadin.event.Action[] getActions(Object target, Object sender) { - return new com.vaadin.event.Action[]{analyzeAction}; + List actions = new ArrayList<>(3); + + if (clientConfig.getManualSaveScreenSettings()) { + actions.add(saveSettingsAction); + actions.add(restoreToDefaultsAction); + } + if (clientConfig.getLayoutAnalyzerEnabled()) { + actions.add(analyzeAction); + } + + return actions.toArray(new com.vaadin.event.Action[actions.size()]); } @Override public void handleAction(com.vaadin.event.Action action, Object sender, Object target) { - if (analyzeAction == action) { + if (saveSettingsAction == action) { + window.saveSettings(); + } else if (restoreToDefaultsAction == action) { + window.deleteSettings(); + } else if (analyzeAction == action) { LayoutAnalyzer analyzer = new LayoutAnalyzer(); List tipsList = analyzer.analyze(window); diff --git a/modules/web/src/com/haulmont/cuba/web/gui/WebWindow.java b/modules/web/src/com/haulmont/cuba/web/gui/WebWindow.java index a7317db60f..22cc354339 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/WebWindow.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/WebWindow.java @@ -864,13 +864,16 @@ public class WebWindow implements Window, Component.Wrapper, return false; } - if (closing) + if (closing) { return true; + } + + ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); if (!forceClose && isModified()) { final Committable committable = (getWrapper() instanceof Committable) ? (Committable) getWrapper() : (this instanceof Committable) ? (Committable) this : null; - if ((committable != null) && configuration.getConfig(ClientConfig.class).getUseSaveConfirmation()) { + if ((committable != null) && clientConfig.getUseSaveConfirmation()) { windowManager.showOptionDialog( messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("saveUnsaved"), @@ -942,10 +945,13 @@ public class WebWindow implements Window, Component.Wrapper, return false; } - if (getWrapper() != null) - getWrapper().saveSettings(); - else - saveSettings(); + if (!clientConfig.getManualSaveScreenSettings()) { + if (getWrapper() != null) { + getWrapper().saveSettings(); + } else { + saveSettings(); + } + } delegate.disposeComponents(); @@ -976,6 +982,11 @@ public class WebWindow implements Window, Component.Wrapper, delegate.saveSettings(); } + @Override + public void deleteSettings() { + delegate.deleteSettings(); + } + @Override public String getCaption() { return caption; diff --git a/modules/web/src/com/haulmont/cuba/web/settings/WebSettingsClient.java b/modules/web/src/com/haulmont/cuba/web/settings/WebSettingsClient.java index 8de6a02acd..7ebce8dc02 100644 --- a/modules/web/src/com/haulmont/cuba/web/settings/WebSettingsClient.java +++ b/modules/web/src/com/haulmont/cuba/web/settings/WebSettingsClient.java @@ -49,6 +49,12 @@ public class WebSettingsClient implements SettingsClient { userSettingService.saveSetting(ClientType.WEB, name, value); } + @Override + public void deleteSettings(String name) { + getCache().put(name, Optional.absent()); + userSettingService.deleteSettings(ClientType.WEB, name); + } + public void clearCache() { VaadinSession session = VaadinSession.getCurrent(); session.setAttribute(SettingsClient.NAME, null); diff --git a/modules/web6/src/com/haulmont/cuba/web/gui/WebWindow.java b/modules/web6/src/com/haulmont/cuba/web/gui/WebWindow.java index db95ff35ad..dbf475efbb 100644 --- a/modules/web6/src/com/haulmont/cuba/web/gui/WebWindow.java +++ b/modules/web6/src/com/haulmont/cuba/web/gui/WebWindow.java @@ -942,6 +942,11 @@ public class WebWindow implements Window, Component.Wrapper, Component.HasXmlDes delegate.saveSettings(); } + @Override + public void deleteSettings() { + delegate.deleteSettings(); + } + @Override public String getCaption() { return caption; diff --git a/modules/web6/src/com/haulmont/cuba/web/settings/WebSettingsClient.java b/modules/web6/src/com/haulmont/cuba/web/settings/WebSettingsClient.java index 5e6c6b859c..697d3e1119 100644 --- a/modules/web6/src/com/haulmont/cuba/web/settings/WebSettingsClient.java +++ b/modules/web6/src/com/haulmont/cuba/web/settings/WebSettingsClient.java @@ -50,6 +50,12 @@ public class WebSettingsClient implements SettingsClient { userSettingService.saveSetting(ClientType.WEB, name, value); } + @Override + public void deleteSettings(String name) { + getCache().put(name, Optional.absent()); + userSettingService.deleteSettings(ClientType.WEB, name); + } + protected Map> getCache() { HttpSession session = RequestContext.get().getSession(); @SuppressWarnings("unchecked")