blob: 2848c79a4532060dfd2faf4e94971f691ff8b482 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*******************************************************************************
* Copyright (c) 2005, 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
*******************************************************************************/
package org.eclipse.ui.internal;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
import org.eclipse.jface.internal.InternalPolicy;
import org.eclipse.jface.preference.JFacePreferences;
import org.eclipse.jface.util.ILogger;
import org.eclipse.jface.util.ISafeRunnableRunner;
import org.eclipse.jface.util.Policy;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.jface.util.StatusHandler;
import org.eclipse.ui.statushandlers.StatusAdapter;
import org.eclipse.ui.statushandlers.StatusManager;
/**
* Utility class for setting up JFace for use by Eclipse.
*
* @since 3.1
*/
final class JFaceUtil {
private JFaceUtil() {
// prevents intantiation
}
/**
* Initializes JFace for use by Eclipse.
*/
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("/debug"))) { //$NON-NLS-1$ //$NON-NLS-2$
Policy.DEBUG_DIALOG_NO_PARENT = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/dialog/noparent")); //$NON-NLS-1$ //$NON-NLS-2$
Policy.TRACE_ACTIONS = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/actions")); //$NON-NLS-1$ //$NON-NLS-2$
Policy.TRACE_TOOLBAR = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/toolbarDisposal")); //$NON-NLS-1$ //$NON-NLS-2$
InternalPolicy.DEBUG_LOG_REENTRANT_VIEWER_CALLS = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/viewers/reentrantViewerCalls")); //$NON-NLS-1$ //$NON-NLS-2$
}
}
/**
* Adds a preference listener so that the JFace preference store is initialized
* as soon as the workbench preference store becomes available.
*/
public static void initializeJFacePreferences() {
IEclipsePreferences rootNode = (IEclipsePreferences) Platform.getPreferencesService().getRootNode().node(InstanceScope.SCOPE);
final String workbenchName = WorkbenchPlugin.getDefault().getBundle().getSymbolicName();
rootNode.addNodeChangeListener(new IEclipsePreferences.INodeChangeListener() {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#added(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
*/
public void added(NodeChangeEvent event) {
if (!event.getChild().name().equals(workbenchName)) {
return;
}
((IEclipsePreferences) event.getChild()).addPreferenceChangeListener(PlatformUIPreferenceListener.getSingleton());
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#removed(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
*/
public void removed(NodeChangeEvent event) {
// Nothing to do here
}
});
JFacePreferences.setPreferenceStore(WorkbenchPlugin.getDefault().getPreferenceStore());
}
}
|