Remember size of resizeable dialog window

Hello,

I have a screen that is openend as a non-modal, resizeable dialog window (a PDF preview dialog window and I want to save the width and height of the window and set it the next time the user opens the dialog.

AFAIK there is no resize event I can add a listener to, so I’m thinking of writting custom JavaScript that will invoke method in the controller?

Hello,

you can subscribe to AfterCloseEvent and save the width and height of DialogWindow in settings. In onBeforeShow load and set sizes to the DialogWindow.

For instance:

@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
    if (getWindow() instanceof DialogWindow) {
        DialogWindow windowDialog = (DialogWindow) getWindow();
        Element element = getSettings().get("dialogSizes");

        String width = element.attributeValue("width");
        if (!Strings.isNullOrEmpty(width)) {
            windowDialog.setDialogWidth(width);
        }
        String height = element.attributeValue("height");
        if (!Strings.isNullOrEmpty(height)) {
            windowDialog.setDialogHeight(height);
        }
    }
}

@Subscribe
public void onAfterClose(AfterCloseEvent event) {
    if (getWindow() instanceof DialogWindow) {
        DialogWindow windowDialog = (DialogWindow) getWindow();
        Element element = getSettings().get("dialogSizes");
        element.addAttribute("width", windowDialog.getDialogWidth() + "px");
        element.addAttribute("height", windowDialog.getDialogHeight() + "px");
        getSettings().commit();
    }
}
1 Like

@Pinyazhin Thanks, that works. I also wasn’t aware that the concrete class for a dialog is DialogWindow. Nice. :slight_smile: