Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6a3bfa55b5532c1a5d797fc2b009c488ec4b69c5 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*******************************************************************************
 * Copyright (c) 2000, 2013 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
 *     Freescale Semiconductor - bug 287863
 *     Patrick Chuong (Texas Instruments) - Improve usability of the breakpoint view (Bug 238956)
 *******************************************************************************/
package org.eclipse.debug.internal.ui.actions.breakpointGroups;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointContainer;
import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView;
import org.eclipse.debug.internal.ui.views.breakpoints.WorkingSetCategory;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.TreePath;

/**
 * Removes a breakpoint from a breakpoint working set.
 */
public class RemoveFromWorkingSetAction extends BreakpointSelectionAction {

    private BreakpointSetElement[] fBreakpoints;


	/**
     * Constructs action to remove breakpoints from a category.
     *
     * @param view
     */
    public RemoveFromWorkingSetAction(BreakpointsView view) {
        super(BreakpointGroupMessages.RemoveFromWorkingSetAction_0, view);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.action.IAction#run()
     */
    @Override
	public void run() {
    	if (fBreakpoints != null) {
    		for (int i = 0; i < fBreakpoints.length; i++) {
    			fBreakpoints[i].container.getOrganizer().removeBreakpoint(fBreakpoints[i].breakpoint, fBreakpoints[i].container.getCategory());
    		}
    	}
    }

    protected static class BreakpointSetElement {
    	BreakpointSetElement(IBreakpoint b, IBreakpointContainer c) { breakpoint = b; container = c; }
    	IBreakpoint breakpoint;
    	IBreakpointContainer container;
    }

    /**
     * Returns a array of breakpoint/container pairs for the selection
     *
     *  All the returned elements contain a breakpoint and a working set container the breakpoint is contained and the breakpoint
     *  can be removed from.
     *
     * @param selection
     * @return
     */
    protected BreakpointSetElement[] getRemovableBreakpoints(IStructuredSelection selection) {
		List<BreakpointSetElement> res = new ArrayList<BreakpointSetElement>();
    	if (selection instanceof ITreeSelection) {
    		ITreeSelection tSel = (ITreeSelection)selection;

    		TreePath[] paths = tSel.getPaths();
    		for (int i = 0; i < paths.length; i++) {
    			TreePath path = paths[i];

    			// We can remove Breakpoints from their working set if any of their parents is a non "Other" breakpoint working set
                IBreakpoint breakpoint = (IBreakpoint)DebugPlugin.getAdapter(path.getLastSegment(), IBreakpoint.class);
    			if (breakpoint != null) {
    				TreePath parents = path.getParentPath();

    				for (int j = 0; j < parents.getSegmentCount(); j++) {
    					Object parent = parents.getSegment(j);

    					if (parent instanceof IBreakpointContainer) {
    						IBreakpointContainer container = (IBreakpointContainer)parent;

    						// Test if this is a working set container.
    						if (container.getCategory() instanceof WorkingSetCategory) {
    							// Test if this container allows to remove this breakpoint.
    							if (container.getOrganizer().canRemove(breakpoint, container.getCategory())) {
    								res.add(new BreakpointSetElement(breakpoint, container));
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    	return res.toArray(new BreakpointSetElement[res.size()]);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.action.Action#isEnabled()
     */
    @Override
	public boolean isEnabled() {
    	if(fBreakpoints != null) {
    		return fBreakpoints.length > 0;
    	}
    	return false;
    }

    /* (non-Javadoc)
     * @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
     */
    @Override
	protected boolean updateSelection(IStructuredSelection selection) {
    	fBreakpoints = getRemovableBreakpoints(selection);
    	return fBreakpoints.length > 0;
    }
}

Back to the top