Have icon for "reset" entry in reflog
[egit/eclipse.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / clone / GitCloneWizard.java
blob5c48e2de568b40f0bdd8c4de24bbf817e9302803
1 /*******************************************************************************
2 * Copyright (C) 2008, Roger C. Soares <rogersoares@intelinet.com.br>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
4 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
5 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
6 * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
7 * Copyright (C) 2010, Benjamin Muskalla <bmuskalla@eclipsesource.com>
9 * All rights reserved. This program and the acco mpanying materials
10 * are made available under the terms of the Eclipse Public License 2.0
11 * which accompanies this distribution, and is available at
12 * https://www.eclipse.org/legal/epl-2.0/
14 * SPDX-License-Identifier: EPL-2.0
15 *******************************************************************************/
16 package org.eclipse.egit.ui.internal.clone;
18 import java.io.File;
19 import java.io.IOException;
20 import java.net.URISyntaxException;
22 import org.eclipse.egit.ui.Activator;
23 import org.eclipse.egit.ui.internal.UIIcons;
24 import org.eclipse.egit.ui.internal.UIText;
25 import org.eclipse.egit.ui.internal.components.RepositorySelectionPage;
26 import org.eclipse.egit.ui.internal.provisional.wizards.IRepositorySearchResult;
27 import org.eclipse.egit.ui.internal.provisional.wizards.NoRepositoryInfoException;
28 import org.eclipse.jface.dialogs.MessageDialog;
29 import org.eclipse.jgit.util.FileUtils;
31 /**
32 * Import Git Repository Wizard. A front end to a git clone operation.
34 public class GitCloneWizard extends AbstractGitCloneWizard {
36 private static final String HELP_CONTEXT = "org.eclipse.egit.ui.GitCloneWizard"; //$NON-NLS-1$
38 /**
39 * Construct the clone wizard with a repository location page that allows
40 * the repository info to be provided by different search providers.
42 public GitCloneWizard() {
43 initialize();
46 /**
47 * Construct the clone wizard with a preset URI. The wizard skips the
48 * repository location page in this case. Instead, it starts with the Custom
49 * URI repository selection page.
51 * @param presetUri
52 * the clone URI to prepopulate the URI field of the clone wizard
53 * with.
55 public GitCloneWizard(String presetUri) {
56 super(new RepositorySelectionPage(true, presetUri));
57 initialize();
60 /**
61 * Construct the clone wizard based on given repository search result. The
62 * wizard skips the repository location page in this case.
64 * @param searchResult
65 * the search result to initialize the clone wizard with.
67 public GitCloneWizard(IRepositorySearchResult searchResult) {
68 super(searchResult);
69 initialize();
72 private void initialize() {
73 setWindowTitle(UIText.GitCloneWizard_title);
74 setDefaultPageImageDescriptor(UIIcons.WIZBAN_IMPORT_REPO);
75 setNeedsProgressMonitor(true);
76 validSource.setHelpContext(HELP_CONTEXT);
77 cloneDestination.setHelpContext(HELP_CONTEXT);
80 /**
81 * Set whether to show project import options on the destination page
83 * @param show
84 * @return this wizard
86 public AbstractGitCloneWizard setShowProjectImport(boolean show) {
87 cloneDestination.setShowProjectImport(show);
88 return this;
91 @Override
92 public boolean performCancel() {
93 if (alreadyClonedInto != null) {
94 File test = new File(alreadyClonedInto);
95 if (test.exists()
96 && MessageDialog.openQuestion(getShell(),
97 UIText.GitCloneWizard_abortingCloneTitle,
98 UIText.GitCloneWizard_abortingCloneMsg)) {
99 try {
100 FileUtils.delete(test, FileUtils.RECURSIVE | FileUtils.RETRY);
101 } catch (IOException e) {
102 throw new RuntimeException(e);
106 return true;
109 @Override
110 protected void addPreClonePages() {
111 // no pages to add
114 @Override
115 protected void addPostClonePages() {
116 // no pages to add
119 @Override
120 public boolean canFinish() {
121 return cloneDestination.isPageComplete();
124 @Override
125 public boolean performFinish() {
126 try {
127 return performClone(currentSearchResult.getGitRepositoryInfo());
128 } catch (URISyntaxException e) {
129 Activator.error(UIText.GitImportWizard_errorParsingURI, e);
130 } catch (NoRepositoryInfoException e) {
131 Activator.error(UIText.GitImportWizard_noRepositoryInfo, e);
132 } catch (Exception e) {
133 Activator.error(e.getMessage(), e);
134 } finally {
135 setWindowTitle(UIText.GitCloneWizard_title);
137 return false;