Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ public class DataTransferMessages extends NLS {
public static String SmartImportProposals_hideExistingProjects;
public static String SmartImportProposals_inspecitionCanceled;
public static String SmartImportProposals_errorWhileInspecting;
public static String SmartImportProposals_projectAlreadyOpen_title;
public static String SmartImportProposals_projectAlreadyOpen_message;
public static String SmartImportProposals_projectAlreadyClosed_title;
public static String SmartImportProposals_projectAlreadyClosed_message;
public static String SmartImportProposals_showInProjectExplorer;
public static String SmartImportProposals_openProject;
public static String SmartImportProposals_openProjectFailed;
public static String SmartImportProposals_openFailed;

public static String SmartImportReport_importedProjects;
public static String SmartImportReport_importedProjectsWithCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.fieldassist.ControlDecoration;
Expand All @@ -62,6 +64,7 @@
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.ProgressMonitorPart;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
Expand All @@ -88,7 +91,11 @@
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
Expand All @@ -100,6 +107,7 @@
import org.eclipse.ui.internal.progress.ProgressManager.JobMonitor;
import org.eclipse.ui.internal.registry.WorkingSetDescriptor;
import org.eclipse.ui.internal.registry.WorkingSetRegistry;
import org.eclipse.ui.part.ISetSelectionTarget;
import org.eclipse.ui.statushandlers.StatusManager;
import org.eclipse.ui.wizards.datatransfer.ProjectConfigurator;
import org.osgi.framework.FrameworkUtil;
Expand Down Expand Up @@ -607,14 +615,21 @@ public boolean isChecked(Object element) {
}
});
tree.addCheckStateListener(event -> {
if (isExistingProject((File) event.getElement()) || isExistingProjectName((File) event.getElement())) {
tree.setChecked(event.getElement(), false);
File file = (File) event.getElement();
IProject existingProject = findExistingProject(file);
if (existingProject != null) {
tree.setChecked(file, false);
promptAlreadyImportedProject(file, existingProject);
return;
}
if (isExistingProjectName(file)) {
tree.setChecked(file, false);
return;
}
if (event.getChecked()) {
SmartImportRootWizardPage.this.directoriesToImport.add((File) event.getElement());
SmartImportRootWizardPage.this.directoriesToImport.add(file);
} else {
SmartImportRootWizardPage.this.directoriesToImport.remove(event.getElement());
SmartImportRootWizardPage.this.directoriesToImport.remove(file);
}
proposalsSelectionChanged();
});
Expand Down Expand Up @@ -787,21 +802,92 @@ private String getValue(String s) {
}

}
protected boolean isExistingProject(File element) {

protected IProject findExistingProject(File element) {
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
IPath location = project.getLocation();
if (location != null && element.equals(location.toFile())) {
return true;
return project;
}
}
return false;
return null;
}

protected boolean isExistingProject(File element) {
return findExistingProject(element) != null;
}

protected boolean isExistingProjectName(File element) {
String name = element.getName();
return !name.isEmpty() && ResourcesPlugin.getWorkspace().getRoot().getProject(name).exists();
}

private void promptAlreadyImportedProject(File file, IProject project) {
tree.setSelection(new StructuredSelection(file), true);
boolean isOpen = project.isOpen();
String title = isOpen ? DataTransferMessages.SmartImportProposals_projectAlreadyOpen_title
: DataTransferMessages.SmartImportProposals_projectAlreadyClosed_title;
String message = NLS.bind(isOpen ? DataTransferMessages.SmartImportProposals_projectAlreadyOpen_message
: DataTransferMessages.SmartImportProposals_projectAlreadyClosed_message, project.getName());
String actionLabel = isOpen ? DataTransferMessages.SmartImportProposals_showInProjectExplorer
: DataTransferMessages.SmartImportProposals_openProject;

MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION,
new String[] { actionLabel, IDialogConstants.CANCEL_LABEL }, 0);
if (dialog.open() == 0) {
if (isOpen) {
showProjectInExplorer(project);
} else {
openProject(project);
}
if (tree.getCheckedElements().length == 0) {
getContainer().getShell().getDisplay().asyncExec(() -> {
if (getContainer() instanceof WizardDialog wizardDialog) {
wizardDialog.close();
}
});
}
}
}

private void openProject(IProject project) {
try {
getContainer().run(true, true, monitor -> {
try {
project.open(monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException | InterruptedException e) {
StatusManager
.getManager().handle(
new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH,
NLS.bind(DataTransferMessages.SmartImportProposals_openProjectFailed,
project.getName()),
e.getCause() != null ? e.getCause() : e),
StatusManager.LOG | StatusManager.SHOW);
return;
}
showProjectInExplorer(project);
}

private void showProjectInExplorer(IProject project) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null || window.getActivePage() == null) {
return;
}
try {
IViewPart view = window.getActivePage().showView(IPageLayout.ID_PROJECT_EXPLORER);
if (view instanceof ISetSelectionTarget target) {
target.selectReveal(new StructuredSelection(project));
}
} catch (PartInitException e) {
StatusManager.getManager().handle(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH,
DataTransferMessages.SmartImportProposals_openFailed, e), StatusManager.LOG);
}
}

protected void validatePage() {
// reset error message
setErrorMessage(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ SmartImportProposals_importAs=Import as
SmartImportProposals_hideExistingProjects=&Hide already open projects
SmartImportProposals_inspecitionCanceled=Inspeciton canceled
SmartImportProposals_errorWhileInspecting=Error while inspecting: {0}
SmartImportProposals_projectAlreadyOpen_title=Project Already Open
SmartImportProposals_projectAlreadyOpen_message=The project ''{0}'' is already open in the workspace.
SmartImportProposals_projectAlreadyClosed_title=Project Already Exists (Closed)
SmartImportProposals_projectAlreadyClosed_message=The project ''{0}'' already exists in the workspace but is currently closed.
SmartImportProposals_showInProjectExplorer=&Show In Project Explorer
SmartImportProposals_openProject=&Open Project
SmartImportProposals_openProjectFailed=Failed to open project ''{0}''
SmartImportProposals_openFailed=Unable to open project in Explorer view
SmartImportJob_detectAndConfigureProjects=Detecting and configuring nested projects
SmartImportJob_configuringSelectedDirectories=Configuring selected directories
SmartImportJob_configuring=Configuring project {0}
Expand Down
Loading