Search in sources :

Example 1 with FormDialog

use of com.servoy.j2db.gui.FormDialog in project servoy-client by Servoy.

the class SwingRuntimeWindowManager method getOrderedContainers.

@Override
protected List<String> getOrderedContainers() {
    // here we have to close in reverse order of the opening
    FormManager fm = ((FormManager) application.getFormManager());
    List<String> orderedDialogs = new ArrayList<String>();
    Map<FormDialog, String> dialogs = new HashMap<FormDialog, String>();
    List<String> all = fm.getCreatedMainContainerKeys();
    for (String key : all) {
        if (key != null) {
            IMainContainer mContainer = fm.getMainContainer(key);
            if (fm.getMainContainer(null) != mContainer) {
                Container parent = ((Component) mContainer).getParent();
                while (parent != null && !(parent instanceof FormDialog)) {
                    parent = parent.getParent();
                }
                if (parent instanceof FormDialog) {
                    dialogs.put((FormDialog) parent, key);
                    continue;
                }
            }
        }
    }
    for (FormDialog dialog : dialogs.keySet()) {
        addDialogsInOrder(dialog, dialogs, orderedDialogs);
    }
    if (orderedDialogs.size() < all.size()) {
        for (String key : all) {
            if (!orderedDialogs.contains(key)) {
                orderedDialogs.add(key);
            }
        }
    }
    return orderedDialogs;
}
Also used : FormDialog(com.servoy.j2db.gui.FormDialog) IMainContainer(com.servoy.j2db.IMainContainer) IBasicMainContainer(com.servoy.j2db.IBasicMainContainer) Container(java.awt.Container) FormManager(com.servoy.j2db.FormManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMainContainer(com.servoy.j2db.IMainContainer) Component(java.awt.Component)

Example 2 with FormDialog

use of com.servoy.j2db.gui.FormDialog in project servoy-client by Servoy.

the class SwingRuntimeWindow method doOldShowInDialog.

private void doOldShowInDialog(String formName, boolean closeAll, boolean legacyV3Behavior) {
    FormManager fm = ((FormManager) getApplication().getFormManager());
    IMainContainer currentModalDialogContainer = fm.getModalDialogContainer();
    JSWindow parentJSWindow = getParent();
    RuntimeWindow parentRuntimeWindow = null;
    if (parentJSWindow != null && parentJSWindow.getImpl().isVisible())
        parentRuntimeWindow = parentJSWindow.getImpl();
    else {
        Window dialogWindowOwner = getWindowFromMainContainer(currentModalDialogContainer);
        if (dialogWindowOwner != null) {
            IMainContainer currentContainer = fm.getCurrentContainer();
            Window currentContainerWindow = getWindowFromMainContainer(currentContainer);
            while (currentContainerWindow != null) {
                if (dialogWindowOwner == currentContainerWindow) {
                    break;
                }
                currentContainerWindow = currentContainerWindow.getOwner();
            }
            if (currentContainerWindow == null) {
                // if it never really was the owner (in the own chain of the dialog) then do just use the currentContainer.
                currentModalDialogContainer = currentContainer;
            }
        }
        parentRuntimeWindow = getApplication().getRuntimeWindowManager().getWindow(currentModalDialogContainer.getContainerName());
    }
    boolean windowModal = ((legacyV3Behavior && wrappedWindow == null) || getType() == JSWindow.MODAL_DIALOG);
    Pair<Boolean, IMainContainer> p = createAndReparentDialogIfNeeded(fm, parentRuntimeWindow, windowModal);
    boolean bringToFrontNeeded = p.getLeft().booleanValue();
    IMainContainer previousModalContainer = p.getRight();
    FormDialog sfd = (FormDialog) wrappedWindow;
    IMainContainer container = sfd.getMainContainer();
    // For none legacy the dialog must always be really closed
    sfd.setCloseAll(closeAll || !legacyV3Behavior);
    if (sfd.isVisible()) {
        sfd.storeBounds();
    }
    final FormController fp = fm.showFormInMainPanel(formName, container, title, closeAll && legacyV3Behavior, windowName);
    if (fp != null && fp.getName().equals(formName)) {
        sfd.setModal(windowModal);
        if (!sfd.isDisplayable() && isUndecorated()) {
            sfd.setUndecorated(true);
            sfd.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
            // $NON-NLS-1$
            if (Utils.isAppleMacOS())
                sfd.getRootPane().putClientProperty("Window.shadow", Boolean.FALSE);
        }
        applyOpacityAndTransparency(sfd, container, sfd.getContentPane(), sfd.isUndecorated());
        if (windowModal) {
            testAndSetJava6Modality(sfd);
            // When a modal window is closed, the old modal window state will have to be restored...
            // For example, when inside JS for an event you close a modal window and open another one,
            // the new modal window must have as owner not the closed window, but the last opened modal window
            // before the window just closed.
            // This has to happen when setVisible(false) is called on the modal dialog. We cannot simply rely
            // on executing this after sfd.setVisible(true) is unblocked, because then it will be executed
            // after the new dialog is opened by java script. (because that execution continues as the next event on the EventThread)
            sfd.setPreviousMainContainer(previousModalContainer, currentModalDialogContainer);
        } else {
            // If it is a none modal dialog, make sure the current container is reset to the currentMainContainer (== previous his parent)
            // else it is switched a bit to early (if a developer shows 2 dialogs at once from a main container)
            // the focus event of the FormDialog will set it correctly.
            fm.setCurrentContainer(currentModalDialogContainer, currentModalDialogContainer.getName());
        }
    }
    finalizeShowWindow(fp, formName, container, true, legacyV3Behavior, bringToFrontNeeded);
}
Also used : ISmartRuntimeWindow(com.servoy.j2db.plugins.ISmartRuntimeWindow) RuntimeWindow(com.servoy.j2db.scripting.RuntimeWindow) Window(java.awt.Window) JSWindow(com.servoy.j2db.scripting.JSWindow) FormWindow(com.servoy.j2db.FormWindow) FormController(com.servoy.j2db.FormController) FormDialog(com.servoy.j2db.gui.FormDialog) ISmartRuntimeWindow(com.servoy.j2db.plugins.ISmartRuntimeWindow) RuntimeWindow(com.servoy.j2db.scripting.RuntimeWindow) FormManager(com.servoy.j2db.FormManager) JSWindow(com.servoy.j2db.scripting.JSWindow) IMainContainer(com.servoy.j2db.IMainContainer)

Example 3 with FormDialog

use of com.servoy.j2db.gui.FormDialog in project servoy-client by Servoy.

the class SwingRuntimeWindow method createAndReparentDialogIfNeeded.

private Pair<Boolean, IMainContainer> createAndReparentDialogIfNeeded(FormManager fm, RuntimeWindow parentJSWindow, boolean windowModal) {
    IMainContainer container = fm.getOrCreateMainContainer(windowName);
    IMainContainer previousModalContainer = null;
    FormDialog sfd = (FormDialog) wrappedWindow;
    boolean reparented = false;
    Object[] savedStatusForRecreate = null;
    // make sure the dialog has the correct owner
    if (sfd != null) {
        Window formDialogOwner = sfd.getOwner();
        Window owner = null;
        if (parentJSWindow == null || parentJSWindow.getWrappedObject() == null) {
            owner = getApplication().getMainApplicationFrame();
        } else {
            owner = (Window) parentJSWindow.getWrappedObject();
        }
        if ((owner != sfd) && !owner.equals(formDialogOwner)) {
            // wrong owner... will create a new window and close/dispose old one
            savedStatusForRecreate = saveWrappedWindowStatusForRecreate();
            hide(true);
            sfd.dispose();
            sfd = null;
            wrappedWindow = null;
            reparented = true;
        }
    }
    if (windowModal) {
        previousModalContainer = fm.setModalDialogContainer(container);
    }
    boolean bringToFrontNeeded = false;
    if (sfd == null) {
        wrappedWindow = sfd = createFormDialog(parentJSWindow != null ? (Window) parentJSWindow.getWrappedObject() : null, windowModal, windowName);
        createdNewWindow = true;
        sfd.setResizable(resizable);
        sfd.setMainContainer(container);
        if (reparented) {
            restoreWrappedWindowStatusAfterRecreate(savedStatusForRecreate);
        }
    } else if (sfd.isVisible()) {
        bringToFrontNeeded = true;
    }
    return new Pair<Boolean, IMainContainer>(Boolean.valueOf(bringToFrontNeeded), previousModalContainer);
}
Also used : ISmartRuntimeWindow(com.servoy.j2db.plugins.ISmartRuntimeWindow) RuntimeWindow(com.servoy.j2db.scripting.RuntimeWindow) Window(java.awt.Window) JSWindow(com.servoy.j2db.scripting.JSWindow) FormWindow(com.servoy.j2db.FormWindow) FormDialog(com.servoy.j2db.gui.FormDialog) IMainContainer(com.servoy.j2db.IMainContainer) Pair(com.servoy.j2db.util.Pair)

Aggregations

IMainContainer (com.servoy.j2db.IMainContainer)3 FormDialog (com.servoy.j2db.gui.FormDialog)3 FormManager (com.servoy.j2db.FormManager)2 FormWindow (com.servoy.j2db.FormWindow)2 ISmartRuntimeWindow (com.servoy.j2db.plugins.ISmartRuntimeWindow)2 JSWindow (com.servoy.j2db.scripting.JSWindow)2 RuntimeWindow (com.servoy.j2db.scripting.RuntimeWindow)2 Window (java.awt.Window)2 FormController (com.servoy.j2db.FormController)1 IBasicMainContainer (com.servoy.j2db.IBasicMainContainer)1 Pair (com.servoy.j2db.util.Pair)1 Component (java.awt.Component)1 Container (java.awt.Container)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1