Skip to main content
summaryrefslogtreecommitdiffstats
blob: 46b529f2b86b4b9b48c458ff42dd720ec5dfedda (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
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.views.breakpoints;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IBreakpointManager;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

public class BreakpointsViewContentProvider implements ITreeContentProvider {
	
	private List fBreakpointContainerFactories= new ArrayList();
	
	private Map fParentMap= new HashMap();
	
	public BreakpointsViewContentProvider() {
		fBreakpointContainerFactories.add(BreakpointContainerFactoryManager.getDefault().getFactory("org.eclipse.debug.ui.breakpointTypeContainerFactory"));
		fBreakpointContainerFactories.add(BreakpointContainerFactoryManager.getDefault().getFactory("org.eclipse.debug.ui.breakpointProjectContainerFactory"));
		fBreakpointContainerFactories.add(BreakpointContainerFactoryManager.getDefault().getFactory("org.eclipse.debug.ui.breakpointFileContainerFactory"));
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
	 */
	public Object[] getElements(Object parent) {
		Object children[];
		IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints();
		if (fBreakpointContainerFactories.isEmpty()) {
			children= breakpoints;
		} else if (parent instanceof IBreakpointManager) {
			IBreakpointContainerFactory factory = (IBreakpointContainerFactory) fBreakpointContainerFactories.get(0);
			children= factory.getContainers(breakpoints, "");
		} else if (parent instanceof IBreakpointContainer) {
			IBreakpointContainer container = ((IBreakpointContainer) parent);
			IBreakpointContainerFactory parentFactory = container.getParentFactory();
			int index = fBreakpointContainerFactories.indexOf(parentFactory);
			if (index == -1) {
				children= new Object[0];
			} else if (index == fBreakpointContainerFactories.size() - 1) {
				// last container level
				children= container.getBreakpoints();
			} else {
				IBreakpointContainerFactory nextFactory = (IBreakpointContainerFactory) fBreakpointContainerFactories.get(index + 1);
				children= nextFactory.getContainers(container.getBreakpoints(), getParentId(container));
			}
		} else {
			children= new Object[0];
		}
		for (int i = 0; i < children.length; i++) {
			fParentMap.put(children[i], parent);
		}
		return children;
	}
	
	public String getParentId(IBreakpointContainer container) {
		Object parent= getParent(container);
		if (parent instanceof IBreakpointContainer) {
			return getParentId((IBreakpointContainer) parent) + '.' + container.getName();
		} else if (parent instanceof IBreakpointManager) {
			return container.getName();
		}
		return "";
	}
	
	public void setBreakpointContainerFactories(List factories) {
		Iterator iter = fBreakpointContainerFactories.iterator();
		while (iter.hasNext()) {
			((IBreakpointContainerFactory) iter.next()).dispose();
		}
		fBreakpointContainerFactories= factories;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
	 */
	public void dispose() {
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		fParentMap.clear();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
	 */
	public Object[] getChildren(Object parentElement) {
		return getElements(parentElement);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
	 */
	public Object getParent(Object element) {
		return fParentMap.get(element);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
	 */
	public boolean hasChildren(Object element) {
		return element instanceof IBreakpointContainer;
	}
}

Back to the top