KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > progress > ProgressTreeContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.progress;
12
13 import org.eclipse.jface.viewers.ITreeContentProvider;
14
15 /**
16  * The ProgressTreeContentProvider is the content provider for trees that show
17  * progress.
18  */

19 public class ProgressTreeContentProvider extends ProgressContentProvider
20         implements ITreeContentProvider {
21
22     NewProgressViewer viewer;
23
24     /**
25      * Create an instance of the receiver on the viewer.
26      * @param mainViewer
27      */

28     public ProgressTreeContentProvider(NewProgressViewer mainViewer) {
29         super();
30         viewer = mainViewer;
31     }
32
33     
34     /**
35      * Create a new instance of the receiver with the supplied
36      * viewer and debug flag.
37      * @param mainViewer
38      * @param debug If true do show debug information
39      * @see ProgressContentProvider
40      */

41     public ProgressTreeContentProvider(NewProgressViewer mainViewer,
42             boolean debug) {
43         super(debug);
44         viewer = mainViewer;
45     }
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
51      */

52
53     public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
54         return ((JobTreeElement) parentElement).getChildren();
55     }
56
57     /*
58      * (non-Javadoc)
59      *
60      * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
61      */

62     public Object JavaDoc getParent(Object JavaDoc element) {
63         if (element == this)
64             return null;
65           return ((JobTreeElement) element).getParent();
66     }
67
68     /*
69      * (non-Javadoc)
70      *
71      * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
72      */

73     public boolean hasChildren(Object JavaDoc element) {
74         if (element == this)
75             return ProgressManager.getInstance().hasJobInfos();
76        return ((JobTreeElement) element).hasChildren();
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.ui.internal.progress.IProgressUpdateCollector#add(org.eclipse.ui.internal.progress.JobTreeElement[])
81      */

82     public void add(Object JavaDoc[] elements) {
83         viewer.add(viewer.getInput(), elements);
84
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.ui.internal.progress.IProgressUpdateCollector#refresh()
89      */

90     public void refresh() {
91         viewer.refresh(true);
92
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.ui.internal.progress.IProgressUpdateCollector#refresh(org.eclipse.ui.internal.progress.JobTreeElement[])
97      */

98     public void refresh(Object JavaDoc[] elements) {
99         for (int i = 0; i < elements.length; i++) {
100             viewer.refresh(elements[i], true);
101         }
102
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.ui.internal.progress.IProgressUpdateCollector#remove(org.eclipse.ui.internal.progress.JobTreeElement[])
107      */

108     public void remove(Object JavaDoc[] elements) {
109         viewer.remove(elements);
110
111     }
112
113 }
114
Popular Tags