/*******************************************************************************
 * Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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:
 *     Ted R Williams (Wind River Systems, Inc.) - initial implementation
 *     Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
 *******************************************************************************/

package org.eclipse.cdt.debug.ui.memory.floatingpoint;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

public class FPRenderingPlugin extends AbstractUIPlugin
{
    public static final String PLUGIN_ID = "org.eclipse.cdt.debug.ui.memory.floatingpoint"; //$NON-NLS-1$

    private static FPRenderingPlugin plugin;

    public FPRenderingPlugin()
    {
        super();
    }

    
    @Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
        plugin = this;
	}


	@Override
	public void stop(BundleContext context) throws Exception {
        plugin = null;
		super.stop(context);
	}


	/**
     * Returns the shared instance.
     */
    public static FPRenderingPlugin getDefault()
    {
        return plugin;
    }

    /**
     * Returns the unique identifier for this plugin.
     */
    public static String getUniqueIdentifier()
    {
        return PLUGIN_ID;
    }

    /**
     * Returns the workbench's display.
     */
    public static Display getStandardDisplay()
    {
        return PlatformUI.getWorkbench().getDisplay();
    }

    /**
     * Returns the currently active workbench window shell or <code>null</code>
     * if none.
     * 
     * @return the currently active workbench window shell or <code>null</code>
     */
    public static Shell getShell()
    {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        
        if (window == null)
        {
            IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
            if (windows.length > 0)
            {
                return windows[0].getShell();
            }
        }
        else
        {
            return window.getShell();
        }
        return null;
    }
}
