Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d19b878a562e90b846574eca7551306db7c96c17 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*****************************************************************
 * Copyright (c) 2009, 2011 Texas Instruments and others
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Patrick Chuong (Texas Instruments) - Initial API and implementation (Bug 238956)
 *****************************************************************/
package org.eclipse.debug.internal.ui.model.elements;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.internal.ui.CompositeDebugImageDescriptor;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointContainer;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.model.IWorkbenchAdapter2;

/**
 * Breakpoint container label provider.
 *
 * @since 3.6
 */
public class BreakpointContainerLabelProvider extends DebugElementLabelProvider {
	@Override
	protected ImageDescriptor getImageDescriptor(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException {
		ImageDescriptor desc = super.getImageDescriptor(elementPath, presentationContext, columnId);
		int flags = computeAdornmentFlags();

		if (flags > 0) {
			Image image = DebugUIPlugin.getImageDescriptorRegistry().get(desc);
			CompositeDebugImageDescriptor compDesc = new CompositeDebugImageDescriptor(image, flags);
			return compDesc;
		}
		return desc;
	}

	@Override
	public boolean getChecked(TreePath path, IPresentationContext presentationContext) throws CoreException {
		Object lastSegment = path.getLastSegment();
		if (lastSegment instanceof IBreakpointContainer) {
			IBreakpointContainer container = (IBreakpointContainer) lastSegment;
			for (IBreakpoint breakpoint : container.getBreakpoints()) {
				if (breakpoint.isEnabled()) {
					return true;
				}
			}

			return false;
		}

		return super.getChecked(path, presentationContext);
	}

	@Override
	public boolean getGrayed(TreePath path, IPresentationContext presentationContext) throws CoreException {
		Object lastSegment = path.getLastSegment();
		if (lastSegment instanceof IBreakpointContainer) {
			IBreakpointContainer container = (IBreakpointContainer) lastSegment;
			
			// Return true, gray if some breakpoints are enabled and some are disabled.
			// return false if all breakpoints are either disabled or all are enabled.
			boolean hasEnabled = false;
			boolean hasDisabled = false;

			for (IBreakpoint breakpoint : container.getBreakpoints()) {
				if (breakpoint.isEnabled()) {
					hasEnabled = true;
				} else {
					hasDisabled = true;
				}

				if (hasEnabled && hasDisabled) {
					return true;
				}
			}

			return false;
		}

		return super.getGrayed(path, presentationContext);
	}

	// Forward font data requests to the workbench adapter
	@Override
	protected FontData getFontData(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException {
		Object element = elementPath.getLastSegment();
		FontData fontData = super.getFontData(elementPath, presentationContext, columnId);
		if (fontData == null && element instanceof IAdaptable) {

			IWorkbenchAdapter2 adapter = ((IAdaptable)element).getAdapter(IWorkbenchAdapter2.class);
			if (adapter != null) {
				fontData = adapter.getFont(element);
			}
		}
		return fontData;
	}

	// Forward foreground color requests to the workbench adapter
	@Override
	protected RGB getForeground(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException {
		Object element = elementPath.getLastSegment();
		RGB rgb = super.getForeground(elementPath, presentationContext, columnId);
		if (rgb == null && element instanceof IAdaptable) {

			IWorkbenchAdapter2 adapter = ((IAdaptable)element).getAdapter(IWorkbenchAdapter2.class);
			if (adapter != null) {
				rgb = adapter.getForeground(element);
			}
		}
		return rgb;
	}

	// Forward background color requests to the workbench adapter
	@Override
	protected RGB getBackground(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException {
		Object element = elementPath.getLastSegment();
		RGB rgb = super.getBackground(elementPath, presentationContext, columnId);
		if (rgb == null && element instanceof IAdaptable) {

			IWorkbenchAdapter2 adapter = ((IAdaptable)element).getAdapter(IWorkbenchAdapter2.class);
			if (adapter != null) {
				rgb = adapter.getBackground(element);
			}
		}
		return rgb;
	}

	/**
	 * Computes and return common adornment flags for the given category.
	 *
	 * @return adornment flags defined in CompositeDebugImageDescriptor
	 */
	private int computeAdornmentFlags() {
		if (!DebugPlugin.getDefault().getBreakpointManager().isEnabled()) {
			return CompositeDebugImageDescriptor.SKIP_BREAKPOINT;
		}
		return 0;
	}
}

Back to the top