4
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2004, 2007 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 dwtx.core.runtime enlarges standalone JFace applications)
|
|
12 * Port to the D programming language:
|
|
13 * Frank Benoit <benoit@tionex.de>
|
|
14 *******************************************************************************/
|
|
15 module dwtx.jface.util.Policy;
|
|
16
|
|
17 static import dwtx.core.runtime.Assert;
|
|
18 import dwtx.core.runtime.IStatus;
|
|
19 import dwtx.jface.dialogs.AnimatorFactory;
|
|
20 import dwtx.jface.dialogs.ErrorSupportProvider;
|
|
21
|
|
22 import dwtx.jface.util.ILogger;
|
|
23
|
|
24 import dwt.dwthelper.utils;
|
|
25 import tango.io.Stdout;
|
|
26
|
|
27 /**
|
|
28 * The Policy class handles settings for behaviour, debug flags and logging
|
|
29 * within JFace.
|
|
30 *
|
|
31 * @since 3.0
|
|
32 */
|
|
33 public class Policy {
|
|
34
|
|
35 /**
|
|
36 * Constant for the the default setting for debug options.
|
|
37 */
|
|
38 public static const bool DEFAULT = false;
|
|
39
|
|
40 /**
|
|
41 * The unique identifier of the JFace plug-in.
|
|
42 */
|
|
43 public static const String JFACE = "dwtx.jface";//$NON-NLS-1$
|
|
44
|
|
45 private static ILogger log;
|
|
46
|
|
47 private static Comparator viewerComparator;
|
|
48
|
|
49 private static AnimatorFactory animatorFactory;
|
|
50
|
|
51 /**
|
|
52 * A flag to indicate whether unparented dialogs should be checked.
|
|
53 */
|
|
54 public static bool DEBUG_DIALOG_NO_PARENT = DEFAULT;
|
|
55
|
|
56 /**
|
|
57 * A flag to indicate whether actions are being traced.
|
|
58 */
|
|
59 public static bool TRACE_ACTIONS = DEFAULT;
|
|
60
|
|
61 /**
|
|
62 * A flag to indicate whether toolbars are being traced.
|
|
63 */
|
|
64
|
|
65 public static bool TRACE_TOOLBAR = DEFAULT;
|
|
66
|
|
67 private static ErrorSupportProvider errorSupportProvider;
|
|
68
|
|
69 /**
|
|
70 * Returns the dummy log to use if none has been set
|
|
71 */
|
|
72 private static ILogger getDummyLog() {
|
|
73 return new class ILogger {
|
|
74 public void log(IStatus status) {
|
|
75 Stderr.formatln(status.getMessage());
|
|
76 if (status.getException() !is null) {
|
|
77 auto e = status.getException();
|
|
78 Stderr( "Exception in {}({}): {}", e.file, e.line, e.msg );
|
|
79 foreach( msg; e.info ){
|
|
80 Stderr( " trc: {}", msg );
|
|
81 }
|
|
82 // status.getException().printStackTrace();
|
|
83 }
|
|
84 }
|
|
85 };
|
|
86 }
|
|
87
|
|
88 /**
|
|
89 * Sets the logger used by JFace to log errors.
|
|
90 *
|
|
91 * @param logger
|
|
92 * the logger to use, or <code>null</code> to use the default
|
|
93 * logger
|
|
94 * @since 3.1
|
|
95 */
|
|
96 public static void setLog(ILogger logger) {
|
|
97 log = logger;
|
|
98 }
|
|
99
|
|
100 /**
|
|
101 * Returns the logger used by JFace to log errors.
|
|
102 * <p>
|
|
103 * The default logger prints the status to <code>System.err</code>.
|
|
104 * </p>
|
|
105 *
|
|
106 * @return the logger
|
|
107 * @since 3.1
|
|
108 */
|
|
109 public static ILogger getLog() {
|
|
110 if (log is null) {
|
|
111 log = getDummyLog();
|
|
112 }
|
|
113 return log;
|
|
114 }
|
|
115
|
|
116 /**
|
|
117 * Return the default comparator used by JFace to sort strings.
|
|
118 *
|
|
119 * @return a default comparator used by JFace to sort strings
|
|
120 */
|
|
121 private static Comparator getDefaultComparator() {
|
|
122 return new class() Comparator {
|
|
123 /**
|
|
124 * Compares string s1 to string s2.
|
|
125 *
|
|
126 * @param s1
|
|
127 * string 1
|
|
128 * @param s2
|
|
129 * string 2
|
|
130 * @return Returns an integer value. Value is less than zero if
|
|
131 * source is less than target, value is zero if source and
|
|
132 * target are equal, value is greater than zero if source is
|
|
133 * greater than target.
|
|
134 * @exception ClassCastException
|
|
135 * the arguments cannot be cast to Strings.
|
|
136 */
|
|
137 public int compare(Object s1, Object s2) {
|
|
138 auto a = (cast(ArrayWrapperString) s1).array;
|
|
139 auto b = (cast(ArrayWrapperString) s2).array;
|
|
140 return a < b;
|
|
141 }
|
|
142 };
|
|
143 }
|
|
144
|
|
145 /**
|
|
146 * Return the comparator used by JFace to sort strings.
|
|
147 *
|
|
148 * @return the comparator used by JFace to sort strings
|
|
149 * @since 3.2
|
|
150 */
|
|
151 public static Comparator getComparator() {
|
|
152 if (viewerComparator is null) {
|
|
153 viewerComparator = getDefaultComparator();
|
|
154 }
|
|
155 return viewerComparator;
|
|
156 }
|
|
157
|
|
158 /**
|
|
159 * Sets the comparator used by JFace to sort strings.
|
|
160 *
|
|
161 * @param comparator
|
|
162 * comparator used by JFace to sort strings
|
|
163 * @since 3.2
|
|
164 */
|
|
165 public static void setComparator(Comparator comparator) {
|
|
166 dwtx.core.runtime.Assert.Assert.isTrue(viewerComparator is null);
|
|
167 viewerComparator = comparator;
|
|
168 }
|
|
169
|
|
170 /**
|
|
171 * Sets the animator factory used by JFace to create control animator
|
|
172 * instances.
|
|
173 *
|
|
174 * @param factory
|
|
175 * the AnimatorFactory to use.
|
|
176 * @since 3.2
|
|
177 * @deprecated this is no longer in use as of 3.3
|
|
178 */
|
|
179 public static void setAnimatorFactory(AnimatorFactory factory) {
|
|
180 animatorFactory = factory;
|
|
181 }
|
|
182
|
|
183 /**
|
|
184 * Returns the animator factory used by JFace to create control animator
|
|
185 * instances.
|
|
186 *
|
|
187 * @return the animator factory used to create control animator instances.
|
|
188 * @since 3.2
|
|
189 * @deprecated this is no longer in use as of 3.3
|
|
190 */
|
|
191 public static AnimatorFactory getAnimatorFactory() {
|
|
192 if (animatorFactory is null)
|
|
193 animatorFactory = new AnimatorFactory();
|
|
194 return animatorFactory;
|
|
195 }
|
|
196
|
|
197 /**
|
|
198 * Set the error support provider for error dialogs.
|
|
199 *
|
|
200 * @param provider
|
|
201 * @since 3.3
|
|
202 */
|
|
203 public static void setErrorSupportProvider(ErrorSupportProvider provider) {
|
|
204 errorSupportProvider = provider;
|
|
205 }
|
|
206
|
|
207 /**
|
|
208 * Return the ErrorSupportProvider for the receiver.
|
|
209 *
|
|
210 * @return ErrorSupportProvider or <code>null</code> if this has not been set
|
|
211 * @since 3.3
|
|
212 */
|
|
213 public static ErrorSupportProvider getErrorSupportProvider() {
|
|
214 return errorSupportProvider;
|
|
215 }
|
|
216
|
|
217 }
|