/*******************************************************************************
* Copyright (c) 2007, 2015 Zend Technologies 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:
* Zend Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.php.refactoring.ui;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
/**
* The activator class controls the plug-in life cycle
*/
public class RefactoringUIPlugin extends AbstractUIPlugin {
public static final int INTERNAL_ERROR = 10001;
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.php.refactoring.ui"; //$NON-NLS-1$
// The shared instance
private static RefactoringUIPlugin plugin;
/**
* The constructor
*/
public RefactoringUIPlugin() {
plugin = this;
}
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
public static IWorkbenchPage getActivePage() {
return getDefault().internalGetActivePage();
}
public static IWorkbenchWindow getActiveWorkbenchWindow() {
return getDefault().getWorkbench().getActiveWorkbenchWindow();
}
public static Shell getActiveWorkbenchShell() {
IWorkbenchWindow window = getActiveWorkbenchWindow();
if (window != null) {
return window.getShell();
}
return null;
}
private IWorkbenchPage internalGetActivePage() {
IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
if (window == null)
return null;
return window.getActivePage();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.
* BundleContext )
*/
public void start(BundleContext context) throws Exception {
super.start(context);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.
* BundleContext )
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static RefactoringUIPlugin getDefault() {
return plugin;
}
public static void log(Exception e) {
String message = e != null ? e.toString() + " in " + e.getStackTrace()[0].getFileName() : ""; //$NON-NLS-1$ //$NON-NLS-2$
logErrorMessage(message);
}
public static void logErrorMessage(String message) {
log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, message == null ? "" : message, null)); //$NON-NLS-1$
}
public static void log(IStatus status) {
getDefault().getLog().log(status);
}
/**
* Returns a section in the Refactoring plugin's dialog settings. If the
* section doesn't exist yet, it is created.
*
* @param name
* the name of the section
* @return the section of the given name
* @since 3.2
*/
public IDialogSettings getDialogSettingsSection(String name) {
IDialogSettings dialogSettings = getDialogSettings();
IDialogSettings section = dialogSettings.getSection(name);
if (section == null) {
section = dialogSettings.addNewSection(name);
}
return section;
}
public String getVersion() {
return (String) getBundle().getHeaders().get(Constants.BUNDLE_VERSION);
}
}