X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=swt%2Forg.argeo.cms.swt%2Fsrc%2Forg%2Fargeo%2Fcms%2Fswt%2Fdialogs%2FLightweightDialog.java;h=d74be6aa20c59c3ba4348c56f680f438a3514987;hb=e018ad9078249a806f2e2ef86a6adcbd8cca3188;hp=bf6417beadd3baf911407cd57e6665c946649698;hpb=7b242851c0094d13cbaca5b68261ad92c873a59f;p=lgpl%2Fargeo-commons.git diff --git a/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/dialogs/LightweightDialog.java b/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/dialogs/LightweightDialog.java index bf6417bea..d74be6aa2 100644 --- a/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/dialogs/LightweightDialog.java +++ b/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/dialogs/LightweightDialog.java @@ -29,13 +29,15 @@ public class LightweightDialog { private Shell backgroundShell; private Shell foregoundShell; + private Display display; + private Integer returnCode = null; private boolean block = true; private String title; /** Tries to find a display */ - private static Display getDisplay() { + static Display findDisplay() { try { Display display = Display.getCurrent(); if (display != null) @@ -52,6 +54,7 @@ public class LightweightDialog { } public int open() { + display = findDisplay(); if (foregoundShell != null) throw new EclipseUiException("There is already a shell"); backgroundShell = new Shell(parentShell, SWT.ON_TOP); @@ -61,7 +64,7 @@ public class LightweightDialog { // } else // backgroundShell.setMaximized(true); backgroundShell.setAlpha(128); - backgroundShell.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK)); + backgroundShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); foregoundShell = new Shell(backgroundShell, SWT.NO_TRIM | SWT.ON_TOP); if (title != null) setTitle(title); @@ -71,7 +74,7 @@ public class LightweightDialog { // shell.pack(); // shell.layout(); - Rectangle shellBounds = parentShell != null ? parentShell.getBounds() : Display.getCurrent().getBounds();// RAP + Rectangle shellBounds = parentShell != null ? parentShell.getBounds() : display.getBounds();// RAP Point dialogSize = foregoundShell.getSize(); int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2; int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2; @@ -113,6 +116,7 @@ public class LightweightDialog { closeShell(CANCEL); } }); + backgroundShell.addDisposeListener((event) -> onClose()); if (block) { block(); @@ -141,6 +145,10 @@ public class LightweightDialog { return foregoundShell.getShells().length != 0; } + protected void onClose() { + + } + // public synchronized int openAndWait() { // open(); // while (returnCode == null) @@ -175,9 +183,6 @@ public class LightweightDialog { } protected Point getInitialSize() { - // if (exception != null) - // return new Point(800, 600); - // else return new Point(600, 400); } @@ -252,4 +257,8 @@ public class LightweightDialog { return returnCode; } + Display getDisplay() { + return display; + } + } \ No newline at end of file