]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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.swt.widgets.Display; | |
15 | ||
16 | import org.eclipse.core.runtime.IProgressMonitor; | |
17 | import org.eclipse.core.runtime.OperationCanceledException; | |
18 | import org.eclipse.core.runtime.jobs.ISchedulingRule; | |
19 | ||
20 | import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; | |
21 | import org.eclipse.ui.progress.IElementCollector; | |
22 | ||
23 | import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper; | |
24 | ||
25 | import org.eclipse.jdt.internal.ui.JavaPlugin; | |
26 | ||
27 | public class DeferredMethodWrapper extends MethodWrapperWorkbenchAdapter implements IDeferredWorkbenchAdapter { | |
28 | private final CallHierarchyContentProvider fProvider; | |
29 | ||
30 | /** | |
31 | * A simple job scheduling rule for serializing jobs that shouldn't be run | |
32 | * concurrently. | |
33 | */ | |
34 | private class BatchSimilarSchedulingRule implements ISchedulingRule { | |
35 | public String id; | |
36 | ||
37 | public BatchSimilarSchedulingRule(String id) { | |
38 | this.id = id; | |
39 | } | |
40 | ||
41 | /* | |
42 | * @see org.eclipse.core.runtime.jobs.ISchedulingRule#isConflicting(org.eclipse.core.runtime.jobs.ISchedulingRule) | |
43 | */ | |
44 | public boolean isConflicting(ISchedulingRule rule) { | |
45 | if (rule instanceof BatchSimilarSchedulingRule) { | |
46 | return ((BatchSimilarSchedulingRule) rule).id.equals(id); | |
47 | } | |
48 | return false; | |
49 | } | |
50 | ||
51 | /* | |
52 | * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule) | |
53 | */ | |
54 | public boolean contains(ISchedulingRule rule) { | |
55 | return this == rule; | |
56 | } | |
57 | } | |
58 | ||
59 | DeferredMethodWrapper(CallHierarchyContentProvider provider, MethodWrapper methodWrapper) { | |
60 | super(methodWrapper); | |
61 | this.fProvider = provider; | |
62 | } | |
63 | ||
64 | private Object getCalls(IProgressMonitor monitor) { | |
65 | return getMethodWrapper().getCalls(monitor); | |
66 | } | |
67 | ||
68 | /* | |
69 | * (non-Javadoc) | |
70 | * | |
71 | * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object, | |
72 | * org.eclipse.jface.progress.IElementCollector, | |
73 | * org.eclipse.core.runtime.IProgressMonitor) | |
74 | */ | |
75 | public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) { | |
76 | final DeferredMethodWrapper deferredMethodWrapper= (DeferredMethodWrapper)object; | |
77 | try { | |
78 | fProvider.startFetching(); | |
79 | collector.add((Object[]) deferredMethodWrapper.getCalls(monitor), monitor); | |
80 | collector.done(); | |
81 | } catch (OperationCanceledException e) { | |
82 | final MethodWrapper methodWrapper= deferredMethodWrapper.getMethodWrapper(); | |
83 | if (!CallHierarchyContentProvider.isExpandWithConstructors(methodWrapper)) { | |
84 | Display.getDefault().asyncExec(new Runnable(){ | |
85 | public void run(){ | |
86 | CallHierarchyViewPart viewPart= fProvider.getViewPart(); | |
87 | if (viewPart != null && !viewPart.getViewer().getControl().isDisposed()) | |
88 | fProvider.collapseAndRefresh(methodWrapper); | |
89 | } | |
90 | }); | |
91 | } | |
92 | } catch (Exception e) { | |
93 | JavaPlugin.log(e); | |
94 | } finally { | |
95 | fProvider.doneFetching(); | |
96 | } | |
97 | } | |
98 | ||
99 | /* | |
100 | * (non-Javadoc) | |
101 | * | |
102 | * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#isContainer() | |
103 | */ | |
104 | public boolean isContainer() { | |
105 | return true; | |
106 | } | |
107 | ||
108 | /* | |
109 | * (non-Javadoc) | |
110 | * | |
111 | * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#getRule() | |
112 | */ | |
113 | public ISchedulingRule getRule(Object o) { | |
114 | return new BatchSimilarSchedulingRule("org.eclipse.jdt.ui.callhierarchy.methodwrapper"); //$NON-NLS-1$ | |
115 | } | |
116 | ||
117 | /* | |
118 | * (non-Javadoc) | |
119 | * | |
120 | * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) | |
121 | */ | |
122 | @Override | |
123 | public Object[] getChildren(Object o) { | |
124 | return this.fProvider.fetchChildren(((DeferredMethodWrapper) o).getMethodWrapper()); | |
125 | } | |
126 | ||
127 | } |