KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > launcher > JREResolution


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.launcher;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
18 import org.eclipse.jdt.internal.debug.ui.jres.JREsLabelProvider;
19 import org.eclipse.jdt.launching.IVMInstall;
20 import org.eclipse.jdt.launching.IVMInstallType;
21 import org.eclipse.jdt.launching.JavaRuntime;
22 import org.eclipse.ui.IMarkerResolution;
23 import org.eclipse.ui.dialogs.ElementListSelectionDialog;
24
25 /**
26  * Superclass of for JRE resolution errors.
27  */

28 public abstract class JREResolution implements IMarkerResolution {
29     
30     /**
31      * Prompts the user to choose a JRE for the given project.
32      * Returns the selected VM or <code>null</code>.
33      *
34      * @param title the title for the dialog
35      * @param message the message for the dialog
36      * @return selected VM or <code>null</code>
37      */

38     protected IVMInstall chooseVMInstall(String JavaDoc title, String JavaDoc message) {
39         ElementListSelectionDialog dialog = new ElementListSelectionDialog(JDIDebugUIPlugin.getActiveWorkbenchShell(), new JREsLabelProvider());
40         dialog.setElements(getAllVMs());
41         dialog.setTitle(title);
42         dialog.setMessage(message);
43         dialog.setMultipleSelection(false);
44         dialog.open();
45         return (IVMInstall)dialog.getFirstResult();
46     }
47     
48     /**
49      * Returns all defined VMs
50      *
51      * @return IVMInstall[]
52      */

53     protected static IVMInstall[] getAllVMs() {
54         IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
55         List JavaDoc vms = new ArrayList JavaDoc();
56         for (int i = 0; i < types.length; i++) {
57             IVMInstallType type = types[i];
58             IVMInstall[] installs = type.getVMInstalls();
59             for (int j = 0; j < installs.length; j++) {
60                 vms.add(installs[j]);
61             }
62         }
63         return (IVMInstall[])vms.toArray(new IVMInstall[vms.size()]);
64     }
65
66 }
67
Popular Tags