001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal;
011:
012: import org.eclipse.core.runtime.ISafeRunnable;
013: import org.eclipse.core.runtime.IStatus;
014: import org.eclipse.core.runtime.Platform;
015: import org.eclipse.core.runtime.preferences.IEclipsePreferences;
016: import org.eclipse.core.runtime.preferences.InstanceScope;
017: import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
018: import org.eclipse.jface.internal.InternalPolicy;
019: import org.eclipse.jface.preference.JFacePreferences;
020: import org.eclipse.jface.util.ILogger;
021: import org.eclipse.jface.util.ISafeRunnableRunner;
022: import org.eclipse.jface.util.Policy;
023: import org.eclipse.jface.util.SafeRunnable;
024: import org.eclipse.ui.statushandlers.StatusManager;
025:
026: /**
027: * Utility class for setting up JFace for use by Eclipse.
028: *
029: * @since 3.1
030: */
031: final class JFaceUtil {
032:
033: private JFaceUtil() {
034: // prevents intantiation
035: }
036:
037: /**
038: * Initializes JFace for use by Eclipse.
039: */
040: public static void initializeJFace() {
041: // Set the Platform to run all SafeRunnables
042: SafeRunnable.setRunner(new ISafeRunnableRunner() {
043: public void run(ISafeRunnable code) {
044: Platform.run(code);
045: }
046: });
047:
048: // Pass all errors and warnings to the status handling facility
049: // and the rest to the main runtime log
050: Policy.setLog(new ILogger() {
051: public void log(IStatus status) {
052: if (status.getSeverity() == IStatus.WARNING
053: || status.getSeverity() == IStatus.ERROR) {
054: StatusManager.getManager().handle(status);
055: } else {
056: WorkbenchPlugin.log(status);
057: }
058: }
059: });
060:
061: // Get all debug options from Platform
062: if ("true".equalsIgnoreCase(Platform.getDebugOption("/debug"))) { //$NON-NLS-1$ //$NON-NLS-2$
063: Policy.DEBUG_DIALOG_NO_PARENT = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/dialog/noparent")); //$NON-NLS-1$ //$NON-NLS-2$
064: Policy.TRACE_ACTIONS = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/actions")); //$NON-NLS-1$ //$NON-NLS-2$
065: Policy.TRACE_TOOLBAR = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/toolbarDisposal")); //$NON-NLS-1$ //$NON-NLS-2$
066: InternalPolicy.DEBUG_LOG_REENTRANT_VIEWER_CALLS = "true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/viewers/reentrantViewerCalls")); //$NON-NLS-1$ //$NON-NLS-2$
067: }
068: }
069:
070: /**
071: * Adds a preference listener so that the JFace preference store is initialized
072: * as soon as the workbench preference store becomes available.
073: */
074: public static void initializeJFacePreferences() {
075: IEclipsePreferences rootNode = (IEclipsePreferences) Platform
076: .getPreferencesService().getRootNode().node(
077: InstanceScope.SCOPE);
078: final String workbenchName = WorkbenchPlugin.getDefault()
079: .getBundle().getSymbolicName();
080:
081: rootNode
082: .addNodeChangeListener(new IEclipsePreferences.INodeChangeListener() {
083: /*
084: * (non-Javadoc)
085: *
086: * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#added(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
087: */
088: public void added(NodeChangeEvent event) {
089: if (!event.getChild().name().equals(
090: workbenchName)) {
091: return;
092: }
093: ((IEclipsePreferences) event.getChild())
094: .addPreferenceChangeListener(PlatformUIPreferenceListener
095: .getSingleton());
096:
097: }
098:
099: /*
100: * (non-Javadoc)
101: *
102: * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#removed(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
103: */
104: public void removed(NodeChangeEvent event) {
105: // Nothing to do here
106:
107: }
108: });
109:
110: JFacePreferences.setPreferenceStore(WorkbenchPlugin
111: .getDefault().getPreferenceStore());
112: }
113: }
|