Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 146846 Details for
Bug 30881
[type hierarchy] Type hierarchy should be computed in a background thread
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch
patch1_30881.txt (text/plain), 18.14 KB, created by
Raksha Vasisht
on 2009-09-10 05:34:24 EDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Raksha Vasisht
Created:
2009-09-10 05:34:24 EDT
Size:
18.14 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyLifeCycle.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyLifeCycle.java,v >retrieving revision 1.46 >diff -u -r1.46 TypeHierarchyLifeCycle.java >--- ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyLifeCycle.java 31 Dec 2008 21:13:30 -0000 1.46 >+++ ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyLifeCycle.java 10 Sep 2009 09:16:13 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -14,8 +14,13 @@ > import java.util.ArrayList; > import java.util.List; > >+import org.eclipse.swt.widgets.Display; >+ > import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.jobs.Job; > > import org.eclipse.jface.operation.IRunnableContext; > import org.eclipse.jface.operation.IRunnableWithProgress; >@@ -37,6 +42,9 @@ > import org.eclipse.jdt.core.JavaModelException; > > import org.eclipse.jdt.internal.corext.util.JavaModelUtil; >+import org.eclipse.jdt.internal.corext.util.Messages; >+ >+import org.eclipse.jdt.ui.JavaElementLabels; > > import org.eclipse.jdt.internal.ui.JavaPlugin; > >@@ -52,8 +60,30 @@ > > private List fChangeListeners; > >- public TypeHierarchyLifeCycle() { >+ /** >+ * The type hierarchy view part. >+ * >+ * @since 3.6 >+ */ >+ private TypeHierarchyViewPart fTypeHierarchyViewPart; >+ >+ /** >+ * The job that runs in the background to refresh the type hierarchy. >+ * >+ * @since 3.6 >+ */ >+ private Job fRefreshHierarchyJob; >+ >+ /** >+ * Creates the type hierarchy life cycle. >+ * >+ * @param part the type hierarchy view part >+ * @since 3.6 >+ */ >+ public TypeHierarchyLifeCycle(TypeHierarchyViewPart part) { > this(false); >+ fTypeHierarchyViewPart= part; >+ fRefreshHierarchyJob= null; > } > > public TypeHierarchyLifeCycle(boolean isSuperTypesOnly) { >@@ -98,6 +128,14 @@ > } > } > >+ /** >+ * Refreshes the type hierarchy for the java element if it exists. >+ * >+ * @param element the java element for which the type hierarchy is computed >+ * @param context the runnable context >+ * @throws InterruptedException thrown from the <code>OperationCanceledException</code> when the monitor is canceled >+ * @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 >+ */ > public void ensureRefreshedTypeHierarchy(final IJavaElement element, IRunnableContext context) throws InvocationTargetException, InterruptedException { > if (element == null || !element.exists()) { > freeHierarchy(); >@@ -106,21 +144,71 @@ > boolean hierachyCreationNeeded= (fHierarchy == null || !element.equals(fInputElement)); > > if (hierachyCreationNeeded || fHierarchyRefreshNeeded) { >- >- IRunnableWithProgress op= new IRunnableWithProgress() { >- public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { >- try { >- doHierarchyRefresh(element, pm); >- } catch (JavaModelException e) { >- throw new InvocationTargetException(e); >- } catch (OperationCanceledException e) { >- throw new InterruptedException(); >+ if (fTypeHierarchyViewPart == null) { >+ IRunnableWithProgress op= new IRunnableWithProgress() { >+ public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { >+ try { >+ doHierarchyRefresh(element, pm); >+ } catch (JavaModelException e) { >+ throw new InvocationTargetException(e); >+ } catch (OperationCanceledException e) { >+ throw new InterruptedException(); >+ } > } >+ }; >+ fHierarchyRefreshNeeded= true; >+ context.run(true, true, op); >+ fHierarchyRefreshNeeded= false; >+ } else { >+ synchronized (this) { >+ final String label= Messages.format(TypeHierarchyMessages.TypeHierarchyLifeCycle_computeInput, JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT)); >+ fRefreshHierarchyJob= new Job(label) { >+ /* >+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public IStatus run(IProgressMonitor pm) { >+ pm.beginTask(label, LONG); >+ fTypeHierarchyViewPart.setCancelEnabled(true); >+ try { >+ doHierarchyRefreshBackground(element, pm); >+ } catch (OperationCanceledException e) { >+ fTypeHierarchyViewPart.setCanceledViewer(); >+ return Status.CANCEL_STATUS; >+ } catch (JavaModelException e) { >+ return e.getStatus(); >+ } finally { >+ fTypeHierarchyViewPart.setCancelEnabled(false); >+ fHierarchyRefreshNeeded= false; >+ pm.done(); >+ } >+ return Status.OK_STATUS; >+ } >+ }; >+ fRefreshHierarchyJob.schedule(); > } >- }; >- fHierarchyRefreshNeeded= true; >- context.run(true, true, op); >- fHierarchyRefreshNeeded= false; >+ } >+ } >+ } >+ >+ /** >+ * Refreshes the hierarchy in the background and updates the hierarchy viewer asynchronously in the UI thread. >+ * >+ * @param element the java element on which the hierarchy is computed >+ * @param pm the progress monitor >+ * @throws JavaModelException if the java element does not exist or if an exception occurs while accessing its corresponding resource. >+ * @since 3.6 >+ */ >+ protected synchronized void doHierarchyRefreshBackground(final IJavaElement element, final IProgressMonitor pm) throws JavaModelException { >+ doHierarchyRefresh(element, pm); >+ if (!pm.isCanceled()) { >+ Display.getDefault().asyncExec(new Runnable() { >+ /* >+ * @see java.lang.Runnable#run() >+ */ >+ public void run() { >+ fTypeHierarchyViewPart.updateHierarchyViewer(true); >+ } >+ }); > } > } > >@@ -176,6 +264,8 @@ > fInputElement= element; > } else { > fHierarchy.refresh(pm); >+ if (pm != null && pm.isCanceled()) >+ throw new OperationCanceledException(); > } > fHierarchy.addTypeHierarchyChangedListener(this); > JavaCore.addElementChangedListener(this); >@@ -274,5 +364,18 @@ > } > } > >+ /** >+ * Cancels the job that refreshes the type hierarchy. >+ * >+ * @since 3.6 >+ */ >+ public void cancelRefreshJob() { >+ if (fRefreshHierarchyJob != null) { >+ fRefreshHierarchyJob.cancel(); >+ fRefreshHierarchyJob= null; >+ fTypeHierarchyViewPart.setCanceledViewer(); >+ } >+ } >+ > > } >Index: ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.properties,v >retrieving revision 1.59 >diff -u -r1.59 TypeHierarchyMessages.properties >--- ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.properties 17 Aug 2009 15:28:36 -0000 1.59 >+++ ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.properties 10 Sep 2009 09:16:13 -0000 >@@ -9,6 +9,8 @@ > # IBM Corporation - initial API and implementation > ############################################################################### > >+CancelTypeHierarchyComputationAction_label=Cancel >+CancelTypeHierarchyComputationAction_tooltip=Cancel Current Computation > EnableMemberFilterAction_label=Members in Hierarchy > EnableMemberFilterAction_tooltip=Lock View and Show Members in Hierarchy > EnableMemberFilterAction_description=Lock view and show members in hierarchy >@@ -62,6 +64,7 @@ > SortByDefiningTypeAction_label=Sort by the Defining Type > SortByDefiningTypeAction_tooltip=Sort Methods by the Defining Type > SortByDefiningTypeAction_description=Sort methods by the defining type >+TypeHierarchyLifeCycle_computeInput=Computing type hierarchy of ''{0}''... > > TypeHierarchyViewPart_error_title=Open Type Hierarchy > TypeHierarchyViewPart_createinput=Creating type hierarchy of ''{0}''... >Index: ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.java,v >retrieving revision 1.12 >diff -u -r1.12 TypeHierarchyMessages.java >--- ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.java 6 Aug 2009 13:53:47 -0000 1.12 >+++ ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyMessages.java 10 Sep 2009 09:16:13 -0000 >@@ -20,6 +20,8 @@ > // Do not instantiate > } > >+ public static String CancelTypeHierarchyComputationAction_label; >+ public static String CancelTypeHierarchyComputationAction_tooltip; > public static String EnableMemberFilterAction_label; > public static String EnableMemberFilterAction_tooltip; > public static String EnableMemberFilterAction_description; >@@ -72,6 +74,7 @@ > public static String TypeHierarchyViewPart_ws_tooltip; > public static String TypeHierarchyViewPart_restoreinput; > public static String TypeHierarchyViewPart_layout_submenu; >+ public static String TypeHierarchyLifeCycle_computeInput; > public static String ToggleViewAction_subtypes_label; > public static String ToggleViewAction_subtypes_tooltip; > public static String ToggleViewAction_subtypes_description; >Index: ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewPart.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewPart.java,v >retrieving revision 1.227 >diff -u -r1.227 TypeHierarchyViewPart.java >--- ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewPart.java 6 Aug 2009 13:53:47 -0000 1.227 >+++ ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewPart.java 10 Sep 2009 09:16:15 -0000 >@@ -241,8 +241,12 @@ > private OpenAndLinkWithEditorHelper fTypeOpenAndLinkWithEditorHelper; > > private OpenAction fOpenAction; >- >- >+ /** >+ * Action to cancel the type hierarchy computation. >+ * >+ * @since 3.6 >+ */ >+ private CancelTypeHierarchyComputationAction fCancelTypeHierarchyComputationAction; > public TypeHierarchyViewPart() { > fSelectedType= null; > fInputElement= null; >@@ -251,7 +255,7 @@ > fSelectInEditor= true; > fRestoreStateJob= null; > >- fHierarchyLifeCycle= new TypeHierarchyLifeCycle(); >+ fHierarchyLifeCycle= new TypeHierarchyLifeCycle(this); > fTypeHierarchyLifeCycleListener= new ITypeHierarchyLifeCycleListener() { > public void typeHierarchyChanged(TypeHierarchyLifeCycle typeHierarchy, IType[] changedTypes) { > doTypeHierarchyChanged(typeHierarchy, changedTypes); >@@ -282,6 +286,9 @@ > fHistoryDropDownAction= new HistoryDropDownAction(this); > fHistoryDropDownAction.setEnabled(false); > >+ fCancelTypeHierarchyComputationAction= new CancelTypeHierarchyComputationAction(this); >+ setCancelEnabled(false); >+ > fToggleOrientationActions= new ToggleOrientationAction[] { > new ToggleOrientationAction(this, VIEW_LAYOUT_VERTICAL), > new ToggleOrientationAction(this, VIEW_LAYOUT_HORIZONTAL), >@@ -535,12 +542,9 @@ > fHierarchyLifeCycle.ensureRefreshedTypeHierarchy(inputElement, JavaPlugin.getActiveWorkbenchWindow()); > // fHierarchyLifeCycle.ensureRefreshedTypeHierarchy(inputElement, getSite().getWorkbenchWindow()); > } catch (InvocationTargetException e) { >- ExceptionHandler.handle(e, getSite().getShell(), TypeHierarchyMessages.TypeHierarchyViewPart_exception_title, TypeHierarchyMessages.TypeHierarchyViewPart_exception_message); >- clearInput(); >- return; >+ //Do nothing > } catch (InterruptedException e) { >- fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty); >- return; >+ //Do nothing > } > > if (inputElement.getElementType() != IJavaElement.TYPE) { >@@ -561,6 +565,7 @@ > updateToolTipAndDescription(); > showMembersInHierarchy(false); > fPagebook.showPage(fTypeMethodsSplitter); >+ setViewerVisibility(true); > fSelectInEditor= true; > } > } >@@ -1043,6 +1048,7 @@ > tbmanager.add(fViewActions[i]); > } > tbmanager.add(fHistoryDropDownAction); >+ tbmanager.add(fCancelTypeHierarchyComputationAction); > tbmanager.update(false); > } > >@@ -1124,7 +1130,7 @@ > * <code>updateHierarchyViewer<code> brings up the correct view and refreshes > * the current tree > */ >- private void updateHierarchyViewer(final boolean doExpand) { >+ public void updateHierarchyViewer(final boolean doExpand) { > if (fInputElement == null) { > fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty); > fPagebook.showPage(fNoHierarchyShownLabel); >@@ -1561,12 +1567,16 @@ > > fRestoreStateJob= new Job(label) { > protected IStatus run(IProgressMonitor monitor) { >+ fCancelTypeHierarchyComputationAction.setEnabled(true); > try { > doRestoreInBackground(memento, hierarchyInput, monitor); > } catch (JavaModelException e) { > return e.getStatus(); > } catch (OperationCanceledException e) { >+ setCanceledViewer(); > return Status.CANCEL_STATUS; >+ } finally { >+ fCancelTypeHierarchyComputationAction.setEnabled(false); > } > return Status.OK_STATUS; > } >@@ -1579,17 +1589,16 @@ > private void doRestoreInBackground(final IMemento memento, final IJavaElement hierarchyInput, IProgressMonitor monitor) throws JavaModelException { > fHierarchyLifeCycle.doHierarchyRefresh(hierarchyInput, monitor); > final boolean doRestore= !monitor.isCanceled(); >- Display.getDefault().asyncExec(new Runnable() { >- public void run() { >- // running async: check first if view still exists >- if (fPagebook != null && !fPagebook.isDisposed()) { >- if (doRestore) >+ if (doRestore) { >+ Display.getDefault().asyncExec(new Runnable() { >+ public void run() { >+ // running async: check first if view still exists >+ if (fPagebook != null && !fPagebook.isDisposed()) { > doRestoreState(memento, hierarchyInput); >- else >- fNoHierarchyShownLabel.setText(TypeHierarchyMessages.TypeHierarchyViewPart_empty); >+ } > } >- } >- }); >+ }); >+ } > } > > >@@ -1731,4 +1740,50 @@ > fNeedRefresh= false; > } > >+ /** >+ * Sets the enablement state of the cancel button. >+ * >+ * @param enabled <code>true</code> if cancel should be enabled, <code>false</code> otherwise >+ * @since 3.6 >+ */ >+ void setCancelEnabled(boolean enabled) { >+ fCancelTypeHierarchyComputationAction.setEnabled(enabled); >+ } >+ >+ /** >+ * Cancels the current computation of type hierarchy. >+ * >+ * @since 3.6 >+ */ >+ public void cancelRestoreJob() { >+ if (fRestoreStateJob != null) { >+ fRestoreStateJob.cancel(); >+ setCanceledViewer(); >+ } >+ } >+ >+ /** >+ * Sets the empty viewer after the canceled job in the display thread. >+ * >+ * @since 3.6 >+ */ >+ public void setCanceledViewer() { >+ Display.getDefault().asyncExec(new Runnable() { >+ public void run() { >+ clearInput(); >+ } >+ }); >+ } >+ >+ /** >+ * Returns the type hierarchy life cycle. >+ * >+ * @return the type hierarchy life cycle >+ * >+ * @since 3.6 >+ */ >+ public TypeHierarchyLifeCycle getTypeHierarchyLifeCycle() { >+ return fHierarchyLifeCycle; >+ >+ } > } >Index: ui/org/eclipse/jdt/internal/ui/typehierarchy/CancelTypeHierarchyComputationAction.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/ui/typehierarchy/CancelTypeHierarchyComputationAction.java >diff -N ui/org/eclipse/jdt/internal/ui/typehierarchy/CancelTypeHierarchyComputationAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/internal/ui/typehierarchy/CancelTypeHierarchyComputationAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,54 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.jdt.internal.ui.typehierarchy; >+ >+import org.eclipse.jface.action.Action; >+ >+import org.eclipse.ui.PlatformUI; >+ >+import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; >+import org.eclipse.jdt.internal.ui.JavaPluginImages; >+ >+/** >+ * Action to cancel the current type hierarchy computation. >+ * >+ * @since 3.6 >+ * >+ */ >+public class CancelTypeHierarchyComputationAction extends Action { >+ /** >+ * The type hierarchy view part. >+ */ >+ private TypeHierarchyViewPart fTypeHierarchyViewPart; >+ >+ /** >+ * Creates the cancel action for type hierarchy computation. >+ * >+ * @param part the type hierarchy view part >+ */ >+ public CancelTypeHierarchyComputationAction(TypeHierarchyViewPart part) { >+ super(TypeHierarchyMessages.CancelTypeHierarchyComputationAction_label); >+ fTypeHierarchyViewPart= part; >+ setToolTipText(TypeHierarchyMessages.CancelTypeHierarchyComputationAction_tooltip); >+ JavaPluginImages.setLocalImageDescriptors(this, "ch_cancel.gif"); //$NON-NLS-1$ >+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.TYPE_HIERARCHY_CANCEL_COMPUTATION_ACTION); >+ } >+ >+ /* >+ * @see org.eclipse.jface.action.Action#run() >+ */ >+ public void run() { >+ setEnabled(false); >+ fTypeHierarchyViewPart.getTypeHierarchyLifeCycle().cancelRefreshJob(); >+ fTypeHierarchyViewPart.cancelRestoreJob(); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 30881
:
146846
|
146848
|
148399
|
148408
|
150907
|
150908
|
151768