blob: 19cb8651356a9e84f4ea154edbe0d1e3602d4687 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.jsdt.internal.ui.dialogs;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.TwoPaneElementSelector;
import org.eclipse.wst.jsdt.core.IType;
import org.eclipse.wst.jsdt.core.search.IJavaScriptSearchScope;
import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.wst.jsdt.internal.ui.JavaUIMessages;
import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler;
import org.eclipse.wst.jsdt.internal.ui.util.MainMethodSearchEngine;
import org.eclipse.wst.jsdt.ui.JavaScriptElementLabelProvider;
/**
* A dialog to select a type from a list of types. The dialog allows
* multiple selections.
*/
public class MainTypeSelectionDialog extends TwoPaneElementSelector {
private IRunnableContext fRunnableContext;
private IJavaScriptSearchScope fScope;
private int fStyle;
private static class PackageRenderer extends JavaScriptElementLabelProvider {
public PackageRenderer() {
super(JavaScriptElementLabelProvider.SHOW_PARAMETERS | JavaScriptElementLabelProvider.SHOW_POST_QUALIFIED | JavaScriptElementLabelProvider.SHOW_ROOT);
}
public Image getImage(Object element) {
return super.getImage(((IType)element).getPackageFragment());
}
public String getText(Object element) {
return super.getText(((IType)element).getPackageFragment());
}
}
/**
* Constructor.
*/
public MainTypeSelectionDialog(Shell shell, IRunnableContext context,
IJavaScriptSearchScope scope, int style)
{
super(shell, new JavaScriptElementLabelProvider(JavaScriptElementLabelProvider.SHOW_BASICS | JavaScriptElementLabelProvider.SHOW_OVERLAY_ICONS),
new PackageRenderer());
Assert.isNotNull(context);
Assert.isNotNull(scope);
fRunnableContext= context;
fScope= scope;
fStyle= style;
}
/*
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.MAINTYPE_SELECTION_DIALOG);
}
/*
* @see Window#open()
*/
public int open() {
MainMethodSearchEngine engine= new MainMethodSearchEngine();
IType[] types;
try {
types= engine.searchMainMethods(fRunnableContext, fScope, fStyle);
} catch (InterruptedException e) {
return CANCEL;
} catch (InvocationTargetException e) {
ExceptionHandler.handle(e, JavaUIMessages.MainTypeSelectionDialog_errorTitle, e.getMessage());
return CANCEL;
}
setElements(types);
return super.open();
}
}