mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-01 10:47:37 +08:00
PL-6923 TabSheet closing dirty tabs issue
This commit is contained in:
parent
05182d219a
commit
2551750f0b
@ -211,7 +211,9 @@ saveUnsaved=Do you want to save changes before close?
|
||||
closeUnsaved.save=Save
|
||||
closeUnsaved.discard=Don't save
|
||||
discardChangesOnClose=Do you want to discard unsaved changes?
|
||||
discardChangesInTabs=Do you want to discard unsaved changes?
|
||||
closeApplication=Discard changes
|
||||
closeTabs=Close
|
||||
|
||||
multiupload.submit=Upload
|
||||
multiupload.uploadError=Uploading error for file '%s'
|
||||
|
@ -184,7 +184,9 @@ saveUnsaved=Сохранить изменения перед закрытием
|
||||
closeUnsaved.save=Сохранить
|
||||
closeUnsaved.discard=Не сохранять
|
||||
discardChangesOnClose=Вы действительно хотите выйти из приложения?
|
||||
discardChangesInTabs=Вы действительно хотите закрыть вкладки?
|
||||
closeApplication=Выйти
|
||||
closeTabs=Закрыть
|
||||
|
||||
accessDenied.message=Доступ запрещен
|
||||
noSuchScreen.message=Экран не определен
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.haulmont.bali.util.ParamsMap;
|
||||
import com.haulmont.cuba.client.ClientConfig;
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
@ -175,7 +176,7 @@ public class WebWindowManager extends WindowManager {
|
||||
String formattedCaption;
|
||||
|
||||
if (openInfo != null
|
||||
&& (openInfo.getOpenMode() == OpenMode.NEW_TAB
|
||||
&& (openInfo.getOpenMode() == OpenMode.NEW_TAB
|
||||
|| openInfo.getOpenMode() == OpenMode.THIS_TAB)) {
|
||||
formattedCaption = formatTabCaption(caption, description);
|
||||
} else {
|
||||
@ -773,7 +774,8 @@ public class WebWindowManager extends WindowManager {
|
||||
|
||||
/**
|
||||
* Check modifications and close all screens in all main windows.
|
||||
* @param runIfOk a closure to run after all screens are closed
|
||||
*
|
||||
* @param runIfOk a closure to run after all screens are closed
|
||||
*/
|
||||
public void checkModificationsAndCloseAll(Runnable runIfOk) {
|
||||
checkModificationsAndCloseAll(runIfOk, null);
|
||||
@ -781,8 +783,9 @@ public class WebWindowManager extends WindowManager {
|
||||
|
||||
/**
|
||||
* Check modifications and close all screens in all main windows.
|
||||
* @param runIfOk a closure to run after all screens are closed
|
||||
* @param runIfCancel a closure to run if there were modifications and a user canceled the operation
|
||||
*
|
||||
* @param runIfOk a closure to run after all screens are closed
|
||||
* @param runIfCancel a closure to run if there were modifications and a user canceled the operation
|
||||
*/
|
||||
public void checkModificationsAndCloseAll(final Runnable runIfOk, final @Nullable Runnable runIfCancel) {
|
||||
boolean modified = false;
|
||||
@ -837,6 +840,64 @@ public class WebWindowManager extends WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void closeAllTabbedWindows() {
|
||||
closeAllTabbedWindowsExcept(null);
|
||||
}
|
||||
|
||||
public void closeAllTabbedWindowsExcept(@Nullable ComponentContainer keepOpened) {
|
||||
boolean modified = false;
|
||||
List<WebWindow> windowsToClose = new ArrayList<>();
|
||||
WindowBreadCrumbs keepOpenedCrumbs = tabs.get(keepOpened);
|
||||
Frame keepOpenedFrame = keepOpenedCrumbs != null ? keepOpenedCrumbs.getCurrentWindow().getFrame() : null;
|
||||
|
||||
for (Window window : getOpenWindows()) {
|
||||
OpenMode openMode = windowOpenMode.get(window).getOpenMode();
|
||||
WindowBreadCrumbs windowBreadCrumbs = tabs.get(windowOpenMode.get(window).getData());
|
||||
if (window.getFrame() == keepOpenedFrame || openMode == OpenMode.DIALOG || keepOpenedCrumbs == windowBreadCrumbs)
|
||||
continue;
|
||||
|
||||
if (window.getDsContext() != null && window.getDsContext().isModified()) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
windowsToClose.add((WebWindow) window);
|
||||
}
|
||||
|
||||
disableSavingScreenHistory = true;
|
||||
|
||||
if (modified) {
|
||||
showOptionDialog(
|
||||
messages.getMessage(WebWindow.class, "closeUnsaved.caption"),
|
||||
messages.getMessage(WebWindow.class, "discardChangesInTabs"),
|
||||
MessageType.WARNING,
|
||||
new Action[]{
|
||||
new AbstractAction(messages.getMessage(WebWindow.class, "closeTabs")) {
|
||||
|
||||
{
|
||||
ThemeConstantsManager thCM = AppBeans.get(ThemeConstantsManager.NAME);
|
||||
icon = thCM.getThemeValue("actions.dialog.Ok.icon");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
|
||||
closeTabsForce(windowsToClose);
|
||||
}
|
||||
},
|
||||
new DialogAction(Type.CANCEL, Status.PRIMARY)
|
||||
}
|
||||
);
|
||||
} else {
|
||||
closeTabsForce(windowsToClose);
|
||||
}
|
||||
}
|
||||
|
||||
protected void closeTabsForce(List<WebWindow> windowsToClose) {
|
||||
windowsToClose = Lists.reverse(windowsToClose);
|
||||
for (WebWindow window : windowsToClose) {
|
||||
window.close(Window.CLOSE_ACTION_ID, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all screens in all main windows (browser tabs).
|
||||
*/
|
||||
@ -1183,7 +1244,7 @@ public class WebWindowManager extends WindowManager {
|
||||
button.addStyleName(WebButton.ICON_STYLE);
|
||||
}
|
||||
|
||||
if (action instanceof AbstractAction && ((AbstractAction)action).isPrimary()) {
|
||||
if (action instanceof AbstractAction && ((AbstractAction) action).isPrimary()) {
|
||||
button.addStyleName("cuba-primary-action");
|
||||
button.focus();
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web.toolkit.ui;
|
||||
|
||||
import com.haulmont.cuba.web.App;
|
||||
import com.haulmont.cuba.web.WebWindowManager;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.tabsheet.ClientAction;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.tabsheet.CubaTabSheetClientRpc;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.tabsheet.CubaTabSheetServerRpc;
|
||||
@ -23,6 +25,7 @@ import com.haulmont.cuba.web.toolkit.ui.client.tabsheet.CubaTabSheetState;
|
||||
import com.vaadin.event.Action;
|
||||
import com.vaadin.server.KeyMapper;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.ComponentContainer;
|
||||
import fi.jasoft.dragdroplayouts.DDTabSheet;
|
||||
|
||||
import java.util.*;
|
||||
@ -234,17 +237,12 @@ public class CubaTabSheet extends DDTabSheet implements Action.Container {
|
||||
}
|
||||
|
||||
public void closeOtherTabs(Component currentTab) {
|
||||
Set<Component> tabs = new HashSet<>(this.tabs.keySet());
|
||||
for (final Component tab : tabs) {
|
||||
if (tab.equals(currentTab)) continue;
|
||||
closeTab(tab);
|
||||
}
|
||||
WebWindowManager windowManager = App.getInstance().getWindowManager();
|
||||
windowManager.closeAllTabbedWindowsExcept((ComponentContainer) currentTab);
|
||||
}
|
||||
|
||||
public void closeAllTabs() {
|
||||
Set<Component> tabs = new HashSet<>(this.tabs.keySet());
|
||||
for (final Component tab : tabs) {
|
||||
closeTab(tab);
|
||||
}
|
||||
WebWindowManager windowManager = App.getInstance().getWindowManager();
|
||||
windowManager.closeAllTabbedWindows();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user