X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.eclipse.ui%2Fsrc%2Forg%2Fargeo%2Feclipse%2Fui%2Fdialogs%2FLightweightDialog.java;h=d00365bf2c7e8ad1aa6547ffae2a326a6d8ecfd8;hb=c53fec78daddb69c489686844188036b04e1615a;hp=a923b0134c6c0173eef2eb0dd5bb7ea4555a915f;hpb=b7606ca647d875808ee3fdd19240dc9d51f40ac6;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java index a923b0134..d00365bf2 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java @@ -1,18 +1,3 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.argeo.eclipse.ui.dialogs; import org.apache.commons.logging.Log; @@ -33,6 +18,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; /** Generic lightweight dialog, not based on JFace. */ +@Deprecated public class LightweightDialog { private final static Log log = LogFactory.getLog(LightweightDialog.class); @@ -70,8 +56,11 @@ public class LightweightDialog { public int open() { if (foregoundShell != null) throw new EclipseUiException("There is already a shell"); - backgroundShell = new Shell(parentShell, SWT.DIALOG_TRIM | SWT.ON_TOP); + backgroundShell = new Shell(parentShell, SWT.ON_TOP); backgroundShell.setFullScreen(true); + // if (parentShell != null) { + // backgroundShell.setBounds(parentShell.getBounds()); + // } else // backgroundShell.setMaximized(true); backgroundShell.setAlpha(128); backgroundShell.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK)); @@ -84,7 +73,7 @@ public class LightweightDialog { // shell.pack(); // shell.layout(); - Rectangle shellBounds = Display.getCurrent().getBounds();// RAP + Rectangle shellBounds = parentShell != null ? parentShell.getBounds() : Display.getCurrent().getBounds();// RAP Point dialogSize = foregoundShell.getSize(); int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2; int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2; @@ -95,6 +84,8 @@ public class LightweightDialog { @Override public void shellDeactivated(ShellEvent e) { + if (hasChildShells()) + return; if (returnCode == null)// not yet closed closeShell(CANCEL); } @@ -118,23 +109,40 @@ public class LightweightDialog { @Override public void focusGained(FocusEvent event) { + if (hasChildShells()) + return; if (returnCode == null)// not yet closed closeShell(CANCEL); } }); if (block) { - try { - runEventLoop(foregoundShell); - } catch (Throwable t) { - log.error("Cannot open blocking lightweight dialog", t); - } + block(); } if (returnCode == null) returnCode = OK; return returnCode; } + public void block() { + try { + runEventLoop(foregoundShell); + } catch (ThreadDeath t) { + returnCode = CANCEL; + if (log.isTraceEnabled()) + log.error("Thread death, canceling dialog", t); + } catch (Throwable t) { + returnCode = CANCEL; + log.error("Cannot open blocking lightweight dialog", t); + } + } + + private boolean hasChildShells() { + if (foregoundShell == null) + return false; + return foregoundShell.getShells().length != 0; + } + // public synchronized int openAndWait() { // open(); // while (returnCode == null) @@ -211,6 +219,8 @@ public class LightweightDialog { if (!display.readAndDispatch()) { display.sleep(); } + } catch (UnsupportedOperationException e) { + throw e; } catch (Throwable e) { handleException(e); } @@ -240,4 +250,8 @@ public class LightweightDialog { getForegoundShell().setText(title); } + public Integer getReturnCode() { + return returnCode; + } + } \ No newline at end of file