| /******************************************************************************* |
| * Copyright (c) 2000, 2005 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.debug.internal.ui.actions; |
| |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.debug.core.model.ISuspendResume; |
| import org.eclipse.debug.ui.IDebugUIConstants; |
| import org.eclipse.debug.ui.actions.*; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.ui.ISelectionListener; |
| import org.eclipse.ui.IWorkbenchPart; |
| import org.eclipse.ui.IWorkbenchWindow; |
| |
| /** |
| * Global retargettable run to line action. |
| * |
| * @since 3.0 |
| */ |
| public class RetargetRunToLineAction extends RetargetAction { |
| |
| private ISelectionListener selectionListener = new DebugSelectionListener(); |
| private ISuspendResume targetElement = null; |
| |
| class DebugSelectionListener implements ISelectionListener { |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) |
| */ |
| public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
| targetElement = null; |
| if (selection instanceof IStructuredSelection) { |
| IStructuredSelection ss = (IStructuredSelection) selection; |
| if (ss.size() == 1) { |
| Object object = ss.getFirstElement(); |
| if (object instanceof ISuspendResume) { |
| targetElement = (ISuspendResume) object; |
| } |
| } |
| } |
| update(); |
| } |
| |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() |
| */ |
| public void dispose() { |
| fWindow.getSelectionService().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, selectionListener); |
| super.dispose(); |
| } |
| /* (non-Javadoc) |
| * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) |
| */ |
| public void init(IWorkbenchWindow window) { |
| super.init(window); |
| window.getSelectionService().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, selectionListener); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.debug.internal.ui.actions.RetargetAction#canPerformAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart) |
| */ |
| protected boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part) { |
| return targetElement != null && |
| ((IRunToLineTarget)target).canRunToLine(part, selection, targetElement); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getAdapterClass() |
| */ |
| protected Class getAdapterClass() { |
| return IRunToLineTarget.class; |
| } |
| /* (non-Javadoc) |
| * @see org.eclipse.debug.internal.ui.actions.RetargetAction#performAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart) |
| */ |
| protected void performAction(Object target, ISelection selection, IWorkbenchPart part) throws CoreException { |
| ((IRunToLineTarget)target).runToLine(part, selection, targetElement); |
| } |
| } |