KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > breakpointGroups > PasteBreakpointsAction


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.debug.internal.ui.actions.breakpointGroups;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
16 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointContainer;
17 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView;
18 import org.eclipse.debug.internal.ui.views.breakpoints.OtherBreakpointCategory;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
22
23 /**
24  * Standard action for pasting resources on the clipboard to the selected resource's location.
25  * <p>
26  * This class may be instantiated; it is not intended to be subclassed.
27  * </p>
28  *
29  * @since 2.0
30  */

31 public class PasteBreakpointsAction extends BreakpointSelectionAction {
32     
33     /**
34      * Creates a new action.
35      *
36      * @param view the view of this action
37      */

38     public PasteBreakpointsAction(BreakpointsView view) {
39         super(BreakpointGroupMessages.PasteBreakpointsAction_0, view);
40         setToolTipText(BreakpointGroupMessages.PasteBreakpointsAction_1);
41         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.PASTE_BREAKPOINTS_ACTION);
42     }
43
44     /**
45      * Returns the actual target of the paste action. Returns null
46      * if no valid target is selected.
47      *
48      * @return the actual target of the paste action
49      */

50     private Object JavaDoc getTarget() {
51         List JavaDoc selectedNonResources = getSelectedNonResources();
52         if (selectedNonResources.size() == 1) {
53             Object JavaDoc target = selectedNonResources.get(0);
54             if (target instanceof BreakpointContainer) {
55                 return target;
56             }
57         }
58         return null;
59     }
60
61     /**
62      * Implementation of method defined on <code>IAction</code>.
63      */

64     public void run() {
65         if (getBreakpointsView().canPaste(getTarget(), LocalSelectionTransfer.getInstance().getSelection())) {
66             getBreakpointsView().performPaste(getTarget(), LocalSelectionTransfer.getInstance().getSelection());
67         }
68     }
69
70     /**
71      * Returns whether this action should be enabled based on the selection
72      * in the clipboard. Only updates when the breakpoints view has focus.
73      */

74     protected boolean updateSelection(IStructuredSelection selection) {
75         // can't paste into "Others" (only move)
76
Object JavaDoc target = getTarget();
77         if (target instanceof BreakpointContainer) {
78             BreakpointContainer container = (BreakpointContainer) target;
79             if (container.getCategory() instanceof OtherBreakpointCategory) {
80                 return false;
81             }
82             return true;
83         }
84         // don't access clipboard - causes Hang -see bug 84870
85
return false;
86     }
87 }
88
Popular Tags