org.rubypeople.rdt.internal.ui.preferences.PreferencePageSupport.java Source code

Java tutorial

Introduction

Here is the source code for org.rubypeople.rdt.internal.ui.preferences.PreferencePageSupport.java

Source

/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.rubypeople.rdt.internal.ui.preferences;

import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.IPreferencePage;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.jface.window.Window;

/**
 *
 */
public class PreferencePageSupport {
    /**
     * 
     */
    private PreferencePageSupport() {
        super();
    }

    /**
     * Open the given preference page in a preference dialog.
     * @param shell The shell to open on
     * @param id The id of the preference page as in the plugin.xml 
     * @param page An instance of the page. Note that such a page should also set its own
     * title to correctly show up.
     * @return Returns <code>true</code> if the user ended the page by pressing OK.
     */
    public static boolean showPreferencePage(Shell shell, String id, IPreferencePage page) {
        final IPreferenceNode targetNode = new PreferenceNode(id, page);

        PreferenceManager manager = new PreferenceManager();
        manager.addToRoot(targetNode);
        final PreferenceDialog dialog = new PreferenceDialog(shell, manager);
        final boolean[] result = new boolean[] { false };
        BusyIndicator.showWhile(shell.getDisplay(), new Runnable() {
            public void run() {
                dialog.create();
                dialog.setMessage(targetNode.getLabelText());
                result[0] = (dialog.open() == Window.OK);
            }
        });
        return result[0];
    }
}