Search in sources :

Example 1 with ValidationAwareWindowClosingListener

use of com.haulmont.cuba.desktop.sys.validation.ValidationAwareWindowClosingListener in project cuba by cuba-platform.

the class DesktopWindowManager method showWindowDialog.

protected JDialog showWindowDialog(final Window window, String caption, String description, OpenType openType, boolean forciblyDialog) {
    final DialogWindow dialog = new DialogWindow(frame, caption);
    dialog.setName(window.getId());
    dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    JComponent jComponent = DesktopComponentsHelper.getComposition(window);
    dialog.add(jComponent);
    dialog.addWindowListener(new ValidationAwareWindowClosingListener() {

        @Override
        public void windowClosingAfterValidation(WindowEvent e) {
            if (BooleanUtils.isNotFalse(window.getDialogOptions().getCloseable())) {
                if (!isCloseWithCloseButtonPrevented(window)) {
                    if (window.close("close")) {
                        dialog.dispose();
                    }
                }
            }
        }
    });
    Dimension dim = new Dimension();
    if (forciblyDialog) {
        // todo move it to desktop application preferences
        dim.width = 800;
        dim.height = 500;
        dialog.setResizable(BooleanUtils.isNotFalse(openType.getResizable()));
        if (!dialog.isResizable()) {
            dialog.setFixedHeight(dim.height);
            dialog.setFixedWidth(dim.width);
        }
        window.setHeight("100%");
    } else {
        dialog.setResizable(BooleanUtils.isTrue(openType.getResizable()));
        if (openType.getWidth() == null) {
            dim.width = 600;
            if (!dialog.isResizable()) {
                dialog.setFixedWidth(dim.width);
            }
        } else if (openType.getWidth() == DialogParams.AUTO_SIZE_PX) {
            window.setWidth(AUTO_SIZE);
        } else {
            if (openType.getWidthUnit() != null && openType.getWidthUnit() != SizeUnit.PIXELS) {
                throw new UnsupportedOperationException("Dialog size can be set only in pixels");
            }
            dim.width = openType.getWidth().intValue();
            if (!dialog.isResizable()) {
                dialog.setFixedWidth(dim.width);
            }
        }
        if (openType.getHeight() != null && openType.getHeight() != DialogParams.AUTO_SIZE_PX) {
            if (openType.getHeightUnit() != null && openType.getHeightUnit() != SizeUnit.PIXELS) {
                throw new UnsupportedOperationException("Dialog size can be set only in pixels");
            }
            dim.height = openType.getHeight().intValue();
            if (!dialog.isResizable()) {
                dialog.setFixedHeight(dim.height);
            }
            window.setHeight("100%");
        } else {
            window.setHeight(AUTO_SIZE);
        }
    }
    getDialogParams().reset();
    dialog.setMinimumSize(dim);
    dialog.pack();
    if (openType.getPositionY() == null && openType.getPositionX() == null) {
        dialog.setLocationRelativeTo(frame);
    } else {
        dialog.setLocation(openType.getPositionX() != null ? openType.getPositionX() : 0, openType.getPositionY() != null ? openType.getPositionY() : 0);
    }
    boolean modal = true;
    if (!hasModalWindow() && openType.getModal() != null) {
        modal = openType.getModal();
    }
    if (modal) {
        DialogWindow lastDialogWindow = getLastDialogWindow();
        if (lastDialogWindow == null)
            frame.deactivate(null);
        else
            lastDialogWindow.disableWindow(null);
        dialog.setSoftModal(true);
    }
    dialog.setVisible(true);
    JPopupMenu popupMenu = createWindowPopupMenu(window);
    if (popupMenu.getComponentCount() > 0) {
        jComponent.setComponentPopupMenu(popupMenu);
    }
    return dialog;
}
Also used : ValidationAwareWindowClosingListener(com.haulmont.cuba.desktop.sys.validation.ValidationAwareWindowClosingListener)

Example 2 with ValidationAwareWindowClosingListener

use of com.haulmont.cuba.desktop.sys.validation.ValidationAwareWindowClosingListener in project cuba by cuba-platform.

the class App method initUI.

protected void initUI() {
    ToolTipManager.sharedInstance().setEnabled(false);
    mainFrame = createMainFrame();
    mainFrame.setName("MainFrame");
    mainFrame.addWindowListener(new ValidationAwareWindowClosingListener() {

        @Override
        public void windowClosingAfterValidation(WindowEvent e) {
            exit();
        }
    });
    mainFrame.setContentPane(createStartContentPane());
    registerFrame(mainFrame);
    createMainWindowProperties().load();
}
Also used : ValidationAwareWindowClosingListener(com.haulmont.cuba.desktop.sys.validation.ValidationAwareWindowClosingListener) WindowEvent(java.awt.event.WindowEvent)

Example 3 with ValidationAwareWindowClosingListener

use of com.haulmont.cuba.desktop.sys.validation.ValidationAwareWindowClosingListener in project cuba by cuba-platform.

the class DesktopWindowManager method attachTab.

public void attachTab(WindowBreadCrumbs breadCrumbs, Stack<Map.Entry<Window, Integer>> stack, Window window, Integer hashCode, final JComponent tabContent, Map<Window, WindowOpenInfo> openInfos) {
    frame.add(tabContent);
    frame.addWindowListener(new ValidationAwareWindowClosingListener() {

        @Override
        public void windowClosingAfterValidation(WindowEvent e) {
            closeTab(tabContent);
        }
    });
    tabs.put(tabContent, breadCrumbs);
    windowOpenMode.putAll(openInfos);
    stacks.put(breadCrumbs, stack);
    for (Map.Entry<Window, Integer> entry : stack) {
        entry.getKey().setWindowManager(this);
    }
    window.setWindowManager(this);
    if (hashCode != null) {
        windows.put(window, hashCode);
    }
    JPopupMenu popupMenu = createWindowPopupMenu(window);
    if (popupMenu.getComponentCount() > 0) {
        frame.getRootPane().setComponentPopupMenu(popupMenu);
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DesktopWindow(com.haulmont.cuba.desktop.gui.components.DesktopWindow) ValidationAwareWindowClosingListener(com.haulmont.cuba.desktop.sys.validation.ValidationAwareWindowClosingListener) ParamsMap(com.haulmont.bali.util.ParamsMap)

Aggregations

ValidationAwareWindowClosingListener (com.haulmont.cuba.desktop.sys.validation.ValidationAwareWindowClosingListener)3 ParamsMap (com.haulmont.bali.util.ParamsMap)1 DesktopWindow (com.haulmont.cuba.desktop.gui.components.DesktopWindow)1 Window (com.haulmont.cuba.gui.components.Window)1 WindowEvent (java.awt.event.WindowEvent)1