KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > viewers > model > HasChildrenUpdate


1 /*******************************************************************************
2  * Copyright (c) 2006, 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.model;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider;
17 import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate;
18 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
19 import org.eclipse.jface.viewers.TreePath;
20 import org.eclipse.jface.viewers.TreeViewer;
21
22 /**
23  * @since 3.3
24  */

25 class HasChildrenUpdate extends ViewerUpdateMonitor implements IHasChildrenUpdate {
26
27     private boolean fHasChildren = false;
28     
29     private List JavaDoc fBatchedRequests = null;
30     
31     /**
32      * @param contentProvider
33      */

34     public HasChildrenUpdate(ModelContentProvider contentProvider, TreePath elementPath, Object JavaDoc element, IElementContentProvider elementContentProvider, IPresentationContext context) {
35         super(contentProvider, elementPath, element, elementContentProvider, context);
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.debug.internal.ui.viewers.model.provisional.viewers.ViewerUpdateMonitor#performUpdate()
40      */

41     protected void performUpdate() {
42         ModelContentProvider contentProvider = getContentProvider();
43         TreePath elementPath = getElementPath();
44         if (!fHasChildren) {
45             contentProvider.clearFilters(elementPath);
46         }
47         if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) {
48             System.out.println("setHasChildren(" + getElement() + " >> " + fHasChildren); //$NON-NLS-1$ //$NON-NLS-2$
49
}
50         ((TreeViewer)(contentProvider.getViewer())).setHasChildren(elementPath, fHasChildren);
51         if (elementPath.getSegmentCount() > 0) {
52             contentProvider.doRestore(elementPath);
53         }
54     }
55
56     public void setHasChilren(boolean hasChildren) {
57         fHasChildren = hasChildren;
58     }
59
60     public String JavaDoc toString() {
61         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
62         buf.append("IHasChildrenUpdate: "); //$NON-NLS-1$
63
buf.append(getElement());
64         return buf.toString();
65     }
66     
67     /* (non-Javadoc)
68      * @see org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor#coalesce(org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor)
69      */

70     boolean coalesce(ViewerUpdateMonitor request) {
71         if (request instanceof HasChildrenUpdate) {
72             if (getElementPath().equals(request.getElementPath())) {
73                 // duplicate request
74
return true;
75             } else if (getElementContentProvider().equals(request.getElementContentProvider())) {
76                 if (fBatchedRequests == null) {
77                     fBatchedRequests = new ArrayList JavaDoc();
78                     fBatchedRequests.add(this);
79                 }
80                 fBatchedRequests.add(request);
81                 return true;
82             }
83         }
84         return false;
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor#startRequest()
89      */

90     void startRequest() {
91         if (fBatchedRequests == null) {
92             getElementContentProvider().update(new IHasChildrenUpdate[]{this});
93         } else {
94             IHasChildrenUpdate[] updates = (IHasChildrenUpdate[]) fBatchedRequests.toArray(new IHasChildrenUpdate[fBatchedRequests.size()]);
95             // notify that the other updates have also started to ensure correct sequence
96
// of model updates - **** start at index 1 since the first (0) update has
97
// already notified the content provider that it has started.
98
for (int i = 1; i < updates.length; i++) {
99                 getContentProvider().updateStarted((ViewerUpdateMonitor) updates[i]);
100             }
101             getElementContentProvider().update(updates);
102         }
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor#getPriority()
107      */

108     int getPriority() {
109         return 1;
110     }
111     
112     /* (non-Javadoc)
113      * @see org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor#getSchedulingPath()
114      */

115     TreePath getSchedulingPath() {
116         TreePath path = getElementPath();
117         if (path.getSegmentCount() > 0) {
118             return path.getParentPath();
119         }
120         return path;
121     }
122 }
123
Popular Tags