[Importer] Better error handling
diff --git a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/EasymportJob.java b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/EasymportJob.java
index 503c3d0..390a650 100644
--- a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/EasymportJob.java
+++ b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/EasymportJob.java
@@ -56,6 +56,7 @@
private Map<IProject, List<ProjectConfigurator>> report;
private boolean isRootANewProject;
private boolean discardRootProject;
+ private Map<IPath, Exception> errors;
private JobGroup crawlerJobGroup;
@@ -71,6 +72,7 @@
this.recursiveConfigure = recuriveConfigure;
this.report = new HashMap<>();
this.crawlerJobGroup = new JobGroup("Detecting and configurating nested projects", 0, 1);
+ this.errors = new HashMap<>();
}
public void setListener(RecursiveImportListener listener) {
@@ -233,7 +235,15 @@
mainProjectConfigurators.add(configurator);
if (project == null) {
// Create project
- project = toExistingOrNewProject(container.getLocation().toFile(), progressMonitor, IResource.BACKGROUND_REFRESH);
+ try {
+ project = toExistingOrNewProject(container.getLocation().toFile(), progressMonitor, IResource.BACKGROUND_REFRESH);
+ } catch (CouldNotImportProjectException ex) {
+ this.errors.put(container.getLocation(), ex);
+ if (this.listener != null) {
+ this.listener.errorHappened(container.getLocation(), ex);
+ }
+ return projectFromCurrentContainer;
+ }
if (this.listener != null) {
this.listener.projectCreated(project);
}
@@ -262,7 +272,15 @@
if (allNestedProjects.isEmpty() && isRootProject) {
// No sub-project found, so apply available configurators anyway
progressMonitor.beginTask("Configuring 'leaf' of project at " + container.getLocation().toFile().getAbsolutePath(), activeConfigurators.size());
- project = toExistingOrNewProject(container.getLocation().toFile(), progressMonitor, IResource.NONE);
+ try {
+ project = toExistingOrNewProject(container.getLocation().toFile(), progressMonitor, IResource.BACKGROUND_REFRESH);
+ } catch (CouldNotImportProjectException ex) {
+ this.errors.put(container.getLocation(), ex);
+ if (this.listener != null) {
+ this.listener.errorHappened(container.getLocation(), ex);
+ }
+ return projectFromCurrentContainer;
+ }
if (this.listener != null) {
listener.projectCreated(project);
}
@@ -370,6 +388,10 @@
}
public Map<IProject, List<ProjectConfigurator>> getConfiguredProjects() {
- return report;
+ return this.report;
+ }
+
+ public Map<IPath, Exception> getErrors() {
+ return this.errors;
}
}
diff --git a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/EasymportJobReportDialog.java b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/EasymportJobReportDialog.java
index ae918bb..96ddded 100644
--- a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/EasymportJobReportDialog.java
+++ b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/EasymportJobReportDialog.java
@@ -57,7 +57,6 @@
private Label abortedStatusLabel;
private Button stopButton;
private boolean cancel;
- private Label label;
public EasymportJobReportDialog(Shell shell, EasymportJob job) {
super(shell);
@@ -111,13 +110,15 @@
getShell().setText(Messages.EasymportWizardPage_nestedProjects);
// setDescription(Messages.EasymportWizardPage_detectNestedProjects);
// setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.getDefault().getBundle().getSymbolicName(), "pics/wizban/nestedProjects.png")); //$NON-NLS-1$
- Composite res = new Composite(parent, SWT.NONE);
+ final Composite res = new Composite(parent, SWT.NONE);
res.setLayout(new GridLayout(2, false));
res.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- label = new Label(res, SWT.NONE);
- label.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1));
- label.setText(NLS.bind(Messages.EasymportWizardPage_importedProjects, 1));
+ //// Nested projects
+ final Label nestedProjectsLabel = new Label(res, SWT.NONE);
+ nestedProjectsLabel.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1));
+ nestedProjectsLabel.setText(NLS.bind(Messages.EasymportWizardPage_importedProjects, 0));
+
final TableViewer nestedProjectsTable = new TableViewer(res);
nestedProjectsTable.setContentProvider(new IStructuredContentProvider() {
@Override
@@ -193,16 +194,86 @@
return projectLocation.makeRelativeTo(rootLocation).toString();
}
});
-
nestedProjectsTable.setInput(this.job.getConfiguredProjects());
+
+
+ //// Errors
+ final Label errorsLabel = new Label(res, SWT.NONE);
+ GridData errorLabelLayoutData = new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1);
+ errorLabelLayoutData.exclude = true;
+ errorsLabel.setLayoutData(errorLabelLayoutData);
+ errorsLabel.setText(NLS.bind(Messages.EasymportWizardPage_importErrors, 0));
+
+ final TableViewer errorsTable = new TableViewer(res);
+ errorsTable.setContentProvider(new IStructuredContentProvider() {
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+ @Override
+ public Object[] getElements(Object root) {
+ return ((Map<IPath, Exception>)root).entrySet().toArray();
+ }
+ });
+ errorsTable.setSorter(new ViewerSorter() {
+ @Override
+ public int compare(Viewer viewer, Object o1, Object o2) {
+ IPath location1 = ((Entry<IPath, Exception>) o1).getKey();
+ IPath location2 = ((Entry<IPath, Exception>) o2).getKey();
+ return location1.toString().compareTo(location2.toString());
+ }
+ });
+ errorsTable.setFilters(new ViewerFilter[] { new ViewerFilter() {
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ Entry<IPath, Exception> entry = (Entry<IPath, Exception>) element;
+ return job.getRootProject().getLocation().isPrefixOf(entry.getKey());
+ }
+ } });
+ errorsTable.getTable().setHeaderVisible(true);
+ GridData errorTableLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
+ errorTableLayoutData.heightHint = 100;
+ errorTableLayoutData.exclude = true;
+ errorsTable.getControl().setLayoutData(errorTableLayoutData);
+
+ TableViewerColumn errorRelativePathColumn = new TableViewerColumn(errorsTable, SWT.LEFT);
+ errorRelativePathColumn.getColumn().setText(Messages.EasymportWizardPage_relativePath);
+ errorRelativePathColumn.getColumn().setWidth(300);
+ errorRelativePathColumn.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ IPath rootLocation = job.getRootProject().getLocation();
+ IPath projectLocation = ((Entry<IPath, Exception>)element).getKey();
+ return projectLocation.makeRelativeTo(rootLocation).toString();
+ }
+ });
+ TableViewerColumn errorColumn = new TableViewerColumn(errorsTable, SWT.LEFT);
+ errorColumn.getColumn().setText(Messages.EasymportWizardPage_error);
+ errorColumn.getColumn().setWidth(500);
+ errorColumn.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return ((Entry<IPath, Exception>)element).getValue().getMessage();
+ }
+ });
+ errorsTable.setInput(this.job.getErrors());
+
+
+
RecursiveImportListener tableReportFiller = new RecursiveImportListener() {
@Override
public void projectCreated(IProject project) {
nestedProjectsTable.getControl().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
- getShell().layout(true);
- label.setText(NLS.bind(Messages.EasymportWizardPage_importedProjects, nestedProjectsTable.getTable().getItemCount()));
+ nestedProjectsTable.refresh();
+ nestedProjectsTable.getTable().update();
+ nestedProjectsTable.getTable().redraw();
+ nestedProjectsLabel.setText(NLS.bind(Messages.EasymportWizardPage_importedProjects, job.getConfiguredProjects().size()));
}
});
}
@@ -218,6 +289,24 @@
}
});
}
+
+ @Override
+ public void errorHappened(IPath location, Exception error) {
+ errorsTable.getControl().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ GridData gridData = (GridData)errorsTable.getControl().getLayoutData();
+ if (gridData.exclude) {
+ gridData.exclude = false;
+ ((GridData)errorsLabel.getLayoutData()).exclude = false;
+ }
+ errorsTable.refresh();
+ errorsTable.getTable().update();
+ errorsLabel.setText(NLS.bind(Messages.EasymportWizardPage_importErrors, job.getErrors().size()));
+ res.layout(true);
+ }
+ });
+ }
};
this.job.setListener(tableReportFiller);
diff --git a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/Messages.java b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/Messages.java
index dc568f4..8379488 100644
--- a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/Messages.java
+++ b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/Messages.java
@@ -42,6 +42,8 @@
public static String EasymportWizardPage_relativePath;
public static String EasymportWizardPage_project;
public static String EasymportWizardPage_natures;
+ public static String EasymportWizardPage_importErrors;
+ public static String EasymportWizardPage_error;
public static String discardRootProject_title;
public static String discardRootProject_description;
diff --git a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/Messages.properties b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/Messages.properties
index 5b38848..adc366e 100644
--- a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/Messages.properties
+++ b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/Messages.properties
@@ -35,6 +35,8 @@
EasymportWizardPage_relativePath=Relative Path
EasymportWizardPage_project=Project
EasymportWizardPage_natures=Natures
+EasymportWizardPage_importErrors=Skipped {0} locations because of errors
+EasymportWizardPage_error=Error
discardRootProject_title=Discard root project?
discardRootProject_description=It seems like the root directory you specified doesn't contain much development data. Do you want to discard it?\n\
While keeping the root project may be helpful for navigation purpose (especially if you use nested view of projects), discarding it may improve the overall performances of your IDE.
\ No newline at end of file
diff --git a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/RecursiveImportListener.java b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/RecursiveImportListener.java
index 5c31da0..a529078 100644
--- a/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/RecursiveImportListener.java
+++ b/bundles/org.eclipse.e4.ui.importer/src/org/eclipse/ui/internal/wizards/datatransfer/RecursiveImportListener.java
@@ -11,6 +11,7 @@
package org.eclipse.ui.internal.wizards.datatransfer;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.ui.wizards.datatransfer.ProjectConfigurator;
public interface RecursiveImportListener {
@@ -18,5 +19,7 @@
public void projectCreated(IProject project);
public void projectConfigured(IProject project, ProjectConfigurator configurator);
-
+
+ public void errorHappened(IPath location, Exception ex);
+
}