KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > callhierarchy > DeferredMethodWrapper


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  * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10  * (report 36180: Callers/Callees view)
11  *******************************************************************************/

12 package org.eclipse.jdt.internal.ui.callhierarchy;
13
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.OperationCanceledException;
16 import org.eclipse.core.runtime.jobs.ISchedulingRule;
17 import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
18 import org.eclipse.jdt.internal.ui.JavaPlugin;
19 import org.eclipse.ui.progress.IElementCollector;
20 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
21
22 public class DeferredMethodWrapper extends MethodWrapperWorkbenchAdapter implements IDeferredWorkbenchAdapter {
23     private final CallHierarchyContentProvider fProvider;
24
25     /**
26      * A simple job scheduling rule for serializing jobs that shouldn't be run
27      * concurrently.
28      */

29     private class BatchSimilarSchedulingRule implements ISchedulingRule {
30         public String JavaDoc id;
31
32         public BatchSimilarSchedulingRule(String JavaDoc id) {
33             this.id = id;
34         }
35
36         /*
37          * @see org.eclipse.core.runtime.jobs.ISchedulingRule#isConflicting(org.eclipse.core.runtime.jobs.ISchedulingRule)
38          */

39         public boolean isConflicting(ISchedulingRule rule) {
40             if (rule instanceof BatchSimilarSchedulingRule) {
41                 return ((BatchSimilarSchedulingRule) rule).id.equals(id);
42             }
43             return false;
44         }
45
46         /*
47          * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule)
48          */

49         public boolean contains(ISchedulingRule rule) {
50             return this == rule;
51         }
52     }
53
54     DeferredMethodWrapper(CallHierarchyContentProvider provider, MethodWrapper methodWrapper) {
55         super(methodWrapper);
56         this.fProvider = provider;
57     }
58
59     private Object JavaDoc getCalls(IProgressMonitor monitor) {
60         return getMethodWrapper().getCalls(monitor);
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object,
67      * org.eclipse.jface.progress.IElementCollector,
68      * org.eclipse.core.runtime.IProgressMonitor)
69      */

70     public void fetchDeferredChildren(Object JavaDoc object, IElementCollector collector, IProgressMonitor monitor) {
71         try {
72             fProvider.startFetching();
73             DeferredMethodWrapper methodWrapper = (DeferredMethodWrapper) object;
74             collector.add((Object JavaDoc[]) methodWrapper.getCalls(monitor), monitor);
75             collector.done();
76         } catch (OperationCanceledException e) {
77             collector.add(new Object JavaDoc[] { TreeTermination.SEARCH_CANCELED }, monitor);
78         } catch (Exception JavaDoc e) {
79             JavaPlugin.log(e);
80         } finally {
81             fProvider.doneFetching();
82         }
83     }
84
85     /*
86      * (non-Javadoc)
87      *
88      * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#isContainer()
89      */

90     public boolean isContainer() {
91         return true;
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#getRule()
98      */

99     public ISchedulingRule getRule(Object JavaDoc o) {
100         return new BatchSimilarSchedulingRule("org.eclipse.jdt.ui.callhierarchy.methodwrapper"); //$NON-NLS-1$
101
}
102
103     /*
104      * (non-Javadoc)
105      *
106      * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
107      */

108     public Object JavaDoc[] getChildren(Object JavaDoc o) {
109         return this.fProvider.fetchChildren(((DeferredMethodWrapper) o).getMethodWrapper());
110     }
111
112     /**
113      * Returns an object which is an instance of the given class associated
114      * with this object. Returns <code>null</code> if no such object can be
115      * found.
116      */

117     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
118         if (adapter == IDeferredWorkbenchAdapter.class)
119             return this;
120         return null;
121     }
122 }
123
Popular Tags