KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > JFaceUtil


1 /*******************************************************************************
2  * Copyright (c) 2005, 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  *******************************************************************************/

11
12 package org.eclipse.ui.internal;
13
14 import org.eclipse.core.runtime.ISafeRunnable;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
18 import org.eclipse.core.runtime.preferences.InstanceScope;
19 import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
20 import org.eclipse.jface.internal.InternalPolicy;
21 import org.eclipse.jface.preference.JFacePreferences;
22 import org.eclipse.jface.util.ILogger;
23 import org.eclipse.jface.util.ISafeRunnableRunner;
24 import org.eclipse.jface.util.Policy;
25 import org.eclipse.jface.util.SafeRunnable;
26 import org.eclipse.ui.statushandlers.StatusManager;
27
28 /**
29  * Utility class for setting up JFace for use by Eclipse.
30  *
31  * @since 3.1
32  */

33 final class JFaceUtil {
34
35     private JFaceUtil() {
36         // prevents intantiation
37
}
38
39     /**
40      * Initializes JFace for use by Eclipse.
41      */

42     public static void initializeJFace() {
43         // Set the Platform to run all SafeRunnables
44
SafeRunnable.setRunner(new ISafeRunnableRunner() {
45             public void run(ISafeRunnable code) {
46                 Platform.run(code);
47             }
48         });
49
50         // Pass all errors and warnings to the status handling facility
51
// and the rest to the main runtime log
52
Policy.setLog(new ILogger() {
53             public void log(IStatus status) {
54                 if (status.getSeverity() == IStatus.WARNING
55                         || status.getSeverity() == IStatus.ERROR) {
56                     StatusManager.getManager().handle(status);
57                 } else {
58                     WorkbenchPlugin.log(status);
59                 }
60             }
61         });
62
63
64         // Get all debug options from Platform
65
if ("true".equalsIgnoreCase(Platform.getDebugOption("/debug"))) { //$NON-NLS-1$ //$NON-NLS-2$
66
Policy.DEBUG_DIALOG_NO_PARENT = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/dialog/noparent")); //$NON-NLS-1$ //$NON-NLS-2$
67
Policy.TRACE_ACTIONS = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/actions")); //$NON-NLS-1$ //$NON-NLS-2$
68
Policy.TRACE_TOOLBAR = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/toolbarDisposal")); //$NON-NLS-1$ //$NON-NLS-2$
69
InternalPolicy.DEBUG_LOG_REENTRANT_VIEWER_CALLS = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/viewers/reentrantViewerCalls")); //$NON-NLS-1$ //$NON-NLS-2$
70
}
71     }
72
73     /**
74      * Adds a preference listener so that the JFace preference store is initialized
75      * as soon as the workbench preference store becomes available.
76      */

77     public static void initializeJFacePreferences() {
78         IEclipsePreferences rootNode = (IEclipsePreferences) Platform.getPreferencesService().getRootNode().node(InstanceScope.SCOPE);
79         final String JavaDoc workbenchName = WorkbenchPlugin.getDefault().getBundle().getSymbolicName();
80         
81         rootNode.addNodeChangeListener(new IEclipsePreferences.INodeChangeListener() {
82             /*
83              * (non-Javadoc)
84              *
85              * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#added(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
86              */

87             public void added(NodeChangeEvent event) {
88                 if (!event.getChild().name().equals(workbenchName)) {
89                     return;
90                 }
91                 ((IEclipsePreferences) event.getChild()).addPreferenceChangeListener(PlatformUIPreferenceListener.getSingleton());
92
93             }
94             /*
95              * (non-Javadoc)
96              *
97              * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#removed(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
98              */

99             public void removed(NodeChangeEvent event) {
100                 // Nothing to do here
101

102             }
103         });
104         
105         JFacePreferences.setPreferenceStore(WorkbenchPlugin.getDefault().getPreferenceStore());
106     }
107 }
108
Popular Tags