Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 14-25
Link Here
|
14 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
15 |
import java.util.List; |
15 |
import java.util.List; |
16 |
|
16 |
|
|
|
17 |
import org.eclipse.swt.widgets.Display; |
18 |
|
17 |
import org.eclipse.core.runtime.IProgressMonitor; |
19 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
|
20 |
import org.eclipse.core.runtime.IStatus; |
18 |
import org.eclipse.core.runtime.OperationCanceledException; |
21 |
import org.eclipse.core.runtime.OperationCanceledException; |
|
|
22 |
import org.eclipse.core.runtime.Status; |
23 |
import org.eclipse.core.runtime.jobs.Job; |
19 |
|
24 |
|
20 |
import org.eclipse.jface.operation.IRunnableContext; |
25 |
import org.eclipse.jface.operation.IRunnableContext; |
21 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
26 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
22 |
|
27 |
|
|
|
28 |
import org.eclipse.ui.progress.IWorkbenchSiteProgressService; |
29 |
|
23 |
import org.eclipse.jdt.core.ElementChangedEvent; |
30 |
import org.eclipse.jdt.core.ElementChangedEvent; |
24 |
import org.eclipse.jdt.core.IClassFile; |
31 |
import org.eclipse.jdt.core.IClassFile; |
25 |
import org.eclipse.jdt.core.ICompilationUnit; |
32 |
import org.eclipse.jdt.core.ICompilationUnit; |
Lines 37-42
Link Here
|
37 |
import org.eclipse.jdt.core.JavaModelException; |
44 |
import org.eclipse.jdt.core.JavaModelException; |
38 |
|
45 |
|
39 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
46 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
|
|
47 |
import org.eclipse.jdt.internal.corext.util.Messages; |
48 |
|
49 |
import org.eclipse.jdt.ui.JavaElementLabels; |
40 |
|
50 |
|
41 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
51 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
42 |
|
52 |
|
Lines 52-59
Link Here
|
52 |
|
62 |
|
53 |
private List fChangeListeners; |
63 |
private List fChangeListeners; |
54 |
|
64 |
|
55 |
public TypeHierarchyLifeCycle() { |
65 |
/** |
|
|
66 |
* The type hierarchy view part. |
67 |
* |
68 |
* @since 3.6 |
69 |
*/ |
70 |
private TypeHierarchyViewPart fTypeHierarchyViewPart; |
71 |
|
72 |
/** |
73 |
* The job that runs in the background to refresh the type hierarchy. |
74 |
* |
75 |
* @since 3.6 |
76 |
*/ |
77 |
private Job fRefreshHierarchyJob; |
78 |
|
79 |
/** |
80 |
* Creates the type hierarchy life cycle. |
81 |
* |
82 |
* @param part the type hierarchy view part |
83 |
* @since 3.6 |
84 |
*/ |
85 |
public TypeHierarchyLifeCycle(TypeHierarchyViewPart part) { |
56 |
this(false); |
86 |
this(false); |
|
|
87 |
fTypeHierarchyViewPart= part; |
88 |
fRefreshHierarchyJob= null; |
57 |
} |
89 |
} |
58 |
|
90 |
|
59 |
public TypeHierarchyLifeCycle(boolean isSuperTypesOnly) { |
91 |
public TypeHierarchyLifeCycle(boolean isSuperTypesOnly) { |
Lines 98-104
Link Here
|
98 |
} |
130 |
} |
99 |
} |
131 |
} |
100 |
|
132 |
|
|
|
133 |
/** |
134 |
* Refreshes the type hierarchy for the java element if it exists. |
135 |
* |
136 |
* @param element the java element for which the type hierarchy is computed |
137 |
* @param context the runnable context |
138 |
* @throws InterruptedException thrown from the <code>OperationCanceledException</code> when the monitor is canceled |
139 |
* @throws InvocationTargetException thrown from the <code>JavaModelException</code> if the java element does not exist or if an exception occurs while accessing its corresponding resource |
140 |
*/ |
101 |
public void ensureRefreshedTypeHierarchy(final IJavaElement element, IRunnableContext context) throws InvocationTargetException, InterruptedException { |
141 |
public void ensureRefreshedTypeHierarchy(final IJavaElement element, IRunnableContext context) throws InvocationTargetException, InterruptedException { |
|
|
142 |
synchronized (this) { |
143 |
if (fRefreshHierarchyJob != null) { |
144 |
fRefreshHierarchyJob.cancel(); |
145 |
try { |
146 |
fRefreshHierarchyJob.join(); |
147 |
} catch (InterruptedException e) { |
148 |
// ignore |
149 |
} finally { |
150 |
fRefreshHierarchyJob= null; |
151 |
} |
152 |
} |
153 |
} |
102 |
if (element == null || !element.exists()) { |
154 |
if (element == null || !element.exists()) { |
103 |
freeHierarchy(); |
155 |
freeHierarchy(); |
104 |
return; |
156 |
return; |
Lines 106-126
Link Here
|
106 |
boolean hierachyCreationNeeded= (fHierarchy == null || !element.equals(fInputElement)); |
158 |
boolean hierachyCreationNeeded= (fHierarchy == null || !element.equals(fInputElement)); |
107 |
|
159 |
|
108 |
if (hierachyCreationNeeded || fHierarchyRefreshNeeded) { |
160 |
if (hierachyCreationNeeded || fHierarchyRefreshNeeded) { |
109 |
|
161 |
if (fTypeHierarchyViewPart == null) { |
110 |
IRunnableWithProgress op= new IRunnableWithProgress() { |
162 |
IRunnableWithProgress op= new IRunnableWithProgress() { |
111 |
public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { |
163 |
public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { |
112 |
try { |
164 |
try { |
113 |
doHierarchyRefresh(element, pm); |
165 |
doHierarchyRefresh(element, pm); |
114 |
} catch (JavaModelException e) { |
166 |
} catch (JavaModelException e) { |
115 |
throw new InvocationTargetException(e); |
167 |
throw new InvocationTargetException(e); |
116 |
} catch (OperationCanceledException e) { |
168 |
} catch (OperationCanceledException e) { |
117 |
throw new InterruptedException(); |
169 |
throw new InterruptedException(); |
|
|
170 |
} |
118 |
} |
171 |
} |
|
|
172 |
}; |
173 |
fHierarchyRefreshNeeded= true; |
174 |
context.run(true, true, op); |
175 |
fHierarchyRefreshNeeded= false; |
176 |
} else { |
177 |
synchronized (this) { |
178 |
final String label= Messages.format(TypeHierarchyMessages.TypeHierarchyLifeCycle_computeInput, JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT)); |
179 |
fRefreshHierarchyJob= new Job(label) { |
180 |
/* |
181 |
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) |
182 |
*/ |
183 |
public IStatus run(IProgressMonitor pm) { |
184 |
pm.beginTask(label, LONG); |
185 |
try { |
186 |
doHierarchyRefreshBackground(element, pm); |
187 |
} catch (OperationCanceledException e) { |
188 |
fTypeHierarchyViewPart.setCanceledViewer(); |
189 |
return Status.CANCEL_STATUS; |
190 |
} catch (JavaModelException e) { |
191 |
return e.getStatus(); |
192 |
} finally { |
193 |
fHierarchyRefreshNeeded= false; |
194 |
pm.done(); |
195 |
} |
196 |
return Status.OK_STATUS; |
197 |
} |
198 |
}; |
199 |
fRefreshHierarchyJob.setUser(true); |
200 |
IWorkbenchSiteProgressService progressService = (IWorkbenchSiteProgressService) fTypeHierarchyViewPart.getSite() |
201 |
.getAdapter(IWorkbenchSiteProgressService.class); |
202 |
progressService.schedule(fRefreshHierarchyJob, 0); |
119 |
} |
203 |
} |
120 |
}; |
204 |
} |
121 |
fHierarchyRefreshNeeded= true; |
205 |
} |
122 |
context.run(true, true, op); |
206 |
} |
123 |
fHierarchyRefreshNeeded= false; |
207 |
|
|
|
208 |
/** |
209 |
* Refreshes the hierarchy in the background and updates the hierarchy viewer asynchronously in the UI thread. |
210 |
* |
211 |
* @param element the java element on which the hierarchy is computed |
212 |
* @param pm the progress monitor |
213 |
* @throws JavaModelException if the java element does not exist or if an exception occurs while accessing its corresponding resource. |
214 |
* @since 3.6 |
215 |
*/ |
216 |
protected void doHierarchyRefreshBackground(final IJavaElement element, final IProgressMonitor pm) throws JavaModelException { |
217 |
doHierarchyRefresh(element, pm); |
218 |
if (!pm.isCanceled()) { |
219 |
Display.getDefault().asyncExec(new Runnable() { |
220 |
/* |
221 |
* @see java.lang.Runnable#run() |
222 |
*/ |
223 |
public void run() { |
224 |
fTypeHierarchyViewPart.setViewersInput(); |
225 |
fTypeHierarchyViewPart.updateHierarchyViewer(true); |
226 |
} |
227 |
}); |
124 |
} |
228 |
} |
125 |
} |
229 |
} |
126 |
|
230 |
|
Lines 176-181
Link Here
|
176 |
fInputElement= element; |
280 |
fInputElement= element; |
177 |
} else { |
281 |
} else { |
178 |
fHierarchy.refresh(pm); |
282 |
fHierarchy.refresh(pm); |
|
|
283 |
if (pm != null && pm.isCanceled()) |
284 |
throw new OperationCanceledException(); |
179 |
} |
285 |
} |
180 |
fHierarchy.addTypeHierarchyChangedListener(this); |
286 |
fHierarchy.addTypeHierarchyChangedListener(this); |
181 |
JavaCore.addElementChangedListener(this); |
287 |
JavaCore.addElementChangedListener(this); |