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 (-14 / +57 lines)
Lines 241-247 Link Here
241
	private OpenAndLinkWithEditorHelper fTypeOpenAndLinkWithEditorHelper;
241
	private OpenAndLinkWithEditorHelper fTypeOpenAndLinkWithEditorHelper;
242
242
243
	private OpenAction fOpenAction;
243
	private OpenAction fOpenAction;
244
244
	protected boolean fIsRestoreJob= false;
245
245
246
	public TypeHierarchyViewPart() {
246
	public TypeHierarchyViewPart() {
247
		fSelectedType= null;
247
		fSelectedType= null;
Lines 251-257 Link Here
251
		fSelectInEditor= true;
251
		fSelectInEditor= true;
252
		fRestoreStateJob= null;
252
		fRestoreStateJob= null;
253
253
254
		fHierarchyLifeCycle= new TypeHierarchyLifeCycle();
254
		fHierarchyLifeCycle= new TypeHierarchyLifeCycle(this);
255
		fTypeHierarchyLifeCycleListener= new ITypeHierarchyLifeCycleListener() {
255
		fTypeHierarchyLifeCycleListener= new ITypeHierarchyLifeCycleListener() {
256
			public void typeHierarchyChanged(TypeHierarchyLifeCycle typeHierarchy, IType[] changedTypes) {
256
			public void typeHierarchyChanged(TypeHierarchyLifeCycle typeHierarchy, IType[] changedTypes) {
257
				doTypeHierarchyChanged(typeHierarchy, changedTypes);
257
				doTypeHierarchyChanged(typeHierarchy, changedTypes);
Lines 529-534 Link Here
529
		if (inputElement == null) {
529
		if (inputElement == null) {
530
			clearInput();
530
			clearInput();
531
		} else {
531
		} else {
532
			if (!inputElement.equals(prevInput) && !fIsRestoreJob) {
533
				for (int i= 0; i < fAllViewers.length; i++) {
534
					fAllViewers[i].setInput(null);
535
				}
536
			}
532
			fInputElement= inputElement;
537
			fInputElement= inputElement;
533
			fNoHierarchyShownLabel.setText(Messages.format(TypeHierarchyMessages.TypeHierarchyViewPart_createinput, JavaElementLabels.getElementLabel(inputElement, JavaElementLabels.ALL_DEFAULT)));
538
			fNoHierarchyShownLabel.setText(Messages.format(TypeHierarchyMessages.TypeHierarchyViewPart_createinput, JavaElementLabels.getElementLabel(inputElement, JavaElementLabels.ALL_DEFAULT)));
534
			try {
539
			try {
Lines 537-546 Link Here
537
			} catch (InvocationTargetException e) {
542
			} catch (InvocationTargetException e) {
538
				ExceptionHandler.handle(e, getSite().getShell(), TypeHierarchyMessages.TypeHierarchyViewPart_exception_title, TypeHierarchyMessages.TypeHierarchyViewPart_exception_message);
543
				ExceptionHandler.handle(e, getSite().getShell(), TypeHierarchyMessages.TypeHierarchyViewPart_exception_title, TypeHierarchyMessages.TypeHierarchyViewPart_exception_message);
539
				clearInput();
544
				clearInput();
540
				return;
545
				return;// panic code. This code wont be executed.
541
			} catch (InterruptedException e) {
546
			} catch (InterruptedException e) {
542
				fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
547
				fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
543
				return;
548
				return;// panic code. This code wont be executed.
544
			}
549
			}
545
550
546
			if (inputElement.getElementType() != IJavaElement.TYPE) {
551
			if (inputElement.getElementType() != IJavaElement.TYPE) {
Lines 561-570 Link Here
561
			updateToolTipAndDescription();
566
			updateToolTipAndDescription();
562
			showMembersInHierarchy(false);
567
			showMembersInHierarchy(false);
563
			fPagebook.showPage(fTypeMethodsSplitter);
568
			fPagebook.showPage(fTypeMethodsSplitter);
569
			setViewerVisibility(true);
564
			fSelectInEditor= true;
570
			fSelectInEditor= true;
565
		}
571
		}
566
	}
572
	}
567
573
574
	/**
575
	 * Sets the input for all the hierarchy viewers with their respective viewer instances. This is usually called after the
576
	 * viewer's input have been set to null and before their contents are updated.
577
	 *
578
	 * @since 3.6
579
	 */
580
	public void setViewersInput() {
581
		for (int i= 0; i < fAllViewers.length; i++) {
582
			fAllViewers[i].setInput(fAllViewers[i]);
583
		}
584
	}
585
568
	private void processOutstandingEvents() {
586
	private void processOutstandingEvents() {
569
		Display display= getDisplay();
587
		Display display= getDisplay();
570
		if (display != null && !display.isDisposed())
588
		if (display != null && !display.isDisposed())
Lines 1124-1130 Link Here
1124
	 * <code>updateHierarchyViewer<code> brings up the correct view and refreshes
1142
	 * <code>updateHierarchyViewer<code> brings up the correct view and refreshes
1125
	 * the current tree
1143
	 * the current tree
1126
	 */
1144
	 */
1127
	private void updateHierarchyViewer(final boolean doExpand) {
1145
	public void updateHierarchyViewer(final boolean doExpand) {
1128
		if (fInputElement == null) {
1146
		if (fInputElement == null) {
1129
			fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
1147
			fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
1130
			fPagebook.showPage(fNoHierarchyShownLabel);
1148
			fPagebook.showPage(fNoHierarchyShownLabel);
Lines 1561-1571 Link Here
1561
1579
1562
				fRestoreStateJob= new Job(label) {
1580
				fRestoreStateJob= new Job(label) {
1563
					protected IStatus run(IProgressMonitor monitor) {
1581
					protected IStatus run(IProgressMonitor monitor) {
1582
						fIsRestoreJob= true;
1564
						try {
1583
						try {
1565
							doRestoreInBackground(memento, hierarchyInput, monitor);
1584
							doRestoreInBackground(memento, hierarchyInput, monitor);
1566
						} catch (JavaModelException e) {
1585
						} catch (JavaModelException e) {
1567
							return e.getStatus();
1586
							return e.getStatus();
1568
						} catch (OperationCanceledException e) {
1587
						} catch (OperationCanceledException e) {
1588
							setCanceledViewer();
1569
							return Status.CANCEL_STATUS;
1589
							return Status.CANCEL_STATUS;
1570
						}
1590
						}
1571
						return Status.OK_STATUS;
1591
						return Status.OK_STATUS;
Lines 1579-1595 Link Here
1579
	private void doRestoreInBackground(final IMemento memento, final IJavaElement hierarchyInput, IProgressMonitor monitor) throws JavaModelException {
1599
	private void doRestoreInBackground(final IMemento memento, final IJavaElement hierarchyInput, IProgressMonitor monitor) throws JavaModelException {
1580
		fHierarchyLifeCycle.doHierarchyRefresh(hierarchyInput, monitor);
1600
		fHierarchyLifeCycle.doHierarchyRefresh(hierarchyInput, monitor);
1581
		final boolean doRestore= !monitor.isCanceled();
1601
		final boolean doRestore= !monitor.isCanceled();
1582
		Display.getDefault().asyncExec(new Runnable() {
1602
		if (doRestore) {
1583
			public void run() {
1603
			Display.getDefault().asyncExec(new Runnable() {
1584
				// running async: check first if view still exists
1604
				public void run() {
1585
				if (fPagebook != null && !fPagebook.isDisposed()) {
1605
					// running async: check first if view still exists
1586
					if (doRestore)
1606
					if (fPagebook != null && !fPagebook.isDisposed()) {
1587
						doRestoreState(memento, hierarchyInput);
1607
						doRestoreState(memento, hierarchyInput);
1588
					else
1608
					}
1589
						fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty);
1590
				}
1609
				}
1591
			}
1610
			});
1592
		});
1611
		}
1593
	}
1612
	}
1594
1613
1595
1614
Lines 1731-1734 Link Here
1731
		fNeedRefresh= false;
1750
		fNeedRefresh= false;
1732
	}
1751
	}
1733
1752
1753
	/**
1754
	 * Sets the empty viewer after the canceled job in the display thread.
1755
	 *
1756
	 * @since 3.6
1757
	 */
1758
	public void setCanceledViewer() {
1759
		Display.getDefault().asyncExec(new Runnable() {
1760
			public void run() {
1761
				clearInput();
1762
			}
1763
		});
1764
	}
1765
1766
	/**
1767
	 * Returns the type hierarchy life cycle.
1768
	 *
1769
	 * @return the type hierarchy life cycle
1770
	 *
1771
	 * @since 3.6
1772
	 */
1773
	public TypeHierarchyLifeCycle getTypeHierarchyLifeCycle() {
1774
		return fHierarchyLifeCycle;
1775
1776
	}
1734
}
1777
}

Return to bug 30881