Update org.apache.commons:commons-compress to 1.25.0
[egit/eclipse.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / clone / SmartImportGitWizard.java
blobe6123c6afed4d2974923405cbeb6edb03dbe7a2d
1 /*******************************************************************************
2 * Copyright (C) 2015, 2019 Red Hat Inc. and others
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
11 * Contributors:
12 * - Mickael Istria (Red Hat Inc.) : initial implementation
13 *******************************************************************************/
14 package org.eclipse.egit.ui.internal.clone;
16 import java.io.File;
17 import java.net.URISyntaxException;
18 import java.util.List;
20 import org.eclipse.egit.ui.internal.UIIcons;
21 import org.eclipse.egit.ui.internal.UIText;
22 import org.eclipse.egit.ui.internal.clone.GitCloneSourceProviderExtension.CloneSourceProvider;
23 import org.eclipse.egit.ui.internal.provisional.wizards.GitRepositoryInfo;
24 import org.eclipse.egit.ui.internal.provisional.wizards.NoRepositoryInfoException;
25 import org.eclipse.jface.dialogs.IDialogSettings;
26 import org.eclipse.jface.dialogs.IPageChangeProvider;
27 import org.eclipse.jface.dialogs.IPageChangedListener;
28 import org.eclipse.jface.dialogs.PageChangedEvent;
29 import org.eclipse.jface.viewers.IStructuredSelection;
30 import org.eclipse.jface.wizard.IWizardContainer;
31 import org.eclipse.jface.wizard.IWizardPage;
32 import org.eclipse.jgit.lib.Repository;
33 import org.eclipse.ui.IImportWizard;
34 import org.eclipse.ui.IWorkbench;
35 import org.eclipse.ui.internal.wizards.datatransfer.SmartImportRootWizardPage;
36 import org.eclipse.ui.internal.wizards.datatransfer.SmartImportWizard;
38 /**
39 * Alternative Git clone wizard using auto import framework incubating in e4
41 public class SmartImportGitWizard extends AbstractGitCloneWizard
42 implements IImportWizard, IPageChangedListener {
44 private SmartImportWizard smartImportWizard;
46 private GitSelectRepositoryPage selectRepoPage = new GitSelectRepositoryPage(
47 false);
49 /**
50 * Constructor
52 public SmartImportGitWizard() {
53 super();
54 IDialogSettings dialogSettings = super.getDialogSettings();
55 if (dialogSettings == null) {
56 dialogSettings = org.eclipse.egit.ui.Activator.getDefault()
57 .getDialogSettings();
58 setDialogSettings(dialogSettings);
60 setDefaultPageImageDescriptor(UIIcons.WIZBAN_IMPORT_REPO);
61 this.smartImportWizard = new SmartImportWizard();
62 setWindowTitle(UIText.GitImportWizard_WizardTitle);
65 @Override
66 protected void addPreClonePages() {
67 if (!hasSearchResult()) {
68 addPage(selectRepoPage);
72 @Override
73 protected void addPostClonePages() {
74 this.smartImportWizard.addPages();
77 @Override
78 public boolean performFinish() {
79 return true; // delegated to SmartImportWizard
82 @Override
83 public boolean canFinish() {
84 return getContainer().getCurrentPage()
85 .getWizard() == this.smartImportWizard
86 && this.smartImportWizard.canFinish();
89 @Override
90 public void init(IWorkbench workbench, IStructuredSelection selection) {
91 // nothing to do
94 @Override
95 protected List<CloneSourceProvider> getCloneSourceProviders() {
96 List<CloneSourceProvider> cloneSourceProvider = super.getCloneSourceProviders();
97 cloneSourceProvider.add(0, CloneSourceProvider.LOCAL);
98 return cloneSourceProvider;
102 * @return the clone destination page
104 public CloneDestinationPage getCloneDestinationPage() {
105 return this.cloneDestination;
108 @Override
109 public IWizardPage getNextPage(IWizardPage page) {
110 if (page == selectRepoPage || page == this.cloneDestination) {
111 return this.smartImportWizard.getPages()[0];
113 return super.getNextPage(page);
117 * @return whether according to current config, the selected repo needs to
118 * be cloned
120 public boolean needsClone() {
121 return this.cloneDestination.cloneSettingsChanged();
124 private boolean needToCloneRepository() {
125 return SmartImportGitWizard.this.cloneDestination.cloneSettingsChanged();
128 private File doClone(final SmartImportRootWizardPage importRootPage) {
129 setCallerRunsCloneOperation(true);
130 try {
131 final GitRepositoryInfo repositoryInfo = currentSearchResult.getGitRepositoryInfo();
132 performClone(repositoryInfo);
133 getContainer().getShell().getDisplay().asyncExec(() -> {
134 runCloneOperation(getContainer(), repositoryInfo);
135 cloneDestination.saveSettingsForClonedRepo();
136 importRootPage.setInitialImportRoot(
137 getCloneDestinationPage().getDestinationFile());
139 } catch (URISyntaxException e) {
140 org.eclipse.egit.ui.Activator.error(UIText.GitImportWizard_errorParsingURI, e);
141 } catch (NoRepositoryInfoException e) {
142 org.eclipse.egit.ui.Activator.error(UIText.GitImportWizard_noRepositoryInfo, e);
143 } catch (Exception e) {
144 org.eclipse.egit.ui.Activator.error(e.getMessage(), e);
146 return getCloneDestinationPage().getDestinationFile();
149 @Override
150 public void pageChanged(PageChangedEvent event) {
151 SmartImportRootWizardPage selectRootPage = (SmartImportRootWizardPage) this.smartImportWizard
152 .getPages()[0];
153 if (event.getSelectedPage() == selectRootPage) {
154 Repository existingRepo = selectRepoPage.getRepository();
155 if (existingRepo != null) {
156 selectRootPage.setInitialImportRoot(existingRepo.getWorkTree());
157 } else if (needToCloneRepository()) {
158 // asynchronous clone, set root later.
159 doClone(selectRootPage);
164 @Override
165 public void setContainer(IWizardContainer container) {
166 if (container instanceof IPageChangeProvider) {
167 ((IPageChangeProvider) container).addPageChangedListener(this);
169 super.setContainer(container);
172 @Override
173 public void dispose() {
174 if (getContainer() instanceof IPageChangeProvider) {
175 ((IPageChangeProvider) getContainer())
176 .removePageChangedListener(this);
178 super.dispose();