Commit | Line | Data |
---|---|---|
be222f56 PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2010 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Yuriy Vashchuk - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.filter; | |
14 | ||
15 | import java.util.ArrayList; | |
16 | ||
17 | import org.eclipse.jface.viewers.ITreeContentProvider; | |
18 | import org.eclipse.jface.viewers.Viewer; | |
19 | import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode; | |
20 | ||
21 | /** | |
22 | * This is the Content Provider of our tree | |
23 | * | |
24 | * @version 1.0 | |
25 | * @author Yuriy Vashchuk | |
26 | */ | |
27 | public class FilterTreeContentProvider implements ITreeContentProvider { | |
28 | ||
29 | /* | |
30 | * (non-Javadoc) | |
31 | * @see org.eclipse.jface.viewers.IContentProvider#dispose() | |
32 | */ | |
33 | @Override | |
34 | public void dispose() { | |
35 | // TODO Auto-generated method stub | |
36 | } | |
37 | ||
38 | /* | |
39 | * (non-Javadoc) | |
40 | * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) | |
41 | */ | |
42 | @Override | |
43 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
44 | // TODO Auto-generated method stub | |
45 | } | |
46 | ||
47 | /* | |
48 | * (non-Javadoc) | |
49 | * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object) | |
50 | */ | |
51 | @Override | |
52 | public Object[] getElements(Object inputElement) { | |
53 | if (inputElement instanceof ITmfFilterTreeNode) { | |
54 | ArrayList<ITmfFilterTreeNode> result = new ArrayList<ITmfFilterTreeNode>(); | |
55 | for(int i = 0; i < ((ITmfFilterTreeNode)inputElement).getChildrenCount(); i++) { | |
56 | result.add(((ITmfFilterTreeNode)inputElement).getChild(i)); | |
57 | } | |
58 | ||
59 | return result.toArray(); | |
60 | } | |
61 | return null; | |
62 | } | |
63 | ||
64 | /* | |
65 | * (non-Javadoc) | |
66 | * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) | |
67 | */ | |
68 | @Override | |
69 | public Object[] getChildren(Object parentElement) { | |
70 | ArrayList<ITmfFilterTreeNode> result = new ArrayList<ITmfFilterTreeNode>(); | |
71 | for(int i = 0; i < ((ITmfFilterTreeNode)parentElement).getChildrenCount(); i++) { | |
72 | result.add(((ITmfFilterTreeNode)parentElement).getChild(i)); | |
73 | } | |
74 | return result.toArray(); | |
75 | } | |
76 | ||
77 | /* | |
78 | * (non-Javadoc) | |
79 | * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) | |
80 | */ | |
81 | @Override | |
82 | public Object getParent(Object element) { | |
83 | return ((ITmfFilterTreeNode) element).getParent(); | |
84 | } | |
85 | ||
86 | /* | |
87 | * (non-Javadoc) | |
88 | * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) | |
89 | */ | |
90 | @Override | |
91 | public boolean hasChildren(Object element) { | |
92 | return ((ITmfFilterTreeNode) element).hasChildren(); | |
93 | } | |
94 | ||
95 | } |