KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > variables > RemoteVariableContentManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.debug.internal.ui.views.variables;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.debug.core.model.IVariable;
17 import org.eclipse.debug.internal.ui.elements.adapters.DeferredVariableLogicalStructure;
18 import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager;
19 import org.eclipse.debug.internal.ui.views.RemoteTreeViewer;
20 import org.eclipse.jface.viewers.ITreeContentProvider;
21 import org.eclipse.ui.IWorkbenchPartSite;
22 import org.eclipse.ui.internal.progress.PendingUpdateAdapter;
23 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
24 import org.eclipse.ui.progress.IElementCollector;
25
26 /**
27  * Remote content manager for variables. Creates an appropriate adapter for
28  * logical structures.
29  */

30 public class RemoteVariableContentManager extends RemoteTreeContentManager {
31
32     protected VariablesView fView;
33     private IDeferredWorkbenchAdapter fVariableLogicalStructureAdapter = new DeferredVariableLogicalStructure();
34     
35     private Set JavaDoc fHasChildren = new HashSet JavaDoc();
36     private Set JavaDoc fNoChildren = new HashSet JavaDoc();
37     
38     /**
39      * Special collector to also collect accurate "has children" information.
40      */

41     public class VariableCollector extends RemoteTreeContentManager.Collector {
42
43         public VariableCollector(Object JavaDoc parent) {
44             super(parent);
45         }
46         
47         /**
48          * Notification the given element has children
49          *
50          * @param element
51          */

52         public void setHasChildren(Object JavaDoc element, boolean children) {
53             synchronized (fHasChildren) {
54                 if (children) {
55                     fHasChildren.add(element);
56                     fNoChildren.remove(element);
57                 } else {
58                     fNoChildren.add(element);
59                     fHasChildren.remove(element);
60                 }
61             }
62         }
63
64     }
65     
66     /**
67      * Constructs a remote content manager for a variables view.
68      */

69     public RemoteVariableContentManager(ITreeContentProvider provider, RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) {
70         super(provider, viewer, site);
71         fView = view;
72     }
73
74     /* (non-Javadoc)
75      * @see org.eclipse.ui.progress.DeferredTreeContentManager#getAdapter(java.lang.Object)
76      */

77     protected IDeferredWorkbenchAdapter getAdapter(Object JavaDoc element) {
78         if (element instanceof IVariable && fView !=null && fView.isShowLogicalStructure()) {
79             return fVariableLogicalStructureAdapter;
80         }
81         return super.getAdapter(element);
82     }
83     
84     /* (non-Javadoc)
85      * @see org.eclipse.ui.progress.DeferredTreeContentManager#createElementCollector(java.lang.Object, org.eclipse.ui.internal.progress.PendingUpdateAdapter)
86      */

87     protected IElementCollector createElementCollector(Object JavaDoc parent, PendingUpdateAdapter placeholder) {
88         return new VariableCollector(parent);
89     }
90
91     /* (non-Javadoc)
92      * @see org.eclipse.ui.progress.DeferredTreeContentManager#mayHaveChildren(java.lang.Object)
93      */

94     public boolean mayHaveChildren(Object JavaDoc element) {
95         synchronized (fHasChildren) {
96             if (fHasChildren.contains(element)) {
97                 return true;
98             } else if (fNoChildren.contains(element)) {
99                 return false;
100             }
101         }
102         return super.mayHaveChildren(element);
103     }
104     
105     /**
106      * Called to clear the "has children" state cache when the view input changes.
107      */

108     public void clearHasChildrenCache() {
109         synchronized (fHasChildren) {
110             fHasChildren.clear();
111             fNoChildren.clear();
112         }
113     }
114 }
115
Popular Tags