Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b7e5570006ef082456f4d0db227f94efd6b9e2d7 (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
/*******************************************************************************
 * Copyright (c) 2000, 2011 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.views.breakpoints;

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.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugModelPresentation;
import org.eclipse.jface.viewers.IFontProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.model.WorkbenchLabelProvider;

/**
 * Label provider for the breakpoints view
 */
public class BreakpointsLabelProvider extends LabelProvider implements IFontProvider {

    private WorkbenchLabelProvider fWorkbenchLabelProvider;
    private IDebugModelPresentation fPresentation;
    
    /**
     * Constructs a new label provide for the breakpoints view.
     */
    public BreakpointsLabelProvider() {
        fWorkbenchLabelProvider = new WorkbenchLabelProvider();
        fPresentation = DebugUITools.newDebugModelPresentation();
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
     */
    public void dispose() {
        fWorkbenchLabelProvider.dispose();
        fPresentation.dispose();
        super.dispose();
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
     */
    public Image getImage(Object element) {
        if (element instanceof IBreakpoint) {
            return fPresentation.getImage(element);
        }
        Image image = fWorkbenchLabelProvider.getImage(element);
        if (image != null) {
            int flags= computeAdornmentFlags();
            if (flags > 0) {
                CompositeDebugImageDescriptor descriptor= new CompositeDebugImageDescriptor(image, flags);
                return DebugUIPlugin.getImageDescriptorRegistry().get(descriptor);
            }
        }
        return image;        
    }
    
	/**
     * 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;
    }    
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
     */
    public String getText(Object element) {
        if (element instanceof IBreakpoint) {
            return fPresentation.getText(element);
        }
        return fWorkbenchLabelProvider.getText(element);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
     */
    public Font getFont(Object element) {
        if (element instanceof IBreakpoint) {
            return null;
        }
        return fWorkbenchLabelProvider.getFont(element);
    }
    
    /**
     * Returns the debug model presentation used by this label provider.
     * 
     * @return the debug model presentation used by this label provider
     */
    public IDebugModelPresentation getPresentation() {
        return fPresentation;
    }
}

Back to the top