Example usage for org.eclipse.jface.util ILogger ILogger

List of usage examples for org.eclipse.jface.util ILogger ILogger

Introduction

In this page you can find the example usage for org.eclipse.jface.util ILogger ILogger.

Prototype

ILogger

Source Link

Usage

From source file:org.eclipse.gyrex.admin.ui.internal.application.AdminApplication.java

License:Open Source License

private void setupJFacePolicy() {
    Policy.setLog(new ILogger() {

        @Override/* w  w  w.j av a 2 s.  c o  m*/
        public void log(final IStatus status) {
            if (status.matches(IStatus.CANCEL) || status.matches(IStatus.ERROR)) {
                LOG.error(status.getMessage(), status.getException());
            } else if (status.matches(IStatus.WARNING)) {
                LOG.warn(status.getMessage(), status.getException());
            } else {
                LOG.info(status.getMessage(), status.getException());
            }
        }
    });
    final StatusHandler defaultStatusHandler = Policy.getStatusHandler();
    Policy.setStatusHandler(new StatusHandler() {

        @Override
        public void show(final IStatus status, final String title) {
            Policy.getLog().log(status);
            defaultStatusHandler.show(status, title);
        }
    });
}

From source file:org.eclipse.ui.internal.JFaceUtil.java

License:Open Source License

/**
 * Initializes JFace for use by Eclipse.
 *//*from  w w  w .j a v a2 s.co m*/
public static void initializeJFace() {
    // Set the SafeRunner to run all SafeRunnables
    SafeRunnable.setRunner(new ISafeRunnableRunner() {
        public void run(ISafeRunnable code) {
            SafeRunner.run(code);
        }
    });

    // Pass all errors and warnings to the status handling facility
    // and the rest to the main runtime log
    Policy.setLog(new ILogger() {
        public void log(IStatus status) {
            if (status.getSeverity() == IStatus.WARNING || status.getSeverity() == IStatus.ERROR) {
                StatusManager.getManager().handle(status);
            } else {
                WorkbenchPlugin.log(status);
            }
        }
    });

    Policy.setStatusHandler(new StatusHandler() {
        public void show(IStatus status, String title) {
            StatusAdapter statusAdapter = new StatusAdapter(status);
            statusAdapter.setProperty(StatusAdapter.TITLE_PROPERTY, title);
            StatusManager.getManager().handle(statusAdapter, StatusManager.SHOW);
        }
    });

    // Get all debug options from Platform
    if ("true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug"))) { //$NON-NLS-1$ //$NON-NLS-2$
        Policy.DEBUG_DIALOG_NO_PARENT = "true" //$NON-NLS-1$
                .equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/dialog/noparent")); //$NON-NLS-1$
        Policy.TRACE_ACTIONS = "true" //$NON-NLS-1$
                .equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/actions")); //$NON-NLS-1$
        Policy.TRACE_TOOLBAR = "true" //$NON-NLS-1$
                .equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/toolbarDisposal")); //$NON-NLS-1$
        InternalPolicy.DEBUG_LOG_REENTRANT_VIEWER_CALLS = "true".equalsIgnoreCase( //$NON-NLS-1$
                Platform.getDebugOption(Policy.JFACE + "/debug/viewers/reentrantViewerCalls")); //$NON-NLS-1$
        InternalPolicy.DEBUG_LOG_EQUAL_VIEWER_ELEMENTS = "true" //$NON-NLS-1$
                .equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/viewers/equalElements")); //$NON-NLS-1$
    }
}

From source file:org.eclipse.ui.tests.preferences.FontPreferenceTestCase.java

License:Open Source License

/**
 * The test added to assess results of accessing FontRegistry from a non-UI 
 * thread. See bug 230360./*from  w  ww. j a  va 2 s. com*/
 */
public void testNonUIThreadFontAccess() {
    // create a separate font registry to avoid contaminating other tests
    final FontRegistry fontRegistry = new FontRegistry("org.eclipse.jface.resource.jfacefonts"); //$NON-NLS-1$
    // pre-calculate the default font; calling it in worker thread will only cause SWTException
    Font defaultFont = fontRegistry.defaultFont();
    defaultFont.toString(); // avoids compiler warning

    // redirect logging so that we catch the error log
    final boolean[] errorLogged = new boolean[] { false };
    ILogger logger = Policy.getLog();
    Policy.setLog(new ILogger() {
        public void log(IStatus status) {
            if (status != null && status.getSeverity() == IStatus.ERROR
                    && status.getPlugin().equals(Policy.JFACE))
                errorLogged[0] = true;
        }
    });

    Job job = new Job("Non-UI thread FontRegistry Access Test") {
        protected IStatus run(IProgressMonitor monitor) {
            // this should produce no exception, but should log a error 
            boolean created = checkFont(fontRegistry);
            assertFalse(created);
            return Status.OK_STATUS;
        }
    };
    job.schedule();
    try {
        job.join();
        assertTrue(errorLogged[0]);
    } catch (InterruptedException e) {
        fail("Worker thread was interrupted in the FontRegistry access test");
    } finally {
        Policy.setLog(logger);
    }

    // now let's try to create the same font in the UI thread and check that the correct 
    boolean created = checkFont(fontRegistry);
    assertTrue(created);
}