2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.eclipse.org/org/documents/epl-v10.php
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.ide.eclipse.adt.internal.launch;
19 import org.eclipse.core.resources.IProject;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.runtime.IAdaptable;
22 import org.eclipse.debug.core.ILaunchConfiguration;
23 import org.eclipse.debug.ui.DebugUITools;
24 import org.eclipse.debug.ui.ILaunchShortcut;
25 import org.eclipse.jface.viewers.ISelection;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27 import org.eclipse.ui.IEditorPart;
30 * Launch shortcut to launch debug/run configuration directly.
32 public class LaunchShortcut implements ILaunchShortcut {
36 * @see org.eclipse.debug.ui.ILaunchShortcut#launch(
37 * org.eclipse.jface.viewers.ISelection, java.lang.String)
39 public void launch(ISelection selection, String mode) {
40 if (selection instanceof IStructuredSelection) {
42 // get the object and the project from it
43 IStructuredSelection structSelect = (IStructuredSelection)selection;
44 Object o = structSelect.getFirstElement();
46 // get the first (and normally only) element
47 if (o instanceof IAdaptable) {
48 IResource r = (IResource)((IAdaptable)o).getAdapter(IResource.class);
50 // get the project from the resource
52 IProject project = r.getProject();
54 if (project != null) {
56 launch(project, mode);
64 * @see org.eclipse.debug.ui.ILaunchShortcut#launch(
65 * org.eclipse.ui.IEditorPart, java.lang.String)
67 public void launch(IEditorPart editor, String mode) {
68 // since we force the shortcut to only work on selection in the
69 // package explorer, this will never be called.
74 * Launch a config for the specified project.
75 * @param project The project to launch
76 * @param mode The launch mode ("debug", "run" or "profile")
78 private void launch(IProject project, String mode) {
79 // get an existing or new launch configuration
80 ILaunchConfiguration config = AndroidLaunchController.getLaunchConfig(project);
84 DebugUITools.launch(config, mode);