|
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-21
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; |
|
Lines 37-42
Link Here
|
| 37 |
import org.eclipse.jdt.core.JavaModelException; |
42 |
import org.eclipse.jdt.core.JavaModelException; |
| 38 |
|
43 |
|
| 39 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
44 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
|
|
45 |
import org.eclipse.jdt.internal.corext.util.Messages; |
| 46 |
|
| 47 |
import org.eclipse.jdt.ui.JavaElementLabels; |
| 40 |
|
48 |
|
| 41 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
49 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
| 42 |
|
50 |
|
|
Lines 52-59
Link Here
|
| 52 |
|
60 |
|
| 53 |
private List fChangeListeners; |
61 |
private List fChangeListeners; |
| 54 |
|
62 |
|
| 55 |
public TypeHierarchyLifeCycle() { |
63 |
/** |
|
|
64 |
* The type hierarchy view part. |
| 65 |
* |
| 66 |
* @since 3.6 |
| 67 |
*/ |
| 68 |
private TypeHierarchyViewPart fTypeHierarchyViewPart; |
| 69 |
|
| 70 |
/** |
| 71 |
* The job that runs in the background to refresh the type hierarchy. |
| 72 |
* |
| 73 |
* @since 3.6 |
| 74 |
*/ |
| 75 |
private Job fRefreshHierarchyJob; |
| 76 |
|
| 77 |
/** |
| 78 |
* Creates the type hierarchy life cycle. |
| 79 |
* |
| 80 |
* @param part the type hierarchy view part |
| 81 |
* @since 3.6 |
| 82 |
*/ |
| 83 |
public TypeHierarchyLifeCycle(TypeHierarchyViewPart part) { |
| 56 |
this(false); |
84 |
this(false); |
|
|
85 |
fTypeHierarchyViewPart= part; |
| 86 |
fRefreshHierarchyJob= null; |
| 57 |
} |
87 |
} |
| 58 |
|
88 |
|
| 59 |
public TypeHierarchyLifeCycle(boolean isSuperTypesOnly) { |
89 |
public TypeHierarchyLifeCycle(boolean isSuperTypesOnly) { |
|
Lines 98-103
Link Here
|
| 98 |
} |
128 |
} |
| 99 |
} |
129 |
} |
| 100 |
|
130 |
|
|
|
131 |
/** |
| 132 |
* Refreshes the type hierarchy for the java element if it exists. |
| 133 |
* |
| 134 |
* @param element the java element for which the type hierarchy is computed |
| 135 |
* @param context the runnable context |
| 136 |
* @throws InterruptedException thrown from the <code>OperationCanceledException</code> when the monitor is canceled |
| 137 |
* @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 |
| 138 |
*/ |
| 101 |
public void ensureRefreshedTypeHierarchy(final IJavaElement element, IRunnableContext context) throws InvocationTargetException, InterruptedException { |
139 |
public void ensureRefreshedTypeHierarchy(final IJavaElement element, IRunnableContext context) throws InvocationTargetException, InterruptedException { |
| 102 |
if (element == null || !element.exists()) { |
140 |
if (element == null || !element.exists()) { |
| 103 |
freeHierarchy(); |
141 |
freeHierarchy(); |
|
Lines 106-126
Link Here
|
| 106 |
boolean hierachyCreationNeeded= (fHierarchy == null || !element.equals(fInputElement)); |
144 |
boolean hierachyCreationNeeded= (fHierarchy == null || !element.equals(fInputElement)); |
| 107 |
|
145 |
|
| 108 |
if (hierachyCreationNeeded || fHierarchyRefreshNeeded) { |
146 |
if (hierachyCreationNeeded || fHierarchyRefreshNeeded) { |
| 109 |
|
147 |
if (fTypeHierarchyViewPart == null) { |
| 110 |
IRunnableWithProgress op= new IRunnableWithProgress() { |
148 |
IRunnableWithProgress op= new IRunnableWithProgress() { |
| 111 |
public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { |
149 |
public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { |
| 112 |
try { |
150 |
try { |
| 113 |
doHierarchyRefresh(element, pm); |
151 |
doHierarchyRefresh(element, pm); |
| 114 |
} catch (JavaModelException e) { |
152 |
} catch (JavaModelException e) { |
| 115 |
throw new InvocationTargetException(e); |
153 |
throw new InvocationTargetException(e); |
| 116 |
} catch (OperationCanceledException e) { |
154 |
} catch (OperationCanceledException e) { |
| 117 |
throw new InterruptedException(); |
155 |
throw new InterruptedException(); |
|
|
156 |
} |
| 118 |
} |
157 |
} |
|
|
158 |
}; |
| 159 |
fHierarchyRefreshNeeded= true; |
| 160 |
context.run(true, true, op); |
| 161 |
fHierarchyRefreshNeeded= false; |
| 162 |
} else { |
| 163 |
synchronized (this) { |
| 164 |
final String label= Messages.format(TypeHierarchyMessages.TypeHierarchyLifeCycle_computeInput, JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT)); |
| 165 |
fRefreshHierarchyJob= new Job(label) { |
| 166 |
/* |
| 167 |
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) |
| 168 |
*/ |
| 169 |
public IStatus run(IProgressMonitor pm) { |
| 170 |
pm.beginTask(label, LONG); |
| 171 |
fTypeHierarchyViewPart.setCancelEnabled(true); |
| 172 |
try { |
| 173 |
doHierarchyRefreshBackground(element, pm); |
| 174 |
} catch (OperationCanceledException e) { |
| 175 |
fTypeHierarchyViewPart.setCanceledViewer(); |
| 176 |
return Status.CANCEL_STATUS; |
| 177 |
} catch (JavaModelException e) { |
| 178 |
return e.getStatus(); |
| 179 |
} finally { |
| 180 |
fTypeHierarchyViewPart.setCancelEnabled(false); |
| 181 |
fHierarchyRefreshNeeded= false; |
| 182 |
pm.done(); |
| 183 |
} |
| 184 |
return Status.OK_STATUS; |
| 185 |
} |
| 186 |
}; |
| 187 |
fRefreshHierarchyJob.schedule(); |
| 119 |
} |
188 |
} |
| 120 |
}; |
189 |
} |
| 121 |
fHierarchyRefreshNeeded= true; |
190 |
} |
| 122 |
context.run(true, true, op); |
191 |
} |
| 123 |
fHierarchyRefreshNeeded= false; |
192 |
|
|
|
193 |
/** |
| 194 |
* Refreshes the hierarchy in the background and updates the hierarchy viewer asynchronously in the UI thread. |
| 195 |
* |
| 196 |
* @param element the java element on which the hierarchy is computed |
| 197 |
* @param pm the progress monitor |
| 198 |
* @throws JavaModelException if the java element does not exist or if an exception occurs while accessing its corresponding resource. |
| 199 |
* @since 3.6 |
| 200 |
*/ |
| 201 |
protected synchronized void doHierarchyRefreshBackground(final IJavaElement element, final IProgressMonitor pm) throws JavaModelException { |
| 202 |
doHierarchyRefresh(element, pm); |
| 203 |
if (!pm.isCanceled()) { |
| 204 |
Display.getDefault().asyncExec(new Runnable() { |
| 205 |
/* |
| 206 |
* @see java.lang.Runnable#run() |
| 207 |
*/ |
| 208 |
public void run() { |
| 209 |
fTypeHierarchyViewPart.updateHierarchyViewer(true); |
| 210 |
} |
| 211 |
}); |
| 124 |
} |
212 |
} |
| 125 |
} |
213 |
} |
| 126 |
|
214 |
|
|
Lines 176-181
Link Here
|
| 176 |
fInputElement= element; |
264 |
fInputElement= element; |
| 177 |
} else { |
265 |
} else { |
| 178 |
fHierarchy.refresh(pm); |
266 |
fHierarchy.refresh(pm); |
|
|
267 |
if (pm != null && pm.isCanceled()) |
| 268 |
throw new OperationCanceledException(); |
| 179 |
} |
269 |
} |
| 180 |
fHierarchy.addTypeHierarchyChangedListener(this); |
270 |
fHierarchy.addTypeHierarchyChangedListener(this); |
| 181 |
JavaCore.addElementChangedListener(this); |
271 |
JavaCore.addElementChangedListener(this); |
|
Lines 274-278
Link Here
|
| 274 |
} |
364 |
} |
| 275 |
} |
365 |
} |
| 276 |
|
366 |
|
|
|
367 |
/** |
| 368 |
* Cancels the job that refreshes the type hierarchy. |
| 369 |
* |
| 370 |
* @since 3.6 |
| 371 |
*/ |
| 372 |
public void cancelRefreshJob() { |
| 373 |
if (fRefreshHierarchyJob != null) { |
| 374 |
fRefreshHierarchyJob.cancel(); |
| 375 |
fRefreshHierarchyJob= null; |
| 376 |
fTypeHierarchyViewPart.setCanceledViewer(); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 277 |
|
380 |
|
| 278 |
} |
381 |
} |