Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: be2005ce348069ea18a286aa09afaafac667e93b (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.views.breakpoints;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointOrganizer;
import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages;
import org.eclipse.debug.ui.IBreakpointOrganizerDelegate;
import org.eclipse.debug.ui.IBreakpointOrganizerDelegateExtension;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.IPropertyChangeListener;

/**
 * A contributed breakpoint organizer.
 */
public class BreakpointOrganizerExtension implements IBreakpointOrganizer, IBreakpointOrganizerDelegateExtension {

	private IConfigurationElement fElement;
	private IBreakpointOrganizerDelegate fDelegate;
	private ImageDescriptor fDescriptor;

	// attributes
	public static final String ATTR_LABEL = "label"; //$NON-NLS-1$
	public static final String ATTR_CLASS = "class"; //$NON-NLS-1$
	public static final String ATTR_ID = "id"; //$NON-NLS-1$
	public static final String ATTR_ICON = "icon"; //$NON-NLS-1$
    public static final String ATTR_OTHERS_LABEL = "othersLabel"; //$NON-NLS-1$

	public BreakpointOrganizerExtension(IConfigurationElement element) {
		fElement = element;
	}

	/**
	 * Returns the image descriptor for this organizer.
	 *
	 * @return image descriptor
	 */
	@Override
	public ImageDescriptor getImageDescriptor() {
		if (fDescriptor == null) {
			fDescriptor = DebugUIPlugin.getImageDescriptor(fElement, ATTR_ICON);
			if (fDescriptor == null) {
				fDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
		}
		return fDescriptor;
	}

	/**
	 * Returns this organizer's label.
	 *
	 * @return this organizer's label
	 */
	@Override
	public String getLabel() {
		return fElement.getAttribute(ATTR_LABEL);
	}

    /**
     * Returns this organizer's identifier.
     *
     * @return this organizer's identifier
     */
    @Override
	public String getIdentifier() {
        return fElement.getAttribute(ATTR_ID);
    }

	/**
	 * Returns this organizer's delegate, instantiating it if required.
	 *
	 * @return this organizer's delegate
	 */
	protected IBreakpointOrganizerDelegate getOrganizer() {
		if (fDelegate == null) {
			try {
				fDelegate = (IBreakpointOrganizerDelegate) fElement.createExecutableExtension(ATTR_CLASS);
			} catch (CoreException e) {
				DebugUIPlugin.log(e);
			}
		}
		return fDelegate;
	}

    @Override
	public IAdaptable[] getCategories(IBreakpoint breakpoint) {
        return getOrganizer().getCategories(breakpoint);
    }

    @Override
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
        getOrganizer().addPropertyChangeListener(listener);
    }

    @Override
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
        getOrganizer().removePropertyChangeListener(listener);
    }

    @Override
	public void addBreakpoint(IBreakpoint breakpoint, IAdaptable category) {
        getOrganizer().addBreakpoint(breakpoint, category);
    }

    @Override
	public void removeBreakpoint(IBreakpoint breakpoint, IAdaptable category) {
        getOrganizer().removeBreakpoint(breakpoint, category);
    }

    @Override
	public boolean canAdd(IBreakpoint breakpoint, IAdaptable category) {
        return getOrganizer().canAdd(breakpoint, category);
    }

    @Override
	public boolean canRemove(IBreakpoint breakpoint, IAdaptable category) {
        return getOrganizer().canRemove(breakpoint, category);
    }

    @Override
	public void dispose() {
    	// don't instantiate the delegate if it has not been used
    	if (fDelegate != null) {
    		fDelegate.dispose();
    	}
    }

    @Override
	public String getOthersLabel() {
        String attribute = fElement.getAttribute(ATTR_OTHERS_LABEL);
        if (attribute == null) {
            return DebugUIViewsMessages.OtherBreakpointOrganizer_0;
        }
        return attribute;
    }

    @Override
	public IAdaptable[] getCategories() {
        return getOrganizer().getCategories();
    }

	@Override
	public void addBreakpoints(IBreakpoint[] breakpoints, IAdaptable category) {
		IBreakpointOrganizerDelegate organizer = getOrganizer();
		if (organizer instanceof IBreakpointOrganizerDelegateExtension) {
			((IBreakpointOrganizerDelegateExtension)organizer).addBreakpoints(breakpoints, category);
		} else {
			for (int i = 0; i < breakpoints.length; i++) {
				addBreakpoint(breakpoints[i], category);
			}
		}
	}

	@Override
	public void removeBreakpoints(IBreakpoint[] breakpoints, IAdaptable category) {
		IBreakpointOrganizerDelegate organizer = getOrganizer();
		if (organizer instanceof IBreakpointOrganizerDelegateExtension) {
			((IBreakpointOrganizerDelegateExtension)organizer).removeBreakpoints(breakpoints, category);
		} else {
			for (int i = 0; i < breakpoints.length; i++) {
				removeBreakpoint(breakpoints[i], category);
			}
		}

	}
}

Back to the top