1 11 package org.eclipse.jdt.internal.debug.ui.launcher; 12 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.HashSet ; 16 import java.util.Set ; 17 18 import org.eclipse.core.resources.IWorkspaceRoot; 19 import org.eclipse.core.resources.ResourcesPlugin; 20 import org.eclipse.core.runtime.Assert; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.core.runtime.SubProgressMonitor; 23 import org.eclipse.jdt.core.IJavaModel; 24 import org.eclipse.jdt.core.IJavaProject; 25 import org.eclipse.jdt.core.IType; 26 import org.eclipse.jdt.core.JavaCore; 27 import org.eclipse.jdt.core.JavaModelException; 28 import org.eclipse.jdt.ui.JavaElementLabelProvider; 29 import org.eclipse.jface.operation.IRunnableContext; 30 import org.eclipse.jface.operation.IRunnableWithProgress; 31 import org.eclipse.swt.graphics.Image; 32 import org.eclipse.swt.widgets.Composite; 33 import org.eclipse.swt.widgets.Control; 34 import org.eclipse.swt.widgets.Shell; 35 import org.eclipse.ui.dialogs.TwoPaneElementSelector; 36 37 40 public class AppletSelectionDialog extends TwoPaneElementSelector { 41 42 private IRunnableContext fRunnableContext; 43 private IJavaProject fProject; 44 private static final IType[] EMPTY_TYPE_ARRAY = new IType[] {}; 45 46 private static class PackageRenderer extends JavaElementLabelProvider { 47 public PackageRenderer() { 48 super(JavaElementLabelProvider.SHOW_PARAMETERS | JavaElementLabelProvider.SHOW_POST_QUALIFIED | JavaElementLabelProvider.SHOW_ROOT); 49 } 50 51 public Image getImage(Object element) { 52 return super.getImage(((IType) element).getPackageFragment()); 53 } 54 55 public String getText(Object element) { 56 return super.getText(((IType) element).getPackageFragment()); 57 } 58 } 59 60 public AppletSelectionDialog(Shell shell, IRunnableContext context, IJavaProject project) { 61 super(shell, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_BASICS | JavaElementLabelProvider.SHOW_OVERLAY_ICONS), new PackageRenderer()); 62 63 Assert.isNotNull(context); 64 65 fRunnableContext = context; 66 fProject = project; 67 } 68 69 72 protected void configureShell(Shell newShell) { 73 super.configureShell(newShell); 74 } 75 76 79 public int open() { 80 IType[] types = getAppletTypes(); 81 if (types == null) { 82 return CANCEL; 83 } 84 setElements(types); 85 return super.open(); 86 } 87 88 93 private IType[] getAppletTypes() { 94 final IJavaProject[] javaProjects; 97 if (fProject == null) { 98 try { 99 javaProjects = getJavaModel().getJavaProjects(); 100 } catch (JavaModelException jme) { 101 return EMPTY_TYPE_ARRAY; 102 } 103 } else { 104 javaProjects = new IJavaProject[] {fProject}; 105 } 106 107 final int projectCount = javaProjects.length; 110 final Set results = new HashSet (projectCount); 111 boolean canceled = false; 112 try { 113 fRunnableContext.run(true, true, new IRunnableWithProgress() { 114 public void run(IProgressMonitor monitor) { 115 monitor.beginTask(LauncherMessages.AppletSelectionDialog_Searching____1, projectCount); 116 for (int i = 0; i < projectCount; i++) { 117 IJavaProject javaProject = javaProjects[i]; 118 SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1); 119 results.addAll(AppletLaunchConfigurationUtils.collectAppletTypesInProject(subMonitor, javaProject)); 120 monitor.worked(1); 121 } 122 monitor.done(); 123 } 124 }); 125 } catch (InvocationTargetException ite) { 126 } catch (InterruptedException ie) { 127 canceled = true; 128 } 129 130 if (canceled) { 132 return null; 133 } 134 IType[] types = null; 135 types = (IType[]) results.toArray(new IType[results.size()]); 136 return types; 137 } 138 139 142 public Control createDialogArea(Composite parent) { 143 Control control = super.createDialogArea(parent); 144 applyDialogFont(control); 145 return control; 146 } 147 148 151 private IJavaModel getJavaModel() { 152 return JavaCore.create(getWorkspaceRoot()); 153 } 154 155 158 private IWorkspaceRoot getWorkspaceRoot() { 159 return ResourcesPlugin.getWorkspace().getRoot(); 160 } 161 162 } 163 | Popular Tags |