View | Details | Raw Unified | Return to bug 30881 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyLifeCycle.java (-15 / +121 lines)
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);
(-)ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.java (+1 lines)
Lines 72-77 Link Here
72
	public static String TypeHierarchyViewPart_ws_tooltip;
72
	public static String TypeHierarchyViewPart_ws_tooltip;
73
	public static String TypeHierarchyViewPart_restoreinput;
73
	public static String TypeHierarchyViewPart_restoreinput;
74
	public static String TypeHierarchyViewPart_layout_submenu;
74
	public static String TypeHierarchyViewPart_layout_submenu;
75
	public static String TypeHierarchyLifeCycle_computeInput;
75
	public static String ToggleViewAction_subtypes_label;
76
	public static String ToggleViewAction_subtypes_label;
76
	public static String ToggleViewAction_subtypes_tooltip;
77
	public static String ToggleViewAction_subtypes_tooltip;
77
	public static String ToggleViewAction_subtypes_description;
78
	public static String ToggleViewAction_subtypes_description;
(-)ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.properties (+1 lines)
Lines 62-67 Link Here
62
SortByDefiningTypeAction_label=Sort by the Defining Type
62
SortByDefiningTypeAction_label=Sort by the Defining Type
63
SortByDefiningTypeAction_tooltip=Sort Methods by the Defining Type
63
SortByDefiningTypeAction_tooltip=Sort Methods by the Defining Type
64
SortByDefiningTypeAction_description=Sort methods by the defining type
64
SortByDefiningTypeAction_description=Sort methods by the defining type
65
TypeHierarchyLifeCycle_computeInput=Computing type hierarchy of ''{0}''...
65
66
66
TypeHierarchyViewPart_error_title=Open Type Hierarchy
67
TypeHierarchyViewPart_error_title=Open Type Hierarchy
67
TypeHierarchyViewPart_createinput=Creating type hierarchy of ''{0}''...
68
TypeHierarchyViewPart_createinput=Creating type hierarchy of ''{0}''...
(-)ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewPart.java (-13 / +55 lines)
Lines 251-257 Link Here
251
		fSelectInEditor= true;
250
		fSelectInEditor= true;
252
		fRestoreStateJob= null;
251
		fRestoreStateJob= null;
253
252
254
		fHierarchyLifeCycle= new TypeHierarchyLifeCycle();
253
		fHierarchyLifeCycle= new TypeHierarchyLifeCycle(this);
255
		fTypeHierarchyLifeCycleListener= new ITypeHierarchyLifeCycleListener() {
254
		fTypeHierarchyLifeCycleListener= new ITypeHierarchyLifeCycleListener() {
256
			public void typeHierarchyChanged(TypeHierarchyLifeCycle typeHierarchy, IType[] changedTypes) {
255
			public void typeHierarchyChanged(TypeHierarchyLifeCycle typeHierarchy, IType[] changedTypes) {
257
				doTypeHierarchyChanged(typeHierarchy, changedTypes);
256
				doTypeHierarchyChanged(typeHierarchy, changedTypes);
Lines 529-534 Link Here
529
		if (inputElement == null) {
528
		if (inputElement == null) {
530
			clearInput();
529
			clearInput();
531
		} else {
530
		} else {
531
			if (!inputElement.equals(prevInput)) {
532
				for (int i= 0; i < fAllViewers.length; i++) {
533
					fAllViewers[i].setInput(null);
534
				}
535
			}
532
			fInputElement= inputElement;
536
			fInputElement= inputElement;
533
			fNoHierarchyShownLabel.setText(Messages.format(TypeHierarchyMessages.TypeHierarchyViewPart_createinput, JavaElementLabels.getElementLabel(inputElement, JavaElementLabels.ALL_DEFAULT)));
537
			fNoHierarchyShownLabel.setText(Messages.format(TypeHierarchyMessages.TypeHierarchyViewPart_createinput, JavaElementLabels.getElementLabel(inputElement, JavaElementLabels.ALL_DEFAULT)));
534
			try {
538
			try {
Lines 537-546 Link Here
537
			} catch (InvocationTargetException e) {
541
			} catch (InvocationTargetException e) {
538
				ExceptionHandler.handle(e, getSite().getShell(), TypeHierarchyMessages.TypeHierarchyViewPart_exception_title, TypeHierarchyMessages.TypeHierarchyViewPart_exception_message);
542
				ExceptionHandler.handle(e, getSite().getShell(), TypeHierarchyMessages.TypeHierarchyViewPart_exception_title, TypeHierarchyMessages.TypeHierarchyViewPart_exception_message);
539
				clearInput();
543
				clearInput();
540
				return;
544
				return;// panic code. This code wont be executed.
541
			} catch (InterruptedException e) {
545
			} catch (InterruptedException e) {
542
				fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
546
				fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
543
				return;
547
				return;// panic code. This code wont be executed.
544
			}
548
			}
545
549
546
			if (inputElement.getElementType() != IJavaElement.TYPE) {
550
			if (inputElement.getElementType() != IJavaElement.TYPE) {
Lines 561-570 Link Here
561
			updateToolTipAndDescription();
565
			updateToolTipAndDescription();
562
			showMembersInHierarchy(false);
566
			showMembersInHierarchy(false);
563
			fPagebook.showPage(fTypeMethodsSplitter);
567
			fPagebook.showPage(fTypeMethodsSplitter);
568
			setViewerVisibility(true);
564
			fSelectInEditor= true;
569
			fSelectInEditor= true;
565
		}
570
		}
566
	}
571
	}
567
572
573
	/**
574
	 * Sets the input for all the hierarchy viewers with their respective viewer instances. This is usually called after the
575
	 * viewer's input have been set to null and before their contents are updated.
576
	 *
577
	 * @since 3.6
578
	 */
579
	public void setViewersInput() {
580
		for (int i= 0; i < fAllViewers.length; i++) {
581
			fAllViewers[i].setInput(fAllViewers[i]);
582
		}
583
	}
584
568
	private void processOutstandingEvents() {
585
	private void processOutstandingEvents() {
569
		Display display= getDisplay();
586
		Display display= getDisplay();
570
		if (display != null && !display.isDisposed())
587
		if (display != null && !display.isDisposed())
Lines 1124-1130 Link Here
1124
	 * <code>updateHierarchyViewer<code> brings up the correct view and refreshes
1141
	 * <code>updateHierarchyViewer<code> brings up the correct view and refreshes
1125
	 * the current tree
1142
	 * the current tree
1126
	 */
1143
	 */
1127
	private void updateHierarchyViewer(final boolean doExpand) {
1144
	public void updateHierarchyViewer(final boolean doExpand) {
1128
		if (fInputElement == null) {
1145
		if (fInputElement == null) {
1129
			fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
1146
			fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
1130
			fPagebook.showPage(fNoHierarchyShownLabel);
1147
			fPagebook.showPage(fNoHierarchyShownLabel);
Lines 1566-1571 Link Here
1566
						} catch (JavaModelException e) {
1583
						} catch (JavaModelException e) {
1567
							return e.getStatus();
1584
							return e.getStatus();
1568
						} catch (OperationCanceledException e) {
1585
						} catch (OperationCanceledException e) {
1586
							setCanceledViewer();
1569
							return Status.CANCEL_STATUS;
1587
							return Status.CANCEL_STATUS;
1570
						}
1588
						}
1571
						return Status.OK_STATUS;
1589
						return Status.OK_STATUS;
Lines 1579-1595 Link Here
1579
	private void doRestoreInBackground(final IMemento memento, final IJavaElement hierarchyInput, IProgressMonitor monitor) throws JavaModelException {
1597
	private void doRestoreInBackground(final IMemento memento, final IJavaElement hierarchyInput, IProgressMonitor monitor) throws JavaModelException {
1580
		fHierarchyLifeCycle.doHierarchyRefresh(hierarchyInput, monitor);
1598
		fHierarchyLifeCycle.doHierarchyRefresh(hierarchyInput, monitor);
1581
		final boolean doRestore= !monitor.isCanceled();
1599
		final boolean doRestore= !monitor.isCanceled();
1582
		Display.getDefault().asyncExec(new Runnable() {
1600
		if (doRestore) {
1583
			public void run() {
1601
			Display.getDefault().asyncExec(new Runnable() {
1584
				// running async: check first if view still exists
1602
				public void run() {
1585
				if (fPagebook != null && !fPagebook.isDisposed()) {
1603
					// running async: check first if view still exists
1586
					if (doRestore)
1604
					if (fPagebook != null && !fPagebook.isDisposed()) {
1587
						doRestoreState(memento, hierarchyInput);
1605
						doRestoreState(memento, hierarchyInput);
1588
					else
1606
					}
1589
						fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
1590
				}
1607
				}
1591
			}
1608
			});
1592
		});
1609
		}
1593
	}
1610
	}
1594
1611
1595
1612
Lines 1731-1734 Link Here
1731
		fNeedRefresh= false;
1748
		fNeedRefresh= false;
1732
	}
1749
	}
1733
1750
1751
	/**
1752
	 * Sets the empty viewer after the canceled job in the display thread.
1753
	 *
1754
	 * @since 3.6
1755
	 */
1756
	public void setCanceledViewer() {
1757
		Display.getDefault().asyncExec(new Runnable() {
1758
			public void run() {
1759
				clearInput();
1760
			}
1761
		});
1762
	}
1763
1764
	/**
1765
	 * Returns the type hierarchy life cycle.
1766
	 *
1767
	 * @return the type hierarchy life cycle
1768
	 *
1769
	 * @since 3.6
1770
	 */
1771
	public TypeHierarchyLifeCycle getTypeHierarchyLifeCycle() {
1772
		return fHierarchyLifeCycle;
1773
1774
	}
1734
}
1775
}

Return to bug 30881