use of com.servoy.j2db.scripting.RuntimeWindow 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);
}
use of com.servoy.j2db.scripting.RuntimeWindow 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);
}
use of com.servoy.j2db.scripting.RuntimeWindow in project servoy-client by Servoy.
the class FormManager method showFormInDialog.
public void showFormInDialog(String formName, Rectangle bounds, String title, boolean resizeble, boolean showTextToolbar, boolean closeAll, boolean modal, String windowName) {
// first window is modal, second reuses same dialog
boolean legacyV3Behavior = false;
if (windowName == null) {
windowName = DEFAULT_DIALOG_NAME;
legacyV3Behavior = true;
}
RuntimeWindow thisWindow = application.getRuntimeWindowManager().getWindow(windowName);
if (thisWindow != null && thisWindow.getType() != JSWindow.DIALOG && thisWindow.getType() != JSWindow.MODAL_DIALOG) {
// make sure it is closed before reference to it is lost
thisWindow.hide(true);
thisWindow.destroy();
thisWindow = null;
}
if (thisWindow == null) {
thisWindow = application.getRuntimeWindowManager().createWindow(windowName, modal ? JSWindow.MODAL_DIALOG : JSWindow.DIALOG, null);
}
thisWindow.setInitialBounds(bounds.x, bounds.y, bounds.width, bounds.height);
thisWindow.showTextToolbar(showTextToolbar);
thisWindow.setTitle(title);
thisWindow.setResizable(resizeble);
thisWindow.oldShow(formName, closeAll, legacyV3Behavior);
}
use of com.servoy.j2db.scripting.RuntimeWindow in project servoy-client by Servoy.
the class RuntimeWindowManager method createWindow.
/**
* Create a new user window. If a window with this name already exists, it will be closed/destroyed first.
* @param windowName the name of the window. Must not be null.
* @param parent
* @param i
* @return the newly created window.
*/
public RuntimeWindow createWindow(String windowName, int type, JSWindow parent) {
RuntimeWindow win = windows.get(windowName);
if (win != null) {
win.destroy();
}
// RuntimeWindow currentWindow = null;
// if (type == JSWindow.DIALOG || type == JSWindow.MODAL_DIALOG)
// {
// RuntimeWindow pw = application.getRuntimeWindowManager().getCurrentWindow();
// if (pw != null)
// {
// currentWindow = pw.getJSWindow().getImpl();
// }
// }
// was : currentWindow, but why use fixed parent if it was not specified in JS? better decide each time the window/dialog is shown, so null should be better
win = createWindowInternal(windowName, type, parent != null ? parent.getImpl() : null);
if (win != null)
windows.put(windowName, win);
return win;
}
use of com.servoy.j2db.scripting.RuntimeWindow in project servoy-client by Servoy.
the class RuntimeWindowManager method getCurrentWindow.
public RuntimeWindow getCurrentWindow() {
RuntimeWindow window = getWindow(currentWindowName);
if (window == null) {
if (log.isInfoEnabled())
log.info("No current window for '" + currentWindowName + "' creating one if name is not null");
if (currentWindowName != null) {
// the current window shouldn't be null, this could be a new tab in the web, create it
window = createWindowInternal(currentWindowName, JSWindow.WINDOW, null);
windows.put(currentWindowName, window);
}
}
return window;
}
Aggregations