Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Xenos2015-09-14 19:39:08 +0000
committerStefan Xenos2015-09-15 20:29:09 +0000
commit9468f370adbfd4af0d76c4ec6e6c22edb43162e4 (patch)
treee1acd4ae24134e54a0cd31ed66a62074b959c2f7
parentd7a1117af7376fa32af298daeb4065bfcd631551 (diff)
downloadeclipse.platform.ui-9468f370adbfd4af0d76c4ec6e6c22edb43162e4.tar.gz
eclipse.platform.ui-9468f370adbfd4af0d76c4ec6e6c22edb43162e4.tar.xz
eclipse.platform.ui-9468f370adbfd4af0d76c4ec6e6c22edb43162e4.zip
Bug 475785 - Remove usage of SubProgressMonitor in org.eclipse.ui.internal.wizards.datatransfer
Change-Id: Id1697717ee0e6fb7e1eecf2680486f9ddc1312a9 Signed-off-by: Stefan Xenos <sxenos@gmail.com>
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardProjectsImportPage.java62
1 files changed, 28 insertions, 34 deletions
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();

Back to the top