diff options
| author | Markus Keller | 2015-09-16 13:57:25 +0000 |
|---|---|---|
| committer | Markus Keller | 2015-09-16 14:11:36 +0000 |
| commit | 29da1e2b77a857c43a558eafcc528e5717b1e321 (patch) | |
| tree | d2cabb4c13556e357e751df15625e4c5c4efb137 | |
| parent | 85b93c1e2053aa36564fe96be16b502e1944b683 (diff) | |
| download | eclipse.platform.ui-29da1e2b77a857c43a558eafcc528e5717b1e321.tar.gz eclipse.platform.ui-29da1e2b77a857c43a558eafcc528e5717b1e321.tar.xz eclipse.platform.ui-29da1e2b77a857c43a558eafcc528e5717b1e321.zip | |
Revert commits for "Bug 475785 - Remove usage of SubProgressMonitor in *"I20150916-2000
This reverts commit 85b93c1e2053aa36564fe96be16b502e1944b683.
This reverts commit 9468f370adbfd4af0d76c4ec6e6c22edb43162e4.
This reverts commit d7a1117af7376fa32af298daeb4065bfcd631551.
This reverts commit e1fb21c161e6f9188ad46cb4aebf2c4a6984f90c.
This reverts commit 9030b39b10c8df7a53aacb45437b92be765b8566.
This reverts commit 5957cef476205f372aa1ad15a8798bb2254a87ed.
This reverts commit b071a5aa0e1dbef1760839ea0a8abe805a6d8830.
This reverts commit 2daab974129378b92daacc860dbcee77dabf2123.
This reverts commit ab0a4e07b8b5102fa2756c32111cd2d6d7ce13e2.
This reverts commit ea9d71a488dcd539b8b3a84d7ddc8b2acbca7bf5.
28 files changed, 799 insertions, 572 deletions
diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/BuildAction.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/BuildAction.java index 18a97b182fd..2c9fa27a256 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/BuildAction.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/BuildAction.java @@ -30,7 +30,7 @@ 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.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.preference.IPreferenceStore; @@ -278,13 +278,12 @@ public class BuildAction extends WorkspaceAction { @Override public IStatus runInWorkspace(IProgressMonitor monitor) { IStatus status = null; - SubMonitor progress = SubMonitor.convert(monitor, 10000); - progress.setTaskName(getOperationMessage()); + monitor.beginTask("", 10000); //$NON-NLS-1$ + monitor.setTaskName(getOperationMessage()); try { // Backwards compatibility: check shouldPerformResourcePruning(). // Previously if this returned true, the full reference graph is built, otherwise just build the selected configurations - ResourcesPlugin.getWorkspace().build(configs, kind, shouldPerformResourcePruning(), - progress.newChild(10000)); + ResourcesPlugin.getWorkspace().build(configs, kind, shouldPerformResourcePruning(), new SubProgressMonitor(monitor, 10000)); } catch (CoreException e) { status = e.getStatus(); } diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyFilesAndFoldersOperation.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyFilesAndFoldersOperation.java index ca6e2bb26c5..3972803ca8b 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyFilesAndFoldersOperation.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyFilesAndFoldersOperation.java @@ -44,7 +44,7 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IInputValidator; @@ -424,7 +424,7 @@ public class CopyFilesAndFoldersOperation { * the resources to copy * @param destination * destination to which resources will be copied - * @param monitor + * @param subMonitor * a progress monitor for showing progress and for cancelation * * @deprecated As of 3.3, the work is performed in the undoable operation @@ -432,12 +432,15 @@ public class CopyFilesAndFoldersOperation { * {@link #getUndoableCopyOrMoveOperation(IResource[], IPath)} */ @Deprecated - protected void copy(IResource[] resources, IPath destination, IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, - IDEWorkbenchMessages.CopyFilesAndFoldersOperation_CopyResourcesTask, resources.length); + protected void copy(IResource[] resources, IPath destination, + IProgressMonitor subMonitor) throws CoreException { + + subMonitor + .beginTask( + IDEWorkbenchMessages.CopyFilesAndFoldersOperation_CopyResourcesTask, + resources.length); for (int i = 0; i < resources.length; i++) { - SubMonitor iterationProgress = subMonitor.newChild(1).setWorkRemaining(100); IResource source = resources[i]; IPath destinationPath = destination.append(source.getName()); IWorkspace workspace = source.getWorkspace(); @@ -449,45 +452,55 @@ public class CopyFilesAndFoldersOperation { // children of the folder. if (homogenousResources(source, existing)) { IResource[] children = ((IContainer) source).members(); - copy(children, destinationPath, iterationProgress.newChild(100)); + copy(children, destinationPath, new SubProgressMonitor( + subMonitor, 1)); } else { // delete the destination folder, copying a linked folder // over an unlinked one or vice versa. Fixes bug 28772. - delete(existing, iterationProgress.newChild(10)); - source.copy(destinationPath, IResource.SHALLOW, iterationProgress.newChild(90)); + delete(existing, new SubProgressMonitor(subMonitor, 0)); + source.copy(destinationPath, IResource.SHALLOW, + new SubProgressMonitor(subMonitor, 1)); } } else { if (existing != null) { if (homogenousResources(source, existing)) { - copyExisting(source, existing, iterationProgress.newChild(100)); + copyExisting(source, existing, new SubProgressMonitor( + subMonitor, 1)); } else { - if (existing != null) { - // Copying a linked resource over unlinked or vice - // versa. - // Can't use setContents here. Fixes bug 28772. - delete(existing, iterationProgress.newChild(10)); + if (existing != null) { + // Copying a linked resource over unlinked or vice + // versa. + // Can't use setContents here. Fixes bug 28772. + delete(existing, new SubProgressMonitor(subMonitor, 0)); + } + + if ((createLinks || createVirtualFoldersAndLinks) + && (source.isLinked() == false) + && (source.isVirtual() == false)) { + if (source.getType() == IResource.FILE) { + IFile file = workspaceRoot.getFile(destinationPath); + file.createLink(createRelativePath(source.getLocationURI(), file), 0, + new SubProgressMonitor(subMonitor, 1)); + } else { + IFolder folder = workspaceRoot + .getFolder(destinationPath); + if (createVirtualFoldersAndLinks) { + folder.create(IResource.VIRTUAL, true, + new SubProgressMonitor(subMonitor, + 1)); + IResource[] members = ((IContainer) source) + .members(); + if (members.length > 0) + copy(members, destinationPath, + new SubProgressMonitor(subMonitor, + 1)); + } else + folder.createLink(createRelativePath(source.getLocationURI(), folder), 0, + new SubProgressMonitor(subMonitor, 1)); } - iterationProgress.setWorkRemaining(100); - - if ((createLinks || createVirtualFoldersAndLinks) && (source.isLinked() == false) - && (source.isVirtual() == false)) { - if (source.getType() == IResource.FILE) { - IFile file = workspaceRoot.getFile(destinationPath); - file.createLink(createRelativePath(source.getLocationURI(), file), 0, - iterationProgress.newChild(100)); - } else { - IFolder folder = workspaceRoot.getFolder(destinationPath); - if (createVirtualFoldersAndLinks) { - folder.create(IResource.VIRTUAL, true, subMonitor.newChild(1)); - IResource[] members = ((IContainer) source).members(); - if (members.length > 0) - copy(members, destinationPath, iterationProgress.newChild(100)); - } else - folder.createLink(createRelativePath(source.getLocationURI(), folder), 0, - iterationProgress.newChild(100)); - } - } else - source.copy(destinationPath, IResource.SHALLOW, iterationProgress.newChild(100)); + } else + source.copy(destinationPath, IResource.SHALLOW, + new SubProgressMonitor(subMonitor, 1)); } if (subMonitor.isCanceled()) { @@ -531,15 +544,17 @@ public class CopyFilesAndFoldersOperation { * @throws CoreException * setContents failed */ - private void copyExisting(IResource source, IResource existing, IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, 1); + private void copyExisting(IResource source, IResource existing, + IProgressMonitor subMonitor) throws CoreException { IFile existingFile = getFile(existing); if (existingFile != null) { IFile sourceFile = getFile(source); if (sourceFile != null) { - existingFile.setContents(sourceFile.getContents(), IResource.KEEP_HISTORY, subMonitor.newChild(1)); + existingFile.setContents(sourceFile.getContents(), + IResource.KEEP_HISTORY, new SubProgressMonitor( + subMonitor, 0)); } } } @@ -1787,15 +1802,16 @@ public class CopyFilesAndFoldersOperation { return (IResource[]) copyItems.toArray(new IResource[copyItems.size()]); } - private void copyResources(final IResource[] resources, final IPath destinationPath, - final IResource[][] copiedResources, IProgressMonitor mon) { + private void copyResources(final IResource[] resources, + final IPath destinationPath, final IResource[][] copiedResources, + IProgressMonitor monitor) { IResource[] copyResources = resources; // Fix for bug 31116. Do not provide a task name when // creating the task. - SubMonitor subMonitor = SubMonitor.convert(mon, 100); - subMonitor.setTaskName(getOperationTitle()); - subMonitor.worked(10); // show some initial progress + monitor.beginTask("", 100); //$NON-NLS-1$ + monitor.setTaskName(getOperationTitle()); + monitor.worked(10); // show some initial progress // Checks only required if this is an exisiting container path. boolean copyWithAutoRename = false; @@ -1829,11 +1845,13 @@ public class CopyFilesAndFoldersOperation { errorStatus = null; if (copyResources.length > 0) { if (copyWithAutoRename) { - performCopyWithAutoRename(copyResources, destinationPath, subMonitor.newChild(90)); + performCopyWithAutoRename(copyResources, destinationPath, + new SubProgressMonitor(monitor, 90)); } else { - performCopy(copyResources, destinationPath, subMonitor.newChild(90)); + performCopy(copyResources, destinationPath, new SubProgressMonitor(monitor, 90)); } } + monitor.done(); copiedResources[0] = copyResources; } diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/GlobalBuildAction.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/GlobalBuildAction.java index 4acbaa2b804..5eeda86021a 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/GlobalBuildAction.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/GlobalBuildAction.java @@ -19,7 +19,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.ErrorDialog; @@ -172,9 +172,10 @@ public class GlobalBuildAction extends Action implements Job buildJob = new Job(IDEWorkbenchMessages.GlobalBuildAction_jobTitle) { @Override protected IStatus run(IProgressMonitor monitor) { - SubMonitor subMonitor = SubMonitor.convert(monitor, getOperationMessage(), 100); + monitor.beginTask(getOperationMessage(), 100); try { - ResourcesPlugin.getWorkspace().build(buildType, subMonitor.newChild(100)); + ResourcesPlugin.getWorkspace().build(buildType, + new SubProgressMonitor(monitor, 100)); } catch (CoreException e) { return e.getStatus(); } finally { diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/MoveFilesAndFoldersOperation.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/MoveFilesAndFoldersOperation.java index 4371b568ef6..e79be2f8d6c 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/MoveFilesAndFoldersOperation.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/MoveFilesAndFoldersOperation.java @@ -19,7 +19,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.ide.undo.AbstractWorkspaceOperation; @@ -67,7 +67,7 @@ public class MoveFilesAndFoldersOperation extends CopyFilesAndFoldersOperation { * the resources to move * @param destination * destination to which resources will be moved - * @param monitor + * @param subMonitor * a progress monitor for showing progress and for cancelation * * @deprecated As of 3.3, the work is performed in the undoable operation @@ -76,10 +76,9 @@ public class MoveFilesAndFoldersOperation extends CopyFilesAndFoldersOperation { */ @Deprecated @Override - protected void copy(IResource[] resources, IPath destination, IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, resources.length); + protected void copy(IResource[] resources, IPath destination, + IProgressMonitor subMonitor) throws CoreException { for (int i = 0; i < resources.length; i++) { - SubMonitor iterationMonitor = subMonitor.newChild(1).setWorkRemaining(100); IResource source = resources[i]; IPath destinationPath = destination.append(source.getName()); IWorkspace workspace = source.getWorkspace(); @@ -90,32 +89,36 @@ public class MoveFilesAndFoldersOperation extends CopyFilesAndFoldersOperation { // move the children of the folder. if (homogenousResources(source, existing)) { IResource[] children = ((IContainer) source).members(); - copy(children, destinationPath, iterationMonitor.newChild(100)); + copy(children, destinationPath, subMonitor); delete(source, subMonitor); } else { // delete the destination folder, moving a linked folder // over an unlinked one or vice versa. Fixes bug 28772. - delete(existing, iterationMonitor.newChild(50)); - source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY, - iterationMonitor.newChild(50)); + delete(existing, new SubProgressMonitor(subMonitor, 0)); + source.move(destinationPath, IResource.SHALLOW + | IResource.KEEP_HISTORY, new SubProgressMonitor( + subMonitor, 0)); } } else { // if we're merging folders, we could be overwriting an existing // file if (existing != null) { if (homogenousResources(source, existing)) { - moveExisting(source, existing, iterationMonitor.newChild(100)); + moveExisting(source, existing, subMonitor); } else { // Moving a linked resource over unlinked or vice versa. // Can't use setContents here. Fixes bug 28772. - delete(existing, iterationMonitor.newChild(50)); - source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY, - iterationMonitor.newChild(50)); + delete(existing, new SubProgressMonitor(subMonitor, 0)); + source.move(destinationPath, IResource.SHALLOW + | IResource.KEEP_HISTORY, + new SubProgressMonitor(subMonitor, 0)); } } else { - source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY, - iterationMonitor.newChild(100)); + source.move(destinationPath, IResource.SHALLOW + | IResource.KEEP_HISTORY, new SubProgressMonitor( + subMonitor, 0)); } + subMonitor.worked(1); if (subMonitor.isCanceled()) { throw new OperationCanceledException(); } @@ -188,23 +191,25 @@ public class MoveFilesAndFoldersOperation extends CopyFilesAndFoldersOperation { * source file to move * @param existing * existing file to set the source content in - * @param monitor + * @param subMonitor * a progress monitor for showing progress and for cancelation * @throws CoreException * setContents failed * @deprecated As of 3.3, this method is not called. */ @Deprecated - private void moveExisting(IResource source, IResource existing, IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, 2); + private void moveExisting(IResource source, IResource existing, + IProgressMonitor subMonitor) throws CoreException { IFile existingFile = getFile(existing); if (existingFile != null) { IFile sourceFile = getFile(source); if (sourceFile != null) { - existingFile.setContents(sourceFile.getContents(), IResource.KEEP_HISTORY, subMonitor.newChild(1)); - delete(sourceFile, subMonitor.newChild(1)); + existingFile.setContents(sourceFile.getContents(), + IResource.KEEP_HISTORY, new SubProgressMonitor( + subMonitor, 0)); + delete(sourceFile, subMonitor); } } } diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/OpenResourceAction.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/OpenResourceAction.java index 7c8d9cc7475..05362217593 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/OpenResourceAction.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/OpenResourceAction.java @@ -27,7 +27,7 @@ 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.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; @@ -215,7 +215,7 @@ public class OpenResourceAction extends WorkspaceAction implements IResourceChan * Opens the selected projects, and all related projects, in the background. */ private void runOpenWithReferences() { - final List<IResource> resources = new ArrayList<>(getActionResources()); + final List resources = new ArrayList(getActionResources()); Job job = new WorkspaceJob(removeMnemonics(getText())) { private boolean openProjectReferences = true; private boolean hasPrompted = false; @@ -223,9 +223,11 @@ public class OpenResourceAction extends WorkspaceAction implements IResourceChan /** * Opens a project along with all projects it references */ - private void doOpenWithReferences(IProject project, IProgressMonitor mon) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(mon, openProjectReferences ? 2 : 1); - project.open(subMonitor.newChild(1)); + private void doOpenWithReferences(IProject project, IProgressMonitor monitor) throws CoreException { + if (!project.exists() || project.isOpen()) { + return; + } + project.open(new SubProgressMonitor(monitor, 1000)); final IProject[] references = project.getReferencedProjects(); if (!hasPrompted) { openProjectReferences = false; @@ -250,28 +252,23 @@ public class OpenResourceAction extends WorkspaceAction implements IResourceChan } } if (openProjectReferences) { - SubMonitor loopMonitor = subMonitor.newChild(1).setWorkRemaining(references.length); for (int i = 0; i < references.length; i++) { - doOpenWithReferences(references[i], loopMonitor.newChild(1)); + doOpenWithReferences(references[i], monitor); } } } @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, countClosedProjects()); - // at most we can only open all projects currently closed - subMonitor.setTaskName(getOperationMessage()); - for (IResource resource : resources) { - if (!(resource instanceof IProject)) { - continue; - } - - IProject project = (IProject) resource; - if (!project.exists() || project.isOpen()) { - continue; + try { + // at most we can only open all projects currently closed + monitor.beginTask("", countClosedProjects() * 1000); //$NON-NLS-1$ + monitor.setTaskName(getOperationMessage()); + for (Iterator it = resources.iterator(); it.hasNext();) { + doOpenWithReferences((IProject) it.next(), monitor); } - doOpenWithReferences(project, subMonitor.newChild(1)); + } finally { + monitor.done(); } return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RefreshAction.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RefreshAction.java index eacad7c4e57..54f1208def9 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RefreshAction.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RefreshAction.java @@ -30,7 +30,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.MultiRule; import org.eclipse.jface.dialogs.IDialogConstants; @@ -221,24 +221,28 @@ public class RefreshAction extends WorkspaceAction { } return new WorkspaceModifyOperation(rule) { @Override - public void execute(IProgressMonitor mon) { - SubMonitor subMonitor = SubMonitor.convert(mon, resources.size()); + public void execute(IProgressMonitor monitor) { MultiStatus errors = null; - subMonitor.setTaskName(getOperationMessage()); + monitor.beginTask("", resources.size() * 1000); //$NON-NLS-1$ + monitor.setTaskName(getOperationMessage()); Iterator<? extends IResource> resourcesEnum = resources.iterator(); - while (resourcesEnum.hasNext()) { - try { - IResource resource = resourcesEnum.next(); - refreshResource(resource, subMonitor.newChild(1)); - } catch (CoreException e) { - errors = recordError(errors, e); + try { + while (resourcesEnum.hasNext()) { + try { + IResource resource = resourcesEnum.next(); + refreshResource(resource, new SubProgressMonitor(monitor, 1000)); + } catch (CoreException e) { + errors = recordError(errors, e); + } + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } } - if (subMonitor.isCanceled()) { - throw new OperationCanceledException(); + if (errors != null) { + errorStatus[0] = errors; } - } - if (errors != null) { - errorStatus[0] = errors; + } finally { + monitor.done(); } } }; diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java index fb2c590b045..006319878f0 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java @@ -26,7 +26,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.dialogs.ErrorDialog; @@ -140,29 +140,38 @@ public abstract class WorkspaceAction extends SelectionListenerAction { * a progress monitor * @return The result of the execution */ - final IStatus execute(List<? extends IResource> resources, IProgressMonitor mon) { + final IStatus execute(List<? extends IResource> resources, IProgressMonitor monitor) { MultiStatus errors = null; // 1FTIMQN: ITPCORE:WIN - clients required to do too much iteration work if (shouldPerformResourcePruning()) { resources = pruneResources(resources); } - SubMonitor subMonitor = SubMonitor.convert(mon, resources.size()); + // 1FV0B3Y: ITPUI:ALL - sub progress monitors granularity issues + monitor.beginTask("", resources.size() * 1000); //$NON-NLS-1$ // Fix for bug 31768 - Don't provide a task name in beginTask // as it will be appended to each subTask message. Need to // call setTaskName as its the only was to assure the task name is // set in the monitor (see bug 31824) - subMonitor.setTaskName(getOperationMessage()); - for (IResource resource : resources) { - try { - invokeOperation(resource, subMonitor.newChild(1)); - } catch (CoreException e) { - errors = recordError(errors, e); - } - if (subMonitor.isCanceled()) { - throw new OperationCanceledException(); + monitor.setTaskName(getOperationMessage()); + Iterator<? extends IResource> resourcesEnum = resources.iterator(); + try { + while (resourcesEnum.hasNext()) { + IResource resource = resourcesEnum.next(); + try { + // 1FV0B3Y: ITPUI:ALL - sub progress monitors granularity + // issues + invokeOperation(resource, new SubProgressMonitor(monitor, 1000)); + } catch (CoreException e) { + errors = recordError(errors, e); + } + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } } + return errors == null ? Status.OK_STATUS : errors; + } finally { + monitor.done(); } - return errors == null ? Status.OK_STATUS : errors; } /** diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ContainerGenerator.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ContainerGenerator.java index 889c5433779..29afc51711a 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ContainerGenerator.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ContainerGenerator.java @@ -22,7 +22,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; @@ -113,16 +113,21 @@ public class ContainerGenerator { */ private IProject createProject(IProject projectHandle, IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, 2); - projectHandle.create(subMonitor.newChild(1)); - if (monitor.isCanceled()) { - throw new OperationCanceledException(); - } + try { + monitor.beginTask("", 2000);//$NON-NLS-1$ - projectHandle.open(subMonitor.newChild(1)); - if (monitor.isCanceled()) { - throw new OperationCanceledException(); - } + projectHandle.create(new SubProgressMonitor(monitor, 1000)); + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + + projectHandle.open(new SubProgressMonitor(monitor, 1000)); + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + } finally { + monitor.done(); + } return projectHandle; } @@ -157,8 +162,9 @@ public class ContainerGenerator { public IContainer generateContainer(IProgressMonitor monitor) throws CoreException { IDEWorkbenchPlugin.getPluginWorkspace().run(monitor1 -> { - SubMonitor subMonitor = SubMonitor.convert(monitor1, - IDEWorkbenchMessages.ContainerGenerator_progressMessage, containerFullPath.segmentCount()); + monitor1 + .beginTask( + IDEWorkbenchMessages.ContainerGenerator_progressMessage, 1000 * containerFullPath.segmentCount()); if (container != null) { return; } @@ -181,16 +187,18 @@ public class ContainerGenerator { throw new CoreException(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1, msg, null)); } container = (IContainer) resource; - subMonitor.worked(1); + monitor1.worked(1000); } else { if (i == 0) { IProject projectHandle = createProjectHandle(root, currentSegment); - container = createProject(projectHandle, subMonitor.newChild(1)); + container = createProject(projectHandle, + new SubProgressMonitor(monitor1, 1000)); } else { IFolder folderHandle = createFolderHandle( container, currentSegment); - container = createFolder(folderHandle, subMonitor.newChild(1)); + container = createFolder(folderHandle, + new SubProgressMonitor(monitor1, 1000)); } } } diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/WizardNewFolderMainPage.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/WizardNewFolderMainPage.java index 495e7e91827..fe601583021 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/WizardNewFolderMainPage.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/WizardNewFolderMainPage.java @@ -37,7 +37,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IMessageProvider; @@ -299,15 +299,14 @@ public class WizardNewFolderMainPage extends WizardPage implements Listener { @Deprecated protected void createFolder(IFolder folderHandle, IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, 100); - try { // Create the folder resource in the workspace // Update: Recursive to create any folders which do not exist // already if (!folderHandle.exists()) { if (linkTargetPath != null) { - folderHandle.createLink(linkTargetPath, IResource.ALLOW_MISSING_LOCAL, subMonitor.newChild(100)); + folderHandle.createLink(linkTargetPath, + IResource.ALLOW_MISSING_LOCAL, monitor); } else { IPath path = folderHandle.getFullPath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace() @@ -316,8 +315,6 @@ public class WizardNewFolderMainPage extends WizardPage implements Listener { if (numSegments > 2 && !root.getFolder(path.removeLastSegments(1)) .exists()) { - - SubMonitor loopProgress = subMonitor.newChild(90).setWorkRemaining(numSegments - 3); // If the direct parent of the path doesn't exist, try // to create the // necessary directories. @@ -325,25 +322,25 @@ public class WizardNewFolderMainPage extends WizardPage implements Listener { IFolder folder = root.getFolder(path .removeLastSegments(i)); if (!folder.exists()) { - folder.create(false, true, loopProgress.newChild(1)); + folder.create(false, true, monitor); } } } - subMonitor.setWorkRemaining(10); - folderHandle.create(false, true, subMonitor.newChild(10)); + folderHandle.create(false, true, monitor); } } } catch (CoreException e) { // If the folder already existed locally, just refresh to get // contents if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED) { - folderHandle.refreshLocal(IResource.DEPTH_INFINITE, subMonitor.setWorkRemaining(1).newChild(1)); + folderHandle.refreshLocal(IResource.DEPTH_INFINITE, + new SubProgressMonitor(monitor, 500)); } else { throw e; } } - if (subMonitor.isCanceled()) { + if (monitor.isCanceled()) { throw new OperationCanceledException(); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyProjectOperation.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyProjectOperation.java index c515118dad1..8053a11a7c8 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyProjectOperation.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyProjectOperation.java @@ -27,7 +27,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.ui.internal.ide.undo.ProjectDescription; import org.eclipse.ui.internal.ide.undo.UndoMessages; @@ -130,9 +130,9 @@ public class CopyProjectOperation extends AbstractCopyOrMoveResourcesOperation { @Override protected void doUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, 1); // Delete the project that was copied - WorkspaceUndoUtil.delete(resources, subMonitor.newChild(1), uiInfo, true); + WorkspaceUndoUtil.delete(resources, new SubProgressMonitor(monitor, 1), + uiInfo, true); // Set the target resource to the original setTargetResources(new IResource[] { originalProject }); setResourceDescriptions(new ResourceDescription[0]); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyResourcesOperation.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyResourcesOperation.java index 350de9925b9..8c4617c218e 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyResourcesOperation.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyResourcesOperation.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.ui.internal.ide.undo.UndoMessages; /** @@ -140,9 +140,9 @@ public class CopyResourcesOperation extends protected void copy(IProgressMonitor monitor, IAdaptable uiInfo) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, - resources.length + (resourceDescriptions != null ? resourceDescriptions.length : 0)); - subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress); + monitor.beginTask("", 2000); //$NON-NLS-1$ + monitor + .setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress); List resourcesAtDestination = new ArrayList(); List overwrittenResources = new ArrayList(); @@ -150,8 +150,11 @@ public class CopyResourcesOperation extends // Copy the resources and record the overwrites that would // be restored if this operation were reversed ResourceDescription[] overwrites; - overwrites = WorkspaceUndoUtil.copy(new IResource[] { resources[i] }, getDestinationPath(resources[i], i), - resourcesAtDestination, subMonitor.newChild(1), uiInfo, true, fCreateGroups, fCreateLinks, + overwrites = WorkspaceUndoUtil.copy( + new IResource[] { resources[i] }, getDestinationPath( + resources[i], i), resourcesAtDestination, + new SubProgressMonitor(monitor, 1000 / resources.length), + uiInfo, true, fCreateGroups, fCreateLinks, fRelativeToVariable); // Accumulate the overwrites into the full list for (int j = 0; j < overwrites.length; j++) { @@ -163,7 +166,9 @@ public class CopyResourcesOperation extends if (resourceDescriptions != null) { for (int i = 0; i < resourceDescriptions.length; i++) { if (resourceDescriptions[i] != null) { - resourceDescriptions[i].createResource(subMonitor.newChild(1)); + resourceDescriptions[i] + .createResource(new SubProgressMonitor(monitor, + 1000 / resourceDescriptions.length)); } } } @@ -176,6 +181,7 @@ public class CopyResourcesOperation extends // location. setTargetResources((IResource[]) resourcesAtDestination .toArray(new IResource[resourcesAtDestination.size()])); + monitor.done(); } /* @@ -185,12 +191,15 @@ public class CopyResourcesOperation extends @Override protected void doUndo(IProgressMonitor monitor, IAdaptable uiInfo) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, 2); - subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress); + monitor.beginTask("", 2); //$NON-NLS-1$ + monitor + .setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress); // undoing a copy is first deleting the copied resources... - WorkspaceUndoUtil.delete(resources, subMonitor.newChild(1), uiInfo, true); + WorkspaceUndoUtil.delete(resources, new SubProgressMonitor(monitor, 1), + uiInfo, true); // then restoring any overwritten by the previous copy... - WorkspaceUndoUtil.recreate(resourceDescriptions, subMonitor.newChild(1), uiInfo); + WorkspaceUndoUtil.recreate(resourceDescriptions, + new SubProgressMonitor(monitor, 1), uiInfo); setResourceDescriptions(new ResourceDescription[0]); // then setting the target resources back to the original ones. // Note that the destination paths never changed since they diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/MoveResourcesOperation.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/MoveResourcesOperation.java index 0b2f8413ae0..f4ab6c40821 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/MoveResourcesOperation.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/MoveResourcesOperation.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.ui.internal.ide.undo.UndoMessages; /** @@ -119,9 +119,10 @@ public class MoveResourcesOperation extends */ protected void move(IProgressMonitor monitor, IAdaptable uiInfo) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, - resources.length + (resourceDescriptions != null ? resourceDescriptions.length : 0)); - subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_MovingResources); + + monitor.beginTask("", 2000); //$NON-NLS-1$ + monitor + .setTaskName(UndoMessages.AbstractResourcesOperation_MovingResources); List resourcesAtDestination = new ArrayList(); List undoDestinationPaths = new ArrayList(); List overwrittenResources = new ArrayList(); @@ -130,8 +131,11 @@ public class MoveResourcesOperation extends // Move the resources and record the overwrites that would // be restored if this operation were reversed ResourceDescription[] overwrites; - overwrites = WorkspaceUndoUtil.move(new IResource[] { resources[i] }, getDestinationPath(resources[i], i), - resourcesAtDestination, undoDestinationPaths, subMonitor.newChild(1), uiInfo, true); + overwrites = WorkspaceUndoUtil.move( + new IResource[] { resources[i] }, getDestinationPath( + resources[i], i), resourcesAtDestination, + undoDestinationPaths, new SubProgressMonitor(monitor, + 1000 / resources.length), uiInfo, true); // Accumulate the overwrites into the full list for (int j = 0; j < overwrites.length; j++) { @@ -143,7 +147,9 @@ public class MoveResourcesOperation extends if (resourceDescriptions != null) { for (int i = 0; i < resourceDescriptions.length; i++) { if (resourceDescriptions[i] != null) { - resourceDescriptions[i].createResource(subMonitor.newChild(1)); + resourceDescriptions[i] + .createResource(new SubProgressMonitor(monitor, + 1000 / resourceDescriptions.length)); } } } @@ -160,6 +166,8 @@ public class MoveResourcesOperation extends destinationPaths = (IPath[]) undoDestinationPaths .toArray(new IPath[undoDestinationPaths.size()]); destination = null; + + monitor.done(); } /* diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/WorkspaceUndoUtil.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/WorkspaceUndoUtil.java index eca0776c73c..c9e05bd8566 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/WorkspaceUndoUtil.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/WorkspaceUndoUtil.java @@ -38,7 +38,7 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osgi.util.NLS; @@ -175,53 +175,63 @@ public class WorkspaceUndoUtil { * @throws CoreException * propagates any CoreExceptions thrown from the resources API */ - static ResourceDescription[] delete(IResource[] resourcesToDelete, IProgressMonitor mon, IAdaptable uiInfo, - boolean deleteContent) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(mon, resourcesToDelete.length); - - final List<CoreException> exceptions = new ArrayList<>(); + static ResourceDescription[] delete(IResource[] resourcesToDelete, + IProgressMonitor monitor, IAdaptable uiInfo, boolean deleteContent) + throws CoreException { + final List exceptions = new ArrayList(); boolean forceOutOfSyncDelete = false; ResourceDescription[] returnedResourceDescriptions = new ResourceDescription[resourcesToDelete.length]; - subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_DeleteResourcesProgress); - for (int i = 0; i < resourcesToDelete.length; ++i) { - if (subMonitor.isCanceled()) { - throw new OperationCanceledException(); - } - IResource resource = resourcesToDelete[i]; - try { - returnedResourceDescriptions[i] = delete(resource, subMonitor.newChild(1), uiInfo, - forceOutOfSyncDelete, deleteContent); - } catch (CoreException e) { - if (resource.getType() == IResource.FILE) { - IStatus[] children = e.getStatus().getChildren(); - if (children.length == 1 && children[0].getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) { - int result = queryDeleteOutOfSync(resource, uiInfo); - - if (result == IDialogConstants.YES_ID) { - // retry the delete with a force out of sync - delete(resource, subMonitor.newChild(1), uiInfo, true, deleteContent); - } else if (result == IDialogConstants.YES_TO_ALL_ID) { - // all future attempts should force out of - // sync - forceOutOfSyncDelete = true; - delete(resource, subMonitor.newChild(1), uiInfo, forceOutOfSyncDelete, - deleteContent); - } else if (result == IDialogConstants.CANCEL_ID) { - throw new OperationCanceledException(); + monitor.beginTask("", resourcesToDelete.length); //$NON-NLS-1$ + monitor + .setTaskName(UndoMessages.AbstractResourcesOperation_DeleteResourcesProgress); + try { + for (int i = 0; i < resourcesToDelete.length; ++i) { + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + IResource resource = resourcesToDelete[i]; + try { + returnedResourceDescriptions[i] = delete(resource, + new SubProgressMonitor(monitor, 1), uiInfo, + forceOutOfSyncDelete, deleteContent); + } catch (CoreException e) { + if (resource.getType() == IResource.FILE) { + IStatus[] children = e.getStatus().getChildren(); + if (children.length == 1 + && children[0].getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) { + int result = queryDeleteOutOfSync(resource, uiInfo); + + if (result == IDialogConstants.YES_ID) { + // retry the delete with a force out of sync + delete(resource, new SubProgressMonitor( + monitor, 1), uiInfo, true, + deleteContent); + } else if (result == IDialogConstants.YES_TO_ALL_ID) { + // all future attempts should force out of + // sync + forceOutOfSyncDelete = true; + delete(resource, new SubProgressMonitor( + monitor, 1), uiInfo, + forceOutOfSyncDelete, deleteContent); + } else if (result == IDialogConstants.CANCEL_ID) { + throw new OperationCanceledException(); + } else { + exceptions.add(e); + } } else { exceptions.add(e); } } else { exceptions.add(e); } - } else { - exceptions.add(e); } } - } - IStatus result = createResult(exceptions); - if (!result.isOK()) { - throw new CoreException(result); + IStatus result = createResult(exceptions); + if (!result.isOK()) { + throw new CoreException(result); + } + } finally { + monitor.done(); } return returnedResourceDescriptions; } @@ -257,8 +267,9 @@ public class WorkspaceUndoUtil { * @throws CoreException * propagates any CoreExceptions thrown from the resources API */ - static ResourceDescription[] copy(IResource[] resources, IPath destination, List<IResource> resourcesAtDestination, - IProgressMonitor monitor, IAdaptable uiInfo, boolean pathIncludesName) throws CoreException { + static ResourceDescription[] copy(IResource[] resources, IPath destination, + List resourcesAtDestination, IProgressMonitor monitor, + IAdaptable uiInfo, boolean pathIncludesName) throws CoreException { return copy(resources, destination, resourcesAtDestination, monitor, uiInfo, pathIncludesName, false, false, null); } @@ -307,14 +318,18 @@ public class WorkspaceUndoUtil { * @throws CoreException * propagates any CoreExceptions thrown from the resources API */ - static ResourceDescription[] copy(IResource[] resources, IPath destination, List<IResource> resourcesAtDestination, - IProgressMonitor monitor, IAdaptable uiInfo, boolean pathIncludesName, boolean createVirtual, - boolean createLinks, String relativeToVariable) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, resources.length); - subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress); - List<ResourceDescription> overwrittenResources = new ArrayList<>(); - for (IResource source : resources) { - SubMonitor iterationProgress = subMonitor.newChild(1).setWorkRemaining(100); + static ResourceDescription[] copy(IResource[] resources, IPath destination, + List resourcesAtDestination, IProgressMonitor monitor, + IAdaptable uiInfo, boolean pathIncludesName, boolean createVirtual, + boolean createLinks, String relativeToVariable) + throws CoreException { + + monitor.beginTask("", resources.length); //$NON-NLS-1$ + monitor + .setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress); + List overwrittenResources = new ArrayList(); + for (int i = 0; i < resources.length; i++) { + IResource source = resources[i]; IPath destinationPath; if (pathIncludesName) { destinationPath = destination; @@ -336,7 +351,7 @@ public class WorkspaceUndoUtil { children = filterNonLinkedResources(children); ResourceDescription[] overwritten = copy(children, destinationPath, resourcesAtDestination, - iterationProgress, uiInfo, false, + new SubProgressMonitor(monitor, 1), uiInfo, false, createVirtual, createLinks, relativeToVariable); // We don't record the copy since this recursive call will // do so. Just record the overwrites. @@ -346,28 +361,37 @@ public class WorkspaceUndoUtil { } else { // delete the destination folder, copying a linked folder // over an unlinked one or vice versa. Fixes bug 28772. - ResourceDescription[] deleted = delete(new IResource[] { existing }, iterationProgress.newChild(1), - uiInfo, false); - iterationProgress.setWorkRemaining(100); - if ((createLinks || createVirtual) && (source.isLinked() == false) + ResourceDescription[] deleted = delete( + new IResource[] { existing }, + new SubProgressMonitor(monitor, 0), uiInfo, false); + if ((createLinks || createVirtual) + && (source.isLinked() == false) && (source.isVirtual() == false)) { IFolder folder = workspaceRoot.getFolder(destinationPath); if (createVirtual) { - folder.create(IResource.VIRTUAL, true, iterationProgress.newChild(1)); - IResource[] members = ((IContainer) source).members(); + folder.create(IResource.VIRTUAL, true, + new SubProgressMonitor(monitor, 1)); + IResource[] members = ((IContainer) source) + .members(); if (members.length > 0) { - overwrittenResources.addAll(Arrays.asList(copy(members, destinationPath, - resourcesAtDestination, iterationProgress.newChild(99), uiInfo, false, - createVirtual, createLinks, relativeToVariable))); + overwrittenResources.addAll(Arrays.asList(copy( + members, destinationPath, + resourcesAtDestination, + new SubProgressMonitor(monitor, 1), + uiInfo, false, createVirtual, + createLinks, relativeToVariable))); } } else - folder.createLink(createRelativePath(source.getLocationURI(), relativeToVariable, folder), - 0, iterationProgress.newChild(100)); + folder.createLink(createRelativePath(source + .getLocationURI(), relativeToVariable, folder), 0, + new SubProgressMonitor(monitor, 1)); } else - source.copy(destinationPath, IResource.SHALLOW, iterationProgress.newChild(100)); + source.copy(destinationPath, IResource.SHALLOW, + new SubProgressMonitor(monitor, 1)); // Record the copy - resourcesAtDestination.add(getWorkspace().getRoot().findMember(destinationPath)); + resourcesAtDestination.add(getWorkspace().getRoot() + .findMember(destinationPath)); for (int j = 0; j < deleted.length; j++) { overwrittenResources.add(deleted[j]); } @@ -381,29 +405,37 @@ public class WorkspaceUndoUtil { // destination ResourceDescription[] deleted = delete( new IResource[] { existing }, - iterationProgress.newChild(1), uiInfo, + new SubProgressMonitor(monitor, 0), uiInfo, false); - iterationProgress.setWorkRemaining(100); if (source.getType() == IResource.FILE) { IFile file = workspaceRoot.getFile(destinationPath); file.createLink(createRelativePath( source.getLocationURI(), relativeToVariable, file), 0, - iterationProgress.newChild(100)); + new SubProgressMonitor(monitor, 1)); } else { IFolder folder = workspaceRoot .getFolder(destinationPath); if (createVirtual) { - folder.create(IResource.VIRTUAL, true, iterationProgress.newChild(1)); - IResource[] members = ((IContainer) source).members(); + folder.create(IResource.VIRTUAL, true, + new SubProgressMonitor(monitor, 1)); + IResource[] members = ((IContainer) source) + .members(); if (members.length > 0) { - overwrittenResources.addAll(Arrays.asList(copy(members, destinationPath, - resourcesAtDestination, iterationProgress.newChild(99), uiInfo, false, - createVirtual, createLinks, relativeToVariable))); + overwrittenResources.addAll(Arrays + .asList(copy(members, + destinationPath, + resourcesAtDestination, + new SubProgressMonitor( + monitor, 1), + uiInfo, false, + createVirtual, createLinks, + relativeToVariable))); + } } else - folder.createLink( - createRelativePath(source.getLocationURI(), relativeToVariable, folder), 0, - iterationProgress.newChild(100)); + folder.createLink(createRelativePath( + source.getLocationURI(), relativeToVariable, folder), + 0, new SubProgressMonitor(monitor, 1)); } resourcesAtDestination.add(getWorkspace().getRoot() .findMember(destinationPath)); @@ -412,8 +444,9 @@ public class WorkspaceUndoUtil { } } else { if (source.isLinked() == existing.isLinked()) { - overwrittenResources.add(copyOverExistingResource(source, existing, - iterationProgress.newChild(100), uiInfo, false)); + overwrittenResources.add(copyOverExistingResource( + source, existing, new SubProgressMonitor( + monitor, 1), uiInfo, false)); // Record the "copy" resourcesAtDestination.add(existing); } else { @@ -422,9 +455,10 @@ public class WorkspaceUndoUtil { // 28772. ResourceDescription[] deleted = delete( new IResource[] { existing }, - iterationProgress.newChild(1), uiInfo, + new SubProgressMonitor(monitor, 0), uiInfo, false); - source.copy(destinationPath, IResource.SHALLOW, iterationProgress.newChild(99)); + source.copy(destinationPath, IResource.SHALLOW, + new SubProgressMonitor(monitor, 1)); // Record the copy resourcesAtDestination.add(getWorkspace().getRoot() .findMember(destinationPath)); @@ -448,25 +482,33 @@ public class WorkspaceUndoUtil { IFile file = workspaceRoot.getFile(destinationPath); file.createLink(createRelativePath( source.getLocationURI(), relativeToVariable, file), 0, - iterationProgress.newChild(100)); + new SubProgressMonitor(monitor, 1)); } else { IFolder folder = workspaceRoot .getFolder(destinationPath); if (createVirtual) { - folder.create(IResource.VIRTUAL, true, iterationProgress.newChild(1)); + folder.create(IResource.VIRTUAL, true, + new SubProgressMonitor(monitor, 1)); IResource[] members = ((IContainer) source).members(); if (members.length > 0) { - overwrittenResources.addAll(Arrays.asList(copy(members, destinationPath, - resourcesAtDestination, iterationProgress.newChild(99), uiInfo, false, - createVirtual, createLinks, relativeToVariable))); + overwrittenResources.addAll(Arrays + .asList(copy(members, + destinationPath, + resourcesAtDestination, + new SubProgressMonitor( + monitor, 1), + uiInfo, false, + createVirtual, createLinks, + relativeToVariable))); + } } else - folder.createLink( - createRelativePath(source.getLocationURI(), relativeToVariable, folder), 0, - iterationProgress.newChild(100)); + folder.createLink(createRelativePath(source.getLocationURI(), relativeToVariable, folder), + 0, new SubProgressMonitor(monitor, 1)); } } else - source.copy(destinationPath, IResource.SHALLOW, iterationProgress.newChild(100)); + source.copy(destinationPath, IResource.SHALLOW, + new SubProgressMonitor(monitor, 1)); // Record the copy. If we had to generate a parent // folder, that should be recorded as part of the copy if (generatedParent == null) { @@ -477,12 +519,13 @@ public class WorkspaceUndoUtil { } } - if (subMonitor.isCanceled()) { + if (monitor.isCanceled()) { throw new OperationCanceledException(); } } } - return overwrittenResources + monitor.done(); + return (ResourceDescription[]) overwrittenResources .toArray(new ResourceDescription[overwrittenResources.size()]); } @@ -521,13 +564,13 @@ public class WorkspaceUndoUtil { * A list used to record each moved resource. * @param reverseDestinations * A list used to record each moved resource's original location - * @param mon + * @param monitor * the progress monitor used to show progress * @param uiInfo - * the IAdaptable (or <code>null</code>) provided by the caller - * in order to supply UI information for prompting the user if - * necessary. When this parameter is not <code>null</code>, it - * contains an adapter for the + * the IAdaptable (or <code>null</code>) provided by the + * caller in order to supply UI information for prompting the + * user if necessary. When this parameter is not + * <code>null</code>, it contains an adapter for the * org.eclipse.swt.widgets.Shell.class * @param pathIncludesName * a boolean that indicates whether the specified path includes @@ -541,15 +584,16 @@ public class WorkspaceUndoUtil { * @throws CoreException * propagates any CoreExceptions thrown from the resources API */ - static ResourceDescription[] move(IResource[] resources, IPath destination, List<IResource> resourcesAtDestination, - List<IPath> reverseDestinations, IProgressMonitor mon, IAdaptable uiInfo, boolean pathIncludesName) - throws CoreException { + static ResourceDescription[] move(IResource[] resources, IPath destination, + List resourcesAtDestination, List reverseDestinations, + IProgressMonitor monitor, IAdaptable uiInfo, + boolean pathIncludesName) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(mon, resources.length); - subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_MovingResources); - List<ResourceDescription> overwrittenResources = new ArrayList<>(); + monitor.beginTask("", resources.length); //$NON-NLS-1$ + monitor + .setTaskName(UndoMessages.AbstractResourcesOperation_MovingResources); + List overwrittenResources = new ArrayList(); for (int i = 0; i < resources.length; i++) { - SubMonitor iterationProgress = subMonitor.newChild(1); IResource source = resources[i]; IPath destinationPath; if (pathIncludesName) { @@ -563,31 +607,36 @@ public class WorkspaceUndoUtil { // The resource is a folder and it exists in the destination. // Move its children to the existing destination. if (source.isLinked() == existing.isLinked()) { - IResource[] children = ((IContainer) source).members(); - // move only linked resource children (267173) - if (source.isLinked() && source.getLocation().equals(existing.getLocation())) - children = filterNonLinkedResources(children); - ResourceDescription[] overwritten = move(children, destinationPath, resourcesAtDestination, - reverseDestinations, iterationProgress.newChild(90), uiInfo, false); - // We don't record the moved resources since the recursive - // call has done so. Just record the overwrites. - for (int j = 0; j < overwritten.length; j++) { - overwrittenResources.add(overwritten[j]); - } + IResource[] children = ((IContainer) source).members(); + // move only linked resource children (267173) + if (source.isLinked() && source.getLocation().equals(existing.getLocation())) + children = filterNonLinkedResources(children); + ResourceDescription[] overwritten = move(children, + destinationPath, resourcesAtDestination, + reverseDestinations, new SubProgressMonitor( + monitor, 1), uiInfo, false); + // We don't record the moved resources since the recursive + // call has done so. Just record the overwrites. + for (int j = 0; j < overwritten.length; j++) { + overwrittenResources.add(overwritten[j]); + } // Delete the source. No need to record it since it // will get moved back. - delete(source, iterationProgress.newChild(10), uiInfo, false, false); + delete(source, monitor, uiInfo, false, false); } else { // delete the destination folder, moving a linked folder // over an unlinked one or vice versa. Fixes bug 28772. - ResourceDescription[] deleted = delete(new IResource[] { existing }, iterationProgress.newChild(10), - uiInfo, false); + ResourceDescription[] deleted = delete( + new IResource[] { existing }, + new SubProgressMonitor(monitor, 0), uiInfo, false); // Record the original path reverseDestinations.add(source.getFullPath()); - source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY, - iterationProgress.newChild(90)); + source.move(destinationPath, IResource.SHALLOW + | IResource.KEEP_HISTORY, new SubProgressMonitor( + monitor, 1)); // Record the resource at its destination - resourcesAtDestination.add(getWorkspace().getRoot().findMember(destinationPath)); + resourcesAtDestination.add(getWorkspace().getRoot() + .findMember(destinationPath)); for (int j = 0; j < deleted.length; j++) { overwrittenResources.add(deleted[j]); } @@ -597,20 +646,21 @@ public class WorkspaceUndoUtil { if (source.isLinked() == existing.isLinked()) { // Record the original path reverseDestinations.add(source.getFullPath()); - overwrittenResources.add(copyOverExistingResource(source, existing, - iterationProgress.newChild(100), uiInfo, true)); + overwrittenResources.add(copyOverExistingResource( + source, existing, new SubProgressMonitor( + monitor, 1), uiInfo, true)); resourcesAtDestination.add(existing); } else { // Moving a linked resource over unlinked or vice // versa. Can't use setContents here. Fixes bug 28772. ResourceDescription[] deleted = delete( new IResource[] { existing }, - iterationProgress.newChild(1), uiInfo, + new SubProgressMonitor(monitor, 0), uiInfo, false); reverseDestinations.add(source.getFullPath()); source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY, - iterationProgress.newChild(99)); + new SubProgressMonitor(monitor, 1)); // Record the resource at its destination resourcesAtDestination.add(getWorkspace().getRoot() .findMember(destinationPath)); @@ -629,8 +679,9 @@ public class WorkspaceUndoUtil { } IContainer generatedParent = generateContainers(parentPath); - source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY, - iterationProgress.newChild(100)); + source.move(destinationPath, IResource.SHALLOW + | IResource.KEEP_HISTORY, new SubProgressMonitor( + monitor, 1)); // Record the move. If we had to generate a parent // folder, that should be recorded as part of the copy if (generatedParent == null) { @@ -641,12 +692,13 @@ public class WorkspaceUndoUtil { } } - if (subMonitor.isCanceled()) { + if (monitor.isCanceled()) { throw new OperationCanceledException(); } } } - return overwrittenResources + monitor.done(); + return (ResourceDescription[]) overwrittenResources .toArray(new ResourceDescription[overwrittenResources.size()]); } @@ -657,12 +709,12 @@ public class WorkspaceUndoUtil { * @return The linked resources */ private static IResource[] filterNonLinkedResources(IResource[] resources) { - List<IResource> result = new ArrayList<>(); + List result = new ArrayList(); for (int i = 0; i < resources.length; i++) { if (resources[i].isLinked()) result.add(resources[i]); } - return result.toArray(new IResource[0]); + return (IResource[]) result.toArray(new IResource[0]); } /** @@ -684,23 +736,29 @@ public class WorkspaceUndoUtil { */ static IResource[] recreate(ResourceDescription[] resourcesToRecreate, IProgressMonitor monitor, IAdaptable uiInfo) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, resourcesToRecreate.length); - final List<CoreException> exceptions = new ArrayList<>(); + final List exceptions = new ArrayList(); IResource[] resourcesToReturn = new IResource[resourcesToRecreate.length]; - subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_CreateResourcesProgress); - for (int i = 0; i < resourcesToRecreate.length; ++i) { - if (monitor.isCanceled()) { - throw new OperationCanceledException(); + monitor.beginTask("", resourcesToRecreate.length); //$NON-NLS-1$ + monitor + .setTaskName(UndoMessages.AbstractResourcesOperation_CreateResourcesProgress); + try { + for (int i = 0; i < resourcesToRecreate.length; ++i) { + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + try { + resourcesToReturn[i] = resourcesToRecreate[i] + .createResource(new SubProgressMonitor(monitor, 1)); + } catch (CoreException e) { + exceptions.add(e); + } } - try { - resourcesToReturn[i] = resourcesToRecreate[i].createResource(subMonitor.newChild(1)); - } catch (CoreException e) { - exceptions.add(e); + IStatus result = WorkspaceUndoUtil.createResult(exceptions); + if (!result.isOK()) { + throw new CoreException(result); } - } - IStatus result = WorkspaceUndoUtil.createResult(exceptions); - if (!result.isOK()) { - throw new CoreException(result); + } finally { + monitor.done(); } return resourcesToReturn; } @@ -734,18 +792,17 @@ public class WorkspaceUndoUtil { IProgressMonitor monitor, IAdaptable uiInfo, boolean forceOutOfSyncDelete, boolean deleteContent) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor); ResourceDescription resourceDescription = ResourceDescription .fromResource(resourceToDelete); if (resourceToDelete.getType() == IResource.PROJECT) { // it is a project - subMonitor + monitor .setTaskName(UndoMessages.AbstractResourcesOperation_DeleteResourcesProgress); IProject project = (IProject) resourceToDelete; - project.delete(deleteContent, forceOutOfSyncDelete, subMonitor); + project.delete(deleteContent, forceOutOfSyncDelete, monitor); } else { // if it's not a project, just delete it - subMonitor.setWorkRemaining(2); + monitor.beginTask("", 2); //$NON-NLS-1$ monitor .setTaskName(UndoMessages.AbstractResourcesOperation_DeleteResourcesProgress); int updateFlags; @@ -754,8 +811,11 @@ public class WorkspaceUndoUtil { } else { updateFlags = IResource.KEEP_HISTORY; } - resourceToDelete.delete(updateFlags, subMonitor.newChild(1)); - resourceDescription.recordStateFromHistory(resourceToDelete, subMonitor.newChild(1)); + resourceToDelete.delete(updateFlags, new SubProgressMonitor( + monitor, 1)); + resourceDescription.recordStateFromHistory(resourceToDelete, + new SubProgressMonitor(monitor, 1)); + monitor.done(); } return resourceDescription; @@ -774,26 +834,35 @@ public class WorkspaceUndoUtil { } IFile file = (IFile) source; IFile existingFile = (IFile) existing; - SubMonitor subMonitor = SubMonitor.convert(monitor, - UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress, deleteSourceFile ? 3 : 2); + monitor + .beginTask( + UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress, + 3); if (file != null && existingFile != null) { if (validateEdit(file, existingFile, getShell(uiInfo))) { // Remember the state of the existing file so it can be // restored. - FileDescription fileDescription = new FileDescription(existingFile); + FileDescription fileDescription = new FileDescription( + existingFile); // Reset the contents to that of the file being moved - existingFile.setContents(file.getContents(), IResource.KEEP_HISTORY, subMonitor.newChild(1)); - fileDescription.recordStateFromHistory(existingFile, subMonitor.newChild(1)); + existingFile.setContents(file.getContents(), + IResource.KEEP_HISTORY, new SubProgressMonitor(monitor, + 1)); + fileDescription.recordStateFromHistory(existingFile, + new SubProgressMonitor(monitor, 1)); // Now delete the source file if requested // We don't need to remember anything about it, because // any undo involving this operation will move the original // content back to it. if (deleteSourceFile) { - file.delete(IResource.KEEP_HISTORY, subMonitor.newChild(1)); + file.delete(IResource.KEEP_HISTORY, new SubProgressMonitor( + monitor, 1)); } + monitor.done(); return fileDescription; } } + monitor.done(); return null; } @@ -877,15 +946,15 @@ public class WorkspaceUndoUtil { * Creates and return a result status appropriate for the given list of * exceptions. */ - private static IStatus createResult(List<CoreException> exceptions) { + private static IStatus createResult(List exceptions) { if (exceptions.isEmpty()) { return Status.OK_STATUS; } final int exceptionCount = exceptions.size(); if (exceptionCount == 1) { - return exceptions.get(0).getStatus(); + return ((CoreException) exceptions.get(0)).getStatus(); } - CoreException[] children = exceptions + CoreException[] children = (CoreException[]) exceptions .toArray(new CoreException[exceptionCount]); boolean outOfSync = false; for (int i = 0; i < children.length; i++) { diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/CleanDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/CleanDialog.java index 026f21409af..c40614f4d9e 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/CleanDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/CleanDialog.java @@ -27,7 +27,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.MessageDialog; @@ -313,10 +313,15 @@ public class CleanDialog extends MessageDialog { if (cleanAll) { ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, monitor); } else { - SubMonitor subMonitor = SubMonitor.convert(monitor, IDEWorkbenchMessages.CleanDialog_cleanSelectedTaskName, - selection.length); - for (int i = 0; i < selection.length; i++) { - ((IProject) selection[i]).build(IncrementalProjectBuilder.CLEAN_BUILD, subMonitor.newChild(1)); + try { + monitor.beginTask(IDEWorkbenchMessages.CleanDialog_cleanSelectedTaskName, selection.length); + for (int i = 0; i < selection.length; i++) { + ((IProject) selection[i]).build( + IncrementalProjectBuilder.CLEAN_BUILD, + new SubProgressMonitor(monitor, 1)); + } + } finally { + monitor.done(); } } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/LinkedResourceEditor.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/LinkedResourceEditor.java index f68dcdc60ad..3977153b39c 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/LinkedResourceEditor.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/LinkedResourceEditor.java @@ -32,7 +32,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -545,24 +545,30 @@ return true; IDEWorkbenchMessages.LinkedResourceEditor_removeTitle, IDEWorkbenchMessages.LinkedResourceEditor_removeMessage)) { final IResource[] selectedResources = getSelectedResource(); - final ArrayList<IResource> removedResources = new ArrayList<>(); + final ArrayList/*<IResource>*/ removedResources = new ArrayList(); IRunnableWithProgress op = monitor -> { - SubMonitor subMonitor = SubMonitor.convert(monitor, - IDEWorkbenchMessages.LinkedResourceEditor_removingMessage, selectedResources.length); - for (int i = 0; i < selectedResources.length; i++) { - if (subMonitor.isCanceled()) - break; - String fullPath = selectedResources[i].getFullPath().toPortableString(); - try { - selectedResources[i].delete(true, subMonitor.newChild(1)); - removedResources.add(selectedResources[i]); - fBrokenResources.remove(fullPath); - fFixedResources.remove(fullPath); - fAbsoluteResources.remove(fullPath); - } catch (CoreException e) { - e.printStackTrace(); + try { + monitor.beginTask( + IDEWorkbenchMessages.LinkedResourceEditor_removingMessage, + selectedResources.length); + for (int i = 0; i < selectedResources.length; i++) { + if (monitor.isCanceled()) + break; + String fullPath = selectedResources[i] + .getFullPath().toPortableString(); + try { + selectedResources[i].delete(true, new SubProgressMonitor(monitor, 1)); + removedResources.add(selectedResources[i]); + fBrokenResources.remove(fullPath); + fFixedResources.remove(fullPath); + fAbsoluteResources.remove(fullPath); + } catch (CoreException e) { + e.printStackTrace(); + } } + } finally { + monitor.done(); } }; try { diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkingSetResourceMapping.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkingSetResourceMapping.java index ad34cd06e8a..fc5a713f7d5 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkingSetResourceMapping.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkingSetResourceMapping.java @@ -25,7 +25,8 @@ import org.eclipse.core.resources.mapping.ResourceTraversal; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.ui.IWorkingSet; /** @@ -55,7 +56,7 @@ public class WorkingSetResourceMapping extends ResourceMapping { @Override public IProject[] getProjects() { - Set<IProject> result = new HashSet<>(); + Set result = new HashSet(); ResourceMapping[] mappings = getMappings(); for (int i = 0; i < mappings.length; i++) { ResourceMapping mapping = mappings[i]; @@ -65,21 +66,25 @@ public class WorkingSetResourceMapping extends ResourceMapping { result.add(project); } } - return result.toArray(new IProject[result.size()]); + return (IProject[]) result.toArray(new IProject[result.size()]); } @Override - public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor mon) - throws CoreException { - ResourceMapping[] mappings = getMappings(); - SubMonitor subMonitor = SubMonitor.convert(mon, mappings.length); - - List<ResourceTraversal> result = new ArrayList<>(); - for (int i = 0; i < mappings.length; i++) { - ResourceMapping mapping = mappings[i]; - result.addAll(Arrays.asList(mapping.getTraversals(context, subMonitor.newChild(1)))); + public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException { + if (monitor == null) + monitor = new NullProgressMonitor(); + try { + ResourceMapping[] mappings = getMappings(); + monitor.beginTask("", 100 * mappings.length); //$NON-NLS-1$ + List result = new ArrayList(); + for (int i = 0; i < mappings.length; i++) { + ResourceMapping mapping = mappings[i]; + result.addAll(Arrays.asList(mapping.getTraversals(context, new SubProgressMonitor(monitor, 100)))); + } + return (ResourceTraversal[]) result.toArray(new ResourceTraversal[result.size()]); + } finally { + monitor.done(); } - return result.toArray(new ResourceTraversal[result.size()]); } /** @@ -88,7 +93,7 @@ public class WorkingSetResourceMapping extends ResourceMapping { */ private ResourceMapping[] getMappings() { IAdaptable[] elements = set.getElements(); - List<ResourceMapping> result = new ArrayList<>(); + List result = new ArrayList(); for (int i = 0; i < elements.length; i++) { IAdaptable element = elements[i]; ResourceMapping mapping = WorkingSetAdapterFactory.getContributedResourceMapping(element); @@ -99,7 +104,7 @@ public class WorkingSetResourceMapping extends ResourceMapping { result.add(mapping); } } - return result.toArray(new ResourceMapping[result.size()]); + return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]); } @Override diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ContainerDescription.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ContainerDescription.java index b4d55cbef61..e23033b0fef 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ContainerDescription.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ContainerDescription.java @@ -24,7 +24,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.ui.ide.dialogs.UIResourceFilterDescription; import org.eclipse.ui.ide.undo.ResourceDescription; @@ -176,42 +176,48 @@ public abstract class ContainerDescription extends AbstractResourceDescription { * the handle of the created parent * @param monitor * the progress monitor to be used + * @param ticks + * the number of ticks allocated for creating children * @throws CoreException */ - protected final void createChildResources(IContainer parentHandle, - IProgressMonitor monitor) throws CoreException { + protected void createChildResources(IContainer parentHandle, + IProgressMonitor monitor, int ticks) throws CoreException { + // restore any children if (members != null && members.length > 0) { - SubMonitor subMonitor = SubMonitor.convert(monitor, members.length); for (int i = 0; i < members.length; i++) { members[i].parent = parentHandle; - members[i].createResource(subMonitor.newChild(1)); + members[i].createResource(new SubProgressMonitor(monitor, ticks + / members.length)); } } } @Override - public void recordStateFromHistory(IResource resource, IProgressMonitor mon) throws CoreException { + public void recordStateFromHistory(IResource resource, + IProgressMonitor monitor) throws CoreException { + monitor.beginTask( + UndoMessages.FolderDescription_SavingUndoInfoProgress, 100); if (members != null) { - SubMonitor subMonitor = SubMonitor.convert(mon, UndoMessages.FolderDescription_SavingUndoInfoProgress, - members.length); for (int i = 0; i < members.length; i++) { - SubMonitor iterationMonitor = subMonitor.newChild(1); if (members[i] instanceof FileDescription) { IPath path = resource.getFullPath().append( ((FileDescription) members[i]).name); IFile fileHandle = resource.getWorkspace().getRoot().getFile( path); - members[i].recordStateFromHistory(fileHandle, iterationMonitor); + members[i].recordStateFromHistory(fileHandle, + new SubProgressMonitor(monitor, 100 / members.length)); } else if (members[i] instanceof FolderDescription) { IPath path = resource.getFullPath().append( ((FolderDescription) members[i]).name); IFolder folderHandle = resource.getWorkspace().getRoot() .getFolder(path); - members[i].recordStateFromHistory(folderHandle, iterationMonitor); + members[i].recordStateFromHistory(folderHandle, + new SubProgressMonitor(monitor, 100 / members.length)); } } } + monitor.done(); } /** diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FileDescription.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FileDescription.java index 8785d37bc8a..e7f4ec67024 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FileDescription.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FileDescription.java @@ -25,7 +25,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; /** * FileDescription is a lightweight description that describes a file to be @@ -132,21 +132,23 @@ public class FileDescription extends AbstractResourceDescription { } @Override - public void createExistentResourceFromHandle(IResource resource, IProgressMonitor mon) throws CoreException { + public void createExistentResourceFromHandle(IResource resource, + IProgressMonitor monitor) throws CoreException { Assert.isLegal(resource instanceof IFile); if (resource.exists()) { return; } IFile fileHandle = (IFile) resource; - SubMonitor subMonitor = SubMonitor.convert(mon, 200); - subMonitor.setTaskName(UndoMessages.FileDescription_NewFileProgress); + monitor.beginTask("", 200); //$NON-NLS-1$ + monitor.setTaskName(UndoMessages.FileDescription_NewFileProgress); try { - if (subMonitor.isCanceled()) { + if (monitor.isCanceled()) { throw new OperationCanceledException(); } if (location != null) { - fileHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, subMonitor.newChild(200)); + fileHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, + new SubProgressMonitor(monitor, 200)); } else { InputStream contents = new ByteArrayInputStream( UndoMessages.FileDescription_ContentsCouldNotBeRestored @@ -159,10 +161,12 @@ public class FileDescription extends AbstractResourceDescription { && fileContentDescription.exists()) { contents = fileContentDescription.getContents(); } - fileHandle.create(contents, false, subMonitor.newChild(100)); - fileHandle.setCharset(charset, subMonitor.newChild(100)); + fileHandle.create(contents, false, new SubProgressMonitor( + monitor, 100)); + fileHandle.setCharset(charset, new SubProgressMonitor(monitor, + 100)); } - if (subMonitor.isCanceled()) { + if (monitor.isCanceled()) { throw new OperationCanceledException(); } } catch (CoreException e) { @@ -171,6 +175,8 @@ public class FileDescription extends AbstractResourceDescription { } else { throw e; } + } finally { + monitor.done(); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FolderDescription.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FolderDescription.java index e0a8e7de9e4..305007b8812 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FolderDescription.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FolderDescription.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; /** * FolderDescription is a lightweight description that describes a folder to be @@ -75,33 +75,41 @@ public class FolderDescription extends ContainerDescription { } @Override - public void createExistentResourceFromHandle(IResource resource, IProgressMonitor mon) throws CoreException { + public void createExistentResourceFromHandle(IResource resource, + IProgressMonitor monitor) throws CoreException { + Assert.isLegal(resource instanceof IFolder); if (resource.exists()) { return; } IFolder folderHandle = (IFolder) resource; - SubMonitor subMonitor = SubMonitor.convert(mon, 300); - subMonitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress); - if (subMonitor.isCanceled()) { - throw new OperationCanceledException(); - } - if (filters != null) { - SubMonitor loopMonitor = subMonitor.newChild(100).setWorkRemaining(filters.length); - for (int i = 0; i < filters.length; i++) { - folderHandle.createFilter(filters[i].getType(), filters[i].getFileInfoMatcherDescription(), 0, - loopMonitor.newChild(1)); + try { + monitor.beginTask("", 200); //$NON-NLS-1$ + monitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress); + if (monitor.isCanceled()) { + throw new OperationCanceledException(); } + if (filters != null) { + for (int i = 0; i < filters.length; i++) { + folderHandle.createFilter(filters[i].getType(), filters[i].getFileInfoMatcherDescription(), 0, new SubProgressMonitor( + monitor, 100)); + } + } + if (location != null) { + folderHandle.createLink(location, + IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor( + monitor, 100)); + } else { + folderHandle.create(virtual ? IResource.VIRTUAL:0, true, new SubProgressMonitor( + monitor, 100)); + } + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + createChildResources(folderHandle, monitor, 100); + + } finally { + monitor.done(); } - subMonitor.setWorkRemaining(200); - if (location != null) { - folderHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, subMonitor.newChild(100)); - } else { - folderHandle.create(virtual ? IResource.VIRTUAL : 0, true, subMonitor.newChild(100)); - } - if (subMonitor.isCanceled()) { - throw new OperationCanceledException(); - } - createChildResources(folderHandle, subMonitor.newChild(100)); } }
\ No newline at end of file diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ProjectDescription.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ProjectDescription.java index b36ccb1fad2..862dc9535bb 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ProjectDescription.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ProjectDescription.java @@ -19,7 +19,7 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; /** * ProjectDescription is a lightweight description that describes a project to @@ -79,25 +79,28 @@ public class ProjectDescription extends ContainerDescription { @Override public void createExistentResourceFromHandle(IResource resource, IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, 200); Assert.isLegal(resource instanceof IProject); if (resource.exists()) { return; } IProject projectHandle = (IProject) resource; - subMonitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress); + monitor.beginTask("", 200); //$NON-NLS-1$ + monitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress); if (projectDescription == null) { - projectHandle.create(subMonitor.newChild(100)); + projectHandle.create(new SubProgressMonitor(monitor, 100)); } else { - projectHandle.create(projectDescription, subMonitor.newChild(100)); + projectHandle.create(projectDescription, new SubProgressMonitor( + monitor, 100)); } - if (subMonitor.isCanceled()) { + if (monitor.isCanceled()) { throw new OperationCanceledException(); } if (openOnCreate) { - projectHandle.open(IResource.NONE, subMonitor.newChild(100)); + projectHandle.open(IResource.NONE, + new SubProgressMonitor(monitor, 100)); } + monitor.done(); } @Override diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkCompletedHandler.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkCompletedHandler.java index 3459bef96db..1e2f39a9e1c 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkCompletedHandler.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkCompletedHandler.java @@ -18,7 +18,7 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.undo.UpdateMarkersOperation; import org.eclipse.ui.internal.ide.StatusUtil; @@ -40,8 +40,8 @@ public class MarkCompletedHandler extends MarkerViewHandler { final ExecutionEvent finalEvent = event; try { - PlatformUI.getWorkbench().getProgressService().run(true, true, mon -> { - SubMonitor subMonitor = SubMonitor.convert(mon, MarkerMessages.markCompletedHandler_task, 100); + PlatformUI.getWorkbench().getProgressService().run(true, true, monitor -> { + monitor.beginTask(MarkerMessages.markCompletedHandler_task, 100); IMarker[] markers = getSelectedMarkers(finalEvent); if (markers.length == 0) { return; @@ -52,11 +52,12 @@ public class MarkCompletedHandler extends MarkerViewHandler { IUndoableOperation op = new UpdateMarkersOperation(markers, attrs, MarkerMessages.markCompletedAction_title, true); - subMonitor.worked(20); - if (subMonitor.isCanceled()) { + monitor.worked(20); + if(monitor.isCanceled()) { return; } - execute(op, MarkerMessages.markCompletedAction_title, subMonitor.newChild(80), null); + execute(op, MarkerMessages.markCompletedAction_title, new SubProgressMonitor(monitor, 80), null); + monitor.done(); }); } catch (InvocationTargetException e) { StatusManager.getManager().handle( diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixWizard.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixWizard.java index d4ca28c62f7..7ee6e58161d 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixWizard.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixWizard.java @@ -17,7 +17,7 @@ import java.util.Map; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.Wizard; @@ -68,20 +68,23 @@ class QuickFixWizard extends Wizard { @Override public boolean performFinish() { - IRunnableWithProgress finishRunnable = mon -> { - IWizardPage[] pages = getPages(); - SubMonitor subMonitor = SubMonitor.convert(mon, MarkerMessages.MarkerResolutionDialog_Fixing, - (10 * pages.length) + 1); - subMonitor.worked(1); - for (int i = 0; i < pages.length; i++) { - // Allow for cancel event processing - getShell().getDisplay().readAndDispatch(); - if (subMonitor.isCanceled()) - return; - QuickFixPage wizardPage = (QuickFixPage) pages[i]; - wizardPage.performFinish(subMonitor.newChild(10)); - } - }; + IRunnableWithProgress finishRunnable = monitor -> { + IWizardPage[] pages = getPages(); + monitor.beginTask(MarkerMessages.MarkerResolutionDialog_Fixing, + (10 * pages.length) + 1); + monitor.worked(1); + for (int i = 0; i < pages.length; i++) { + //Allow for cancel event processing + getShell().getDisplay().readAndDispatch(); + if(monitor.isCanceled()) + return; + QuickFixPage wizardPage = (QuickFixPage) pages[i]; + wizardPage.performFinish(new SubProgressMonitor(monitor,10)); + monitor.worked(1); + } + monitor.done(); + +}; try { getContainer().run(false, true, finishRunnable); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardProjectsImportPage.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardProjectsImportPage.java index 56d407980bf..a42a7fe6a24 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardProjectsImportPage.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardProjectsImportPage.java @@ -54,7 +54,7 @@ import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogSettings; @@ -1186,23 +1186,28 @@ public class WizardProjectsImportPage extends WizardDataTransferPage { saveWidgetValues(); final Object[] selected = projectsList.getCheckedElements(); - createdProjects = new ArrayList<>(); + createdProjects = new ArrayList(); WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override - protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - SubMonitor subMonitor = SubMonitor.convert(monitor, selected.length); - if (subMonitor.isCanceled()) { - throw new OperationCanceledException(); - } - // Import as many projects as we can; accumulate errors to - // report to the user - MultiStatus status = new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, 1, - DataTransferMessages.WizardProjectsImportPage_projectsInWorkspaceAndInvalid, null); - for (Object element : selected) { - status.add(createExistingProject((ProjectRecord) element, subMonitor.newChild(1))); - } - if (!status.isOK()) { - throw new InvocationTargetException(new CoreException(status)); + protected void execute(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + try { + monitor.beginTask("", selected.length); //$NON-NLS-1$ + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + // Import as many projects as we can; accumulate errors to + // report to the user + MultiStatus status = new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, 1, + DataTransferMessages.WizardProjectsImportPage_projectsInWorkspaceAndInvalid, null); + for (Object element : selected) { + status.add(createExistingProject((ProjectRecord) element, new SubProgressMonitor(monitor, 1))); + } + if (!status.isOK()) { + throw new InvocationTargetException(new CoreException(status)); + } + } finally { + monitor.done(); } } }; @@ -1266,9 +1271,8 @@ public class WizardProjectsImportPage extends WizardDataTransferPage { * @return status of the creation * @throws InterruptedException */ - private IStatus createExistingProject(final ProjectRecord record, IProgressMonitor mon) + private IStatus createExistingProject(final ProjectRecord record, IProgressMonitor monitor) throws InterruptedException { - SubMonitor subMonitor = SubMonitor.convert(mon, 3); String projectName = record.getProjectName(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); @@ -1298,7 +1302,7 @@ public class WizardProjectsImportPage extends WizardDataTransferPage { structureProvider, this, fileSystemObjects); operation.setContext(getShell()); try { - operation.run(subMonitor.newChild(1)); + operation.run(monitor); } catch (InvocationTargetException e) { if (e.getCause() instanceof CoreException) { return ((CoreException) e.getCause()).getStatus(); @@ -1308,7 +1312,6 @@ public class WizardProjectsImportPage extends WizardDataTransferPage { } return operation.getStatus(); } - // import from file system File importSource = null; if (copyFiles) { @@ -1339,16 +1342,19 @@ public class WizardProjectsImportPage extends WizardDataTransferPage { } } - subMonitor.setWorkRemaining((copyFiles && importSource != null) ? 2 : 1); - try { - SubMonitor subTask = subMonitor.newChild(1).setWorkRemaining(100); - subTask.setTaskName(DataTransferMessages.WizardProjectsImportPage_CreateProjectsTask); - project.create(record.description, subTask.newChild(30)); - project.open(IResource.BACKGROUND_REFRESH, subTask.newChild(70)); - subTask.setTaskName(""); //$NON-NLS-1$ + monitor + .beginTask( + DataTransferMessages.WizardProjectsImportPage_CreateProjectsTask, + 100); + project.create(record.description, new SubProgressMonitor(monitor, + 30)); + project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor( + monitor, 70)); } catch (CoreException e) { return e.getStatus(); + } finally { + monitor.done(); } // import operation to import project files if copy checkbox is selected @@ -1364,7 +1370,7 @@ public class WizardProjectsImportPage extends WizardDataTransferPage { // files operation.setCreateContainerStructure(false); try { - operation.run(subMonitor.newChild(1)); + operation.run(monitor); } catch (InvocationTargetException e) { if (e.getCause() instanceof CoreException) { return ((CoreException) e.getCause()).getStatus(); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/ImportOperation.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/ImportOperation.java index bb242c47ac9..7d93b4ced65 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/ImportOperation.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/ImportOperation.java @@ -39,7 +39,7 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; @@ -77,6 +77,8 @@ public class ImportOperation extends WorkspaceModifyOperation { private IImportStructureProvider provider; + private IProgressMonitor monitor; + protected IOverwriteQuery overwriteCallback; private Shell context; @@ -229,10 +231,9 @@ public class ImportOperation extends WorkspaceModifyOperation { * @param policy on of the POLICY constants defined in the * class. */ - void collectExistingReadonlyFiles(IPath sourceStart, List sources, ArrayList noOverwrite, - ArrayList overwriteReadonly, int policy, IProgressMonitor monitor) { - SubMonitor subMonitor = SubMonitor.convert(monitor, 100); - IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + void collectExistingReadonlyFiles(IPath sourceStart, List sources, + ArrayList noOverwrite, ArrayList overwriteReadonly, int policy) { + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); Iterator sourceIter = sources.iterator(); IPath sourceRootPath = null; @@ -271,8 +272,9 @@ public class ImportOperation extends WorkspaceModifyOperation { } } if (provider.isFolder(nextSource)) { - collectExistingReadonlyFiles(newDestinationPath, provider.getChildren(nextSource), noOverwrite, - overwriteReadonly, POLICY_FORCE_OVERWRITE, subMonitor.newChild(100)); + collectExistingReadonlyFiles(newDestinationPath, provider + .getChildren(nextSource), noOverwrite, + overwriteReadonly, POLICY_FORCE_OVERWRITE); } } else { IFile file = getFile(newDestination); @@ -371,24 +373,41 @@ public class ImportOperation extends WorkspaceModifyOperation { @Override protected void execute(IProgressMonitor progressMonitor) { - SubMonitor subMonitor = SubMonitor.convert(progressMonitor, DataTransferMessages.DataTransfer_importTask, 100); + + monitor = progressMonitor; + try { if (selectedFiles == null) { - ContainerGenerator generator = new ContainerGenerator(destinationPath); - subMonitor.worked(3); - validateFiles(Arrays.asList(new Object[] { source }), subMonitor.newChild(3)); - destinationContainer = generator.generateContainer(subMonitor.newChild(4)); - importRecursivelyFrom(source, POLICY_DEFAULT, subMonitor.newChild(90)); + //Set the amount to 1000 as we have no idea of how long this will take + monitor.beginTask(DataTransferMessages.DataTransfer_importTask, 1000); + ContainerGenerator generator = new ContainerGenerator( + destinationPath); + monitor.worked(30); + validateFiles(Arrays.asList(new Object[] { source })); + monitor.worked(50); + destinationContainer = generator + .generateContainer(new SubProgressMonitor(monitor, 50)); + importRecursivelyFrom(source, POLICY_DEFAULT); + //Be sure it finishes + monitor.worked(90); } else { // Choose twice the selected files size to take folders into account - ContainerGenerator generator = new ContainerGenerator(destinationPath); - subMonitor.worked(3); - validateFiles(selectedFiles, subMonitor.newChild(3)); - destinationContainer = generator.generateContainer(subMonitor.newChild(4)); - importFileSystemObjects(selectedFiles, subMonitor.newChild(90)); + int creationCount = selectedFiles.size(); + monitor.beginTask(DataTransferMessages.DataTransfer_importTask, creationCount + 100); + ContainerGenerator generator = new ContainerGenerator( + destinationPath); + monitor.worked(30); + validateFiles(selectedFiles); + monitor.worked(50); + destinationContainer = generator + .generateContainer(new SubProgressMonitor(monitor, 50)); + importFileSystemObjects(selectedFiles); + monitor.done(); } } catch (CoreException e) { errorTable.add(e.getStatus()); + } finally { + monitor.done(); } } @@ -500,8 +519,7 @@ public class ImportOperation extends WorkspaceModifyOperation { * @param fileObject the file system object to be imported * @param policy determines how the file object is imported */ - void importFile(Object fileObject, int policy, IProgressMonitor mon) { - SubMonitor subMonitor = SubMonitor.convert(mon, 100); + void importFile(Object fileObject, int policy) { IContainer containerResource; try { containerResource = getDestinationContainerFor(fileObject); @@ -515,9 +533,10 @@ public class ImportOperation extends WorkspaceModifyOperation { } String fileObjectPath = provider.getFullPath(fileObject); - subMonitor.subTask(fileObjectPath); + monitor.subTask(fileObjectPath); IFile targetResource = containerResource.getFile(new Path(provider .getLabel(fileObject))); + monitor.worked(1); if (rejectedFiles.contains(targetResource.getFullPath())) { return; @@ -545,44 +564,51 @@ public class ImportOperation extends WorkspaceModifyOperation { return; } - try { - if (createVirtualFolder || createLinks || createLinkFilesOnly) { - if (targetResource.exists()) - targetResource.delete(true, subMonitor.newChild(50)); - targetResource.createLink( - createRelativePath(new Path(provider.getFullPath(fileObject)), targetResource), 0, - subMonitor.newChild(50)); - } else { - if (targetResource.exists()) { - if (targetResource.isLinked()) { - targetResource.delete(true, subMonitor.newChild(50)); - targetResource.create(contentStream, false, subMonitor.newChild(50)); - } else - targetResource.setContents(contentStream, IResource.KEEP_HISTORY, subMonitor.newChild(100)); - } else - targetResource.create(contentStream, false, subMonitor.newChild(100)); - } - setResourceAttributes(targetResource, fileObject); - - if (provider instanceof TarLeveledStructureProvider) { - try { - targetResource.setResourceAttributes( - ((TarLeveledStructureProvider) provider).getResourceAttributes(fileObject)); - } catch (CoreException e) { - errorTable.add(e.getStatus()); - } - } - } catch (CoreException e) { - errorTable.add(e.getStatus()); - } finally { - try { - contentStream.close(); - } catch (IOException e) { - errorTable.add(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, - NLS.bind(DataTransferMessages.ImportOperation_closeStreamError, fileObjectPath), e)); - } - } - } + try { + if (createVirtualFolder || createLinks || createLinkFilesOnly) { + if (targetResource.exists()) + targetResource.delete(true, null); + targetResource.createLink(createRelativePath( + new Path(provider + .getFullPath(fileObject)), targetResource), 0, null); + } else { + if (targetResource.exists()) { + if (targetResource.isLinked()) { + targetResource.delete(true, null); + targetResource.create(contentStream, false, null); + } + else + targetResource.setContents(contentStream, + IResource.KEEP_HISTORY, null); + } + else + targetResource.create(contentStream, false, null); + } + setResourceAttributes(targetResource, fileObject); + + if (provider instanceof TarLeveledStructureProvider) { + try { + targetResource.setResourceAttributes(((TarLeveledStructureProvider) provider).getResourceAttributes(fileObject)); + } catch (CoreException e) { + errorTable.add(e.getStatus()); + } + } + } catch (CoreException e) { + errorTable.add(e.getStatus()); + } finally { + try { + contentStream.close(); + } catch (IOException e) { + errorTable + .add(new Status( + IStatus.ERROR, + PlatformUI.PLUGIN_ID, + 0, + NLS.bind(DataTransferMessages.ImportOperation_closeStreamError, fileObjectPath), + e)); + } + } + } /** * Reuse the file attributes set in the import. @@ -631,11 +657,9 @@ public class ImportOperation extends WorkspaceModifyOperation { * @throws CoreException * @exception OperationCanceledException if canceled */ - void importFileSystemObjects(List filesToImport, IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, filesToImport.size()); + void importFileSystemObjects(List filesToImport) throws CoreException { Iterator filesEnum = filesToImport.iterator(); while (filesEnum.hasNext()) { - SubMonitor iterationMonitor = subMonitor.newChild(1); Object fileSystemObject = filesEnum.next(); if (source == null) { // We just import what we are given into the destination @@ -652,7 +676,7 @@ public class ImportOperation extends WorkspaceModifyOperation { } source = sourcePath.toFile(); } - importRecursivelyFrom(fileSystemObject, POLICY_DEFAULT, iterationMonitor); + importRecursivelyFrom(fileSystemObject, POLICY_DEFAULT); } } @@ -666,7 +690,7 @@ public class ImportOperation extends WorkspaceModifyOperation { * @return the policy to use to import the folder's children * @throws CoreException */ - int importFolder(Object folderObject, int policy, IProgressMonitor monitor) throws CoreException { + int importFolder(Object folderObject, int policy) throws CoreException { IContainer containerResource; try { containerResource = getDestinationContainerFor(folderObject); @@ -754,23 +778,22 @@ public class ImportOperation extends WorkspaceModifyOperation { * @throws CoreException * @exception OperationCanceledException if canceled */ - void importRecursivelyFrom(Object fileSystemObject, int policy, IProgressMonitor mon) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(mon, 100); - if (subMonitor.isCanceled()) { + void importRecursivelyFrom(Object fileSystemObject, int policy) throws CoreException { + if (monitor.isCanceled()) { throw new OperationCanceledException(); } if (!provider.isFolder(fileSystemObject)) { - importFile(fileSystemObject, policy, subMonitor.newChild(100)); + importFile(fileSystemObject, policy); return; } - int childPolicy = importFolder(fileSystemObject, policy, subMonitor.newChild(10)); + int childPolicy = importFolder(fileSystemObject, policy); if (childPolicy != POLICY_SKIP_CHILDREN) { - List children = provider.getChildren(fileSystemObject); - SubMonitor loopMonitor = subMonitor.newChild(90).setWorkRemaining(children.size()); - for (Object child : children) { - importRecursivelyFrom(child, childPolicy, loopMonitor.newChild(1)); + Iterator children = provider.getChildren(fileSystemObject) + .iterator(); + while (children.hasNext()) { + importRecursivelyFrom(children.next(), childPolicy); } } } @@ -919,14 +942,14 @@ public class ImportOperation extends WorkspaceModifyOperation { * * @param sourceFiles files to validate */ - void validateFiles(List sourceFiles, IProgressMonitor monitor) { + void validateFiles(List sourceFiles) { ArrayList noOverwrite = new ArrayList(); ArrayList overwriteReadonly = new ArrayList(); - collectExistingReadonlyFiles(destinationPath, sourceFiles, noOverwrite, overwriteReadonly, POLICY_DEFAULT, - monitor); - rejectedFiles = validateEdit(overwriteReadonly); - rejectedFiles.addAll(noOverwrite); + collectExistingReadonlyFiles(destinationPath, sourceFiles, noOverwrite, + overwriteReadonly, POLICY_DEFAULT); + rejectedFiles = validateEdit(overwriteReadonly); + rejectedFiles.addAll(noOverwrite); } /** diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/WizardExternalProjectImportPage.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/WizardExternalProjectImportPage.java index e07fa7328d4..bb4ebb27ad1 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/WizardExternalProjectImportPage.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/WizardExternalProjectImportPage.java @@ -26,7 +26,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.wizard.WizardPage; @@ -437,12 +437,14 @@ public class WizardExternalProjectImportPage extends WizardPage { @Override protected void execute(IProgressMonitor monitor) throws CoreException { - SubMonitor subMonitor = SubMonitor.convert(monitor, 100); - project.create(description, subMonitor.newChild(50)); - if (subMonitor.isCanceled()) { + monitor.beginTask("", 2000); //$NON-NLS-1$ + project.create(description, new SubProgressMonitor(monitor, + 1000)); + if (monitor.isCanceled()) { throw new OperationCanceledException(); } - project.open(IResource.BACKGROUND_REFRESH, subMonitor.newChild(50)); + project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1000)); + } }; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java index b34b4d728cd..ed5ad50bf52 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java @@ -40,7 +40,7 @@ import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.ProgressMonitorWrapper; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; @@ -2091,16 +2091,22 @@ public abstract class FilteredItemsSelectionDialog extends lastCompletedFilter = null; lastCompletedResult = null; - SubMonitor subMonitor = SubMonitor.convert(monitor, + SubProgressMonitor subMonitor = null; + if (monitor != null) { + monitor + .beginTask( WorkbenchMessages.FilteredItemsSelectionDialog_searchJob_taskName, 100); + subMonitor = new SubProgressMonitor(monitor, 95); - fillContentProvider(contentProvider, itemsFilter, subMonitor.newChild(95)); + } + + fillContentProvider(contentProvider, itemsFilter, subMonitor); if (monitor != null && !monitor.isCanceled()) { - subMonitor.worked(2); + monitor.worked(2); contentProvider.rememberResult(itemsFilter); - subMonitor.worked(3); + monitor.worked(3); } } @@ -2810,41 +2816,61 @@ public abstract class FilteredItemsSelectionDialog extends * @param monitor * progress monitor */ - public void reloadCache(boolean checkDuplicates, IProgressMonitor monitor) { + public void reloadCache(boolean checkDuplicates, + IProgressMonitor monitor) { + reset = false; - // the work is divided into two actions of the same length - int totalWork = checkDuplicates ? 200 : 100; + if (monitor != null) { + // the work is divided into two actions of the same length + int totalWork = checkDuplicates ? 200 : 100; - SubMonitor subMonitor = SubMonitor.convert(monitor, - WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob, totalWork); + monitor + .beginTask( + WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob, + totalWork); + } // the TableViewer's root (the input) is treated as parent - lastFilteredItems = Arrays.asList(getFilteredItems(list.getInput(), subMonitor.newChild(100))); + lastFilteredItems = Arrays.asList(getFilteredItems(list.getInput(), + monitor != null ? new SubProgressMonitor(monitor, 100) + : null)); - if (reset || subMonitor.isCanceled()) { + if (reset || (monitor != null && monitor.isCanceled())) { + if (monitor != null) + monitor.done(); return; } if (checkDuplicates) { - checkDuplicates(subMonitor.newChild(100)); + checkDuplicates(monitor); } + if (monitor != null) + monitor.done(); } private void checkDuplicates(IProgressMonitor monitor) { synchronized (lastFilteredItems) { - SubMonitor subMonitor = SubMonitor.convert(monitor, - WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob_checkDuplicates, - lastFilteredItems.size()); - HashMap<String, Object> helperMap = new HashMap<>(); + IProgressMonitor subMonitor = null; + int reportEvery = lastFilteredItems.size() / 20; + if (monitor != null) { + subMonitor = new SubProgressMonitor(monitor, 100); + subMonitor + .beginTask( + WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob_checkDuplicates, + 5); + } + HashMap helperMap = new HashMap(); for (int i = 0; i < lastFilteredItems.size(); i++) { - if (reset || subMonitor.isCanceled()) + if (reset + || (subMonitor != null && subMonitor.isCanceled())) return; Object item = lastFilteredItems.get(i); if (!(item instanceof ItemsListSeparator)) { - Object previousItem = helperMap.put(getElementName(item), item); + Object previousItem = helperMap.put( + getElementName(item), item); if (previousItem != null) { setDuplicateElement(previousItem, true); setDuplicateElement(item, true); @@ -2853,7 +2879,9 @@ public abstract class FilteredItemsSelectionDialog extends } } - subMonitor.worked(1); + if (subMonitor != null && reportEvery != 0 + && (i + 1) % reportEvery == 0) + subMonitor.worked(1); } helperMap.clear(); } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java index f901028ec14..bf55b297630 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java @@ -25,6 +25,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; @@ -188,18 +189,18 @@ public class SaveableHelper { @Override public void run(IProgressMonitor monitor) { IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor); - SubMonitor subMonitor = SubMonitor.convert(monitorWrap, WorkbenchMessages.Save, dirtyModels.size()); + monitorWrap.beginTask(WorkbenchMessages.Save, dirtyModels.size()); try { for (Iterator<Saveable> i = dirtyModels.iterator(); i.hasNext();) { Saveable model = i.next(); // handle case where this model got saved as a result of // saving another if (!model.isDirty()) { - subMonitor.worked(1); + monitor.worked(1); continue; } - doSaveModel(model, subMonitor.newChild(1), window, confirm); - if (subMonitor.isCanceled()) { + doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), window, confirm); + if (monitor.isCanceled()) { break; } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java index 02714ac565d..86cf326693a 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java @@ -25,7 +25,7 @@ import org.eclipse.core.runtime.AssertionFailedException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.ListenerList; -import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialogWithToggle; @@ -652,19 +652,19 @@ public class SaveablesList implements ISaveablesLifecycleListener { IRunnableWithProgress progressOp = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { - IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor); - SubMonitor subMonitor = SubMonitor.convert(monitorWrap, WorkbenchMessages.Saving_Modifications, - finalModels.size()); + IProgressMonitor monitorWrap = new EventLoopProgressMonitor( + monitor); + monitorWrap.beginTask(WorkbenchMessages.Saving_Modifications, finalModels.size()); for (Saveable model : finalModels) { // handle case where this model got saved as a result of // saving another if (!model.isDirty()) { - subMonitor.worked(1); + monitor.worked(1); continue; } - SaveableHelper.doSaveModel(model, subMonitor.newChild(1), + SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider, blockUntilSaved); - if (subMonitor.isCanceled()) + if (monitorWrap.isCanceled()) break; } monitorWrap.done(); |
