EMMA Coverage Report (generated Mon Sep 29 15:05:28 EDT 2008)
[all classes][org.eclipse.jface.util]

COVERAGE SUMMARY FOR SOURCE FILE [SafeRunnable.java]

nameclass, %method, %block, %line, %
SafeRunnable.java50%  (1/2)64%  (9/14)52%  (51/98)55%  (24/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SafeRunnable$10%   (0/1)0%   (0/3)0%   (0/39)0%   (0/18)
SafeRunnable$1 (): void 0%   (0/1)0%   (0/3)0%   (0/2)
handleException (ISafeRunnable, Throwable): void 0%   (0/1)0%   (0/21)0%   (0/10)
run (ISafeRunnable): void 0%   (0/1)0%   (0/15)0%   (0/6)
     
class SafeRunnable100% (1/1)82%  (9/11)86%  (51/59)89%  (24/27)
createDefaultRunner (): ISafeRunnableRunner 0%   (0/1)0%   (0/4)0%   (0/1)
getIgnoreErrors (boolean): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
getRunner (): ISafeRunnableRunner 100% (1/1)67%  (4/6)67%  (2/3)
<static initializer> 100% (1/1)100% (3/3)100% (2/2)
SafeRunnable (): void 100% (1/1)100% (3/3)100% (2/2)
SafeRunnable (String): void 100% (1/1)100% (6/6)100% (3/3)
getIgnoreErrors (): boolean 100% (1/1)100% (2/2)100% (1/1)
handleException (Throwable): void 100% (1/1)100% (23/23)100% (8/8)
run (ISafeRunnable): void 100% (1/1)100% (4/4)100% (2/2)
setIgnoreErrors (boolean): void 100% (1/1)100% (3/3)100% (2/2)
setRunner (ISafeRunnableRunner): void 100% (1/1)100% (3/3)100% (2/2)

1/*******************************************************************************
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *     Chris Gross (schtoo@schtoo.com) - support for ISafeRunnableRunner added
11 *       (bug 49497 [RCP] JFace dependency on org.eclipse.core.runtime enlarges standalone JFace applications)
12 *******************************************************************************/
13package org.eclipse.jface.util;
14 
15import org.eclipse.core.runtime.ISafeRunnable;
16import org.eclipse.core.runtime.IStatus;
17import org.eclipse.core.runtime.OperationCanceledException;
18import org.eclipse.core.runtime.Status;
19import org.eclipse.jface.resource.JFaceResources;
20 
21/**
22 * Implements a default implementation of ISafeRunnable. The default
23 * implementation of <code>handleException</code> opens a dialog to show any
24 * errors as they accumulate.
25 * <p>
26 * This may be executed on any thread.
27 */
28public abstract class SafeRunnable implements ISafeRunnable {
29 
30        private static boolean ignoreErrors = false;
31 
32        private static ISafeRunnableRunner runner;
33 
34        private String message;
35 
36        /**
37         * Creates a new instance of SafeRunnable with a default error message.
38         */
39        public SafeRunnable() {
40                // do nothing
41        }
42 
43        /**
44         * Creates a new instance of SafeRunnable with the given error message.
45         * 
46         * @param message
47         *            the error message to use
48         */
49        public SafeRunnable(String message) {
50                this.message = message;
51        }
52 
53        /*
54         * (non-Javadoc)
55         * 
56         * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
57         */
58        public void handleException(Throwable e) {
59                // Workaround to avoid interactive error dialogs during
60                // automated testing
61                if (ignoreErrors)
62                        return;
63 
64                if (message == null)
65                        message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$
66 
67                Policy.getStatusHandler().show(
68                                new Status(IStatus.ERROR, Policy.JFACE, message, e),
69                                JFaceResources.getString("SafeRunnable.errorMessage")); //$NON-NLS-1$
70        }
71 
72        /**
73         * Flag to avoid interactive error dialogs during automated testing.
74         * 
75         * @param flag
76         * @return true if errors should be ignored
77         * @deprecated use getIgnoreErrors()
78         */
79        public static boolean getIgnoreErrors(boolean flag) {
80                return ignoreErrors;
81        }
82 
83        /**
84         * Flag to avoid interactive error dialogs during automated testing.
85         * 
86         * @return true if errors should be ignored
87         * 
88         * @since 3.0
89         */
90        public static boolean getIgnoreErrors() {
91                return ignoreErrors;
92        }
93 
94        /**
95         * Flag to avoid interactive error dialogs during automated testing.
96         * 
97         * @param flag
98         *            set to true if errors should be ignored
99         */
100        public static void setIgnoreErrors(boolean flag) {
101                ignoreErrors = flag;
102        }
103 
104        /**
105         * Returns the safe runnable runner.
106         * 
107         * @return the safe runnable runner
108         * 
109         * @since 3.1
110         */
111        public static ISafeRunnableRunner getRunner() {
112                if (runner == null) {
113                        runner = createDefaultRunner();
114                }
115                return runner;
116        }
117 
118        /**
119         * Creates the default safe runnable runner.
120         * 
121         * @return the default safe runnable runner
122         * @since 3.1
123         */
124        private static ISafeRunnableRunner createDefaultRunner() {
125                return new ISafeRunnableRunner() {
126                        public void run(ISafeRunnable code) {
127                                try {
128                                        code.run();
129                                } catch (Exception e) {
130                                        handleException(code, e);
131                                } catch (LinkageError e) {
132                                        handleException(code, e);
133                                }
134                        }
135 
136                        private void handleException(ISafeRunnable code, Throwable e) {
137                                if (!(e instanceof OperationCanceledException)) {
138                                        try {
139                                                Policy.getLog()
140                                                                .log(
141                                                                                new Status(IStatus.ERROR, Policy.JFACE,
142                                                                                                IStatus.ERROR,
143                                                                                                "Exception occurred", e)); //$NON-NLS-1$
144                                        } catch (Exception ex) {
145                                                e.printStackTrace();
146                                        }
147                                }
148                                code.handleException(e);
149                        }
150                };
151        }
152 
153        /**
154         * Sets the safe runnable runner.
155         * 
156         * @param runner
157         *            the runner to set, or <code>null</code> to reset to the
158         *            default runner
159         * @since 3.1
160         */
161        public static void setRunner(ISafeRunnableRunner runner) {
162                SafeRunnable.runner = runner;
163        }
164 
165        /**
166         * Runs the given safe runnable using the safe runnable runner. This is a
167         * convenience method, equivalent to:
168         * <code>SafeRunnable.getRunner().run(runnable)</code>.
169         * 
170         * @param runnable
171         *            the runnable to run
172         * @since 3.1
173         */
174        public static void run(ISafeRunnable runnable) {
175                getRunner().run(runnable);
176        }
177 
178}

[all classes][org.eclipse.jface.util]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov