Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Xenos2015-09-18 18:06:20 +0000
committerStefan Xenos2015-09-18 18:06:20 +0000
commitb51d6dfc180ca7cdf065958541f51484c2e036d9 (patch)
tree39f4b7986d475f00d32dd32970480793ec177c4d
parent671eed0c1fb4ed5154b6cb3b5e18a1164d538330 (diff)
downloadeclipse.platform.ui-b51d6dfc180ca7cdf065958541f51484c2e036d9.tar.gz
eclipse.platform.ui-b51d6dfc180ca7cdf065958541f51484c2e036d9.tar.xz
eclipse.platform.ui-b51d6dfc180ca7cdf065958541f51484c2e036d9.zip
Revert "Revert commits for "Bug 475785 - Remove usage of SubProgressMonitor in *""
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/BuildAction.java9
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyFilesAndFoldersOperation.java110
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/GlobalBuildAction.java7
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/MoveFilesAndFoldersOperation.java45
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/OpenResourceAction.java35
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/RefreshAction.java34
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java35
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/ContainerGenerator.java38
-rw-r--r--bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/WizardNewFolderMainPage.java19
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyProjectOperation.java6
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/CopyResourcesOperation.java31
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/MoveResourcesOperation.java22
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/undo/WorkspaceUndoUtil.java381
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/CleanDialog.java15
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/LinkedResourceEditor.java38
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/model/WorkingSetResourceMapping.java35
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ContainerDescription.java28
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FileDescription.java24
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/FolderDescription.java52
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/undo/ProjectDescription.java17
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkCompletedHandler.java13
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixWizard.java33
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardProjectsImportPage.java62
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/ImportOperation.java179
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/WizardExternalProjectImportPage.java12
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java68
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java9
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java14
28 files changed, 572 insertions, 799 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 2c9fa27a256..18a97b182fd 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -278,12 +278,13 @@ public class BuildAction extends WorkspaceAction {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
IStatus status = null;
- monitor.beginTask("", 10000); //$NON-NLS-1$
- monitor.setTaskName(getOperationMessage());
+ SubMonitor progress = SubMonitor.convert(monitor, 10000);
+ progress.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(), new SubProgressMonitor(monitor, 10000));
+ ResourcesPlugin.getWorkspace().build(configs, kind, shouldPerformResourcePruning(),
+ progress.newChild(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 3972803ca8b..ca6e2bb26c5 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
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 subMonitor
+ * @param monitor
* a progress monitor for showing progress and for cancelation
*
* @deprecated As of 3.3, the work is performed in the undoable operation
@@ -432,15 +432,12 @@ public class CopyFilesAndFoldersOperation {
* {@link #getUndoableCopyOrMoveOperation(IResource[], IPath)}
*/
@Deprecated
- protected void copy(IResource[] resources, IPath destination,
- IProgressMonitor subMonitor) throws CoreException {
-
- subMonitor
- .beginTask(
- IDEWorkbenchMessages.CopyFilesAndFoldersOperation_CopyResourcesTask,
- resources.length);
+ protected void copy(IResource[] resources, IPath destination, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMonitor = SubMonitor.convert(monitor,
+ 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();
@@ -452,55 +449,45 @@ public class CopyFilesAndFoldersOperation {
// children of the folder.
if (homogenousResources(source, existing)) {
IResource[] children = ((IContainer) source).members();
- copy(children, destinationPath, new SubProgressMonitor(
- subMonitor, 1));
+ copy(children, destinationPath, iterationProgress.newChild(100));
} else {
// delete the destination folder, copying a linked folder
// over an unlinked one or vice versa. Fixes bug 28772.
- delete(existing, new SubProgressMonitor(subMonitor, 0));
- source.copy(destinationPath, IResource.SHALLOW,
- new SubProgressMonitor(subMonitor, 1));
+ delete(existing, iterationProgress.newChild(10));
+ source.copy(destinationPath, IResource.SHALLOW, iterationProgress.newChild(90));
}
} else {
if (existing != null) {
if (homogenousResources(source, existing)) {
- copyExisting(source, existing, new SubProgressMonitor(
- subMonitor, 1));
+ copyExisting(source, existing, iterationProgress.newChild(100));
} else {
- 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));
+ 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));
}
- } else
- source.copy(destinationPath, IResource.SHALLOW,
- 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));
}
if (subMonitor.isCanceled()) {
@@ -544,17 +531,15 @@ public class CopyFilesAndFoldersOperation {
* @throws CoreException
* setContents failed
*/
- private void copyExisting(IResource source, IResource existing,
- IProgressMonitor subMonitor) throws CoreException {
+ private void copyExisting(IResource source, IResource existing, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
IFile existingFile = getFile(existing);
if (existingFile != null) {
IFile sourceFile = getFile(source);
if (sourceFile != null) {
- existingFile.setContents(sourceFile.getContents(),
- IResource.KEEP_HISTORY, new SubProgressMonitor(
- subMonitor, 0));
+ existingFile.setContents(sourceFile.getContents(), IResource.KEEP_HISTORY, subMonitor.newChild(1));
}
}
}
@@ -1802,16 +1787,15 @@ public class CopyFilesAndFoldersOperation {
return (IResource[]) copyItems.toArray(new IResource[copyItems.size()]);
}
- private void copyResources(final IResource[] resources,
- final IPath destinationPath, final IResource[][] copiedResources,
- IProgressMonitor monitor) {
+ private void copyResources(final IResource[] resources, final IPath destinationPath,
+ final IResource[][] copiedResources, IProgressMonitor mon) {
IResource[] copyResources = resources;
// Fix for bug 31116. Do not provide a task name when
// creating the task.
- monitor.beginTask("", 100); //$NON-NLS-1$
- monitor.setTaskName(getOperationTitle());
- monitor.worked(10); // show some initial progress
+ SubMonitor subMonitor = SubMonitor.convert(mon, 100);
+ subMonitor.setTaskName(getOperationTitle());
+ subMonitor.worked(10); // show some initial progress
// Checks only required if this is an exisiting container path.
boolean copyWithAutoRename = false;
@@ -1845,13 +1829,11 @@ public class CopyFilesAndFoldersOperation {
errorStatus = null;
if (copyResources.length > 0) {
if (copyWithAutoRename) {
- performCopyWithAutoRename(copyResources, destinationPath,
- new SubProgressMonitor(monitor, 90));
+ performCopyWithAutoRename(copyResources, destinationPath, subMonitor.newChild(90));
} else {
- performCopy(copyResources, destinationPath, new SubProgressMonitor(monitor, 90));
+ performCopy(copyResources, destinationPath, subMonitor.newChild(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 5eeda86021a..4acbaa2b804 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.ErrorDialog;
@@ -172,10 +172,9 @@ public class GlobalBuildAction extends Action implements
Job buildJob = new Job(IDEWorkbenchMessages.GlobalBuildAction_jobTitle) {
@Override
protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask(getOperationMessage(), 100);
+ SubMonitor subMonitor = SubMonitor.convert(monitor, getOperationMessage(), 100);
try {
- ResourcesPlugin.getWorkspace().build(buildType,
- new SubProgressMonitor(monitor, 100));
+ ResourcesPlugin.getWorkspace().build(buildType, subMonitor.newChild(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 e79be2f8d6c..4371b568ef6 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
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 subMonitor
+ * @param monitor
* a progress monitor for showing progress and for cancelation
*
* @deprecated As of 3.3, the work is performed in the undoable operation
@@ -76,9 +76,10 @@ public class MoveFilesAndFoldersOperation extends CopyFilesAndFoldersOperation {
*/
@Deprecated
@Override
- protected void copy(IResource[] resources, IPath destination,
- IProgressMonitor subMonitor) throws CoreException {
+ protected void copy(IResource[] resources, IPath destination, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, resources.length);
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();
@@ -89,36 +90,32 @@ public class MoveFilesAndFoldersOperation extends CopyFilesAndFoldersOperation {
// move the children of the folder.
if (homogenousResources(source, existing)) {
IResource[] children = ((IContainer) source).members();
- copy(children, destinationPath, subMonitor);
+ copy(children, destinationPath, iterationMonitor.newChild(100));
delete(source, subMonitor);
} else {
// delete the destination folder, moving a linked folder
// over an unlinked one or vice versa. Fixes bug 28772.
- delete(existing, new SubProgressMonitor(subMonitor, 0));
- source.move(destinationPath, IResource.SHALLOW
- | IResource.KEEP_HISTORY, new SubProgressMonitor(
- subMonitor, 0));
+ delete(existing, iterationMonitor.newChild(50));
+ source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY,
+ iterationMonitor.newChild(50));
}
} else {
// if we're merging folders, we could be overwriting an existing
// file
if (existing != null) {
if (homogenousResources(source, existing)) {
- moveExisting(source, existing, subMonitor);
+ moveExisting(source, existing, iterationMonitor.newChild(100));
} else {
// Moving a linked resource over unlinked or vice versa.
// Can't use setContents here. Fixes bug 28772.
- delete(existing, new SubProgressMonitor(subMonitor, 0));
- source.move(destinationPath, IResource.SHALLOW
- | IResource.KEEP_HISTORY,
- new SubProgressMonitor(subMonitor, 0));
+ delete(existing, iterationMonitor.newChild(50));
+ source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY,
+ iterationMonitor.newChild(50));
}
} else {
- source.move(destinationPath, IResource.SHALLOW
- | IResource.KEEP_HISTORY, new SubProgressMonitor(
- subMonitor, 0));
+ source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY,
+ iterationMonitor.newChild(100));
}
- subMonitor.worked(1);
if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
@@ -191,25 +188,23 @@ public class MoveFilesAndFoldersOperation extends CopyFilesAndFoldersOperation {
* source file to move
* @param existing
* existing file to set the source content in
- * @param subMonitor
+ * @param monitor
* 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 subMonitor) throws CoreException {
+ private void moveExisting(IResource source, IResource existing, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
IFile existingFile = getFile(existing);
if (existingFile != null) {
IFile sourceFile = getFile(source);
if (sourceFile != null) {
- existingFile.setContents(sourceFile.getContents(),
- IResource.KEEP_HISTORY, new SubProgressMonitor(
- subMonitor, 0));
- delete(sourceFile, subMonitor);
+ existingFile.setContents(sourceFile.getContents(), IResource.KEEP_HISTORY, subMonitor.newChild(1));
+ delete(sourceFile, subMonitor.newChild(1));
}
}
}
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 05362217593..7c8d9cc7475 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
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 resources = new ArrayList(getActionResources());
+ final List<IResource> resources = new ArrayList<>(getActionResources());
Job job = new WorkspaceJob(removeMnemonics(getText())) {
private boolean openProjectReferences = true;
private boolean hasPrompted = false;
@@ -223,11 +223,9 @@ public class OpenResourceAction extends WorkspaceAction implements IResourceChan
/**
* Opens a project along with all projects it references
*/
- private void doOpenWithReferences(IProject project, IProgressMonitor monitor) throws CoreException {
- if (!project.exists() || project.isOpen()) {
- return;
- }
- project.open(new SubProgressMonitor(monitor, 1000));
+ private void doOpenWithReferences(IProject project, IProgressMonitor mon) throws CoreException {
+ SubMonitor subMonitor = SubMonitor.convert(mon, openProjectReferences ? 2 : 1);
+ project.open(subMonitor.newChild(1));
final IProject[] references = project.getReferencedProjects();
if (!hasPrompted) {
openProjectReferences = false;
@@ -252,23 +250,28 @@ 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], monitor);
+ doOpenWithReferences(references[i], loopMonitor.newChild(1));
}
}
}
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
- 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);
+ 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;
}
- } finally {
- monitor.done();
+ doOpenWithReferences(project, subMonitor.newChild(1));
}
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 54f1208def9..eacad7c4e57 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.jface.dialogs.IDialogConstants;
@@ -221,28 +221,24 @@ public class RefreshAction extends WorkspaceAction {
}
return new WorkspaceModifyOperation(rule) {
@Override
- public void execute(IProgressMonitor monitor) {
+ public void execute(IProgressMonitor mon) {
+ SubMonitor subMonitor = SubMonitor.convert(mon, resources.size());
MultiStatus errors = null;
- monitor.beginTask("", resources.size() * 1000); //$NON-NLS-1$
- monitor.setTaskName(getOperationMessage());
+ subMonitor.setTaskName(getOperationMessage());
Iterator<? extends IResource> resourcesEnum = resources.iterator();
- 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();
- }
+ while (resourcesEnum.hasNext()) {
+ try {
+ IResource resource = resourcesEnum.next();
+ refreshResource(resource, subMonitor.newChild(1));
+ } catch (CoreException e) {
+ errors = recordError(errors, e);
}
- if (errors != null) {
- errorStatus[0] = errors;
+ if (subMonitor.isCanceled()) {
+ throw new OperationCanceledException();
}
- } finally {
- monitor.done();
+ }
+ if (errors != null) {
+ errorStatus[0] = errors;
}
}
};
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 006319878f0..fb2c590b045 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.ErrorDialog;
@@ -140,38 +140,29 @@ public abstract class WorkspaceAction extends SelectionListenerAction {
* a progress monitor
* @return The result of the execution
*/
- final IStatus execute(List<? extends IResource> resources, IProgressMonitor monitor) {
+ final IStatus execute(List<? extends IResource> resources, IProgressMonitor mon) {
MultiStatus errors = null;
// 1FTIMQN: ITPCORE:WIN - clients required to do too much iteration work
if (shouldPerformResourcePruning()) {
resources = pruneResources(resources);
}
- // 1FV0B3Y: ITPUI:ALL - sub progress monitors granularity issues
- monitor.beginTask("", resources.size() * 1000); //$NON-NLS-1$
+ SubMonitor subMonitor = SubMonitor.convert(mon, resources.size());
// 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)
- 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();
- }
+ 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();
}
- 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 29afc51711a..889c5433779 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
@@ -113,21 +113,16 @@ public class ContainerGenerator {
*/
private IProject createProject(IProject projectHandle,
IProgressMonitor monitor) throws CoreException {
- try {
- monitor.beginTask("", 2000);//$NON-NLS-1$
-
- projectHandle.create(new SubProgressMonitor(monitor, 1000));
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
+ projectHandle.create(subMonitor.newChild(1));
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
- projectHandle.open(new SubProgressMonitor(monitor, 1000));
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- } finally {
- monitor.done();
- }
+ projectHandle.open(subMonitor.newChild(1));
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
return projectHandle;
}
@@ -162,9 +157,8 @@ public class ContainerGenerator {
public IContainer generateContainer(IProgressMonitor monitor)
throws CoreException {
IDEWorkbenchPlugin.getPluginWorkspace().run(monitor1 -> {
- monitor1
- .beginTask(
- IDEWorkbenchMessages.ContainerGenerator_progressMessage, 1000 * containerFullPath.segmentCount());
+ SubMonitor subMonitor = SubMonitor.convert(monitor1,
+ IDEWorkbenchMessages.ContainerGenerator_progressMessage, containerFullPath.segmentCount());
if (container != null) {
return;
}
@@ -187,18 +181,16 @@ public class ContainerGenerator {
throw new CoreException(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1, msg, null));
}
container = (IContainer) resource;
- monitor1.worked(1000);
+ subMonitor.worked(1);
} else {
if (i == 0) {
IProject projectHandle = createProjectHandle(root,
currentSegment);
- container = createProject(projectHandle,
- new SubProgressMonitor(monitor1, 1000));
+ container = createProject(projectHandle, subMonitor.newChild(1));
} else {
IFolder folderHandle = createFolderHandle(
container, currentSegment);
- container = createFolder(folderHandle,
- new SubProgressMonitor(monitor1, 1000));
+ container = createFolder(folderHandle, subMonitor.newChild(1));
}
}
}
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 fe601583021..495e7e91827 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
@@ -299,14 +299,15 @@ 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, monitor);
+ folderHandle.createLink(linkTargetPath, IResource.ALLOW_MISSING_LOCAL, subMonitor.newChild(100));
} else {
IPath path = folderHandle.getFullPath();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
@@ -315,6 +316,8 @@ 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.
@@ -322,25 +325,25 @@ public class WizardNewFolderMainPage extends WizardPage implements Listener {
IFolder folder = root.getFolder(path
.removeLastSegments(i));
if (!folder.exists()) {
- folder.create(false, true, monitor);
+ folder.create(false, true, loopProgress.newChild(1));
}
}
}
- folderHandle.create(false, true, monitor);
+ subMonitor.setWorkRemaining(10);
+ folderHandle.create(false, true, subMonitor.newChild(10));
}
}
} 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,
- new SubProgressMonitor(monitor, 500));
+ folderHandle.refreshLocal(IResource.DEPTH_INFINITE, subMonitor.setWorkRemaining(1).newChild(1));
} else {
throw e;
}
}
- if (monitor.isCanceled()) {
+ if (subMonitor.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 8053a11a7c8..c515118dad1 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
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, new SubProgressMonitor(monitor, 1),
- uiInfo, true);
+ WorkspaceUndoUtil.delete(resources, subMonitor.newChild(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 8c4617c218e..350de9925b9 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
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 {
- monitor.beginTask("", 2000); //$NON-NLS-1$
- monitor
- .setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress);
+ SubMonitor subMonitor = SubMonitor.convert(monitor,
+ resources.length + (resourceDescriptions != null ? resourceDescriptions.length : 0));
+ subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress);
List resourcesAtDestination = new ArrayList();
List overwrittenResources = new ArrayList();
@@ -150,11 +150,8 @@ 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,
- new SubProgressMonitor(monitor, 1000 / resources.length),
- uiInfo, true, fCreateGroups, fCreateLinks,
+ overwrites = WorkspaceUndoUtil.copy(new IResource[] { resources[i] }, getDestinationPath(resources[i], i),
+ resourcesAtDestination, subMonitor.newChild(1), uiInfo, true, fCreateGroups, fCreateLinks,
fRelativeToVariable);
// Accumulate the overwrites into the full list
for (int j = 0; j < overwrites.length; j++) {
@@ -166,9 +163,7 @@ public class CopyResourcesOperation extends
if (resourceDescriptions != null) {
for (int i = 0; i < resourceDescriptions.length; i++) {
if (resourceDescriptions[i] != null) {
- resourceDescriptions[i]
- .createResource(new SubProgressMonitor(monitor,
- 1000 / resourceDescriptions.length));
+ resourceDescriptions[i].createResource(subMonitor.newChild(1));
}
}
}
@@ -181,7 +176,6 @@ public class CopyResourcesOperation extends
// location.
setTargetResources((IResource[]) resourcesAtDestination
.toArray(new IResource[resourcesAtDestination.size()]));
- monitor.done();
}
/*
@@ -191,15 +185,12 @@ public class CopyResourcesOperation extends
@Override
protected void doUndo(IProgressMonitor monitor, IAdaptable uiInfo)
throws CoreException {
- monitor.beginTask("", 2); //$NON-NLS-1$
- monitor
- .setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress);
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
+ subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress);
// undoing a copy is first deleting the copied resources...
- WorkspaceUndoUtil.delete(resources, new SubProgressMonitor(monitor, 1),
- uiInfo, true);
+ WorkspaceUndoUtil.delete(resources, subMonitor.newChild(1), uiInfo, true);
// then restoring any overwritten by the previous copy...
- WorkspaceUndoUtil.recreate(resourceDescriptions,
- new SubProgressMonitor(monitor, 1), uiInfo);
+ WorkspaceUndoUtil.recreate(resourceDescriptions, subMonitor.newChild(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 f4ab6c40821..0b2f8413ae0 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.ui.internal.ide.undo.UndoMessages;
/**
@@ -119,10 +119,9 @@ public class MoveResourcesOperation extends
*/
protected void move(IProgressMonitor monitor, IAdaptable uiInfo)
throws CoreException {
-
- monitor.beginTask("", 2000); //$NON-NLS-1$
- monitor
- .setTaskName(UndoMessages.AbstractResourcesOperation_MovingResources);
+ SubMonitor subMonitor = SubMonitor.convert(monitor,
+ resources.length + (resourceDescriptions != null ? resourceDescriptions.length : 0));
+ subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_MovingResources);
List resourcesAtDestination = new ArrayList();
List undoDestinationPaths = new ArrayList();
List overwrittenResources = new ArrayList();
@@ -131,11 +130,8 @@ 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, new SubProgressMonitor(monitor,
- 1000 / resources.length), uiInfo, true);
+ overwrites = WorkspaceUndoUtil.move(new IResource[] { resources[i] }, getDestinationPath(resources[i], i),
+ resourcesAtDestination, undoDestinationPaths, subMonitor.newChild(1), uiInfo, true);
// Accumulate the overwrites into the full list
for (int j = 0; j < overwrites.length; j++) {
@@ -147,9 +143,7 @@ public class MoveResourcesOperation extends
if (resourceDescriptions != null) {
for (int i = 0; i < resourceDescriptions.length; i++) {
if (resourceDescriptions[i] != null) {
- resourceDescriptions[i]
- .createResource(new SubProgressMonitor(monitor,
- 1000 / resourceDescriptions.length));
+ resourceDescriptions[i].createResource(subMonitor.newChild(1));
}
}
}
@@ -166,8 +160,6 @@ 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 c9e05bd8566..eca0776c73c 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
@@ -175,63 +175,53 @@ public class WorkspaceUndoUtil {
* @throws CoreException
* propagates any CoreExceptions thrown from the resources API
*/
- static ResourceDescription[] delete(IResource[] resourcesToDelete,
- IProgressMonitor monitor, IAdaptable uiInfo, boolean deleteContent)
- throws CoreException {
- final List exceptions = new ArrayList();
+ 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<>();
boolean forceOutOfSyncDelete = false;
ResourceDescription[] returnedResourceDescriptions = new ResourceDescription[resourcesToDelete.length];
- 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);
- }
+ 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();
} else {
exceptions.add(e);
}
} else {
exceptions.add(e);
}
+ } else {
+ exceptions.add(e);
}
}
- IStatus result = createResult(exceptions);
- if (!result.isOK()) {
- throw new CoreException(result);
- }
- } finally {
- monitor.done();
+ }
+ IStatus result = createResult(exceptions);
+ if (!result.isOK()) {
+ throw new CoreException(result);
}
return returnedResourceDescriptions;
}
@@ -267,9 +257,8 @@ public class WorkspaceUndoUtil {
* @throws CoreException
* propagates any CoreExceptions thrown from the resources API
*/
- static ResourceDescription[] copy(IResource[] resources, IPath destination,
- List resourcesAtDestination, IProgressMonitor monitor,
- IAdaptable uiInfo, boolean pathIncludesName) throws CoreException {
+ static ResourceDescription[] copy(IResource[] resources, IPath destination, List<IResource> resourcesAtDestination,
+ IProgressMonitor monitor, IAdaptable uiInfo, boolean pathIncludesName) throws CoreException {
return copy(resources, destination, resourcesAtDestination, monitor,
uiInfo, pathIncludesName, false, false, null);
}
@@ -318,18 +307,14 @@ public class WorkspaceUndoUtil {
* @throws CoreException
* propagates any CoreExceptions thrown from the resources API
*/
- 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];
+ 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);
IPath destinationPath;
if (pathIncludesName) {
destinationPath = destination;
@@ -351,7 +336,7 @@ public class WorkspaceUndoUtil {
children = filterNonLinkedResources(children);
ResourceDescription[] overwritten = copy(children,
destinationPath, resourcesAtDestination,
- new SubProgressMonitor(monitor, 1), uiInfo, false,
+ iterationProgress, uiInfo, false,
createVirtual, createLinks, relativeToVariable);
// We don't record the copy since this recursive call will
// do so. Just record the overwrites.
@@ -361,37 +346,28 @@ 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 },
- new SubProgressMonitor(monitor, 0), uiInfo, false);
- if ((createLinks || createVirtual)
- && (source.isLinked() == false)
+ ResourceDescription[] deleted = delete(new IResource[] { existing }, iterationProgress.newChild(1),
+ uiInfo, false);
+ iterationProgress.setWorkRemaining(100);
+ if ((createLinks || createVirtual) && (source.isLinked() == false)
&& (source.isVirtual() == false)) {
IFolder folder = workspaceRoot.getFolder(destinationPath);
if (createVirtual) {
- folder.create(IResource.VIRTUAL, true,
- new SubProgressMonitor(monitor, 1));
- IResource[] members = ((IContainer) source)
- .members();
+ folder.create(IResource.VIRTUAL, true, iterationProgress.newChild(1));
+ IResource[] members = ((IContainer) source).members();
if (members.length > 0) {
- overwrittenResources.addAll(Arrays.asList(copy(
- members, destinationPath,
- resourcesAtDestination,
- new SubProgressMonitor(monitor, 1),
- uiInfo, false, createVirtual,
- createLinks, relativeToVariable)));
+ overwrittenResources.addAll(Arrays.asList(copy(members, destinationPath,
+ resourcesAtDestination, iterationProgress.newChild(99), uiInfo, false,
+ createVirtual, createLinks, relativeToVariable)));
}
} else
- folder.createLink(createRelativePath(source
- .getLocationURI(), relativeToVariable, folder), 0,
- new SubProgressMonitor(monitor, 1));
+ folder.createLink(createRelativePath(source.getLocationURI(), relativeToVariable, folder),
+ 0, iterationProgress.newChild(100));
} else
- source.copy(destinationPath, IResource.SHALLOW,
- new SubProgressMonitor(monitor, 1));
+ source.copy(destinationPath, IResource.SHALLOW, iterationProgress.newChild(100));
// 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]);
}
@@ -405,37 +381,29 @@ public class WorkspaceUndoUtil {
// destination
ResourceDescription[] deleted = delete(
new IResource[] { existing },
- new SubProgressMonitor(monitor, 0), uiInfo,
+ iterationProgress.newChild(1), uiInfo,
false);
+ iterationProgress.setWorkRemaining(100);
if (source.getType() == IResource.FILE) {
IFile file = workspaceRoot.getFile(destinationPath);
file.createLink(createRelativePath(
source.getLocationURI(), relativeToVariable, file), 0,
- new SubProgressMonitor(monitor, 1));
+ iterationProgress.newChild(100));
} else {
IFolder folder = workspaceRoot
.getFolder(destinationPath);
if (createVirtual) {
- folder.create(IResource.VIRTUAL, true,
- new SubProgressMonitor(monitor, 1));
- IResource[] members = ((IContainer) source)
- .members();
+ folder.create(IResource.VIRTUAL, true, iterationProgress.newChild(1));
+ IResource[] members = ((IContainer) source).members();
if (members.length > 0) {
- overwrittenResources.addAll(Arrays
- .asList(copy(members,
- destinationPath,
- resourcesAtDestination,
- new SubProgressMonitor(
- monitor, 1),
- uiInfo, false,
- createVirtual, createLinks,
- relativeToVariable)));
-
+ overwrittenResources.addAll(Arrays.asList(copy(members, destinationPath,
+ resourcesAtDestination, iterationProgress.newChild(99), uiInfo, false,
+ createVirtual, createLinks, relativeToVariable)));
}
} else
- folder.createLink(createRelativePath(
- source.getLocationURI(), relativeToVariable, folder),
- 0, new SubProgressMonitor(monitor, 1));
+ folder.createLink(
+ createRelativePath(source.getLocationURI(), relativeToVariable, folder), 0,
+ iterationProgress.newChild(100));
}
resourcesAtDestination.add(getWorkspace().getRoot()
.findMember(destinationPath));
@@ -444,9 +412,8 @@ public class WorkspaceUndoUtil {
}
} else {
if (source.isLinked() == existing.isLinked()) {
- overwrittenResources.add(copyOverExistingResource(
- source, existing, new SubProgressMonitor(
- monitor, 1), uiInfo, false));
+ overwrittenResources.add(copyOverExistingResource(source, existing,
+ iterationProgress.newChild(100), uiInfo, false));
// Record the "copy"
resourcesAtDestination.add(existing);
} else {
@@ -455,10 +422,9 @@ public class WorkspaceUndoUtil {
// 28772.
ResourceDescription[] deleted = delete(
new IResource[] { existing },
- new SubProgressMonitor(monitor, 0), uiInfo,
+ iterationProgress.newChild(1), uiInfo,
false);
- source.copy(destinationPath, IResource.SHALLOW,
- new SubProgressMonitor(monitor, 1));
+ source.copy(destinationPath, IResource.SHALLOW, iterationProgress.newChild(99));
// Record the copy
resourcesAtDestination.add(getWorkspace().getRoot()
.findMember(destinationPath));
@@ -482,33 +448,25 @@ public class WorkspaceUndoUtil {
IFile file = workspaceRoot.getFile(destinationPath);
file.createLink(createRelativePath(
source.getLocationURI(), relativeToVariable, file), 0,
- new SubProgressMonitor(monitor, 1));
+ iterationProgress.newChild(100));
} else {
IFolder folder = workspaceRoot
.getFolder(destinationPath);
if (createVirtual) {
- folder.create(IResource.VIRTUAL, true,
- new SubProgressMonitor(monitor, 1));
+ folder.create(IResource.VIRTUAL, true, iterationProgress.newChild(1));
IResource[] members = ((IContainer) source).members();
if (members.length > 0) {
- overwrittenResources.addAll(Arrays
- .asList(copy(members,
- destinationPath,
- resourcesAtDestination,
- new SubProgressMonitor(
- monitor, 1),
- uiInfo, false,
- createVirtual, createLinks,
- relativeToVariable)));
-
+ overwrittenResources.addAll(Arrays.asList(copy(members, destinationPath,
+ resourcesAtDestination, iterationProgress.newChild(99), uiInfo, false,
+ createVirtual, createLinks, relativeToVariable)));
}
} else
- folder.createLink(createRelativePath(source.getLocationURI(), relativeToVariable, folder),
- 0, new SubProgressMonitor(monitor, 1));
+ folder.createLink(
+ createRelativePath(source.getLocationURI(), relativeToVariable, folder), 0,
+ iterationProgress.newChild(100));
}
} else
- source.copy(destinationPath, IResource.SHALLOW,
- new SubProgressMonitor(monitor, 1));
+ source.copy(destinationPath, IResource.SHALLOW, iterationProgress.newChild(100));
// Record the copy. If we had to generate a parent
// folder, that should be recorded as part of the copy
if (generatedParent == null) {
@@ -519,13 +477,12 @@ public class WorkspaceUndoUtil {
}
}
- if (monitor.isCanceled()) {
+ if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
}
}
- monitor.done();
- return (ResourceDescription[]) overwrittenResources
+ return overwrittenResources
.toArray(new ResourceDescription[overwrittenResources.size()]);
}
@@ -564,13 +521,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 monitor
+ * @param mon
* 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
@@ -584,16 +541,15 @@ public class WorkspaceUndoUtil {
* @throws CoreException
* propagates any CoreExceptions thrown from the resources API
*/
- static ResourceDescription[] move(IResource[] resources, IPath destination,
- List resourcesAtDestination, List reverseDestinations,
- IProgressMonitor monitor, IAdaptable uiInfo,
- boolean pathIncludesName) throws CoreException {
+ static ResourceDescription[] move(IResource[] resources, IPath destination, List<IResource> resourcesAtDestination,
+ List<IPath> reverseDestinations, IProgressMonitor mon, IAdaptable uiInfo, boolean pathIncludesName)
+ throws CoreException {
- monitor.beginTask("", resources.length); //$NON-NLS-1$
- monitor
- .setTaskName(UndoMessages.AbstractResourcesOperation_MovingResources);
- List overwrittenResources = new ArrayList();
+ SubMonitor subMonitor = SubMonitor.convert(mon, resources.length);
+ subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_MovingResources);
+ List<ResourceDescription> overwrittenResources = new ArrayList<>();
for (int i = 0; i < resources.length; i++) {
+ SubMonitor iterationProgress = subMonitor.newChild(1);
IResource source = resources[i];
IPath destinationPath;
if (pathIncludesName) {
@@ -607,36 +563,31 @@ 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, 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]);
- }
+ 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]);
+ }
// Delete the source. No need to record it since it
// will get moved back.
- delete(source, monitor, uiInfo, false, false);
+ delete(source, iterationProgress.newChild(10), 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 },
- new SubProgressMonitor(monitor, 0), uiInfo, false);
+ ResourceDescription[] deleted = delete(new IResource[] { existing }, iterationProgress.newChild(10),
+ uiInfo, false);
// Record the original path
reverseDestinations.add(source.getFullPath());
- source.move(destinationPath, IResource.SHALLOW
- | IResource.KEEP_HISTORY, new SubProgressMonitor(
- monitor, 1));
+ source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY,
+ iterationProgress.newChild(90));
// 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]);
}
@@ -646,21 +597,20 @@ public class WorkspaceUndoUtil {
if (source.isLinked() == existing.isLinked()) {
// Record the original path
reverseDestinations.add(source.getFullPath());
- overwrittenResources.add(copyOverExistingResource(
- source, existing, new SubProgressMonitor(
- monitor, 1), uiInfo, true));
+ overwrittenResources.add(copyOverExistingResource(source, existing,
+ iterationProgress.newChild(100), 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 },
- new SubProgressMonitor(monitor, 0), uiInfo,
+ iterationProgress.newChild(1), uiInfo,
false);
reverseDestinations.add(source.getFullPath());
source.move(destinationPath, IResource.SHALLOW
| IResource.KEEP_HISTORY,
- new SubProgressMonitor(monitor, 1));
+ iterationProgress.newChild(99));
// Record the resource at its destination
resourcesAtDestination.add(getWorkspace().getRoot()
.findMember(destinationPath));
@@ -679,9 +629,8 @@ public class WorkspaceUndoUtil {
}
IContainer generatedParent = generateContainers(parentPath);
- source.move(destinationPath, IResource.SHALLOW
- | IResource.KEEP_HISTORY, new SubProgressMonitor(
- monitor, 1));
+ source.move(destinationPath, IResource.SHALLOW | IResource.KEEP_HISTORY,
+ iterationProgress.newChild(100));
// Record the move. If we had to generate a parent
// folder, that should be recorded as part of the copy
if (generatedParent == null) {
@@ -692,13 +641,12 @@ public class WorkspaceUndoUtil {
}
}
- if (monitor.isCanceled()) {
+ if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
}
}
- monitor.done();
- return (ResourceDescription[]) overwrittenResources
+ return overwrittenResources
.toArray(new ResourceDescription[overwrittenResources.size()]);
}
@@ -709,12 +657,12 @@ public class WorkspaceUndoUtil {
* @return The linked resources
*/
private static IResource[] filterNonLinkedResources(IResource[] resources) {
- List result = new ArrayList();
+ List<IResource> result = new ArrayList<>();
for (int i = 0; i < resources.length; i++) {
if (resources[i].isLinked())
result.add(resources[i]);
}
- return (IResource[]) result.toArray(new IResource[0]);
+ return result.toArray(new IResource[0]);
}
/**
@@ -736,29 +684,23 @@ public class WorkspaceUndoUtil {
*/
static IResource[] recreate(ResourceDescription[] resourcesToRecreate,
IProgressMonitor monitor, IAdaptable uiInfo) throws CoreException {
- final List exceptions = new ArrayList();
+ SubMonitor subMonitor = SubMonitor.convert(monitor, resourcesToRecreate.length);
+ final List<CoreException> exceptions = new ArrayList<>();
IResource[] resourcesToReturn = new IResource[resourcesToRecreate.length];
- 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);
- }
+ subMonitor.setTaskName(UndoMessages.AbstractResourcesOperation_CreateResourcesProgress);
+ for (int i = 0; i < resourcesToRecreate.length; ++i) {
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
}
- IStatus result = WorkspaceUndoUtil.createResult(exceptions);
- if (!result.isOK()) {
- throw new CoreException(result);
+ try {
+ resourcesToReturn[i] = resourcesToRecreate[i].createResource(subMonitor.newChild(1));
+ } catch (CoreException e) {
+ exceptions.add(e);
}
- } finally {
- monitor.done();
+ }
+ IStatus result = WorkspaceUndoUtil.createResult(exceptions);
+ if (!result.isOK()) {
+ throw new CoreException(result);
}
return resourcesToReturn;
}
@@ -792,17 +734,18 @@ 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
- monitor
+ subMonitor
.setTaskName(UndoMessages.AbstractResourcesOperation_DeleteResourcesProgress);
IProject project = (IProject) resourceToDelete;
- project.delete(deleteContent, forceOutOfSyncDelete, monitor);
+ project.delete(deleteContent, forceOutOfSyncDelete, subMonitor);
} else {
// if it's not a project, just delete it
- monitor.beginTask("", 2); //$NON-NLS-1$
+ subMonitor.setWorkRemaining(2);
monitor
.setTaskName(UndoMessages.AbstractResourcesOperation_DeleteResourcesProgress);
int updateFlags;
@@ -811,11 +754,8 @@ public class WorkspaceUndoUtil {
} else {
updateFlags = IResource.KEEP_HISTORY;
}
- resourceToDelete.delete(updateFlags, new SubProgressMonitor(
- monitor, 1));
- resourceDescription.recordStateFromHistory(resourceToDelete,
- new SubProgressMonitor(monitor, 1));
- monitor.done();
+ resourceToDelete.delete(updateFlags, subMonitor.newChild(1));
+ resourceDescription.recordStateFromHistory(resourceToDelete, subMonitor.newChild(1));
}
return resourceDescription;
@@ -834,35 +774,26 @@ public class WorkspaceUndoUtil {
}
IFile file = (IFile) source;
IFile existingFile = (IFile) existing;
- monitor
- .beginTask(
- UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress,
- 3);
+ SubMonitor subMonitor = SubMonitor.convert(monitor,
+ UndoMessages.AbstractResourcesOperation_CopyingResourcesProgress, deleteSourceFile ? 3 : 2);
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, new SubProgressMonitor(monitor,
- 1));
- fileDescription.recordStateFromHistory(existingFile,
- new SubProgressMonitor(monitor, 1));
+ existingFile.setContents(file.getContents(), IResource.KEEP_HISTORY, subMonitor.newChild(1));
+ fileDescription.recordStateFromHistory(existingFile, subMonitor.newChild(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, new SubProgressMonitor(
- monitor, 1));
+ file.delete(IResource.KEEP_HISTORY, subMonitor.newChild(1));
}
- monitor.done();
return fileDescription;
}
}
- monitor.done();
return null;
}
@@ -946,15 +877,15 @@ public class WorkspaceUndoUtil {
* Creates and return a result status appropriate for the given list of
* exceptions.
*/
- private static IStatus createResult(List exceptions) {
+ private static IStatus createResult(List<CoreException> exceptions) {
if (exceptions.isEmpty()) {
return Status.OK_STATUS;
}
final int exceptionCount = exceptions.size();
if (exceptionCount == 1) {
- return ((CoreException) exceptions.get(0)).getStatus();
+ return exceptions.get(0).getStatus();
}
- CoreException[] children = (CoreException[]) exceptions
+ CoreException[] children = 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 c40614f4d9e..026f21409af 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -313,15 +313,10 @@ public class CleanDialog extends MessageDialog {
if (cleanAll) {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, monitor);
} else {
- 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();
+ 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));
}
}
}
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 3977153b39c..f68dcdc60ad 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -545,30 +545,24 @@ 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 -> {
- 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();
- }
+ 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();
}
- } 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 fc5a713f7d5..ad34cd06e8a 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,8 +25,7 @@ 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.NullProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.ui.IWorkingSet;
/**
@@ -56,7 +55,7 @@ public class WorkingSetResourceMapping extends ResourceMapping {
@Override
public IProject[] getProjects() {
- Set result = new HashSet();
+ Set<IProject> result = new HashSet<>();
ResourceMapping[] mappings = getMappings();
for (int i = 0; i < mappings.length; i++) {
ResourceMapping mapping = mappings[i];
@@ -66,25 +65,21 @@ public class WorkingSetResourceMapping extends ResourceMapping {
result.add(project);
}
}
- return (IProject[]) result.toArray(new IProject[result.size()]);
+ return result.toArray(new IProject[result.size()]);
}
@Override
- 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();
+ 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))));
}
+ return result.toArray(new ResourceTraversal[result.size()]);
}
/**
@@ -93,7 +88,7 @@ public class WorkingSetResourceMapping extends ResourceMapping {
*/
private ResourceMapping[] getMappings() {
IAdaptable[] elements = set.getElements();
- List result = new ArrayList();
+ List<ResourceMapping> result = new ArrayList<>();
for (int i = 0; i < elements.length; i++) {
IAdaptable element = elements[i];
ResourceMapping mapping = WorkingSetAdapterFactory.getContributedResourceMapping(element);
@@ -104,7 +99,7 @@ public class WorkingSetResourceMapping extends ResourceMapping {
result.add(mapping);
}
}
- return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]);
+ return 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 e23033b0fef..b4d55cbef61 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.ui.ide.dialogs.UIResourceFilterDescription;
import org.eclipse.ui.ide.undo.ResourceDescription;
@@ -176,48 +176,42 @@ 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 void createChildResources(IContainer parentHandle,
- IProgressMonitor monitor, int ticks) throws CoreException {
-
+ protected final void createChildResources(IContainer parentHandle,
+ IProgressMonitor monitor) 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(new SubProgressMonitor(monitor, ticks
- / members.length));
+ members[i].createResource(subMonitor.newChild(1));
}
}
}
@Override
- public void recordStateFromHistory(IResource resource,
- IProgressMonitor monitor) throws CoreException {
- monitor.beginTask(
- UndoMessages.FolderDescription_SavingUndoInfoProgress, 100);
+ public void recordStateFromHistory(IResource resource, IProgressMonitor mon) throws CoreException {
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,
- new SubProgressMonitor(monitor, 100 / members.length));
+ members[i].recordStateFromHistory(fileHandle, iterationMonitor);
} 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,
- new SubProgressMonitor(monitor, 100 / members.length));
+ members[i].recordStateFromHistory(folderHandle, iterationMonitor);
}
}
}
- 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 e7f4ec67024..8785d37bc8a 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
/**
* FileDescription is a lightweight description that describes a file to be
@@ -132,23 +132,21 @@ public class FileDescription extends AbstractResourceDescription {
}
@Override
- public void createExistentResourceFromHandle(IResource resource,
- IProgressMonitor monitor) throws CoreException {
+ public void createExistentResourceFromHandle(IResource resource, IProgressMonitor mon) throws CoreException {
Assert.isLegal(resource instanceof IFile);
if (resource.exists()) {
return;
}
IFile fileHandle = (IFile) resource;
- monitor.beginTask("", 200); //$NON-NLS-1$
- monitor.setTaskName(UndoMessages.FileDescription_NewFileProgress);
+ SubMonitor subMonitor = SubMonitor.convert(mon, 200);
+ subMonitor.setTaskName(UndoMessages.FileDescription_NewFileProgress);
try {
- if (monitor.isCanceled()) {
+ if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
if (location != null) {
- fileHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL,
- new SubProgressMonitor(monitor, 200));
+ fileHandle.createLink(location, IResource.ALLOW_MISSING_LOCAL, subMonitor.newChild(200));
} else {
InputStream contents = new ByteArrayInputStream(
UndoMessages.FileDescription_ContentsCouldNotBeRestored
@@ -161,12 +159,10 @@ public class FileDescription extends AbstractResourceDescription {
&& fileContentDescription.exists()) {
contents = fileContentDescription.getContents();
}
- fileHandle.create(contents, false, new SubProgressMonitor(
- monitor, 100));
- fileHandle.setCharset(charset, new SubProgressMonitor(monitor,
- 100));
+ fileHandle.create(contents, false, subMonitor.newChild(100));
+ fileHandle.setCharset(charset, subMonitor.newChild(100));
}
- if (monitor.isCanceled()) {
+ if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
} catch (CoreException e) {
@@ -175,8 +171,6 @@ 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 305007b8812..e0a8e7de9e4 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
/**
* FolderDescription is a lightweight description that describes a folder to be
@@ -75,41 +75,33 @@ public class FolderDescription extends ContainerDescription {
}
@Override
- public void createExistentResourceFromHandle(IResource resource,
- IProgressMonitor monitor) throws CoreException {
-
+ public void createExistentResourceFromHandle(IResource resource, IProgressMonitor mon) throws CoreException {
Assert.isLegal(resource instanceof IFolder);
if (resource.exists()) {
return;
}
IFolder folderHandle = (IFolder) resource;
- 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();
+ 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));
}
- 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 862dc9535bb..b36ccb1fad2 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
/**
* ProjectDescription is a lightweight description that describes a project to
@@ -79,28 +79,25 @@ 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;
- monitor.beginTask("", 200); //$NON-NLS-1$
- monitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress);
+ subMonitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress);
if (projectDescription == null) {
- projectHandle.create(new SubProgressMonitor(monitor, 100));
+ projectHandle.create(subMonitor.newChild(100));
} else {
- projectHandle.create(projectDescription, new SubProgressMonitor(
- monitor, 100));
+ projectHandle.create(projectDescription, subMonitor.newChild(100));
}
- if (monitor.isCanceled()) {
+ if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
if (openOnCreate) {
- projectHandle.open(IResource.NONE,
- new SubProgressMonitor(monitor, 100));
+ projectHandle.open(IResource.NONE, subMonitor.newChild(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 1e2f39a9e1c..3459bef96db 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
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, monitor -> {
- monitor.beginTask(MarkerMessages.markCompletedHandler_task, 100);
+ PlatformUI.getWorkbench().getProgressService().run(true, true, mon -> {
+ SubMonitor subMonitor = SubMonitor.convert(mon, MarkerMessages.markCompletedHandler_task, 100);
IMarker[] markers = getSelectedMarkers(finalEvent);
if (markers.length == 0) {
return;
@@ -52,12 +52,11 @@ public class MarkCompletedHandler extends MarkerViewHandler {
IUndoableOperation op = new UpdateMarkersOperation(markers, attrs,
MarkerMessages.markCompletedAction_title, true);
- monitor.worked(20);
- if(monitor.isCanceled()) {
+ subMonitor.worked(20);
+ if (subMonitor.isCanceled()) {
return;
}
- execute(op, MarkerMessages.markCompletedAction_title, new SubProgressMonitor(monitor, 80), null);
- monitor.done();
+ execute(op, MarkerMessages.markCompletedAction_title, subMonitor.newChild(80), null);
});
} 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 7ee6e58161d..d4ca28c62f7 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
@@ -68,23 +68,20 @@ class QuickFixWizard extends Wizard {
@Override
public boolean performFinish() {
- 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();
-
-};
+ 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));
+ }
+ };
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 a42a7fe6a24..56d407980bf 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogSettings;
@@ -1186,28 +1186,23 @@ 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 {
- 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();
+ 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));
}
}
};
@@ -1271,8 +1266,9 @@ public class WizardProjectsImportPage extends WizardDataTransferPage {
* @return status of the creation
* @throws InterruptedException
*/
- private IStatus createExistingProject(final ProjectRecord record, IProgressMonitor monitor)
+ private IStatus createExistingProject(final ProjectRecord record, IProgressMonitor mon)
throws InterruptedException {
+ SubMonitor subMonitor = SubMonitor.convert(mon, 3);
String projectName = record.getProjectName();
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProject project = workspace.getRoot().getProject(projectName);
@@ -1302,7 +1298,7 @@ public class WizardProjectsImportPage extends WizardDataTransferPage {
structureProvider, this, fileSystemObjects);
operation.setContext(getShell());
try {
- operation.run(monitor);
+ operation.run(subMonitor.newChild(1));
} catch (InvocationTargetException e) {
if (e.getCause() instanceof CoreException) {
return ((CoreException) e.getCause()).getStatus();
@@ -1312,6 +1308,7 @@ public class WizardProjectsImportPage extends WizardDataTransferPage {
}
return operation.getStatus();
}
+
// import from file system
File importSource = null;
if (copyFiles) {
@@ -1342,19 +1339,16 @@ public class WizardProjectsImportPage extends WizardDataTransferPage {
}
}
+ subMonitor.setWorkRemaining((copyFiles && importSource != null) ? 2 : 1);
+
try {
- monitor
- .beginTask(
- DataTransferMessages.WizardProjectsImportPage_CreateProjectsTask,
- 100);
- project.create(record.description, new SubProgressMonitor(monitor,
- 30));
- project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(
- monitor, 70));
+ 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$
} catch (CoreException e) {
return e.getStatus();
- } finally {
- monitor.done();
}
// import operation to import project files if copy checkbox is selected
@@ -1370,7 +1364,7 @@ public class WizardProjectsImportPage extends WizardDataTransferPage {
// files
operation.setCreateContainerStructure(false);
try {
- operation.run(monitor);
+ operation.run(subMonitor.newChild(1));
} 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 7d93b4ced65..bb242c47ac9 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
@@ -77,8 +77,6 @@ public class ImportOperation extends WorkspaceModifyOperation {
private IImportStructureProvider provider;
- private IProgressMonitor monitor;
-
protected IOverwriteQuery overwriteCallback;
private Shell context;
@@ -231,9 +229,10 @@ 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) {
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ 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();
Iterator sourceIter = sources.iterator();
IPath sourceRootPath = null;
@@ -272,9 +271,8 @@ public class ImportOperation extends WorkspaceModifyOperation {
}
}
if (provider.isFolder(nextSource)) {
- collectExistingReadonlyFiles(newDestinationPath, provider
- .getChildren(nextSource), noOverwrite,
- overwriteReadonly, POLICY_FORCE_OVERWRITE);
+ collectExistingReadonlyFiles(newDestinationPath, provider.getChildren(nextSource), noOverwrite,
+ overwriteReadonly, POLICY_FORCE_OVERWRITE, subMonitor.newChild(100));
}
} else {
IFile file = getFile(newDestination);
@@ -373,41 +371,24 @@ public class ImportOperation extends WorkspaceModifyOperation {
@Override
protected void execute(IProgressMonitor progressMonitor) {
-
- monitor = progressMonitor;
-
+ SubMonitor subMonitor = SubMonitor.convert(progressMonitor, DataTransferMessages.DataTransfer_importTask, 100);
try {
if (selectedFiles == null) {
- //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);
+ 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));
} else {
// Choose twice the selected files size to take folders into account
- 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();
+ ContainerGenerator generator = new ContainerGenerator(destinationPath);
+ subMonitor.worked(3);
+ validateFiles(selectedFiles, subMonitor.newChild(3));
+ destinationContainer = generator.generateContainer(subMonitor.newChild(4));
+ importFileSystemObjects(selectedFiles, subMonitor.newChild(90));
}
} catch (CoreException e) {
errorTable.add(e.getStatus());
- } finally {
- monitor.done();
}
}
@@ -519,7 +500,8 @@ 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) {
+ void importFile(Object fileObject, int policy, IProgressMonitor mon) {
+ SubMonitor subMonitor = SubMonitor.convert(mon, 100);
IContainer containerResource;
try {
containerResource = getDestinationContainerFor(fileObject);
@@ -533,10 +515,9 @@ public class ImportOperation extends WorkspaceModifyOperation {
}
String fileObjectPath = provider.getFullPath(fileObject);
- monitor.subTask(fileObjectPath);
+ subMonitor.subTask(fileObjectPath);
IFile targetResource = containerResource.getFile(new Path(provider
.getLabel(fileObject)));
- monitor.worked(1);
if (rejectedFiles.contains(targetResource.getFullPath())) {
return;
@@ -564,51 +545,44 @@ public class ImportOperation extends WorkspaceModifyOperation {
return;
}
- 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));
- }
- }
- }
+ 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));
+ }
+ }
+ }
/**
* Reuse the file attributes set in the import.
@@ -657,9 +631,11 @@ public class ImportOperation extends WorkspaceModifyOperation {
* @throws CoreException
* @exception OperationCanceledException if canceled
*/
- void importFileSystemObjects(List filesToImport) throws CoreException {
+ void importFileSystemObjects(List filesToImport, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, filesToImport.size());
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
@@ -676,7 +652,7 @@ public class ImportOperation extends WorkspaceModifyOperation {
}
source = sourcePath.toFile();
}
- importRecursivelyFrom(fileSystemObject, POLICY_DEFAULT);
+ importRecursivelyFrom(fileSystemObject, POLICY_DEFAULT, iterationMonitor);
}
}
@@ -690,7 +666,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) throws CoreException {
+ int importFolder(Object folderObject, int policy, IProgressMonitor monitor) throws CoreException {
IContainer containerResource;
try {
containerResource = getDestinationContainerFor(folderObject);
@@ -778,22 +754,23 @@ public class ImportOperation extends WorkspaceModifyOperation {
* @throws CoreException
* @exception OperationCanceledException if canceled
*/
- void importRecursivelyFrom(Object fileSystemObject, int policy) throws CoreException {
- if (monitor.isCanceled()) {
+ void importRecursivelyFrom(Object fileSystemObject, int policy, IProgressMonitor mon) throws CoreException {
+ SubMonitor subMonitor = SubMonitor.convert(mon, 100);
+ if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
if (!provider.isFolder(fileSystemObject)) {
- importFile(fileSystemObject, policy);
+ importFile(fileSystemObject, policy, subMonitor.newChild(100));
return;
}
- int childPolicy = importFolder(fileSystemObject, policy);
+ int childPolicy = importFolder(fileSystemObject, policy, subMonitor.newChild(10));
if (childPolicy != POLICY_SKIP_CHILDREN) {
- Iterator children = provider.getChildren(fileSystemObject)
- .iterator();
- while (children.hasNext()) {
- importRecursivelyFrom(children.next(), childPolicy);
+ List children = provider.getChildren(fileSystemObject);
+ SubMonitor loopMonitor = subMonitor.newChild(90).setWorkRemaining(children.size());
+ for (Object child : children) {
+ importRecursivelyFrom(child, childPolicy, loopMonitor.newChild(1));
}
}
}
@@ -942,14 +919,14 @@ public class ImportOperation extends WorkspaceModifyOperation {
*
* @param sourceFiles files to validate
*/
- void validateFiles(List sourceFiles) {
+ void validateFiles(List sourceFiles, IProgressMonitor monitor) {
ArrayList noOverwrite = new ArrayList();
ArrayList overwriteReadonly = new ArrayList();
- collectExistingReadonlyFiles(destinationPath, sourceFiles, noOverwrite,
- overwriteReadonly, POLICY_DEFAULT);
- rejectedFiles = validateEdit(overwriteReadonly);
- rejectedFiles.addAll(noOverwrite);
+ collectExistingReadonlyFiles(destinationPath, sourceFiles, noOverwrite, overwriteReadonly, POLICY_DEFAULT,
+ monitor);
+ 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 bb4ebb27ad1..e07fa7328d4 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.WizardPage;
@@ -437,14 +437,12 @@ public class WizardExternalProjectImportPage extends WizardPage {
@Override
protected void execute(IProgressMonitor monitor)
throws CoreException {
- monitor.beginTask("", 2000); //$NON-NLS-1$
- project.create(description, new SubProgressMonitor(monitor,
- 1000));
- if (monitor.isCanceled()) {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
+ project.create(description, subMonitor.newChild(50));
+ if (subMonitor.isCanceled()) {
throw new OperationCanceledException();
}
- project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1000));
-
+ project.open(IResource.BACKGROUND_REFRESH, subMonitor.newChild(50));
}
};
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 ed5ad50bf52..b34b4d728cd 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
@@ -2091,22 +2091,16 @@ public abstract class FilteredItemsSelectionDialog extends
lastCompletedFilter = null;
lastCompletedResult = null;
- SubProgressMonitor subMonitor = null;
- if (monitor != null) {
- monitor
- .beginTask(
+ SubMonitor subMonitor = SubMonitor.convert(monitor,
WorkbenchMessages.FilteredItemsSelectionDialog_searchJob_taskName,
100);
- subMonitor = new SubProgressMonitor(monitor, 95);
- }
-
- fillContentProvider(contentProvider, itemsFilter, subMonitor);
+ fillContentProvider(contentProvider, itemsFilter, subMonitor.newChild(95));
if (monitor != null && !monitor.isCanceled()) {
- monitor.worked(2);
+ subMonitor.worked(2);
contentProvider.rememberResult(itemsFilter);
- monitor.worked(3);
+ subMonitor.worked(3);
}
}
@@ -2816,61 +2810,41 @@ 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;
- if (monitor != null) {
- // the work is divided into two actions of the same length
- int totalWork = checkDuplicates ? 200 : 100;
+ // the work is divided into two actions of the same length
+ int totalWork = checkDuplicates ? 200 : 100;
- monitor
- .beginTask(
- WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob,
- totalWork);
- }
+ SubMonitor subMonitor = SubMonitor.convert(monitor,
+ WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob, totalWork);
// the TableViewer's root (the input) is treated as parent
- lastFilteredItems = Arrays.asList(getFilteredItems(list.getInput(),
- monitor != null ? new SubProgressMonitor(monitor, 100)
- : null));
+ lastFilteredItems = Arrays.asList(getFilteredItems(list.getInput(), subMonitor.newChild(100)));
- if (reset || (monitor != null && monitor.isCanceled())) {
- if (monitor != null)
- monitor.done();
+ if (reset || subMonitor.isCanceled()) {
return;
}
if (checkDuplicates) {
- checkDuplicates(monitor);
+ checkDuplicates(subMonitor.newChild(100));
}
- if (monitor != null)
- monitor.done();
}
private void checkDuplicates(IProgressMonitor monitor) {
synchronized (lastFilteredItems) {
- 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();
+ SubMonitor subMonitor = SubMonitor.convert(monitor,
+ WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob_checkDuplicates,
+ lastFilteredItems.size());
+ HashMap<String, Object> helperMap = new HashMap<>();
for (int i = 0; i < lastFilteredItems.size(); i++) {
- if (reset
- || (subMonitor != null && subMonitor.isCanceled()))
+ if (reset || 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);
@@ -2879,9 +2853,7 @@ public abstract class FilteredItemsSelectionDialog extends
}
}
- if (subMonitor != null && reportEvery != 0
- && (i + 1) % reportEvery == 0)
- subMonitor.worked(1);
+ 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 bf55b297630..f901028ec14 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,7 +25,6 @@ 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;
@@ -189,18 +188,18 @@ public class SaveableHelper {
@Override
public void run(IProgressMonitor monitor) {
IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor);
- monitorWrap.beginTask(WorkbenchMessages.Save, dirtyModels.size());
+ SubMonitor subMonitor = SubMonitor.convert(monitorWrap, 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()) {
- monitor.worked(1);
+ subMonitor.worked(1);
continue;
}
- doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), window, confirm);
- if (monitor.isCanceled()) {
+ doSaveModel(model, subMonitor.newChild(1), window, confirm);
+ if (subMonitor.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 86cf326693a..02714ac565d 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.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
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);
- monitorWrap.beginTask(WorkbenchMessages.Saving_Modifications, finalModels.size());
+ IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor);
+ SubMonitor subMonitor = SubMonitor.convert(monitorWrap, 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()) {
- monitor.worked(1);
+ subMonitor.worked(1);
continue;
}
- SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1),
+ SaveableHelper.doSaveModel(model, subMonitor.newChild(1),
shellProvider, blockUntilSaved);
- if (monitorWrap.isCanceled())
+ if (subMonitor.isCanceled())
break;
}
monitorWrap.done();

Back to the top