Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2aaef065ddb8429d08358fb3c059cc5d31c0031c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
 * Copyright (c) 2000, 2009 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.breakpointGroups;

import java.util.List;

import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointContainer;
import org.eclipse.debug.internal.ui.breakpoints.provisional.OtherBreakpointCategory;
import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.PlatformUI;

/**
 * Standard action for pasting resources on the clipboard to the selected resource's location.
 * <p>
 * This class may be instantiated; it is not intended to be subclassed.
 * </p>
 * 
 * @since 2.0
 */
public class PasteBreakpointsAction extends BreakpointSelectionAction {
    
    /**
     * Creates a new action.
     *
     * @param view the view of this action
     */
    public PasteBreakpointsAction(BreakpointsView view) {
        super(BreakpointGroupMessages.PasteBreakpointsAction_0, view); 
        setToolTipText(BreakpointGroupMessages.PasteBreakpointsAction_1);
        PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.PASTE_BREAKPOINTS_ACTION);
    }

    /**
     * Returns the actual target of the paste action. Returns null
     * if no valid target is selected.
     * 
     * @return the actual target of the paste action
     */
    private Object getTarget() {
        List selectedNonResources = getSelectedNonResources();
        if (selectedNonResources.size() == 1) {
            Object target = selectedNonResources.get(0);
            if (target instanceof IBreakpointContainer) {
                return target;
            }
        }
        return null;
    }

    /**
     * Implementation of method defined on <code>IAction</code>.
     */
    public void run() {
		if (getBreakpointsView().canPaste(getTarget(), LocalSelectionTransfer.getTransfer().getSelection())) {
			getBreakpointsView().performPaste(getTarget(), LocalSelectionTransfer.getTransfer().getSelection());
		}
    }

    /**
     * Returns whether this action should be enabled based on the selection
     * in the clipboard. Only updates when the breakpoints view has focus. 
     */
    protected boolean updateSelection(IStructuredSelection selection) {
        // can't paste into "Others" (only move)
        Object target = getTarget();
        if (target instanceof IBreakpointContainer) {
            IBreakpointContainer container = (IBreakpointContainer) target;
            if (container.getCategory() instanceof OtherBreakpointCategory) {
                return false;
            }
			return true;
        }
		// don't access clipboard - causes Hang -see bug 84870
		return false;
    }
}

Back to the top