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

COVERAGE SUMMARY FOR SOURCE FILE [Policy.java]

nameclass, %method, %block, %line, %
Policy.java33%  (2/6)46%  (12/26)28%  (54/194)40%  (22.7/57)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Policy$10%   (0/1)0%   (0/2)0%   (0/15)0%   (0/6)
Policy$1 (): void 0%   (0/1)0%   (0/3)0%   (0/2)
log (IStatus): void 0%   (0/1)0%   (0/12)0%   (0/4)
     
class Policy$20%   (0/1)0%   (0/2)0%   (0/18)0%   (0/7)
Policy$2 (): void 0%   (0/1)0%   (0/3)0%   (0/2)
show (IStatus, String): void 0%   (0/1)0%   (0/15)0%   (0/5)
     
class Policy$30%   (0/1)0%   (0/2)0%   (0/57)0%   (0/11)
Policy$3 (Policy$2, IStatus): void 0%   (0/1)0%   (0/9)0%   (0/2)
run (): void 0%   (0/1)0%   (0/48)0%   (0/9)
     
class Policy$40%   (0/1)0%   (0/2)0%   (0/12)0%   (0/4)
Policy$4 (Policy$3): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetDisposed (DisposeEvent): void 0%   (0/1)0%   (0/6)0%   (0/2)
     
class Policy100% (1/1)62%  (10/16)54%  (45/83)62%  (21.6/35)
Policy (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getAnimatorFactory (): AnimatorFactory 0%   (0/1)0%   (0/8)0%   (0/3)
getDummyLog (): ILogger 0%   (0/1)0%   (0/4)0%   (0/1)
getDummyStatusHandler (): StatusHandler 0%   (0/1)0%   (0/4)0%   (0/1)
logException (Exception): void 0%   (0/1)0%   (0/11)0%   (0/4)
setAnimatorFactory (AnimatorFactory): void 0%   (0/1)0%   (0/3)0%   (0/2)
getLog (): ILogger 100% (1/1)67%  (4/6)67%  (2/3)
getStatusHandler (): StatusHandler 100% (1/1)67%  (4/6)67%  (2/3)
setComparator (Comparator): void 100% (1/1)90%  (9/10)97%  (2.9/3)
<static initializer> 100% (1/1)100% (7/7)100% (4/4)
getComparator (): Comparator 100% (1/1)100% (6/6)100% (3/3)
getDefaultComparator (): Comparator 100% (1/1)100% (4/4)100% (1/1)
getErrorSupportProvider (): ErrorSupportProvider 100% (1/1)100% (2/2)100% (1/1)
setErrorSupportProvider (ErrorSupportProvider): void 100% (1/1)100% (3/3)100% (2/2)
setLog (ILogger): void 100% (1/1)100% (3/3)100% (2/2)
setStatusHandler (StatusHandler): void 100% (1/1)100% (3/3)100% (2/2)
     
class Policy$5100% (1/1)100% (2/2)100% (9/9)100% (3/3)
Policy$5 (): void 100% (1/1)100% (3/3)100% (2/2)
compare (Object, Object): int 100% (1/1)100% (6/6)100% (1/1)

1/*******************************************************************************
2 * Copyright (c) 2004, 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 ILogger added
11 *       (bug 49497 [RCP] JFace dependency on org.eclipse.core.runtime enlarges standalone JFace applications)
12 *******************************************************************************/
13package org.eclipse.jface.util;
14 
15import java.util.Comparator;
16 
17import org.eclipse.core.runtime.IStatus;
18import org.eclipse.core.runtime.Status;
19import org.eclipse.jface.dialogs.AnimatorFactory;
20import org.eclipse.jface.dialogs.ErrorSupportProvider;
21import org.eclipse.swt.events.DisposeEvent;
22import org.eclipse.swt.events.DisposeListener;
23import org.eclipse.swt.widgets.Display;
24 
25/**
26 * The Policy class handles settings for behaviour, debug flags and logging
27 * within JFace.
28 * 
29 * @since 3.0
30 */
31public class Policy {
32 
33        /**
34         * Constant for the the default setting for debug options.
35         */
36        public static final boolean DEFAULT = false;
37 
38        /**
39         * The unique identifier of the JFace plug-in.
40         */
41        public static final String JFACE = "org.eclipse.jface"; //$NON-NLS-1$
42 
43        private static ILogger log;
44 
45        private static Comparator viewerComparator;
46 
47        private static AnimatorFactory animatorFactory;
48 
49        /**
50         * A flag to indicate whether unparented dialogs should be checked.
51         */
52        public static boolean DEBUG_DIALOG_NO_PARENT = DEFAULT;
53 
54        /**
55         * A flag to indicate whether actions are being traced.
56         */
57        public static boolean TRACE_ACTIONS = DEFAULT;
58 
59        /**
60         * A flag to indicate whether toolbars are being traced.
61         */
62 
63        public static boolean TRACE_TOOLBAR = DEFAULT;
64 
65        private static ErrorSupportProvider errorSupportProvider;
66 
67        private static StatusHandler statusHandler;
68 
69        /**
70         * Returns the dummy log to use if none has been set
71         */
72        private static ILogger getDummyLog() {
73                return new ILogger() {
74                        public void log(IStatus status) {
75                                System.err.println(status.getMessage());
76                                if (status.getException() != null) {
77                                        status.getException().printStackTrace(System.err);
78                                }
79                        }
80                };
81        }
82 
83        /**
84         * Sets the logger used by JFace to log errors.
85         * 
86         * @param logger
87         *            the logger to use, or <code>null</code> to use the default
88         *            logger
89         * @since 3.1
90         */
91        public static void setLog(ILogger logger) {
92                log = logger;
93        }
94 
95        /**
96         * Returns the logger used by JFace to log errors.
97         * <p>
98         * The default logger prints the status to <code>System.err</code>.
99         * </p>
100         * 
101         * @return the logger
102         * @since 3.1
103         */
104        public static ILogger getLog() {
105                if (log == null) {
106                        log = getDummyLog();
107                }
108                return log;
109        }
110 
111        /**
112         * Sets the status handler used by JFace to handle statuses.
113         * 
114         * @param status
115         *            the handler to use, or <code>null</code> to use the default
116         *            one
117         * @since 3.4
118         */
119        public static void setStatusHandler(StatusHandler status) {
120                statusHandler = status;
121        }
122 
123        /**
124         * Returns the status handler used by JFace to handle statuses.
125         * 
126         * @return the status handler
127         * @since 3.4
128         */
129        public static StatusHandler getStatusHandler() {
130                if (statusHandler == null) {
131                        statusHandler = getDummyStatusHandler();
132                }
133                return statusHandler;
134        }
135 
136        private static StatusHandler getDummyStatusHandler() {
137                return new StatusHandler() {
138                        private SafeRunnableDialog dialog;
139 
140                        public void show(final IStatus status, String title) {
141                                Runnable runnable = new Runnable() {
142                                        public void run() {
143                                                if (dialog == null || dialog.getShell().isDisposed()) {
144                                                        dialog = new SafeRunnableDialog(status);
145                                                        dialog.create();
146                                                        dialog.getShell().addDisposeListener(
147                                                                        new DisposeListener() {
148                                                                                public void widgetDisposed(
149                                                                                                DisposeEvent e) {
150                                                                                        dialog = null;
151                                                                                }
152                                                                        });
153                                                        dialog.open();
154                                                } else {
155                                                        dialog.addStatus(status);
156                                                        dialog.refresh();
157                                                }
158                                        }
159                                };
160                                if (Display.getCurrent() != null) {
161                                        runnable.run();
162                                } else {
163                                        Display.getDefault().asyncExec(runnable);
164                                }
165                        }
166                };
167        }
168 
169        /**
170         * Return the default comparator used by JFace to sort strings.
171         * 
172         * @return a default comparator used by JFace to sort strings
173         */
174        private static Comparator getDefaultComparator() {
175                return new Comparator() {
176                        /**
177                         * Compares string s1 to string s2.
178                         * 
179                         * @param s1
180                         *            string 1
181                         * @param s2
182                         *            string 2
183                         * @return Returns an integer value. Value is less than zero if
184                         *         source is less than target, value is zero if source and
185                         *         target are equal, value is greater than zero if source is
186                         *         greater than target.
187                         * @exception ClassCastException
188                         *                the arguments cannot be cast to Strings.
189                         */
190                        public int compare(Object s1, Object s2) {
191                                return ((String) s1).compareTo((String) s2);
192                        }
193                };
194        }
195 
196        /**
197         * Return the comparator used by JFace to sort strings.
198         * 
199         * @return the comparator used by JFace to sort strings
200         * @since 3.2
201         */
202        public static Comparator getComparator() {
203                if (viewerComparator == null) {
204                        viewerComparator = getDefaultComparator();
205                }
206                return viewerComparator;
207        }
208 
209        /**
210         * Sets the comparator used by JFace to sort strings.
211         * 
212         * @param comparator
213         *            comparator used by JFace to sort strings
214         * @since 3.2
215         */
216        public static void setComparator(Comparator comparator) {
217                org.eclipse.core.runtime.Assert.isTrue(viewerComparator == null);
218                viewerComparator = comparator;
219        }
220 
221        /**
222         * Sets the animator factory used by JFace to create control animator
223         * instances.
224         * 
225         * @param factory
226         *            the AnimatorFactory to use.
227         * @since 3.2
228         * @deprecated this is no longer in use as of 3.3
229         */
230        public static void setAnimatorFactory(AnimatorFactory factory) {
231                animatorFactory = factory;
232        }
233 
234        /**
235         * Returns the animator factory used by JFace to create control animator
236         * instances.
237         * 
238         * @return the animator factory used to create control animator instances.
239         * @since 3.2
240         * @deprecated this is no longer in use as of 3.3
241         */
242        public static AnimatorFactory getAnimatorFactory() {
243                if (animatorFactory == null)
244                        animatorFactory = new AnimatorFactory();
245                return animatorFactory;
246        }
247 
248        /**
249         * Set the error support provider for error dialogs.
250         * 
251         * @param provider
252         * @since 3.3
253         */
254        public static void setErrorSupportProvider(ErrorSupportProvider provider) {
255                errorSupportProvider = provider;
256        }
257 
258        /**
259         * Return the ErrorSupportProvider for the receiver.
260         * 
261         * @return ErrorSupportProvider or <code>null</code> if this has not been
262         *         set
263         * @since 3.3
264         */
265        public static ErrorSupportProvider getErrorSupportProvider() {
266                return errorSupportProvider;
267        }
268 
269        /**
270         * Log the Exception to the logger.
271         * 
272         * @param exception
273         * @since 3.4
274         */
275        public static void logException(Exception exception) {
276                getLog().log(
277                                new Status(IStatus.ERROR, JFACE, exception
278                                                .getLocalizedMessage(), exception));
279 
280        }
281 
282}

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