KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > viewers > ChildrenRequestMonitor


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.debug.internal.ui.viewers;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.debug.internal.ui.viewers.provisional.IChildrenRequestMonitor;
18
19 /**
20  * Implementation for <code>IChildrenRequestMonitor</code>. Collects
21  * children from an asynchronous tree content adapter.
22  * <p>
23  * Not intended to be subclassed or instantiated by clients. For use
24  * speficially with <code>AsynchronousTreeViewer</code>.
25  * </p>
26  * @since 3.2
27  */

28 class ChildrenRequestMonitor extends AsynchronousRequestMonitor implements IChildrenRequestMonitor {
29     
30     private boolean fFirstUpdate = true;
31     
32     /**
33      * Collection of children retrieved
34      */

35     private List JavaDoc fChildren = new ArrayList JavaDoc();
36
37     /**
38      * Constucts a monitor to retrieve and update the children of the given
39      * node.
40      *
41      * @param parent parent to retrieve children for
42      * @param model model being updated
43      */

44     ChildrenRequestMonitor(ModelNode parent, AsynchronousModel model) {
45         super(parent, model);
46     }
47     
48     /* (non-Javadoc)
49      * @see org.eclipse.debug.ui.viewers.IChildrenRequestMonitor#addChild(java.lang.Object)
50      */

51     public void addChild(Object JavaDoc child) {
52         synchronized (fChildren) {
53             fChildren.add(child);
54         }
55         
56         scheduleViewerUpdate(250);
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.debug.ui.viewers.IChildrenRequestMonitor#addChildren(java.lang.Object[])
61      */

62     public void addChildren(Object JavaDoc[] children) {
63         synchronized (fChildren) {
64             for (int i = 0; i < children.length; i++) {
65                 fChildren.add(children[i]);
66             }
67         }
68         
69         scheduleViewerUpdate(0);
70     }
71     
72     /* (non-Javadoc)
73      * @see org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor#contains(org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor)
74      */

75     protected boolean contains(AsynchronousRequestMonitor update) {
76         return (update instanceof ChildrenRequestMonitor) && contains(update.getNode());
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor#performUpdate()
81      */

82     protected void performUpdate() {
83         synchronized (fChildren) {
84             if (fFirstUpdate) {
85                 getModel().setChildren(getNode(), fChildren);
86                 fFirstUpdate = false;
87             } else {
88                 for (Iterator JavaDoc iter = fChildren.iterator(); iter.hasNext();) {
89                     Object JavaDoc child = iter.next();
90                     getModel().add(getNode(), child);
91                 }
92             }
93             fChildren.clear();
94         }
95     }
96
97 }
98
Popular Tags