Mercurial > projects > dwt-addons
diff dwtx/jface/util/Policy.d @ 70:46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 22 May 2008 01:36:46 +0200 |
parents | da5ad8eedf5d |
children | 4878bef4a38e |
line wrap: on
line diff
--- a/dwtx/jface/util/Policy.d Mon May 19 13:41:06 2008 +0200 +++ b/dwtx/jface/util/Policy.d Thu May 22 01:36:46 2008 +0200 @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation * Chris Gross (schtoo@schtoo.com) - support for ILogger added @@ -15,7 +15,11 @@ module dwtx.jface.util.Policy; static import dwtx.core.runtime.Assert; +import dwt.events.DisposeEvent; +import dwt.events.DisposeListener; +import dwt.widgets.Display; import dwtx.core.runtime.IStatus; +import dwtx.core.runtime.Status; import dwtx.jface.dialogs.AnimatorFactory; import dwtx.jface.dialogs.ErrorSupportProvider; @@ -40,7 +44,7 @@ /** * The unique identifier of the JFace plug-in. */ - public static const String JFACE = "dwtx.jface";//$NON-NLS-1$ + public static const String JFACE = "dwtx.jface"; //$NON-NLS-1$ private static ILogger log; @@ -66,6 +70,8 @@ private static ErrorSupportProvider errorSupportProvider; + private static StatusHandler statusHandler; + /** * Returns the dummy log to use if none has been set */ @@ -114,6 +120,64 @@ } /** + * Sets the status handler used by JFace to handle statuses. + * + * @param status + * the handler to use, or <code>null</code> to use the default + * one + * @since 3.4 + */ + public static void setStatusHandler(StatusHandler status) { + statusHandler = status; + } + + /** + * Returns the status handler used by JFace to handle statuses. + * + * @return the status handler + * @since 3.4 + */ + public static StatusHandler getStatusHandler() { + if (statusHandler is null) { + statusHandler = getDummyStatusHandler(); + } + return statusHandler; + } + + private static StatusHandler getDummyStatusHandler() { + return new StatusHandler() { + private SafeRunnableDialog dialog; + + public void show(final IStatus status, String title) { + Runnable runnable = new Runnable() { + public void run() { + if (dialog is null || dialog.getShell().isDisposed()) { + dialog = new SafeRunnableDialog(status); + dialog.create(); + dialog.getShell().addDisposeListener( + new DisposeListener() { + public void widgetDisposed( + DisposeEvent e) { + dialog = null; + } + }); + dialog.open(); + } else { + dialog.addStatus(status); + dialog.refresh(); + } + } + }; + if (Display.getCurrent() !is null) { + runnable.run(); + } else { + Display.getDefault().asyncExec(runnable); + } + } + }; + } + + /** * Return the default comparator used by JFace to sort strings. * * @return a default comparator used by JFace to sort strings @@ -207,11 +271,24 @@ /** * Return the ErrorSupportProvider for the receiver. * - * @return ErrorSupportProvider or <code>null</code> if this has not been set + * @return ErrorSupportProvider or <code>null</code> if this has not been + * set * @since 3.3 */ public static ErrorSupportProvider getErrorSupportProvider() { return errorSupportProvider; } + /** + * Log the Exception to the logger. + * + * @param exception + */ + public static void logException(Exception exception) { + getLog().log( + new Status(IStatus.ERROR, JFACE, exception + .getLocalizedMessage(), exception)); + + } + }