use of com.haulmont.cuba.web.gui.WebWindow in project cuba by cuba-platform.
the class WebWindowManager method setWindowCaption.
@Override
public void setWindowCaption(Window window, String caption, String description) {
Window webWindow = window;
if (window instanceof Window.Wrapper) {
webWindow = ((Window.Wrapper) window).getWrappedWindow();
}
window.setCaption(caption);
window.setDebugId(description);
WindowOpenInfo openInfo = windowOpenMode.get(webWindow);
String formattedCaption;
if (openInfo != null && (openInfo.getOpenMode() == OpenMode.NEW_TAB || openInfo.getOpenMode() == OpenMode.NEW_WINDOW || openInfo.getOpenMode() == OpenMode.THIS_TAB)) {
formattedCaption = formatTabCaption(caption, description);
} else {
formattedCaption = formatTabDescription(caption, description);
}
if (openInfo != null) {
if (openInfo.getOpenMode() == OpenMode.DIALOG) {
com.vaadin.ui.Window dialog = (com.vaadin.ui.Window) openInfo.getData();
dialog.setCaption(formattedCaption);
} else {
if (getConfiguredWorkArea(createWorkAreaContext(window)).getMode() == Mode.SINGLE) {
return;
}
Component tabContent = (Component) openInfo.getData();
if (tabContent == null) {
return;
}
TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(window)).getTabbedWindowContainer().getTabSheetBehaviour();
String tabId = tabSheet.getTab(tabContent);
if (tabId == null) {
return;
}
tabSheet.setTabCaption(tabId, formattedCaption);
String formattedDescription = formatTabDescription(caption, description);
if (!Objects.equals(formattedDescription, formattedCaption)) {
tabSheet.setTabDescription(tabId, formattedDescription);
} else {
tabSheet.setTabDescription(tabId, null);
}
}
}
}
use of com.haulmont.cuba.web.gui.WebWindow in project cuba by cuba-platform.
the class WebWindowManager method closeAllTabbedWindowsExcept.
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()) {
if (!canWindowBeClosed(window)) {
continue;
}
OpenMode openMode = windowOpenMode.get(window).getOpenMode();
WindowBreadCrumbs windowBreadCrumbs = tabs.get(windowOpenMode.get(window).getData());
Window currentWindow = (windowBreadCrumbs != null && window != windowBreadCrumbs.getCurrentWindow()) ? windowBreadCrumbs.getCurrentWindow() : window;
if (window.getFrame() == keepOpenedFrame || openMode == OpenMode.DIALOG || keepOpenedCrumbs == windowBreadCrumbs || isCloseWithCloseButtonPrevented(currentWindow))
continue;
if (window.getDsContext() != null && window.getDsContext().isModified()) {
modified = true;
}
windowsToClose.add((WebWindow) window);
}
disableSavingScreenHistory = true;
if (modified) {
showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("discardChangesInTabs"), MessageType.WARNING, new Action[] { new AbstractAction(messages.getMainMessage("closeTabs")) {
{
icon = icons.get(CubaIcon.DIALOG_OK);
}
@Override
public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
closeTabsForce(windowsToClose);
}
}, new DialogAction(Type.CANCEL, Status.PRIMARY) });
} else {
closeTabsForce(windowsToClose);
}
}
use of com.haulmont.cuba.web.gui.WebWindow in project cuba by cuba-platform.
the class WebWindowManager method closeWindow.
protected void closeWindow(Window window, WindowOpenInfo openInfo) {
if (!disableSavingScreenHistory) {
screenHistorySupport.saveScreenHistory(window, openInfo.getOpenMode());
}
WebWindow webWindow = (WebWindow) window;
webWindow.stopTimers();
switch(openInfo.getOpenMode()) {
case DIALOG:
{
final CubaWindow cubaDialogWindow = (CubaWindow) openInfo.getData();
cubaDialogWindow.forceClose();
fireListeners(window, tabs.size() != 0);
break;
}
case NEW_WINDOW:
case NEW_TAB:
{
final Layout layout = (Layout) openInfo.getData();
layout.removeComponent(WebComponentsHelper.getComposition(window));
WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
if (workArea.getMode() == Mode.TABBED) {
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
tabSheet.silentCloseTabAndSelectPrevious(layout);
tabSheet.removeComponent(layout);
} else {
VerticalLayout singleLayout = workArea.getSingleWindowContainer();
singleLayout.removeComponent(layout);
}
WindowBreadCrumbs windowBreadCrumbs = tabs.get(layout);
if (windowBreadCrumbs != null) {
windowBreadCrumbs.clearListeners();
windowBreadCrumbs.removeWindow();
}
tabs.remove(layout);
stacks.remove(windowBreadCrumbs);
fireListeners(window, !tabs.isEmpty());
if (tabs.isEmpty() && app.getConnection().isConnected()) {
workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
}
break;
}
case THIS_TAB:
{
final Layout layout = (Layout) openInfo.getData();
final WindowBreadCrumbs breadCrumbs = tabs.get(layout);
if (breadCrumbs == null) {
throw new IllegalStateException("Unable to close screen: breadCrumbs not found");
}
breadCrumbs.removeWindow();
Window currentWindow = breadCrumbs.getCurrentWindow();
if (!getStack(breadCrumbs).empty()) {
Pair<Window, Integer> entry = getStack(breadCrumbs).pop();
putToWindowMap(entry.getFirst(), entry.getSecond());
}
Component component = WebComponentsHelper.getComposition(currentWindow);
component.setSizeFull();
WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
layout.removeComponent(WebComponentsHelper.getComposition(window));
if (app.getConnection().isConnected()) {
layout.addComponent(component);
if (workArea.getMode() == Mode.TABBED) {
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
String tabId = tabSheet.getTab(layout);
String formattedCaption = formatTabCaption(currentWindow.getCaption(), currentWindow.getDescription());
tabSheet.setTabCaption(tabId, formattedCaption);
String formattedDescription = formatTabDescription(currentWindow.getCaption(), currentWindow.getDescription());
if (!Objects.equals(formattedCaption, formattedDescription)) {
tabSheet.setTabDescription(tabId, formattedDescription);
} else {
tabSheet.setTabDescription(tabId, null);
}
tabSheet.setTabIcon(tabId, iconResolver.getIconResource(currentWindow.getIcon()));
ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(currentWindow.getContentSwitchMode().name());
tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
}
}
fireListeners(window, !tabs.isEmpty());
if (tabs.isEmpty() && app.getConnection().isConnected()) {
workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
}
break;
}
default:
{
throw new UnsupportedOperationException();
}
}
}
Aggregations